Skip to content

Commit 8188d32

Browse files
committed
Use MIR without regions for pure functions.
1 parent 95c4305 commit 8188d32

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

prusti-interface/src/environment/body.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use prusti_common::config;
21
use prusti_rustc_interface::{
32
macros::{TyDecodable, TyEncodable},
43
middle::{
@@ -321,15 +320,11 @@ impl<'tcx> EnvBody<'tcx> {
321320

322321
pub(crate) fn load_pure_fn_body(&mut self, def_id: LocalDefId) {
323322
assert!(!self.pure_fns.local.contains_key(&def_id));
324-
if config::no_verify() {
325-
let body = Self::load_local_mir(self.tcx, def_id);
326-
self.pure_fns.local.insert(def_id, body);
327-
} else {
328-
let bwbf = Self::load_local_mir_with_facts(self.tcx, def_id);
329-
self.pure_fns.local.insert(def_id, bwbf.body.clone());
330-
// Also add to `impure_fns` since we'll also be encoding this as impure
331-
self.local_impure_fns.borrow_mut().insert(def_id, bwbf);
332-
}
323+
let body = Self::load_local_mir(self.tcx, def_id);
324+
self.pure_fns.local.insert(def_id, body);
325+
let bwbf = Self::load_local_mir_with_facts(self.tcx, def_id);
326+
// Also add to `impure_fns` since we'll also be encoding this as impure
327+
self.local_impure_fns.borrow_mut().insert(def_id, bwbf);
333328
}
334329

335330
pub(crate) fn load_closure_body(&mut self, def_id: LocalDefId) {

prusti-viper/src/encoder/mir/errors/interface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ pub(crate) trait ErrorInterface {
2727
error_ctxt: ErrorCtxt,
2828
) -> vir_high::Position;
2929
fn set_surrounding_error_context(
30-
&mut self,
30+
&self,
3131
position: vir_high::Position,
3232
error_ctxt: ErrorCtxt,
3333
) -> vir_high::Position;
3434
fn set_surrounding_error_context_for_expression(
35-
&mut self,
35+
&self,
3636
expression: vir_high::Expression,
3737
default_position: vir_high::Position,
3838
error_ctxt: ErrorCtxt,
@@ -93,7 +93,7 @@ impl<'v, 'tcx: 'v> ErrorInterface for super::super::super::Encoder<'v, 'tcx> {
9393
new_position.into()
9494
}
9595
fn set_surrounding_error_context(
96-
&mut self,
96+
&self,
9797
position: vir_high::Position,
9898
error_ctxt: ErrorCtxt,
9999
) -> vir_high::Position {
@@ -106,14 +106,14 @@ impl<'v, 'tcx: 'v> ErrorInterface for super::super::super::Encoder<'v, 'tcx> {
106106
/// 1. `default_position` if `position.is_default()`.
107107
/// 2. With surrounding error context otherwise.
108108
fn set_surrounding_error_context_for_expression(
109-
&mut self,
109+
&self,
110110
expression: vir_high::Expression,
111111
default_position: vir_high::Position,
112112
error_ctxt: ErrorCtxt,
113113
) -> vir_high::Expression {
114114
assert!(!default_position.is_default());
115115
struct Visitor<'p, 'v: 'p, 'tcx: 'v> {
116-
encoder: &'p mut super::super::super::Encoder<'v, 'tcx>,
116+
encoder: &'p super::super::super::Encoder<'v, 'tcx>,
117117
default_position: vir_high::Position,
118118
error_ctxt: ErrorCtxt,
119119
}

prusti-viper/src/encoder/mir/pure/pure_functions/encoder_high.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::encoder::{
33
errors::{ErrorCtxt, SpannedEncodingError, SpannedEncodingResult, WithSpan},
44
mir::{
55
contracts::{ContractsEncoderInterface, ProcedureContractMirDef},
6+
errors::ErrorInterface,
67
generics::MirGenericsEncoderInterface,
78
pure::{
89
interpreter::{
@@ -341,11 +342,12 @@ impl<'p, 'v: 'p, 'tcx: 'v> PureEncoder<'p, 'v, 'tcx> {
341342
self.parent_def_id,
342343
assertion_substs,
343344
)?;
344-
self.encoder.error_manager().set_error(
345-
encoded_assertion.position().into(),
345+
let original_position = encoded_assertion.position();
346+
conjuncts.push(self.encoder.set_surrounding_error_context_for_expression(
347+
encoded_assertion,
348+
original_position,
346349
ErrorCtxt::PureFunctionDefinition,
347-
);
348-
conjuncts.push(encoded_assertion);
350+
));
349351
}
350352
Ok(conjuncts.into_iter().conjoin())
351353
}

prusti-viper/src/encoder/mir/pure/pure_functions/encoder_poly.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,11 @@ impl<'p, 'v: 'p, 'tcx: 'v> PureFunctionEncoder<'p, 'v, 'tcx> {
479479
self.parent_def_id,
480480
assertion_substs,
481481
)?;
482-
self.encoder
483-
.error_manager()
484-
.set_error(encoded_assertion.pos(), ErrorCtxt::PureFunctionDefinition);
485-
func_spec.push(encoded_assertion);
482+
let new_pos = self.encoder.error_manager().set_surrounding_error_context(
483+
encoded_assertion.pos(),
484+
ErrorCtxt::PureFunctionDefinition,
485+
);
486+
func_spec.push(encoded_assertion.set_pos(new_pos));
486487
}
487488

488489
Ok((

prusti-viper/src/encoder/procedure_encoder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5511,10 +5511,8 @@ impl<'p, 'v: 'p, 'tcx: 'v> ProcedureEncoder<'p, 'v, 'tcx> {
55115511
}
55125512
} else {
55135513
// FIXME: why are we getting the MIR body for this?
5514-
let mir = self.encoder.env().body.get_impure_fn_body(
5514+
let mir = self.encoder.env().body.get_impure_fn_body_identity(
55155515
containing_def_id.expect_local(),
5516-
// TODO(tymap): identity substs here are probably wrong?
5517-
self.encoder.env().query.identity_substs(containing_def_id),
55185516
);
55195517
let return_ty = mir.return_ty();
55205518
let arg_tys = mir.args_iter().map(|arg| mir.local_decls[arg].ty).collect();

0 commit comments

Comments
 (0)