Move a few queries to using an arena.

This commit is contained in:
Camille GILLOT 2020-04-15 00:07:31 +02:00
parent 0b789834dd
commit e33327782f
6 changed files with 17 additions and 13 deletions

View file

@ -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:
//

View file

@ -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 }
}
}

View file

@ -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<u32, Symbol, ty::AssocItem>,
pub struct AssociatedItems<'tcx> {
items: SortedIndexMultiMap<u32, Symbol, &'tcx ty::AssocItem>,
}
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<Item = ty::AssocItem>) -> Self {
pub fn new(items_in_def_order: impl IntoIterator<Item = &'tcx ty::AssocItem>) -> 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<Item = &ty::AssocItem> {
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<Item = &ty::AssocItem> {
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<AssocItem> {
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,

View file

@ -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]
}
_ => &[],

View file

@ -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;
}

View file

@ -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)
}