From e33327782f868e81ece04b40d6fae56ede9845cd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 15 Apr 2020 00:07:31 +0200 Subject: [PATCH] Move a few queries to using an arena. --- src/librustc_codegen_llvm/attributes.rs | 2 +- src/librustc_middle/query/mod.rs | 8 ++++++-- src/librustc_middle/ty/mod.rs | 14 +++++++------- src/librustc_mir_build/lints.rs | 2 +- src/librustc_passes/reachable.rs | 2 +- src/librustc_ty/ty.rs | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 93577d64157a..0eae17b5f564 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -252,7 +252,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: inline(cx, llfn, attributes::InlineAttr::Hint); } - inline(cx, llfn, codegen_fn_attrs.inline); + inline(cx, llfn, codegen_fn_attrs.inline.clone()); // The `uwtable` attribute according to LLVM is: // diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 62a759f29bc9..e57c51b9eefb 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -367,10 +367,12 @@ rustc_queries! { query associated_item_def_ids(_: DefId) -> &'tcx [DefId] {} /// Maps from a trait item to the trait item "descriptor". - query associated_item(_: DefId) -> ty::AssocItem {} + query associated_item(_: DefId) -> ty::AssocItem { + storage(ArenaCacheSelector<'tcx>) + } /// Collects the associated items defined on a trait or impl. - query associated_items(key: DefId) -> ty::AssociatedItems { + query associated_items(key: DefId) -> ty::AssociatedItems<'tcx> { storage(ArenaCacheSelector<'tcx>) desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) } } @@ -395,6 +397,7 @@ rustc_queries! { query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult { desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } + storage(ArenaCacheSelector<'tcx>) } /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error @@ -644,6 +647,7 @@ rustc_queries! { Codegen { query codegen_fn_attrs(_: DefId) -> CodegenFnAttrs { + storage(ArenaCacheSelector<'tcx>) cache_on_disk_if { true } } } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 0abe44b31065..5dee8cf7bdfc 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -257,13 +257,13 @@ impl AssocItem { /// it is relatively expensive. Instead, items are indexed by `Symbol` and hygienic comparison is /// done only on items with the same name. #[derive(Debug, Clone, PartialEq, HashStable)] -pub struct AssociatedItems { - items: SortedIndexMultiMap, +pub struct AssociatedItems<'tcx> { + items: SortedIndexMultiMap, } -impl AssociatedItems { +impl<'tcx> AssociatedItems<'tcx> { /// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order. - pub fn new(items_in_def_order: impl IntoIterator) -> Self { + pub fn new(items_in_def_order: impl IntoIterator) -> Self { let items = items_in_def_order.into_iter().map(|item| (item.ident.name, item)).collect(); AssociatedItems { items } } @@ -273,7 +273,7 @@ impl AssociatedItems { /// New code should avoid relying on definition order. If you need a particular associated item /// for a known trait, make that trait a lang item instead of indexing this array. pub fn in_definition_order(&self) -> impl '_ + Iterator { - self.items.iter().map(|(_, v)| v) + self.items.iter().map(|(_, v)| *v) } /// Returns an iterator over all associated items with the given name, ignoring hygiene. @@ -281,7 +281,7 @@ impl AssociatedItems { &self, name: Symbol, ) -> impl '_ + Iterator { - self.items.get_by_key(&name) + self.items.get_by_key(&name).map(|v| *v) } /// Returns an iterator over all associated items with the given name. @@ -2672,7 +2672,7 @@ impl<'tcx> TyCtxt<'tcx> { .and_then(|def_id| self.hir().get(self.hir().as_local_hir_id(def_id)).ident()) } - pub fn opt_associated_item(self, def_id: DefId) -> Option { + pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> { let is_associated_item = if let Some(def_id) = def_id.as_local() { match self.hir().get(self.hir().as_local_hir_id(def_id)) { Node::TraitItem(_) | Node::ImplItem(_) => true, diff --git a/src/librustc_mir_build/lints.rs b/src/librustc_mir_build/lints.rs index 990f55f6d422..69bfad6b1399 100644 --- a/src/librustc_mir_build/lints.rs +++ b/src/librustc_mir_build/lints.rs @@ -24,7 +24,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) { Some(AssocItem { container: AssocItemContainer::TraitContainer(trait_def_id), .. }) => { - let trait_substs_count = tcx.generics_of(trait_def_id).count(); + let trait_substs_count = tcx.generics_of(*trait_def_id).count(); &InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count] } _ => &[], diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index d913486cb0e1..1a86babbc46c 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -23,7 +23,7 @@ use rustc_target::spec::abi::Abi; // Returns true if the given item must be inlined because it may be // monomorphized or it was marked with `#[inline]`. This will only return // true for functions. -fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: CodegenFnAttrs) -> bool { +fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: &CodegenFnAttrs) -> bool { if attrs.requests_inline() { return true; } diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 5b1389bf5a33..b65f1cd6fac4 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -220,7 +220,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] { } } -fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssociatedItems { +fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssociatedItems<'_> { let items = tcx.associated_item_def_ids(def_id).iter().map(|did| tcx.associated_item(*did)); ty::AssociatedItems::new(items) }