Skip to content

Add validation of smt parse trees to construct smt_responset instances. #6458

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

Merged

Conversation

thomasspriggs
Copy link
Contributor

@thomasspriggs thomasspriggs commented Nov 16, 2021

This PR adds validation of smt parse trees to construct smt_responset instances.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Nov 16, 2021

Codecov Report

Merging #6458 (0e66013) into develop (578765e) will increase coverage by 0.01%.
The diff coverage is 93.12%.

❗ Current head 0e66013 differs from pull request most recent head 6c3d1da. Consider uploading reports for the commit 6c3d1da to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6458      +/-   ##
===========================================
+ Coverage    75.98%   75.99%   +0.01%     
===========================================
  Files         1542     1546       +4     
  Lines       165038   165240     +202     
===========================================
+ Hits        125404   125579     +175     
- Misses       39634    39661      +27     
Impacted Files Coverage Δ
src/solvers/smt2_incremental/smt_responses.h 100.00% <ø> (ø)
unit/solvers/smt2/smt2irep.cpp 100.00% <ø> (+16.90%) ⬆️
unit/testing-utils/smt2irep.cpp 59.25% <59.25%> (ø)
...lvers/smt2_incremental/smt_response_validation.cpp 96.51% <96.51%> (ø)
...lvers/smt2_incremental/smt_response_validation.cpp 97.22% <97.22%> (ø)
...solvers/smt2_incremental/smt_response_validation.h 100.00% <100.00%> (ø)
src/solvers/smt2_incremental/smt_responses.cpp 100.00% <100.00%> (ø)
src/solvers/flattening/boolbv_member.cpp 53.65% <0.00%> (-43.91%) ⬇️
src/solvers/flattening/boolbv_shift.cpp 75.00% <0.00%> (-9.38%) ⬇️
src/util/pointer_predicates.cpp 89.23% <0.00%> (-4.32%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb8ad8e...6c3d1da. Read the comment docs.

@thomasspriggs thomasspriggs force-pushed the tas/type_check_smt_response branch 2 times, most recently from 2b91bf9 to 0e66013 Compare November 18, 2021 12:07
Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall 👍🏻

@@ -37,5 +37,14 @@ template class response_or_errort<smt_responset>;

response_or_errort<smt_responset> validate_smt_response(const irept &parse_tree)
{
if(parse_tree.id() == "sat")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Why not switch (parse_tree.id()) { case "sat": }. Might make it a bit more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you can't switch on a string in C++.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can switch on a/the first character... so if you want a big nested tree of case statements... ;)

Comment on lines 177 to 178
return {response_or_errort<smt_responset>{
"Error response has multiple error messages."}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something nicer here? Maybe gather all the error messages into a multiline string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done something nicer here. The original parse tree is now included in this error message, as instances where the messages are sub trees could also fall into this case.

@@ -37,5 +37,14 @@ template class response_or_errort<smt_responset>;

response_or_errort<smt_responset> validate_smt_response(const irept &parse_tree)
{
if(parse_tree.id() == "sat")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can switch on a/the first character... so if you want a big nested tree of case statements... ;)

The `response_or_errort` class is a template, so that it can be reused
for smt_termt and `smt_sortt` sub trees of the SMT responses, whilst
maintaining strong compile time type checking.

The `UNIMPLEMENTED` macro in the `validate_smt_response` function
will be replaced with an implementation in the following commits of this
PR.
To facilitate debugging of tests and tracking down causes of test
failures.
So they can be reused in multiple test `.cpp` files.
For each non-leaf node in the `smt_responset` tree, the same logic is
required where the child nodes are validated and we construct the
non-leaf node if there are no errors, or collect and propagate the
errors upwards if there are errors validating the child nodes.

The template in this commit abstracts this logic out, so that it doesn't
need to be duplicated for each type of node we construct.
This is currently implemented using `pretty`, but this function is used
forward to replace with an implementation specific to our use case which
is more easily readable by users of CBMC.
The template parameter is specified for mapping to upper case characters
to fix a warning compiling on Ubuntu 18. This warning was related to
`std::toupper` being declared with the deprecated `throw ()` in the
standard library and the meaning of this changing between C++ versions.
So that it is still possible to see the error message which was being
reported.
@thomasspriggs thomasspriggs force-pushed the tas/type_check_smt_response branch from 0e66013 to 6c3d1da Compare November 19, 2021 16:00
@thomasspriggs thomasspriggs merged commit 516f109 into diffblue:develop Nov 19, 2021
@thomasspriggs thomasspriggs deleted the tas/type_check_smt_response branch November 19, 2021 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants