3
3
//! After a const evaluation has computed a value, before we destroy the const evaluator's session
4
4
//! memory, we need to extract all memory allocations to the global memory pool so they stay around.
5
5
6
- use rustc:: ty:: { Ty , self } ;
7
- use rustc:: mir:: interpret:: { InterpResult , ErrorHandled } ;
8
- use rustc:: hir;
9
6
use super :: validity:: RefTracking ;
10
- use rustc_data_structures:: fx:: FxHashSet ;
7
+ use rustc:: hir;
8
+ use rustc:: mir:: interpret:: { ErrorHandled , InterpResult } ;
9
+ use rustc:: ty:: { self , Ty } ;
10
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
11
11
12
12
use syntax:: ast:: Mutability ;
13
13
14
14
use super :: {
15
- ValueVisitor , MemoryKind , AllocId , MPlaceTy , Scalar ,
15
+ AllocId , Allocation , InterpCx , Machine , MemoryKind , MPlaceTy , Scalar , ValueVisitor ,
16
16
} ;
17
- use crate :: const_eval:: { CompileTimeInterpreter , CompileTimeEvalContext } ;
18
17
19
- struct InternVisitor < ' rt , ' mir , ' tcx > {
18
+ struct InternVisitor < ' rt , ' mir , ' tcx , M >
19
+ where
20
+ M : Machine <
21
+ ' mir ,
22
+ ' tcx ,
23
+ MemoryKinds = !,
24
+ PointerTag = ( ) ,
25
+ ExtraFnVal = !,
26
+ FrameExtra = ( ) ,
27
+ MemoryExtra = ( ) ,
28
+ AllocExtra = ( ) ,
29
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
30
+ > ,
31
+ {
20
32
/// The ectx from which we intern.
21
- ecx : & ' rt mut CompileTimeEvalContext < ' mir , ' tcx > ,
33
+ ecx : & ' rt mut InterpCx < ' mir , ' tcx , M > ,
22
34
/// Previously encountered safe references.
23
35
ref_tracking : & ' rt mut RefTracking < ( MPlaceTy < ' tcx > , Mutability , InternMode ) > ,
24
36
/// A list of all encountered allocations. After type-based interning, we traverse this list to
@@ -58,18 +70,28 @@ struct IsStaticOrFn;
58
70
/// `immutable` things might become mutable if `ty` is not frozen.
59
71
/// `ty` can be `None` if there is no potential interior mutability
60
72
/// to account for (e.g. for vtables).
61
- fn intern_shallow < ' rt , ' mir , ' tcx > (
62
- ecx : & ' rt mut CompileTimeEvalContext < ' mir , ' tcx > ,
73
+ fn intern_shallow < ' rt , ' mir , ' tcx , M > (
74
+ ecx : & ' rt mut InterpCx < ' mir , ' tcx , M > ,
63
75
leftover_allocations : & ' rt mut FxHashSet < AllocId > ,
64
76
mode : InternMode ,
65
77
alloc_id : AllocId ,
66
78
mutability : Mutability ,
67
79
ty : Option < Ty < ' tcx > > ,
68
- ) -> InterpResult < ' tcx , Option < IsStaticOrFn > > {
69
- trace ! (
70
- "InternVisitor::intern {:?} with {:?}" ,
71
- alloc_id, mutability,
72
- ) ;
80
+ ) -> InterpResult < ' tcx , Option < IsStaticOrFn > >
81
+ where
82
+ M : Machine <
83
+ ' mir ,
84
+ ' tcx ,
85
+ MemoryKinds = !,
86
+ PointerTag = ( ) ,
87
+ ExtraFnVal = !,
88
+ FrameExtra = ( ) ,
89
+ MemoryExtra = ( ) ,
90
+ AllocExtra = ( ) ,
91
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
92
+ > ,
93
+ {
94
+ trace ! ( "InternVisitor::intern {:?} with {:?}" , alloc_id, mutability, ) ;
73
95
// remove allocation
74
96
let tcx = ecx. tcx ;
75
97
let ( kind, mut alloc) = match ecx. memory . alloc_map . remove ( & alloc_id) {
@@ -130,7 +152,20 @@ fn intern_shallow<'rt, 'mir, 'tcx>(
130
152
Ok ( None )
131
153
}
132
154
133
- impl < ' rt , ' mir , ' tcx > InternVisitor < ' rt , ' mir , ' tcx > {
155
+ impl < ' rt , ' mir , ' tcx , M > InternVisitor < ' rt , ' mir , ' tcx , M >
156
+ where
157
+ M : Machine <
158
+ ' mir ,
159
+ ' tcx ,
160
+ MemoryKinds = !,
161
+ PointerTag = ( ) ,
162
+ ExtraFnVal = !,
163
+ FrameExtra = ( ) ,
164
+ MemoryExtra = ( ) ,
165
+ AllocExtra = ( ) ,
166
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
167
+ > ,
168
+ {
134
169
fn intern_shallow (
135
170
& mut self ,
136
171
alloc_id : AllocId ,
@@ -148,15 +183,27 @@ impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
148
183
}
149
184
}
150
185
151
- impl < ' rt , ' mir , ' tcx >
152
- ValueVisitor < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > >
186
+ impl < ' rt , ' mir , ' tcx , M >
187
+ ValueVisitor < ' mir , ' tcx , M >
153
188
for
154
- InternVisitor < ' rt , ' mir , ' tcx >
189
+ InternVisitor < ' rt , ' mir , ' tcx , M >
190
+ where
191
+ M : Machine <
192
+ ' mir ,
193
+ ' tcx ,
194
+ MemoryKinds = !,
195
+ PointerTag = ( ) ,
196
+ ExtraFnVal = !,
197
+ FrameExtra = ( ) ,
198
+ MemoryExtra = ( ) ,
199
+ AllocExtra = ( ) ,
200
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
201
+ > ,
155
202
{
156
203
type V = MPlaceTy < ' tcx > ;
157
204
158
205
#[ inline( always) ]
159
- fn ecx ( & self ) -> & CompileTimeEvalContext < ' mir , ' tcx > {
206
+ fn ecx ( & self ) -> & InterpCx < ' mir , ' tcx , M > {
160
207
& self . ecx
161
208
}
162
209
@@ -265,12 +312,25 @@ for
265
312
}
266
313
}
267
314
268
- pub fn intern_const_alloc_recursive (
269
- ecx : & mut CompileTimeEvalContext < ' mir , ' tcx > ,
315
+ pub fn intern_const_alloc_recursive < M > (
316
+ ecx : & mut InterpCx < ' mir , ' tcx , M > ,
270
317
// The `mutability` of the place, ignoring the type.
271
318
place_mut : Option < hir:: Mutability > ,
272
319
ret : MPlaceTy < ' tcx > ,
273
- ) -> InterpResult < ' tcx > {
320
+ ) -> InterpResult < ' tcx >
321
+ where
322
+ M : Machine <
323
+ ' mir ,
324
+ ' tcx ,
325
+ MemoryKinds = !,
326
+ PointerTag = ( ) ,
327
+ ExtraFnVal = !,
328
+ FrameExtra = ( ) ,
329
+ MemoryExtra = ( ) ,
330
+ AllocExtra = ( ) ,
331
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
332
+ > ,
333
+ {
274
334
let tcx = ecx. tcx ;
275
335
let ( base_mutability, base_intern_mode) = match place_mut {
276
336
Some ( hir:: Mutability :: Immutable ) => ( Mutability :: Immutable , InternMode :: Static ) ,
0 commit comments