roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.16k stars 294 forks source link

Panic in alias analysis #6544

Open j-maas opened 7 months ago

j-maas commented 7 months ago

I have come across more code that makes the alias analysis panic that is related to nested oneOfs from the roc-parser package and expects. When I run the code below, I get this compiler error:

jojo@Windows-PC:~/code/feed-reader$ roc test backend/test.roc
[... some warnings about unnecessary definitions ...]
thread 'main' panicked at 'Error in alias analysis: duplicate function name FuncName("\x14\x00\x00\x00\x0b\x00\x00\x00\x02hE\x88u\xeaN\x8f") in module', crates/compiler/gen_llvm/src/llvm/build.rs:5761:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is minimal reproduction code. If you put this in a file at the root of the roc-parser repo and run it with roc test, you should see the above error.

app "hello-world"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br",
        parser: "./package/main.roc",
    }
    imports [
        pf.Stdout,
        pf.Task.{ Task },
        parser.Core.{ Parser, oneOf },
        parser.String.{ Utf8 },
    ]
    provides [main] to pf

Node : [
    Element (List Node),
]

pElement : Parser Utf8 _
pElement =
    # Removing one of the `oneOf`s solves the panic
    oneOf [
        oneOf [
            pElement,
        ],
    ]

expect
    # Removing this access solves the panic
    _temp = pElement
    Bool.true

main : Task {} I32
main =
    _temp =
        # This access does not cause the panic
        pElement
    Stdout.line "Testing"

I'm running the current nightly of Roc:

jojo@Windows-PC:~/code/roc-xml-parser/dependencies/roc-parser$ roc --version
roc nightly pre-release, built from commit 3ea9739 on Di 27 Feb 2024 09:01:38 UTC

Similar issues

I reported this issue on the roc-parser repo first, but we suspect that we should report it here too.

I've searched the issues here for the error message (Error in alias analysis: duplicate function name) and these are currently open:

folkertdev commented 6 months ago

note that the error is generally not in alias analysis, but earlier in monomorphization. alias analysis just validates the program and when an earlier step is incorrect, it will be detected in alias analysis.