Skip to content

Commit 04fa29e

Browse files
committed
Compute local variables inside var_to_const, rather than further down
the pipeline. That way, we don't over include the constants introduced to disambiguate mutated variables.
1 parent 23330c3 commit 04fa29e

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

verify/air/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ impl<'ctx> Context<'ctx> {
237237
if let Err(err) = crate::typecheck::check_query(self, query) {
238238
return ValidityResult::TypeError(err);
239239
}
240-
let (query, snapshots) = crate::var_to_const::lower_query(query);
240+
let (query, snapshots, local_vars) = crate::var_to_const::lower_query(query);
241241
self.air_middle_log.log_query(&query);
242242
let query = crate::block_to_assert::lower_query(&query);
243243
self.air_final_log.log_query(&query);
244244

245-
let validity = crate::smt_verify::smt_check_query(self, &query, snapshots);
245+
let validity = crate::smt_verify::smt_check_query(self, &query, snapshots, local_vars);
246246

247247
validity
248248
}

verify/air/src/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a> Model<'a> {
5959

6060

6161
/// Reconstruct an AIR-level model based on the Z3 model
62-
pub fn build(&mut self, context: &mut Context, local_vars: &Vec<Decl>) {
62+
pub fn build(&mut self, context: &mut Context, local_vars: Vec<Decl>) {
6363
println!("Building the AIR model");
6464
for (snap_id, id_snapshot) in &self.id_snapshots {
6565
let mut value_snapshot = HashMap::new();

verify/air/src/smt_verify.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ast::{
2-
BinaryOp, BindX, Constant, Decl, DeclX,Expr, ExprX, Ident, MultiOp, Quant, Query, SnapShots, Span, StmtX,
2+
BinaryOp, BindX, Constant, Decl, DeclX, Expr, ExprX, Ident, MultiOp, Quant, Query, SnapShots, Span, StmtX,
33
Typ, TypX, UnaryOp,
44
};
55
use crate::context::{AssertionInfo, Context, ValidityResult};
@@ -364,7 +364,7 @@ fn smt_check_assertion<'ctx>(
364364
context: &mut Context<'ctx>,
365365
infos: &Vec<AssertionInfo>,
366366
snapshots: SnapShots,
367-
local_vars: &Vec<Decl>, // Expected to be entirely DeclX::Const
367+
local_vars: Vec<Decl>, // Expected to be entirely DeclX::Const
368368
expr: &Expr,
369369
) -> ValidityResult<'ctx> {
370370
let mut discovered_span = Rc::new(None);
@@ -435,21 +435,16 @@ fn smt_check_assertion<'ctx>(
435435
}
436436
}
437437

438-
pub(crate) fn smt_check_query<'ctx>(context: &mut Context<'ctx>, query: &Query, snapshots: SnapShots) -> ValidityResult<'ctx> {
438+
pub(crate) fn smt_check_query<'ctx>(context: &mut Context<'ctx>, query: &Query, snapshots: SnapShots, local_vars: Vec<Decl>) -> ValidityResult<'ctx> {
439439
context.smt_log.log_push();
440440
context.solver.push();
441441
context.push_name_scope();
442442

443-
let mut local_vars = Vec::new();
444-
445443
// add query-local declarations
446444
for decl in query.local.iter() {
447445
if let Err(err) = crate::typecheck::add_decl(context, decl, false) {
448446
return ValidityResult::TypeError(err);
449447
}
450-
if let DeclX::Const(_, _) = **decl {
451-
local_vars.push(decl.clone());
452-
}
453448
smt_add_decl(context, decl);
454449
}
455450

@@ -473,7 +468,7 @@ pub(crate) fn smt_check_query<'ctx>(context: &mut Context<'ctx>, query: &Query,
473468
}
474469

475470
// check assertion
476-
let result = smt_check_assertion(context, &infos, snapshots, &local_vars, &labeled_assertion);
471+
let result = smt_check_assertion(context, &infos, snapshots, local_vars, &labeled_assertion);
477472

478473
// clean up
479474
context.pop_name_scope();

verify/air/src/var_to_const.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ fn lower_stmt(
125125
}
126126
}
127127

128-
pub(crate) fn lower_query(query: &Query) -> (Query, SnapShots) {
128+
pub(crate) fn lower_query(query: &Query) -> (Query, SnapShots, Vec<Decl>) {
129129
let QueryX { local, assertion } = &**query;
130130
let mut decls: Vec<Decl> = Vec::new();
131131
let mut versions: HashMap<Ident, u32> = HashMap::new();
132132
let mut version_decls: HashSet<Ident> = HashSet::new();
133133
let mut snapshots: SnapShots = HashMap::new();
134134
let mut types: HashMap<Ident, Typ> = HashMap::new();
135+
let mut local_vars: Vec<Decl> = Vec::new();
136+
135137
for decl in local.iter() {
136138
if let DeclX::Axiom(expr) = &**decl {
137139
let decl_x = DeclX::Axiom(lower_expr(&versions, &snapshots, expr));
@@ -140,12 +142,16 @@ pub(crate) fn lower_query(query: &Query) -> (Query, SnapShots) {
140142
decls.push(decl.clone());
141143
}
142144
if let DeclX::Var(x, t) = &**decl {
145+
println!("In var_to_const, lower_query, DeclX::Var of {}", x);
143146
versions.insert(x.clone(), 0);
144147
types.insert(x.clone(), t.clone());
145148
let x = Rc::new(rename_var(x, 0));
146149
let decl = Rc::new(DeclX::Const(x.clone(), t.clone()));
147150
decls.push(decl);
148151
}
152+
if let DeclX::Const(_, _) = &**decl {
153+
local_vars.push(decl.clone());
154+
}
149155
}
150156
let assertion = lower_stmt(
151157
&mut decls,
@@ -156,5 +162,5 @@ pub(crate) fn lower_query(query: &Query) -> (Query, SnapShots) {
156162
assertion,
157163
);
158164
let local = Rc::new(decls);
159-
(Rc::new(QueryX { local, assertion }), snapshots)
165+
(Rc::new(QueryX { local, assertion }), snapshots, local_vars)
160166
}

0 commit comments

Comments
 (0)