Make super_traits_of return Lrc for cheaper clone

This commit is contained in:
Santiago Pastorino 2020-11-24 17:36:36 -03:00
parent 1895e52505
commit 67ea9b227f
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
2 changed files with 5 additions and 3 deletions

View file

@ -438,7 +438,7 @@ rustc_queries! {
/// Maps from the `DefId` of a trait to the list of
/// all the ancestors super traits.
query super_traits_of(key: DefId) -> FxHashSet<DefId> {
query super_traits_of(key: DefId) -> Lrc<FxHashSet<DefId>> {
desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) }
}

View file

@ -26,6 +26,7 @@ use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
@ -1118,7 +1119,8 @@ fn super_predicates_that_define_assoc_type(
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
/// to identify which traits may define a given associated type to help avoid cycle errors.
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
/// Returns `Lrc<FxHashSet<DefId>>` so that cloning is cheaper.
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Lrc<FxHashSet<DefId>> {
let mut set = FxHashSet::default();
let mut stack = vec![trait_def_id];
while let Some(trait_did) = stack.pop() {
@ -1178,7 +1180,7 @@ fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
}
}
set
Lrc::new(set)
}
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {