Repository navigation
Join an if on the instances its condition read #408
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
29 changes: 29 additions & 0 deletions
29
liquidjava-example/src/main/java/testSuite/CorrectNestedIfCallComparison.java
This file contains hidden or 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,29 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.StateRefinement; | ||
| import liquidjava.specification.StateSet; | ||
|
|
||
| @StateSet({"open", "closed"}) | ||
| class CorrectNestedIfDoor { | ||
| @StateRefinement(to = "open(this)") | ||
| public CorrectNestedIfDoor() {} | ||
|
|
||
| @StateRefinement(from = "open(this)", to = "closed(this)") | ||
| public void close() {} | ||
| } | ||
|
|
||
| public class CorrectNestedIfCallComparison { | ||
| static CorrectNestedIfDoor current() { | ||
| return new CorrectNestedIfDoor(); | ||
| } | ||
|
|
||
| static void compareInNestedIf(boolean b) { | ||
| CorrectNestedIfDoor d = new CorrectNestedIfDoor(); | ||
| if (b) { | ||
| if (current() == d) { | ||
| System.out.println("same"); | ||
| } | ||
| } | ||
| d.close(); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
liquidjava-example/src/main/java/testSuite/CorrectRepeatedParameterCondition.java
This file contains hidden or 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,44 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
| import liquidjava.specification.StateRefinement; | ||
| import liquidjava.specification.StateSet; | ||
|
|
||
| @StateSet({"open", "closed"}) | ||
| class RepeatedConditionDoor { | ||
| @StateRefinement(to = "open(this)") | ||
| public RepeatedConditionDoor() {} | ||
|
|
||
| @StateRefinement(from = "open(this)", to = "closed(this)") | ||
| public void close() {} | ||
| } | ||
|
|
||
| public class CorrectRepeatedParameterCondition { | ||
| @Refinement("_ == b") | ||
| static boolean identity(boolean b) { | ||
| if (b == true) { | ||
| return b; | ||
| } | ||
| return b; | ||
| } | ||
|
|
||
| @Refinement("_ == b") | ||
| static boolean returnAfterReassignment(boolean b) { | ||
| if (b) { | ||
| // Exercise the condition snapshot before the reassignment. | ||
| } | ||
| b = false; | ||
| return b; | ||
| } | ||
|
|
||
| static void closeOnce(boolean b) { | ||
| RepeatedConditionDoor d = new RepeatedConditionDoor(); | ||
| if (b == true) { | ||
| d.close(); | ||
| } | ||
| if (b == false) { | ||
| d.close(); | ||
| } | ||
| b = false; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
liquidjava-example/src/main/java/testSuite/ErrorIfReferenceComparison.java
This file contains hidden or 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,41 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.StateRefinement; | ||
| import liquidjava.specification.StateSet; | ||
|
|
||
| @StateSet({"open", "closed"}) | ||
| class ErrorIfReferenceDoor { | ||
| @StateRefinement(to = "open(this)") | ||
| public ErrorIfReferenceDoor() {} | ||
|
|
||
| @StateRefinement(from = "open(this)", to = "closed(this)") | ||
| public void close() {} | ||
| } | ||
|
|
||
| public class ErrorIfReferenceComparison { | ||
| static void closeTwice(ErrorIfReferenceDoor other) { | ||
| ErrorIfReferenceDoor d = new ErrorIfReferenceDoor(); | ||
| if (other == d) { | ||
| d.close(); | ||
| } | ||
| d.close(); // Expect: State Refinement Error | ||
| } | ||
|
|
||
| static void closeTwiceAfterChangingCondition(boolean b) { | ||
| ErrorIfReferenceDoor d = new ErrorIfReferenceDoor(); | ||
| if (b == true) { | ||
| d.close(); | ||
| } | ||
| b = false; | ||
| d.close(); // Expect: State Refinement Error | ||
| } | ||
|
|
||
| static void closeTwiceAfterBareCondition(boolean b) { | ||
| ErrorIfReferenceDoor d = new ErrorIfReferenceDoor(); | ||
| if (b) { | ||
| d.close(); | ||
| } | ||
| b = false; | ||
| d.close(); // Expect: State Refinement Error | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
liquidjava-example/src/main/java/testSuite/ErrorNestedIfCallComparison.java
This file contains hidden or 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,46 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
| import liquidjava.specification.StateRefinement; | ||
| import liquidjava.specification.StateSet; | ||
|
|
||
| @StateSet({"open", "closed"}) | ||
| class ErrorNestedIfDoor { | ||
| @StateRefinement(to = "open(this)") | ||
| public ErrorNestedIfDoor() {} | ||
|
|
||
| @StateRefinement(from = "open(this)", to = "closed(this)") | ||
| public void close() {} | ||
| } | ||
|
|
||
| public class ErrorNestedIfCallComparison { | ||
| static ErrorNestedIfDoor current() { | ||
| return new ErrorNestedIfDoor(); | ||
| } | ||
|
|
||
| @Refinement("_ == 1") | ||
| static int one() { return 1; } | ||
|
|
||
| @Refinement("_ == (n > 0)") | ||
| static boolean positive(int n) { return n > 0; } | ||
|
|
||
| static void closeTwice(boolean b) { | ||
| ErrorNestedIfDoor d = new ErrorNestedIfDoor(); | ||
| if (b) { | ||
| if (current() == d) { | ||
| d.close(); | ||
| } | ||
| } | ||
| d.close(); // Expect: State Refinement Error | ||
| } | ||
|
|
||
| static void closeTwiceWithCallArgument(boolean b) { | ||
| ErrorNestedIfDoor d = new ErrorNestedIfDoor(); | ||
| if (b) { | ||
| if (positive(one() + 1)) { | ||
| d.close(); | ||
| } | ||
| } | ||
| d.close(); // Expect: State Refinement Error | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
This still leaves a soundness gap when a condition reads a variable that has no last instance (for example, a method parameter).
substituteAllVariablesForLastInstanceleavesbas a name, so a later assignment changes the meaning of the already-joined guard:I ran this on the PR head; LiquidJava says
Correct! Passed Verification.The join uses the currentb == true(false), discarding the path wheredwas closed. Could we snapshot condition operands even when they have no existing instance, and add a regression for mutation after theif? This appears to be an existing weakness that the newjoinGuarddoes not cover.