Skip to content

Commit d045df8

Browse files
committed
Cleanup boolbv quantifier instantiation
1) Do not take references of temporaries. 2) Instead of post_processing, some expressions can be instantiated and converted immediately. 3) Use skip_typecast rather than local, partial typecast skipping. 4) No need for redundant precondition checks. 5) Mark file-local procedures static.
1 parent c2e3503 commit d045df8

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

src/solvers/flattening/boolbv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ class boolbvt:public arrayst
238238
class quantifiert
239239
{
240240
public:
241+
quantifiert(exprt _expr, literalt _l)
242+
: expr(std::move(_expr)), l(std::move(_l))
243+
{
244+
}
245+
241246
exprt expr;
242247
literalt l;
243248
};

src/solvers/flattening/boolbv_quantifier.cpp

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ Author: Daniel Kroening, [email protected]
99
#include "boolbv.h"
1010

1111
#include <util/arith_tools.h>
12+
#include <util/expr_util.h>
1213
#include <util/invariant.h>
1314
#include <util/optional.h>
1415
#include <util/replace_expr.h>
1516
#include <util/simplify_expr.h>
1617

1718
/// A method to detect equivalence between experts that can contain typecast
18-
bool expr_eq(const exprt &expr1, const exprt &expr2)
19+
static bool expr_eq(const exprt &expr1, const exprt &expr2)
1920
{
20-
exprt e1=expr1, e2=expr2;
21-
if(expr1.id()==ID_typecast)
22-
e1=expr1.op0();
23-
if(expr2.id()==ID_typecast)
24-
e2=expr2.op0();
25-
return e1==e2;
21+
return skip_typecast(expr1) == skip_typecast(expr2);
2622
}
2723

2824
/// To obtain the min value for the quantifier variable of the specified
2925
/// forall/exists operator. The min variable is in the form of "!(var_expr >
3026
/// constant)".
31-
exprt get_quantifier_var_min(
27+
static exprt get_quantifier_var_min(
3228
const exprt &var_expr,
3329
const exprt &quantifier_expr)
3430
{
@@ -75,7 +71,7 @@ exprt get_quantifier_var_min(
7571

7672
/// To obtain the max value for the quantifier variable of the specified
7773
/// forall/exists operator.
78-
exprt get_quantifier_var_max(
74+
static exprt get_quantifier_var_max(
7975
const exprt &var_expr,
8076
const exprt &quantifier_expr)
8177
{
@@ -132,27 +128,25 @@ exprt get_quantifier_var_max(
132128
return res;
133129
}
134130

135-
optionalt<exprt>
131+
static optionalt<exprt>
136132
instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
137133
{
138-
PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists);
139-
140134
const symbol_exprt &var_expr = expr.symbol();
141135

142136
/**
143137
* We need to rewrite the forall/exists quantifier into
144138
* an OR/AND expr.
145139
**/
146140

147-
const exprt &re = simplify_expr(expr.where(), ns);
141+
const exprt re = simplify_expr(expr.where(), ns);
148142

149143
if(re.is_true() || re.is_false())
150144
{
151145
return re;
152146
}
153147

154-
const exprt &min_i = get_quantifier_var_min(var_expr, re);
155-
const exprt &max_i = get_quantifier_var_max(var_expr, re);
148+
const exprt min_i = get_quantifier_var_min(var_expr, re);
149+
const exprt max_i = get_quantifier_var_max(var_expr, re);
156150

157151
if(min_i.is_false() || max_i.is_false())
158152
return nullopt;
@@ -183,42 +177,29 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
183177
}
184178

185179
UNREACHABLE;
186-
return nullopt;
187180
}
188181

189182
literalt boolbvt::convert_quantifier(const quantifier_exprt &src)
190183
{
191184
PRECONDITION(src.id() == ID_forall || src.id() == ID_exists);
192185

193-
quantifier_exprt expr(src);
194-
const auto res = instantiate_quantifier(expr, ns);
195-
196-
if(!res)
197-
{
198-
return SUB::convert_rest(src);
199-
}
186+
const auto res = instantiate_quantifier(src, ns);
200187

201-
quantifiert quantifier;
202-
quantifier.expr = *res;
203-
quantifier_list.push_back(quantifier);
188+
if(res)
189+
return convert_bool(*res);
204190

205-
literalt l=prop.new_variable();
206-
quantifier_list.back().l=l;
191+
// we failed to instantiate here, need to pass to post-processing
192+
quantifier_list.emplace_back(quantifiert(src, prop.new_variable()));
207193

208-
return l;
194+
return quantifier_list.back().l;
209195
}
210196

211197
void boolbvt::post_process_quantifiers()
212198
{
213-
std::set<exprt> instances;
214-
215199
if(quantifier_list.empty())
216200
return;
217201

218-
for(auto it=quantifier_list.begin();
219-
it!=quantifier_list.end();
220-
++it)
221-
{
222-
prop.set_equal(convert_bool(it->expr), it->l);
223-
}
202+
// we do not yet have any elaborate post-processing
203+
for(const auto &q : quantifier_list)
204+
conversion_failed(q.expr);
224205
}

0 commit comments

Comments
 (0)