Stream: contributing

Topic: when alias bug


view this post on Zulip Brendan Hansknecht (Mar 21 2023 at 23:48):

does #5174 look like something that won't take too much digging to fix? I am willing to work on and fix it because having this fixed will make a program I am working on a lot nicer to write. That said, if this would be better left to someone more familiar with that area of code, I can just wait.

view this post on Zulip Ayaz Hafiz (Mar 22 2023 at 04:52):

Folkert probably knows best but looking at it, I dont think it would be to difficult. This kind of thing happens every so often and usually takes me <1hr

view this post on Zulip Folkert de Vries (Mar 22 2023 at 18:44):

yes should be relatively easy. I'd start by looking at the mono IR that is generated

view this post on Zulip Folkert de Vries (Mar 22 2023 at 18:44):

the problem is usually the mono IR, it's not an alias analysis bug

view this post on Zulip Brendan Hansknecht (Mar 22 2023 at 18:53):

Quick IR question: is it valid to repeat an identifier in different branches in the mono ir:

if `#UserApp.32` then
  let `#UserApp.9` : I64 = 3i64;
else
  let `#UserApp.9` : I64 = 3i64;

Or should those be unique?

view this post on Zulip Folkert de Vries (Mar 22 2023 at 18:56):

it happens a log today, so I don't think we make assumptions about it not happening

view this post on Zulip Folkert de Vries (Mar 22 2023 at 18:56):

e.g. this is in our mono tests

        switch Test.31:
            case 0:
                let Test.25 : Str = CallByName Test.9 Test.23;
                jump Test.24 Test.25;

            default:
                let Test.25 : Str = CallByName Test.11 Test.23;
                jump Test.24 Test.25;

view this post on Zulip Brendan Hansknecht (Mar 22 2023 at 18:58):

:thumbs_up:

view this post on Zulip Brendan Hansknecht (Mar 22 2023 at 19:34):

The issue seems to be caused by this line being repeated in both branches of an if/else:

let `#UserApp.8` : Int1 = CallByName `Num.isLt` `#UserApp.x` `#UserApp.9`;

Given it has the exact same arg names and function, I think they are getting the same specialization id.

view this post on Zulip Brendan Hansknecht (Mar 22 2023 at 19:38):

Though that doesn't exactly explain the bug to me. What is wrong with two calls having the same CalleeSpecVar? Does that just mean that both functions use the same specialized version of a function? I assume I don't quite understand what the CalleeSpecVar means.

view this post on Zulip Ayaz Hafiz (Mar 22 2023 at 21:00):

multiple calls might end up resolving to the same specialization, but I believe each call must be annotated with a unique variable because morphic might or might not assign them unique specializations

view this post on Zulip Ayaz Hafiz (Mar 22 2023 at 21:00):

by the way, ROC_CHECK_MONO_IR=1 should catch this if that is indeed the problem

view this post on Zulip Ayaz Hafiz (Mar 22 2023 at 21:00):

because we should create a unique CallSpecId in mono

view this post on Zulip Ayaz Hafiz (Mar 22 2023 at 21:00):

for each call

view this post on Zulip Brendan Hansknecht (Mar 22 2023 at 21:32):

yeah, it finds issues:

IR PROBLEMS FOUND:
── DUPLICATE JOIN POINT ────────────────────────────────────────────────────────

in main : () -> {Str, {}} ((niche {}))

18│              let `#UserApp.x` : I64 = lowlevel ListGetUnsafe `#UserApp.data` `#UserApp.15`;
19│>             joinpoint `#UserApp.7` `#UserApp.14`:
20│                  if `#UserApp.14` then

The join point #UserApp.7 was previously defined here

48│          let `#UserApp.28` : U64 = 1i64;
49│>         let `#UserApp.29` : Int1 = lowlevel NumGte `#UserApp.27` `#UserApp.28`;
50│          if `#UserApp.29` then

and is redefined here
── DUPLICATE CALL SPEC ID ──────────────────────────────────────────────────────

in main : () -> {Str, {}} ((niche {}))

24│              in
25│>             let `#UserApp.9` : I64 = 3i64;
26│              let `#UserApp.8` : Int1 = CallByName `Num.isLt` `#UserApp.x` `#UserApp.9`;

This call has a specialization ID

54│                  if `#UserApp.25` then
55│>                     jump `#UserApp.12`;
56│                  else

...that is the same as the specialization ID of the call here

Last updated: Jul 05 2025 at 12:14 UTC