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

Fix de Bruijn indices in LetRecs #2227

Merged
merged 3 commits into from
Jun 26, 2023
Merged

Fix de Bruijn indices in LetRecs #2227

merged 3 commits into from
Jun 26, 2023

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Jun 26, 2023

For the program

module letrec;

import Stdlib.Prelude open;

myfun : {A : Type} -> (A -> A) -> A -> A;
myfun {A} f a :=
      let
        go : Nat -> A -> A;
        go' : Nat -> A -> A;

        go zero a := a;
        go (suc n) a := f (go' n a);

        go' zero a := a;
        go' (suc n) a := f (go n a);
      in
      go 5 a;

main : Nat;
main := myfun ((+) 1) 7;

after translating to Core and lambda-lifting we got the incorrect indices in types of the let-bindings.

def myfun : Π A : Type, (A$0 → A$1) → A$1 → A$2 :=
  λ(A : Type)
    λ(f : A$0 → A$1)
      λ(a : A$1)
        let go' : Int → a$1 → a$2 := go'_9 A$2 f$1 in
        let go : Int → a$2 → a$3 := go_10 A$3 f$2 in
        go$0 5 a$2;

The indices have been corrected in this PR.

@lukaszcz lukaszcz added this to the 0.4.2 milestone Jun 26, 2023
@lukaszcz lukaszcz self-assigned this Jun 26, 2023
Copy link
Collaborator

@janmasrovira janmasrovira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test that has been fixed by this?

@lukaszcz
Copy link
Collaborator Author

Is it possible to add a test that has been fixed by this?

It's really hard because I can't produce an example that actually makes things crash with the old code, because currently the indices in types are mostly ignored.

@lukaszcz
Copy link
Collaborator Author

Is it possible to add a test that has been fixed by this?

It's really hard because I can't produce an example that actually makes things crash with the old code, because currently the indices in types are mostly ignored.

Any test looking at the output instead would be very unstable, and I don't think we should add it.

@janmasrovira
Copy link
Collaborator

Is it possible to add a test that has been fixed by this?

It's really hard because I can't produce an example that actually makes things crash with the old code, because currently the indices in types are mostly ignored.

That's fine, then please, paste the output (before and after the fix) here as a comment

@lukaszcz lukaszcz merged commit 82a86ac into main Jun 26, 2023
@lukaszcz lukaszcz deleted the bug-letrec-indices branch June 26, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The de Bruijn indices in the types in LetRecs are all messed up
2 participants