Skip to content
Open
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 @@ -2243,15 +2243,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
11 changes: 8 additions & 3 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ mod variance;

pub use errors::NoVariantNamed;
use rustc_abi::{CVariadicStatus, ExternAbi};
use rustc_data_structures::sync::par_for_each_in;
use rustc_hir::def::DefKind;
use rustc_hir::lints::DelayedLint;
use rustc_hir::{self as hir};
Expand Down Expand Up @@ -167,16 +168,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
123 changes: 69 additions & 54 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,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 @@ -1086,43 +1097,55 @@ 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| {
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);
sess.time("misc_checking_2", || {
parallel!(
{
// 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 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()
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()),
);
}
}
});
});
},
{
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
sess.time("layout_testing", || layout_test::test_layout(tcx));
sess.time("abi_testing", || abi_test::test_abi(tcx));
}
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));

// If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
// (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
// in MIR optimizations that may only be reachable through codegen, or other codepaths
Expand Down Expand Up @@ -1158,28 +1181,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;
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lints::DelayedLint;
Expand Down Expand Up @@ -92,47 +92,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 @@ -210,7 +210,7 @@ mod autodiff;
use std::cell::OnceCell;

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 @@ -1739,9 +1739,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 @@ -1881,6 +1881,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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,6 @@ LL | #![link(name = "x")]
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: the feature `rust1` has been stable since 1.0.0 and no longer requires an attribute to enable
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:100:12
|
LL | #![feature(rust1)]
| ^^^^^
|
= note: `#[warn(stable_features)]` on by default

warning: crate-level attribute should be in the root module
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:505:17
|
Expand Down Expand Up @@ -637,6 +629,14 @@ help: add a `!`
LL | #![no_builtins] impl S { }
| +

warning: the feature `rust1` has been stable since 1.0.0 and no longer requires an attribute to enable
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:100:12
|
LL | #![feature(rust1)]
| ^^^^^
|
= note: `#[warn(stable_features)]` on by default

warning: `#[macro_use]` attribute cannot be used on functions
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:191:5
|
Expand Down
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
Loading
Loading