Skip to content

Commit

Permalink
[ExportSMTLIB] Fix printing of too many closing parentheses
Browse files Browse the repository at this point in the history
The number of open parentheses should not be propagated to quantifier bodies and the first child expression of 'let' which declares the bound variable
  • Loading branch information
maerhart committed Apr 20, 2024
1 parent b4b4a7b commit 3a08dce
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion integration_test/Target/ExportSMTLIB/attributes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ smt.solver () : () -> () {
// CHECK-NOT: ERROR
// CHECK-NOT: error
// CHECK-NOT: unsat
// CHECK: sat
// CHECK: sat
6 changes: 3 additions & 3 deletions lib/Target/ExportSMTLIB/ExportSMTLIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct ExpressionVisitor
info.stream << "(let ((" << name << " ";

VisitorInfo newInfo(info.stream, info.valueMap,
info.indentLevel + 7 + name.size(), info.openParens);
info.indentLevel + 8 + name.size(), 0);
if (failed(Base::dispatchSMTOpVisitor(op, newInfo)))
return failure();

Expand Down Expand Up @@ -332,14 +332,14 @@ struct ExpressionVisitor
worklist.push_back(yieldedValue);
unsigned indentExt = operatorString.size() + 2;
VisitorInfo newInfo(info.stream, info.valueMap,
info.indentLevel + indentExt, info.openParens);
info.indentLevel + indentExt, 0);
newInfo.stream.indent(newInfo.indentLevel);
if (failed(printExpression(worklist, newInfo)))
return failure();

info.stream << info.valueMap.lookup(yieldedValue);

for (int j = 0; j < newInfo.openParens; ++j)
for (unsigned j = 0; j < newInfo.openParens; ++j)
info.stream << ")";

if (weight != 0)
Expand Down
2 changes: 1 addition & 1 deletion test/Target/ExportSMTLIB/attributes.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ smt.solver () : () -> () {

// CHECK: (reset)
// CHECK-INLINED: (reset)
}
}
23 changes: 23 additions & 0 deletions test/Target/ExportSMTLIB/core.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ smt.solver () : () -> () {
}
smt.assert %2

// Test: make sure that open parens from outside quantifier bodies are not
// propagated into the body.
// CHECK: (assert (let (([[V15:.+]] (exists (([[V16:.+]] Int) ([[V17:.+]] Int)){{$}}
// CHECK: (let (([[V18:.+]] (= [[V16]] [[V17]]))){{$}}
// CHECK: [[V18]])))){{$}}
// CHECK: (let (([[V19:.+]] (exists (([[V20:.+]] Int) ([[V21:.+]] Int)){{$}}
// CHECK: (let (([[V22:.+]] (= [[V20]] [[V21]]))){{$}}
// CHECK: [[V22]])))){{$}}
// CHECK: (let (([[V23:.+]] (and [[V19]] [[V15]]))){{$}}
// CHECK: [[V23]])))){{$}}
%3 = smt.exists {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%5 = smt.eq %arg2, %arg3 : !smt.int
smt.yield %5 : !smt.bool
}
%5 = smt.exists {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%6 = smt.eq %arg2, %arg3 : !smt.int
smt.yield %6 : !smt.bool
}
%6 = smt.and %3, %5
smt.assert %6

// CHECK: (check-sat)
// CHECK-INLINED: (check-sat)
smt.check sat {} unknown {} unsat {}
Expand Down

0 comments on commit 3a08dce

Please sign in to comment.