Skip to content

Commit 98ae447

Browse files
bors[bot]lnicola
andauthored
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 #1987 (comment)) Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 5749c42 + 5953cbd commit 98ae447

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use rustc_hash::FxHashMap;
33

44
use hir::{HirDisplay, PathResolution, SemanticsScope};
5-
use ra_ide_db::RootDatabase;
65
use ra_syntax::{
76
algo::SyntaxRewriter,
87
ast::{self, AstNode},
@@ -32,14 +31,14 @@ impl<'a> AstTransform<'a> for NullTransformer {
3231
}
3332

3433
pub struct SubstituteTypeParams<'a> {
35-
source_scope: &'a SemanticsScope<'a, RootDatabase>,
34+
source_scope: &'a SemanticsScope<'a>,
3635
substs: FxHashMap<hir::TypeParam, ast::TypeRef>,
3736
previous: Box<dyn AstTransform<'a> + 'a>,
3837
}
3938

4039
impl<'a> SubstituteTypeParams<'a> {
4140
pub fn for_trait_impl(
42-
source_scope: &'a SemanticsScope<'a, RootDatabase>,
41+
source_scope: &'a SemanticsScope<'a>,
4342
// FIXME: there's implicit invariant that `trait_` and `source_scope` match...
4443
trait_: hir::Trait,
4544
impl_def: ast::ImplDef,
@@ -126,16 +125,13 @@ impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
126125
}
127126

128127
pub struct QualifyPaths<'a> {
129-
target_scope: &'a SemanticsScope<'a, RootDatabase>,
130-
source_scope: &'a SemanticsScope<'a, RootDatabase>,
128+
target_scope: &'a SemanticsScope<'a>,
129+
source_scope: &'a SemanticsScope<'a>,
131130
previous: Box<dyn AstTransform<'a> + 'a>,
132131
}
133132

134133
impl<'a> QualifyPaths<'a> {
135-
pub fn new(
136-
target_scope: &'a SemanticsScope<'a, RootDatabase>,
137-
source_scope: &'a SemanticsScope<'a, RootDatabase>,
138-
) -> Self {
134+
pub fn new(target_scope: &'a SemanticsScope<'a>, source_scope: &'a SemanticsScope<'a>) -> Self {
139135
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
140136
}
141137

@@ -156,7 +152,7 @@ impl<'a> QualifyPaths<'a> {
156152
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
157153
match resolution {
158154
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)?;
160156
let mut path = path_to_ast(found_path);
161157

162158
let type_args = p

crates/ra_hir/src/semantics.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,19 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
297297
self.with_ctx(|ctx| ctx.file_to_def(file)).map(Module::from)
298298
}
299299

300-
pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db, DB> {
300+
pub fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
301301
let node = self.find_file(node.clone());
302302
let resolver = self.analyze2(node.as_ref(), None).resolver;
303303
SemanticsScope { db: self.db, resolver }
304304
}
305305

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> {
307307
let node = self.find_file(node.clone());
308308
let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
309309
SemanticsScope { db: self.db, resolver }
310310
}
311311

312-
pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db, DB> {
312+
pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
313313
let resolver = def.id.resolver(self.db);
314314
SemanticsScope { db: self.db, resolver }
315315
}
@@ -419,12 +419,12 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
419419
node.ancestors().last().unwrap()
420420
}
421421

422-
pub struct SemanticsScope<'a, DB> {
423-
pub db: &'a DB,
422+
pub struct SemanticsScope<'a> {
423+
pub db: &'a dyn HirDatabase,
424424
resolver: Resolver,
425425
}
426426

427-
impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> {
427+
impl<'a> SemanticsScope<'a> {
428428
pub fn module(&self) -> Option<Module> {
429429
Some(Module { id: self.resolver.module()? })
430430
}
@@ -433,13 +433,13 @@ impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> {
433433
// FIXME: rename to visible_traits to not repeat scope?
434434
pub fn traits_in_scope(&self) -> FxHashSet<TraitId> {
435435
let resolver = &self.resolver;
436-
resolver.traits_in_scope(self.db)
436+
resolver.traits_in_scope(self.db.upcast())
437437
}
438438

439439
pub fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) {
440440
let resolver = &self.resolver;
441441

442-
resolver.process_all_names(self.db, &mut |name, def| {
442+
resolver.process_all_names(self.db.upcast(), &mut |name, def| {
443443
let def = match def {
444444
resolver::ScopeDef::PerNs(it) => {
445445
let items = ScopeDef::all_items(it);

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'a> CompletionContext<'a> {
213213
}
214214
}
215215

216-
pub(crate) fn scope(&self) -> SemanticsScope<'_, RootDatabase> {
216+
pub(crate) fn scope(&self) -> SemanticsScope<'_> {
217217
self.sema.scope_at_offset(&self.token.parent(), self.offset)
218218
}
219219

0 commit comments

Comments
 (0)