Skip to content

Commit 1ea4dae

Browse files
committed
Document expansion queries
1 parent 3f6980e commit 1ea4dae

File tree

1 file changed

+21
-0
lines changed
  • crates/hir_expand/src

1 file changed

+21
-0
lines changed

crates/hir_expand/src/db.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,45 @@ impl TokenExpander {
8787
pub trait AstDatabase: SourceDatabase {
8888
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
8989

90+
/// Main public API -- parsis a hir file, not caring whether it's a real
91+
/// file or a macro expansion.
9092
#[salsa::transparent]
9193
fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>;
94+
/// Implementation for the macro case.
9295
fn parse_macro_expansion(
9396
&self,
9497
macro_file: MacroFile,
9598
) -> ExpandResult<Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>>;
9699

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.
97105
#[salsa::interned]
98106
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.
99109
#[salsa::interned]
100110
fn intern_eager_expansion(&self, eager: EagerCallLoc) -> EagerMacroId;
101111

112+
/// Lowers syntactic macro call to a token tree representation.
102113
#[salsa::transparent]
103114
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.
104118
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.
105121
fn macro_def(&self, id: MacroDefId) -> Option<Arc<TokenExpander>>;
106122

123+
/// Expand macro call to a token tree. This query is LRUed (we keep 128 or so results in memory)
107124
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!
108129
fn expand_proc_macro(&self, call: MacroCallId) -> Result<tt::Subtree, mbe::ExpandError>;
109130
/// Firewall query that returns the error from the `macro_expand` query.
110131
fn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>;

0 commit comments

Comments
 (0)