Skip to content

Commit abc57f6

Browse files
committed
Move body_owners to tcx.hir().
1 parent db9fea5 commit abc57f6

File tree

7 files changed

+18
-25
lines changed

7 files changed

+18
-25
lines changed

compiler/rustc_driver/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ fn print_with_analysis(
489489
let mut out = String::new();
490490
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
491491
debug!("pretty printing THIR tree");
492-
for did in tcx.body_owners() {
492+
for did in tcx.hir().body_owners() {
493493
let _ = writeln!(
494494
out,
495495
"{:?}:\n{}\n",

compiler/rustc_interface/src/passes.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
886886
parallel!(
887887
{
888888
sess.time("match_checking", || {
889-
tcx.par_body_owners(|def_id| {
890-
tcx.ensure().check_match(def_id.to_def_id());
891-
});
889+
tcx.hir().par_body_owners(|def_id| tcx.ensure().check_match(def_id.to_def_id()))
892890
});
893891
},
894892
{
@@ -907,11 +905,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
907905
});
908906

909907
sess.time("MIR_borrow_checking", || {
910-
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
908+
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
911909
});
912910

913911
sess.time("MIR_effect_checking", || {
914-
for def_id in tcx.body_owners() {
912+
for def_id in tcx.hir().body_owners() {
915913
tcx.ensure().thir_check_unsafety(def_id);
916914
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
917915
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);

compiler/rustc_middle/src/hir/map/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ impl<'hir> Map<'hir> {
491491
Some(ccx)
492492
}
493493

494+
/// Returns an iterator of the `DefId`s for all body-owners in this
495+
/// crate. If you would prefer to iterate over the bodies
496+
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
497+
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir {
498+
self.krate().bodies.keys().map(move |&body_id| self.body_owner_def_id(body_id))
499+
}
500+
501+
pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
502+
par_for_each_in(&self.krate().bodies, |(&body_id, _)| f(self.body_owner_def_id(body_id)));
503+
}
504+
494505
pub fn ty_param_owner(&self, id: HirId) -> HirId {
495506
match self.get(id) {
496507
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => id,

compiler/rustc_middle/src/ty/mod.rs

-14
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
2929
use crate::ty::util::Discr;
3030
use rustc_ast as ast;
3131
use rustc_attr as attr;
32-
use rustc_data_structures::captures::Captures;
3332
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3433
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
35-
use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
3634
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
3735
use rustc_hir as hir;
3836
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@@ -1660,18 +1658,6 @@ impl<'tcx> TyCtxt<'tcx> {
16601658
self.typeck(self.hir().body_owner_def_id(body))
16611659
}
16621660

1663-
/// Returns an iterator of the `DefId`s for all body-owners in this
1664-
/// crate. If you would prefer to iterate over the bodies
1665-
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
1666-
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
1667-
self.hir().krate().bodies.keys().map(move |&body_id| self.hir().body_owner_def_id(body_id))
1668-
}
1669-
1670-
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
1671-
par_iter(&self.hir().krate().bodies)
1672-
.for_each(|(&body_id, _)| f(self.hir().body_owner_def_id(body_id)));
1673-
}
1674-
16751661
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
16761662
self.associated_items(id)
16771663
.in_definition_order()

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
133133
let mut set = FxHashSet::default();
134134

135135
// All body-owners have MIR associated with them.
136-
set.extend(tcx.body_owners());
136+
set.extend(tcx.hir().body_owners());
137137

138138
// Additionally, tuple struct/variant constructors have MIR, but
139139
// they don't have a BodyId, so we need to build them separately.

compiler/rustc_typeck/src/check/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,7 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
921921
}
922922

923923
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
924-
tcx.par_body_owners(|body_owner_def_id| {
925-
tcx.ensure().typeck(body_owner_def_id);
926-
});
924+
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
927925
}
928926

929927
fn fatally_break_rust(sess: &Session) {

compiler/rustc_typeck/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::{Span, Symbol};
99

1010
pub fn check_crate(tcx: TyCtxt<'_>) {
1111
let mut used_trait_imports = FxHashSet::default();
12-
for item_def_id in tcx.body_owners() {
12+
for item_def_id in tcx.hir().body_owners() {
1313
let imports = tcx.used_trait_imports(item_def_id);
1414
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
1515
used_trait_imports.extend(imports.iter());

0 commit comments

Comments
 (0)