aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/db.rs3
-rw-r--r--crates/ra_hir/src/ids.rs53
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_ide_api/src/change.rs2
-rw-r--r--crates/ra_ide_api/src/status.rs34
5 files changed, 61 insertions, 33 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 872103219..3afd0994c 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -33,8 +33,11 @@ pub trait AstDatabase: SourceDatabase {
33 #[salsa::transparent] 33 #[salsa::transparent]
34 #[salsa::invoke(crate::source_id::AstIdMap::file_item_query)] 34 #[salsa::invoke(crate::source_id::AstIdMap::file_item_query)]
35 fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>; 35 fn ast_id_to_node(&self, file_id: HirFileId, ast_id: ErasedFileAstId) -> TreeArc<SyntaxNode>;
36 #[salsa::transparent]
36 #[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)] 37 #[salsa::invoke(crate::ids::HirFileId::parse_or_expand_query)]
37 fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>; 38 fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>;
39 #[salsa::invoke(crate::ids::HirFileId::parse_macro_query)]
40 fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<TreeArc<SyntaxNode>>;
38 41
39 #[salsa::invoke(crate::ids::macro_def_query)] 42 #[salsa::invoke(crate::ids::macro_def_query)]
40 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; 43 fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 79e32e579..a95561812 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -62,32 +62,35 @@ impl HirFileId {
62 file_id: HirFileId, 62 file_id: HirFileId,
63 ) -> Option<TreeArc<SyntaxNode>> { 63 ) -> Option<TreeArc<SyntaxNode>> {
64 db.check_canceled(); 64 db.check_canceled();
65 let _p = profile("parse_or_expand_query");
66 match file_id.0 { 65 match file_id.0 {
67 HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()), 66 HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()),
68 HirFileIdRepr::Macro(macro_file) => { 67 HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file),
69 let macro_call_id = macro_file.macro_call_id; 68 }
70 let tt = db 69 }
71 .macro_expand(macro_call_id) 70
72 .map_err(|err| { 71 pub(crate) fn parse_macro_query(
73 // Note: 72 db: &impl AstDatabase,
74 // The final goal we would like to make all parse_macro success, 73 macro_file: MacroFile,
75 // such that the following log will not call anyway. 74 ) -> Option<TreeArc<SyntaxNode>> {
76 log::warn!( 75 let _p = profile("parse_macro_query");
77 "fail on macro_parse: (reason: {}) {}", 76 let macro_call_id = macro_file.macro_call_id;
78 err, 77 let tt = db
79 macro_call_id.debug_dump(db) 78 .macro_expand(macro_call_id)
80 ); 79 .map_err(|err| {
81 }) 80 // Note:
82 .ok()?; 81 // The final goal we would like to make all parse_macro success,
83 match macro_file.macro_file_kind { 82 // such that the following log will not call anyway.
84 MacroFileKind::Items => { 83 log::warn!(
85 Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()) 84 "fail on macro_parse: (reason: {}) {}",
86 } 85 err,
87 MacroFileKind::Expr => { 86 macro_call_id.debug_dump(db)
88 mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) 87 );
89 } 88 })
90 } 89 .ok()?;
90 match macro_file.macro_file_kind {
91 MacroFileKind::Items => Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()),
92 MacroFileKind::Expr => {
93 mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned())
91 } 94 }
92 } 95 }
93 } 96 }
@@ -100,7 +103,7 @@ enum HirFileIdRepr {
100} 103}
101 104
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 105#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
103struct MacroFile { 106pub struct MacroFile {
104 macro_call_id: MacroCallId, 107 macro_call_id: MacroCallId,
105 macro_file_kind: MacroFileKind, 108 macro_file_kind: MacroFileKind,
106} 109}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index f2a31795d..18dea5f17 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -60,7 +60,7 @@ pub use self::{
60 path::{Path, PathKind}, 60 path::{Path, PathKind},
61 name::Name, 61 name::Name,
62 source_id::{AstIdMap, ErasedFileAstId}, 62 source_id::{AstIdMap, ErasedFileAstId},
63 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc}, 63 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, MacroFile},
64 nameres::{PerNs, Namespace, ImportId}, 64 nameres::{PerNs, Namespace, ImportId},
65 ty::{Ty, ApplicationTy, TypeCtor, TraitRef, Substs, display::HirDisplay, CallableDef}, 65 ty::{Ty, ApplicationTy, TypeCtor, TraitRef, Substs, display::HirDisplay, CallableDef},
66 impl_block::{ImplBlock, ImplItem}, 66 impl_block::{ImplBlock, ImplItem},
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs
index 02814ce56..247dc0fee 100644
--- a/crates/ra_ide_api/src/change.rs
+++ b/crates/ra_ide_api/src/change.rs
@@ -226,7 +226,7 @@ impl RootDatabase {
226 226
227 self.query(ra_db::ParseQuery).sweep(sweep); 227 self.query(ra_db::ParseQuery).sweep(sweep);
228 228
229 self.query(hir::db::ParseOrExpandQuery).sweep(sweep); 229 self.query(hir::db::ParseMacroQuery).sweep(sweep);
230 self.query(hir::db::MacroDefQuery).sweep(sweep); 230 self.query(hir::db::MacroDefQuery).sweep(sweep);
231 self.query(hir::db::MacroArgQuery).sweep(sweep); 231 self.query(hir::db::MacroArgQuery).sweep(sweep);
232 self.query(hir::db::MacroExpandQuery).sweep(sweep); 232 self.query(hir::db::MacroExpandQuery).sweep(sweep);
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index 822279812..0cdeb15eb 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -4,12 +4,12 @@ use std::{
4 sync::Arc, 4 sync::Arc,
5}; 5};
6 6
7use ra_syntax::{TreeArc, SyntaxNode}; 7use ra_syntax::{TreeArc, SyntaxNode, Parse, AstNode};
8use ra_db::{ 8use ra_db::{
9 FileTextQuery, SourceRootId, 9 FileTextQuery, SourceRootId,
10 salsa::{Database, debug::{DebugQueryTable, TableEntry}}, 10 salsa::{Database, debug::{DebugQueryTable, TableEntry}},
11}; 11};
12use hir::HirFileId; 12use hir::MacroFile;
13 13
14use crate::{ 14use crate::{
15 FileId, db::RootDatabase, 15 FileId, db::RootDatabase,
@@ -17,18 +17,23 @@ use crate::{
17}; 17};
18 18
19pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { 19pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
20 db.query(hir::db::ParseOrExpandQuery).entries::<SyntaxTreeStats>() 20 db.query(ra_db::ParseQuery).entries::<SyntaxTreeStats>()
21}
22pub(crate) fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
23 db.query(hir::db::ParseMacroQuery).entries::<SyntaxTreeStats>()
21} 24}
22 25
23pub(crate) fn status(db: &RootDatabase) -> String { 26pub(crate) fn status(db: &RootDatabase) -> String {
24 let files_stats = db.query(FileTextQuery).entries::<FilesStats>(); 27 let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
25 let syntax_tree_stats = syntax_tree_stats(db); 28 let syntax_tree_stats = syntax_tree_stats(db);
29 let macro_syntax_tree_stats = macro_syntax_tree_stats(db);
26 let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>(); 30 let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>();
27 format!( 31 format!(
28 "{}\n{}\n{}\n\n\nmemory:\n{}\ngc {:?} seconds ago", 32 "{}\n{}\n{}\n{} (macros)\n\n\nmemory:\n{}\ngc {:?} seconds ago",
29 files_stats, 33 files_stats,
30 symbols_stats, 34 symbols_stats,
31 syntax_tree_stats, 35 syntax_tree_stats,
36 macro_syntax_tree_stats,
32 MemoryStats::current(), 37 MemoryStats::current(),
33 db.last_gc.elapsed().as_secs(), 38 db.last_gc.elapsed().as_secs(),
34 ) 39 )
@@ -73,10 +78,27 @@ impl fmt::Display for SyntaxTreeStats {
73 } 78 }
74} 79}
75 80
76impl FromIterator<TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats { 81impl FromIterator<TableEntry<FileId, Parse>> for SyntaxTreeStats {
82 fn from_iter<T>(iter: T) -> SyntaxTreeStats
83 where
84 T: IntoIterator<Item = TableEntry<FileId, Parse>>,
85 {
86 let mut res = SyntaxTreeStats::default();
87 for entry in iter {
88 res.total += 1;
89 if let Some(tree) = entry.value.as_ref().map(|it| &it.tree) {
90 res.retained += 1;
91 res.retained_size += tree.syntax().memory_size_of_subtree();
92 }
93 }
94 res
95 }
96}
97
98impl FromIterator<TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>> for SyntaxTreeStats {
77 fn from_iter<T>(iter: T) -> SyntaxTreeStats 99 fn from_iter<T>(iter: T) -> SyntaxTreeStats
78 where 100 where
79 T: IntoIterator<Item = TableEntry<HirFileId, Option<TreeArc<SyntaxNode>>>>, 101 T: IntoIterator<Item = TableEntry<MacroFile, Option<TreeArc<SyntaxNode>>>>,
80 { 102 {
81 let mut res = SyntaxTreeStats::default(); 103 let mut res = SyntaxTreeStats::default();
82 for entry in iter { 104 for entry in iter {