don't do any work towards ptr provenance in const mode
This commit is contained in:
parent
2af11f7433
commit
c885d8b41e
4 changed files with 13 additions and 5 deletions
|
@ -348,6 +348,7 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
|
||||||
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
|
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
|
||||||
|
|
||||||
const STATIC_KIND: Option<!> = None; // no copying of statics allowed
|
const STATIC_KIND: Option<!> = None; // no copying of statics allowed
|
||||||
|
const ENABLE_PTR_TRACKING_HOOKS: bool = false; // we don't have no provenance
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
|
fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
|
||||||
|
|
|
@ -47,7 +47,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
|
||||||
Misc => {
|
Misc => {
|
||||||
let src = self.read_value(src)?;
|
let src = self.read_value(src)?;
|
||||||
|
|
||||||
if src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr() {
|
if M::ENABLE_PTR_TRACKING_HOOKS &&
|
||||||
|
src.layout.ty.is_region_ptr() && dest.layout.ty.is_unsafe_ptr()
|
||||||
|
{
|
||||||
// For the purpose of the "ptr tag hooks", treat this as creating
|
// For the purpose of the "ptr tag hooks", treat this as creating
|
||||||
// a new, raw reference.
|
// a new, raw reference.
|
||||||
let place = self.ref_to_mplace(src)?;
|
let place = self.ref_to_mplace(src)?;
|
||||||
|
|
|
@ -101,6 +101,11 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
|
||||||
/// that is added to the memory so that the work is not done twice.
|
/// that is added to the memory so that the work is not done twice.
|
||||||
const STATIC_KIND: Option<Self::MemoryKinds>;
|
const STATIC_KIND: Option<Self::MemoryKinds>;
|
||||||
|
|
||||||
|
/// As an optimization, you can prevent the pointer tracking hooks from ever being
|
||||||
|
/// called. You should only do this if you do not care about provenance tracking.
|
||||||
|
/// This controls the `tag_reference` and `tag_dereference` hooks.
|
||||||
|
const ENABLE_PTR_TRACKING_HOOKS: bool;
|
||||||
|
|
||||||
/// Whether to enforce the validity invariant
|
/// Whether to enforce the validity invariant
|
||||||
fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
|
fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
|
||||||
|
|
||||||
|
|
|
@ -265,12 +265,12 @@ where
|
||||||
val: ValTy<'tcx, M::PointerTag>,
|
val: ValTy<'tcx, M::PointerTag>,
|
||||||
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
|
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
|
||||||
let ptr = match val.to_scalar_ptr()? {
|
let ptr = match val.to_scalar_ptr()? {
|
||||||
Scalar::Ptr(ptr) => {
|
Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
|
||||||
// Machine might want to track the `*` operator
|
// Machine might want to track the `*` operator
|
||||||
let tag = M::tag_dereference(self, ptr, val.layout.ty)?;
|
let tag = M::tag_dereference(self, ptr, val.layout.ty)?;
|
||||||
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
|
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
|
||||||
}
|
}
|
||||||
scalar @ Scalar::Bits { .. } => scalar,
|
other => other,
|
||||||
};
|
};
|
||||||
|
|
||||||
let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
|
let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
|
||||||
|
@ -294,14 +294,14 @@ where
|
||||||
borrow_kind: Option<mir::BorrowKind>,
|
borrow_kind: Option<mir::BorrowKind>,
|
||||||
) -> EvalResult<'tcx, Value<M::PointerTag>> {
|
) -> EvalResult<'tcx, Value<M::PointerTag>> {
|
||||||
let ptr = match place.ptr {
|
let ptr = match place.ptr {
|
||||||
Scalar::Ptr(ptr) => {
|
Scalar::Ptr(ptr) if M::ENABLE_PTR_TRACKING_HOOKS => {
|
||||||
// Machine might want to track the `&` operator
|
// Machine might want to track the `&` operator
|
||||||
let (size, _) = self.size_and_align_of_mplace(place)?
|
let (size, _) = self.size_and_align_of_mplace(place)?
|
||||||
.expect("create_ref cannot determine size");
|
.expect("create_ref cannot determine size");
|
||||||
let tag = M::tag_reference(self, ptr, place.layout.ty, size, borrow_kind)?;
|
let tag = M::tag_reference(self, ptr, place.layout.ty, size, borrow_kind)?;
|
||||||
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
|
Scalar::Ptr(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
|
||||||
},
|
},
|
||||||
scalar @ Scalar::Bits { .. } => scalar,
|
other => other,
|
||||||
};
|
};
|
||||||
Ok(match place.meta {
|
Ok(match place.meta {
|
||||||
None => Value::Scalar(ptr.into()),
|
None => Value::Scalar(ptr.into()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue