-
Notifications
You must be signed in to change notification settings - Fork 274
Rewrite smt2_conv to build a syntax tree TG-5825 #4100
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
Rewrite smt2_conv to build a syntax tree TG-5825 #4100
Conversation
Why not use |
The original reason was type safety, so that we couldn't mix ASTs and exprt. |
I had expected some collection of classes that would do actual typed AST nodes, but it seems this is just another string-based approach so I’m not particularly convinced there is added type safety? For printing, I have not yet understood what makes this new AST class so fundamentally different- irept can happily be used without recursion, as is done in the depth iterator. |
Yes for now there are only strings and mp_integer and we don't do many checks, but we can slowly transition to stricter type checking. The idea would be to avoid direct calls to smt2_node and instead used typed functions like
I thought depth iterator were using a stack, but apparently it's a deque, so yes it could work. |
0ecb1e3
to
fef9a22
Compare
Well, there are different approaches to building ASTs. One school of thought is to use dedicated classes/data types for each kind, and another approach is to have a generic representation with information held in strings (or some other sufficiently general data type). Of course the latter doesn't give you compiler-supported type checking, but it makes it much easier to extend a language. If you would like to pursue the first approach with dedicated data types that's fine, but I just don't see how the PR achieves this at the moment. As far as I understand (and I might be wrong) the PR introduces just a new generic data type to hold AST nodes. Maybe it's in some way more efficient than So I'll keep fighting what currently feels like not-invented-here-syndrome until sufficient documentation, commit messages, etc. is provided to clearly describe why a new AST base class is needed, and what its characteristics/limitations are. |
BTW, for type safety, simply derive from |
The goal is to separate conversion from printing. The immediate benefit is the syntax correctness is easier to check (in particular we don't have to worry about unmatched parenthesis) and the code should be clearer. Ultimately we could pass the AST directly to the smt solver without having to print it and then parse it back. @tautschnig |
fef9a22
to
842ae2a
Compare
0193bf4
to
89d558e
Compare
bd6ecec
to
37aa9cb
Compare
feea012
to
750acf3
Compare
750acf3
to
fc65eae
Compare
fe3f5ba
to
9dd2ff4
Compare
src/solvers/smt2/smt2_ast.h
Outdated
{ | ||
} | ||
|
||
smt2_sortt(smt2_symbolt symbol, std::vector<smt2_astt> &¶meters) |
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.
The parameters should be smt2_sortt
s and symbol should be smt2_identifiert
src/solvers/smt2/smt2_ast.h
Outdated
private: | ||
/// Indexed sort, only used for BitVec at the moment | ||
smt2_sortt(irep_idt symbol, std::vector<smt2_constantt> &¶meters) | ||
: smt2_astt(smt2_identifiert{smt2_symbolt(symbol), std::move(parameters)}) |
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.
there shouldn't be a need for this constructor if the one above is made to take a smt2_identifiert
return stream; | ||
} | ||
|
||
class smt2_commandt final : public smt2_command_or_commentt |
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.
Reference the SMT-LIB standard http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.0-r10.12.21.pdf
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 9dd2ff4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/112202263
f36bb2a
to
af2eedf
Compare
af2eedf
to
4ddd58f
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 4ddd58f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/114702452
This reflects the inheritance from exprt and will avoid collision with a type that will be introduced for smt2 ASTs.
This is to represent the structure of the smt2 instance generated by smt2_conv. This will allow separation between the structure and the printing of these instances. The structure is not used in this commit but will ultimately be used by convert_expr. The class inherits from non_sharing_treet to reuse the structure of trees. Sharing does not seem to be useful for the usage we will make of these ASTs. We don't inherit from irept so that we can get some type safety: in particular we can't add a irept child to a smt2_astt by mistake.
This allows to separate the creation of the structure of the AST from its printing. Unfortunately all the functions we modify here are mutualy recursive so they have to be modified all at once. That's why this commit is so big. The correctness of this change is checked by the regression test that are run using: scripts/delete_failing_smt2_solver_tests ; env PATH=$PATH:`pwd`/src/solvers UBSAN_OPTIONS=print_stacktrace=1 make -C regression/cbmc test-cprover-smt2 which is done by travis.
This reflects the structure of SMT2 commands, making commands constructed using this framework will be syntatically correct by construction.
Allow better structure of the code and avoids syntaxic mistakes.
4ddd58f
to
84b0a90
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 84b0a90).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/116629722
Closing as this is now out of date and being done in another series of PRs, for details see #6134 |
This defines an AST class for smt2 instances, and modify convert_expr to return one of this instances.