Skip to content

Commit ae9e9cb

Browse files
authored
Merge pull request #695 from RalfJung/stacked-borrows-2
Stacked borrows 2 (alpha 1)
2 parents 3e8bd45 + 39ecd05 commit ae9e9cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+763
-728
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ee621f42329069c296b4c2066b3743cc4ff0f369
1+
efe2f32a6b8217425f361ec7c206910c611c03ee

src/fn_call.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
1313
fn find_fn(
1414
&mut self,
1515
instance: ty::Instance<'tcx>,
16-
args: &[OpTy<'tcx, Borrow>],
17-
dest: Option<PlaceTy<'tcx, Borrow>>,
16+
args: &[OpTy<'tcx, Tag>],
17+
dest: Option<PlaceTy<'tcx, Tag>>,
1818
ret: Option<mir::BasicBlock>,
1919
) -> EvalResult<'tcx, Option<&'mir mir::Mir<'tcx>>> {
2020
let this = self.eval_context_mut();
@@ -55,8 +55,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
5555
fn emulate_foreign_item(
5656
&mut self,
5757
def_id: DefId,
58-
args: &[OpTy<'tcx, Borrow>],
59-
dest: Option<PlaceTy<'tcx, Borrow>>,
58+
args: &[OpTy<'tcx, Tag>],
59+
dest: Option<PlaceTy<'tcx, Tag>>,
6060
ret: Option<mir::BasicBlock>,
6161
) -> EvalResult<'tcx> {
6262
let this = self.eval_context_mut();
@@ -92,7 +92,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
9292
} else {
9393
let align = this.tcx.data_layout.pointer_align.abi;
9494
let ptr = this.memory_mut().allocate(Size::from_bytes(size), align, MiriMemoryKind::C.into());
95-
this.write_scalar(Scalar::Ptr(ptr.with_default_tag()), dest)?;
95+
this.write_scalar(Scalar::Ptr(ptr), dest)?;
9696
}
9797
}
9898
"calloc" => {
@@ -105,7 +105,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
105105
} else {
106106
let size = Size::from_bytes(bytes);
107107
let align = this.tcx.data_layout.pointer_align.abi;
108-
let ptr = this.memory_mut().allocate(size, align, MiriMemoryKind::C.into()).with_default_tag();
108+
let ptr = this.memory_mut().allocate(size, align, MiriMemoryKind::C.into());
109109
this.memory_mut().get_mut(ptr.alloc_id)?.write_repeat(tcx, ptr, 0, size)?;
110110
this.write_scalar(Scalar::Ptr(ptr), dest)?;
111111
}
@@ -132,7 +132,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
132132
Align::from_bytes(align).unwrap(),
133133
MiriMemoryKind::C.into()
134134
);
135-
this.write_scalar(Scalar::Ptr(ptr.with_default_tag()), ret.into())?;
135+
this.write_scalar(Scalar::Ptr(ptr), ret.into())?;
136136
}
137137
this.write_null(dest)?;
138138
}
@@ -162,8 +162,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
162162
Size::from_bytes(size),
163163
Align::from_bytes(align).unwrap(),
164164
MiriMemoryKind::Rust.into()
165-
)
166-
.with_default_tag();
165+
);
167166
this.write_scalar(Scalar::Ptr(ptr), dest)?;
168167
}
169168
"__rust_alloc_zeroed" => {
@@ -180,8 +179,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
180179
Size::from_bytes(size),
181180
Align::from_bytes(align).unwrap(),
182181
MiriMemoryKind::Rust.into()
183-
)
184-
.with_default_tag();
182+
);
185183
this.memory_mut()
186184
.get_mut(ptr.alloc_id)?
187185
.write_repeat(tcx, ptr, 0, Size::from_bytes(size))?;
@@ -222,7 +220,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
222220
Align::from_bytes(align).unwrap(),
223221
MiriMemoryKind::Rust.into(),
224222
)?;
225-
this.write_scalar(Scalar::Ptr(new_ptr.with_default_tag()), dest)?;
223+
this.write_scalar(Scalar::Ptr(new_ptr), dest)?;
226224
}
227225

