-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a proof-by-contradiction attribute (#5001)
### Description Allows a particular assertion to be marked as an intentional proof by contradiction, preventing `--warn-contradictory-assumptions` from flagging it. Fixes #4778 ### How has this been tested? `Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4778.dfy` By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
- Loading branch information
Showing
11 changed files
with
83 additions
and
20 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
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
39 changes: 39 additions & 0 deletions
39
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4778.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,39 @@ | ||
// RUN: %verify --warn-contradictory-assumptions "%s" > "%t" | ||
// DIFF: "%s.expect" "%t" | ||
|
||
type CodeUnit | ||
type CodeUnitSeq = seq<CodeUnit> | ||
type MinimalWellFormedCodeUnitSeq = s: CodeUnitSeq | ||
| IsMinimalWellFormedCodeUnitSubsequence(s) | ||
witness * | ||
|
||
function IsMinimalWellFormedCodeUnitSubsequence(s: CodeUnitSeq): (b: bool) | ||
ensures b ==> | ||
&& |s| > 0 | ||
&& forall i | 0 < i < |s| :: !IsMinimalWellFormedCodeUnitSubsequence(s[..i]) | ||
decreases |s| | ||
|
||
/** | ||
* If minimal well-formed code unique subsequences `m1` and `m2` are prefixes of `s`, then they are equal. | ||
*/ | ||
lemma LemmaUniquePrefixMinimalWellFormedCodeUnitSeq( | ||
s: CodeUnitSeq, m1: MinimalWellFormedCodeUnitSeq, m2: MinimalWellFormedCodeUnitSeq | ||
) | ||
decreases |s|, |m1|, |m2| | ||
requires m1 <= s | ||
requires m2 <= s | ||
ensures m1 == m2 | ||
{ | ||
// Handle only the |m1| <= |m2| case explicitly | ||
if |m1| > |m2| { | ||
LemmaUniquePrefixMinimalWellFormedCodeUnitSeq(s, m2, m1); | ||
} else { | ||
assert m1 <= m2; | ||
assert m1 == m2 by { | ||
var m2' := m2[..|m1|]; | ||
if m1 < m2 { | ||
assert {:contradiction} m1 == m2'; | ||
} | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
Source/IntegrationTests/TestFiles/LitTests/LitTest/git-issues/git-issue-4778.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,2 @@ | ||
|
||
Dafny program verifier finished with 2 verified, 0 errors |
8 changes: 4 additions & 4 deletions
8
Source/IntegrationTests/TestFiles/LitTests/LitTest/logger/ProofDependencyWarnings.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
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 @@ | ||
The new `{:contradiction}` attribute can be placed on an `assert` statement to indicate that it forms part of an intentional proof by contradiction and therefore shouldn't be warned about when `--warn-contradictory-assumptions` is turned on. |