From 67ea9b227f7e7f5599ff9e194566ae769e34847d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 24 Nov 2020 17:36:36 -0300 Subject: [PATCH] Make super_traits_of return Lrc for cheaper clone --- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 925a05c879bd..aba534ac19f9 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -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 { + query super_traits_of(key: DefId) -> Lrc> { desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) } } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 1ee29001c846..21d450eaf6e6 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -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 { +/// Returns `Lrc>` so that cloning is cheaper. +fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Lrc> { 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 { } } - set + Lrc::new(set) } fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {