Skip to content

Commit 096df4e

Browse files
author
Jonathan S
committed
Purged ReducedGraphParent
1 parent 28659cf commit 096df4e

File tree

2 files changed

+41
-85
lines changed

2 files changed

+41
-85
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use Namespace::{TypeNS, ValueNS};
2323
use NameBindings;
2424
use ParentLink::{mod, ModuleParentLink, BlockParentLink};
2525
use Resolver;
26-
use ReducedGraphParent::{mod, ModuleReducedGraphParent};
2726
use RibKind::*;
2827
use Shadowable;
2928
use TypeNsDef;
@@ -111,7 +110,7 @@ impl<'a, 'b:'a, 'tcx:'b> DerefMut<Resolver<'b, 'tcx>> for GraphBuilder<'a, 'b, '
111110
impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
112111
/// Constructs the reduced graph for the entire crate.
113112
fn build_reduced_graph(self, krate: &ast::Crate) {
114-
let parent = ModuleReducedGraphParent(self.graph_root.get_module());
113+
let parent = self.graph_root.get_module();
115114
let mut visitor = BuildReducedGraphVisitor {
116115
builder: self,
117116
parent: parent
@@ -131,7 +130,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
131130
/// a block.
132131
fn add_child(&self,
133132
name: Name,
134-
reduced_graph_parent: ReducedGraphParent,
133+
parent: Rc<Module>,
135134
duplicate_checking_mode: DuplicateCheckingMode,
136135
// For printing errors
137136
sp: Span)
@@ -140,18 +139,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
140139
// child name directly. Otherwise, we create or reuse an anonymous
141140
// module and add the child to that.
142141

143-
let module_ = reduced_graph_parent.module();
144-
145-
self.check_for_conflicts_between_external_crates_and_items(&*module_,
142+
self.check_for_conflicts_between_external_crates_and_items(&*parent,
146143
name,
147144
sp);
148145

149146
// Add or reuse the child.
150-
let child = module_.children.borrow().get(&name).cloned();
147+
let child = parent.children.borrow().get(&name).cloned();
151148
match child {
152149
None => {
153150
let child = Rc::new(NameBindings::new());
154-
module_.children.borrow_mut().insert(name, child.clone());
151+
parent.children.borrow_mut().insert(name, child.clone());
155152
child
156153
}
157154
Some(child) => {
@@ -268,20 +265,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
268265
return false;
269266
}
270267

271-
fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Name)
268+
fn get_parent_link(&mut self, parent: Rc<Module>, name: Name)
272269
-> ParentLink {
273-
match parent {
274-
ModuleReducedGraphParent(module_) => {
275-
return ModuleParentLink(module_.downgrade(), name);
276-
}
277-
}
270+
ModuleParentLink(parent.downgrade(), name)
278271
}
279272

280273
/// Constructs the reduced graph for one item.
281274
fn build_reduced_graph_for_item(&mut self,
282275
item: &Item,
283-
parent: ReducedGraphParent)
284-
-> ReducedGraphParent
276+
parent: Rc<Module>)
277+
-> Rc<Module>
285278
{
286279
let name = item.ident.name;
287280
let sp = item.span;
@@ -302,7 +295,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
302295
item.vis == ast::Public,
303296
sp);
304297

305-
ModuleReducedGraphParent(name_bindings.get_module())
298+
name_bindings.get_module()
306299
}
307300

308301
ItemForeignMod(..) => parent,
@@ -370,7 +363,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
370363
self.build_reduced_graph_for_variant(
371364
&**variant,
372365
local_def(item.id),
373-
ModuleReducedGraphParent(name_bindings.get_module()));
366+
name_bindings.get_module());
374367
}
375368
parent
376369
}
@@ -446,22 +439,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
446439
}
447440
Some(mod_name) => {
448441
// Create the module and add all methods.
449-
let parent_opt = parent.module().children.borrow()
450-
.get(&mod_name).cloned();
442+
let parent_opt = parent.children.borrow().get(&mod_name).cloned();
451443
let new_parent = match parent_opt {
452444
// It already exists
453445
Some(ref child) if child.get_module_if_available()
454446
.is_some() &&
455447
(child.get_module().kind.get() == ImplModuleKind ||
456448
child.get_module().kind.get() == TraitModuleKind) => {
457-
ModuleReducedGraphParent(child.get_module())
449+
child.get_module()
458450
}
459451
Some(ref child) if child.get_module_if_available()
460452
.is_some() &&
461453
child.get_module().kind.get() ==
462-
EnumModuleKind => {
463-
ModuleReducedGraphParent(child.get_module())
464-
}
454+
EnumModuleKind => child.get_module(),
465455
// Create the module
466456
_ => {
467457
let name_bindings =
@@ -485,8 +475,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
485475
is_public,
486476
sp);
487477

488-
ModuleReducedGraphParent(
489-
name_bindings.get_module())
478+
name_bindings.get_module()
490479
}
491480
};
492481

