@@ -18,7 +18,7 @@ use super::validity::RefTracking;
18
18
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
19
19
use rustc_errors:: ErrorGuaranteed ;
20
20
use rustc_hir as hir;
21
- use rustc_middle:: mir:: interpret:: InterpResult ;
21
+ use rustc_middle:: mir:: interpret:: { CtfeProvenance , InterpResult } ;
22
22
use rustc_middle:: ty:: { self , layout:: TyAndLayout , Ty } ;
23
23
24
24
use rustc_ast:: Mutability ;
@@ -34,7 +34,7 @@ pub trait CompileTimeMachine<'mir, 'tcx: 'mir, T> = Machine<
34
34
' mir ,
35
35
' tcx ,
36
36
MemoryKind = T ,
37
- Provenance = AllocId ,
37
+ Provenance = CtfeProvenance ,
38
38
ExtraFnVal = !,
39
39
FrameExtra = ( ) ,
40
40
AllocExtra = ( ) ,
@@ -135,7 +135,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
135
135
alloc. mutability = Mutability :: Not ;
136
136
} ;
137
137
// link the alloc id to the actual allocation
138
- leftover_allocations. extend ( alloc. provenance ( ) . ptrs ( ) . iter ( ) . map ( |& ( _, alloc_id ) | alloc_id) ) ;
138
+ leftover_allocations. extend ( alloc. provenance ( ) . ptrs ( ) . iter ( ) . map ( |& ( _, prov ) | prov . alloc_id ( ) ) ) ;
139
139
let alloc = tcx. mk_const_alloc ( alloc) ;
140
140
tcx. set_alloc_id_memory ( alloc_id, alloc) ;
141
141
None
@@ -178,10 +178,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
178
178
tcx. struct_tail_erasing_lifetimes ( referenced_ty, self . ecx . param_env ) . kind ( )
179
179
{
180
180
let ptr = mplace. meta ( ) . unwrap_meta ( ) . to_pointer ( & tcx) ?;
181
- if let Some ( alloc_id ) = ptr. provenance {
181
+ if let Some ( prov ) = ptr. provenance {
182
182
// Explicitly choose const mode here, since vtables are immutable, even
183
183
// if the reference of the fat pointer is mutable.
184
- self . intern_shallow ( alloc_id, InternMode :: Const , None ) ;
184
+ self . intern_shallow ( prov . alloc_id ( ) , InternMode :: Const , None ) ;
185
185
} else {
186
186
// Validation will error (with a better message) on an invalid vtable pointer.
187
187
// Let validation show the error message, but make sure it *does* error.
@@ -191,7 +191,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
191
191
}
192
192
// Check if we have encountered this pointer+layout combination before.
193
193
// Only recurse for allocation-backed pointers.
194
- if let Some ( alloc_id ) = mplace. ptr ( ) . provenance {
194
+ if let Some ( prov ) = mplace. ptr ( ) . provenance {
195
195
// Compute the mode with which we intern this. Our goal here is to make as many
196
196
// statics as we can immutable so they can be placed in read-only memory by LLVM.
197
197
let ref_mode = match self . mode {
@@ -234,7 +234,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
234
234
InternMode :: Const
235
235
}
236
236
} ;
237
- match self . intern_shallow ( alloc_id, ref_mode, Some ( referenced_ty) ) {
237
+ match self . intern_shallow ( prov . alloc_id ( ) , ref_mode, Some ( referenced_ty) ) {
238
238
// No need to recurse, these are interned already and statics may have
239
239
// cycles, so we don't want to recurse there
240
240
Some ( IsStaticOrFn ) => { }
@@ -353,7 +353,7 @@ pub fn intern_const_alloc_recursive<
353
353
leftover_allocations,
354
354
// The outermost allocation must exist, because we allocated it with
355
355
// `Memory::allocate`.
356
- ret. ptr ( ) . provenance . unwrap ( ) ,
356
+ ret. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ,
357
357
base_intern_mode,
358
358
Some ( ret. layout . ty ) ,
359
359
) ;
@@ -431,7 +431,8 @@ pub fn intern_const_alloc_recursive<
431
431
}
432
432
let alloc = tcx. mk_const_alloc ( alloc) ;
433
433
tcx. set_alloc_id_memory ( alloc_id, alloc) ;
434
- for & ( _, alloc_id) in alloc. inner ( ) . provenance ( ) . ptrs ( ) . iter ( ) {
434
+ for & ( _, prov) in alloc. inner ( ) . provenance ( ) . ptrs ( ) . iter ( ) {
435
+ let alloc_id = prov. alloc_id ( ) ;
435
436
if leftover_allocations. insert ( alloc_id) {
436
437
todo. push ( alloc_id) ;
437
438
}
@@ -503,10 +504,11 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
503
504
// `allocate` picks a fresh AllocId that we will associate with its data below.
504
505
let dest = self . allocate ( layout, MemoryKind :: Stack ) ?;
505
506
f ( self , & dest. clone ( ) . into ( ) ) ?;
506
- let mut alloc = self . memory . alloc_map . remove ( & dest. ptr ( ) . provenance . unwrap ( ) ) . unwrap ( ) . 1 ;
507
+ let mut alloc =
508
+ self . memory . alloc_map . remove ( & dest. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ) . unwrap ( ) . 1 ;
507
509
alloc. mutability = Mutability :: Not ;
508
510
let alloc = self . tcx . mk_const_alloc ( alloc) ;
509
- let alloc_id = dest. ptr ( ) . provenance . unwrap ( ) ; // this was just allocated, it must have provenance
511
+ let alloc_id = dest. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ; // this was just allocated, it must have provenance
510
512
self . tcx . set_alloc_id_memory ( alloc_id, alloc) ;
511
513
Ok ( alloc_id)
512
514
}
0 commit comments