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+ 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 > > {
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,15 @@ 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 : CompileTimeMachine < ' mir , ' tcx > > (
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 > > ,
6880) -> InterpResult < ' tcx , Option < IsStaticOrFn > > {
69- trace ! (
70- "InternVisitor::intern {:?} with {:?}" ,
71- alloc_id, mutability,
72- ) ;
81+ trace ! ( "InternVisitor::intern {:?} with {:?}" , alloc_id, mutability, ) ;
7382 // remove allocation
7483 let tcx = ecx. tcx ;
7584 let ( kind, mut alloc) = match ecx. memory . alloc_map . remove ( & alloc_id) {
@@ -130,7 +139,7 @@ fn intern_shallow<'rt, 'mir, 'tcx>(
130139 Ok ( None )
131140}
132141
133- impl < ' rt , ' mir , ' tcx > InternVisitor < ' rt , ' mir , ' tcx > {
142+ impl < ' rt , ' mir , ' tcx , M : CompileTimeMachine < ' mir , ' tcx > > InternVisitor < ' rt , ' mir , ' tcx , M > {
134143 fn intern_shallow (
135144 & mut self ,
136145 alloc_id : AllocId ,
@@ -148,15 +157,15 @@ impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
148157 }
149158}
150159
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 >
153162for
154- InternVisitor < ' rt , ' mir , ' tcx >
163+ InternVisitor < ' rt , ' mir , ' tcx , M >
155164{
156165 type V = MPlaceTy < ' tcx > ;
157166
158167 #[ inline( always) ]
159- fn ecx ( & self ) -> & CompileTimeEvalContext < ' mir , ' tcx > {
168+ fn ecx ( & self ) -> & InterpCx < ' mir , ' tcx , M > {
160169 & self . ecx
161170 }
162171
265274 }
266275}
267276
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 > ,
270279 // The `mutability` of the place, ignoring the type.
271280 place_mut : Option < hir:: Mutability > ,
272281 ret : MPlaceTy < ' tcx > ,
0 commit comments