-
Notifications
You must be signed in to change notification settings - Fork 139
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 for #1904 autolifting of data fields #1921
Draft
Fizzixnerd
wants to merge
6
commits into
ucsd-progsys:develop
Choose a base branch
from
Fizzixnerd:1904-autolifted-data-fields
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f2076b
Fix for #1904 autolifting of data fields
Fizzixnerd 8aaceac
Add negative test for #1904
Fizzixnerd 943cc45
More tests for #1904
Fizzixnerd d737a26
Simplify AutoliftedFields02.hs
Fizzixnerd 3500cd9
working on fix for #1904 decls having wrong inferred LH type
Fizzixnerd 8a84fd2
Remove bad test from other branch
Fizzixnerd 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{-@ LIQUID "--exact-data-cons" @-} | ||
|
||
-- data decl in LH is missing and uses a LH-refined type alias incorrectly | ||
|
||
module AutoliftedFields00 where | ||
|
||
{-@ type Nat = { v : Int | v >= 0 } @-} | ||
type Nat = Int | ||
|
||
data T = T { getT :: Nat } | ||
|
||
{-@ f :: T -> { v : Int | v < 0 } @-} | ||
f :: T -> Nat | ||
f (T x) = x | ||
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,15 @@ | ||
{-@ LIQUID "--exact-data-cons" @-} | ||
|
||
-- data decl in LH and Haskell do not match and the LH one is not a subtype | ||
|
||
module AutoliftedFields01 where | ||
|
||
{-@ type Nat = { v : Int | v >= 0 } @-} | ||
type Nat = Int | ||
|
||
{-@ data T = T { getT :: Float } @-} | ||
data T = T { getT :: Nat } | ||
|
||
{-@ f :: { t : T | getT t >= 1 } -> Nat @-} | ||
f :: T -> Nat | ||
f (T x) = x |
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 @@ | ||
{-@ LIQUID "--exact-data-cons" @-} | ||
|
||
-- data decl in LH is missing but uses a LH-refined type alias correctly | ||
|
||
module AutoliftedFields00 where | ||
|
||
{-@ type Nat = { v : Int | v >= 0 } @-} | ||
type Nat = Int | ||
|
||
data T = T { getT :: Nat } | ||
|
||
{-@ f :: T -> Nat @-} | ||
f :: T -> Nat | ||
f (T x) = x |
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,16 @@ | ||
{-@ LIQUID "--exact-data-cons" @-} | ||
|
||
-- data decl in LH and Haskell give different names to the fields, but use them | ||
-- in valid ways. | ||
|
||
module AutoliftedFields01 where | ||
|
||
{-@ type Nat = { v : Int | v >= 0 } @-} | ||
type Nat = Int | ||
|
||
{-@ data T = T { getMyT :: Nat } @-} | ||
data T = T { getT :: Nat } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have expected naming a field differently in the specification to be an error. Shouldn't it fail? |
||
|
||
{-@ f :: { t : T | getT t == getMyT t } -> Nat @-} | ||
f :: T -> Nat | ||
f (T x) = x |
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,15 @@ | ||
{-@ LIQUID "--exact-data-cons" @-} | ||
|
||
-- data decl in LH and Haskell do not match but the LH is a subtype | ||
|
||
module AutoliftedFields02 where | ||
|
||
{-@ type Nat = { v : Int | v >= 0 } @-} | ||
type Nat = Int | ||
|
||
{-@ data T = T { getT :: Nat } @-} | ||
data T = T { getT :: Int } | ||
|
||
{-@ f :: T -> Nat @-} | ||
f :: T -> Nat | ||
f (T x) = x |
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.
If
x
is aNat
, as the type ofgetT
says, shouldn't this function be accepted by LH?If I try the following program, supposedly equivalent to this test, LH accepts it.
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 can confirm your program is accepted while the one I wrote is not... though I'm not sure why!
I do not understand fully why the one with the explicit data decl is accepted. My understanding is that if
getT :: Nat
andgetT t <= 0
then the only available value for the function to return is whenx == 0
. I suppose that subtypesNat
, and that's why it's accepted, since there is no "true" (in the HM sense) refinement type for anything?Then it must be that
Nat
is being used asInt
in the no decl case... No, I still don't understand. Since,getT t <= 0
would implyx <= 0
which subtypesInt
, just like in the above case! I will investigate further.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 understand it this way. LH needs to prove that
f
returns aNat
, since that is what the specification says. There are two hypothesis to accomplish thisx
is aNat
becauset = T x
(inferred from the pattern matching), andT :: Nat -> T
.x = getT t && getT t <= 0
So LH completes the proof using hypothesis (1).
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 can confirm that the reason is that the fields are being inferred to have (refinement) type
GHC.Types.Int
instead ofAutoliftedFields00.Nat
. With the specification, the type is correctlyNat
. @nikivazou, do you happen to have an idea of why this would be? I'm vaguely aware of expansion being done using theExpand
typeclass, and I suspect it's being done too early on for fields/data decls, so that the alias is being expanded before LH has a chance to see it and know that it should use the corresponding LH alias. However, the details are much more complicated than what I've been able to figure out myself. For example, I don't know when the type for the field is first grabbed from GHC; if you knew this or could point me in the right direction it would be greatly appreciated!