1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Reduced graph building
13 //! Here we build the "reduced graph": the graph of the module tree without
14 //! any imports resolved.
17 use resolve_imports::ImportDirective;
18 use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
19 use resolve_imports::{ImportResolution, ImportResolutionPerNamespace};
21 use Namespace::{TypeNS, ValueNS};
23 use {names_to_string, module_to_string};
24 use ParentLink::{self, ModuleParentLink, BlockParentLink};
26 use resolve_imports::Shadowable;
27 use {resolve_error, ResolutionError};
29 use self::DuplicateCheckingMode::*;
31 use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
32 use rustc::middle::def::*;
33 use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
35 use syntax::ast::{Name, NodeId};
36 use syntax::attr::AttrMetaMethods;
37 use syntax::parse::token::special_idents;
38 use syntax::codemap::{Span, DUMMY_SP};
41 use rustc_front::hir::{Block, DeclItem};
42 use rustc_front::hir::{ForeignItem, ForeignItemFn, ForeignItemStatic};
43 use rustc_front::hir::{Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn};
44 use rustc_front::hir::{ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl};
45 use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
46 use rustc_front::hir::{NamedField, PathListIdent, PathListMod};
47 use rustc_front::hir::StmtDecl;
48 use rustc_front::hir::UnnamedField;
49 use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
50 use rustc_front::hir::Visibility;
51 use rustc_front::intravisit::{self, Visitor};
53 use std::mem::replace;
54 use std::ops::{Deref, DerefMut};
57 // Specifies how duplicates should be handled when adding a child item if
58 // another item exists with the same name in some namespace.
59 #[derive(Copy, Clone, PartialEq)]
60 enum DuplicateCheckingMode {
62 ForbidDuplicateValues,
63 ForbidDuplicateTypesAndValues,
67 struct GraphBuilder<'a, 'b: 'a, 'tcx: 'b> {
68 resolver: &'a mut Resolver<'b, 'tcx>,
71 impl<'a, 'b:'a, 'tcx:'b> Deref for GraphBuilder<'a, 'b, 'tcx> {
72 type Target = Resolver<'b, 'tcx>;
74 fn deref(&self) -> &Resolver<'b, 'tcx> {
79 impl<'a, 'b:'a, 'tcx:'b> DerefMut for GraphBuilder<'a, 'b, 'tcx> {
80 fn deref_mut(&mut self) -> &mut Resolver<'b, 'tcx> {
85 impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
86 /// Constructs the reduced graph for the entire crate.
87 fn build_reduced_graph(self, krate: &hir::Crate) {
88 let mut visitor = BuildReducedGraphVisitor {
89 parent: self.graph_root.clone(),
92 intravisit::walk_crate(&mut visitor, krate);
95 /// Adds a new child item to the module definition of the parent node,
96 /// or if there is already a child, does duplicate checking on the child.
97 /// Returns the child's corresponding name bindings.
101 duplicate_checking_mode: DuplicateCheckingMode,
102 // For printing errors
105 self.check_for_conflicts_between_external_crates_and_items(&**parent, name, sp);
107 // Add or reuse the child.
108 let child = parent.children.borrow().get(&name).cloned();
111 let child = NameBindings::new();
112 parent.children.borrow_mut().insert(name, child.clone());
116 // Enforce the duplicate checking mode:
118 // * If we're requesting duplicate type checking, check that
119 // the name isn't defined in the type namespace.
121 // * If we're requesting duplicate value checking, check that
122 // the name isn't defined in the value namespace.
124 // * If we're requesting duplicate type and value checking,
125 // check that the name isn't defined in either namespace.
127 // * If no duplicate checking was requested at all, do
130 let ns = match duplicate_checking_mode {
131 ForbidDuplicateTypes if child.type_ns.defined() => TypeNS,
132 ForbidDuplicateValues if child.value_ns.defined() => ValueNS,
133 ForbidDuplicateTypesAndValues if child.type_ns.defined() => TypeNS,
134 ForbidDuplicateTypesAndValues if child.value_ns.defined() => ValueNS,
138 // Record an error here by looking up the namespace that had the duplicate
139 let ns_str = match ns { TypeNS => "type or module", ValueNS => "value" };
140 resolve_error(self, sp, ResolutionError::DuplicateDefinition(ns_str, name));
142 if let Some(sp) = child[ns].span() {
143 let note = format!("first definition of {} `{}` here", ns_str, name);
144 self.session.span_note(sp, ¬e);
151 fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
152 // Check each statement.
153 for statement in &block.stmts {
154 match statement.node {
155 StmtDecl(ref declaration, _) => {
156 match declaration.node {
171 // If we found no items, we don't need to create
172 // an anonymous module.
177 fn get_parent_link(&mut self, parent: &Rc<Module>, name: Name) -> ParentLink {
178 ModuleParentLink(Rc::downgrade(parent), name)
181 /// Constructs the reduced graph for one item.
182 fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) -> Rc<Module> {
183 let name = item.name;
185 let is_public = item.vis == hir::Public;
186 let modifiers = if is_public {
189 DefModifiers::empty()
190 } | DefModifiers::IMPORTABLE;
193 ItemUse(ref view_path) => {
194 // Extract and intern the module part of the path. For
195 // globs and lists, the path is found directly in the AST;
196 // for simple paths we have to munge the path a little.
197 let module_path = match view_path.node {
198 ViewPathSimple(_, ref full_path) => {
204 .map(|seg| seg.identifier.name)
208 ViewPathGlob(ref module_ident_path) |
209 ViewPathList(ref module_ident_path, _) => {
210 module_ident_path.segments
212 .map(|seg| seg.identifier.name)
217 // Build up the import directives.
218 let shadowable = item.attrs.iter().any(|attr| {
219 attr.name() == special_idents::prelude_import.name.as_str()
221 let shadowable = if shadowable {
227 match view_path.node {
228 ViewPathSimple(binding, ref full_path) => {
229 let source_name = full_path.segments.last().unwrap().identifier.name;
230 if source_name.as_str() == "mod" || source_name.as_str() == "self" {
233 ResolutionError::SelfImportsOnlyAllowedWithin);
236 let subclass = SingleImport(binding, source_name);
237 self.build_import_directive(&**parent,
245 ViewPathList(_, ref source_items) => {
246 // Make sure there's at most one `mod` import in the list.
247 let mod_spans = source_items.iter()
250 PathListMod { .. } => Some(item.span),
254 .collect::<Vec<Span>>();
255 if mod_spans.len() > 1 {
258 ResolutionError::SelfImportCanOnlyAppearOnceInTheList);
259 for other_span in mod_spans.iter().skip(1) {
261 .span_note(*other_span, "another `self` import appears here");
265 for source_item in source_items {
266 let (module_path, name, rename) = match source_item.node {
267 PathListIdent { name, rename, .. } =>
268 (module_path.clone(), name, rename.unwrap_or(name)),
269 PathListMod { rename, .. } => {
270 let name = match module_path.last() {
277 SelfImportOnlyInImportListWithNonEmptyPrefix
282 let module_path = module_path.split_last().unwrap().1;
283 let rename = rename.unwrap_or(name);
284 (module_path.to_vec(), name, rename)
287 self.build_import_directive(&**parent,
289 SingleImport(rename, name),
291 source_item.node.id(),
297 self.build_import_directive(&**parent,
309 ItemExternCrate(_) => {
310 // n.b. we don't need to look at the path option here, because cstore already
312 if let Some(crate_id) = self.session.cstore.extern_mod_stmt_cnum(item.id) {
315 index: CRATE_DEF_INDEX,
317 self.external_exports.insert(def_id);
318 let parent_link = ModuleParentLink(Rc::downgrade(parent), name);
319 let def = DefMod(def_id);
320 let external_module = Module::new(parent_link, Some(def), false, true);
322 debug!("(build reduced graph for item) found extern `{}`",
323 module_to_string(&*external_module));
324 self.check_for_conflicts_between_external_crates(&**parent, name, sp);
325 parent.external_module_children
327 .insert(name, external_module.clone());
328 self.build_reduced_graph_for_external_crate(&external_module);
334 let name_bindings = self.add_child(name, parent, ForbidDuplicateTypes, sp);
336 let parent_link = self.get_parent_link(parent, name);
337 let def = DefMod(self.ast_map.local_def_id(item.id));
338 let module = Module::new(parent_link, Some(def), false, is_public);
339 name_bindings.define_module(module.clone(), sp);
343 ItemForeignMod(..) => parent.clone(),
345 // These items live in the value namespace.
346 ItemStatic(_, m, _) => {
347 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
348 let mutbl = m == hir::MutMutable;
350 name_bindings.define_value(DefStatic(self.ast_map.local_def_id(item.id), mutbl),
356 self.add_child(name, parent, ForbidDuplicateValues, sp)
357 .define_value(DefConst(self.ast_map.local_def_id(item.id)), sp, modifiers);
360 ItemFn(_, _, _, _, _, _) => {
361 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
363 let def = DefFn(self.ast_map.local_def_id(item.id), false);
364 name_bindings.define_value(def, sp, modifiers);
368 // These items live in the type namespace.
370 let name_bindings = self.add_child(name,
372 ForbidDuplicateTypes,
375 let parent_link = self.get_parent_link(parent, name);
376 let def = DefTy(self.ast_map.local_def_id(item.id), false);
377 let module = Module::new(parent_link, Some(def), false, is_public);
378 name_bindings.define_module(module, sp);
382 ItemEnum(ref enum_definition, _) => {
383 let name_bindings = self.add_child(name,
385 ForbidDuplicateTypes,
388 let parent_link = self.get_parent_link(parent, name);
389 let def = DefTy(self.ast_map.local_def_id(item.id), true);
390 let module = Module::new(parent_link, Some(def), false, is_public);
391 name_bindings.define_module(module.clone(), sp);
393 for variant in &(*enum_definition).variants {
394 let item_def_id = self.ast_map.local_def_id(item.id);
395 self.build_reduced_graph_for_variant(variant, item_def_id, &module);
400 // These items live in both the type and value namespaces.
401 ItemStruct(ref struct_def, _) => {
402 // Adding to both Type and Value namespaces or just Type?
403 let (forbid, ctor_id) = if struct_def.is_struct() {
404 (ForbidDuplicateTypes, None)
406 (ForbidDuplicateTypesAndValues, Some(struct_def.id()))
409 let name_bindings = self.add_child(name, parent, forbid, sp);
411 // Define a name in the type namespace.
412 name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false),
416 // If this is a newtype or unit-like struct, define a name
417 // in the value namespace as well
418 if let Some(cid) = ctor_id {
419 name_bindings.define_value(DefStruct(self.ast_map.local_def_id(cid)),
424 // Record the def ID and fields of this struct.
425 let named_fields = struct_def.fields()
429 NamedField(name, _) => Some(name),
430 UnnamedField(_) => None,
434 let item_def_id = self.ast_map.local_def_id(item.id);
435 self.structs.insert(item_def_id, named_fields);
440 ItemDefaultImpl(_, _) |
441 ItemImpl(..) => parent.clone(),
443 ItemTrait(_, _, _, ref items) => {
444 let name_bindings = self.add_child(name,
446 ForbidDuplicateTypes,
449 let def_id = self.ast_map.local_def_id(item.id);
451 // Add all the items within to a new module.
452 let parent_link = self.get_parent_link(parent, name);
453 let def = DefTrait(def_id);
454 let module_parent = Module::new(parent_link, Some(def), false, is_public);
455 name_bindings.define_module(module_parent.clone(), sp);
457 // Add the names of all the items to the trait info.
458 for trait_item in items {
459 let name_bindings = self.add_child(trait_item.name,
461 ForbidDuplicateTypesAndValues,
464 match trait_item.node {
465 hir::ConstTraitItem(..) => {
466 let def = DefAssociatedConst(self.ast_map.local_def_id(trait_item.id));
467 // NB: not DefModifiers::IMPORTABLE
468 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
470 hir::MethodTraitItem(..) => {
471 let def = DefMethod(self.ast_map.local_def_id(trait_item.id));
472 // NB: not DefModifiers::IMPORTABLE
473 name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
475 hir::TypeTraitItem(..) => {
476 let def = DefAssociatedTy(self.ast_map.local_def_id(item.id),
477 self.ast_map.local_def_id(trait_item.id));
478 // NB: not DefModifiers::IMPORTABLE
479 name_bindings.define_type(def, trait_item.span, DefModifiers::PUBLIC);
483 let trait_item_def_id = self.ast_map.local_def_id(trait_item.id);
484 self.trait_item_map.insert((trait_item.name, def_id), trait_item_def_id);
492 // Constructs the reduced graph for one variant. Variants exist in the
493 // type and value namespaces.
494 fn build_reduced_graph_for_variant(&mut self,
497 parent: &Rc<Module>) {
498 let name = variant.node.name;
499 let is_exported = if variant.node.data.is_struct() {
500 // Not adding fields for variants as they are not accessed with a self receiver
501 let variant_def_id = self.ast_map.local_def_id(variant.node.data.id());
502 self.structs.insert(variant_def_id, Vec::new());
508 let child = self.add_child(name, parent, ForbidDuplicateTypesAndValues, variant.span);
509 // variants are always treated as importable to allow them to be glob
511 child.define_value(DefVariant(item_id,
512 self.ast_map.local_def_id(variant.node.data.id()),
515 DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
516 child.define_type(DefVariant(item_id,
517 self.ast_map.local_def_id(variant.node.data.id()),
520 DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
523 /// Constructs the reduced graph for one foreign item.
524 fn build_reduced_graph_for_foreign_item(&mut self,
525 foreign_item: &ForeignItem,
526 parent: &Rc<Module>) {
527 let name = foreign_item.name;
528 let is_public = foreign_item.vis == hir::Public;
529 let modifiers = if is_public {
532 DefModifiers::empty()
533 } | DefModifiers::IMPORTABLE;
534 let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, foreign_item.span);
536 let def = match foreign_item.node {
537 ForeignItemFn(..) => {
538 DefFn(self.ast_map.local_def_id(foreign_item.id), false)
540 ForeignItemStatic(_, m) => {
541 DefStatic(self.ast_map.local_def_id(foreign_item.id), m)
544 name_bindings.define_value(def, foreign_item.span, modifiers);
547 fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &Rc<Module>) -> Rc<Module> {
548 if self.block_needs_anonymous_module(block) {
549 let block_id = block.id;
551 debug!("(building reduced graph for block) creating a new anonymous module for block \
555 let parent_link = BlockParentLink(Rc::downgrade(parent), block_id);
556 let new_module = Module::new(parent_link, None, false, false);
557 parent.anonymous_children.borrow_mut().insert(block_id, new_module.clone());
564 fn handle_external_def(&mut self,
567 child_name_bindings: &NameBindings,
570 new_parent: &Rc<Module>) {
571 debug!("(building reduced graph for external crate) building external def {}, priv {:?}",
574 let is_public = vis == hir::Public;
575 let modifiers = if is_public {
578 DefModifiers::empty()
579 } | DefModifiers::IMPORTABLE;
580 let is_exported = is_public &&
581 match new_parent.def_id() {
583 Some(did) => self.external_exports.contains(&did),
586 self.external_exports.insert(def.def_id());
594 if let Some(module_def) = child_name_bindings.type_ns.module() {
595 debug!("(building reduced graph for external crate) already created module");
596 module_def.def.set(Some(def));
598 debug!("(building reduced graph for external crate) building module {} {}",
601 let parent_link = self.get_parent_link(new_parent, name);
602 let module = Module::new(parent_link, Some(def), true, is_public);
603 child_name_bindings.define_module(module, DUMMY_SP);
610 DefMod(_) | DefForeignMod(_) => {}
611 DefVariant(_, variant_id, is_struct) => {
612 debug!("(building reduced graph for external crate) building variant {}",
614 // variants are always treated as importable to allow them to be
616 let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
618 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
619 // Not adding fields for variants as they are not accessed with a self receiver
620 self.structs.insert(variant_id, Vec::new());
622 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
625 DefFn(ctor_id, true) => {
626 child_name_bindings.define_value(
627 self.session.cstore.tuple_struct_definition_if_ctor(ctor_id)
628 .map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, modifiers);
633 DefAssociatedConst(..) |
635 debug!("(building reduced graph for external crate) building value (fn/static) {}",
637 // impl methods have already been defined with the correct importability
639 let mut modifiers = match *child_name_bindings.value_ns.borrow() {
640 Some(ref def) => (modifiers & !DefModifiers::IMPORTABLE) |
641 (def.modifiers & DefModifiers::IMPORTABLE),
644 if !new_parent.is_normal() {
645 modifiers = modifiers & !DefModifiers::IMPORTABLE;
647 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
649 DefTrait(def_id) => {
650 debug!("(building reduced graph for external crate) building type {}",
653 // If this is a trait, add all the trait item names to the trait
656 let trait_item_def_ids = self.session.cstore.trait_item_def_ids(def_id);
657 for trait_item_def in &trait_item_def_ids {
658 let trait_item_name =
659 self.session.cstore.item_name(trait_item_def.def_id());
661 debug!("(building reduced graph for external crate) ... adding trait item \
665 self.trait_item_map.insert((trait_item_name, def_id), trait_item_def.def_id());
668 self.external_exports.insert(trait_item_def.def_id());
672 // Define a module if necessary.
673 let parent_link = self.get_parent_link(new_parent, name);
674 let module = Module::new(parent_link, Some(def), true, is_public);
675 child_name_bindings.define_module(module, DUMMY_SP);
677 DefTy(..) | DefAssociatedTy(..) => {
678 debug!("(building reduced graph for external crate) building type {}",
681 let modifiers = match new_parent.is_normal() {
683 _ => modifiers & !DefModifiers::IMPORTABLE,
686 if let DefTy(..) = def {
687 child_name_bindings.type_ns.set_modifiers(modifiers);
689 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
692 DefStruct(def_id) => {
693 debug!("(building reduced graph for external crate) building type and value for \
696 child_name_bindings.define_type(def, DUMMY_SP, modifiers);
697 let fields = self.session.cstore.struct_field_names(def_id);
699 if fields.is_empty() {
700 child_name_bindings.define_value(def, DUMMY_SP, modifiers);
703 // Record the def ID and fields of this struct.
704 self.structs.insert(def_id, fields);
714 panic!("didn't expect `{:?}`", def);
719 /// Builds the reduced graph for a single item in an external crate.
720 fn build_reduced_graph_for_external_crate_def(&mut self,
725 // Add the new child item, if necessary.
727 DefForeignMod(def_id) => {
728 // Foreign modules have no names. Recur and populate
730 for child in self.session.cstore.item_children(def_id) {
731 self.build_reduced_graph_for_external_crate_def(root, child)
735 let child_name_bindings = self.add_child(xcdef.name,
740 self.handle_external_def(def,
742 &child_name_bindings,
743 &xcdef.name.as_str(),
750 debug!("(building reduced graph for external crate) ignoring impl");
753 debug!("(building reduced graph for external crate) ignoring field");
758 /// Builds the reduced graph rooted at the given external module.
759 fn populate_external_module(&mut self, module: &Rc<Module>) {
760 debug!("(populating external module) attempting to populate {}",
761 module_to_string(&**module));
763 let def_id = match module.def_id() {
765 debug!("(populating external module) ... no def ID!");
768 Some(def_id) => def_id,
771 for child in self.session.cstore.item_children(def_id) {
772 debug!("(populating external module) ... found ident: {}",
774 self.build_reduced_graph_for_external_crate_def(module, child);
776 module.populated.set(true)
779 /// Ensures that the reduced graph rooted at the given external module
780 /// is built, building it if it is not.
781 fn populate_module_if_necessary(&mut self, module: &Rc<Module>) {
782 if !module.populated.get() {
783 self.populate_external_module(module)
785 assert!(module.populated.get())
788 /// Builds the reduced graph rooted at the 'use' directive for an external
790 fn build_reduced_graph_for_external_crate(&mut self, root: &Rc<Module>) {
791 let root_cnum = root.def_id().unwrap().krate;
792 for child in self.session.cstore.crate_top_level_items(root_cnum) {
793 self.build_reduced_graph_for_external_crate_def(root, child);
797 /// Creates and adds an import directive to the given module.
798 fn build_import_directive(&mut self,
800 module_path: Vec<Name>,
801 subclass: ImportDirectiveSubclass,
805 shadowable: Shadowable) {
808 .push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
809 self.unresolved_imports += 1;
812 module_.inc_pub_count();
815 // Bump the reference count on the name. Or, if this is a glob, set
816 // the appropriate flag.
819 SingleImport(target, _) => {
820 debug!("(building import directive) building import directive: {}::{}",
821 names_to_string(&module_.imports.borrow().last().unwrap().module_path),
824 let mut import_resolutions = module_.import_resolutions.borrow_mut();
825 match import_resolutions.get_mut(&target) {
826 Some(resolution_per_ns) => {
827 debug!("(building import directive) bumping reference");
828 resolution_per_ns.outstanding_references += 1;
830 // the source of this name is different now
832 ImportResolution { id: id, is_public: is_public, target: None };
833 resolution_per_ns[TypeNS] = resolution.clone();
834 resolution_per_ns[ValueNS] = resolution;
839 debug!("(building import directive) creating new");
840 let mut import_resolution_per_ns = ImportResolutionPerNamespace::new(id, is_public);
841 import_resolution_per_ns.outstanding_references = 1;
842 import_resolutions.insert(target, import_resolution_per_ns);
845 // Set the glob flag. This tells us that we don't know the
846 // module's exports ahead of time.
848 module_.inc_glob_count();
850 module_.inc_pub_glob_count();
857 struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
858 builder: GraphBuilder<'a, 'b, 'tcx>,
862 impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
863 fn visit_nested_item(&mut self, item: hir::ItemId) {
864 self.visit_item(self.builder.resolver.ast_map.expect_item(item.id))
867 fn visit_item(&mut self, item: &Item) {
868 let p = self.builder.build_reduced_graph_for_item(item, &self.parent);
869 let old_parent = replace(&mut self.parent, p);
870 intravisit::walk_item(self, item);
871 self.parent = old_parent;
874 fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
875 self.builder.build_reduced_graph_for_foreign_item(foreign_item, &self.parent);
878 fn visit_block(&mut self, block: &Block) {
879 let np = self.builder.build_reduced_graph_for_block(block, &self.parent);
880 let old_parent = replace(&mut self.parent, np);
881 intravisit::walk_block(self, block);
882 self.parent = old_parent;
886 pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
887 GraphBuilder { resolver: resolver }.build_reduced_graph(krate);
890 pub fn populate_module_if_necessary(resolver: &mut Resolver, module: &Rc<Module>) {
891 GraphBuilder { resolver: resolver }.populate_module_if_necessary(module);