228226
"syscall" => {
@@ -428,7 +426,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
428426
Size::from_bytes((value.len() + 1) as u64),
429427
Align::from_bytes(1).unwrap(),
430428
MiriMemoryKind::Env.into(),
431-
).with_default_tag();
429+
);
432430
{
433431
let alloc = this.memory_mut().get_mut(value_copy.alloc_id)?;
434432
alloc.write_bytes(tcx, value_copy, &value)?;
@@ -798,13 +796,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
798796
Ok(())
799797
}
800798

801-
fn write_null(&mut self, dest: PlaceTy<'tcx, Borrow>) -> EvalResult<'tcx> {
799+
fn write_null(&mut self, dest: PlaceTy<'tcx, Tag>) -> EvalResult<'tcx> {
802800
self.eval_context_mut().write_scalar(Scalar::from_int(0, dest.layout.size), dest)
803801
}
804802

805803
/// Evaluates the scalar at the specified path. Returns Some(val)
806804
/// if the path could be resolved, and None otherwise
807-
fn eval_path_scalar(&mut self, path: &[&str]) -> EvalResult<'tcx, Option<ScalarMaybeUndef<stacked_borrows::Borrow>>> {
805+
fn eval_path_scalar(&mut self, path: &[&str]) -> EvalResult<'tcx, Option<ScalarMaybeUndef<Tag>>> {
808806
let this = self.eval_context_mut();
809807
if let Ok(instance) = this.resolve_path(path) {
810808
let cid = GlobalId {

src/helpers.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
4747
/// will be true if this is frozen, false if this is in an `UnsafeCell`.
4848
fn visit_freeze_sensitive(
4949
&self,
50-
place: MPlaceTy<'tcx, Borrow>,
50+
place: MPlaceTy<'tcx, Tag>,
5151
size: Size,
52-
mut action: impl FnMut(Pointer<Borrow>, Size, bool) -> EvalResult<'tcx>,
52+
mut action: impl FnMut(Pointer<Tag>, Size, bool) -> EvalResult<'tcx>,
5353
) -> EvalResult<'tcx> {
5454
let this = self.eval_context_ref();
5555
trace!("visit_frozen(place={:?}, size={:?})", *place, size);
@@ -64,7 +64,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
6464
let mut end_ptr = place.ptr;
6565
// Called when we detected an `UnsafeCell` at the given offset and size.
6666
// Calls `action` and advances `end_ptr`.
67-
let mut unsafe_cell_action = |unsafe_cell_ptr: Scalar<Borrow>, unsafe_cell_size: Size| {
67+
let mut unsafe_cell_action = |unsafe_cell_ptr: Scalar<Tag>, unsafe_cell_size: Size| {
6868
if unsafe_cell_size != Size::ZERO {
6969
debug_assert_eq!(unsafe_cell_ptr.to_ptr().unwrap().alloc_id,
7070
end_ptr.to_ptr().unwrap().alloc_id);
@@ -120,7 +120,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
120120
/// Visiting the memory covered by a `MemPlace`, being aware of
121121
/// whether we are inside an `UnsafeCell` or not.
122122
struct UnsafeCellVisitor<'ecx, 'a, 'mir, 'tcx, F>
123-
where F: FnMut(MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx>
123+
where F: FnMut(MPlaceTy<'tcx, Tag>) -> EvalResult<'tcx>
124124
{
125125
ecx: &'ecx MiriEvalContext<'a, 'mir, 'tcx>,
126126
unsafe_cell_action: F,
@@ -131,17 +131,17 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
131131
for
132132
UnsafeCellVisitor<'ecx, 'a, 'mir, 'tcx, F>
133133
where
134-
F: FnMut(MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx>
134+
F: FnMut(MPlaceTy<'tcx, Tag>) -> EvalResult<'tcx>
135135
{
136-
type V = MPlaceTy<'tcx, Borrow>;
136+
type V = MPlaceTy<'tcx, Tag>;
137137

138138
#[inline(always)]
139139
fn ecx(&self) -> &MiriEvalContext<'a, 'mir, 'tcx> {
140140
&self.ecx
141141
}
142142

143143
// Hook to detect `UnsafeCell`.
144-
fn visit_value(&mut self, v: MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx>
144+
fn visit_value(&mut self, v: MPlaceTy<'tcx, Tag>) -> EvalResult<'tcx>
145145
{
146146
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);
147147
let is_unsafe_cell = match v.layout.ty.sty {
@@ -163,8 +163,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
163163
// Make sure we visit aggregrates in increasing offset order.
164164
fn visit_aggregate(
165165
&mut self,
166-
place: MPlaceTy<'tcx, Borrow>,
167-
fields: impl Iterator<Item=EvalResult<'tcx, MPlaceTy<'tcx, Borrow>>>,
166+
place: MPlaceTy<'tcx, Tag>,
167+
fields: impl Iterator<Item=EvalResult<'tcx, MPlaceTy<'tcx, Tag>>>,
168168
) -> EvalResult<'tcx> {
169169
match place.layout.fields {
170170
layout::FieldPlacement::Array { .. } => {
@@ -174,7 +174,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
174174
}
175175
layout::FieldPlacement::Arbitrary { .. } => {
176176
// Gather the subplaces and sort them before visiting.
177-
let mut places = fields.collect::<EvalResult<'tcx, Vec<MPlaceTy<'tcx, Borrow>>>>()?;
177+
let mut places = fields.collect::<EvalResult<'tcx, Vec<MPlaceTy<'tcx, Tag>>>>()?;
178178
places.sort_by_key(|place| place.ptr.get_ptr_offset(self.ecx()));
179179
self.walk_aggregate(place, places.into_iter().map(Ok))
180180
}
@@ -186,7 +186,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
186186
}
187187

188188
// We have to do *something* for unions.
189-
fn visit_union(&mut self, v: MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx>
189+
fn visit_union(&mut self, v: MPlaceTy<'tcx, Tag>) -> EvalResult<'tcx>
190190
{
191191
// With unions, we fall back to whatever the type says, to hopefully be consistent
192192
// with LLVM IR.
@@ -200,7 +200,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
200200
}
201201

202202
// We should never get to a primitive, but always short-circuit somewhere above.
203-
fn visit_primitive(&mut self, _v: MPlaceTy<'tcx, Borrow>) -> EvalResult<'tcx>
203+
fn visit_primitive(&mut self, _v: MPlaceTy<'tcx, Tag>) -> EvalResult<'tcx>
204204
{
205205
bug!("we should always short-circuit before coming to a primitive")
206206
}

src/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc::ty::layout::{self, LayoutOf, Size};
44
use rustc::ty;
55

66
use crate::{
7-
PlaceTy, OpTy, ImmTy, Immediate, Scalar, ScalarMaybeUndef, Borrow,
7+
PlaceTy, OpTy, ImmTy, Immediate, Scalar, ScalarMaybeUndef, Tag,
88
OperatorEvalContextExt
99
};
1010

@@ -13,8 +13,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
1313
fn call_intrinsic(
1414
&mut self,
1515
instance: ty::Instance<'tcx>,
16-
args: &[OpTy<'tcx, Borrow>],
17-
dest: PlaceTy<'tcx, Borrow>,
16+
args: &[OpTy<'tcx, Tag>],
17+
dest: PlaceTy<'tcx, Tag>,
1818
) -> EvalResult<'tcx> {
1919
let this = self.eval_context_mut();
2020
if this.emulate_intrinsic(instance, args, dest)? {

0 commit comments

Comments
 (0)