@@ -30,14 +30,14 @@ use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceT
3030use crate :: const_eval:: DummyMachine ;
3131use crate :: { const_eval, errors} ;
3232
33- pub trait CompileTimeMachine < ' tcx , T > = Machine <
33+ pub trait CompileTimeMachine < ' tcx > = Machine <
3434 ' tcx ,
35- MemoryKind = T ,
35+ MemoryKind = const_eval :: MemoryKind ,
3636 Provenance = CtfeProvenance ,
3737 ExtraFnVal = !,
3838 FrameExtra = ( ) ,
3939 AllocExtra = ( ) ,
40- MemoryMap = FxIndexMap < AllocId , ( MemoryKind < T > , Allocation ) > ,
40+ MemoryMap = FxIndexMap < AllocId , ( MemoryKind < const_eval :: MemoryKind > , Allocation ) > ,
4141 > + HasStaticRootDefId ;
4242
4343pub trait HasStaticRootDefId {
@@ -52,43 +52,14 @@ impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> {
5252 }
5353}
5454
55- pub enum DisallowInternReason {
56- ConstHeap ,
57- }
58-
59- /// A trait for controlling whether memory allocated in the interpreter can be interned.
60- ///
61- /// This prevents us from interning `const_allocate` pointers that have not been made
62- /// global through `const_make_global`.
63- pub trait CanIntern : Copy {
64- fn disallows_intern ( & self ) -> Option < DisallowInternReason > ;
65- }
66-
67- impl CanIntern for const_eval:: MemoryKind {
68- fn disallows_intern ( & self ) -> Option < DisallowInternReason > {
69- match self {
70- const_eval:: MemoryKind :: Heap { was_made_global : false } => {
71- Some ( DisallowInternReason :: ConstHeap )
72- }
73- const_eval:: MemoryKind :: Heap { was_made_global : true } => None ,
74- }
75- }
76- }
77-
78- impl CanIntern for ! {
79- fn disallows_intern ( & self ) -> Option < DisallowInternReason > {
80- * self
81- }
82- }
83-
8455/// Intern an allocation. Returns `Err` if the allocation does not exist in the local memory.
8556///
8657/// `mutability` can be used to force immutable interning: if it is `Mutability::Not`, the
8758/// allocation is interned immutably; if it is `Mutability::Mut`, then the allocation *must be*
8859/// already mutable (as a sanity check).
8960///
9061/// Returns an iterator over all relocations referred to by this allocation.
91- fn intern_shallow < ' tcx , T : CanIntern , M : CompileTimeMachine < ' tcx , T > > (
62+ fn intern_shallow < ' tcx , M : CompileTimeMachine < ' tcx > > (
9263 ecx : & mut InterpCx < ' tcx , M > ,
9364 alloc_id : AllocId ,
9465 mutability : Mutability ,
@@ -102,16 +73,16 @@ fn intern_shallow<'tcx, T: CanIntern, M: CompileTimeMachine<'tcx, T>>(
10273 } ;
10374
10475 match kind {
105- MemoryKind :: Machine ( x ) if let Some ( reason ) = x . disallows_intern ( ) => match reason {
106- DisallowInternReason :: ConstHeap => {
76+ MemoryKind :: Machine ( const_eval :: MemoryKind :: Heap { was_made_global } ) => {
77+ if !was_made_global {
10778 // Attempting to intern a `const_allocate`d pointer that was not made global via
10879 // `const_make_global`. We want to error here, but we have to first put the
10980 // allocation back into the `alloc_map` to keep things in a consistent state.
11081 ecx. memory . alloc_map . insert ( alloc_id, ( kind, alloc) ) ;
11182 return Err ( InternError :: ConstAllocNotGlobal ) ;
11283 }
113- } ,
114- MemoryKind :: Machine ( _ ) | MemoryKind :: Stack | MemoryKind :: CallerLocation => { }
84+ }
85+ MemoryKind :: Stack | MemoryKind :: CallerLocation => { }
11586 }
11687
11788 // Set allocation mutability as appropriate. This is used by LLVM to put things into
@@ -204,7 +175,7 @@ pub enum InternError {
204175///
205176/// For `InternKind::Static` the root allocation will not be interned, but must be handled by the caller.
206177#[ instrument( level = "debug" , skip( ecx) ) ]
207- pub fn intern_const_alloc_recursive < ' tcx , M : CompileTimeMachine < ' tcx , const_eval :: MemoryKind > > (
178+ pub fn intern_const_alloc_recursive < ' tcx , M : CompileTimeMachine < ' tcx > > (
208179 ecx : & mut InterpCx < ' tcx , M > ,
209180 intern_kind : InternKind ,
210181 ret : & MPlaceTy < ' tcx > ,
@@ -365,7 +336,7 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval
365336
366337/// Intern `ret`. This function assumes that `ret` references no other allocation.
367338#[ instrument( level = "debug" , skip( ecx) ) ]
368- pub fn intern_const_alloc_for_constprop < ' tcx , T : CanIntern , M : CompileTimeMachine < ' tcx , T > > (
339+ pub fn intern_const_alloc_for_constprop < ' tcx , M : CompileTimeMachine < ' tcx > > (
369340 ecx : & mut InterpCx < ' tcx , M > ,
370341 alloc_id : AllocId ,
371342) -> InterpResult < ' tcx , ( ) > {
0 commit comments