33//! After a const evaluation has computed a value, before we destroy the const evaluator's session
44//! memory, we need to extract all memory allocations to the global memory pool so they stay around.
55
6- use rustc:: ty:: { Ty , self } ;
7- use rustc:: mir:: interpret:: { InterpResult , ErrorHandled } ;
8- use rustc:: hir;
96use 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 } ;
1111
1212use syntax:: ast:: Mutability ;
1313
1414use super :: {
15- ValueVisitor , MemoryKind , AllocId , MPlaceTy , Scalar ,
15+ AllocId , Allocation , InterpCx , Machine , MemoryKind , MPlaceTy , Scalar , ValueVisitor ,
1616} ;
17- use crate :: const_eval:: { CompileTimeInterpreter , CompileTimeEvalContext } ;
1817
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+ {
2032 /// The ectx from which we intern.
21- ecx : & ' rt mut CompileTimeEvalContext < ' mir , ' tcx > ,
33+ ecx : & ' rt mut InterpCx < ' mir , ' tcx , M > ,
2234 /// Previously encountered safe references.
2335 ref_tracking : & ' rt mut RefTracking < ( MPlaceTy < ' tcx > , Mutability , InternMode ) > ,
2436 /// A list of all encountered allocations. After type-based interning, we traverse this list to
@@ -58,18 +70,28 @@ struct IsStaticOrFn;
5870/// `immutable` things might become mutable if `ty` is not frozen.
5971/// `ty` can be `None` if there is no potential interior mutability
6072/// 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 > ,
6375 leftover_allocations : & ' rt mut FxHashSet < AllocId > ,
6476 mode : InternMode ,
6577 alloc_id : AllocId ,
6678 mutability : Mutability ,
6779 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, ) ;
7395 // remove allocation
7496 let tcx = ecx. tcx ;
7597 let ( kind, mut alloc) = match ecx. memory . alloc_map . remove ( & alloc_id) {
@@ -130,7 +152,20 @@ fn intern_shallow<'rt, 'mir, 'tcx>(
130152 Ok ( None )
131153}
132154
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+ {
134169 fn intern_shallow (
135170 & mut self ,
136171 alloc_id : AllocId ,
@@ -148,15 +183,27 @@ impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
148183 }
149184}
150185
151- impl < ' rt , ' mir , ' tcx >
152- ValueVisitor < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > >
186+ impl < ' rt , ' mir , ' tcx , M >
187+ ValueVisitor < ' mir , ' tcx , M >
153188for
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+ > ,
155202{
156203 type V = MPlaceTy < ' tcx > ;
157204
158205 #[ inline( always) ]
159- fn ecx ( & self ) -> & CompileTimeEvalContext < ' mir , ' tcx > {
206+ fn ecx ( & self ) -> & InterpCx < ' mir , ' tcx , M > {
160207 & self . ecx
161208 }
162209
@@ -265,12 +312,25 @@ for
265312 }
266313}
267314
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 > ,
270317 // The `mutability` of the place, ignoring the type.
271318 place_mut : Option < hir:: Mutability > ,
272319 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+ {
274334 let tcx = ecx. tcx ;
275335 let ( base_mutability, base_intern_mode) = match place_mut {
276336 Some ( hir:: Mutability :: Immutable ) => ( Mutability :: Immutable , InternMode :: Static ) ,
0 commit comments