-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
PackMutual
: Eta-Expand as needed
The `packMutual` code ought to reliably replace all recursive calls to the functions in `preDefs`, even when they are under- or over-applied. Therefore eta-expand if need rsp. keep extra arguments around. Needs a tweak to `Meta.transform` to avoid mistaking the `f` in `f x1 x2` as a zero-arity application. Includes a test case. This fixes #2628 and #2883.
- Loading branch information
Showing
4 changed files
with
119 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/-! | ||
Test that PackMutual isn't confused when a recursive call has more arguments than is packed | ||
into the unary argument, which can happen if the retturn type is a function type. | ||
-/ | ||
|
||
namespace Ex1 | ||
mutual | ||
def foo : Nat → Nat | ||
| .zero => 0 | ||
| .succ n => (id bar) n | ||
def bar : Nat → Nat | ||
| .zero => 0 | ||
| .succ n => foo n | ||
end | ||
termination_by foo n => n; bar n => n | ||
decreasing_by sorry | ||
|
||
end Ex1 | ||
|
||
-- Same for n-ary functions | ||
|
||
opaque id' : ∀ {α}, α → α := id | ||
|
||
namespace Ex2 | ||
|
||
mutual | ||
def foo : Nat → Nat → Nat | ||
| .zero, _m => 0 | ||
| .succ n, .zero => (id' (bar n)) .zero | ||
| .succ n, m => (id' bar) n m | ||
def bar : Nat → Nat → Nat | ||
| .zero, _m => 0 | ||
| .succ n, m => foo n m | ||
end | ||
termination_by foo n m => (n,m); bar n m => (n,m) | ||
decreasing_by sorry | ||
|
||
end Ex2 | ||
|
||
-- With extra arguments | ||
|
||
namespace Ex3 | ||
mutual | ||
def foo : Nat → Nat → Nat | ||
| .zero => fun _ => 0 | ||
| .succ n => fun m => (id bar) n m | ||
def bar : Nat → Nat → Nat | ||
| .zero => fun _ => 0 | ||
| .succ n => fun m => foo n m | ||
end | ||
termination_by foo n => n; bar n => n | ||
decreasing_by sorry | ||
|
||
end Ex3 | ||
|
||
-- n-ary and with extra arguments | ||
|
||
namespace Ex4 | ||
|
||
mutual | ||
def foo : Nat → Nat → Nat → Nat | ||
| .zero, _m => fun _ => 0 | ||
| .succ n, .zero => fun k => (id' (bar n)) .zero k | ||
| .succ n, m => fun k => (id' bar) n m k | ||
def bar : Nat → Nat → Nat → Nat | ||
| .zero, _m => fun _ => 0 | ||
| .succ n, m => fun k => foo n m k | ||
end | ||
termination_by foo n m => (n,m); bar n m => (n,m) | ||
decreasing_by sorry | ||
|
||
end Ex4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters