It took me way too long to realize that the problem is not in my code but Dict is broken :smiling_face_with_tear:
Any more details on how it is broken or a minimal repro if you have/can make one?
Min-repro’ing this is going to be really hard. My code works for the “example input”, and on the bigger input it crashes after many many iterations with an unwrap of KeyNotFound on a dict that IIUC has that key in there. https://github.com/shritesh/advent/blob/4995ae8d8bdc4d0ea11edce9555ccccc27707324/2022/12.roc#L36
Is see. Yeah, may be quite hard to debug. Does dbg printing Dict.keys
show the key?
That will end up printing the underlying list. Would let us know if it is simply a bug in the hash lookup or if it is something else.
In the latest Apple Silicon nightly, running roc dev 12.roc
simply exits without doing anything if I put a dbg before the unwrap
ok. sad
Interesting. I can't seem to repro. It still fails, but it is hitting a integer addition overflowed!
in the helper function Looks to be happening directly in the newHops List.walk lambda. (note, I am running from source, not from a nightly)
Oh, actually. it is specifically hitting it on alt = currentHop + 1
. If I change that to alt = Num.addWrap currentHop 1
, the code you linked will pass for me and print out a result.
nice. roc dev
was taking too long for the full input so I was using optimize. Is integer overflow an undefined behavior in optimized roc programs?
no we specifically do want it to panic in release builds
gotcha. I can repro different behaviors in the file linked above where roc run
crashes with overflow while roc run --optimize
essentially shows undefined behavior.
Just a note, roc dev --optimize
works. So you can have both
Huh. Only roc run --optimize
manifests the "undefined behavior". roc dev
, roc dev --optimize
and roc run
all result in the integer overflow.
That's quite intriguing. Definitely something to investigate
seems likely to be unrelated
like there's an --optimize
bug unrelated to overflow that's causing things to break in a way that means the overflow doesn't happen
But only in run --optimize
and not dev --optimize
?
Yeah, i see. I guess it means there is a compiler bug. Then there is also the bug with the example shared
Ok so this is definitely a compiler bug: I fixed the integer overflow error in my code. roc run
, roc dev
and roc dev --optimize
all return the correct result. roc run --optimize
crashes at that exact same point as before. https://github.com/shritesh/advent/blob/d021f18788fd46b12b485df7932fc5c8315c4e55/2022/12.roc
moar: roc build --optimize
is broken as well
even moar: the same holds true for --opt-size
instead of --optimize
for all the commands.
Opened up an issue: https://github.com/roc-lang/roc/issues/4756
Anyway, here's my final solution for Day 12. I'm extremely pleased with the result. Implementing Dijkstra's in Roc forced me to truly internalize the algorithm while my previous understanding was a data structure centric one: "use a minimum priority queue, mark nodes as visited, etc.". Roc is turning into my favorite programming language by the day.
Last updated: Jul 06 2025 at 12:14 UTC