Skip to content

Commit 5ffa8f6

Browse files
committed
Auto merge of rust-lang#98222 - cjgillot:single-wf, r=michaelwoerister
Only keep a single query for well-formed checking There are currently 3 queries to perform wf checks on different item-likes. This complexity is not required. This PR replaces the query by: - one query per item; - one query to invoke it for a whole module. This allows to remove HIR `ParItemLikeVisitor`.
2 parents 7f08d04 + f446bbc commit 5ffa8f6

30 files changed

+241
-442
lines changed

compiler/rustc_hir/src/intravisit.rs

-24
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
//! example generator inference, and possibly also HIR borrowck.
6666
6767
use crate::hir::*;
68-
use crate::itemlikevisit::ParItemLikeVisitor;
6968
use rustc_ast::walk_list;
7069
use rustc_ast::{Attribute, Label};
7170
use rustc_span::symbol::{Ident, Symbol};
@@ -76,29 +75,6 @@ pub trait IntoVisitor<'hir> {
7675
fn into_visitor(&self) -> Self::Visitor;
7776
}
7877

79-
pub struct ParDeepVisitor<V>(pub V);
80-
81-
impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>
82-
where
83-
V: IntoVisitor<'hir>,
84-
{
85-
fn visit_item(&self, item: &'hir Item<'hir>) {
86-
self.0.into_visitor().visit_item(item);
87-
}
88-
89-
fn visit_trait_item(&self, trait_item: &'hir TraitItem<'hir>) {
90-
self.0.into_visitor().visit_trait_item(trait_item);
91-
}
92-
93-
fn visit_impl_item(&self, impl_item: &'hir ImplItem<'hir>) {
94-
self.0.into_visitor().visit_impl_item(impl_item);
95-
}
96-
97-
fn visit_foreign_item(&self, foreign_item: &'hir ForeignItem<'hir>) {
98-
self.0.into_visitor().visit_foreign_item(foreign_item);
99-
}
100-
}
101-
10278
#[derive(Copy, Clone, Debug)]
10379
pub enum FnKind<'a> {
10480
/// `#[xxx] pub async/const/extern "Abi" fn foo()`

compiler/rustc_hir/src/itemlikevisit.rs

-9
This file was deleted.

compiler/rustc_hir/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub use rustc_span::def_id;
2727
mod hir;
2828
pub mod hir_id;
2929
pub mod intravisit;
30-
pub mod itemlikevisit;
3130
pub mod lang_items;
3231
pub mod pat_util;
3332
mod stable_hash_impls;

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

+4-17
Original file line numberDiff line numberDiff line change
@@ -612,23 +612,6 @@ impl<'hir> Map<'hir> {
612612
}
613613
}
614614

615-
/// A parallel version of `visit_all_item_likes`.
616-
pub fn par_visit_all_item_likes<V>(self, visitor: &V)
617-
where
618-
V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send,
619-
{
620-
let krate = self.krate();
621-
par_for_each_in(&krate.owners.raw, |owner| match owner.map(OwnerInfo::node) {
622-
MaybeOwner::Owner(OwnerNode::Item(item)) => visitor.visit_item(item),
623-
MaybeOwner::Owner(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item),
624-
MaybeOwner::Owner(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item),
625-
MaybeOwner::Owner(OwnerNode::TraitItem(item)) => visitor.visit_trait_item(item),
626-
MaybeOwner::Owner(OwnerNode::Crate(_))
627-
| MaybeOwner::NonOwner(_)
628-
| MaybeOwner::Phantom => {}
629-
})
630-
}
631-
632615
/// If you don't care about nesting, you should use the
633616
/// `tcx.hir_module_items()` query or `module_items()` instead.
634617
/// Please see notes in `deep_visit_all_item_likes`.
@@ -867,6 +850,10 @@ impl<'hir> Map<'hir> {
867850
)
868851
}
869852

