Skip to content

Commit 291c1a6

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 93fcb68 commit 291c1a6

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
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: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@ 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(
32-
const exprt &var_expr,
33-
const exprt &quantifier_expr)
27+
static exprt
28+
get_quantifier_var_min(const exprt &var_expr, const exprt &quantifier_expr)
3429
{
3530
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
3631

@@ -75,9 +70,8 @@ exprt get_quantifier_var_min(
7570

7671
/// To obtain the max value for the quantifier variable of the specified
7772
/// forall/exists operator.
78-
exprt get_quantifier_var_max(
79-
const exprt &var_expr,
80-
const exprt &quantifier_expr)
73+
static exprt
74+
get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr)
8175
{
8276
PRECONDITION(quantifier_expr.id() == ID_or || quantifier_expr.id() == ID_and);
8377
exprt res = false_exprt();
@@ -132,27 +126,25 @@ exprt get_quantifier_var_max(
132126
return res;
133127
}
134128

135-
optionalt<exprt>
129+
static optionalt<exprt>
136130
instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
137131
{
138-
PRECONDITION(expr.id() == ID_forall || expr.id() == ID_exists);
139-
140132
const symbol_exprt &var_expr = expr.symbol();
141133

142134
/**
143135
* We need to rewrite the forall/exists quantifier into
144136
* an OR/AND expr.
145137
**/
146138

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

149141
if(re.is_true() || re.is_false())
150142
{
151143
return re;
152144
}
153145

154-
const exprt &min_i = get_quantifier_var_min(var_expr, re);
155-
const exprt &max_i = get_quantifier_var_max(var_expr, re);
146+
const exprt min_i = get_quantifier_var_min(var_expr, re);
147+
const exprt max_i = get_quantifier_var_max(var_expr, re);
156148

157149
if(min_i.is_false() || max_i.is_false())
158150
return nullopt;
@@ -183,42 +175,29 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns)
183175
}
184176

185177
UNREACHABLE;
186-
return nullopt;
187178
}
188179

189180
literalt boolbvt::convert_quantifier(const quantifier_exprt &src)
190181
{
191182
PRECONDITION(src.id() == ID_forall || src.id() == ID_exists);
192183

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-
}
184+
const auto res = instantiate_quantifier(src, ns);
200185

201-
quantifiert quantifier;
202-
quantifier.expr = *res;
203-
quantifier_list.push_back(quantifier);
186+
if(res)
187+
return convert_bool(*res);
204188

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

208-
return l;
192+
return quantifier_list.back().l;
209193
}
210194

211195
void boolbvt::post_process_quantifiers()
212196
{
213-
std::set<exprt> instances;
214-
215197
if(quantifier_list.empty())
216198
return;
217199

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-
}
200+
// we do not yet have any elaborate post-processing
201+
for(const auto &q : quantifier_list)
202+
conversion_failed(q.expr);
224203
}

0 commit comments

Comments
 (0)