@@ -418,7 +418,7 @@ struct Module {
418
418
kind : Cell < ModuleKind > ,
419
419
is_public : bool ,
420
420
421
- children : @ mut HashMap < Name , @NameBindings > ,
421
+ children : RefCell < HashMap < Name , @NameBindings > > ,
422
422
imports : @mut ~[ @ImportDirective ] ,
423
423
424
424
// The external module children of this node that were declared with
@@ -468,7 +468,7 @@ impl Module {
468
468
def_id : Cell :: new ( def_id) ,
469
469
kind : Cell :: new ( kind) ,
470
470
is_public : is_public,
471
- children : @ mut HashMap :: new ( ) ,
471
+ children : RefCell :: new ( HashMap :: new ( ) ) ,
472
472
imports : @mut ~[ ] ,
473
473
external_module_children : RefCell :: new ( HashMap :: new ( ) ) ,
474
474
anonymous_children : RefCell :: new ( HashMap :: new ( ) ) ,
@@ -997,13 +997,18 @@ impl Resolver {
997
997
998
998
// Add or reuse the child.
999
999
let new_parent = ModuleReducedGraphParent ( module_) ;
1000
- match module_. children . find ( & name. name ) {
1000
+ let child_opt = {
1001
+ let children = module_. children . borrow ( ) ;
1002
+ children. get ( ) . find_copy ( & name. name )
1003
+ } ;
1004
+ match child_opt {
1001
1005
None => {
1002
1006
let child = @NameBindings ( ) ;
1003
- module_. children . insert ( name. name , child) ;
1007
+ let mut children = module_. children . borrow_mut ( ) ;
1008
+ children. get ( ) . insert ( name. name , child) ;
1004
1009
return ( child, new_parent) ;
1005
1010
}
1006
- Some ( & child) => {
1011
+ Some ( child) => {
1007
1012
// Enforce the duplicate checking mode:
1008
1013
//
1009
1014
// * If we're requesting duplicate module checking, check that
@@ -1239,11 +1244,15 @@ impl Resolver {
1239
1244
ty_path( ref path, _, _) if path. segments . len ( ) == 1 => {
1240
1245
let name = path_to_ident ( path) ;
1241
1246
1242
- let new_parent = match parent. children . find ( & name. name ) {
1247
+ let existing_parent_opt = {
1248
+ let children = parent. children . borrow ( ) ;
1249
+ children. get ( ) . find_copy ( & name. name )
1250
+ } ;
1251
+ let new_parent = match existing_parent_opt {
1243
1252
// It already exists
1244
- Some ( & child) if child. get_module_if_available ( )
1245
- . is_some ( ) &&
1246
- child. get_module ( ) . kind . get ( ) ==
1253
+ Some ( child) if child. get_module_if_available ( )
1254
+ . is_some ( ) &&
1255
+ child. get_module ( ) . kind . get ( ) ==
1247
1256
ImplModuleKind => {
1248
1257
ModuleReducedGraphParent ( child. get_module ( ) )
1249
1258
}
@@ -2027,13 +2036,16 @@ impl Resolver {
2027
2036
self . resolve_imports_for_module ( module_) ;
2028
2037
2029
2038
self . populate_module_if_necessary ( module_) ;
2030
- for ( _, & child_node) in module_. children . iter ( ) {
2031
- match child_node. get_module_if_available ( ) {
2032
- None => {
2033
- // Nothing to do.
2034
- }
2035
- Some ( child_module) => {
2036
- self . resolve_imports_for_module_subtree ( child_module) ;
2039
+ {
2040
+ let children = module_. children . borrow ( ) ;
2041
+ for ( _, & child_node) in children. get ( ) . iter ( ) {
2042
+ match child_node. get_module_if_available ( ) {
2043
+ None => {
2044
+ // Nothing to do.
2045
+ }
2046
+ Some ( child_module) => {
2047
+ self . resolve_imports_for_module_subtree ( child_module) ;
2048
+ }
2037
2049
}
2038
2050
}
2039
2051
}
@@ -2258,18 +2270,22 @@ impl Resolver {
2258
2270
2259
2271
// Search for direct children of the containing module.
2260
2272
self . populate_module_if_necessary ( containing_module) ;
2261
- match containing_module. children . find ( & source. name ) {
2262
- None => {
2263
- // Continue.
2264
- }
2265
- Some ( child_name_bindings) => {
2266
- if child_name_bindings. defined_in_namespace ( ValueNS ) {
2267
- value_result = BoundResult ( containing_module,
2268
- * child_name_bindings) ;
2273
+
2274
+ {
2275
+ let children = containing_module. children . borrow ( ) ;
2276
+ match children. get ( ) . find ( & source. name ) {
2277
+ None => {
2278
+ // Continue.
2269
2279
}
2270
- if child_name_bindings. defined_in_namespace ( TypeNS ) {
2271
- type_result = BoundResult ( containing_module,
2272
- * child_name_bindings) ;
2280
+ Some ( child_name_bindings) => {
2281
+ if child_name_bindings. defined_in_namespace ( ValueNS ) {
2282
+ value_result = BoundResult ( containing_module,
2283
+ * child_name_bindings) ;
2284
+ }
2285
+ if child_name_bindings. defined_in_namespace ( TypeNS ) {
2286
+ type_result = BoundResult ( containing_module,
2287
+ * child_name_bindings) ;
2288
+ }
2273
2289
}
2274
2290
}
2275
2291
}
@@ -2590,8 +2606,12 @@ impl Resolver {
2590
2606
2591
2607
// Add all children from the containing module.
2592
2608
self . populate_module_if_necessary ( containing_module) ;
2593
- for ( & name, name_bindings) in containing_module. children . iter ( ) {
2594
- merge_import_resolution ( name, * name_bindings) ;
2609
+
2610
+ {
2611
+ let children = containing_module. children . borrow ( ) ;
2612
+ for ( & name, name_bindings) in children. get ( ) . iter ( ) {
2613
+ merge_import_resolution ( name, * name_bindings) ;
2614
+ }
2595
2615
}
2596
2616
2597
2617
// Add external module children from the containing module.
@@ -2858,13 +2878,18 @@ impl Resolver {
2858
2878
// The current module node is handled specially. First, check for
2859
2879
// its immediate children.
2860
2880
self . populate_module_if_necessary ( module_) ;
2861
- match module_. children . find ( & name. name ) {
2862
- Some ( name_bindings)
2863
- if name_bindings. defined_in_namespace ( namespace) => {
2864
- debug ! ( "top name bindings succeeded" ) ;
2865
- return Success ( ( Target :: new ( module_, * name_bindings) , false ) ) ;
2881
+
2882
+ {
2883
+ let children = module_. children . borrow ( ) ;
2884
+ match children. get ( ) . find ( & name. name ) {
2885
+ Some ( name_bindings)
2886
+ if name_bindings. defined_in_namespace ( namespace) => {
2887
+ debug ! ( "top name bindings succeeded" ) ;
2888
+ return Success ( ( Target :: new ( module_, * name_bindings) ,
2889
+ false ) ) ;
2890
+ }
2891
+ Some ( _) | None => { /* Not found; continue. */ }
2866
2892
}
2867
- Some ( _) | None => { /* Not found; continue. */ }
2868
2893
}
2869
2894
2870
2895
// Now check for its import directives. We don't have to have resolved
@@ -3125,14 +3150,19 @@ impl Resolver {
3125
3150
3126
3151
// First, check the direct children of the module.
3127
3152
self . populate_module_if_necessary ( module_) ;
3128
- match module_. children . find ( & name. name ) {
3129
- Some ( name_bindings)
3130
- if name_bindings. defined_in_namespace ( namespace) => {
3131
- debug ! ( "(resolving name in module) found node as child" ) ;
3132
- return Success ( ( Target :: new ( module_, * name_bindings) , false ) ) ;
3133
- }
3134
- Some ( _) | None => {
3135
- // Continue.
3153
+
3154
+ {
3155
+ let children = module_. children . borrow ( ) ;
3156
+ match children. get ( ) . find ( & name. name ) {
3157
+ Some ( name_bindings)
3158
+ if name_bindings. defined_in_namespace ( namespace) => {
3159
+ debug ! ( "(resolving name in module) found node as child" ) ;
3160
+ return Success ( ( Target :: new ( module_, * name_bindings) ,
3161
+ false ) ) ;
3162
+ }
3163
+ Some ( _) | None => {
3164
+ // Continue.
3165
+ }
3136
3166
}
3137
3167
}
3138
3168
@@ -3211,13 +3241,17 @@ impl Resolver {
3211
3241
3212
3242
// Descend into children and anonymous children.
3213
3243
self . populate_module_if_necessary ( module_) ;
3214
- for ( _, & child_node) in module_. children . iter ( ) {
3215
- match child_node. get_module_if_available ( ) {
3216
- None => {
3217
- // Continue.
3218
- }
3219
- Some ( child_module) => {
3220
- self . report_unresolved_imports ( child_module) ;
3244
+
3245
+ {
3246
+ let children = module_. children . borrow ( ) ;
3247
+ for ( _, & child_node) in children. get ( ) . iter ( ) {
3248
+ match child_node. get_module_if_available ( ) {
3249
+ None => {
3250
+ // Continue.
3251
+ }
3252
+ Some ( child_module) => {
3253
+ self . report_unresolved_imports ( child_module) ;
3254
+ }
3221
3255
}
3222
3256
}
3223
3257
}
@@ -3272,13 +3306,16 @@ impl Resolver {
3272
3306
self . record_exports_for_module ( module_) ;
3273
3307
self . populate_module_if_necessary ( module_) ;
3274
3308
3275
- for ( _, & child_name_bindings) in module_. children . iter ( ) {
3276
- match child_name_bindings. get_module_if_available ( ) {
3277
- None => {
3278
- // Nothing to do.
3279
- }
3280
- Some ( child_module) => {
3281
- self . record_exports_for_module_subtree ( child_module) ;
3309
+ {
3310
+ let children = module_. children . borrow ( ) ;
3311
+ for ( _, & child_name_bindings) in children. get ( ) . iter ( ) {
3312
+ match child_name_bindings. get_module_if_available ( ) {
3313
+ None => {
3314
+ // Nothing to do.
3315
+ }
3316
+ Some ( child_module) => {
3317
+ self . record_exports_for_module_subtree ( child_module) ;
3318
+ }
3282
3319
}
3283
3320
}
3284
3321
}
@@ -3382,7 +3419,9 @@ impl Resolver {
3382
3419
}
3383
3420
Some(name) => {
3384
3421
self.populate_module_if_necessary(orig_module);
3385
- match orig_module.children.find(&name.name) {
3422
+
3423
+ let children = orig_module.children.borrow();
3424
+ match children.get().find(&name.name) {
3386
3425
None => {
3387
3426
debug!(" !!! ( with scope) didn' t find `{ } ` in `{ } `",
3388
3427
self . session. str_of( name) ,
@@ -4675,22 +4714,26 @@ impl Resolver {
4675
4714
-> NameDefinition {
4676
4715
// First, search children.
4677
4716
self . populate_module_if_necessary ( containing_module) ;
4678
- match containing_module. children . find ( & name. name ) {
4679
- Some ( child_name_bindings) => {
4680
- match child_name_bindings. def_for_namespace ( namespace) {
4681
- Some ( def) => {
4682
- // Found it. Stop the search here.
4683
- let p = child_name_bindings. defined_in_public_namespace (
4684
- namespace) ;
4685
- let lp = if p { AllPublic } else {
4686
- DependsOn ( def_id_of_def ( def) )
4687
- } ;
4688
- return ChildNameDefinition ( def, lp) ;
4717
+
4718
+ {
4719
+ let children = containing_module. children . borrow ( ) ;
4720
+ match children. get ( ) . find ( & name. name ) {
4721
+ Some ( child_name_bindings) => {
4722
+ match child_name_bindings. def_for_namespace ( namespace) {
4723
+ Some ( def) => {
4724
+ // Found it. Stop the search here.
4725
+ let p = child_name_bindings. defined_in_public_namespace (
4726
+ namespace) ;
4727
+ let lp = if p { AllPublic } else {
4728
+ DependsOn ( def_id_of_def ( def) )
4729
+ } ;
4730
+ return ChildNameDefinition ( def, lp) ;
4731
+ }
4732
+ None => { }
4689
4733
}
4690
- None => { }
4691
4734
}
4735
+ None => { }
4692
4736
}
4693
- None => { }
4694
4737
}
4695
4738
4696
4739
// Next, search import resolutions.
@@ -5299,8 +5342,9 @@ impl Resolver {
5299
5342
5300
5343
// Look for trait children.
5301
5344
self . populate_module_if_necessary ( search_module) ;
5302
- for ( _, & child_name_bindings) in
5303
- search_module. children . iter ( ) {
5345
+
5346
+ let children = search_module. children . borrow ( ) ;
5347
+ for ( _, & child_name_bindings) in children. get ( ) . iter ( ) {
5304
5348
match child_name_bindings. def_for_namespace ( TypeNS ) {
5305
5349
Some ( def) => {
5306
5350
match def {
@@ -5514,7 +5558,8 @@ impl Resolver {
5514
5558
5515
5559
debug ! ( "Children:" ) ;
5516
5560
self . populate_module_if_necessary ( module_) ;
5517
- for ( & name, _) in module_. children . iter ( ) {
5561
+ let children = module_. children . borrow ( ) ;
5562
+ for ( & name, _) in children. get ( ) . iter ( ) {
5518
5563
debug ! ( "* {}" , interner_get( name) ) ;
5519
5564
}
5520
5565
0 commit comments