-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add support for Strings and Rationals to the Princess backend #391
Changes from 110 commits
ccc281a
1f7be15
99337b7
625a0b6
b7bbc3c
53a1885
6f62e05
d59e56c
adaa89c
27faaa7
f8b0c3d
5df33fe
9a7e920
451b0f3
3aaf54b
34b71ed
0ad41d3
e9707d1
f7f9da5
53c0b4b
ebe926f
8b906ec
1936c40
dac5ac4
2df018b
449a87c
2eb9dbf
4871bdc
4652de9
2dde64b
8c9f2b8
d680735
a40f42a
13c01a6
ec6ebaf
262bb96
b503024
3175cf1
0210289
29d25c3
85ebb3d
f99740d
8eee565
abc11e5
1610229
076d626
5df2ce6
9c6ca0e
c546357
7767d2a
51bec64
fd9ae85
0ea532a
9f4d16c
c89c6ac
a65769c
47def53
96c4d61
296d8e4
5b77984
da11b8f
0ea2941
6eb0f67
f5dffee
30c1fe7
9569292
f843131
76efd95
f661c10
2e570a2
d761b17
2d7df5f
3bc04a8
2c06c70
c83063e
a1764de
3b7229a
4c78733
2636f5e
1e8176f
3e1dad8
bbf9b9c
e950269
872944f
c161f00
f3a277e
c2b685b
6beb6f5
9e1d69d
ea21421
6351613
6fc4b9a
43c2c83
3b6102d
fa38940
e075090
ce2e7f9
52fd628
98e49f7
bcb696d
9320257
3648bf0
441e947
0e949d7
ba486a5
21abead
5cfbef7
7ea3b68
a2d2497
922dd53
fd8e810
ae05a8b
1b4ff68
669743f
69517ec
e6bc8f1
0c70424
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import org.sosy_lab.common.collect.PathCopyingPersistentTreeMap; | ||
import org.sosy_lab.common.collect.PersistentMap; | ||
import org.sosy_lab.java_smt.api.BooleanFormula; | ||
import org.sosy_lab.java_smt.api.Formula; | ||
import org.sosy_lab.java_smt.api.Model; | ||
import org.sosy_lab.java_smt.api.SolverContext.ProverOptions; | ||
import org.sosy_lab.java_smt.api.SolverException; | ||
|
@@ -46,6 +47,15 @@ abstract class PrincessAbstractProver<E> extends AbstractProverWithAllSat<E> { | |
protected final PrincessFormulaManager mgr; | ||
protected final Deque<Level> trackingStack = new ArrayDeque<>(); // symbols on all levels | ||
|
||
/** | ||
* Values returned by {@link Model#evaluate(Formula)}. | ||
* | ||
* <p>We need to record these to make sure that the values returned by the evaluator are | ||
* consistant. Calling {@link #isUnsat()} will reset this list as the underlying model has been | ||
* updated. | ||
*/ | ||
protected final List<IFormula> evaluatedTerms = new ArrayList<>(); | ||
|
||
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. This might be a bigger issue for Princess. 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.
I'm afraid in this case the problem here is really with the work-around, and not with Princess. We effectively emulate
The problem is than the sat check causes the solver to forget the old model, and because of this it can choose a different assignment for the variables. For instance, if the only assertion on the stack is EDIT: 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. The implementation of |
||
// assign a unique partition number for eah added constraint, for unsat-core and interpolation. | ||
protected final UniqueIdGenerator idGenerator = new UniqueIdGenerator(); | ||
protected final Deque<PersistentMap<Integer, BooleanFormula>> partitions = new ArrayDeque<>(); | ||
|
@@ -76,9 +86,11 @@ protected PrincessAbstractProver( | |
public boolean isUnsat() throws SolverException { | ||
Preconditions.checkState(!closed); | ||
wasLastSatCheckSat = false; | ||
evaluatedTerms.clear(); | ||
final Value result = api.checkSat(true); | ||
if (result.equals(SimpleAPI.ProverStatus$.MODULE$.Sat())) { | ||
wasLastSatCheckSat = true; | ||
evaluatedTerms.add(api.partialModelAsFormula()); | ||
return false; | ||
} else if (result.equals(SimpleAPI.ProverStatus$.MODULE$.Unsat())) { | ||
return true; | ||
|
@@ -121,14 +133,28 @@ protected void popImpl() { | |
// we have to recreate symbols on lower levels, because JavaSMT assumes "global" symbols. | ||
Level level = trackingStack.pop(); | ||
api.addBooleanVariables(asScala(level.booleanSymbols)); | ||
api.addConstants(asScala(level.intSymbols)); | ||
api.addConstants(asScala(level.theorySymbols)); | ||
level.functionSymbols.forEach(api::addFunction); | ||
if (!trackingStack.isEmpty()) { | ||
trackingStack.peek().mergeWithHigher(level); | ||
} | ||
partitions.pop(); | ||
} | ||
|
||
/** | ||
* Get a list of all terms that have been evaluated in the current model. | ||
* | ||
* <p>The formulas in this list are assignments that extend the original model. | ||
*/ | ||
List<IFormula> getEvaluatedTerms() { | ||
return evaluatedTerms; | ||
} | ||
|
||
/** Add a new term to the list of evaluated terms. */ | ||
void addEvaluatedTerm(IFormula pFormula) { | ||
evaluatedTerms.add(pFormula); | ||
} | ||
|
||
@SuppressWarnings("resource") | ||
@Override | ||
public Model getModel() throws SolverException { | ||
|
@@ -146,7 +172,7 @@ protected PrincessModel getEvaluatorWithoutChecks() throws SolverException { | |
} catch (SimpleAPIException ex) { | ||
throw new SolverException(ex.getMessage(), ex); | ||
} | ||
return new PrincessModel(this, partialModel, creator, api); | ||
return registerEvaluator(new PrincessModel(this, partialModel, creator, api)); | ||
} | ||
|
||
/** | ||
|
@@ -213,12 +239,12 @@ void addSymbol(IFormula f) { | |
} | ||
} | ||
|
||
/** add external definition: integer variable. */ | ||
/** add external definition: theory variable (integer, rational, string, etc). */ | ||
void addSymbol(ITerm f) { | ||
Preconditions.checkState(!closed); | ||
api.addConstant(f); | ||
if (!trackingStack.isEmpty()) { | ||
trackingStack.peek().intSymbols.add(f); | ||
trackingStack.peek().theorySymbols.add(f); | ||
} | ||
} | ||
|
||
|
@@ -233,21 +259,21 @@ void addSymbol(IFunction f) { | |
|
||
static class Level { | ||
final List<IFormula> booleanSymbols = new ArrayList<>(); | ||
final List<ITerm> intSymbols = new ArrayList<>(); | ||
final List<ITerm> theorySymbols = new ArrayList<>(); | ||
final List<IFunction> functionSymbols = new ArrayList<>(); | ||
|
||
Level() {} | ||
|
||
/** add higher level to current level, we keep the order of creating symbols. */ | ||
void mergeWithHigher(Level other) { | ||
this.booleanSymbols.addAll(other.booleanSymbols); | ||
this.intSymbols.addAll(other.intSymbols); | ||
this.theorySymbols.addAll(other.theorySymbols); | ||
this.functionSymbols.addAll(other.functionSymbols); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("{%s, %s, %s}", booleanSymbols, intSymbols, functionSymbols); | ||
return String.format("{%s, %s, %s}", booleanSymbols, theorySymbols, functionSymbols); | ||
} | ||
} | ||
} |
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.
Do we need this change or is this just for development?
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.
No, it was for development only. Once everything is in our repository it can be removed.
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.
I've restored the original version now.