-
Notifications
You must be signed in to change notification settings - Fork 380
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
[ new ] totality checking can look under constructors #3362
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
21d5ef7
[ new ] totality checking can look under constructors (#3328)
dunhamsteve 572cb98
[ fix ] Add fuel to totality checking under constructors
dunhamsteve 1caa7cf
[ test ] addition tests for totality checking
dunhamsteve d32deff
Merge branch 'main' into totality2
dunhamsteve 4c5e079
[ fix ] compare arguments on type constructors
dunhamsteve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,5 @@ | ||
total | ||
f : (a, List a) -> () | ||
f (_, []) = () | ||
f (x, _::xs) = f (x, xs) | ||
|
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,12 @@ | ||
import Data.Fin | ||
|
||
covering | ||
g : Fin 64 -> Unit | ||
g FZ = () | ||
g (FS i') = g $ weaken i' | ||
|
||
total | ||
g' : Fin 64 -> Unit | ||
g' FZ = () | ||
g' i@(FS i') = g' $ assert_smaller i $ weaken i' | ||
|
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,14 @@ | ||
%default total | ||
|
||
%totality_depth 1 | ||
|
||
failing "not total" | ||
one : List a -> Nat | ||
one (a :: b :: c :: es) = one (a :: b :: es) | ||
one _ = 0 | ||
|
||
%totality_depth 3 | ||
|
||
two : List a -> Nat | ||
two (a :: b :: c :: es) = two (a :: b :: es) | ||
two _ = 0 |
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,50 @@ | ||
%default total | ||
|
||
-- This one needed withHoles on tcOnly (instead of withArgHoles) | ||
-- or the solved implicit for the (ty : Type) on Maybe would not be | ||
-- substituted. | ||
length : Maybe (List a) -> Nat | ||
length Nothing = 0 | ||
length (Just []) = 0 | ||
length (Just (x :: xs)) = 1 + length (Just xs) | ||
|
||
one : List a -> Nat | ||
one (x :: y :: zs) = one (x :: zs) | ||
one _ = 0 | ||
|
||
two : List a -> Nat | ||
two (a :: b :: c :: d :: es) = two (a :: c :: es) | ||
two _ = 0 | ||
|
||
three : List a -> Nat | ||
three (a :: b :: c :: d :: es) = three (b :: c :: es) | ||
three _ = 0 | ||
|
||
failing "not total" | ||
four : List Nat -> Nat | ||
four (a :: b :: c :: es) = four (b :: c :: a :: es) | ||
four _ = 0 | ||
|
||
-- also needs withHoles | ||
five : (List a, List a) -> List a | ||
five (a :: as, bs) = a :: five (as, bs) | ||
five ([], _) = [] | ||
|
||
-- This is total, but not supported | ||
failing "not total" | ||
six : (List a, List a) -> List a | ||
six (a :: as, bs) = a :: six (bs, as) | ||
six ([], _) = [] | ||
|
||
|
||
failing "not total" | ||
-- If we didn't check all of the arguments of MkTuple for | ||
-- Same/Smaller, then this would be incorrectly accepted as total | ||
first : (List Nat, List Nat) -> Nat | ||
second : (List Nat, List Nat) -> Nat | ||
|
||
first (x :: xs, ys) = second (xs, Z :: ys) | ||
first _ = Z | ||
|
||
second (xs, y :: ys) = first (1 :: xs, ys) | ||
second _ = Z |
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,4 @@ | ||
1/1: Building Issue3317 (Issue3317.idr) | ||
1/1: Building Totality (Totality.idr) | ||
1/1: Building Issue3353 (Issue3353.idr) | ||
1/1: Building Pragma (Pragma.idr) |
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,6 @@ | ||
. ../../../testutils.sh | ||
|
||
idris2 --check Issue3317.idr | ||
idris2 --check Totality.idr | ||
idris2 --check Issue3353.idr | ||
idris2 --check Pragma.idr |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me whether it is sound to make applied type constructor of the same name size-equal regardless of their arguments. But I did not manage to come up with a counter-example (assuming a putative Idris with universe levels/universe polymorphism).
Do you have an intuition why this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at the time I was considering them irrelevant. I'm asking for things to be the same or smaller when we go under a constructor, and that was my way of ignoring the implicit type arguments.
I think we would have been ok here for now because we don't look under
TyCon
to determine something is smaller. So if the type got bigger it could still never cause the function to be counted as total.I've changed it to check the arguments, expecting everything to be the
Same
orSmaller
. It's still contributingSame
at best. So, like the status quo, pulling something out from under aTyCon
doesn't count asSmaller
.