Skip to content

Commit b5b403a

Browse files
committed
librustc: De-@mut Module::external_module_children
1 parent ea63a18 commit b5b403a

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

src/librustc/middle/resolve.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ struct Module {
425425

426426
// The external module children of this node that were declared with
427427
// `extern mod`.
428-
external_module_children: @mut HashMap<Name, @Module>,
428+
external_module_children: RefCell<HashMap<Name, @Module>>,
429429

430430
// The anonymous children of this node. Anonymous children are pseudo-
431431
// modules that are implicitly created around items contained within
@@ -472,7 +472,7 @@ impl Module {
472472
is_public: is_public,
473473
children: @mut HashMap::new(),
474474
imports: @mut ~[],
475-
external_module_children: @mut HashMap::new(),
475+
external_module_children: RefCell::new(HashMap::new()),
476476
anonymous_children: @mut HashMap::new(),
477477
import_resolutions: @mut HashMap::new(),
478478
glob_count: Cell::new(0),
@@ -1506,9 +1506,13 @@ impl Resolver {
15061506
false,
15071507
true);
15081508

1509-
parent.external_module_children.insert(
1510-
name.name,
1511-
external_module);
1509+
{
1510+
let mut external_module_children =
1511+
parent.external_module_children.borrow_mut();
1512+
external_module_children.get().insert(
1513+
name.name,
1514+
external_module);
1515+
}
15121516

15131517
self.build_reduced_graph_for_external_crate(
15141518
external_module);
@@ -2352,13 +2356,18 @@ impl Resolver {
23522356
match type_result {
23532357
BoundResult(..) => {}
23542358
_ => {
2355-
match containing_module.external_module_children
2356-
.find(&source.name) {
2359+
let module_opt = {
2360+
let mut external_module_children =
2361+
containing_module.external_module_children
2362+
.borrow_mut();
2363+
external_module_children.get().find_copy(&source.name)
2364+
};
2365+
match module_opt {
23572366
None => {} // Continue.
23582367
Some(module) => {
23592368
let name_bindings =
23602369
@mut Resolver::create_name_bindings_from_module(
2361-
*module);
2370+
module);
23622371
type_result = BoundResult(containing_module,
23632372
name_bindings);
23642373
used_public = true;
@@ -2565,10 +2574,14 @@ impl Resolver {
25652574
}
25662575

25672576
// Add external module children from the containing module.
2568-
for (&name, module) in containing_module.external_module_children.iter() {
2569-
let name_bindings =
2570-
@mut Resolver::create_name_bindings_from_module(*module);
2571-
merge_import_resolution(name, name_bindings);
2577+
{
2578+
let external_module_children =
2579+
containing_module.external_module_children.borrow();
2580+
for (&name, module) in external_module_children.get().iter() {
2581+
let name_bindings =
2582+
@mut Resolver::create_name_bindings_from_module(*module);
2583+
merge_import_resolution(name, name_bindings);
2584+
}
25722585
}
25732586

25742587
// Record the destination of this import
@@ -2861,12 +2874,17 @@ impl Resolver {
28612874

28622875
// Search for external modules.
28632876
if namespace == TypeNS {
2864-
match module_.external_module_children.find(&name.name) {
2877+
let module_opt = {
2878+
let external_module_children =
2879+
module_.external_module_children.borrow();
2880+
external_module_children.get().find_copy(&name.name)
2881+
};
2882+
match module_opt {
28652883
None => {}
28662884
Some(module) => {
28672885
let name_bindings =
28682886
@mut Resolver::create_name_bindings_from_module(
2869-
*module);
2887+
module);
28702888
debug!("lower name bindings succeeded");
28712889
return Success((Target::new(module_, name_bindings), false));
28722890
}
@@ -3133,12 +3151,17 @@ impl Resolver {
31333151

31343152
// Finally, search through external children.
31353153
if namespace == TypeNS {
3136-
match module_.external_module_children.find(&name.name) {
3154+
let module_opt = {
3155+
let external_module_children =
3156+
module_.external_module_children.borrow();
3157+
external_module_children.get().find_copy(&name.name)
3158+
};
3159+
match module_opt {
31373160
None => {}
31383161
Some(module) => {
31393162
let name_bindings =
31403163
@mut Resolver::create_name_bindings_from_module(
3141-
*module);
3164+
module);
31423165
return Success((Target::new(module_, name_bindings), false));
31433166
}
31443167
}
@@ -4664,7 +4687,12 @@ impl Resolver {
46644687

46654688
// Finally, search through external children.
46664689
if namespace == TypeNS {
4667-
match containing_module.external_module_children.find(&name.name) {
4690+
let module_opt = {
4691+
let external_module_children =
4692+
containing_module.external_module_children.borrow();
4693+
external_module_children.get().find_copy(&name.name)
4694+
};
4695+
match module_opt {
46684696
None => {}
46694697
Some(module) => {
46704698
match module.def_id.get() {

0 commit comments

Comments
 (0)