Skip to content

Manage lifetime of MiniSat and Glucose solver pointers using unique_ptr #6078

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 6 commits into from
May 5, 2021

Conversation

thomasspriggs
Copy link
Contributor

Manage lifetime of MiniSat solver pointer using unique_ptr. This has the benefit of allowing the use of a default destructor rather than a hand written destructor. Note that satcheck_minisat2_baset was already non-copyable because its solver_hardness field was non-copyable. I have initially raised a PR following this approach for the MiniSat solver only, so I can check whether other maintainers see this as a reasonable approach. If this meets with approval then similar changes could be made for other solvers as well.

  • 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 avoids having definitions of the constructors of
`satcheck_minisat_simplifiert` and `satcheck_minisat_no_simplifiert`
which were implemented the same way, by having a single template
constructor instead. This will simplify subsequent changes to the
constructor, because they will only need to be made in one place.
Because this matches the current coding standards, removes a warning
from clang-tidy and points out that this is overriding a base class
destructor.
This has the benefit of allowing the use of a default destructor rather
than a hand written destructor. Note that `satcheck_minisat2_baset` was
already non-copyable because its `solver_hardness` field was
non-copyable.

The default implementation of the destructor is in the `.cpp` rather
than the header file in order to avoid recompiling it every time the
header file is included.
@thomasspriggs thomasspriggs force-pushed the tas/solver_unique_ptr branch from 6fb12df to 2543943 Compare May 5, 2021 13:27
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.

@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #6078 (3547708) into develop (0e34169) will increase coverage by 0.15%.
The diff coverage is 65.14%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6078      +/-   ##
===========================================
+ Coverage    74.25%   74.40%   +0.15%     
===========================================
  Files         1445     1446       +1     
  Lines       157479   157816     +337     
===========================================
+ Hits        116933   117427     +494     
+ Misses       40546    40389     -157     
Impacted Files Coverage Δ
src/ansi-c/expr2c.cpp 58.48% <ø> (ø)
src/goto-cc/ld_mode.cpp 35.71% <0.00%> (-11.91%) ⬇️
src/goto-checker/properties.cpp 72.56% <ø> (+5.32%) ⬆️
src/util/format_expr.cpp 84.87% <0.00%> (-0.79%) ⬇️
src/util/pointer_expr.cpp 72.82% <0.00%> (-18.96%) ⬇️
src/util/pointer_expr.h 77.34% <0.00%> (-22.66%) ⬇️
src/util/simplify_expr_class.h 100.00% <ø> (ø)
...riable-sensitivity/abstract_object/index_range.cpp 100.00% <ø> (ø)
src/solvers/flattening/bv_pointers.cpp 81.26% <13.04%> (-3.36%) ⬇️
src/solvers/sat/satcheck_minisat2.cpp 64.08% <33.33%> (-8.26%) ⬇️
... and 71 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 3984250...3547708. Read the comment docs.

@tautschnig
Copy link
Collaborator

Thank you @thomasspriggs, this is so much better than #6070! I had made a brief attempt using unique_ptr, but it didn't occur to me that I (still) had to place the destructor in the .cpp file. Could you please do the same for Glucose?

This avoids having definitions of the constructors of
`satcheck_glucose_simplifiert` and `satcheck_glucose_no_simplifiert`
which were implemented the same way, by having a single template
constructor instead. This will simplify subsequent changes to the
constructor, because they will only need to be made in one place.
Because this matches the current coding standards, removes a warning
from clang-tidy and points out that this is overriding a base class
destructor.
This has the benefit of allowing the use of a default destructor rather
than a hand written destructor. Note that `satcheck_glucose_baset` was
already non-copyable because its `solver_hardness` field was
non-copyable.

The default implementation of the destructor is in the `.cpp` rather
than the header file in order to avoid recompiling it every time the
header file is included and so that the declaration of the solver
destructor is available when instantiating the destructor template of
`unique_ptr`.
@thomasspriggs thomasspriggs changed the title Manage lifetime of MiniSat solver pointer using unique_ptr Manage lifetime of MiniSat and Glucose solver pointers using unique_ptr May 5, 2021
@thomasspriggs
Copy link
Contributor Author

Thank you @thomasspriggs, this is so much better than #6070! I had made a brief attempt using unique_ptr, but it didn't occur to me that I (still) had to place the destructor in the .cpp file. Could you please do the same for Glucose?

@tautschnig - Done.

@tautschnig tautschnig merged commit 648b8e3 into diffblue:develop May 5, 2021
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