Skip to content

Commit

Permalink
Move a few queries to using an arena.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 28, 2020
1 parent 0b78983 commit e333277
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Expand Up @@ -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:
//
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_middle/query/mod.rs
Expand Up @@ -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) }
}
Expand All @@ -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
Expand Down Expand Up @@ -644,6 +647,7 @@ rustc_queries! {

Codegen {
query codegen_fn_attrs(_: DefId) -> CodegenFnAttrs {
storage(ArenaCacheSelector<'tcx>)
cache_on_disk_if { true }
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_middle/ty/mod.rs
Expand Up @@ -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 }
}
Expand All @@ -273,15 +273,15 @@ 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.
pub fn filter_by_name_unhygienic(
&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.
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/lints.rs
Expand Up @@ -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]
}
_ => &[],
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/reachable.rs
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ty/ty.rs
Expand Up @@ -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)
}
Expand Down

0 comments on commit e333277

Please sign in to comment.