Skip to content

Commit c885d8b

Browse files
committed
don't do any work towards ptr provenance in const mode
1 parent 2af11f7 commit c885d8b

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/librustc_mir/const_eval.rs

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
348348
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
349349

350350
const STATIC_KIND: Option<!> = None; // no copying of statics allowed
351+
const ENABLE_PTR_TRACKING_HOOKS: bool = false; // we don't have no provenance
351352

352353
#[inline(always)]
353354
fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {

src/librustc_mir/interpret/cast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
4747
Misc => {
4848
let src = self.read_value(src)?;
4949

50-
if src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr() {
50+
if M::ENABLE_PTR_TRACKING_HOOKS &&
51+
src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr()
52+
{
5153
// For the purpose of the "ptr tag hooks", treat this as creating
5254
// a new, raw reference.
5355
let place = self.ref_to_mplace(src)?;

src/librustc_mir/interpret/machine.rs

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
101101
/// that is added to the memory so that the work is not done twice.
102102
const STATIC_KIND: Option<Self::MemoryKinds>;
103103

104+
/// As an optimization, you can prevent the pointer tracking hooks from ever being
105+
/// called. You should only do this if you do not care about provenance tracking.
106+
/// This controls the `tag_reference` and `tag_dereference` hooks.
107+
const ENABLE_PTR_TRACKING_HOOKS: bool;
108+
104109
/// Whether to enforce the validity invariant
105110
fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
106111

src/librustc_mir/interpret/place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ where
265265
val: ValTy<'tcx, M::PointerTag>,
266266
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
267267
let ptr = match val.to_scalar_ptr()? {
268-
Scalar::Ptr(ptr) => {
268+
Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
269269
// Machine might want to track the `*` operator
270270
let tag = M::tag_dereference(self, ptr, val.layout.ty)?;
271271
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
272272
}
273-
scalar @ Scalar::Bits { .. } => scalar,
273+
other => other,
274274
};
275275

276276
let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
@@ -294,14 +294,14 @@ where
294294
borrow_kind: Option<mir::BorrowKind>,
295295
) -> EvalResult<'tcx, Value<M::PointerTag>> {
296296
let ptr = match place.ptr {
297-
Scalar::Ptr(ptr) => {
297+
Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
298298
// Machine might want to track the `&` operator
299299
let (size, _) = self.size_and_align_of_mplace(place)?
300300
.expect("create_ref cannot determine size");
301301
let tag = M::tag_reference(self, ptr, place.layout.ty, size, borrow_kind)?;
302302
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
303303
},
304-
scalar @ Scalar::Bits { .. } => scalar,
304+
other => other,
305305
};
306306
Ok(match place.meta {
307307
None => Value::Scalar(ptr.into()),

0 commit comments

Comments
 (0)