@@ -46,8 +46,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, T, M: CompileTimeMachine<'mir, 'tcx, T>>(
46
46
ecx : & ' rt mut InterpCx < ' mir , ' tcx , M > ,
47
47
alloc_id : AllocId ,
48
48
mutability : Mutability ,
49
- mut recursive_alloc : impl FnMut ( & InterpCx < ' mir , ' tcx , M > , CtfeProvenance ) ,
50
- ) -> Result < ( ) , ( ) > {
49
+ ) -> Result < impl Iterator < Item = CtfeProvenance > + ' tcx , ( ) > {
51
50
trace ! ( "intern_shallow {:?}" , alloc_id) ;
52
51
// remove allocation
53
52
let Some ( ( _kind, mut alloc) ) = ecx. memory . alloc_map . remove ( & alloc_id) else {
@@ -65,14 +64,10 @@ fn intern_shallow<'rt, 'mir, 'tcx, T, M: CompileTimeMachine<'mir, 'tcx, T>>(
65
64
assert_eq ! ( alloc. mutability, Mutability :: Mut ) ;
66
65
}
67
66
}
68
- // record child allocations
69
- for & ( _, prov) in alloc. provenance ( ) . ptrs ( ) . iter ( ) {
70
- recursive_alloc ( ecx, prov) ;
71
- }
72
67
// link the alloc id to the actual allocation
73
68
let alloc = ecx. tcx . mk_const_alloc ( alloc) ;
74
69
ecx. tcx . set_alloc_id_memory ( alloc_id, alloc) ;
75
- Ok ( ( ) )
70
+ Ok ( alloc . 0 . 0 . provenance ( ) . ptrs ( ) . iter ( ) . map ( | & ( _ , prov ) | prov ) )
76
71
}
77
72
78
73
/// How a constant value should be interned.
@@ -154,7 +149,10 @@ pub fn intern_const_alloc_recursive<
154
149
continue ;
155
150
}
156
151
just_interned. insert ( alloc_id) ;
157
- intern_shallow ( ecx, alloc_id, mutability, |ecx, prov| {
152
+ let provs = intern_shallow ( ecx, alloc_id, mutability) . map_err ( |( ) | {
153
+ ecx. tcx . dcx ( ) . emit_err ( DanglingPtrInFinal { span : ecx. tcx . span , kind : intern_kind } )
154
+ } ) ?;
155
+ for prov in provs {
158
156
let alloc_id = prov. alloc_id ( ) ;
159
157
if intern_kind != InternKind :: Promoted
160
158
&& inner_mutability == Mutability :: Not
@@ -169,7 +167,7 @@ pub fn intern_const_alloc_recursive<
169
167
// during interning is to justify why we intern the *new* allocations immutably,
170
168
// so we can completely ignore existing allocations. We also don't need to add
171
169
// this to the todo list, since after all it is already interned.
172
- return ;
170
+ continue ;
173
171
}
174
172
// Found a mutable pointer inside a const where inner allocations should be
175
173
// immutable. We exclude promoteds from this, since things like `&mut []` and
@@ -189,10 +187,7 @@ pub fn intern_const_alloc_recursive<
189
187
// okay with losing some potential for immutability here. This can anyway only affect
190
188
// `static mut`.
191
189
todo. push ( ( alloc_id, inner_mutability) ) ;
192
- } )
193
- . map_err ( |( ) | {
194
- ecx. tcx . dcx ( ) . emit_err ( DanglingPtrInFinal { span : ecx. tcx . span , kind : intern_kind } )
195
- } ) ?;
190
+ }
196
191
}
197
192
if found_bad_mutable_pointer {
198
193
return Err ( ecx
@@ -220,13 +215,13 @@ pub fn intern_const_alloc_for_constprop<
220
215
return Ok ( ( ) ) ;
221
216
}
222
217
// Move allocation to `tcx`.
223
- intern_shallow ( ecx, alloc_id, Mutability :: Not , |_ecx , _| {
218
+ for _ in intern_shallow ( ecx, alloc_id, Mutability :: Not ) . map_err ( | ( ) | err_ub ! ( DeadLocal ) ) ? {
224
219
// We are not doing recursive interning, so we don't currently support provenance.
225
220
// (If this assertion ever triggers, we should just implement a
226
221
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.
227
222
panic ! ( "`intern_const_alloc_for_constprop` called on allocation with nested provenance" )
228
- } )
229
- . map_err ( | ( ) | err_ub ! ( DeadLocal ) . into ( ) )
223
+ }
224
+ Ok ( ( ) )
230
225
}
231
226
232
227
impl < ' mir , ' tcx : ' mir , M : super :: intern:: CompileTimeMachine < ' mir , ' tcx , !> >
@@ -247,15 +242,14 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
247
242
let dest = self . allocate ( layout, MemoryKind :: Stack ) ?;
248
243
f ( self , & dest. clone ( ) . into ( ) ) ?;
249
244
let alloc_id = dest. ptr ( ) . provenance . unwrap ( ) . alloc_id ( ) ; // this was just allocated, it must have provenance
250
- intern_shallow ( self , alloc_id, Mutability :: Not , |ecx , prov| {
245
+ for prov in intern_shallow ( self , alloc_id, Mutability :: Not ) . unwrap ( ) {
251
246
// We are not doing recursive interning, so we don't currently support provenance.
252
247
// (If this assertion ever triggers, we should just implement a
253
248
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.
254
- if !ecx . tcx . try_get_global_alloc ( prov. alloc_id ( ) ) . is_some ( ) {
249
+ if !self . tcx . try_get_global_alloc ( prov. alloc_id ( ) ) . is_some ( ) {
255
250
panic ! ( "`intern_with_temp_alloc` with nested allocations" ) ;
256
251
}
257
- } )
258
- . unwrap ( ) ;
252
+ }
259
253
Ok ( alloc_id)
260
254
}
261
255
}
0 commit comments