From 769cc733b1663b48e1a1639bd8e8579ef795fbcd Mon Sep 17 00:00:00 2001 From: CastilloDel Date: Sun, 6 Nov 2022 17:47:06 +0100 Subject: [PATCH 1/4] Remove allow(rustc::potential_query_instability) from rustc_ast_lowering --- compiler/rustc_ast_lowering/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index ff29d15f1b525..0af9b40afe3a5 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -34,7 +34,6 @@ #![feature(let_chains)] #![feature(never_type)] #![recursion_limit = "256"] -#![allow(rustc::potential_query_instability)] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] From d1eab51f476554406c1b500f3fc619455209bd02 Mon Sep 17 00:00:00 2001 From: CastilloDel Date: Sun, 6 Nov 2022 17:48:00 +0100 Subject: [PATCH 2/4] Make clobber_abis use an FxIndexMap It seems to be used more for lookup than iteration, so this could be a perf hit --- compiler/rustc_ast_lowering/src/asm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 450cdf246b150..db0d8b08a947f 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -11,7 +11,7 @@ use super::LoweringContext; use rustc_ast::ptr::P; use rustc_ast::*; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::definitions::DefPathData; @@ -71,7 +71,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { .emit(); } - let mut clobber_abis = FxHashMap::default(); + let mut clobber_abis = FxIndexMap::default(); if let Some(asm_arch) = asm_arch { for (abi_name, abi_span) in &asm.clobber_abis { match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) { From fdb5fe2ed8c0ccd351e56d3afaa8b2a986e878b7 Mon Sep 17 00:00:00 2001 From: CastilloDel Date: Sat, 12 Nov 2022 19:07:33 +0100 Subject: [PATCH 3/4] Change LoweringContext.children to Vec --- compiler/rustc_ast_lowering/src/item.rs | 17 +++++++++++------ compiler/rustc_ast_lowering/src/lib.rs | 9 ++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 76316a574acb7..e43bec300bda9 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -6,7 +6,6 @@ use super::{FnDeclKind, LoweringContext, ParamMode}; use rustc_ast::ptr::P; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; -use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sorted_map::SortedMap; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -67,7 +66,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { // HirId handling. bodies: Vec::new(), attrs: SortedMap::default(), - children: FxHashMap::default(), + children: Vec::default(), current_hir_id_owner: hir::CRATE_OWNER_ID, item_local_id_counter: hir::ItemLocalId::new(0), node_id_to_local_id: Default::default(), @@ -95,7 +94,13 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { for (def_id, info) in lctx.children { self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom); debug_assert!(matches!(self.owners[def_id], hir::MaybeOwner::Phantom)); - self.owners[def_id] = info; + match (self.owners[def_id], info) { + (hir::MaybeOwner::Phantom, _) + | (hir::MaybeOwner::NonOwner(_), hir::MaybeOwner::Owner(_)) => { + self.owners[def_id] = info; + } + _ => unreachable!(), + } } } @@ -534,12 +539,12 @@ impl<'hir> LoweringContext<'_, 'hir> { for new_node_id in [id1, id2] { let new_id = self.local_def_id(new_node_id); let Some(res) = resolutions.next() else { + debug_assert!(self.children.iter().find(|(id, _)| id == &new_id).is_none()); // Associate an HirId to both ids even if there is no resolution. - let _old = self.children.insert( + self.children.push(( new_id, - hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id)), + hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id))), ); - debug_assert!(_old.is_none()); continue; }; let ident = *ident; diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 0af9b40afe3a5..cac9096780b2b 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -106,7 +106,7 @@ struct LoweringContext<'a, 'hir> { /// Attributes inside the owner being lowered. attrs: SortedMap, /// Collect items that were created by lowering the current owner. - children: FxHashMap>>, + children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>, generator_kind: Option, @@ -610,8 +610,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.impl_trait_defs = current_impl_trait_defs; self.impl_trait_bounds = current_impl_trait_bounds; - let _old = self.children.insert(def_id, hir::MaybeOwner::Owner(info)); - debug_assert!(_old.is_none()) + debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none()); + self.children.push((def_id, hir::MaybeOwner::Owner(info))); } /// Installs the remapping `remap` in scope while `f` is being executed. @@ -718,8 +718,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { assert_ne!(local_id, hir::ItemLocalId::new(0)); if let Some(def_id) = self.opt_local_def_id(ast_node_id) { - // Do not override a `MaybeOwner::Owner` that may already here. - self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id)); + self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id))); self.local_id_to_def_id.insert(local_id, def_id); } From 557226348f9b5cc06931faf6c510114e2ccea55b Mon Sep 17 00:00:00 2001 From: Daniel del Castillo <52696601+CastilloDel@users.noreply.github.com> Date: Tue, 15 Nov 2022 00:50:16 +0100 Subject: [PATCH 4/4] Update compiler/rustc_ast_lowering/src/item.rs Co-authored-by: Camille Gillot --- compiler/rustc_ast_lowering/src/item.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index e43bec300bda9..ad865a6a0f2e7 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -94,13 +94,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { for (def_id, info) in lctx.children { self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom); debug_assert!(matches!(self.owners[def_id], hir::MaybeOwner::Phantom)); - match (self.owners[def_id], info) { - (hir::MaybeOwner::Phantom, _) - | (hir::MaybeOwner::NonOwner(_), hir::MaybeOwner::Owner(_)) => { - self.owners[def_id] = info; - } - _ => unreachable!(), - } + self.owners[def_id] = info; } }