Skip to content

Commit

Permalink
HirIdify hir::Crate.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Aug 25, 2019
1 parent 4784645 commit 9a6ca41
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub struct LoweringContext<'a> {

trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,

modules: BTreeMap<NodeId, hir::ModuleItems>,
modules: BTreeMap<hir::HirId, hir::ModuleItems>,

generator_kind: Option<hir::GeneratorKind>,

Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct LoweringContext<'a> {
/// vector.
in_scope_lifetimes: Vec<ParamName>,

current_module: NodeId,
current_module: hir::HirId,

type_def_lifetime_params: DefIdMap<usize>,

Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn lower_crate(
is_in_dyn_type: false,
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
type_def_lifetime_params: Default::default(),
current_module: CRATE_NODE_ID,
current_module: hir::CRATE_HIR_ID,
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
item_local_id_counters: Default::default(),
node_id_to_hir_id: IndexVec::new(),
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ impl<'tcx, 'interner> ItemLowerer<'tcx, 'interner> {

impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
fn visit_mod(&mut self, m: &'tcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
self.lctx.modules.insert(n, hir::ModuleItems {
let hir_id = self.lctx.lower_node_id(n);

self.lctx.modules.insert(hir_id, hir::ModuleItems {
items: BTreeSet::new(),
trait_items: BTreeSet::new(),
impl_items: BTreeSet::new(),
});

let old = self.lctx.current_module;
self.lctx.current_module = n;
self.lctx.current_module = hir_id;
visit::walk_mod(self, m);
self.lctx.current_module = old;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/hir_id_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn check_crate(hir_map: &hir::map::Map<'_>) {
let errors = Lock::new(Vec::new());

par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
let local_def_id = hir_map.local_def_id_from_node_id(*module_id);
let local_def_id = hir_map.local_def_id(*module_id);
hir_map.visit_item_likes_in_module(local_def_id, &mut OuterVisitor {
hir_map,
errors: &errors,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ impl<'hir> Map<'hir> {
// in the expect_* calls the loops below
self.read(hir_id);

let node_id = self.hir_to_node_id[&hir_id];

let module = &self.forest.krate.modules[&node_id];
let module = &self.forest.krate.modules[&hir_id];

for id in &module.items {
visitor.visit_item(self.expect_item(*id));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ pub struct Crate {

/// A list of modules written out in the order in which they
/// appear in the crate. This includes the main crate module.
pub modules: BTreeMap<NodeId, ModuleItems>,
pub modules: BTreeMap<HirId, ModuleItems>,
}

impl Crate {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
time(tcx.sess, "module lints", || {
// Run per-module lints
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().lint_mod(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
});
});
});
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
});
}, {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().check_mod_loops(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_attrs(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_unstable_api_usage(
tcx.hir().local_def_id_from_node_id(module));
let local_def_id = tcx.hir().local_def_id(module);
tcx.ensure().check_mod_loops(local_def_id);
tcx.ensure().check_mod_attrs(local_def_id);
tcx.ensure().check_mod_unstable_api_usage(local_def_id);
});
});
});
Expand All @@ -939,9 +939,10 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
// "not all control paths return a value" is reported here.
//
// maybe move the check to a MIR pass?
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id_from_node_id(module));
let local_def_id = tcx.hir().local_def_id(module);

tcx.ensure().check_mod_intrinsics(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_liveness(local_def_id);
tcx.ensure().check_mod_intrinsics(local_def_id);
});
});
});
Expand Down Expand Up @@ -1001,7 +1002,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
}, {
time(sess, "privacy checking modules", || {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
// but it's one that we must perform earlier than the rest of
// WfCheck.
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
tcx.sess.track_errors(|| {
time(tcx.sess, "type collecting", || {
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
}
});
})?;
Expand Down Expand Up @@ -341,7 +341,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {

time(tcx.sess, "item-types checking", || {
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id_from_node_id(module));
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
}
});

Expand Down

0 comments on commit 9a6ca41

Please sign in to comment.