Skip to content

Conversation

thomasspriggs
Copy link
Contributor

This PR adds initial struct support for the incremental SMT2 decision procedure. Further refinements of this and support for other kinds of expression will be handled in follow-up PRs.

  • 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 May 30, 2023

Codecov Report

Patch coverage: 96.52% and project coverage change: +0.01 🎉

Comparison is base (26b8027) 78.54% compared to head (a06d62f) 78.55%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7740      +/-   ##
===========================================
+ Coverage    78.54%   78.55%   +0.01%     
===========================================
  Files         1688     1691       +3     
  Lines       193001   193111     +110     
===========================================
+ Hits        151596   151702     +106     
- Misses       41405    41409       +4     
Impacted Files Coverage Δ
..._incremental/smt2_incremental_decision_procedure.h 75.00% <ø> (ø)
src/solvers/smt2_incremental/struct_encoding.cpp 90.32% <90.32%> (ø)
...ncremental/smt2_incremental_decision_procedure.cpp 96.41% <92.30%> (-0.22%) ⬇️
src/solvers/smt2_incremental/struct_encoding.h 100.00% <100.00%> (ø)
unit/solvers/smt2_incremental/struct_encoding.cpp 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@thomasspriggs thomasspriggs force-pushed the tas/smt2_structs branch 2 times, most recently from 5e99bd8 to f966107 Compare May 30, 2023 14:37
As some of the setup is the same for each test, the tests can be
sections in a single test which share the same setup instead of copying
it.
So that multiple lowering transformations can be added and maintained in
a single location in a single order.
So that we have initial struct support in place.
To make it easier to debug the changes made by lowering operations.
@thomasspriggs thomasspriggs marked this pull request as ready for review May 30, 2023 16:57
Copy link
Contributor

@TGWDB TGWDB left a comment

Choose a reason for hiding this comment

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

Second commit could have been squashed, but not worth rerunning CI unless other changes happen during review.

Also it would be nice to know if any of the normal regression tests now run with this (and hence can be turned on for new SMT).

@thomasspriggs thomasspriggs merged commit 453eb65 into diffblue:develop May 31, 2023
@thomasspriggs
Copy link
Contributor Author

Second commit could have been squashed, but not worth rerunning CI unless other changes happen during review.

I wasn't entirely certain reviewers would prefer the code before or after the refactor, hence I left it in, in case of requests to drop it.

Also it would be nice to know if any of the normal regression tests now run with this (and hence can be turned on for new SMT).

I have merged the PR as is, but I will take a look to see if more regression tests can be switched on for a follow-up PR.

@@ -41,6 +42,11 @@ typet struct_encodingt::encode(typet type) const
return type;
}

static exprt encode(const struct_exprt &struct_expr)
{
return concatenation_exprt{struct_expr.operands(), struct_expr.type()};
Copy link
Collaborator

Choose a reason for hiding this comment

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

With apologies for being (too) late on this: I think this isn't correct as concatenation expressions have the most-significant bits/bytes first. So IMHO you are now getting the byte order wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know. Do you think reversing the order of the operands is sufficient to fix this and is there a regression test (without unions) which would be sufficient to demonstrate the problem?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there is more to it: you will also need to (recursively?) convert the struct expression's operands to bit vectors, unless that will be handled elsewhere?

Do you have any test that exercises this code at all? I would expect that byte-operator lowering produces such struct expressions at times, but then this might involve unions. Why do unions give you grief? I'd expect all operations on unions to use byte operators, which in turn are lowered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unions in combination with structs are not known to cause any grief to us yet. As the PR title suggests, only initial struct support is in place. All further combinations of structs + other feature are yet to be tested / implemented. It may be as you say that the unions will all disappear in the byte-operator lowering. We need to test to confirm the current status for this.

The deep (recursive style) processing of the operands is handled by the struct_encodingt::encode(exprt expr) function. I have avoided actual recursion in order avoid overflowing the stack in the case of deeply nested expressions. There are unit tests for this function in general which can be found in unit/solvers/smt2_incremental/struct_encoding.cpp.

I will add further tests along with other remaining pieces of struct related functionality in follow-up PRs.

Test that we support struct values and traces for a trivial example. At the
time of adding the regression test, this exercised the conversion code specific
to struct_tag_typet and struct_exprt. Field sensitivity is expected to eliminate
many of the struct specific expressions before they can reach the decision
Copy link
Collaborator

Choose a reason for hiding this comment

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

So .. do you actually exercise the newly added code at all? I'm inclined to think that field sensitivity will completely eliminate any use of structs in this example.

Copy link
Contributor Author

@thomasspriggs thomasspriggs May 31, 2023

Choose a reason for hiding this comment

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

Yes, the newly added code is exercised. Before this PR an invariant violation would have been encountered, due to the type to sort conversion not understanding a struct_tag_type. The added type conversion pass is sufficient to support non-det struct typed symbols. After field sensitivity has done its thing with the separate symbols/expressions for each field, they are reassembled back into a struct using a struct_exprt at some stage. This is why support for this type of expression was included in this PR.

The kinds of expressions which are eliminated by field sensitivity in this example are member_exprt and with_exprt applied to structs. I have an example C input file which avoids this, with the aid of a sufficiently large array. So next on my list is support for these two kinds of expression.

My apologies if I hadn't explained this sufficiently clearly in the test description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants