diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-29 12:59:15 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-29 13:22:38 +0200 |
| commit | e561ec0e03c4991938e0d3d39766fa74d86f7448 (patch) | |
| tree | fc2503a4f8669a17bfedf8dd22a11d0a504b81d9 /compiler/rustc_const_eval/src/interpret | |
| parent | 2ac60bc0896b4edd09e192204e768ddbe715a573 (diff) | |
| download | rust-e561ec0e03c4991938e0d3d39766fa74d86f7448.tar.gz rust-e561ec0e03c4991938e0d3d39766fa74d86f7448.zip | |
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intern.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/util.rs | 5 |
2 files changed, 13 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 8f0cb197c44..adf2c255d08 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -17,6 +17,7 @@ use hir::def::DefKind; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_hir as hir; +use rustc_hir::definitions::DisambiguatorState; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::mir::interpret::{ConstAllocation, CtfeProvenance, InterpResult}; use rustc_middle::query::TyCtxtAt; @@ -46,12 +47,13 @@ pub trait CompileTimeMachine<'tcx, T> = Machine< pub trait HasStaticRootDefId { /// Returns the `DefId` of the static item that is currently being evaluated. /// Used for interning to be able to handle nested allocations. - fn static_def_id(&self) -> Option<LocalDefId>; + fn static_parent_and_disambiguator(&mut self) -> Option<(LocalDefId, &mut DisambiguatorState)>; } impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> { - fn static_def_id(&self) -> Option<LocalDefId> { - Some(self.static_root_ids?.1) + fn static_parent_and_disambiguator(&mut self) -> Option<(LocalDefId, &mut DisambiguatorState)> { + let (_, static_id, d) = self.static_root_ids.as_mut()?; + Some((*static_id, d)) } } @@ -87,8 +89,8 @@ fn intern_shallow<'tcx, T, M: CompileTimeMachine<'tcx, T>>( } // link the alloc id to the actual allocation let alloc = ecx.tcx.mk_const_alloc(alloc); - if let Some(static_id) = ecx.machine.static_def_id() { - intern_as_new_static(ecx.tcx, static_id, alloc_id, alloc); + if let Some((static_id, disambiguator)) = ecx.machine.static_parent_and_disambiguator() { + intern_as_new_static(ecx.tcx, static_id, alloc_id, alloc, disambiguator); } else { ecx.tcx.set_alloc_id_memory(alloc_id, alloc); } @@ -102,11 +104,14 @@ fn intern_as_new_static<'tcx>( static_id: LocalDefId, alloc_id: AllocId, alloc: ConstAllocation<'tcx>, + disambiguator: &mut DisambiguatorState, ) { let feed = tcx.create_def( static_id, Some(sym::nested), DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true }, + None, + disambiguator, ); tcx.set_nested_alloc_id_static(alloc_id, feed.def_id()); diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index ba579e25f03..faaa2bd24bb 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -1,4 +1,5 @@ use rustc_hir::def_id::LocalDefId; +use rustc_hir::definitions::DisambiguatorState; use rustc_middle::mir; use rustc_middle::mir::interpret::{AllocInit, Allocation, InterpResult, Pointer}; use rustc_middle::ty::layout::TyAndLayout; @@ -40,8 +41,8 @@ pub(crate) fn create_static_alloc<'tcx>( ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let alloc = Allocation::try_new(layout.size, layout.align.abi, AllocInit::Uninit)?; let alloc_id = ecx.tcx.reserve_and_set_static_alloc(static_def_id.into()); - assert_eq!(ecx.machine.static_root_ids, None); - ecx.machine.static_root_ids = Some((alloc_id, static_def_id)); + assert!(ecx.machine.static_root_ids.is_none()); + ecx.machine.static_root_ids = Some((alloc_id, static_def_id, DisambiguatorState::new())); assert!(ecx.memory.alloc_map.insert(alloc_id, (MemoryKind::Stack, alloc)).is_none()); interp_ok(ecx.ptr_to_mplace(Pointer::from(alloc_id).into(), layout)) } |
