Skip to content

Commit 2726a91

Browse files
committed
cache tag for vtable; fn_alloc's don't have a stack nor tag
1 parent 538e17a commit 2726a91

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/librustc_mir/interpret/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
8686
def_id,
8787
substs,
8888
).ok_or_else(|| InterpError::TooGeneric.into());
89-
let fn_ptr = self.memory.create_fn_alloc(instance?).with_default_tag();
89+
let fn_ptr = self.memory.create_fn_alloc(instance?);
9090
self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?;
9191
}
9292
_ => bug!("reify fn pointer on {:?}", src.layout.ty),
@@ -115,7 +115,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
115115
substs,
116116
ty::ClosureKind::FnOnce,
117117
);
118-
let fn_ptr = self.memory.create_fn_alloc(instance).with_default_tag();
118+
let fn_ptr = self.memory.create_fn_alloc(instance);
119119
let val = Immediate::Scalar(Scalar::Ptr(fn_ptr.into()).into());
120120
self.write_immediate(val, dest)?;
121121
}

src/librustc_mir/interpret/eval_context.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::ty::query::TyCtxtAt;
1515
use rustc_data_structures::indexed_vec::IndexVec;
1616
use rustc::mir::interpret::{
1717
ErrorHandled,
18-
GlobalId, Scalar, FrameInfo, AllocId,
18+
GlobalId, Scalar, Pointer, FrameInfo, AllocId,
1919
EvalResult, InterpError,
2020
truncate, sign_extend,
2121
};
@@ -43,7 +43,10 @@ pub struct InterpretCx<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'a, 'mir, 'tcx>> {
4343
pub(crate) stack: Vec<Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>>,
4444

4545
/// A cache for deduplicating vtables
46-
pub(super) vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), AllocId>,
46+
pub(super) vtables: FxHashMap<
47+
(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>),
48+
Pointer<M::PointerTag>
49+
>,
4750
}
4851

4952
/// A stack frame.

src/librustc_mir/interpret/memory.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
108108
}
109109
}
110110

111-
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer {
112-
Pointer::from(self.tcx.alloc_map.lock().create_fn_alloc(instance))
111+
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer<M::PointerTag> {
112+
// Default tag is okay because anyway you cannot access memory with this.
113+
Pointer::from(self.tcx.alloc_map.lock().create_fn_alloc(instance)).with_default_tag()
113114
}
114115

115116
pub fn allocate_static_bytes(&mut self, bytes: &[u8]) -> Pointer {

src/librustc_mir/interpret/traits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
2525
// always use the same vtable for the same (Type, Trait) combination.
2626
// That's not what happens in rustc, but emulating per-crate deduplication
2727
// does not sound like it actually makes anything any better.
28-
return Ok(Pointer::from(vtable).with_default_tag());
28+
return Ok(vtable);
2929
}
3030

3131
let methods = if let Some(poly_trait_ref) = poly_trait_ref {
@@ -56,7 +56,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
5656
let tcx = &*self.tcx;
5757

5858
let drop = crate::monomorphize::resolve_drop_in_place(*tcx, ty);
59-
let drop = self.memory.create_fn_alloc(drop).with_default_tag();
59+
let drop = self.memory.create_fn_alloc(drop);
6060
// no need to do any alignment checks on the memory accesses below, because we know the
6161
// allocation is correctly aligned as we created it above. Also we're only offsetting by
6262
// multiples of `ptr_align`, which means that it will stay aligned to `ptr_align`.
@@ -83,7 +83,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
8383
def_id,
8484
substs,
8585
).ok_or_else(|| InterpError::TooGeneric)?;
86-
let fn_ptr = self.memory.create_fn_alloc(instance).with_default_tag();
86+
let fn_ptr = self.memory.create_fn_alloc(instance);
8787
let method_ptr = vtable.offset(ptr_size * (3 + i as u64), self)?;
8888
self.memory
8989
.get_mut(method_ptr.alloc_id)?
@@ -92,7 +92,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
9292
}
9393

9494
self.memory.mark_immutable(vtable.alloc_id)?;
95-
assert!(self.vtables.insert((ty, poly_trait_ref), vtable.alloc_id).is_none());
95+
assert!(self.vtables.insert((ty, poly_trait_ref), vtable).is_none());
9696

9797
Ok(vtable)
9898
}

0 commit comments

Comments
 (0)