Conversation
…formula is returned
SMTLIB2 parsing and add a check for set-info
There was a problem hiding this comment.
Our SMTLIB2 parser, to be exact its tokenizer, rejects set-logic commands that are not at the very beginning of the SMT-LIB2 file. This is wrong, these commands are allowed to be everywhere in the file and may be repeated with distinct settings!
I think this is backwards. Here is the diagram from the standard:
(Source of diagram: https://smt-lib.org/papers/smt-lib-reference-v2.6-r2021-05-12.pdf , 4.1 General Requirements, page 53)
So set-logic must be used before anything else can be done, and set-info can appear anywhere in the file
Did you run into any parsing issues with their benchmarks?
src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java
Outdated
Show resolved
Hide resolved
src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java
Outdated
Show resolved
Hide resolved
The issues he faces come from the smtlib files I gave in #613. The output we generate conforms to the shape required by SMT-COMP because we once submitted our benchmarks there. |
Thanks! I've had a look at it, and there seem to be two issues:
In this case the problem is easily fixed by just commenting out some lines: When I now try the tests, I get a runtime of 8s with logic @baierd: We could easily fix the first problem by skipping |
If the query is not incremental, Z3 will use the SAT Solver independently of the logic set (easy to see by executing Z3 with higher verbosity levels). I think most solvers ignore
I think you would need a more general concept of an |
kfriedberger
left a comment
There was a problem hiding this comment.
lgtm.
Why does the formatter or Checkstyle not warn about the String concatenation?
Please fix, then merge. Thanks.
| checkArgument(!formulas.isEmpty(), "No assertion found in the SMTLIB string."); | ||
| checkArgument( | ||
| formulas.size() == 1, | ||
| "More than one assertion found in the SMT-LIB string, " + "please use parseAll(String)."); |
There was a problem hiding this comment.
String concatenation not required. Remove the PLUS.
src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java
Outdated
Show resolved
Hide resolved
If you want to solve the query, it is needed before something is asserted. Which is less strict. Btw. i left the token detection in for if we actually decide that we want to do something with it + documentation. The standard however states that @ThomasHaas do you know whether comments are allowed to be placed before this |
If there is only We could just add a class |
I'm not sure if this is permitted in SMT-COMP, but does it really matter? You want to parse general smtlib2 which is far less restrictive: you can have comments everywhere and |
But shouldn't we at least try to keep to the standard? If we just want to allow
There is really no need to remove the check for that
The problem here is that MathSAT adds private String sanitize(String formulaStr) {
List<String> tokens = Tokenizer.tokenize(formulaStr);
StringBuilder builder = new StringBuilder();
int pos = 0; // index of the current token
for (String token : tokens) {
if (pos == 0 && Tokenizer.isSetInfoToken(token)) {
// set-info call is allowed to be the very first command in the benchmark, but can also
// appear repeatedly throughout a SMT2 program
// Technically it is even required to be the very first command, and it must set the
// :smt-lib-version attribute. See SMT-LIB 2.7 §3.11.3
// TODO: check that version >= 2?
Preconditions.checkArgument(token.contains(":smt-lib-version"));The token is We could probably fix this, but I'm not sure the check is even needed. According to the standard these are additional requirements for their benchmark files:
We're trying to parse "regular" SMTLIB files, so this shouldn't apply to us
Yes, that might be one way to solve it. In this particular example, however, the interesting assertion isn't even on the stack anymore at the end of the SMTLIB file. Instead, it was replaced by |
Yes and no. We try to follow the standard as far as it makes sense. Many solvers do non-standard things and we adapt.
No. This is a clear example for a state-machine. Starting with flags etc. would lead to confusing/complex code. And yes, as stated above, the rule with |
…luate them if there are none
…ct the actual rules of set-logic in the SMTLIB2 standard with some leniency due to solvers often assuming ALL to be set implicitly
…nal simplifications. This currently only checks that our SMTLIB2 out/input is sticking to some important rules, but can be used to actually control the flow of possible parsing with solving etc.
|
So the problem is the following: if we assume the diagram above to be accurate, most solvers don't produce valid SMT-LIB2. Since we know this, we allow some leniency, most notably; we assume implicit logic selection for logic Btw. i also found that the diagram above is incomplete, as I now added a implementation that can easily switch between all of this, depending on a single boolean flag to control whether we allow implicit @daniel-raffler i found that Boolector seems to return an empty SMTLIB2 String in a test case (that i now disabled). Could you open a issue and take a look? Also, i found that we throws exceptions every time we load Bitwuzlas options due to our "further options" implementation (in our code, not Bitwuzlas). While not part of this PR, I still added a small simplification to check for an empty options string to skip the evaluation (as it made my debugging harder ;D). @daniel-raffler would you be so kind and open another issue for this and take a look? Exception based control flow is Java is a very bad idea and we should not do it if possible. |
…ts-set-logic-commands-and-has-a-non-helpful-error-message-for-parse-for-1-items
|
Edit: nvm we actually have tests for this. I need to change the current behavior. |
…pty strings to be parsed
…leading to exception to a checkArgument()
daniel-raffler
left a comment
There was a problem hiding this comment.
Looks fine to me! There are a few TODOs left open, and a lot of the methods in SMTLIB2ProgramStateMachine are currently unused. Do you plan to extend this later? Otherwise, we could probably simplify the class a bit
| int pos = 0; // index of the current token | ||
|
|
||
| // SMTLIB2ProgramState tracks that the SMTLIB2 query conforms to the rules outlined in the | ||
| // standard. SMTLIB2ProgramStateMachine models the |
There was a problem hiding this comment.
This comment seems to have been cut off

Fixes issues from #620 by adding a state-machine for processing SMT-LIB2 programs.
Closes #620.