853+
pub fn expect_owner(self, id: LocalDefId) -> OwnerNode<'hir> {
854+
self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id)).node
855+
}
856+
870857
pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> {
871858
match self.tcx.hir_owner(id) {
872859
Some(Owner { node: OwnerNode::Item(item), .. }) => item,

compiler/rustc_middle/src/hir/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::ty::query::Providers;
1010
use crate::ty::{DefIdTree, ImplSubject, TyCtxt};
1111
use rustc_data_structures::fingerprint::Fingerprint;
1212
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
13+
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
1314
use rustc_hir::def_id::{DefId, LocalDefId};
1415
use rustc_hir::*;
1516
use rustc_query_system::ich::StableHashingContext;
@@ -61,6 +62,22 @@ impl ModuleItems {
6162
pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> + '_ {
6263
self.foreign_items.iter().copied()
6364
}
65+
66+
pub fn par_items(&self, f: impl Fn(ItemId) + Send + Sync) {
67+
par_for_each_in(&self.items[..], |&id| f(id))
68+
}
69+
70+
pub fn par_trait_items(&self, f: impl Fn(TraitItemId) + Send + Sync) {
71+
par_for_each_in(&self.trait_items[..], |&id| f(id))
72+
}
73+
74+
pub fn par_impl_items(&self, f: impl Fn(ImplItemId) + Send + Sync) {
75+
par_for_each_in(&self.impl_items[..], |&id| f(id))
76+
}
77+
78+
pub fn par_foreign_items(&self, f: impl Fn(ForeignItemId) + Send + Sync) {
79+
par_for_each_in(&self.foreign_items[..], |&id| f(id))
80+
}
6481
}
6582

6683
impl<'tcx> TyCtxt<'tcx> {

compiler/rustc_middle/src/query/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ rustc_queries! {
826826
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
827827
}
828828

829+
query check_mod_type_wf(key: LocalDefId) -> () {
830+
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
831+
}
832+
829833
query collect_mod_item_types(key: LocalDefId) -> () {
830834
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
831835
}
@@ -1399,13 +1403,7 @@ rustc_queries! {
13991403
separate_provide_extern
14001404
}
14011405

1402-
query check_item_well_formed(key: LocalDefId) -> () {
1403-
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1404-
}
1405-
query check_trait_item_well_formed(key: LocalDefId) -> () {
1406-
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1407-
}
1408-
query check_impl_item_well_formed(key: LocalDefId) -> () {
1406+
query check_well_formed(key: LocalDefId) -> () {
14091407
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
14101408
}
14111409

compiler/rustc_typeck/src/check/check.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ use rustc_ty_utils::representability::{self, Representability};
3232
use std::iter;
3333
use std::ops::ControlFlow;
3434

35-
pub fn check_wf_new(tcx: TyCtxt<'_>) {
36-
let visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
37-
tcx.hir().par_visit_all_item_likes(&visit);
38-
}
39-
4035
pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
4136
match tcx.sess.target.is_abi_supported(abi) {
4237
Some(true) => (),
@@ -754,7 +749,7 @@ fn check_opaque_meets_bounds<'tcx>(
754749
});
755750
}
756751

757-
pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
752+
fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
758753
debug!(
759754
"check_item_type(it.def_id={:?}, it.name={})",
760755
id.def_id,
@@ -1543,12 +1538,6 @@ pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
15431538
}
15441539
}
15451540

1546-
pub(super) use wfcheck::check_item_well_formed;
1547-
1548-
pub(super) use wfcheck::check_trait_item as check_trait_item_well_formed;
1549-
1550-
pub(super) use wfcheck::check_impl_item as check_impl_item_well_formed;
1551-
15521541
fn async_opaque_type_cycle_error(tcx: TyCtxt<'_>, span: Span) -> ErrorGuaranteed {
15531542
struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing")
15541543
.span_label(span, "recursive `async fn`")

compiler/rustc_typeck/src/check/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ mod upvar;
9393
mod wfcheck;
9494
pub mod writeback;
9595

96-
use check::{
97-
check_abi, check_fn, check_impl_item_well_formed, check_item_well_formed, check_mod_item_types,
98-
check_trait_item_well_formed,
99-
};
100-
pub use check::{check_item_type, check_wf_new};
96+
use check::{check_abi, check_fn, check_mod_item_types};
10197
pub use diverges::Diverges;
10298
pub use expectation::Expectation;
10399
pub use fn_ctxt::*;
@@ -245,6 +241,7 @@ impl<'tcx> EnclosingBreakables<'tcx> {
245241

246242
pub fn provide(providers: &mut Providers) {
247243
method::provide(providers);
244+
wfcheck::provide(providers);
248245
*providers = Providers {
249246
typeck_item_bodies,
250247
typeck_const_arg,
@@ -253,9 +250,6 @@ pub fn provide(providers: &mut Providers) {
253250
has_typeck_results,
254251
adt_destructor,
255252
used_trait_imports,
256-
check_item_well_formed,
257-
check_trait_item_well_formed,
258-
check_impl_item_well_formed,
259253
check_mod_item_types,
260254
region_scope_tree,
261255
..*providers

0 commit comments

Comments
 (0)