Skip to content

Commit 1415ae4

Browse files
Revert "Bitwuzla: Make the code less error prone by identifying |var| and var directly in the variable cache"
This reverts commit ce2688e.
1 parent 2944fa1 commit 1415ae4

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaFormulaCreator.java

+2-27
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import static org.sosy_lab.common.collect.Collections3.transformedImmutableSetCopy;
1313

1414
import com.google.common.base.Preconditions;
15+
import com.google.common.collect.HashBasedTable;
1516
import com.google.common.collect.ImmutableList;
1617
import com.google.common.collect.Table;
17-
import com.google.common.collect.TreeBasedTable;
1818
import java.math.BigInteger;
1919
import java.util.ArrayDeque;
2020
import java.util.ArrayList;
2121
import java.util.Collection;
22-
import java.util.Comparator;
2322
import java.util.Deque;
2423
import java.util.HashMap;
2524
import java.util.LinkedHashSet;
@@ -57,31 +56,7 @@
5756
public class BitwuzlaFormulaCreator extends FormulaCreator<Term, Sort, Void, BitwuzlaDeclaration> {
5857
private final TermManager termManager;
5958

60-
/**
61-
* Returns the symbol name without any SMTLIB quotes.
62-
*
63-
* <p>Will turn <code>| 1var\n|</code> into just <code> 1 var\n</code>. Symbols that are not
64-
* quoted are unaffected.
65-
*/
66-
private String removeQuotes(String symbol) {
67-
return (symbol.startsWith("|") && symbol.endsWith("|"))
68-
? symbol.substring(1, symbol.length() - 1)
69-
: symbol;
70-
}
71-
72-
/**
73-
* Stores Bitwuzla terms for all defined symbols.
74-
*
75-
* <p>The cache maps from <code>String x Sort</code> to <code>Term</code>. Here the first argument
76-
* is the name of the symbol, and we allow polymorphic symbols where the same name can have more
77-
* than one sort. If the symbol can be printed as a simple symbol or a quoted symbol (like <code>
78-
* var1</code> and <code>|var1|</code>) in SMTLIB we identify both version as they refer to the
79-
* same variable.
80-
*/
81-
private final Table<String, Sort, Term> formulaCache =
82-
TreeBasedTable.create(
83-
(String symA, String symB) -> removeQuotes(symA).compareTo(removeQuotes(symB)),
84-
Comparator.comparing(Sort::toString));
59+
private final Table<String, Sort, Term> formulaCache = HashBasedTable.create();
8560

8661
/**
8762
* This mapping stores symbols and their constraints, such as from fp-to-bv casts with their

src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaFormulaManager.java

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public Term parseImpl(String formulaStr) throws IllegalArgumentException {
7474
Term parsed = declParser.get_declared_funs().get(0);
7575

7676
String symbol = parsed.symbol();
77+
if (symbol.startsWith("|") && symbol.endsWith("|")) {
78+
// Strip quotes from the name
79+
symbol = symbol.substring(1, symbol.length() - 1);
80+
}
7781
Sort sort = parsed.sort();
7882

7983
// Check if the symbol is already defined in the variable cache
@@ -134,6 +138,9 @@ public Term parseImpl(String formulaStr) throws IllegalArgumentException {
134138
Map_TermTerm subst = new Map_TermTerm();
135139
for (Term term : declared) {
136140
String symbol = term.symbol();
141+
if (symbol.startsWith("|") && symbol.endsWith("|")) {
142+
symbol = symbol.substring(1, symbol.length() - 1);
143+
}
137144
if (cache.containsRow(symbol)) {
138145
// Symbol is from the context: add the original term to the substitution map
139146
subst.put(term, cache.get(symbol, term.sort()));

0 commit comments

Comments
 (0)