roc: llvm alloca unitentional mutation bug

I also posted this on the chat, but I think actually making an issue sounds like a good idea 🙂

I tried to make this example simpler by using lists instead of strings, but could not reproduce it with a lists version. So it seems to maybe also be related to the specifics of how strings are handled? Unfortunately I have have no idea about roc’s internals to make a good guess what might be happening here, since I just started actually writing roc code.

prefixes = \str, soFar ->
    if Str.isEmpty str then
        soFar

    else
        next = str
            |> Str.graphemes
            |> List.dropFirst 1
            |> Str.joinWith ""

        prefixes next (List.append soFar str)

# this is the (erroneous) output roc produces
expect prefixes "abc" [] == ["abc", "c", ""]

# this is what I whould have expected
expect prefixes "abc" [] == ["abc", "bc", "c"] # fails

If it helps, I could repro this with todays nighly build and an old one I still had from 11/28. It also did not make a difference whether I used basic-cli 0.6.2 or 0.7.0.

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Oof I just took the time to minimize a miscompilation I encountered in Advent of Code and I think it’s a duplicate of this:

interface Issue6139
    exposes [buggy]
    imports []

expect
    buggyAnswer = buggy "A" []
    buggyAnswer == ["A", "B", "C", "D"]

buggy = \node, seen ->
    if List.contains seen node then
        seen
    else
        dbg node # node = "B"
        nextNode = stepNode node
        dbg node # node = "C"

        buggy nextNode (List.append seen node)

stepNode = \node ->
    when node is
        "A" -> "B"
        "B" -> "C"
        "C" -> "D"
        "D" -> "A"
        _ -> crash ""