Skip to content

Commit f4bda12

Browse files
authored
Merge pull request #6549 from diffblue/move_solver_hardness
move solver_hardness.* from solvers/ to goto-symex/
2 parents 29584b3 + 76cbf3e commit f4bda12

30 files changed

+102
-129
lines changed

src/goto-checker/multi_path_symex_checker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Daniel Kroening, Peter Schrammel
1515

1616
#include <util/ui_message.h>
1717

18-
#include <solvers/hardness_collector.h>
18+
#include <goto-symex/solver_hardness.h>
1919

2020
#include "bmc_util.h"
2121
#include "counterexample_beautification.h"

src/goto-checker/solver_factory.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Author: Daniel Kroening, Peter Schrammel
3636
#include <solvers/smt2_incremental/smt_solver_process.h>
3737
#include <solvers/strings/string_refinement.h>
3838

39+
#include <goto-symex/solver_hardness.h>
40+
3941
solver_factoryt::solver_factoryt(
4042
const optionst &_options,
4143
const namespacet &_ns,
@@ -190,11 +192,10 @@ make_satcheck_prop(message_handlert &message_handler, const optionst &options)
190192
if(
191193
auto hardness_collector = dynamic_cast<hardness_collectort *>(&*satcheck))
192194
{
193-
hardness_collector->enable_hardness_collection();
194-
hardness_collector->with_solver_hardness(
195-
[&options](solver_hardnesst &hardness) {
196-
hardness.set_outfile(options.get_option("write-solver-stats-to"));
197-
});
195+
std::unique_ptr<solver_hardnesst> solver_hardness =
196+
util_make_unique<solver_hardnesst>();
197+
solver_hardness->set_outfile(options.get_option("write-solver-stats-to"));
198+
hardness_collector->solver_hardness = std::move(solver_hardness);
198199
}
199200
else
200201
{

src/goto-symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SRC = auto_objects.cpp \
1717
show_program.cpp \
1818
show_vcc.cpp \
1919
slice.cpp \
20+
solver_hardness.cpp \
2021
ssa_step.cpp \
2122
symex_assign.cpp \
2223
symex_atomic_section.cpp \
File renamed without changes.

src/solvers/solver_hardness.h renamed to src/goto-symex/solver_hardness.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Author: Diffblue Ltd.
99
#ifndef CPROVER_SOLVERS_SOLVER_HARDNESS_H
1010
#define CPROVER_SOLVERS_SOLVER_HARDNESS_H
1111

12-
#include <solvers/prop/literal.h>
12+
#include <solvers/hardness_collector.h>
13+
#include <solvers/prop/prop_conv_solver.h>
1314

1415
#include <fstream>
1516
#include <string>
@@ -38,7 +39,7 @@ Author: Diffblue Ltd.
3839
/// derived class of \ref cnft for SAT solving). For this purpose the object
3940
/// lives in the \ref solver_factoryt::solvert and pointers are passed to both
4041
/// \ref decision_proceduret and \ref propt.
41-
struct solver_hardnesst
42+
struct solver_hardnesst : public clause_hardness_collectort
4243
{
4344
// From SAT solver we collect the number of clauses, the number of literals
4445
// and the number of distinct variables that were used in all clauses.
@@ -160,4 +161,26 @@ struct hash<solver_hardnesst::hardness_ssa_keyt>
160161
};
161162
} // namespace std
162163

164+
static inline void with_solver_hardness(
165+
decision_proceduret &maybe_hardness_collector,
166+
std::function<void(solver_hardnesst &hardness)> handler)
167+
{
168+
// FIXME I am wondering if there is a way to do this that is a bit less
169+
// dynamically typed.
170+
if(
171+
auto prop_conv_solver =
172+
dynamic_cast<prop_conv_solvert *>(&maybe_hardness_collector))
173+
{
174+
if(auto hardness_collector = prop_conv_solver->get_hardness_collector())
175+
{
176+
if(hardness_collector->solver_hardness)
177+
{
178+
auto &solver_hardness = static_cast<solver_hardnesst &>(
179+
*(hardness_collector->solver_hardness));
180+
handler(solver_hardness);
181+
}
182+
}
183+
}
184+
}
185+
163186
#endif // CPROVER_SOLVERS_SOLVER_HARDNESS_H

src/goto-symex/symex_target_equation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <util/std_expr.h>
1818

19-
#include <solvers/decision_procedure.h>
20-
#include <solvers/hardness_collector.h>
21-
19+
#include "solver_hardness.h"
2220
#include "ssa_step.h"
2321

24-
static hardness_collectort::handlert
22+
static std::function<void(solver_hardnesst &)>
2523
hardness_register_ssa(std::size_t step_index, const SSA_stept &step)
2624
{
2725
return [step_index, &step](solver_hardnesst &hardness) {

src/solvers/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ SRC = $(BOOLEFORCE_SRC) \
8080
$(SQUOLEM2_SRC) \
8181
$(CADICAL_SRC) \
8282
decision_procedure.cpp \
83-
solver_hardness.cpp \
8483
flattening/arrays.cpp \
8584
flattening/boolbv.cpp \
8685
flattening/boolbv_abs.cpp \

src/solvers/flattening/arrays.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author: Daniel Kroening, [email protected]
2020

2121
#include "equality.h"
2222

23+
class array_comprehension_exprt;
24+
class array_exprt;
2325
class array_of_exprt;
2426
class equal_exprt;
2527
class if_exprt;

src/solvers/flattening/boolbv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class floatbv_typecast_exprt;
3737
class ieee_float_op_exprt;
3838
class member_exprt;
3939
class replication_exprt;
40+
class union_typet;
4041

4142
class boolbvt:public arrayst
4243
{

src/solvers/flattening/boolbv_get.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/arith_tools.h>
1212
#include <util/c_types.h>
13+
#include <util/namespace.h>
1314
#include <util/simplify_expr.h>
1415
#include <util/std_expr.h>
1516
#include <util/threeval.h>

src/solvers/flattening/boolbv_member.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include "boolbv.h"
1010

1111
#include <util/c_types.h>
12+
#include <util/namespace.h>
1213

1314
static bvt convert_member_struct(
1415
const member_exprt &expr,

src/solvers/flattening/boolbv_struct.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11+
#include <util/namespace.h>
12+
1113
bvt boolbvt::convert_struct(const struct_exprt &expr)
1214
{
1315
const struct_typet &struct_type=to_struct_type(ns.follow(expr.type()));

src/solvers/flattening/boolbv_typecast.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/bitvector_types.h>
1515
#include <util/c_types.h>
16+
#include <util/namespace.h>
1617

1718
#include <solvers/floatbv/float_utils.h>
1819

src/solvers/flattening/boolbv_update.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/arith_tools.h>
1212
#include <util/c_types.h>
13+
#include <util/namespace.h>
1314

1415
bvt boolbvt::convert_update(const update_exprt &expr)
1516
{

src/solvers/flattening/boolbv_with.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/arith_tools.h>
1212
#include <util/c_types.h>
13+
#include <util/namespace.h>
1314
#include <util/std_expr.h>
1415

1516
bvt boolbvt::convert_with(const with_exprt &expr)

src/solvers/flattening/bv_pointers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/c_types.h>
1414
#include <util/config.h>
1515
#include <util/exception_utils.h>
16+
#include <util/namespace.h>
1617
#include <util/pointer_expr.h>
1718
#include <util/pointer_offset_size.h>
1819
#include <util/pointer_predicates.h>

src/solvers/hardness_collector.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ Author: Diffblue Ltd.
1414
#ifndef CPROVER_SOLVERS_HARDNESS_COLLECTOR_H
1515
#define CPROVER_SOLVERS_HARDNESS_COLLECTOR_H
1616

17-
#include <functional>
18-
#include <solvers/solver_hardness.h>
17+
#include <solvers/prop/literal.h>
1918

20-
class exprt;
19+
#include <memory>
2120

22-
class hardness_collectort
21+
struct solver_hardnesst;
22+
23+
class clause_hardness_collectort
2324
{
2425
public:
25-
using handlert = std::function<void(solver_hardnesst &)>;
26-
virtual void with_solver_hardness(handlert handler) = 0;
27-
virtual void enable_hardness_collection() = 0;
28-
virtual ~hardness_collectort() = default;
26+
/// Called e.g. from the `satcheck_minisat2::lcnf`, this function adds the
27+
/// complexity statistics from the last SAT query to the `current_ssa_key`.
28+
/// \param bv: the clause (vector of literals)
29+
/// \param cnf: processed clause
30+
/// \param cnf_clause_index: index of clause in dimacs output
31+
/// \param register_cnf: negation of boolean variable tracking if the clause
32+
/// can be eliminated
33+
virtual void register_clause(
34+
const bvt &bv,
35+
const bvt &cnf,
36+
const size_t cnf_clause_index,
37+
bool register_cnf) = 0;
38+
39+
virtual ~clause_hardness_collectort()
40+
{
41+
}
2942
};
3043

31-
template <typename T>
32-
void with_solver_hardness(
33-
T &maybe_hardness_collector,
34-
hardness_collectort::handlert handler)
44+
class hardness_collectort
3545
{
36-
// FIXME I am wondering if there is a way to do this that is a bit less
37-
// dynamically typed.
38-
if(
39-
auto hardness_collector =
40-
dynamic_cast<hardness_collectort *>(&maybe_hardness_collector))
41-
{
42-
hardness_collector->with_solver_hardness(handler);
43-
}
44-
}
46+
public:
47+
std::unique_ptr<clause_hardness_collectort> solver_hardness;
48+
};
49+
4550
#endif // CPROVER_SOLVERS_HARDNESS_COLLECTOR_H

src/solvers/module_dependencies.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cplusplus # cudd
22
cudd
3-
goto-programs
43
solvers
54
util

src/solvers/prop/prop_conv_solver.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,16 +559,3 @@ std::string prop_conv_solvert::decision_procedure_text() const
559559
{
560560
return "propositional reduction";
561561
}
562-
563-
void prop_conv_solvert::with_solver_hardness(
564-
hardness_collectort::handlert handler)
565-
{
566-
::with_solver_hardness(prop, handler);
567-
}
568-
void prop_conv_solvert::enable_hardness_collection()
569-
{
570-
if(auto hardness_collector = dynamic_cast<hardness_collectort *>(&prop))
571-
{
572-
hardness_collector->enable_hardness_collection();
573-
}
574-
}

src/solvers/prop/prop_conv_solver.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ Author: Daniel Kroening, [email protected]
2222
#include "prop_conv.h"
2323
#include "solver_resource_limits.h"
2424

25+
class equal_exprt;
26+
2527
class prop_conv_solvert : public conflict_providert,
2628
public prop_convt,
27-
public solver_resource_limitst,
28-
public hardness_collectort
29+
public solver_resource_limitst
2930
{
3031
public:
3132
prop_conv_solvert(propt &_prop, message_handlert &message_handler)
@@ -95,8 +96,10 @@ class prop_conv_solvert : public conflict_providert,
9596

9697
std::size_t get_number_of_solver_calls() const override;
9798

98-
void with_solver_hardness(handlert handler) override;
99-
void enable_hardness_collection() override;
99+
hardness_collectort *get_hardness_collector()
100+
{
101+
return dynamic_cast<hardness_collectort *>(&prop);
102+
}
100103

101104
protected:
102105
virtual void post_process();

src/solvers/sat/satcheck_cadical.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
6363
}
6464
solver->add(0); // terminate clause
6565

66-
with_solver_hardness([this, &bv](solver_hardnesst &hardness) {
66+
if(solver_hardness)
67+
{
6768
// To map clauses to lines of program code, track clause indices in the
6869
// dimacs cnf output. Dimacs output is generated after processing
6970
// clauses to remove duplicates and clauses that are trivially true.
@@ -77,8 +78,9 @@ void satcheck_cadicalt::lcnf(const bvt &bv)
7778
if(!clause_removed)
7879
cnf_clause_index++;
7980

80-
hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
81-
});
81+
solver_hardness->register_clause(
82+
bv, cnf, cnf_clause_index, !clause_removed);
83+
}
8284

8385
clause_counter++;
8486
}

src/solvers/sat/satcheck_cadical.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,13 @@ class satcheck_cadicalt : public cnf_solvert, public hardness_collectort
4242
}
4343
bool is_in_conflict(literalt a) const override;
4444

45-
void
46-
with_solver_hardness(std::function<void(solver_hardnesst &)> handler) override
47-
{
48-
if(solver_hardness.has_value())
49-
{
50-
handler(solver_hardness.value());
51-
}
52-
}
53-
54-
void enable_hardness_collection() override
55-
{
56-
solver_hardness = solver_hardnesst{};
57-
}
58-
5945
protected:
6046
resultt do_prop_solve() override;
6147

6248
// NOLINTNEXTLINE(readability/identifiers)
6349
CaDiCaL::Solver * solver;
6450

6551
bvt assumptions;
66-
67-
optionalt<solver_hardnesst> solver_hardness;
6852
};
6953

7054
#endif // CPROVER_SOLVERS_SAT_SATCHECK_CADICAL_H

src/solvers/sat/satcheck_glucose.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void satcheck_glucose_baset<T>::lcnf(const bvt &bv)
123123

124124
solver->addClause_(c);
125125

126-
with_solver_hardness([this, &bv](solver_hardnesst &hardness) {
126+
if(solver_hardness)
127+
{
127128
// To map clauses to lines of program code, track clause indices in the
128129
// dimacs cnf output. Dimacs output is generated after processing
129130
// clauses to remove duplicates and clauses that are trivially true.
@@ -137,8 +138,9 @@ void satcheck_glucose_baset<T>::lcnf(const bvt &bv)
137138
if(!clause_removed)
138139
cnf_clause_index++;
139140

140-
hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
141-
});
141+
solver_hardness->register_clause(
142+
bv, cnf, cnf_clause_index, !clause_removed);
143+
}
142144

143145
clause_counter++;
144146
}

src/solvers/sat/satcheck_glucose.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,13 @@ class satcheck_glucose_baset : public cnf_solvert, public hardness_collectort
5757
return true;
5858
}
5959

60-
void
61-
with_solver_hardness(std::function<void(solver_hardnesst &)> handler) override
62-
{
63-
if(solver_hardness.has_value())
64-
{
65-
handler(solver_hardness.value());
66-
}
67-
}
68-
69-
void enable_hardness_collection() override
70-
{
71-
solver_hardness = solver_hardnesst{};
72-
}
73-
7460
protected:
7561
resultt do_prop_solve() override;
7662

7763
std::unique_ptr<T> solver;
7864

7965
void add_variables();
8066
bvt assumptions;
81-
82-
optionalt<solver_hardnesst> solver_hardness;
8367
};
8468

8569
class satcheck_glucose_no_simplifiert:

0 commit comments

Comments
 (0)