1616use hir:: def:: DefKind ;
1717use rustc_ast:: Mutability ;
1818use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
19- use rustc_hir:: def_id:: LocalDefIdMap ;
20- use rustc_hir:: definitions:: {
21- DefPathData , PerParentDisambiguatorState , PerParentDisambiguatorsMap ,
22- } ;
19+ use rustc_hir:: definitions:: { DefPathData , PerParentDisambiguatorState } ;
2320use rustc_hir:: { self as hir} ;
2421use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
2522use rustc_middle:: mir:: interpret:: {
@@ -108,7 +105,7 @@ fn intern_shallow<'tcx, M: CompileTimeMachine<'tcx>>(
108105 ecx : & mut InterpCx < ' tcx , M > ,
109106 alloc_id : AllocId ,
110107 mutability : Mutability ,
111- disambiguators : Option < & mut LocalDefIdMap < PerParentDisambiguatorState > > ,
108+ disambiguator : Option < & mut PerParentDisambiguatorState > ,
112109) -> Result < impl Iterator < Item = CtfeProvenance > + ' tcx , InternError > {
113110 trace ! ( "intern_shallow {:?}" , alloc_id) ;
114111 // remove allocation
@@ -132,7 +129,7 @@ fn intern_shallow<'tcx, M: CompileTimeMachine<'tcx>>(
132129 static_id,
133130 alloc_id,
134131 alloc,
135- disambiguators . expect ( "disambiguators needed" ) ,
132+ disambiguator . expect ( "disambiguator needed" ) ,
136133 ) ;
137134 } else {
138135 ecx. tcx . set_alloc_id_memory ( alloc_id, alloc) ;
@@ -147,19 +144,18 @@ fn intern_as_new_static<'tcx>(
147144 static_id : LocalDefId ,
148145 alloc_id : AllocId ,
149146 alloc : ConstAllocation < ' tcx > ,
150- disambiguators : & mut LocalDefIdMap < PerParentDisambiguatorState > ,
147+ disambiguator : & mut PerParentDisambiguatorState ,
151148) {
152- // `intern_const_alloc_recursive` is called once per static and it contains the `DisambiguatorState `.
149+ // `intern_const_alloc_recursive` is called once per static and it contains the `PerParentDisambiguatorState `.
153150 // The `<static_id>::{{nested}}` path is thus unique to `intern_const_alloc_recursive` and the
154- // `DisambiguatorState ` ensures the generated path is unique for this call as we generate
151+ // `PerParentDisambiguatorState ` ensures the generated path is unique for this call as we generate
155152 // `<static_id>::{{nested#n}}` where `n` is the `n`th `intern_as_new_static` call.
156153 let feed = tcx. create_def (
157154 static_id,
158155 None ,
159156 DefKind :: Static { safety : hir:: Safety :: Safe , mutability : alloc. 0 . mutability , nested : true } ,
160157 Some ( DefPathData :: NestedStatic ) ,
161- //FIXME(oli-obk): cleanup (https://github.com/rust-lang/rust/pull/155547#discussion_r3110792640)
162- disambiguators. get_or_create ( static_id) ,
158+ disambiguator,
163159 ) ;
164160 tcx. set_nested_alloc_id_static ( alloc_id, feed. def_id ( ) ) ;
165161
@@ -209,7 +205,9 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
209205 intern_kind : InternKind ,
210206 ret : & MPlaceTy < ' tcx > ,
211207) -> Result < ( ) , InternError > {
212- let mut disambiguators = Default :: default ( ) ;
208+ let mut disambiguator =
209+ ecx. machine . static_def_id ( ) . map ( |id| PerParentDisambiguatorState :: new ( id) ) ;
210+ let mut disambiguator = disambiguator. as_mut ( ) ;
213211
214212 // We are interning recursively, and for mutability we are distinguishing the "root" allocation
215213 // that we are starting in, and all other allocations that we are encountering recursively.
@@ -248,13 +246,15 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
248246 // This gives us the initial set of nested allocations, which will then all be processed
249247 // recursively in the loop below.
250248 let mut todo: Vec < _ > = if is_static {
249+ assert ! ( disambiguator. is_some( ) ) ;
251250 // Do not steal the root allocation, we need it later to create the return value of `eval_static_initializer`.
252251 // But still change its mutability to match the requested one.
253252 let ( kind, alloc) = ecx. memory . alloc_map . get_mut ( & base_alloc_id) . unwrap ( ) ;
254253 prepare_alloc ( * ecx. tcx , * kind, alloc, base_mutability) ?;
255254 alloc. provenance ( ) . ptrs ( ) . iter ( ) . map ( |& ( _, prov) | prov) . collect ( )
256255 } else {
257- intern_shallow ( ecx, base_alloc_id, base_mutability, Some ( & mut disambiguators) ) ?. collect ( )
256+ assert ! ( disambiguator. is_none( ) ) ;
257+ intern_shallow ( ecx, base_alloc_id, base_mutability, None ) ?. collect ( )
258258 } ;
259259 // We need to distinguish "has just been interned" from "was already in `tcx`",
260260 // so we track this in a separate set.
@@ -336,7 +336,7 @@ pub fn intern_const_alloc_recursive<'tcx, M: CompileTimeMachine<'tcx>>(
336336 // okay with losing some potential for immutability here. This can anyway only affect
337337 // `static mut`.
338338 just_interned. insert ( alloc_id) ;
339- let next = intern_shallow ( ecx, alloc_id, inner_mutability, Some ( & mut disambiguators ) ) ?;
339+ let next = intern_shallow ( ecx, alloc_id, inner_mutability, disambiguator . as_deref_mut ( ) ) ?;
340340 todo. extend ( next) ;
341341 }
342342 if found_bad_mutable_ptr {
0 commit comments