Skip to content

Commit 4c31f34

Browse files
committed
---
yaml --- r: 89017 b: refs/heads/snap-stage3 c: 19ca9e1 h: refs/heads/master i: 89015: 1271b35 v: v3
1 parent bcbc5c8 commit 4c31f34

File tree

2 files changed

+120
-75
lines changed

2 files changed

+120
-75
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: deeca5d586bfaa4aa60246f671a8d611d38f6248
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f857398bc960e683efd0923181c4a7fbd5497cf8
4+
refs/heads/snap-stage3: 19ca9e188474058c066212e103d4addb9630fbbf
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/resolve.rs

Lines changed: 119 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ struct Module {
418418
kind: Cell<ModuleKind>,
419419
is_public: bool,
420420

421-
children: @mut HashMap<Name, @NameBindings>,
421+
children: RefCell<HashMap<Name, @NameBindings>>,
422422
imports: @mut ~[@ImportDirective],
423423

424424
// The external module children of this node that were declared with
@@ -468,7 +468,7 @@ impl Module {
468468
def_id: Cell::new(def_id),
469469
kind: Cell::new(kind),
470470
is_public: is_public,
471-
children: @mut HashMap::new(),
471+
children: RefCell::new(HashMap::new()),
472472
imports: @mut ~[],
473473
external_module_children: RefCell::new(HashMap::new()),
474474
anonymous_children: RefCell::new(HashMap::new()),
@@ -997,13 +997,18 @@ impl Resolver {
997997

998998
// Add or reuse the child.
999999
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 {
10011005
None => {
10021006
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);
10041009
return (child, new_parent);
10051010
}
1006-
Some(&child) => {
1011+
Some(child) => {
10071012
// Enforce the duplicate checking mode:
10081013
//
10091014
// * If we're requesting duplicate module checking, check that
@@ -1239,11 +1244,15 @@ impl Resolver {
12391244
ty_path(ref path, _, _) if path.segments.len() == 1 => {
12401245
let name = path_to_ident(path);
12411246

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 {
12431252
// 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() ==
12471256
ImplModuleKind => {
12481257
ModuleReducedGraphParent(child.get_module())
12491258
}
@@ -2027,13 +2036,16 @@ impl Resolver {
20272036
self.resolve_imports_for_module(module_);
20282037

20292038
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+
}
20372049
}
20382050
}
20392051
}
@@ -2258,18 +2270,22 @@ impl Resolver {
22582270

22592271
// Search for direct children of the containing module.
22602272
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.
22692279
}
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+
}
22732289
}
22742290
}
22752291
}
@@ -2590,8 +2606,12 @@ impl Resolver {
25902606

25912607
// Add all children from the containing module.
25922608
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+
}
25952615
}
25962616

25972617
// Add external module children from the containing module.
@@ -2858,13 +2878,18 @@ impl Resolver {
28582878
// The current module node is handled specially. First, check for
28592879
// its immediate children.
28602880
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. */ }
28662892
}
2867-
Some(_) | None => { /* Not found; continue. */ }
28682893
}
28692894

28702895
// Now check for its import directives. We don't have to have resolved
@@ -3125,14 +3150,19 @@ impl Resolver {
31253150

31263151
// First, check the direct children of the module.
31273152
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+
}
31363166
}
31373167
}
31383168

@@ -3211,13 +3241,17 @@ impl Resolver {
32113241

32123242
// Descend into children and anonymous children.
32133243
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+
}
32213255
}
32223256
}
32233257
}
@@ -3272,13 +3306,16 @@ impl Resolver {
32723306
self.record_exports_for_module(module_);
32733307
self.populate_module_if_necessary(module_);
32743308

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+
}
32823319
}
32833320
}
32843321
}
@@ -3382,7 +3419,9 @@ impl Resolver {
33823419
}
33833420
Some(name) => {
33843421
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) {
33863425
None => {
33873426
debug!("!!! (with scope) didn't find `{}` in `{}`",
33883427
self.session.str_of(name),
@@ -4675,22 +4714,26 @@ impl Resolver {
46754714
-> NameDefinition {
46764715
// First, search children.
46774716
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 => {}
46894733
}
4690-
None => {}
46914734
}
4735+
None => {}
46924736
}
4693-
None => {}
46944737
}
46954738

46964739
// Next, search import resolutions.
@@ -5299,8 +5342,9 @@ impl Resolver {
52995342

53005343
// Look for trait children.
53015344
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() {
53045348
match child_name_bindings.def_for_namespace(TypeNS) {
53055349
Some(def) => {
53065350
match def {
@@ -5514,7 +5558,8 @@ impl Resolver {
55145558

55155559
debug!("Children:");
55165560
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() {
55185563
debug!("* {}", interner_get(name));
55195564
}
55205565

0 commit comments

Comments
 (0)