So I am using a dictionary and using a type {U64, U8} as key, then it works, however if I just changed type to {U128,U8} I start to get some really weird issues... It says keys exist that shouldnt exist. However if I change the code to all using U64 it runs flawlessly. Code used is here, Warning for spoiler for AoC day 11: https://gist.github.com/jonwarghed/d5606997fb705f5ce2a3c09a3ab98705
Thanks for reporting this @Jon Erik Kemi Warghed
There is a lot of output if I execute roc test
, both when using U128
and U64
, can you narrow this down a bit?
We may just hash u128 wrong.
Sure let me see if I can make it more easily reproducible as well.
Code is not much easier, but the output should be clearer, please let me know, I am kinda new in Roc. So not easy to force types correctly yet for a minimal example :)
This is the input? 0 1 10 99 999
also, what type of machine are you on?
Ah sorry example input is 125 17
❯ uname -a
Linux jotunheim 6.6.63 #1-NixOS SMP PREEMPT_DYNAMIC Fri Nov 22 14:38:37 UTC 2024 x86_64 GNU/Linux
thanks. Seems target specific. Works on mac. So probably is alignment or some silly call conv thing.
on m1 mac see:
────────────────────────────────────────────────────────────────────────────────
[/tmp/bug.roc:80] ("Inserting", curr, result) = ("Inserting", {pebble: 125, target: 1}, 1)
[/tmp/bug.roc:87] ("Inserting", curr, r) = ("Inserting", {pebble: 17, target: 1}, 2)
[/tmp/bug.roc:103] end_memory.brain = {{pebble: 125, target: 1}: 1, {pebble: 17, target: 1}: 2}
── EXPECT FAILED in /tmp/bug.roc ───────────────────────────────────────────────
possible, let me know if I should do anything else.
I'll test on my linux box. See if I can repro
yeah, I can repro
Cool, I have a devenv.lock if needed.
Woah, this looks to be a List.append
bug.
That or an inspect printout bug
This is logging from the list insertion in the dictionary:
[/tmp/MyDict.roc:466] data0 = [({pebble: 125, target: 1}, 1)]
[/tmp/MyDict.roc:467] ("Inserting", key, value) = ("Inserting", {pebble: 17, target: 1}, 2)
[/tmp/MyDict.roc:469] data1 = [({pebble: 125, target: 1}, 1), ({pebble: 322962136477993009152, target: 0}, 36893488147419103233)]
[/tmp/MyDict.roc:471] List.get data1 dataIndex = (Ok ({pebble: 322962136477993009152, target: 0}, 36893488147419103233))
So somehow these types break List.append
.
Seems like we might be writting at the wrong offset. 322962136477993009152
constains 17
along with garbage. 36893488147419103233
contains both 1
and 2
Minimal repro is literally just this:
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br" }
import pf.Stdout
main =
x = []
Stdout.line! (Inspect.toStr x)
a = ({pebble: 125u128, target: 1u8}, 1u128)
Stdout.line! "Inserting: $(Inspect.toStr a)"
y = List.append x a
Stdout.line! (Inspect.toStr y)
b = ({pebble: 17, target: 1}, 2)
Stdout.line! "Inserting: $(Inspect.toStr b)"
z = List.append y b
Stdout.line! (Inspect.toStr z)
Oh, this is just llvm thinking that i128 should be aligned to 8 bytes instead of 16
So it ends up calculating the gep instruction wrong
If you assume alignment of 8, { { i128, i8 }, i128 }
has a size of 40
. If the alignment is 16
, the size is 48
This honestly might be a pain to fix. Is a version of llvm with i128 alignment changed to 16 released yet? If so, updating to that version of llvm may be the best fix (work we already have to do anyway).
Looks like LLVM 20 should have it?
The v18 update has been a good amount of work, we should try to separately upgrade from LLVM 18 to 20
Really, not until 20? The rust issue related to this thought it should get release in 18.
Also, saw some micro benchmarks showing the alignment leading to a 12% perf gain. Clearly, these targeted alignment related issues, but just surprising a bit. Looking at rust projects updating to 1.78.0. some got perf gains of up to 20%. but most got 0% to 5% gains.
Let me get a specific answer, this was from loose GH issue investigating
https://godbolt.org/z/c5vaPd9or
It is fixed in 18
we should try to separately upgrade from LLVM 18 to 20
Also, I think 20 is trunk. 19 is the newest release.
Also, can confirm that this bug is fixed with https://github.com/roc-lang/roc/pull/6921
This should be fixed on main now
Last updated: Jul 06 2025 at 12:14 UTC