@@ -1128,10 +1128,12 @@ pub struct Resolver<'ra, 'tcx> {
1128
1128
builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
1129
1129
registered_tools : & ' tcx RegisteredTools ,
1130
1130
macro_use_prelude : FxIndexMap < Symbol , NameBinding < ' ra > > ,
1131
- macro_map : FxHashMap < DefId , MacroData > ,
1131
+ local_macro_map : FxHashMap < LocalDefId , & ' ra MacroData > ,
1132
+ /// Lazily populated cache of macros loaded from external crates.
1133
+ extern_macro_map : RefCell < FxHashMap < DefId , & ' ra MacroData > > ,
1132
1134
dummy_ext_bang : Arc < SyntaxExtension > ,
1133
1135
dummy_ext_derive : Arc < SyntaxExtension > ,
1134
- non_macro_attr : MacroData ,
1136
+ non_macro_attr : & ' ra MacroData ,
1135
1137
local_macro_def_scopes : FxHashMap < LocalDefId , Module < ' ra > > ,
1136
1138
ast_transform_scopes : FxHashMap < LocalExpnId , Module < ' ra > > ,
1137
1139
unused_macros : FxIndexMap < LocalDefId , ( NodeId , Ident ) > ,
@@ -1241,6 +1243,7 @@ pub struct ResolverArenas<'ra> {
1241
1243
imports : TypedArena < ImportData < ' ra > > ,
1242
1244
name_resolutions : TypedArena < RefCell < NameResolution < ' ra > > > ,
1243
1245
ast_paths : TypedArena < ast:: Path > ,
1246
+ macros : TypedArena < MacroData > ,
1244
1247
dropless : DroplessArena ,
1245
1248
}
1246
1249
@@ -1287,7 +1290,7 @@ impl<'ra> ResolverArenas<'ra> {
1287
1290
self . name_resolutions . alloc ( Default :: default ( ) )
1288
1291
}
1289
1292
fn alloc_macro_rules_scope ( & ' ra self , scope : MacroRulesScope < ' ra > ) -> MacroRulesScopeRef < ' ra > {
1290
- Interned :: new_unchecked ( self . dropless . alloc ( Cell :: new ( scope) ) )
1293
+ self . dropless . alloc ( Cell :: new ( scope) )
1291
1294
}
1292
1295
fn alloc_macro_rules_binding (
1293
1296
& ' ra self ,
@@ -1298,6 +1301,9 @@ impl<'ra> ResolverArenas<'ra> {
1298
1301
fn alloc_ast_paths ( & ' ra self , paths : & [ ast:: Path ] ) -> & ' ra [ ast:: Path ] {
1299
1302
self . ast_paths . alloc_from_iter ( paths. iter ( ) . cloned ( ) )
1300
1303
}
1304
+ fn alloc_macro ( & ' ra self , macro_data : MacroData ) -> & ' ra MacroData {
1305
+ self . macros . alloc ( macro_data)
1306
+ }
1301
1307
fn alloc_pattern_spans ( & ' ra self , spans : impl Iterator < Item = Span > ) -> & ' ra [ Span ] {
1302
1308
self . dropless . alloc_from_iter ( spans)
1303
1309
}
@@ -1540,10 +1546,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1540
1546
builtin_macros : Default :: default ( ) ,
1541
1547
registered_tools,
1542
1548
macro_use_prelude : Default :: default ( ) ,
1543
- macro_map : FxHashMap :: default ( ) ,
1549
+ local_macro_map : Default :: default ( ) ,
1550
+ extern_macro_map : Default :: default ( ) ,
1544
1551
dummy_ext_bang : Arc :: new ( SyntaxExtension :: dummy_bang ( edition) ) ,
1545
1552
dummy_ext_derive : Arc :: new ( SyntaxExtension :: dummy_derive ( edition) ) ,
1546
- non_macro_attr : MacroData :: new ( Arc :: new ( SyntaxExtension :: non_macro_attr ( edition) ) ) ,
1553
+ non_macro_attr : arenas
1554
+ . alloc_macro ( MacroData :: new ( Arc :: new ( SyntaxExtension :: non_macro_attr ( edition) ) ) ) ,
1547
1555
invocation_parent_scopes : Default :: default ( ) ,
1548
1556
output_macro_rules_scopes : Default :: default ( ) ,
1549
1557
macro_rules_scopes : Default :: default ( ) ,
@@ -1616,6 +1624,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1616
1624
)
1617
1625
}
1618
1626
1627
+ fn new_local_macro ( & mut self , def_id : LocalDefId , macro_data : MacroData ) -> & ' ra MacroData {
1628
+ let mac = self . arenas . alloc_macro ( macro_data) ;
1629
+ self . local_macro_map . insert ( def_id, mac) ;
1630
+ mac
1631
+ }
1632
+
1619
1633
fn next_node_id ( & mut self ) -> NodeId {
1620
1634
let start = self . next_node_id ;
1621
1635
let next = start. as_u32 ( ) . checked_add ( 1 ) . expect ( "input too large; ran out of NodeIds" ) ;
@@ -1734,7 +1748,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1734
1748
f ( self , MacroNS ) ;
1735
1749
}
1736
1750
1737
- fn is_builtin_macro ( & mut self , res : Res ) -> bool {
1751
+ fn is_builtin_macro ( & self , res : Res ) -> bool {
1738
1752
self . get_macro ( res) . is_some_and ( |macro_data| macro_data. ext . builtin_name . is_some ( ) )
1739
1753
}
1740
1754
0 commit comments