aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/db.rs2
-rw-r--r--crates/hir_expand/src/db.rs36
-rw-r--r--crates/hir_expand/src/lib.rs2
-rw-r--r--crates/ide/src/status.rs2
-rw-r--r--crates/ide_db/src/apply_change.rs4
-rw-r--r--crates/ide_db/src/lib.rs2
6 files changed, 19 insertions, 29 deletions
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs
index 07333c453..8c767b249 100644
--- a/crates/hir/src/db.rs
+++ b/crates/hir/src/db.rs
@@ -11,7 +11,7 @@ pub use hir_def::db::{
11}; 11};
12pub use hir_expand::db::{ 12pub use hir_expand::db::{
13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, 13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery, 14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
15}; 15};
16pub use hir_ty::db::*; 16pub use hir_ty::db::*;
17 17
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index fc512517c..a9099eb22 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -88,7 +88,7 @@ pub trait AstDatabase: SourceDatabase {
88 #[salsa::transparent] 88 #[salsa::transparent]
89 fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>; 89 fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>;
90 fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>; 90 fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>;
91 fn parse_macro( 91 fn parse_macro_expansion(
92 &self, 92 &self,
93 macro_file: MacroFile, 93 macro_file: MacroFile,
94 ) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>; 94 ) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>;
@@ -138,16 +138,13 @@ pub fn expand_hypothetical(
138 Some((node.syntax_node(), token)) 138 Some((node.syntax_node(), token))
139} 139}
140 140
141pub(crate) fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> { 141fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
142 let map = 142 let map =
143 db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it)); 143 db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it));
144 Arc::new(map) 144 Arc::new(map)
145} 145}
146 146
147pub(crate) fn macro_def( 147fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
148 db: &dyn AstDatabase,
149 id: MacroDefId,
150) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
151 match id.kind { 148 match id.kind {
152 MacroDefKind::Declarative => { 149 MacroDefKind::Declarative => {
153 let macro_call = id.ast_id?.to_node(db); 150 let macro_call = id.ast_id?.to_node(db);
@@ -178,7 +175,7 @@ pub(crate) fn macro_def(
178 } 175 }
179} 176}
180 177
181pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> { 178fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
182 let id = match id { 179 let id = match id {
183 MacroCallId::LazyMacro(id) => id, 180 MacroCallId::LazyMacro(id) => id,
184 MacroCallId::EagerMacro(_id) => { 181 MacroCallId::EagerMacro(_id) => {
@@ -191,16 +188,13 @@ pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<Gr
191 Some(arg.green().clone()) 188 Some(arg.green().clone())
192} 189}
193 190
194pub(crate) fn macro_arg( 191fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
195 db: &dyn AstDatabase,
196 id: MacroCallId,
197) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
198 let arg = db.macro_arg_text(id)?; 192 let arg = db.macro_arg_text(id)?;
199 let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?; 193 let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?;
200 Some(Arc::new((tt, tmap))) 194 Some(Arc::new((tt, tmap)))
201} 195}
202 196
203pub(crate) fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> { 197fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> {
204 macro_expand_with_arg(db, id, None) 198 macro_expand_with_arg(db, id, None)
205} 199}
206 200
@@ -258,7 +252,7 @@ fn macro_expand_with_arg(
258 MacroResult { value: Some(Arc::new(tt)), error: err.map(|e| format!("{:?}", e)) } 252 MacroResult { value: Some(Arc::new(tt)), error: err.map(|e| format!("{:?}", e)) }
259} 253}
260 254
261pub(crate) fn expand_proc_macro( 255fn expand_proc_macro(
262 db: &dyn AstDatabase, 256 db: &dyn AstDatabase,
263 id: MacroCallId, 257 id: MacroCallId,
264) -> Result<tt::Subtree, mbe::ExpandError> { 258) -> Result<tt::Subtree, mbe::ExpandError> {
@@ -285,23 +279,23 @@ pub(crate) fn expand_proc_macro(
285 expander.expand(db, lazy_id, &macro_arg.0) 279 expander.expand(db, lazy_id, &macro_arg.0)
286} 280}
287 281
288pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> { 282fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
289 match file_id.0 { 283 match file_id.0 {
290 HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), 284 HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
291 HirFileIdRepr::MacroFile(macro_file) => { 285 HirFileIdRepr::MacroFile(macro_file) => {
292 db.parse_macro(macro_file).map(|(it, _)| it.syntax_node()).value 286 db.parse_macro_expansion(macro_file).map(|(it, _)| it.syntax_node()).value
293 } 287 }
294 } 288 }
295} 289}
296 290
297pub(crate) fn parse_macro( 291fn parse_macro_expansion(
298 db: &dyn AstDatabase, 292 db: &dyn AstDatabase,
299 macro_file: MacroFile, 293 macro_file: MacroFile,
300) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)> { 294) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)> {
301 parse_macro_with_arg(db, macro_file, None) 295 parse_macro_with_arg(db, macro_file, None)
302} 296}
303 297
304pub fn parse_macro_with_arg( 298fn parse_macro_with_arg(
305 db: &dyn AstDatabase, 299 db: &dyn AstDatabase,
306 macro_file: MacroFile, 300 macro_file: MacroFile,
307 arg: Option<Arc<(tt::Subtree, mbe::TokenMap)>>, 301 arg: Option<Arc<(tt::Subtree, mbe::TokenMap)>>,
@@ -359,11 +353,7 @@ pub fn parse_macro_with_arg(
359 353
360 match result.error { 354 match result.error {
361 Some(error) => { 355 Some(error) => {
362 // FIXME: 356 // Safety check for recursive identity macro.
363 // In future, we should propagate the actual error with recovery information
364 // instead of ignore the error here.
365
366 // Safe check for recurisve identity macro
367 let node = parse.syntax_node(); 357 let node = parse.syntax_node();
368 let file: HirFileId = macro_file.into(); 358 let file: HirFileId = macro_file.into();
369 let call_node = match file.call_node(db) { 359 let call_node = match file.call_node(db) {
@@ -374,7 +364,7 @@ pub fn parse_macro_with_arg(
374 }; 364 };
375 365
376 if !diff(&node, &call_node.value).is_empty() { 366 if !diff(&node, &call_node.value).is_empty() {
377 MacroResult { value: Some((parse, Arc::new(rev_token_map))), error: None } 367 MacroResult { value: Some((parse, Arc::new(rev_token_map))), error: Some(error) }
378 } else { 368 } else {
379 return MacroResult::error(error); 369 return MacroResult::error(error);
380 } 370 }
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 9fc697d6f..83e09738b 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -144,7 +144,7 @@ impl HirFileId {
144 let def_tt = loc.def.ast_id?.to_node(db).token_tree()?; 144 let def_tt = loc.def.ast_id?.to_node(db).token_tree()?;
145 145
146 let macro_def = db.macro_def(loc.def)?; 146 let macro_def = db.macro_def(loc.def)?;
147 let (parse, exp_map) = db.parse_macro(macro_file).value?; 147 let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
148 let macro_arg = db.macro_arg(macro_file.macro_call_id)?; 148 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
149 149
150 Some(ExpansionInfo { 150 Some(ExpansionInfo {
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 8b4a1652e..b75f88ed9 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -19,7 +19,7 @@ fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
19 ide_db::base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() 19 ide_db::base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>()
20} 20}
21fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { 21fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
22 hir::db::ParseMacroQuery.in_db(db).entries::<SyntaxTreeStats>() 22 hir::db::ParseMacroExpansionQuery.in_db(db).entries::<SyntaxTreeStats>()
23} 23}
24 24
25// Feature: Status 25// Feature: Status
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs
index da16fa21d..987191fe3 100644
--- a/crates/ide_db/src/apply_change.rs
+++ b/crates/ide_db/src/apply_change.rs
@@ -76,7 +76,7 @@ impl RootDatabase {
76 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 76 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
77 77
78 base_db::ParseQuery.in_db(self).sweep(sweep); 78 base_db::ParseQuery.in_db(self).sweep(sweep);
79 hir::db::ParseMacroQuery.in_db(self).sweep(sweep); 79 hir::db::ParseMacroExpansionQuery.in_db(self).sweep(sweep);
80 80
81 // Macros do take significant space, but less then the syntax trees 81 // Macros do take significant space, but less then the syntax trees
82 // self.query(hir::db::MacroDefQuery).sweep(sweep); 82 // self.query(hir::db::MacroDefQuery).sweep(sweep);
@@ -143,7 +143,7 @@ impl RootDatabase {
143 hir::db::AstIdMapQuery 143 hir::db::AstIdMapQuery
144 hir::db::MacroArgTextQuery 144 hir::db::MacroArgTextQuery
145 hir::db::MacroDefQuery 145 hir::db::MacroDefQuery
146 hir::db::ParseMacroQuery 146 hir::db::ParseMacroExpansionQuery
147 hir::db::MacroExpandQuery 147 hir::db::MacroExpandQuery
148 148
149 // DefDatabase 149 // DefDatabase
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs
index 38ebdbf79..05139a651 100644
--- a/crates/ide_db/src/lib.rs
+++ b/crates/ide_db/src/lib.rs
@@ -113,7 +113,7 @@ impl RootDatabase {
113 pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { 113 pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) {
114 let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP); 114 let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
115 base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); 115 base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
116 hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity); 116 hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
117 hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); 117 hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
118 } 118 }
119} 119}