@@ -24,7 +24,8 @@ use crate::{
24
24
HirFileId , HirFileIdRepr , MacroCallId , MacroCallKind , MacroCallLoc , MacroDefId , MacroDefKind ,
25
25
MacroFileId ,
26
26
} ;
27
-
27
+ /// This is just to ensure the types of smart_macro_arg and macro_arg are the same
28
+ type MacroArgResult = ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo , Span ) ;
28
29
/// Total limit on the number of tokens produced by any macro invocation.
29
30
///
30
31
/// If an invocation produces more tokens than this limit, it will not be stored in the database and
@@ -98,7 +99,13 @@ pub trait ExpandDatabase: SourceDatabase {
98
99
/// Lowers syntactic macro call to a token tree representation. That's a firewall
99
100
/// query, only typing in the macro call itself changes the returned
100
101
/// subtree.
101
- fn macro_arg ( & self , id : MacroCallId ) -> ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo , Span ) ;
102
+ fn macro_arg ( & self , id : MacroCallId ) -> MacroArgResult ;
103
+ #[ salsa:: transparent]
104
+ fn macro_arg_considering_derives (
105
+ & self ,
106
+ id : MacroCallId ,
107
+ kind : & MacroCallKind ,
108
+ ) -> MacroArgResult ;
102
109
/// Fetches the expander for this macro.
103
110
#[ salsa:: transparent]
104
111
#[ salsa:: invoke( TokenExpander :: macro_expander) ]
@@ -339,20 +346,21 @@ pub(crate) fn parse_with_map(
339
346
}
340
347
}
341
348
}
342
- /// This is just to ensure the types of smart_macro_arg and macro_arg are the same
343
- type MacroArgResult = ( Arc < tt:: Subtree > , SyntaxFixupUndoInfo , Span ) ;
349
+
344
350
/// Imagine the word smart in quotes.
345
351
///
346
352
/// This resolves the [MacroCallId] to check if it is a derive macro if so get the [macro_arg] for the derive.
347
353
/// Other wise return the [macro_arg] for the macro_call_id.
348
354
///
349
355
/// This is not connected to the database so it does not cached the result. However, the inner [macro_arg] query is
350
- fn macro_arg_considering_derives ( db : & dyn ExpandDatabase , id : MacroCallId ) -> MacroArgResult {
351
- let macro_call_kind = db. lookup_intern_macro_call ( id) . kind ;
352
- // FIXME: We called lookup_intern_macro_call twice.
353
- match macro_call_kind {
356
+ fn macro_arg_considering_derives (
357
+ db : & dyn ExpandDatabase ,
358
+ id : MacroCallId ,
359
+ kind : & MacroCallKind ,
360
+ ) -> MacroArgResult {
361
+ match kind {
354
362
// Get the macro arg for the derive macro
355
- MacroCallKind :: Derive { derive_macro_id, .. } => db. macro_arg ( derive_macro_id) ,
363
+ MacroCallKind :: Derive { derive_macro_id, .. } => db. macro_arg ( * derive_macro_id) ,
356
364
// Normal macro arg
357
365
_ => db. macro_arg ( id) ,
358
366
}
@@ -542,7 +550,8 @@ fn macro_expand(
542
550
let ( ExpandResult { value : tt, err } , span) = match loc. def . kind {
543
551
MacroDefKind :: ProcMacro ( ..) => return db. expand_proc_macro ( macro_call_id) . map ( CowArc :: Arc ) ,
544
552
_ => {
545
- let ( macro_arg, undo_info, span) = macro_arg_considering_derives ( db, macro_call_id) ;
553
+ let ( macro_arg, undo_info, span) =
554
+ db. macro_arg_considering_derives ( macro_call_id, & loc. kind ) ;
546
555
547
556
let arg = & * macro_arg;
548
557
let res =
@@ -619,7 +628,7 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
619
628
620
629
fn expand_proc_macro ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ExpandResult < Arc < tt:: Subtree > > {
621
630
let loc = db. lookup_intern_macro_call ( id) ;
622
- let ( macro_arg, undo_info, span) = macro_arg_considering_derives ( db , id ) ;
631
+ let ( macro_arg, undo_info, span) = db . macro_arg_considering_derives ( id , & loc . kind . clone ( ) ) ;
623
632
624
633
let ( expander, ast) = match loc. def . kind {
625
634
MacroDefKind :: ProcMacro ( expander, _, ast) => ( expander, ast) ,
0 commit comments