Stream: beginners

Topic: Error in alias analysis: duplicate function name FuncName


view this post on Zulip Kilian Vounckx (Dec 16 2023 at 15:19):

Just for fun, I was trying to create iterators. I know they are not planned to be in the language and I don't think they should be. I was just trying some stuff out. I was going with ocaml's Seq design to create possibly infinite iterators when the compiler crashed. I don't know if this is a know issue or not.

I have the following file:

interface IterMinimal
    exposes [
        Iter,
        Node,
        fromList,
        map,
        toList,
    ]
    imports []

Iter a : [Iter ({} -> Node a)] # Needs to be a tag because of recursive types

Node a : [
    Nil,
    Cons (a, Iter a),
]

# ======= Sequence Generation =======

fromList : List a -> Iter a
fromList = \list ->
    when list is
        [] -> Iter \{} -> Nil
        [x, .. as rest] -> Iter \{} -> Cons (x, fromList rest)

expect toList (fromList [1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]

# ======= Sequence Transformation =======

map : Iter a, (a -> b) -> Iter b
map = \Iter iter, func ->
    Iter \{} ->
        when iter {} is
            Nil -> Nil
            Cons (x, rest) -> Cons (func x, map rest func)

expect toList (map (fromList [1, 2, 3, 4, 5]) \x -> x * 2) == [2, 4, 6, 8, 10]

# ======= Sequence Consumption =======

toList : Iter a -> List a
toList = \iter ->
    helper : Iter a, List a -> List a
    helper = \Iter it, acc ->
        when it {} is
            Nil -> acc
            Cons (x, rest) -> helper rest (List.append acc x)
    helper iter []

When I do roc check on it, nothing seems wrong. When I do roc test, the compiler crashed with the following message:

thread 'main' panicked at 'Error in alias analysis: duplicate function name FuncName("\x11\x00\x00\x00\x03\x00\x00\x00\x97\xf1\xf2\xd5\xc5]C:") in module', crates/compiler/gen_llvm/src/llvm/build.rs:5744:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:22):

Try merging iter and node into one declaration

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:23):

Currently only self recursive types work, not mutually recursive

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 15:26):

Literally pasting Node's definition into Iter does not work:

Iter a : [
    Iter (
        {} -> [
            Nil,
            Cons (a, Iter a),
        ]
    )
]

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 15:26):

Brendan Hansknecht said:

Currently only self recursive types work, not mutually recursive

Is there a plan to make mutually recursive types work?

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:28):

Just one of those long standing bugs that someone needs to track down and fix, though if this didn't fix your crash must be from something different

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:28):

Also, does roc check say anything useful?

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 15:32):

It checks just fine

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:34):

Hmm... I'm not sure currently

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:51):

Also, interesting, due to the closure, the types work here even though they are technically mutually recursive, no need to merge definitions

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:54):

Some reason, there is an issue when using the map function...not sure why

view this post on Zulip Brendan Hansknecht (Dec 16 2023 at 15:59):

Not sure if this is useful, but probably need to file a bug.

This is what happens when removing the type from map and letting the compiler try to solve for it:

thread '<unnamed>' panicked at 'structures ( Opaque(4.IdentId(0), [313], <313>RangedNumber( NumAtLeastEitherSign(I8))), Recursion(3394, None), )<3393> and ( Opaque(4.IdentId(0), [313], <313>RangedNumber( NumAtLeastEitherSign(I8))), ['Iter' <3356>Func([<3359>EmptyRecord,], <3358=3358>LambdaSet([], ^<3356>), <3357>Recursion(3360, None)) , ]<Any(3283)>, )<3362> do not unify; they should never have been involved in fixing!', crates/compiler/unify/src/fix.rs:346:22
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 16:29):

Brendan Hansknecht said:

Some reason, there is an issue when using the map function...not sure why

Yeah, I had a few tests before adding map which ran fine, maybe should have said that :sweat_smile:

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 16:30):

Brendan Hansknecht said:

Not sure if this is useful, but probably need to file a bug.

This is what happens when removing the type from map and letting the compiler try to solve for it:

thread '<unnamed>' panicked at 'structures ( Opaque(4.IdentId(0), [313], <313>RangedNumber( NumAtLeastEitherSign(I8))), Recursion(3394, None), )<3393> and ( Opaque(4.IdentId(0), [313], <313>RangedNumber( NumAtLeastEitherSign(I8))), ['Iter' <3356>Func([<3359>EmptyRecord,], <3358=3358>LambdaSet([], ^<3356>), <3357>Recursion(3360, None)) , ]<Any(3283)>, )<3362> do not unify; they should never have been involved in fixing!', crates/compiler/unify/src/fix.rs:346:22
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

I will do it later tonight

view this post on Zulip Kilian Vounckx (Dec 16 2023 at 16:55):

issue raised


Last updated: Jul 05 2025 at 12:14 UTC