Move body_owners to tcx.hir().

This commit is contained in:
Camille GILLOT 2021-09-12 11:33:16 +02:00
parent db9fea508a
commit abc57f63ad
7 changed files with 18 additions and 25 deletions

View File

@ -489,7 +489,7 @@ fn print_with_analysis(
let mut out = String::new();
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
debug!("pretty printing THIR tree");
for did in tcx.body_owners() {
for did in tcx.hir().body_owners() {
let _ = writeln!(
out,
"{:?}:\n{}\n",

View File

@ -886,9 +886,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
parallel!(
{
sess.time("match_checking", || {
tcx.par_body_owners(|def_id| {
tcx.ensure().check_match(def_id.to_def_id());
});
tcx.hir().par_body_owners(|def_id| tcx.ensure().check_match(def_id.to_def_id()))
});
},
{
@ -907,11 +905,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
});
sess.time("MIR_borrow_checking", || {
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
});
sess.time("MIR_effect_checking", || {
for def_id in tcx.body_owners() {
for def_id in tcx.hir().body_owners() {
tcx.ensure().thir_check_unsafety(def_id);
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);

View File

@ -491,6 +491,17 @@ pub fn body_const_context(&self, did: LocalDefId) -> Option<ConstContext> {
Some(ccx)
}
/// Returns an iterator of the `DefId`s for all body-owners in this
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir {
self.krate().bodies.keys().map(move |&body_id| self.body_owner_def_id(body_id))
}
pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
par_for_each_in(&self.krate().bodies, |(&body_id, _)| f(self.body_owner_def_id(body_id)));
}
pub fn ty_param_owner(&self, id: HirId) -> HirId {
match self.get(id) {
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => id,

View File

@ -29,10 +29,8 @@
use crate::ty::util::Discr;
use rustc_ast as ast;
use rustc_attr as attr;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@ -1660,18 +1658,6 @@ pub fn typeck_body(self, body: hir::BodyId) -> &'tcx TypeckResults<'tcx> {
self.typeck(self.hir().body_owner_def_id(body))
}
/// Returns an iterator of the `DefId`s for all body-owners in this
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
self.hir().krate().bodies.keys().map(move |&body_id| self.hir().body_owner_def_id(body_id))
}
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
par_iter(&self.hir().krate().bodies)
.for_each(|(&body_id, _)| f(self.hir().body_owner_def_id(body_id)));
}
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
self.associated_items(id)
.in_definition_order()

View File

@ -133,7 +133,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
let mut set = FxHashSet::default();
// All body-owners have MIR associated with them.
set.extend(tcx.body_owners());
set.extend(tcx.hir().body_owners());
// Additionally, tuple struct/variant constructors have MIR, but
// they don't have a BodyId, so we need to build them separately.

View File

@ -921,9 +921,7 @@ fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {}
}
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
tcx.par_body_owners(|body_owner_def_id| {
tcx.ensure().typeck(body_owner_def_id);
});
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
}
fn fatally_break_rust(sess: &Session) {

View File

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