@@ -1128,10 +1128,12 @@ pub struct Resolver<'ra, 'tcx> {
11281128 builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
11291129 registered_tools : & ' tcx RegisteredTools ,
11301130 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 > > ,
11321134 dummy_ext_bang : Arc < SyntaxExtension > ,
11331135 dummy_ext_derive : Arc < SyntaxExtension > ,
1134- non_macro_attr : MacroData ,
1136+ non_macro_attr : & ' ra MacroData ,
11351137 local_macro_def_scopes : FxHashMap < LocalDefId , Module < ' ra > > ,
11361138 ast_transform_scopes : FxHashMap < LocalExpnId , Module < ' ra > > ,
11371139 unused_macros : FxIndexMap < LocalDefId , ( NodeId , Ident ) > ,
@@ -1241,6 +1243,7 @@ pub struct ResolverArenas<'ra> {
12411243 imports : TypedArena < ImportData < ' ra > > ,
12421244 name_resolutions : TypedArena < RefCell < NameResolution < ' ra > > > ,
12431245 ast_paths : TypedArena < ast:: Path > ,
1246+ macros : TypedArena < MacroData > ,
12441247 dropless : DroplessArena ,
12451248}
12461249
@@ -1287,7 +1290,7 @@ impl<'ra> ResolverArenas<'ra> {
12871290 self . name_resolutions . alloc ( Default :: default ( ) )
12881291 }
12891292 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) )
12911294 }
12921295 fn alloc_macro_rules_binding (
12931296 & ' ra self ,
@@ -1298,6 +1301,9 @@ impl<'ra> ResolverArenas<'ra> {
12981301 fn alloc_ast_paths ( & ' ra self , paths : & [ ast:: Path ] ) -> & ' ra [ ast:: Path ] {
12991302 self . ast_paths . alloc_from_iter ( paths. iter ( ) . cloned ( ) )
13001303 }
1304+ fn alloc_macro ( & ' ra self , macro_data : MacroData ) -> & ' ra MacroData {
1305+ self . macros . alloc ( macro_data)
1306+ }
13011307 fn alloc_pattern_spans ( & ' ra self , spans : impl Iterator < Item = Span > ) -> & ' ra [ Span ] {
13021308 self . dropless . alloc_from_iter ( spans)
13031309 }
@@ -1540,10 +1546,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15401546 builtin_macros : Default :: default ( ) ,
15411547 registered_tools,
15421548 macro_use_prelude : Default :: default ( ) ,
1543- macro_map : FxHashMap :: default ( ) ,
1549+ local_macro_map : Default :: default ( ) ,
1550+ extern_macro_map : Default :: default ( ) ,
15441551 dummy_ext_bang : Arc :: new ( SyntaxExtension :: dummy_bang ( edition) ) ,
15451552 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) ) ) ) ,
15471555 invocation_parent_scopes : Default :: default ( ) ,
15481556 output_macro_rules_scopes : Default :: default ( ) ,
15491557 macro_rules_scopes : Default :: default ( ) ,
@@ -1616,6 +1624,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16161624 )
16171625 }
16181626
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+
16191633 fn next_node_id ( & mut self ) -> NodeId {
16201634 let start = self . next_node_id ;
16211635 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> {
17341748 f ( self , MacroNS ) ;
17351749 }
17361750
1737- fn is_builtin_macro ( & mut self , res : Res ) -> bool {
1751+ fn is_builtin_macro ( & self , res : Res ) -> bool {
17381752 self . get_macro ( res) . is_some_and ( |macro_data| macro_data. ext . builtin_name . is_some ( ) )
17391753 }
17401754
0 commit comments