aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-01 08:17:16 +0100
committerGitHub <[email protected]>2020-07-01 08:17:16 +0100
commit98ae447fa7112bef8c525f86652d6484646251f1 (patch)
treeb070bc86e7ccd6b12a8b1d80732020cee7035057 /crates
parent5749c42b71a2485148c374a15f087f0922c138e6 (diff)
parent5953cbd7aefa90da67829fe8e92d066b460ee447 (diff)
Merge #5153
5153: Make SemanticsScope non-generic r=matklad a=lnicola This slightly reduces the build times: ![image](https://user-images.githubusercontent.com/308347/86210975-3a809480-bb7e-11ea-8975-788457f6b353.png) (compare to https://github.com/rust-analyzer/rust-analyzer/issues/1987#issuecomment-652202248) Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/ast_transform.rs16
-rw-r--r--crates/ra_hir/src/semantics.rs16
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs2
3 files changed, 15 insertions, 19 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 00fa95b6c..01adb834c 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -2,7 +2,6 @@
2use rustc_hash::FxHashMap; 2use rustc_hash::FxHashMap;
3 3
4use hir::{HirDisplay, PathResolution, SemanticsScope}; 4use hir::{HirDisplay, PathResolution, SemanticsScope};
5use ra_ide_db::RootDatabase;
6use ra_syntax::{ 5use ra_syntax::{
7 algo::SyntaxRewriter, 6 algo::SyntaxRewriter,
8 ast::{self, AstNode}, 7 ast::{self, AstNode},
@@ -32,14 +31,14 @@ impl<'a> AstTransform<'a> for NullTransformer {
32} 31}
33 32
34pub struct SubstituteTypeParams<'a> { 33pub struct SubstituteTypeParams<'a> {
35 source_scope: &'a SemanticsScope<'a, RootDatabase>, 34 source_scope: &'a SemanticsScope<'a>,
36 substs: FxHashMap<hir::TypeParam, ast::TypeRef>, 35 substs: FxHashMap<hir::TypeParam, ast::TypeRef>,
37 previous: Box<dyn AstTransform<'a> + 'a>, 36 previous: Box<dyn AstTransform<'a> + 'a>,
38} 37}
39 38
40impl<'a> SubstituteTypeParams<'a> { 39impl<'a> SubstituteTypeParams<'a> {
41 pub fn for_trait_impl( 40 pub fn for_trait_impl(
42 source_scope: &'a SemanticsScope<'a, RootDatabase>, 41 source_scope: &'a SemanticsScope<'a>,
43 // FIXME: there's implicit invariant that `trait_` and `source_scope` match... 42 // FIXME: there's implicit invariant that `trait_` and `source_scope` match...
44 trait_: hir::Trait, 43 trait_: hir::Trait,
45 impl_def: ast::ImplDef, 44 impl_def: ast::ImplDef,
@@ -126,16 +125,13 @@ impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
126} 125}
127 126
128pub struct QualifyPaths<'a> { 127pub struct QualifyPaths<'a> {
129 target_scope: &'a SemanticsScope<'a, RootDatabase>, 128 target_scope: &'a SemanticsScope<'a>,
130 source_scope: &'a SemanticsScope<'a, RootDatabase>, 129 source_scope: &'a SemanticsScope<'a>,
131 previous: Box<dyn AstTransform<'a> + 'a>, 130 previous: Box<dyn AstTransform<'a> + 'a>,
132} 131}
133 132
134impl<'a> QualifyPaths<'a> { 133impl<'a> QualifyPaths<'a> {
135 pub fn new( 134 pub fn new(target_scope: &'a SemanticsScope<'a>, source_scope: &'a SemanticsScope<'a>) -> Self {
136 target_scope: &'a SemanticsScope<'a, RootDatabase>,
137 source_scope: &'a SemanticsScope<'a, RootDatabase>,
138 ) -> Self {
139 Self { target_scope, source_scope, previous: Box::new(NullTransformer) } 135 Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
140 } 136 }
141 137
@@ -156,7 +152,7 @@ impl<'a> QualifyPaths<'a> {
156 let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; 152 let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
157 match resolution { 153 match resolution {
158 PathResolution::Def(def) => { 154 PathResolution::Def(def) => {
159 let found_path = from.find_use_path(self.source_scope.db, def)?; 155 let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
160 let mut path = path_to_ast(found_path); 156 let mut path = path_to_ast(found_path);
161 157
162 let type_args = p 158 let type_args = p
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 6a49c424a..810c49d6f 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -297,19 +297,19 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
297 self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from) 297 self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from)
298 } 298 }
299 299
300 pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db, DB> { 300 pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
301 let node = self.find_file(node.clone()); 301 let node = self.find_file(node.clone());
302 let resolver = self.analyze2(node.as_ref(), None).resolver; 302 let resolver = self.analyze2(node.as_ref(), None).resolver;
303 SemanticsScope { db: self.db, resolver } 303 SemanticsScope { db: self.db, resolver }
304 } 304 }
305 305
306 pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db, DB> { 306 pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
307 let node = self.find_file(node.clone()); 307 let node = self.find_file(node.clone());
308 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; 308 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
309 SemanticsScope { db: self.db, resolver } 309 SemanticsScope { db: self.db, resolver }
310 } 310 }
311 311
312 pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db, DB> { 312 pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
313 let resolver = def.id.resolver(self.db); 313 let resolver = def.id.resolver(self.db);
314 SemanticsScope { db: self.db, resolver } 314 SemanticsScope { db: self.db, resolver }
315 } 315 }
@@ -419,12 +419,12 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
419 node.ancestors().last().unwrap() 419 node.ancestors().last().unwrap()
420} 420}
421 421
422pub struct SemanticsScope<'a, DB> { 422pub struct SemanticsScope<'a> {
423 pub db: &'a DB, 423 pub db: &'a dyn HirDatabase,
424 resolver: Resolver, 424 resolver: Resolver,
425} 425}
426 426
427impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> { 427impl<'a> SemanticsScope<'a> {
428 pub fn module(&self) -> Option<Module> { 428 pub fn module(&self) -> Option<Module> {
429 Some(Module { id: self.resolver.module()? }) 429 Some(Module { id: self.resolver.module()? })
430 } 430 }
@@ -433,13 +433,13 @@ impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> {
433 // FIXME: rename to visible_traits to not repeat scope? 433 // FIXME: rename to visible_traits to not repeat scope?
434 pub fn traits_in_scope(&self) -> FxHashSet<TraitId> { 434 pub fn traits_in_scope(&self) -> FxHashSet<TraitId> {
435 let resolver = &self.resolver; 435 let resolver = &self.resolver;
436 resolver.traits_in_scope(self.db) 436 resolver.traits_in_scope(self.db.upcast())
437 } 437 }
438 438
439 pub fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) { 439 pub fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) {
440 let resolver = &self.resolver; 440 let resolver = &self.resolver;
441 441
442 resolver.process_all_names(self.db, &mut |name, def| { 442 resolver.process_all_names(self.db.upcast(), &mut |name, def| {
443 let def = match def { 443 let def = match def {
444 resolver::ScopeDef::PerNs(it) => { 444 resolver::ScopeDef::PerNs(it) => {
445 let items = ScopeDef::all_items(it); 445 let items = ScopeDef::all_items(it);
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 560fb19e6..ef22ea54d 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -213,7 +213,7 @@ impl<'a> CompletionContext<'a> {
213 } 213 }
214 } 214 }
215 215
216 pub(crate) fn scope(&self) -> SemanticsScope<'_, RootDatabase> { 216 pub(crate) fn scope(&self) -> SemanticsScope<'_> {
217 self.sema.scope_at_offset(&self.token.parent(), self.offset) 217 self.sema.scope_at_offset(&self.token.parent(), self.offset)
218 } 218 }
219 219