Stream: contributing

Topic: ✔ Bug in new Dict impl: Integer multiplication overflowed


view this post on Zulip Johan Lindskogen (Dec 11 2023 at 21:42):

Hi, I noticed a problem in the latest main:

Roc crashed with:

    Integer multiplication overflowed!

Here is the call stack that led to the crash:

(there is no call stack in the message)

So I ran git bisect to find out that it was this commit that caused it:

51ec4311b59c766533f74e3af7392564bb9f14b6 - Swap Dict implementation to ankerl dense unordered

I think the new Dict implementation has some integer "underflow" error, (it seems to always report multiplication regardless of the actual operation performed).

Tagging @Brendan Hansknecht in this

Repro:

app "dict"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
    }
    imports [
        pf.Stdout,
        pf.Stderr,
        pf.File,
        pf.Path,
        pf.Task.{ Task },
    ]
    provides [main] to pf

main =

    list = [({x: 2, y: 0}, 16),
        ({x: 3, y: 0}, 1),
        ({x: 4, y: 0}, 2),
        ({x: 4, y: 1}, 3),
        ({x: 3, y: 1}, 4),
        ({x: 3, y: 2}, 5),
        ({x: 3, y: 3}, 6),
        ({x: 3, y: 4}, 7),
        ({x: 2, y: 4}, 8),
        ({x: 2, y: 3}, 9),
        ({x: 1, y: 3}, 10),
        ({x: 0, y: 3}, 11),
        ({x: 0, y: 2}, 12),
        ({x: 1, y: 2}, 13),
        ({x: 1, y: 1}, 14),
        ({x: 2, y: 1}, 15),
        ({x: 2, y: 0}, 16),
        ({x: 2, y: 1}, 1),
        ({x: 1, y: 1}, 2),
        ({x: 1, y: 2}, 3),
        ({x: 0, y: 2}, 4),
        ({x: 0, y: 3}, 5),
        ({x: 1, y: 3}, 6),
        ({x: 2, y: 3}, 7),
        ({x: 2, y: 4}, 8),
        ({x: 3, y: 4}, 9),
        ({x: 3, y: 3}, 10),
        ({x: 3, y: 2}, 11),
        ({x: 3, y: 1}, 12),
        ({x: 4, y: 1}, 13),
        ({x: 4, y: 0}, 14),
        ({x: 3, y: 0}, 15)]

    a = List.walk list (Dict.empty {}) \acc, (k, v) ->
        Dict.update acc k \val ->
            when val is
                Present p -> Present (if v < p then v else p)
                Missing -> Present v


    Stdout.line "res: \(Num.toStr (Dict.len a))"

view this post on Zulip Brendan Hansknecht (Dec 11 2023 at 22:55):

Thanks for the catch, my optimization to update was slightly off

view this post on Zulip Brendan Hansknecht (Dec 11 2023 at 22:55):

Was trying to reduce repeated work

view this post on Zulip Brendan Hansknecht (Dec 11 2023 at 23:37):

Should be fixed by #6256

view this post on Zulip Johan Lindskogen (Dec 12 2023 at 13:25):

Tested OK! :wink:

view this post on Zulip Notification Bot (Dec 12 2023 at 13:25):

Johan Lindskogen has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC