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
+ pub trait CompileTimeMachine < ' mir , ' tcx > =
19
+ Machine <
20
+ ' mir ,
21
+ ' tcx ,
22
+ MemoryKinds = !,
23
+ PointerTag = ( ) ,
24
+ ExtraFnVal = !,
25
+ FrameExtra = ( ) ,
26
+ MemoryExtra = ( ) ,
27
+ AllocExtra = ( ) ,
28
+ MemoryMap = FxHashMap < AllocId , ( MemoryKind < !> , Allocation ) > ,
29
+ > ;
30
+
31
+ struct InternVisitor < ' rt , ' mir , ' tcx , M : CompileTimeMachine < ' mir , ' tcx > > {
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,15 @@ 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 : CompileTimeMachine < ' mir , ' tcx > > (
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
80
) -> InterpResult < ' tcx , Option < IsStaticOrFn > > {
69
- trace ! (
70
- "InternVisitor::intern {:?} with {:?}" ,
71
- alloc_id, mutability,
72
- ) ;
81
+ trace ! ( "InternVisitor::intern {:?} with {:?}" , alloc_id, mutability, ) ;
73
82
// remove allocation
74
83
let tcx = ecx. tcx ;
75
84
let ( kind, mut alloc) = match ecx. memory . alloc_map . remove ( & alloc_id) {
@@ -130,7 +139,7 @@ fn intern_shallow<'rt, 'mir, 'tcx>(
130
139
Ok ( None )
131
140
}
132
141
133
- impl < ' rt , ' mir , ' tcx > InternVisitor < ' rt , ' mir , ' tcx > {
142
+ impl < ' rt , ' mir , ' tcx , M : CompileTimeMachine < ' mir , ' tcx > > InternVisitor < ' rt , ' mir , ' tcx , M > {
134
143
fn intern_shallow (
135
144
& mut self ,
136
145
alloc_id : AllocId ,
@@ -148,15 +157,15 @@ impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
148
157
}
149
158
}
150
159
151
- impl < ' rt , ' mir , ' tcx >
152
- ValueVisitor < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > >
160
+ impl < ' rt , ' mir , ' tcx , M : CompileTimeMachine < ' mir , ' tcx > >
161
+ ValueVisitor < ' mir , ' tcx , M >
153
162
for
154
- InternVisitor < ' rt , ' mir , ' tcx >
163
+ InternVisitor < ' rt , ' mir , ' tcx , M >
155
164
{
156
165
type V = MPlaceTy < ' tcx > ;
157
166
158
167
#[ inline( always) ]
159
- fn ecx ( & self ) -> & CompileTimeEvalContext < ' mir , ' tcx > {
168
+ fn ecx ( & self ) -> & InterpCx < ' mir , ' tcx , M > {
160
169
& self . ecx
161
170
}
162
171
265
274
}
266
275
}
267
276
268
- pub fn intern_const_alloc_recursive (
269
- ecx : & mut CompileTimeEvalContext < ' mir , ' tcx > ,
277
+ pub fn intern_const_alloc_recursive < M : CompileTimeMachine < ' mir , ' tcx > > (
278
+ ecx : & mut InterpCx < ' mir , ' tcx , M > ,
270
279
// The `mutability` of the place, ignoring the type.
271
280
place_mut : Option < hir:: Mutability > ,
272
281
ret : MPlaceTy < ' tcx > ,
0 commit comments