Hi all,
We just updated the builtin Set and Dictionary to be hash based. They now should be significantly faster especially as they get large. These new Set and Dict are in the latest nightly from today (2022-12-05). If you have used Set/Dict in any of your AOC programs, it would be very useful if you could download the latest nightly and test your program again. I want to try and catch/fix any bugs early.
If you run into any issues, please either comment here or create an issue on the github.
I tried to modify today's solution to use Dicts, and ran into an error:
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread '<unnamed>' panicked at 'ambient functions don't unify', /home/big-ci-user/actions-runner/_work/roc/roc/crates/compiler/unify/src/unify.rs:247:18
I pushed the solution to a separate branch in my github repo: https://github.com/mkaszas/aoc-2022/blob/mkaszas/dict-compiler-bug/Day5.roc
I opened a PR as well, with the full stacktrace pasted in the description: https://github.com/mkaszas/aoc-2022/pull/1
Running roc_nightly-linux_x86_64-2022-12-05-306f3be
in docker.
Hope this helps:)
Just trying to get to a minimal example now, and looks like Dict.fromList []
can cause issues too. roc check
passes, but run
& build
fails with:
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', crates/compiler/mono/src/ir.rs:5710:56
Here's a minimal example that still reproduces this issue for me: https://github.com/mkaszas/aoc-2022/blob/mkaszas/dict-compiler-bug/DictTest.roc
Looks like the issue is with creating a Dict with Nat
key type. When I remove the type annotation from myDict
, it works as expected.
app "dict-test"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.1.1/zAoiC9xtQPHywYk350_b7ust04BmWLW00sjb9ZPtSQk.tar.br" }
imports [pf.Process, pf.Stdout, pf.Task]
provides [main] to pf
main =
myDict : Dict Nat Str
myDict =
Dict.single 1 "One"
_ <- Task.await (Stdout.line "ok")
Process.exit 0
Interesting. This looks to specific ally be an issue with using Nat
as a key to the dictionary.
I wonder if abilities have an issue mapping hashing to Nat
. For that it would need to map from Nat
to hashing a U64
because that is the underlying type of Nat
on a 64 bit system.
Yeah. Making everything a U64
and dealing with type conversions back to Nat
when needed fixes the issue. Interesting. @Ayaz Hafiz would this be an issue with deriving the hash ability for Nat
(probably due to it needing to change bitwidth based on the platform)?
Taking a look
Yeah, Nat as a key for a Dict is not currently supported. The underlying issue is that hashing a Nat is not currently supported - that should either be fixed, or the compiler should print a nicer error message for you. While we resolve that, you should be able to use a different integer type for the key.
yeah we should support hashing a Nat if possible!
As for your original reported bug - that should be fixed if you use another number type for now, and with tomorrow's nightly (which should include https://github.com/roc-lang/roc/pull/4688)
Okay, all of this should work in tomorrows nightly release of roc!
Big thanks @Brendan Hansknecht
Last updated: Jul 06 2025 at 12:14 UTC