Skip to content

Commit 6d5953a

Browse files
committed
---
yaml --- r: 277212 b: refs/heads/try c: 6ae8027 h: refs/heads/master
1 parent 7b1e9d5 commit 6d5953a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: ed7c56796ef17f13227a50dc1a72a018b1d5e33f
4+
refs/heads/try: 6ae80273a08c9cb0b75b8aec464f1e7d838a2bda
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc_resolve/lib.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,9 @@ pub struct ModuleS<'a> {
848848
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
849849
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
850850

851+
// Used to memoize the traits in this module for faster searches through all traits in scope.
852+
traits: RefCell<Option<Box<[&'a NameBinding<'a>]>>>,
853+
851854
// Whether this module is populated. If not populated, any attempt to
852855
// access the children must be preceded with a
853856
// `populate_module_if_necessary` call.
@@ -875,6 +878,7 @@ impl<'a> ModuleS<'a> {
875878
prelude: RefCell::new(None),
876879
glob_importers: RefCell::new(Vec::new()),
877880
globs: RefCell::new((Vec::new())),
881+
traits: RefCell::new(None),
878882
populated: Cell::new(!external),
879883
arenas: arenas
880884
}
@@ -3225,18 +3229,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32253229
let mut search_module = self.current_module;
32263230
loop {
32273231
// Look for trait children.
3228-
let mut search_in_module = |module: Module<'a>| module.for_each_child(|_, ns, binding| {
3229-
if ns != TypeNS { return }
3230-
let trait_def_id = match binding.def() {
3231-
Some(Def::Trait(trait_def_id)) => trait_def_id,
3232-
Some(..) | None => return,
3233-
};
3234-
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
3235-
add_trait_info(&mut found_traits, trait_def_id, name);
3236-
let trait_name = self.get_trait_name(trait_def_id);
3237-
self.record_use(trait_name, TypeNS, binding);
3232+
let mut search_in_module = |module: Module<'a>| {
3233+
let mut traits = module.traits.borrow_mut();
3234+
if traits.is_none() {
3235+
let mut collected_traits = Vec::new();
3236+
module.for_each_child(|_, ns, binding| {
3237+
if ns != TypeNS { return }
3238+
if let Some(Def::Trait(_)) = binding.def() {
3239+
collected_traits.push(binding);
3240+
}
3241+
});
3242+
*traits = Some(collected_traits.into_boxed_slice());
32383243
}
3239-
});
3244+
3245+
for binding in traits.as_ref().unwrap().iter() {
3246+
let trait_def_id = binding.def().unwrap().def_id();
3247+
if self.trait_item_map.contains_key(&(name, trait_def_id)) {
3248+
add_trait_info(&mut found_traits, trait_def_id, name);
3249+
let trait_name = self.get_trait_name(trait_def_id);
3250+
self.record_use(trait_name, TypeNS, binding);
3251+
}
3252+
}
3253+
};
32403254
search_in_module(search_module);
32413255

32423256
match search_module.parent_link {

0 commit comments

Comments
 (0)