Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal compiler error: unknown variable #2106

Closed
nqpz opened this issue Feb 10, 2024 · 1 comment
Closed

Internal compiler error: unknown variable #2106

nqpz opened this issue Feb 10, 2024 · 1 comment
Assignees

Comments

@nqpz
Copy link
Member

nqpz commented Feb 10, 2024

The program

def f'' 'a (n: i64) (f: a -> i64) (a: a): [n]i64 = replicate n (f a)

def f (s: {n: i64}): [s.n]i64 =
  let f' 'a (f: a -> i64) (a: a): [s.n]i64 = f'' s.n f a
  in f' id 0

entry main (n: i64) = f {n}

compiled with futhark c from git produces this error:

BuilderT.lookupType: unknown variable d<{s.n}>_5121
Known variables: 
f_4499 a_4500 map_5123

CallStack (from HasCallStack):
  error, called at src/Futhark/Builder.hs:104:9 in futhark-0.26.0-inplace:Futhark.Builder
@athas
Copy link
Member

athas commented Feb 10, 2024

Monomorphisation is probably to blame, as it produces a function with this form:

def f ((s: {n: i64})) : ?[d<{s.n}>].[d<{s.n}>]i64 =
  let (d<{s.n}>: i64) = s.n
  let f' ((f: i64 -> i64)) ((a: i64)): ?[d<{s.n}>].[d<{s.n}>]i64 =
    f'' d<{s.n}> f a
  in f' id 0

Note how d<{s.n}> is shadowed in the return type of f. That probably confuses defunctionalisation, which ultimately produces something bad.

@athas athas self-assigned this Feb 10, 2024
athas added a commit that referenced this issue Feb 10, 2024
This looks a lot more complicated than it ought to. The real bug was a
mishandling of local polymorphic functions in monomorphisation. I
reasoned that there is no reason monomorphisation should ever
encounter those - we should lambda lift those before we monomorphise.
However, that created the need for a bunch of other modifications,
including a new (very small) pass (ApplyTypeAbbrs) that runs just
after defunctorisation.

IT is overall a conceptual simplification, but the code changes look
quite large for such a small bug.
@athas athas closed this as completed in 456a65c Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants