Stream: beginners

Topic: compiler bug?


view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 01:00):

Anything obvious that I am doing wrong here: https://gist.github.com/bhansconnect/4927cd203a407b98ee369da47c4f7e58

thread 'main' panicked at 'Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x02\x00\x00\x00\x13\x00\x00\x00\xa1\xfb\xe2\xb3\x18i\xd5#"), definition of value binding ValueId(3): could not find func in module ModName("UserApp") with name FuncName("\x04\x00\x00\x00\'\x00\x00\x00\xa1\xfb\xe2\xb3\x18i\xd5#")', crates/compiler/gen_llvm/src/llvm/build.rs:5123:19

I assume it is an issue with recursive functions that return task? I am just not sure why. roc check does pass.

view this post on Zulip Brian Carroll (Sep 19 2023 at 05:34):

Those are some funky FuncNames!
They have a lot of non ASCII characters, even though the source code doesn't.
The message mentions alias analysis which is to do with reference counting and operates on the monomorphic IR. Probably worth dumping that to debug further.

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 06:06):

This is a version that works: https://gist.github.com/bhansconnect/bbc096e1a19ad1056856bc0cb40a03c7

Still need to dig into exactly why the original version doesn't work. The core issue is recursively using tasks. Without Task.loop the recursive tasks break and I get the alias error.

view this post on Zulip Brian Carroll (Sep 19 2023 at 06:32):

That link has the same hash as above and writeRow is a recursive task.

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 06:42):

My bad. Updated.

view this post on Zulip Anton (Sep 19 2023 at 10:21):

We have several issues with that error.

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 15:31):

I wonder if that means it is an unclear error with little valuable information or if it means that the error is caused by a consistent issue any many places. Maybe @Ayaz Hafiz has a guess?

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 16:01):

If you hit a bug like that it's definitely a bug with the compiler middle/backend, not a user error

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 16:02):

it usually means we have a miscompilation. almost certainly during the mono IR lowering

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 16:03):

Since you can get a debug compiler, I would run ROC_CHECK_MONO_IR=1 when you build with the debug compiler - that's likely to print out where the problem in the miscompilation is

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 16:12):

Interesting, an error recognizing two specializations are the same?

This is repeated for many different functions:

await : ({Str, {}}, {I64, I64, I64, I64}) ->
[<r>C {Str, {}} {I64, I64, I64, I64}, C Str {}, C [C I32, C {}]] ((niche {}))

was found

The following specializations of Task.await were built:await : ({Str, {}},
{I64, I64, I64, I64}) ->
[<r>C {Str, {}} {I64, I64, I64, I64}, C Str {}, C [C I32, C {}]] ((niche {}))

...

The built specialization matches the one that is claim to be missing here (minus some formatting to print).

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 16:23):

maybe the lambda sets are off. the lambda names are missing in those types

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 16:54):

Is this something you think it is worth me digging in and trying to debug or should I just collect this info and file a bug?

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 18:27):

If you have the bandwidth and want to, yeah, absolutely go for it!

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 18:36):

Any base tips for what to dive into? Haven't messed with specialization or lambda sets.

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 18:37):

I would first look into what is actually the difference between the two specializations

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 18:42):

for example here is where the procedure layout is being printed: https://github.com/roc-lang/roc/blob/ab2ec925a3038643d5da5c431d1773d34fc4100c/crates/compiler/mono/src/debug/report.rs#L537-L565

view this post on Zulip Ayaz Hafiz (Sep 19 2023 at 18:46):

you might want to apply a diff like

diff --git a/crates/compiler/mono/src/debug/report.rs b/crates/compiler/mono/src/debug/report.rs
index bca214c26..7a7495c3e 100644
--- a/crates/compiler/mono/src/debug/report.rs
+++ b/crates/compiler/mono/src/debug/report.rs
@@ -550,16 +550,16 @@ where
     let args = f.intersperse(
         arguments
             .iter()
-            .map(|a| interner.to_doc(*a, f, &mut Default::default(), Parens::InFunction)),
+            .map(|a| format!("{:?}", interner.dbg_deep(*a))),
         f.reflow(", "),
     );
     let fun = f.concat([
         f.concat([f.reflow("("), args, f.reflow(")")]),
         f.reflow(" -> "),
-        interner.to_doc_top(result, f),
+        f.text(format!("{:?}", interner.dbg_deep(result))),
     ]);
     let niche = (f.text("("))
-        .append(captures_niche.to_doc(f, interner, &mut Default::default()))
+        .append(format!("{:?}", captures_niche.dbg_deep(interner)))
         .append(f.text(")"));
     f.concat([fun, f.space(), niche])
 }

to print the whole represetntations

view this post on Zulip Brendan Hansknecht (Sep 19 2023 at 19:03):

Wow is that a lot of output. Looks like built version truncates the tree with a recursive pointer, but the wanted version does not have that recursive pointer. Instead it nests much farther before hitting a recursive pointer. So they probably are equal, but something isn't being compressed into recursive pointers correctly.

view this post on Zulip Anton (Sep 23 2023 at 14:04):

I had completely minimized the basic-cli platform from when I hit this error, that may help reduce the output.


Last updated: Jul 05 2025 at 12:14 UTC