Skip to content

Commit 886c172

Browse files
authored
Improve Debug Logs (#224)
1 parent d977679 commit 886c172

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

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

Lines changed: 19 additions & 4 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.smt.Counterexample;
1214
import liquidjava.utils.Utils;
1315
import spoon.reflect.cu.SourcePosition;
1416
import spoon.reflect.reference.CtTypeReference;
@@ -29,6 +31,7 @@ public final class DebugLog {
2931

3032
private static final String SMT_TAG = Colors.BLUE + "[SMT]" + Colors.RESET;
3133
private static final String SMT_CHECK = Colors.SALMON + "[SMT CHECK]" + Colors.RESET;
34+
private static final String SMP_TAG = Colors.YELLOW + "[SMP]" + Colors.RESET;
3235

3336
private DebugLog() {
3437
}
@@ -123,6 +126,18 @@ public static void smtStart(VCImplication chain, Predicate extraPremise, Predica
123126
System.out.println(SMT_TAG + " " + formatConclusion(conclusion));
124127
}
125128

129+
/**
130+
* Print the simplifier input and output side by side. This keeps the raw expression visible in debug traces while
131+
* callers continue using the simplified expression for user-facing diagnostics.
132+
*/
133+
public static void simplification(Expression input, Expression output) {
134+
if (!enabled()) {
135+
return;
136+
}
137+
System.out.println(SMP_TAG + " Before simplification: " + Colors.YELLOW + input + Colors.RESET);
138+
System.out.println(SMP_TAG + " After simplification: " + Colors.BOLD_YELLOW + output + Colors.RESET);
139+
}
140+
126141
private static String plainLabel(VCImplication node) {
127142
return node.getName() + " : " + simpleType(node.getType());
128143
}
@@ -215,14 +230,14 @@ public static void smtUnsat() {
215230
if (!enabled()) {
216231
return;
217232
}
218-
System.out.println(SMT_TAG + " result: " + Colors.GREEN + "UNSAT (subtype holds)" + Colors.RESET);
233+
System.out.println(SMT_TAG + " Result: " + Colors.GREEN + "UNSAT (subtype holds)" + Colors.RESET);
219234
}
220235

221236
public static void smtSat(Object counterexample) {
222237
if (!enabled()) {
223238
return;
224239
}
225-
String header = SMT_TAG + " result: " + Colors.RED + "SAT (subtype fails)" + Colors.RESET;
240+
String header = SMT_TAG + " Result: " + Colors.RED + "SAT (subtype fails)" + Colors.RESET;
226241
String pretty = formatCounterexample(counterexample);
227242
if (pretty == null) {
228243
System.out.println(header);
@@ -266,7 +281,7 @@ public static void smtUnknown() {
266281
if (!enabled()) {
267282
return;
268283
}
269-
System.out.println(SMT_TAG + " result: " + Colors.YELLOW + "UNKNOWN (treated as OK)" + Colors.RESET);
284+
System.out.println(SMT_TAG + " Result: " + Colors.YELLOW + "UNKNOWN (treated as OK)" + Colors.RESET);
270285
}
271286

272287
/**
@@ -292,7 +307,7 @@ public static void smtError(String message) {
292307
if (!enabled()) {
293308
return;
294309
}
295-
System.out.println(SMT_TAG + " result: " + Colors.RED + "ERROR" + Colors.RESET + " — "
310+
System.out.println(SMT_TAG + " Result: " + Colors.RED + "ERROR" + Colors.RESET + " — "
296311
+ (message == null ? "(no message)" : message));
297312
}
298313
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import java.util.stream.Collectors;
66

7-
import liquidjava.api.CommandLineLauncher;
87
import liquidjava.diagnostics.TranslationTable;
98
import liquidjava.rj_language.ast.Expression;
109
import liquidjava.rj_language.ast.formatter.VariableFormatter;
@@ -53,8 +52,8 @@ public String getCounterExampleString() {
5352
List<String> foundAssignments = found.getValue().getConjuncts().stream().map(Expression::toString).toList();
5453
String counterexampleString = counterexample.assignments().stream()
5554
// only include variables that appear in the found value and are not already fixed there
56-
.filter(a -> CommandLineLauncher.cmdArgs.debugMode || (foundVarNames.contains(a.first())
57-
&& !foundAssignments.contains(a.first() + " == " + a.second())))
55+
.filter(a -> foundVarNames.contains(a.first())
56+
&& !foundAssignments.contains(a.first() + " == " + a.second()))
5857
// format as "var == value"
5958
.map(a -> VariableFormatter.format(a.first()) + " == " + a.second())
6059
// join with "&&"

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Map;
77
import java.util.stream.Collectors;
88

9-
import liquidjava.api.CommandLineLauncher;
9+
import liquidjava.diagnostics.DebugLog;
1010
import liquidjava.diagnostics.errors.LJError;
1111
import liquidjava.diagnostics.errors.NotFoundError;
1212
import liquidjava.processor.context.AliasWrapper;
@@ -257,11 +257,10 @@ public ValDerivationNode simplify(Context context) {
257257
for (AliasWrapper aw : context.getAliases()) {
258258
aliases.put(aw.getName(), aw.createAliasDTO());
259259
}
260-
if (CommandLineLauncher.cmdArgs.debugMode) {
261-
return new ValDerivationNode(exp.clone(), null);
262-
}
263260
// simplify expression
264-
return ExpressionSimplifier.simplify(exp.clone(), aliases);
261+
ValDerivationNode result = ExpressionSimplifier.simplify(exp.clone(), aliases);
262+
DebugLog.simplification(this.getExpression(), result.getValue());
263+
return result;
265264
}
266265

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

0 commit comments

Comments
 (0)