-
Notifications
You must be signed in to change notification settings - Fork 260
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: Use reveal_ constant as function argument in override axiom #5111
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7f0e62a
fix: Use reveal_ constant as function argument in override axiom
RustanLeino f5b6ab9
Add resolution checks
RustanLeino 59a03d0
Add axiom to correlate reveal_ constants for overrides
RustanLeino 589fd80
Add release notes
RustanLeino c28c072
Merge branch 'master' into issue-5017
RustanLeino f2f69c3
Merge branch 'master' into issue-5017
RustanLeino 0c38b12
Fix exit-code expectation
RustanLeino 09f6818
Merge branch 'master' into issue-5017
RustanLeino b9916ea
Introduce const for “reveal_”
RustanLeino 248dec2
Use keyword itself rather than keyword-is-present
RustanLeino 8a4b908
Extract method ReportMemberNotFoundError
RustanLeino de1690f
Add resolutionContext parameter
RustanLeino 16a2e95
chore: Improve code formatting
RustanLeino 563d9a8
Improve error messages for reveal
RustanLeino e6b6169
Further improve error messages
RustanLeino 8c0b2ae
Merge branch 'master' into issue-5017
RustanLeino 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
23 changes: 0 additions & 23 deletions
23
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017.dfy
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017.dfy.expect
This file was deleted.
Oops, something went wrong.
138 changes: 138 additions & 0 deletions
138
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017a.dfy
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,138 @@ | ||
// RUN: %testDafnyForEachResolver --expect-exit-code=4 "%s" -- --general-traits=datatype | ||
|
||
module True { | ||
trait A { | ||
ghost predicate Valid() | ||
} | ||
|
||
trait B extends A { | ||
ghost opaque predicate Valid() { true } | ||
} | ||
|
||
method TestByRequires(b: B) | ||
requires b.Valid() | ||
{ | ||
var a: A := b; | ||
assert a.Valid(); | ||
} | ||
|
||
method TestByReveal(b: B) { | ||
var a: A := b; | ||
assert a.Valid() by { | ||
reveal b.Valid(); | ||
} | ||
} | ||
} | ||
|
||
module X { | ||
trait A { | ||
ghost predicate Valid(w: bool) | ||
} | ||
|
||
trait B extends A { | ||
ghost opaque predicate Valid(x: bool) { x } | ||
} | ||
|
||
method TestByRequires(b: B, y: bool) | ||
requires b.Valid(y) | ||
{ | ||
var a: A := b; | ||
assert a.Valid(y); | ||
} | ||
|
||
method TestByReveal(b: B, y: bool) { | ||
var a: A := b; | ||
assert a.Valid(y) by { // error: assertion violation | ||
reveal b.Valid(); | ||
} | ||
} | ||
} | ||
|
||
module Parameters { | ||
trait A { | ||
ghost predicate P<T>(t: T) | ||
} | ||
|
||
trait B extends A { | ||
ghost opaque predicate P<T>(t: T) { t == t } | ||
} | ||
|
||
|
||
method TestByRequires(b: B) | ||
requires b.P(5) | ||
{ | ||
var a: A := b; | ||
assert a.P(5); | ||
} | ||
|
||
method TestByRequires'(b: B) | ||
requires b.P(6) | ||
{ | ||
var a: A := b; | ||
assert a.P(5); // error: assertion violation | ||
} | ||
|
||
method TestByRequires''(b: B) | ||
requires b.P(true) | ||
{ | ||
var a: A := b; | ||
assert a.P(5); // error: assertion violation | ||
} | ||
|
||
|
||
method TestByReveal(b: B) { | ||
var a: A := b; | ||
assert a.P(5) by { | ||
reveal b.P(); | ||
} | ||
} | ||
|
||
method TestByReveal'(b: B) { | ||
var a: A := b; | ||
assert a.P(true) by { | ||
reveal b.P(); | ||
} | ||
} | ||
} | ||
|
||
module StayOpaque { | ||
trait A { | ||
opaque predicate Valid() | ||
} | ||
|
||
trait B extends A { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
trait C extends A { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
method TestByRequires(b: B) | ||
requires b.Valid() | ||
{ | ||
var a: A := b; | ||
assert a.Valid(); | ||
} | ||
|
||
method TestByReveal(b: B) { | ||
var a: A := b; | ||
assert a.Valid() by { | ||
reveal b.Valid(); | ||
} | ||
} | ||
|
||
method TestIndependence0(b: B, c: C) { | ||
var a: A := b; | ||
assert b.Valid() by { // error: revealing for C should not affect B | ||
reveal c.Valid(); | ||
} | ||
} | ||
|
||
method TestIndependence1(b: B, c: C) { | ||
var a: A := b; | ||
assert a.Valid() by { // fine: revealing for C also reveals for all A's | ||
reveal c.Valid(); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017a.dfy.expect
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 @@ | ||
git-issue-5017a.dfy(45,18): Error: assertion might not hold | ||
git-issue-5017a.dfy(72,14): Error: assertion might not hold | ||
git-issue-5017a.dfy(79,14): Error: assertion might not hold | ||
git-issue-5017a.dfy(127,18): Error: assertion might not hold | ||
|
||
Dafny program verifier finished with 14 verified, 4 errors |
104 changes: 104 additions & 0 deletions
104
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017b.dfy
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,104 @@ | ||
// RUN: %testDafnyForEachResolver --expect-exit-code=2 "%s" -- --general-traits=datatype | ||
|
||
module Opaque { | ||
trait A { | ||
predicate Valid() | ||
} | ||
|
||
trait B { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
trait C { | ||
opaque predicate Valid() | ||
} | ||
|
||
|
||
trait K0 extends A { | ||
predicate Valid() | ||
} | ||
trait K1 extends A { | ||
opaque predicate Valid() | ||
} | ||
trait K2 extends A { | ||
predicate Valid() { true } | ||
} | ||
trait K3 extends A { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
trait L0 extends B { | ||
predicate Valid() { true } // error: B.Valid already has a body | ||
} | ||
trait L1 extends B { | ||
opaque predicate Valid() { true } // error: B.Valid already has a body | ||
} | ||
|
||
trait M0 extends C { | ||
predicate Valid() // error: must be opaque (since it is in C) | ||
} | ||
trait M1 extends C { | ||
opaque predicate Valid() | ||
} | ||
trait M2 extends C { | ||
predicate Valid() { true } // error: must be opaque (since it is in C) | ||
} | ||
trait M3 extends C { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
|
||
datatype W0 extends A = W0 { | ||
predicate Valid() { true } | ||
} | ||
class W1 extends A { | ||
predicate Valid() { true } | ||
} | ||
|
||
datatype X0 extends A = X0 { | ||
opaque predicate Valid() { true } | ||
} | ||
class X1 extends A { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
datatype Y0 extends C = Y0 { | ||
predicate Valid() { true } // error: must be opaque (since it is in C) | ||
} | ||
class Y1 extends C { | ||
predicate Valid() { true } // error: must be opaque (since it is in C) | ||
} | ||
|
||
datatype Z0 extends C = Z0 { | ||
opaque predicate Valid() { true } | ||
} | ||
class Z1 extends C { | ||
opaque predicate Valid() { true } | ||
} | ||
} | ||
|
||
module StayOpaque { | ||
trait A { | ||
opaque predicate Valid() | ||
} | ||
|
||
datatype B extends A = B { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
class C extends A { | ||
opaque predicate Valid() { true } | ||
} | ||
|
||
method TestA(a: A) { | ||
reveal a.Valid(); // error: nothing to reveal | ||
} | ||
|
||
method TestB(b: B) { | ||
reveal b.Valid(); | ||
} | ||
|
||
method TestC(c: C) { | ||
reveal c.Valid(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-5017b.dfy.expect
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,10 @@ | ||
git-issue-5017b.dfy(31,14): Error: fully defined predicate 'Valid' is inherited from trait 'B' and is not allowed to be re-declared | ||
git-issue-5017b.dfy(34,21): Error: fully defined predicate 'Valid' is inherited from trait 'B' and is not allowed to be re-declared | ||
git-issue-5017b.dfy(34,21): Error: static lemma 'reveal_Valid' is inherited from trait 'B' and is not allowed to be re-declared | ||
git-issue-5017b.dfy(38,14): Error: overridden predicate 'Valid' in 'M0' must be 'opaque' since the member is 'opaque' in trait 'C' | ||
git-issue-5017b.dfy(44,14): Error: overridden predicate 'Valid' in 'M2' must be 'opaque' since the member is 'opaque' in trait 'C' | ||
git-issue-5017b.dfy(66,14): Error: overridden predicate 'Valid' in 'Y0' must be 'opaque' since the member is 'opaque' in trait 'C' | ||
git-issue-5017b.dfy(69,14): Error: overridden predicate 'Valid' in 'Y1' must be 'opaque' since the member is 'opaque' in trait 'C' | ||
git-issue-5017b.dfy(94,13): Error: member 'reveal_Valid' does not exist in trait 'A' | ||
git-issue-5017b.dfy(94,18): Error: expression has no reveal lemma | ||
9 resolution/type errors detected in git-issue-5017b.dfy |
Oops, something went wrong.
Oops, something went wrong.
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.
I worried a bit about this issue. It seems that, to resolver it, one would need to implement this member, but the resolution is to actually. make
Valid
opaque in A. Could you detect that particular case and emit a more useful error message?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.
Excellent idea. I improved many messages. However, it became more difficult for some of them. The problem is that, early on during resolution, we change
reveal X();
expressions intoreveal_X();
lemma calls. By the time that these attempted lemma calls go through the resolver, the name looked up isreveal_X
. To improve the error message, we then have to detect that we're in a reveal-statement context and that the thing we're trying to look up has a name that starts with "reveal_
" (which is not actually guaranteed to be one of the rewritten calls, since this could have been a user-defined name in the first place), and then remove the "reveal_
" prefix, try to find what the nameX
might have referred to, and finally reconstruct the reason why noreveal_X
lemma was created in the first place. It would have been much better not to have done thereveal_X
-lemma surgery so early in the pipeline. Then, the symbol we'd be looking at during resolution would beX
. (Btw, I've seen this mistake many times--a change is made too early in the resolution pipeline, because it seems as if that's a quick way to get a new feature into the language, but then this bites later on.)Anyhow, I feel okay with the error messages I did improve. At some point in the future, I expect that we'll revisit
reveal
statements to expand their role. That would be a good time to handlereveal
in a way that's less hacky than today'sreveal_
-lemmas.