Skip to content

Commit 86a5d4b

Browse files
authored
Use Place type everywhere in VIR AST (#1831)
1 parent e09c0af commit 86a5d4b

20 files changed

+942
-502
lines changed

source/rust_verify/src/automatic_derive.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use crate::verus_items::RustItem;
33
use rustc_hir::HirId;
44
use rustc_span::Span;
55
use std::sync::Arc;
6-
use vir::ast::{BinaryOp, Expr, ExprX, FunctionX, Mode, SpannedTyped, VirErr, VirErrAs};
6+
use vir::ast::{
7+
BinaryOp, Expr, ExprX, FunctionX, Mode, Place, PlaceX, SpannedTyped, VirErr, VirErrAs,
8+
};
79

810
/// Traits with special handling
911
#[derive(Clone, Copy, Debug)]
@@ -105,10 +107,16 @@ fn clone_add_post_condition<'tcx>(
105107

106108
match &body.x {
107109
ExprX::Block(_stmts, Some(last_expr)) => match &last_expr.x {
108-
ExprX::Var(id) if &*id.0 == "self" => {
109-
uses_copy = true;
110-
self_var = Some(last_expr.clone());
111-
}
110+
ExprX::ReadPlace(pl, _) => match &pl.x {
111+
PlaceX::Local(id) if &*id.0 == "self" => {
112+
uses_copy = true;
113+
self_var = Some(last_expr.clone());
114+
}
115+
_ => {
116+
warn_unexpected();
117+
return Ok(());
118+
}
119+
},
112120
ExprX::Ctor { .. } => {
113121
uses_copy = false;
114122
self_var = None;
@@ -154,11 +162,20 @@ fn clone_add_post_condition<'tcx>(
154162

155163
// TODO better place for this
156164
fn cleanup_span_ids<'tcx>(ctxt: &Context<'tcx>, span: Span, hir_id: HirId, expr: &Expr) -> Expr {
157-
vir::ast_visitor::map_expr_visitor(expr, &|e: &Expr| {
158-
let e = ctxt.spans.spanned_typed_new(span, &e.typ, e.x.clone());
159-
let mut erasure_info = ctxt.erasure_info.borrow_mut();
160-
erasure_info.hir_vir_ids.push((hir_id, e.span.id));
161-
Ok(e)
162-
})
165+
vir::ast_visitor::map_expr_place_visitor(
166+
expr,
167+
&|e: &Expr| {
168+
let e = ctxt.spans.spanned_typed_new(span, &e.typ, e.x.clone());
169+
let mut erasure_info = ctxt.erasure_info.borrow_mut();
170+
erasure_info.hir_vir_ids.push((hir_id, e.span.id));
171+
Ok(e)
172+
},
173+
&|p: &Place| {
174+
let p = ctxt.spans.spanned_typed_new(span, &p.typ, p.x.clone());
175+
let mut erasure_info = ctxt.erasure_info.borrow_mut();
176+
erasure_info.hir_vir_ids.push((hir_id, p.span.id));
177+
Ok(p)
178+
},
179+
)
163180
.unwrap()
164181
}

source/rust_verify/src/context.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,14 @@ impl<'tcx> ContextX<'tcx> {
8585
r.bodies.push((local_def_id, c));
8686
}
8787
}
88+
89+
impl<'tcx> BodyCtxt<'tcx> {
90+
pub(crate) fn is_copy(&self, ty: rustc_middle::ty::Ty<'tcx>) -> bool {
91+
let param_env = self.ctxt.tcx.param_env(self.fun_id);
92+
let typing_env = rustc_middle::ty::TypingEnv {
93+
param_env,
94+
typing_mode: rustc_middle::ty::TypingMode::PostAnalysis,
95+
};
96+
self.ctxt.tcx.type_is_copy_modulo_regions(typing_env, ty)
97+
}
98+
}

source/rust_verify/src/fn_call_to_vir.rs

Lines changed: 92 additions & 54 deletions
Large diffs are not rendered by default.

source/rust_verify/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub mod lifetime;
5757
mod lifetime_ast;
5858
mod lifetime_emit;
5959
mod lifetime_generate;
60-
pub mod places;
6160
pub mod profiler;
6261
mod resolve_traits;
6362
pub mod reveal_hide;

source/rust_verify/src/places.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)