diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_expand/src/db.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 8f27a7fc9..3e9abd8a1 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs | |||
@@ -87,24 +87,45 @@ impl TokenExpander { | |||
87 | pub trait AstDatabase: SourceDatabase { | 87 | pub trait AstDatabase: SourceDatabase { |
88 | fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; | 88 | fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>; |
89 | 89 | ||
90 | /// Main public API -- parsis a hir file, not caring whether it's a real | ||
91 | /// file or a macro expansion. | ||
90 | #[salsa::transparent] | 92 | #[salsa::transparent] |
91 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>; | 93 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>; |
94 | /// Implementation for the macro case. | ||
92 | fn parse_macro_expansion( | 95 | fn parse_macro_expansion( |
93 | &self, | 96 | &self, |
94 | macro_file: MacroFile, | 97 | macro_file: MacroFile, |
95 | ) -> ExpandResult<Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>>; | 98 | ) -> ExpandResult<Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>>; |
96 | 99 | ||
100 | /// Macro ids. That's probably the tricksiest bit in rust-analyzer, and the | ||
101 | /// reason why we use salsa at all. | ||
102 | /// | ||
103 | /// We encode macro definitions into ids of macro calls, this what allows us | ||
104 | /// to be incremental. | ||
97 | #[salsa::interned] | 105 | #[salsa::interned] |
98 | fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId; | 106 | fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId; |
107 | /// Certain built-in macros are eager (`format!(concat!("file: ", file!(), "{}"")), 92`). | ||
108 | /// For them, we actually want to encode the whole token tree as an argument. | ||
99 | #[salsa::interned] | 109 | #[salsa::interned] |
100 | fn intern_eager_expansion(&self, eager: EagerCallLoc) -> EagerMacroId; | 110 | fn intern_eager_expansion(&self, eager: EagerCallLoc) -> EagerMacroId; |
101 | 111 | ||
112 | /// Lowers syntactic macro call to a token tree representation. | ||
102 | #[salsa::transparent] | 113 | #[salsa::transparent] |
103 | fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>; | 114 | fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>; |
115 | /// Extracts syntax node, corresponding to a macro call. That's a firewall | ||
116 | /// query, only typing in the macro call itself changes the returned | ||
117 | /// subtree. | ||
104 | fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>; | 118 | fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>; |
119 | /// Gets the expander for this macro. This compiles declarative macros, and | ||
120 | /// just fetches procedural ones. | ||
105 | fn macro_def(&self, id: MacroDefId) -> Option<Arc<TokenExpander>>; | 121 | fn macro_def(&self, id: MacroDefId) -> Option<Arc<TokenExpander>>; |
106 | 122 | ||
123 | /// Expand macro call to a token tree. This query is LRUed (we keep 128 or so results in memory) | ||
107 | fn macro_expand(&self, macro_call: MacroCallId) -> ExpandResult<Option<Arc<tt::Subtree>>>; | 124 | fn macro_expand(&self, macro_call: MacroCallId) -> ExpandResult<Option<Arc<tt::Subtree>>>; |
125 | /// Special case of the previous query for procedural macros. We can't LRU | ||
126 | /// proc macros, since they are not deterministic in general, and | ||
127 | /// non-determinism breaks salsa in a very, very, very bad way. @edwin0cheng | ||
128 | /// heroically debugged this once! | ||
108 | fn expand_proc_macro(&self, call: MacroCallId) -> Result<tt::Subtree, mbe::ExpandError>; | 129 | fn expand_proc_macro(&self, call: MacroCallId) -> Result<tt::Subtree, mbe::ExpandError>; |
109 | /// Firewall query that returns the error from the `macro_expand` query. | 130 | /// Firewall query that returns the error from the `macro_expand` query. |
110 | fn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>; | 131 | fn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>; |