aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/semantics
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-13 15:05:46 +0000
committerAleksey Kladov <[email protected]>2020-03-16 16:42:30 +0000
commit9faea2364dee4fbc9391ad233c570b70256ef002 (patch)
tree160af959553ce57fdfcbc0a6c79bafcc3611aeea /crates/ra_hir/src/semantics
parent648df02953a6ebf87a5876668eceba208687e8a7 (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/src/semantics')
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 67b243222..8843f2835 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -21,12 +21,12 @@ use crate::{db::HirDatabase, InFile, MacroDefId};
21 21
22pub(super) type SourceToDefCache = FxHashMap<ChildContainer, DynMap>; 22pub(super) type SourceToDefCache = FxHashMap<ChildContainer, DynMap>;
23 23
24pub(super) struct SourceToDefCtx<'a, DB> { 24pub(super) struct SourceToDefCtx<'a, 'b> {
25 pub(super) db: DB, 25 pub(super) db: &'b dyn HirDatabase,
26 pub(super) cache: &'a mut SourceToDefCache, 26 pub(super) cache: &'a mut SourceToDefCache,
27} 27}
28 28
29impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> { 29impl SourceToDefCtx<'_, '_> {
30 pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { 30 pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> {
31 let _p = profile("SourceBinder::to_module_def"); 31 let _p = profile("SourceBinder::to_module_def");
32 let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { 32 let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| {
@@ -43,7 +43,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
43 .as_ref() 43 .as_ref()
44 .map(|it| it.syntax()) 44 .map(|it| it.syntax())
45 .cloned() 45 .cloned()
46 .ancestors_with_macros(self.db) 46 .ancestors_with_macros(self.db.upcast())
47 .skip(1) 47 .skip(1)
48 .find_map(|it| { 48 .find_map(|it| {
49 let m = ast::Module::cast(it.value.clone())?; 49 let m = ast::Module::cast(it.value.clone())?;
@@ -53,7 +53,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
53 let parent_module = match parent_declaration { 53 let parent_module = match parent_declaration {
54 Some(parent_declaration) => self.module_to_def(parent_declaration), 54 Some(parent_declaration) => self.module_to_def(parent_declaration),
55 None => { 55 None => {
56 let file_id = src.file_id.original_file(self.db); 56 let file_id = src.file_id.original_file(self.db.upcast());
57 self.file_to_def(file_id) 57 self.file_to_def(file_id)
58 } 58 }
59 }?; 59 }?;
@@ -147,7 +147,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
147 // FIXME: use DynMap as well? 147 // FIXME: use DynMap as well?
148 pub(super) fn macro_call_to_def(&mut self, src: InFile<ast::MacroCall>) -> Option<MacroDefId> { 148 pub(super) fn macro_call_to_def(&mut self, src: InFile<ast::MacroCall>) -> Option<MacroDefId> {
149 let kind = MacroDefKind::Declarative; 149 let kind = MacroDefKind::Declarative;
150 let file_id = src.file_id.original_file(self.db); 150 let file_id = src.file_id.original_file(self.db.upcast());
151 let krate = self.file_to_def(file_id)?.krate; 151 let krate = self.file_to_def(file_id)?.krate;
152 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); 152 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value);
153 let ast_id = Some(AstId::new(src.file_id, file_ast_id)); 153 let ast_id = Some(AstId::new(src.file_id, file_ast_id));
@@ -155,7 +155,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
155 } 155 }
156 156
157 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> { 157 pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {
158 for container in src.cloned().ancestors_with_macros(self.db).skip(1) { 158 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
159 let res: ChildContainer = match_ast! { 159 let res: ChildContainer = match_ast! {
160 match (container.value) { 160 match (container.value) {
161 ast::Module(it) => { 161 ast::Module(it) => {
@@ -200,12 +200,12 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
200 return Some(res); 200 return Some(res);
201 } 201 }
202 202
203 let def = self.file_to_def(src.file_id.original_file(self.db))?; 203 let def = self.file_to_def(src.file_id.original_file(self.db.upcast()))?;
204 Some(def.into()) 204 Some(def.into())
205 } 205 }
206 206
207 fn find_type_param_container(&mut self, src: InFile<&SyntaxNode>) -> Option<GenericDefId> { 207 fn find_type_param_container(&mut self, src: InFile<&SyntaxNode>) -> Option<GenericDefId> {
208 for container in src.cloned().ancestors_with_macros(self.db).skip(1) { 208 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
209 let res: GenericDefId = match_ast! { 209 let res: GenericDefId = match_ast! {
210 match (container.value) { 210 match (container.value) {
211 ast::FnDef(it) => { self.fn_to_def(container.with_value(it))?.into() }, 211 ast::FnDef(it) => { self.fn_to_def(container.with_value(it))?.into() },
@@ -223,7 +223,7 @@ impl<DB: HirDatabase> SourceToDefCtx<'_, &'_ DB> {
223 } 223 }
224 224
225 fn find_pat_container(&mut self, src: InFile<&SyntaxNode>) -> Option<DefWithBodyId> { 225 fn find_pat_container(&mut self, src: InFile<&SyntaxNode>) -> Option<DefWithBodyId> {
226 for container in src.cloned().ancestors_with_macros(self.db).skip(1) { 226 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
227 let res: DefWithBodyId = match_ast! { 227 let res: DefWithBodyId = match_ast! {
228 match (container.value) { 228 match (container.value) {
229 ast::ConstDef(it) => { self.const_to_def(container.with_value(it))?.into() }, 229 ast::ConstDef(it) => { self.const_to_def(container.with_value(it))?.into() },
@@ -262,7 +262,8 @@ impl_froms! {
262} 262}
263 263
264impl ChildContainer { 264impl ChildContainer {
265 fn child_by_source(self, db: &impl HirDatabase) -> DynMap { 265 fn child_by_source(self, db: &dyn HirDatabase) -> DynMap {
266 let db = db.upcast();
266 match self { 267 match self {
267 ChildContainer::DefWithBodyId(it) => it.child_by_source(db), 268 ChildContainer::DefWithBodyId(it) => it.child_by_source(db),
268 ChildContainer::ModuleId(it) => it.child_by_source(db), 269 ChildContainer::ModuleId(it) => it.child_by_source(db),