@@ -576,8 +565,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
576565
false,
577566
item.vis == ast::Public,
578567
sp);
579-
let module_parent = ModuleReducedGraphParent(name_bindings.
580-
get_module());
568+
let module_parent = name_bindings.get_module();
581569

582570
let def_id = local_def(item.id);
583571

@@ -654,7 +642,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
654642
fn build_reduced_graph_for_variant(&mut self,
655643
variant: &Variant,
656644
item_id: DefId,
657-
parent: ReducedGraphParent) {
645+
parent: Rc<Module>) {
658646
let name = variant.node.name.name;
659647
let is_exported = match variant.node.kind {
660648
TupleVariantKind(_) => false,
@@ -680,8 +668,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
680668

681669
/// Constructs the reduced graph for one 'view item'. View items consist
682670
/// of imports and use directives.
683-
fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
684-
parent: ReducedGraphParent) {
671+
fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, parent: Rc<Module>) {
685672
match view_item.node {
686673
ViewItemUse(ref view_path) => {
687674
// Extract and intern the module part of the path. For
@@ -703,7 +690,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
703690
};
704691

705692
// Build up the import directives.
706-
let module_ = parent.module();
707693
let is_public = view_item.vis == ast::Public;
708694
let shadowable =
709695
view_item.attrs
@@ -729,7 +715,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
729715

730716
let subclass = SingleImport(binding.name,
731717
source_name);
732-
self.build_import_directive(&*module_,
718+
self.build_import_directive(&*parent,
733719
module_path,
734720
subclass,
735721
view_path.span,
@@ -771,7 +757,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
771757
}
772758
};
773759
self.build_import_directive(
774-
&*module_,
760+
&*parent,
775761
module_path,
776762
SingleImport(name, name),
777763
source_item.span,
@@ -781,7 +767,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
781767
}
782768
}
783769
ViewPathGlob(_, id) => {
784-
self.build_import_directive(&*module_,
770+
self.build_import_directive(&*parent,
785771
module_path,
786772
GlobImport,
787773
view_path.span,
@@ -798,8 +784,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
798784
.find_extern_mod_stmt_cnum(node_id).iter() {
799785
let def_id = DefId { krate: crate_id, node: 0 };
800786
self.external_exports.insert(def_id);
801-
let parent_link =
802-
ModuleParentLink(parent.module().downgrade(), name.name);
787+
let parent_link = ModuleParentLink(parent.downgrade(), name.name);
803788
let external_module = Rc::new(Module::new(parent_link,
804789
Some(def_id),
805790
NormalModuleKind,
@@ -808,11 +793,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
808793
debug!("(build reduced graph for item) found extern `{}`",
809794
self.module_to_string(&*external_module));
810795
self.check_for_conflicts_between_external_crates(
811-
&*parent.module(),
796+
&*parent,
812797
name.name,
813798
view_item.span);
814-
parent.module().external_module_children.borrow_mut()
815-
.insert(name.name, external_module.clone());
799+
parent.external_module_children.borrow_mut()
800+
.insert(name.name, external_module.clone());
816801
self.build_reduced_graph_for_external_crate(external_module);
817802
}
818803
}
@@ -822,7 +807,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
822807
/// Constructs the reduced graph for one foreign item.
823808
fn build_reduced_graph_for_foreign_item<F>(&mut self,
824809
foreign_item: &ForeignItem,
825-
parent: ReducedGraphParent,
810+
parent: Rc<Module>,
826811
f: F) where
827812
F: FnOnce(&mut Resolver),
828813
{
@@ -854,28 +839,22 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
854839
}
855840
}
856841

857-
fn build_reduced_graph_for_block(&mut self,
858-
block: &Block,
859-
parent: ReducedGraphParent)
860-
-> ReducedGraphParent
861-
{
842+
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: Rc<Module>) -> Rc<Module> {
862843
if self.block_needs_anonymous_module(block) {
863844
let block_id = block.id;
864845

865846
debug!("(building reduced graph for block) creating a new \
866847
anonymous module for block {}",
867848
block_id);
868849

869-
let parent_module = parent.module();
870850
let new_module = Rc::new(Module::new(
871-
BlockParentLink(parent_module.downgrade(), block_id),
851+
BlockParentLink(parent.downgrade(), block_id),
872852
None,
873853
AnonymousModuleKind,
874854
false,
875855
false));
876-
parent_module.anonymous_children.borrow_mut()
877-
.insert(block_id, new_module.clone());
878-
ModuleReducedGraphParent(new_module)
856+
parent.anonymous_children.borrow_mut().insert(block_id, new_module.clone());
857+
new_module
879858
} else {
880859
parent
881860
}
@@ -887,19 +866,15 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
887866
child_name_bindings: &NameBindings,
888867
final_ident: &str,
889868
name: Name,
890-
new_parent: ReducedGraphParent) {
869+
new_parent: Rc<Module>) {
891870
debug!("(building reduced graph for \
892871
external crate) building external def, priv {}",
893872
vis);
894873
let is_public = vis == ast::Public;
895874
let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
896-
let is_exported = is_public && match new_parent {
897-
ModuleReducedGraphParent(ref module) => {
898-
match module.def_id.get() {
899-
None => true,
900-
Some(did) => self.external_exports.contains(&did)
901-
}
902-
}
875+
let is_exported = is_public && match new_parent.def_id.get() {
876+
None => true,
877+
Some(did) => self.external_exports.contains(&did)
903878
};
904879
if is_exported {
905880
self.external_exports.insert(def.def_id());
@@ -969,7 +944,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
969944
Some(ref def) => (modifiers & !IMPORTABLE) | (def.modifiers & IMPORTABLE),
970945
None => modifiers
971946
};
972-
if new_parent.module().kind.get() != NormalModuleKind {
947+
if new_parent.kind.get() != NormalModuleKind {
973948
modifiers = modifiers & !IMPORTABLE;
974949
}
975950
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
@@ -1070,7 +1045,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
10701045
_ => {
10711046
let child_name_bindings =
10721047
self.add_child(name,
1073-
ModuleReducedGraphParent(root.clone()),
1048+
root.clone(),
10741049
OverwriteDuplicates,
10751050
DUMMY_SP);
10761051

@@ -1079,7 +1054,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
10791054
&*child_name_bindings,
10801055
token::get_name(name).get(),
10811056
name,
1082-
ModuleReducedGraphParent(root));
1057+
root);
10831058
}
10841059
}
10851060
}
@@ -1100,7 +1075,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
11001075
let child_name_bindings =
11011076
self.add_child(
11021077
final_name,
1103-
ModuleReducedGraphParent(root.clone()),
1078+
root.clone(),
11041079
OverwriteDuplicates,
11051080
DUMMY_SP);
11061081

@@ -1123,8 +1098,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
11231098
}
11241099
Some(_) | None => {
11251100
let parent_link =
1126-
self.get_parent_link(ModuleReducedGraphParent(root),
1127-
final_name);
1101+
self.get_parent_link(root, final_name);
11281102
child_name_bindings.define_module(
11291103
parent_link,
11301104
Some(def),
@@ -1139,8 +1113,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
11391113
}
11401114

11411115
// Add each static method to the module.
1142-
let new_parent =
1143-
ModuleReducedGraphParent(type_module);
1116+
let new_parent = type_module;
11441117
for method_info in methods.iter() {
11451118
let name = method_info.name;
11461119
debug!("(building reduced graph for \
@@ -1290,7 +1263,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
12901263

12911264
struct BuildReducedGraphVisitor<'a, 'b:'a, 'tcx:'b> {
12921265
builder: GraphBuilder<'a, 'b, 'tcx>,
1293-
parent: ReducedGraphParent
1266+
parent: Rc<Module>
12941267
}
12951268

12961269
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {

src/librustc_resolve/lib.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use self::Namespace::*;
2929
use self::NamespaceResult::*;
3030
use self::NameDefinition::*;
3131
use self::ImportDirectiveSubclass::*;
32-
use self::ReducedGraphParent::*;
3332
use self::ResolveResult::*;
3433
use self::FallbackSuggestion::*;
3534
use self::TypeParameters::*;
@@ -185,22 +184,6 @@ enum ImportDirectiveSubclass {
185184
GlobImport
186185
}
187186

188-
/// The context that we thread through while building the reduced graph.
189-
#[deriving(Clone)]
190-
enum ReducedGraphParent {
191-
ModuleReducedGraphParent(Rc<Module>)
192-
}
193-
194-
impl ReducedGraphParent {
195-
fn module(&self) -> Rc<Module> {
196-
match *self {
197-
ModuleReducedGraphParent(ref m) => {
198-
m.clone()
199-
}
200-
}
201-
}
202-
}
203-
204187
type ErrorMessage = Option<(Span, String)>;
205188

206189
enum ResolveResult<T> {

0 commit comments

Comments
 (0)