diff options
author | Aleksey Kladov <[email protected]> | 2020-03-13 15:05:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-16 16:42:30 +0000 |
commit | 9faea2364dee4fbc9391ad233c570b70256ef002 (patch) | |
tree | 160af959553ce57fdfcbc0a6c79bafcc3611aeea /crates/ra_hir_def/src/nameres/collector.rs | |
parent | 648df02953a6ebf87a5876668eceba208687e8a7 (diff) |
Use `dyn Trait` for working with databse
It improves compile time in `--release` mode quite a bit, it doesn't
really slow things down and, conceptually, it seems closer to what we
want the physical architecture to look like (we don't want to
monomorphise EVERYTHING in a single leaf crate).
Diffstat (limited to 'crates/ra_hir_def/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index db9838cb5..7a042e69f 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -30,7 +30,7 @@ use crate::{ | |||
30 | TraitLoc, TypeAliasLoc, UnionLoc, | 30 | TraitLoc, TypeAliasLoc, UnionLoc, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 33 | pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
34 | let crate_graph = db.crate_graph(); | 34 | let crate_graph = db.crate_graph(); |
35 | 35 | ||
36 | // populate external prelude | 36 | // populate external prelude |
@@ -112,8 +112,8 @@ struct DeriveDirective { | |||
112 | } | 112 | } |
113 | 113 | ||
114 | /// Walks the tree of module recursively | 114 | /// Walks the tree of module recursively |
115 | struct DefCollector<'a, DB> { | 115 | struct DefCollector<'a> { |
116 | db: &'a DB, | 116 | db: &'a dyn DefDatabase, |
117 | def_map: CrateDefMap, | 117 | def_map: CrateDefMap, |
118 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, | 118 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, |
119 | unresolved_imports: Vec<ImportDirective>, | 119 | unresolved_imports: Vec<ImportDirective>, |
@@ -124,10 +124,7 @@ struct DefCollector<'a, DB> { | |||
124 | cfg_options: &'a CfgOptions, | 124 | cfg_options: &'a CfgOptions, |
125 | } | 125 | } |
126 | 126 | ||
127 | impl<DB> DefCollector<'_, DB> | 127 | impl DefCollector<'_> { |
128 | where | ||
129 | DB: DefDatabase, | ||
130 | { | ||
131 | fn collect(&mut self) { | 128 | fn collect(&mut self) { |
132 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; | 129 | let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; |
133 | let raw_items = self.db.raw_items(file_id.into()); | 130 | let raw_items = self.db.raw_items(file_id.into()); |
@@ -605,8 +602,8 @@ where | |||
605 | } | 602 | } |
606 | 603 | ||
607 | /// Walks a single module, populating defs, imports and macros | 604 | /// Walks a single module, populating defs, imports and macros |
608 | struct ModCollector<'a, D> { | 605 | struct ModCollector<'a, 'b> { |
609 | def_collector: D, | 606 | def_collector: &'a mut DefCollector<'b>, |
610 | macro_depth: usize, | 607 | macro_depth: usize, |
611 | module_id: LocalModuleId, | 608 | module_id: LocalModuleId, |
612 | file_id: HirFileId, | 609 | file_id: HirFileId, |
@@ -614,10 +611,7 @@ struct ModCollector<'a, D> { | |||
614 | mod_dir: ModDir, | 611 | mod_dir: ModDir, |
615 | } | 612 | } |
616 | 613 | ||
617 | impl<DB> ModCollector<'_, &'_ mut DefCollector<'_, DB>> | 614 | impl ModCollector<'_, '_> { |
618 | where | ||
619 | DB: DefDatabase, | ||
620 | { | ||
621 | fn collect(&mut self, items: &[raw::RawItem]) { | 615 | fn collect(&mut self, items: &[raw::RawItem]) { |
622 | // Note: don't assert that inserted value is fresh: it's simply not true | 616 | // Note: don't assert that inserted value is fresh: it's simply not true |
623 | // for macros. | 617 | // for macros. |
@@ -950,7 +944,7 @@ mod tests { | |||
950 | 944 | ||
951 | use super::*; | 945 | use super::*; |
952 | 946 | ||
953 | fn do_collect_defs(db: &impl DefDatabase, def_map: CrateDefMap) -> CrateDefMap { | 947 | fn do_collect_defs(db: &dyn DefDatabase, def_map: CrateDefMap) -> CrateDefMap { |
954 | let mut collector = DefCollector { | 948 | let mut collector = DefCollector { |
955 | db, | 949 | db, |
956 | def_map, | 950 | def_map, |