@@ -30,14 +30,14 @@ use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceT
30
30
use crate :: const_eval:: DummyMachine ;
31
31
use crate :: { const_eval, errors} ;
32
32
33
- pub trait CompileTimeMachine < ' tcx , T > = Machine <
33
+ pub trait CompileTimeMachine < ' tcx > = Machine <
34
34
' tcx ,
35
- MemoryKind = T ,
35
+ MemoryKind = const_eval :: MemoryKind ,
36
36
Provenance = CtfeProvenance ,
37
37
ExtraFnVal = !,
38
38
FrameExtra = ( ) ,
39
39
AllocExtra = ( ) ,
40
- MemoryMap = FxIndexMap < AllocId , ( MemoryKind < T > , Allocation ) > ,
40
+ MemoryMap = FxIndexMap < AllocId , ( MemoryKind < const_eval :: MemoryKind > , Allocation ) > ,
41
41
> + HasStaticRootDefId ;
42
42
43
43
pub trait HasStaticRootDefId {
@@ -52,43 +52,14 @@ impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> {
52
52
}
53
53
}
54
54
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
-
84
55
/// Intern an allocation. Returns `Err` if the allocation does not exist in the local memory.
85
56
///
86
57
/// `mutability` can be used to force immutable interning: if it is `Mutability::Not`, the
87
58
/// allocation is interned immutably; if it is `Mutability::Mut`, then the allocation *must be*
88
59
/// already mutable (as a sanity check).
89
60
///
90
61
/// 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 > > (
92
63
ecx : & mut InterpCx < ' tcx , M > ,
93
64
alloc_id : AllocId ,
94
65
mutability : Mutability ,
@@ -102,16 +73,16 @@ fn intern_shallow<'tcx, T: CanIntern, M: CompileTimeMachine<'tcx, T>>(
102
73
} ;
103
74
104
75
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 {
107
78
// Attempting to intern a `const_allocate`d pointer that was not made global via
108
79
// `const_make_global`. We want to error here, but we have to first put the
109
80
// allocation back into the `alloc_map` to keep things in a consistent state.
110
81
ecx. memory . alloc_map . insert ( alloc_id, ( kind, alloc) ) ;
111
82
return Err ( InternError :: ConstAllocNotGlobal ) ;
112
83
}
113
- } ,
114
- MemoryKind :: Machine ( _ ) | MemoryKind :: Stack | MemoryKind :: CallerLocation => { }
84
+ }
85
+ MemoryKind :: Stack | MemoryKind :: CallerLocation => { }
115
86
}
116
87
117
88
// Set allocation mutability as appropriate. This is used by LLVM to put things into
@@ -204,7 +175,7 @@ pub enum InternError {
204
175
///
205
176
/// For `InternKind::Static` the root allocation will not be interned, but must be handled by the caller.
206
177
#[ 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 > > (
208
179
ecx : & mut InterpCx < ' tcx , M > ,
209
180
intern_kind : InternKind ,
210
181
ret : & MPlaceTy < ' tcx > ,
@@ -365,7 +336,7 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx, const_eval
365
336
366
337
/// Intern `ret`. This function assumes that `ret` references no other allocation.
367
338
#[ 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 > > (
369
340
ecx : & mut InterpCx < ' tcx , M > ,
370
341
alloc_id : AllocId ,
371
342
) -> InterpResult < ' tcx , ( ) > {
0 commit comments