Skip to content

Add bit vector extract operation support to incremental SMT2 solving #6654

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
merged 8 commits into from
Feb 11, 2022

Conversation

thomasspriggs
Copy link
Contributor

This PR adds support for the bit vector extract operation to the incremental SMT2 solving code. It is separated out from other additions to the bit vector theory, due to the need to add more generalised support for indexed identifiers and the dependency in turn on the back porting of std::void_t.

  • 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.

This resolves clang-tidy warnings in the definitions of the theories due
to "initialization with static storage duration may throw an exception
that cannot be caught".
Comment on lines 1 to 37
// Author: Diffblue Ltd.

/// \file
/// Back ports of utilities available in the `<type_traits>` library for C++14
/// or C++17 to C++11. These can be replaced with the standard library versions
/// as and when we upgrade the version CBMC is compiled with.

#ifndef CPROVER_UTIL_TYPE_TRAITS_H
#define CPROVER_UTIL_TYPE_TRAITS_H

#include <type_traits>

template <bool value>
using bool_constant = std::integral_constant<bool, value>;

namespace detail // NOLINT
{
// Implementation detail of `void_t`.
template <typename... typest>
struct make_voidt
{
using type = void;
};
} // namespace detail

// Back ported from C++17 STL.
template <typename... typest>
using void_t = typename detail::make_voidt<typest...>::type;

#endif // CPROVER_UTIL_TYPE_TRAITS_H
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest to move this to the only file actually using it and also #ifdef it with compiler versions (__cplusplus). Or, at bare minimum, make the comments sufficiently detailed to explain what exactly the code should look like once we move to C++14 (as is done in file_util.h or optional.h).

Copy link
Contributor Author

@thomasspriggs thomasspriggs Feb 10, 2022

Choose a reason for hiding this comment

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

I am more than happy to add extra comments detailing how to transition to using the C++17 version in preparation for the move to that standard. However given that the back ported version will compile with either standards version, is it worth complicating things with different code for different standards, based on the version in __cplusplus?

@codecov
Copy link

codecov bot commented Feb 9, 2022

Codecov Report

Merging #6654 (30d747b) into develop (b630cc5) will increase coverage by 0.03%.
The diff coverage is 96.65%.

❗ Current head 30d747b differs from pull request most recent head 8edd58d. Consider uploading reports for the commit 8edd58d to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6654      +/-   ##
===========================================
+ Coverage    76.73%   76.76%   +0.03%     
===========================================
  Files         1579     1582       +3     
  Lines       181994   182357     +363     
===========================================
+ Hits        139650   139984     +334     
- Misses       42344    42373      +29     
Impacted Files Coverage Δ
...rc/ansi-c/c_typecheck_gcc_polymorphic_builtins.cpp 76.98% <33.33%> (ø)
src/solvers/smt2_incremental/smt_index.cpp 86.66% <86.66%> (ø)
...rc/solvers/smt2_incremental/smt_to_smt2_string.cpp 94.30% <95.83%> (+0.18%) ⬆️
src/goto-programs/remove_vector.cpp 97.00% <100.00%> (+0.42%) ⬆️
...solvers/smt2_incremental/smt_bit_vector_theory.cpp 100.00% <100.00%> (ø)
src/solvers/smt2_incremental/smt_index.h 100.00% <100.00%> (ø)
src/solvers/smt2_incremental/smt_terms.cpp 95.71% <100.00%> (+0.63%) ⬆️
src/solvers/smt2_incremental/smt_terms.h 100.00% <100.00%> (ø)
...solvers/smt2_incremental/smt_bit_vector_theory.cpp 100.00% <100.00%> (ø)
unit/solvers/smt2_incremental/smt_index.cpp 100.00% <100.00%> (ø)
... and 19 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 770d791...8edd58d. Read the comment docs.

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.

I have performed a partial review so far, but I have a couple questions.

TEST_CASE("Test smt_indext.pretty is accessible.", "[core][smt2_incremental]")
{
const smt_indext index = smt_numeral_indext{42};
REQUIRE(index.pretty(0, 0) == "smt_numeral_index\n * value: 42");
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 based on the assumption that .pretty() is always going to return text of a specific format.

I'm not sure if this assumption is always supposed to hold.

If the aim of the test is to make sure that pretty() is accessible, why not just make sure that it's not the empty string? And if you need to make sure that the value is there, make a substring search on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this test would need to be updated if pretty were to change the formatting returned. I'll just check for non-empty instead, to make this less brittle.

}
SECTION("Symbol")
{
REQUIRE(smt_symbol_indext{"foo"}.identifier() == "foo");
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you create a smt_symbol_indext{""}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then the constructed instant will contain the empty string. Are you suggesting an additional invariant?

This is implemented using sfinae to detect if the supplied `functiont`
has an `indices` member function or not, so that it is unneccessary to
add an `indices` member function which returns the empty collections of
indicies for the cases where `function` needs a simple (non indexed)
identifier.

`type_traits.h` is in `solvers/smt2_incremental/` because this is the
only part of the codebase where it is currently used and keeping it here
means the PR with this commit should need fewer code reviewer approvals.
Because adding an include in the following commit will cause
clang-format to re-order the includes. Doing the reorder in advance
makes it possible to review the re-ordering and the additional include
separately.
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.

Looks good overall, just a couple of questions.

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.

My concerns have been adequately addressed.

@thomasspriggs thomasspriggs merged commit e831f43 into diffblue:develop Feb 11, 2022
@thomasspriggs thomasspriggs deleted the tas/smt_bv_extract branch February 11, 2022 15:10
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