Skip to content

Conversation

@thomasspriggs
Copy link
Contributor

Add conversion of incremental smt2 data structures to string. So that they can be converted and sent to a solver. Visitors are used for this implementation, so that the conversion code can be kept separate from the data structures.

  • 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).
  • N/A None claimed - 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.

Because the bit vector theory defined in SMT2 does not allow for bit
vectors of 0 bits.
So that they can be sent to an SMT2 solver using a string based
interface.
@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #6240 (aacc171) into develop (36f661e) will increase coverage by 0.03%.
The diff coverage is 94.97%.

❗ Current head aacc171 differs from pull request most recent head 5dd2519. Consider uploading reports for the commit 5dd2519 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6240      +/-   ##
===========================================
+ Coverage    76.18%   76.22%   +0.03%     
===========================================
  Files         1478     1482       +4     
  Lines       161669   161833     +164     
===========================================
+ Hits        123165   123353     +188     
+ Misses       38504    38480      -24     
Impacted Files Coverage Δ
src/solvers/smt2_incremental/smt_commands.h 100.00% <ø> (ø)
src/solvers/smt2_incremental/smt_to_string.cpp 92.50% <92.50%> (ø)
src/solvers/smt2_incremental/smt_commands.cpp 93.67% <100.00%> (+13.15%) ⬆️
src/solvers/smt2_incremental/smt_sorts.cpp 94.11% <100.00%> (+12.86%) ⬆️
unit/solvers/smt2_incremental/smt_commands.cpp 100.00% <100.00%> (ø)
unit/solvers/smt2_incremental/smt_sorts.cpp 89.74% <100.00%> (+0.85%) ⬆️
unit/solvers/smt2_incremental/smt_to_string.cpp 100.00% <100.00%> (ø)
src/ansi-c/c_typecheck_code.cpp 78.38% <0.00%> (-0.06%) ⬇️
src/ansi-c/parser.y 79.24% <0.00%> (-0.03%) ⬇️
src/solvers/smt2_incremental/smt_sorts.h 100.00% <0.00%> (ø)
... and 15 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 03213c1...5dd2519. Read the comment docs.


void visit(const smt_logic_quantifier_free_bit_vectorst &) override
{
os << "QF_BV";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the logic we currently use and this can cause errors later (we currently use QF_AUFBV explicitly, or for z3 we don't specify and let z3 assume ALL).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is QF_BV enough for our first slice of functionality? I plan to add more different logics in a follow up PR, but I was deliberately limiting the scope of this and the preceding PR, in order to keep things more easily reviewable.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need at least UF for free function symbols:

tgw@DB0907:~$ z3 -smt2 -in
(set-logic QF_BV)
(declare-fun |f| ((_ BitVec 32) (_ BitVec 33)) (_ BitVec 31))
(error "line 2 column 60: logic does not support uninterpreted functions")

as above QF_BV alone will fail, but QF_UFBV below is ok:

tgw@DB0907:~$ z3 -smt2 -in
(set-logic QF_UFBV)
(declare-fun |f| ((_ BitVec 32) (_ BitVec 33)) (_ BitVec 31))
(define-fun |f| ((|g| (_ BitVec 32)) (|h| (_ BitVec 32))) Bool (|=| |g| |h|))
(check-sat)
sat

So that they can be sent to an SMT2 solver using a string based
interface.
For uniformity with `smt_declare_function_commandt` and ease of
correctly escaping the identifer when converting to string.
So that they can be sent to an SMT2 solver using a string based
interface.
Some of the outputs can currently be safely captured by value. However
there is the potential for accidentally introducing dangling reference
type bugs from changes elsewhere in the term to string conversion code.
Therefore this change will reduce the likelyhood of bugs being
introduced in future and should have minimal performance impact due to
the copy-on-write properties of ireps.
@thomasspriggs thomasspriggs force-pushed the tas/smt2_data_structures_to_string branch from e0d089e to aacc171 Compare July 22, 2021 13:33
return os;
}

std::string smt_to_string(const smt_logict &logic)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make the naming here (and in the class/file name) a little more explicit? e.g. smt_to_smt2_string ? Otherwise its not explicitly clear what sort of 'string' is being returned.

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 am fine with making that change if you think it would make things clearer. I can't think of many other kinds of string which we could be converting to, but that is probably because I've been busy writing this one.

In order to make the kind of string being converted to clearer.
In order to make the kind of string being converted to clearer.
In order to be clear about the kind of strings which should be
generated.
@thomasspriggs thomasspriggs merged commit d5c9ef8 into diffblue:develop Jul 23, 2021
@thomasspriggs thomasspriggs deleted the tas/smt2_data_structures_to_string branch July 23, 2021 12:15
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.

4 participants