Skip to content

Commit 67ea9b2

Browse files
committed
Make super_traits_of return Lrc for cheaper clone
1 parent 1895e52 commit 67ea9b2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ rustc_queries! {
438438

439439
/// Maps from the `DefId` of a trait to the list of
440440
/// all the ancestors super traits.
441-
query super_traits_of(key: DefId) -> FxHashSet<DefId> {
441+
query super_traits_of(key: DefId) -> Lrc<FxHashSet<DefId>> {
442442
desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) }
443443
}
444444

compiler/rustc_typeck/src/collect.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_ast::{MetaItemKind, NestedMetaItem};
2626
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
2727
use rustc_data_structures::captures::Captures;
2828
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
29+
use rustc_data_structures::sync::Lrc;
2930
use rustc_errors::{struct_span_err, Applicability};
3031
use rustc_hir as hir;
3132
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -1118,7 +1119,8 @@ fn super_predicates_that_define_assoc_type(
11181119
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
11191120
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
11201121
/// to identify which traits may define a given associated type to help avoid cycle errors.
1121-
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
1122+
/// Returns `Lrc<FxHashSet<DefId>>` so that cloning is cheaper.
1123+
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Lrc<FxHashSet<DefId>> {
11221124
let mut set = FxHashSet::default();
11231125
let mut stack = vec![trait_def_id];
11241126
while let Some(trait_did) = stack.pop() {
@@ -1178,7 +1180,7 @@ fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> FxHashSet<DefId> {
11781180
}
11791181
}
11801182

1181-
set
1183+
Lrc::new(set)
11821184
}
11831185

11841186
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {

0 commit comments

Comments
 (0)