Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2305,15 +2305,22 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {

pub(super) fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
let items = tcx.hir_crate_items(());
let res = items
.par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
.and(items.par_impl_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
.and(items.par_trait_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
.and(
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
)
.and(items.par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
let res =
items
.try_par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
.and(
items.try_par_impl_items(|item| {
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
}),
)
.and(items.try_par_trait_items(|item| {
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
}))
.and(items.try_par_foreign_items(|item| {
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
}))
.and(items.try_par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
.and(items.try_par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
super::entry::check_for_entry_fn(tcx);

res
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ mod variance;

pub use errors::NoVariantNamed;
use rustc_abi::{CVariadicStatus, ExternAbi};
use rustc_hir::attrs::AttributeKind;

use rustc_data_structures::sync::par_for_each_in;use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::DefKind;
use rustc_hir::lints::DelayedLint;
use rustc_hir::{
Expand Down Expand Up @@ -175,16 +176,20 @@ fn emit_delayed_lint(lint: &DelayedLint, tcx: TyCtxt<'_>) {
pub fn check_crate(tcx: TyCtxt<'_>) {
let _prof_timer = tcx.sess.timer("type_check_crate");

// Run dependencies of type checking before entering the loops below
tcx.ensure_done().inferred_outlives_crate(());

tcx.sess.time("coherence_checking", || {
// When discarding query call results, use an explicit type to indicate
// what we are intending to discard, to help future type-based refactoring.
type R = Result<(), ErrorGuaranteed>;

let _: R = tcx.ensure_ok().check_type_wf(());

for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
let _: R = tcx.ensure_ok().coherent_trait(trait_def_id);
}
par_for_each_in(tcx.all_local_trait_impls(()), |(trait_def_id, _)| {
let _: R = tcx.ensure_ok().coherent_trait(*trait_def_id);
});

// these queries are executed for side-effects (error reporting):
let _: R = tcx.ensure_ok().crate_inherent_impls_validity_check(());
let _: R = tcx.ensure_ok().crate_inherent_impls_overlap_check(());
Expand Down
132 changes: 71 additions & 61 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,19 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
{
tcx.ensure_ok().exportable_items(LOCAL_CRATE);
tcx.ensure_ok().stable_order_of_exportable_impls(LOCAL_CRATE);

// Prefetch this as it is used later by the loop below
// to prevent multiple threads from blocking on it.
tcx.ensure_done().get_lang_items(());

let _timer = tcx.sess.timer("misc_module_passes");
tcx.par_hir_for_each_module(|module| {
tcx.ensure_ok().check_mod_attrs(module);
});
},
{
let _timer = tcx.sess.timer("check_unstable_api_usage");
tcx.par_hir_for_each_module(|module| {
tcx.ensure_ok().check_mod_unstable_api_usage(module);
});
},
Expand All @@ -1091,49 +1102,56 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
// This improves performance by allowing lock-free access to them.
tcx.untracked().definitions.freeze();

sess.time("MIR_borrow_checking", || {
tcx.par_hir_body_owners(|def_id| {
let not_typeck_child = !tcx.is_typeck_child(def_id.to_def_id());
if not_typeck_child {
// Child unsafety and borrowck happens together with the parent
tcx.ensure_ok().check_unsafety(def_id);
}
if tcx.is_trivial_const(def_id) {
return;
}
if not_typeck_child {
tcx.ensure_ok().mir_borrowck(def_id);
tcx.ensure_ok().check_transmutes(def_id);
}
tcx.ensure_ok().has_ffi_unwind_calls(def_id);
tcx.ensure_ok().check_liveness(def_id);

// If we need to codegen, ensure that we emit all errors from
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
// them later during codegen.
if tcx.sess.opts.output_types.should_codegen()
|| tcx.hir_body_const_context(def_id).is_some()
sess.time("misc_checking_2", || {
parallel!(
{
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
}
if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure_ok().mir_coroutine_witnesses(def_id);
let _ = tcx.ensure_ok().check_coroutine_obligations(
tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(),
);
if !tcx.is_async_drop_in_place_coroutine(def_id.to_def_id()) {
// Eagerly check the unsubstituted layout for cycles.
tcx.ensure_ok().layout_of(
ty::TypingEnv::post_analysis(tcx, def_id.to_def_id())
.as_query_input(tcx.type_of(def_id).instantiate_identity()),
);
}
// Prefetch this as it is used later by lint checking and privacy checking.
tcx.ensure_done().effective_visibilities(());
},
{
sess.time("misc_body_checking", || {
tcx.par_hir_body_owners(|def_id| {
if !tcx.is_typeck_child(def_id.to_def_id()) {
// Child unsafety and borrowck happens together with the parent
tcx.ensure_ok().check_unsafety(def_id);
tcx.ensure_ok().mir_borrowck(def_id);
tcx.ensure_ok().check_transmutes(def_id);
}
tcx.ensure_ok().has_ffi_unwind_calls(def_id);

// If we need to codegen, ensure that we emit all errors from
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
// them later during codegen.
if tcx.sess.opts.output_types.should_codegen()
|| tcx.hir_body_const_context(def_id).is_some()
{
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
}

if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure_ok().mir_coroutine_witnesses(def_id);
let _ = tcx.ensure_ok().check_coroutine_obligations(
tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(),
);
if !tcx.is_async_drop_in_place_coroutine(def_id.to_def_id()) {
// Eagerly check the unsubstituted layout for cycles.
tcx.ensure_ok().layout_of(
ty::TypingEnv::post_analysis(tcx, def_id.to_def_id())
.as_query_input(tcx.type_of(def_id).instantiate_identity()),
);
}
}
});
});
},
{
sess.time("layout_testing", || layout_test::test_layout(tcx));
sess.time("abi_testing", || abi_test::test_abi(tcx));
}
});
)
});

sess.time("layout_testing", || layout_test::test_layout(tcx));
sess.time("abi_testing", || abi_test::test_abi(tcx));
}
}

/// Runs the type-checking, region checking and other miscellaneous analysis
Expand All @@ -1158,28 +1176,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
sess.time("misc_checking_3", || {
parallel!(
{
tcx.ensure_ok().effective_visibilities(());

parallel!(
{
tcx.par_hir_for_each_module(|module| {
tcx.ensure_ok().check_private_in_public(module)
})
},
{
tcx.par_hir_for_each_module(|module| {
tcx.ensure_ok().check_mod_deathness(module)
});
},
{
sess.time("lint_checking", || {
rustc_lint::check_crate(tcx);
});
},
{
tcx.ensure_ok().clashing_extern_declarations(());
}
);
tcx.par_hir_for_each_module(|module| {
tcx.ensure_ok().check_private_in_public(module)
})
},
{
tcx.par_hir_for_each_module(|module| tcx.ensure_ok().check_mod_deathness(module));
},
{
sess.time("lint_checking", || {
rustc_lint::check_crate(tcx);
});
},
{
tcx.ensure_ok().clashing_extern_declarations(());
},
{
sess.time("privacy_checking_modules", || {
Expand Down
30 changes: 23 additions & 7 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod place;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
use rustc_data_structures::sync::{DynSend, DynSync, par_for_each_in, try_par_for_each_in};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lints::DelayedLint;
Expand Down Expand Up @@ -99,47 +99,63 @@ impl ModuleItems {
}

/// Closures and inline consts
pub fn par_nested_bodies(
pub fn try_par_nested_bodies(
&self,
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
}

pub fn par_items(
pub fn try_par_items(
&self,
f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.free_items[..], |&&id| f(id))
}

pub fn par_trait_items(
pub fn try_par_trait_items(
&self,
f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
}

pub fn par_impl_items(
pub fn try_par_impl_items(
&self,
f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
}

pub fn par_foreign_items(
pub fn try_par_foreign_items(
&self,
f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
}

pub fn par_opaques(
pub fn try_par_opaques(
&self,
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.opaques[..], |&&id| f(id))
}

pub fn par_items(&self, f: impl Fn(ItemId) + DynSend + DynSync) {
par_for_each_in(&self.free_items[..], |&&id| f(id))
}

pub fn par_trait_items(&self, f: impl Fn(TraitItemId) + DynSend + DynSync) {
par_for_each_in(&self.trait_items[..], |&&id| f(id))
}

pub fn par_impl_items(&self, f: impl Fn(ImplItemId) + DynSend + DynSync) {
par_for_each_in(&self.impl_items[..], |&&id| f(id))
}

pub fn par_foreign_items(&self, f: impl Fn(ForeignItemId) + DynSend + DynSync) {
par_for_each_in(&self.foreign_items[..], |&&id| f(id))
}
}

impl<'tcx> TyCtxt<'tcx> {
Expand Down
19 changes: 15 additions & 4 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ use std::cell::OnceCell;
use std::ops::ControlFlow;

use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{MTLock, par_for_each_in};
use rustc_data_structures::sync::{MTLock, join, par_for_each_in};
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_hir as hir;
use rustc_hir::attrs::InlineAttr;
Expand Down Expand Up @@ -1806,9 +1806,20 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
) -> (Vec<MonoItem<'tcx>>, UsageMap<'tcx>) {
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector");

let roots = tcx
.sess
.time("monomorphization_collector_root_collections", || collect_roots(tcx, strategy));
let (roots, _) = join(
|| {
tcx.sess.time("monomorphization_collector_root_collections", || {
collect_roots(tcx, strategy)
})
},
|| {
if tcx.sess.opts.share_generics() {
// Prefetch upstream_monomorphizations as it's very likely to be used in
// code generation later and this is decent spot to compute it.
tcx.ensure_ok().upstream_monomorphizations(());
}
},
);

debug!("building mono item graph, beginning at roots");

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,6 @@ fn check_private_in_public(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
let checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };

let crate_items = tcx.hir_module_items(module_def_id);
let _ = crate_items.par_items(|id| Ok(checker.check_item(id)));
let _ = crate_items.par_foreign_items(|id| Ok(checker.check_foreign_item(id)));
crate_items.par_items(|id| checker.check_item(id));
crate_items.par_foreign_items(|id| checker.check_foreign_item(id));
}
8 changes: 4 additions & 4 deletions tests/ui/macros/macro-span-issue-116502.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | _
| ^ not allowed in type signatures
...
LL | struct S<T = m!()>(m!(), T)
| ---- in this macro invocation
| ---- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand All @@ -15,7 +15,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
LL | _
| ^ not allowed in type signatures
...
LL | T: Trait<m!()>;
LL | struct S<T = m!()>(m!(), T)
| ---- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -26,8 +26,8 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
LL | _
| ^ not allowed in type signatures
...
LL | struct S<T = m!()>(m!(), T)
| ---- in this macro invocation
LL | T: Trait<m!()>;
| ---- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/span/issue-35987.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct Foo<T: Clone>(T);
use std::ops::Add;

impl<T: Clone, Add> Add for Foo<T> {
//~^ ERROR expected trait, found type parameter
//~^ ERROR expected trait, found type parameter
type Output = usize;

fn add(self, rhs: Self) -> Self::Output {
Expand Down
Loading
Loading