-
Notifications
You must be signed in to change notification settings - Fork 35
Add -a/--all flag to show all SMT verification conditions #243
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
Draft
CatarinaGamboa
wants to merge
2
commits into
main
Choose a base branch
from
worktree-issue-240
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.
Draft
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,62 @@ public static boolean enabled() { | |
| return CommandLineLauncher.cmdArgs.debugMode; | ||
| } | ||
|
|
||
| /** | ||
| * Gate for the SMT-query trace (verification conditions fed to Z3 and their outcomes). Enabled by either | ||
| * {@code --debug} / {@code -d} or the lighter {@code --all} / {@code -a}, which shows every query without the rest | ||
| * of the debug output (e.g. simplification passes). | ||
| */ | ||
| public static boolean smtEnabled() { | ||
|
Collaborator
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. Maybe rename to |
||
| return CommandLineLauncher.cmdArgs.debugMode || CommandLineLauncher.cmdArgs.showAllVCs; | ||
| } | ||
|
|
||
| /** | ||
| * Set by {@link #smtStart} (the structured / flat VC printers) and consumed by {@link #smtRawQuery}. Lets the | ||
| * low-level Z3 boundary trace skip a query that a higher layer already printed in full, so {@code -a} shows every | ||
| * query exactly once. Single-threaded: each {@code smtStart} is immediately followed by one {@code solver.check()}. | ||
| * Callers that may abort a structured check before {@code solver.check()} (e.g. a translation failure) must clear | ||
| * the flag via {@link #clearStructuredQueryPending} so suppression cannot leak onto the next, unrelated query. | ||
| */ | ||
| private static boolean structuredQueryPending = false; | ||
|
|
||
| public static void clearStructuredQueryPending() { | ||
| structuredQueryPending = false; | ||
| } | ||
|
|
||
| /** | ||
| * Catch-all trace emitted at the actual {@code solver.check()} boundary so {@code -a} / {@code -d} show EVERY query | ||
| * sent to Z3 — including those that bypass the structured {@link #smtStart} path (the simplifier's implication | ||
| * checks, refinement satisfiability checks, speculative typestate checks). Suppressed for queries a structured | ||
| * print already covered, to avoid duplication. | ||
| * | ||
| * @param sent | ||
| * the predicate actually handed to Z3 | ||
| * @param result | ||
| * the raw Z3 {@code Status} | ||
| */ | ||
| public static void smtRawQuery(Predicate sent, String result) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| if (structuredQueryPending) { | ||
| structuredQueryPending = false; // already shown by the structured print that preceded this check | ||
| return; | ||
| } | ||
| List<Expression> conjuncts = new ArrayList<>(); | ||
| flattenConjunction(sent.getExpression(), conjuncts); | ||
| System.out.println(SMT_TAG + " " + Colors.GREY + "query → Z3" + Colors.RESET); | ||
| for (Expression c : conjuncts) { | ||
| System.out.println(SMT_TAG + " " + c); | ||
| } | ||
| System.out.println(SMT_TAG + " Result: " + Colors.CYAN + result + Colors.RESET); | ||
| } | ||
|
|
||
| /** | ||
| * One-line header for a verification check: emits the absolute file path + line so terminals (iTerm2, VS Code, | ||
| * WezTerm, …) make it ⌘/Ctrl-clickable. Replaces the older two-line {@code info()} prints. | ||
| */ | ||
| public static void smtVerifying(SourcePosition position) { | ||
| if (!enabled() || position == null) { | ||
| if (!smtEnabled() || position == null) { | ||
| return; | ||
| } | ||
| String where = position.getFile().getAbsolutePath() + ":" + position.getLine(); | ||
|
|
@@ -59,9 +109,10 @@ public static void smtVerifying(SourcePosition position) { | |
| * points that don't carry the structured per-variable {@link VCImplication} chain (e.g. ExpressionSimplifier). | ||
| */ | ||
| public static void smtStart(Predicate premises, Predicate conclusion) { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| structuredQueryPending = true; | ||
| List<Expression> conjuncts = new ArrayList<>(); | ||
| flattenConjunction(premises.getExpression(), conjuncts); | ||
| System.out.println(SMT_TAG); | ||
|
|
@@ -85,9 +136,10 @@ public static void smtStart(VCImplication chain, Predicate conclusion) { | |
| * {@code verifySMTSubtypeStates}). | ||
| */ | ||
| public static void smtStart(VCImplication chain, Predicate extraPremise, Predicate conclusion) { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| structuredQueryPending = true; | ||
| // Pre-compute label widths for column alignment across all printed rows. | ||
| int labelWidth = 0; | ||
| for (VCImplication node = chain; node != null; node = node.getNext()) { | ||
|
|
@@ -362,14 +414,14 @@ private static void flattenConjunction(Expression e, List<Expression> out) { | |
| } | ||
|
|
||
| public static void smtUnsat() { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| System.out.println(SMT_TAG + " Result: " + Colors.GREEN + "UNSAT (subtype holds)" + Colors.RESET); | ||
| } | ||
|
|
||
| public static void smtSat(Object counterexample) { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| String header = SMT_TAG + " Result: " + Colors.RED + "SAT (subtype fails)" + Colors.RESET; | ||
|
|
@@ -413,7 +465,7 @@ private static String formatCounterexample(Object counterexample) { | |
| } | ||
|
|
||
| public static void smtUnknown() { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| System.out.println(SMT_TAG + " Result: " + Colors.YELLOW + "UNKNOWN (treated as OK)" + Colors.RESET); | ||
|
|
@@ -424,7 +476,7 @@ public static void smtUnknown() { | |
| * print). {@link liquidjava.smt.SMTResult} doesn't preserve UNKNOWN, so this maps OK → UNSAT and ERROR → SAT. | ||
| */ | ||
| public static void smtResult(liquidjava.smt.SMTResult result) { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| if (result.isError()) { | ||
|
|
@@ -439,7 +491,7 @@ public static void smtResult(liquidjava.smt.SMTResult result) { | |
| * still responsible for surfacing the user-facing error. | ||
| */ | ||
| public static void smtError(String message) { | ||
| if (!enabled()) { | ||
| if (!smtEnabled()) { | ||
| return; | ||
| } | ||
| System.out.println(SMT_TAG + " Result: " + Colors.RED + "ERROR" + Colors.RESET + " — " | ||
|
|
||
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.
Maybe rename to something like
debugAllMode.