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

Detect termination for nested local definitions #3169

Merged
merged 7 commits into from
Nov 15, 2024
Merged

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Nov 13, 2024

When we call a function that is currently being defined (there may be several such due to nested local definitions), we add a reflexive edge in the call map instead of adding an edge from the most nested definition. For example, for

go {A B} (f : A -> B) : List A -> List B
  | nil := nil
  | (elem :: next) :=
    let var1 := f elem;
        var2 := go f next;
    in var1 :: var2;

we add an edge from go to the recursive call go f next, instead of adding an edge from var2 to go f next as before.

This makes the above type-check.

The following still doesn't type-check, because next' is not a subpattern of the clause pattern of go. But this is a less pressing problem.

go {A B} (f : A -> B) : List A -> List B
  | nil := nil
  | (elem :: next) :=
    let var1 := f elem;
        var2 (next' : List A) : List B := go f next';
    in myCons var1 (var2 next);

@lukaszcz lukaszcz added this to the 0.6.9 milestone Nov 13, 2024
@lukaszcz lukaszcz self-assigned this Nov 13, 2024
janmasrovira
janmasrovira previously approved these changes Nov 14, 2024
@lukaszcz lukaszcz force-pushed the fix-let-termination branch from fd425cf to b63c0f0 Compare November 15, 2024 09:28
@lukaszcz lukaszcz merged commit 9f25ffd into main Nov 15, 2024
4 checks passed
@lukaszcz lukaszcz deleted the fix-let-termination branch November 15, 2024 11:30
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.

Termination checking doesn't work with local lets
2 participants