aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/semantics.rs
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.rs
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.rs')
-rw-r--r--crates/ra_hir/src/semantics.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 788bb3eb7..55e634528 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -190,7 +190,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
190 T::to_def(self, src) 190 T::to_def(self, src)
191 } 191 }
192 192
193 fn with_ctx<F: FnOnce(&mut SourceToDefCtx<&DB>) -> T, T>(&self, f: F) -> T { 193 fn with_ctx<F: FnOnce(&mut SourceToDefCtx) -> T, T>(&self, f: F) -> T {
194 let mut cache = self.s2d_cache.borrow_mut(); 194 let mut cache = self.s2d_cache.borrow_mut();
195 let mut ctx = SourceToDefCtx { db: self.db, cache: &mut *cache }; 195 let mut ctx = SourceToDefCtx { db: self.db, cache: &mut *cache };
196 f(&mut ctx) 196 f(&mut ctx)
@@ -369,35 +369,35 @@ impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> {
369} 369}
370 370
371// FIXME: Change `HasSource` trait to work with `Semantics` and remove this? 371// FIXME: Change `HasSource` trait to work with `Semantics` and remove this?
372pub fn original_range(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> FileRange { 372pub fn original_range(db: &dyn HirDatabase, node: InFile<&SyntaxNode>) -> FileRange {
373 if let Some(range) = original_range_opt(db, node) { 373 if let Some(range) = original_range_opt(db, node) {
374 let original_file = range.file_id.original_file(db); 374 let original_file = range.file_id.original_file(db.upcast());
375 if range.file_id == original_file.into() { 375 if range.file_id == original_file.into() {
376 return FileRange { file_id: original_file, range: range.value }; 376 return FileRange { file_id: original_file, range: range.value };
377 } 377 }
378 378
379 log::error!("Fail to mapping up more for {:?}", range); 379 log::error!("Fail to mapping up more for {:?}", range);
380 return FileRange { file_id: range.file_id.original_file(db), range: range.value }; 380 return FileRange { file_id: range.file_id.original_file(db.upcast()), range: range.value };
381 } 381 }
382 382
383 // Fall back to whole macro call 383 // Fall back to whole macro call
384 if let Some(expansion) = node.file_id.expansion_info(db) { 384 if let Some(expansion) = node.file_id.expansion_info(db.upcast()) {
385 if let Some(call_node) = expansion.call_node() { 385 if let Some(call_node) = expansion.call_node() {
386 return FileRange { 386 return FileRange {
387 file_id: call_node.file_id.original_file(db), 387 file_id: call_node.file_id.original_file(db.upcast()),
388 range: call_node.value.text_range(), 388 range: call_node.value.text_range(),
389 }; 389 };
390 } 390 }
391 } 391 }
392 392
393 FileRange { file_id: node.file_id.original_file(db), range: node.value.text_range() } 393 FileRange { file_id: node.file_id.original_file(db.upcast()), range: node.value.text_range() }
394} 394}
395 395
396fn original_range_opt( 396fn original_range_opt(
397 db: &impl HirDatabase, 397 db: &dyn HirDatabase,
398 node: InFile<&SyntaxNode>, 398 node: InFile<&SyntaxNode>,
399) -> Option<InFile<TextRange>> { 399) -> Option<InFile<TextRange>> {
400 let expansion = node.file_id.expansion_info(db)?; 400 let expansion = node.file_id.expansion_info(db.upcast())?;
401 401
402 // the input node has only one token ? 402 // the input node has only one token ?
403 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)? 403 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
@@ -419,7 +419,7 @@ fn original_range_opt(
419} 419}
420 420
421fn ascend_call_token( 421fn ascend_call_token(
422 db: &impl HirDatabase, 422 db: &dyn HirDatabase,
423 expansion: &ExpansionInfo, 423 expansion: &ExpansionInfo,
424 token: InFile<SyntaxToken>, 424 token: InFile<SyntaxToken>,
425) -> Option<InFile<SyntaxToken>> { 425) -> Option<InFile<SyntaxToken>> {
@@ -427,7 +427,7 @@ fn ascend_call_token(
427 if origin != Origin::Call { 427 if origin != Origin::Call {
428 return None; 428 return None;
429 } 429 }
430 if let Some(info) = mapped.file_id.expansion_info(db) { 430 if let Some(info) = mapped.file_id.expansion_info(db.upcast()) {
431 return ascend_call_token(db, &info, mapped); 431 return ascend_call_token(db, &info, mapped);
432 } 432 }
433 Some(mapped) 433 Some(mapped)