Skip to content

Commit c23424f

Browse files
committed
Requested Changes
1 parent f39fff2 commit c23424f

3 files changed

Lines changed: 28 additions & 15 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/diagnostics/DebugLog.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.stream.Collectors;
56

67
import liquidjava.api.CommandLineLauncher;
78
import liquidjava.processor.VCImplication;
89
import liquidjava.rj_language.Predicate;
910
import liquidjava.rj_language.ast.BinaryExpression;
1011
import liquidjava.rj_language.ast.Expression;
1112
import liquidjava.rj_language.ast.GroupExpression;
13+
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
1214
import liquidjava.smt.Counterexample;
1315
import liquidjava.utils.Utils;
1416
import spoon.reflect.cu.SourcePosition;
@@ -30,6 +32,7 @@ public final class DebugLog {
3032

3133
private static final String SMT_TAG = Colors.BLUE + "[SMT]" + Colors.RESET;
3234
private static final String SMT_CHECK = Colors.SALMON + "[SMT CHECK]" + Colors.RESET;
35+
private static final String SMP_TAG = Colors.YELLOW + "[SMP]" + Colors.RESET;
3336

3437
private DebugLog() {
3538
}
@@ -124,21 +127,31 @@ public static void smtStart(VCImplication chain, Predicate extraPremise, Predica
124127
System.out.println(SMT_TAG + " " + formatConclusion(conclusion));
125128
}
126129

127-
public static void simplificationInput(Predicate predicate) {
130+
/**
131+
* Print the simplifier input and output side by side. This keeps the raw expression visible in debug traces while
132+
* callers continue using the simplified expression for user-facing diagnostics.
133+
*/
134+
public static void simplification(Expression input, Expression output) {
128135
if (!enabled()) {
129136
return;
130137
}
131-
System.out.println(SMT_TAG + " unsimplified: " + predicate);
138+
System.out.println(SMP_TAG + " Simplified " + Colors.CYAN + input + Colors.RESET + " to " + Colors.YELLOW
139+
+ output + Colors.RESET);
132140
}
133141

134-
public static void counterexampleAssignments(Counterexample counterexample) {
142+
/**
143+
* Print every assignment returned by the solver before error reporting filters the user-facing counterexample down
144+
* to the variables mentioned in the diagnostic.
145+
*/
146+
public static void counterexample(Counterexample counterexample) {
135147
if (!enabled() || counterexample == null || counterexample.assignments().isEmpty()) {
136148
return;
137149
}
138-
System.out.println(SMT_TAG + " unfiltered counterexample assignments:");
139-
for (var assignment : counterexample.assignments()) {
140-
System.out.println(SMT_TAG + " " + assignment.first() + " = " + assignment.second());
141-
}
150+
System.out
151+
.println(SMP_TAG
152+
+ " Counterexample: " + Colors.RED + counterexample.assignments().stream()
153+
.map(a -> a.first() + " = " + a.second()).collect(Collectors.joining(" && "))
154+
+ Colors.RESET);
142155
}
143156

144157
private static String plainLabel(VCImplication node) {
@@ -233,14 +246,14 @@ public static void smtUnsat() {
233246
if (!enabled()) {
234247
return;
235248
}
236-
System.out.println(SMT_TAG + " result: " + Colors.GREEN + "UNSAT (subtype holds)" + Colors.RESET);
249+
System.out.println(SMT_TAG + " Result: " + Colors.GREEN + "UNSAT (subtype holds)" + Colors.RESET);
237250
}
238251

239252
public static void smtSat(Object counterexample) {
240253
if (!enabled()) {
241254
return;
242255
}
243-
String header = SMT_TAG + " result: " + Colors.RED + "SAT (subtype fails)" + Colors.RESET;
256+
String header = SMT_TAG + " Result: " + Colors.RED + "SAT (subtype fails)" + Colors.RESET;
244257
String pretty = formatCounterexample(counterexample);
245258
if (pretty == null) {
246259
System.out.println(header);
@@ -284,7 +297,7 @@ public static void smtUnknown() {
284297
if (!enabled()) {
285298
return;
286299
}
287-
System.out.println(SMT_TAG + " result: " + Colors.YELLOW + "UNKNOWN (treated as OK)" + Colors.RESET);
300+
System.out.println(SMT_TAG + " Result: " + Colors.YELLOW + "UNKNOWN (treated as OK)" + Colors.RESET);
288301
}
289302

290303
/**
@@ -310,7 +323,7 @@ public static void smtError(String message) {
310323
if (!enabled()) {
311324
return;
312325
}
313-
System.out.println(SMT_TAG + " result: " + Colors.RED + "ERROR" + Colors.RESET + " — "
326+
System.out.println(SMT_TAG + " Result: " + Colors.RED + "ERROR" + Colors.RESET + " — "
314327
+ (message == null ? "(no message)" : message));
315328
}
316329
}

liquidjava-verifier/src/main/java/liquidjava/diagnostics/errors/RefinementError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public String getCounterExampleString() {
4444
if (counterexample == null || counterexample.assignments().isEmpty())
4545
return null;
4646

47-
DebugLog.counterexampleAssignments(counterexample);
47+
DebugLog.counterexample(counterexample);
4848

4949
List<String> foundVarNames = new ArrayList<>();
5050
found.getValue().getVariableNames(foundVarNames);

liquidjava-verifier/src/main/java/liquidjava/rj_language/Predicate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ public Expression getExpression() {
252252
}
253253

254254
public ValDerivationNode simplify(Context context) {
255-
DebugLog.simplificationInput(this);
256-
257255
// collect aliases from context
258256
Map<String, AliasDTO> aliases = new HashMap<>();
259257
for (AliasWrapper aw : context.getAliases()) {
260258
aliases.put(aw.getName(), aw.createAliasDTO());
261259
}
262260
// simplify expression
263-
return ExpressionSimplifier.simplify(exp.clone(), aliases);
261+
ValDerivationNode result = ExpressionSimplifier.simplify(exp.clone(), aliases);
262+
DebugLog.simplification(this.getExpression(), result.getValue());
263+
return result;
264264
}
265265

266266
private static boolean isBooleanLiteral(Expression expr, boolean value) {

0 commit comments

Comments
 (0)