Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6851060

Browse files
committed
use PlaceTy visitor
1 parent 416cddb commit 6851060

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/stacked_borrows/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,17 +1037,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10371037
// Raw pointers need to be enabled.
10381038
ty::RawPtr(tym) if kind == RetagKind::Raw =>
10391039
Some((RefKind::Raw { mutable: tym.mutbl == Mutability::Mut }, false)),
1040-
// Boxes are handled separately due to that allocator situation.
1040+
// Boxes are handled separately due to that allocator situation,
1041+
// see the visitor below.
10411042
_ => None,
10421043
}
10431044
}
10441045

1045-
// We need a visitor to visit all references. However, that requires
1046-
// a `MPlaceTy` (or `OpTy`), so we have a fast path for reference types that
1047-
// avoids allocating.
1048-
1046+
// For some types we can do the work without starting up the visitor infrastructure.
10491047
if let Some((ref_kind, protector)) = qualify(place.layout.ty, kind) {
1050-
// Fast path.
10511048
let val = this.read_immediate(&this.place_to_op(place)?)?;
10521049
let val = this.retag_reference(&val, ref_kind, protector)?;
10531050
this.write_immediate(*val, place)?;
@@ -1077,11 +1074,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10771074
) {
10781075
return Ok(());
10791076
}
1080-
// Now go visit this thing.
1081-
let place = this.force_allocation(place)?;
10821077

1078+
// Now go visit this thing.
10831079
let mut visitor = RetagVisitor { ecx: this, kind };
1084-
return visitor.visit_value(&place);
1080+
return visitor.visit_value(place);
10851081

10861082
// The actual visitor.
10871083
struct RetagVisitor<'ecx, 'mir, 'tcx> {
@@ -1091,36 +1087,36 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10911087
impl<'ecx, 'mir, 'tcx> MutValueVisitor<'mir, 'tcx, Evaluator<'mir, 'tcx>>
10921088
for RetagVisitor<'ecx, 'mir, 'tcx>
10931089
{
1094-
type V = MPlaceTy<'tcx, Tag>;
1090+
type V = PlaceTy<'tcx, Tag>;
10951091

10961092
#[inline(always)]
10971093
fn ecx(&mut self) -> &mut MiriEvalContext<'mir, 'tcx> {
10981094
self.ecx
10991095
}
11001096

1101-
fn visit_box(&mut self, place: &MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
1097+
fn visit_box(&mut self, place: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
11021098
// Boxes do not get a protector: protectors reflect that references outlive the call
11031099
// they were passed in to; that's just not the case for boxes.
11041100
let (ref_kind, protector) = (RefKind::Unique { two_phase: false }, false);
1105-
1106-
let val = self.ecx.read_immediate(&place.into())?;
1101+
let val = self.ecx.read_immediate(&self.ecx.place_to_op(place)?)?;
11071102
let val = self.ecx.retag_reference(&val, ref_kind, protector)?;
1108-
self.ecx.write_immediate(*val, &place.into())?;
1103+
self.ecx.write_immediate(*val, place)?;
11091104
Ok(())
11101105
}
11111106

1112-
fn visit_value(&mut self, place: &MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
1107+
fn visit_value(&mut self, place: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
11131108
if let Some((ref_kind, protector)) = qualify(place.layout.ty, self.kind) {
1114-
let val = self.ecx.read_immediate(&place.into())?;
1109+
let val = self.ecx.read_immediate(&self.ecx.place_to_op(place)?)?;
11151110
let val = self.ecx.retag_reference(&val, ref_kind, protector)?;
1116-
self.ecx.write_immediate(*val, &place.into())?;
1111+
self.ecx.write_immediate(*val, place)?;
11171112
} else if matches!(place.layout.ty.kind(), ty::RawPtr(..)) {
11181113
// Wide raw pointers *do* have fields and their types are strange.
11191114
// vtables have a type like `&[*const (); 3]` or so!
11201115
// Do *not* recurse into them.
1121-
// (No need to worry about wide references or boxes, those always "qualify".)
1116+
// (No need to worry about wide references, those always "qualify". And Boxes
1117+
// are handles specially by the visitor anyway.)
11221118
} else {
1123-
// Maybe we need to go deeper.
1119+
// Recurse deeper.
11241120
self.walk_value(place)?;
11251121
}
11261122
Ok(())

0 commit comments

Comments
 (0)