-
Notifications
You must be signed in to change notification settings - Fork 36
Show counterexample values in the final expected refinement #299
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
Open
CatarinaGamboa
wants to merge
1
commit into
main
Choose a base branch
from
feat/296-counterexample-witness
base: main
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.
+180
−10
Open
Changes from all commits
Commits
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 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
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
76 changes: 76 additions & 0 deletions
76
liquidjava-verifier/src/test/java/liquidjava/diagnostics/errors/RefinementWitnessTest.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,76 @@ | ||
| package liquidjava.diagnostics.errors; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import liquidjava.diagnostics.TranslationTable; | ||
| import liquidjava.processor.VCImplication; | ||
| import liquidjava.rj_language.Predicate; | ||
| import liquidjava.rj_language.opt.VCSimplificationResult; | ||
| import liquidjava.rj_language.parsing.RefinementsParser; | ||
| import liquidjava.smt.Counterexample; | ||
| import liquidjava.utils.Pair; | ||
| import spoon.Launcher; | ||
| import spoon.reflect.factory.Factory; | ||
|
|
||
| class RefinementWitnessTest { | ||
|
|
||
| private static final Factory FACTORY = new Launcher().getFactory(); | ||
|
|
||
| @Test | ||
| void expandsTheFinalExpectedPredicateBeforeShowingTheWitness() { | ||
| RefinementError error = error("Positive(buffered)", "buffered > 0", List.of("buffered"), | ||
| new Pair<>("buffered", "0")); | ||
|
|
||
| assertEquals("Positive(buffered)", error.getExpected().getExpression().toDisplayString()); | ||
| assertEquals("buffered > 0", error.getFinalExpected().getExpression().toDisplayString()); | ||
| assertEquals("0 > 0", error.getExpectedWithWitness().getExpression().toDisplayString()); | ||
| assertTrue(error.getCounterexampleStr().contains("With witness: 0 > 0 ✗")); | ||
| } | ||
|
|
||
| @Test | ||
| void substitutesEveryAvailableValueAndEveryOccurrence() { | ||
| RefinementError error = error("x < y && x != 0", "x < y && x != 0", List.of("x", "y"), new Pair<>("x", "0"), | ||
| new Pair<>("y", "1")); | ||
|
|
||
| assertEquals("0 < 1 && 0 != 0", error.getExpectedWithWitness().getExpression().toDisplayString()); | ||
| } | ||
|
|
||
| @Test | ||
| void leavesValuesThatAreNotSafeLiteralsUnchanged() { | ||
| RefinementError error = error("x < y", "x < y", List.of("x", "y"), new Pair<>("x", "-1"), | ||
| new Pair<>("y", "other")); | ||
|
|
||
| assertNotNull(error.getExpectedWithWitness()); | ||
| assertEquals("-1 < y", error.getExpectedWithWitness().getExpression().toDisplayString()); | ||
| assertTrue(error.getCounterexampleStr().contains("With witness: -1 < y")); | ||
| } | ||
|
|
||
| @SafeVarargs | ||
| private static RefinementError error(String original, String finalExpression, List<String> binders, | ||
| Pair<String, String>... assignments) { | ||
| VCImplication first = null; | ||
| VCImplication last = null; | ||
| for (String binder : binders) { | ||
| VCImplication current = new VCImplication(binder, FACTORY.Type().INTEGER_PRIMITIVE, new Predicate()); | ||
| if (last != null) | ||
| last.setNext(current); | ||
| if (first == null) | ||
| first = current; | ||
| last = current; | ||
| } | ||
| assertNotNull(first); | ||
| return new RefinementError(null, null, predicate(original), predicate(finalExpression), | ||
| new VCSimplificationResult(first), new TranslationTable(), new Counterexample(List.of(assignments)), | ||
| null); | ||
| } | ||
|
|
||
| private static Predicate predicate(String source) { | ||
| return new Predicate(RefinementsParser.createAST(source, "")); | ||
| } | ||
| } |
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.
💡 Edge Case: Witness parsing only catches SyntaxError; other parse failures escape
substituteWitnessnow runs raw Z3 model values throughRefinementsParser.createAST, but it only catchesSyntaxError. The parser can throw other unchecked exceptions. For example,literalCreatecallsLong.parseLongon anyINTtoken, and a Z3Intmodel value outside the long range (Z3 integers are unbounded) throwsNumberFormatException.NotImplementedExceptionand otherLJErrorsubclasses can also escape. Any of these would escape theRefinementErrorconstructor, so the verifier would crash with a runtime exception instead of reporting the refinement error. The witness is best-effort decoration, so a failure to parse one value should skip it the same way a syntax error does.Treat any parse failure of an SMT value as non-representable:
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