@@ -845,13 +845,18 @@ pub struct ModuleS<'a> {
845
845
// access the children must be preceded with a
846
846
// `populate_module_if_necessary` call.
847
847
populated : Cell < bool > ,
848
+
849
+ arenas : & ' a ResolverArenas < ' a > ,
848
850
}
849
851
850
852
pub type Module < ' a > = & ' a ModuleS < ' a > ;
851
853
852
854
impl < ' a > ModuleS < ' a > {
853
-
854
- fn new ( parent_link : ParentLink < ' a > , def : Option < Def > , external : bool , is_public : bool ) -> Self {
855
+ fn new ( parent_link : ParentLink < ' a > ,
856
+ def : Option < Def > ,
857
+ external : bool ,
858
+ is_public : bool ,
859
+ arenas : & ' a ResolverArenas < ' a > ) -> Self {
855
860
ModuleS {
856
861
parent_link : parent_link,
857
862
def : def,
@@ -865,6 +870,7 @@ impl<'a> ModuleS<'a> {
865
870
pub_count : Cell :: new ( 0 ) ,
866
871
pub_glob_count : Cell :: new ( 0 ) ,
867
872
populated : Cell :: new ( !external) ,
873
+ arenas : arenas
868
874
}
869
875
}
870
876
@@ -881,8 +887,9 @@ impl<'a> ModuleS<'a> {
881
887
}
882
888
883
889
// Define the name or return the existing binding if there is a collision.
884
- fn try_define_child ( & self , name : Name , ns : Namespace , binding : & ' a NameBinding < ' a > )
890
+ fn try_define_child ( & self , name : Name , ns : Namespace , binding : NameBinding < ' a > )
885
891
-> Result < ( ) , & ' a NameBinding < ' a > > {
892
+ let binding = self . arenas . alloc_name_binding ( binding) ;
886
893
let mut children = self . resolutions . borrow_mut ( ) ;
887
894
let resolution = children. entry ( ( name, ns) ) . or_insert_with ( Default :: default) ;
888
895
@@ -898,6 +905,11 @@ impl<'a> ModuleS<'a> {
898
905
resolution. try_define ( binding)
899
906
}
900
907
908
+ fn add_import_directive ( & self , import_directive : ImportDirective ) {
909
+ let import_directive = self . arenas . alloc_import_directive ( import_directive) ;
910
+ self . unresolved_imports . borrow_mut ( ) . push ( import_directive) ;
911
+ }
912
+
901
913
fn increment_outstanding_references_for ( & self , name : Name , ns : Namespace ) {
902
914
let mut children = self . resolutions . borrow_mut ( ) ;
903
915
children. entry ( ( name, ns) ) . or_insert_with ( Default :: default) . outstanding_references += 1 ;
@@ -995,14 +1007,14 @@ bitflags! {
995
1007
}
996
1008
997
1009
// Records a possibly-private value, type, or module definition.
998
- #[ derive( Debug ) ]
1010
+ #[ derive( Clone , Debug ) ]
999
1011
pub struct NameBinding < ' a > {
1000
1012
modifiers : DefModifiers ,
1001
1013
kind : NameBindingKind < ' a > ,
1002
1014
span : Option < Span > ,
1003
1015
}
1004
1016
1005
- #[ derive( Debug ) ]
1017
+ #[ derive( Clone , Debug ) ]
1006
1018
enum NameBindingKind < ' a > {
1007
1019
Def ( Def ) ,
1008
1020
Module ( Module < ' a > ) ,
@@ -1171,6 +1183,12 @@ pub struct ResolverArenas<'a> {
1171
1183
}
1172
1184
1173
1185
impl < ' a > ResolverArenas < ' a > {
1186
+ fn alloc_module ( & ' a self , module : ModuleS < ' a > ) -> Module < ' a > {
1187
+ self . modules . alloc ( module)
1188
+ }
1189
+ fn alloc_name_binding ( & ' a self , name_binding : NameBinding < ' a > ) -> & ' a NameBinding < ' a > {
1190
+ self . name_bindings . alloc ( name_binding)
1191
+ }
1174
1192
fn alloc_import_directive ( & ' a self , import_directive : ImportDirective ) -> & ' a ImportDirective {
1175
1193
self . import_directives . alloc ( import_directive)
1176
1194
}
@@ -1189,8 +1207,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1189
1207
arenas : & ' a ResolverArenas < ' a > )
1190
1208
-> Resolver < ' a , ' tcx > {
1191
1209
let root_def_id = ast_map. local_def_id ( CRATE_NODE_ID ) ;
1192
- let graph_root = ModuleS :: new ( NoParentLink , Some ( Def :: Mod ( root_def_id) ) , false , true ) ;
1193
- let graph_root = arenas. modules . alloc ( graph_root) ;
1210
+ let graph_root =
1211
+ ModuleS :: new ( NoParentLink , Some ( Def :: Mod ( root_def_id) ) , false , true , arenas) ;
1212
+ let graph_root = arenas. alloc_module ( graph_root) ;
1194
1213
1195
1214
Resolver {
1196
1215
session : session,
@@ -1250,11 +1269,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1250
1269
def : Option < Def > ,
1251
1270
external : bool ,
1252
1271
is_public : bool ) -> Module < ' a > {
1253
- self . arenas . modules . alloc ( ModuleS :: new ( parent_link, def, external, is_public) )
1254
- }
1255
-
1256
- fn new_name_binding ( & self , name_binding : NameBinding < ' a > ) -> & ' a NameBinding < ' a > {
1257
- self . arenas . name_bindings . alloc ( name_binding)
1272
+ self . arenas . alloc_module ( ModuleS :: new ( parent_link, def, external, is_public, self . arenas ) )
1258
1273
}
1259
1274
1260
1275
fn new_extern_crate_module ( & self ,
@@ -1263,7 +1278,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1263
1278
is_public : bool ,
1264
1279
local_node_id : NodeId )
1265
1280
-> Module < ' a > {
1266
- let mut module = ModuleS :: new ( parent_link, Some ( def) , false , is_public) ;
1281
+ let mut module = ModuleS :: new ( parent_link, Some ( def) , false , is_public, self . arenas ) ;
1267
1282
module. extern_crate_id = Some ( local_node_id) ;
1268
1283
self . arenas . modules . alloc ( module)
1269
1284
}
0 commit comments