about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2020-11-24 17:36:36 -0300
committerSantiago Pastorino <spastorino@gmail.com>2020-11-27 11:23:52 -0300
commit67ea9b227f7e7f5599ff9e194566ae769e34847d (patch)
treede7d139eb35013271bd9642d718e1024b6bc2988
parent1895e52505b59f49e6675376c44ad8e251c4501c (diff)
downloadrust-67ea9b227f7e7f5599ff9e194566ae769e34847d.tar.gz
rust-67ea9b227f7e7f5599ff9e194566ae769e34847d.zip
Make super_traits_of return Lrc for cheaper clone
-rw-r--r--compiler/rustc_middle/src/query/mod.rs2
-rw-r--r--compiler/rustc_typeck/src/collect.rs6
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 925a05c879b..aba534ac19f 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<DefId> {
+        query super_traits_of(key: DefId) -> Lrc<FxHashSet<DefId>> {
             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 1ee29001c84..21d450eaf6e 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<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 {