From 9faea2364dee4fbc9391ad233c570b70256ef002 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Mar 2020 16:05:46 +0100 Subject: 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). --- crates/ra_hir_def/src/nameres.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir_def/src/nameres.rs') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 03515309e..be53313ee 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -151,16 +151,17 @@ impl ModuleOrigin { /// Returns a node which defines this module. /// That is, a file or a `mod foo {}` with items. - fn definition_source(&self, db: &impl DefDatabase) -> InFile { + fn definition_source(&self, db: &dyn DefDatabase) -> InFile { match self { ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => { let file_id = *definition; let sf = db.parse(file_id).tree(); InFile::new(file_id.into(), ModuleSource::SourceFile(sf)) } - ModuleOrigin::Inline { definition } => { - InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) - } + ModuleOrigin::Inline { definition } => InFile::new( + definition.file_id, + ModuleSource::Module(definition.to_node(db.upcast())), + ), } } } @@ -176,7 +177,7 @@ pub struct ModuleData { } impl CrateDefMap { - pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc { + pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc { let _p = profile("crate_def_map_query").detail(|| { db.crate_graph()[krate] .display_name @@ -204,7 +205,7 @@ impl CrateDefMap { pub fn add_diagnostics( &self, - db: &impl DefDatabase, + db: &dyn DefDatabase, module: LocalModuleId, sink: &mut DiagnosticSink, ) { @@ -220,7 +221,7 @@ impl CrateDefMap { pub(crate) fn resolve_path( &self, - db: &impl DefDatabase, + db: &dyn DefDatabase, original_module: LocalModuleId, path: &ModPath, shadow: BuiltinShadowMode, @@ -273,15 +274,15 @@ impl CrateDefMap { impl ModuleData { /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source(&self, db: &impl DefDatabase) -> InFile { + pub fn definition_source(&self, db: &dyn DefDatabase) -> InFile { self.origin.definition_source(db) } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root or block. - pub fn declaration_source(&self, db: &impl DefDatabase) -> Option> { + pub fn declaration_source(&self, db: &dyn DefDatabase) -> Option> { let decl = self.origin.declaration()?; - let value = decl.to_node(db); + let value = decl.to_node(db.upcast()); Some(InFile { file_id: decl.file_id, value }) } } @@ -311,7 +312,7 @@ mod diagnostics { impl DefDiagnostic { pub(super) fn add_to( &self, - db: &impl DefDatabase, + db: &dyn DefDatabase, target_module: LocalModuleId, sink: &mut DiagnosticSink, ) { @@ -320,7 +321,7 @@ mod diagnostics { if *module != target_module { return; } - let decl = declaration.to_node(db); + let decl = declaration.to_node(db.upcast()); sink.push(UnresolvedModule { file: declaration.file_id, decl: AstPtr::new(&decl), -- cgit v1.2.3