Skip to content

Commit

Permalink
Auto merge of rust-lang#122140 - oli-obk:track_errors13, r=davidtwco
Browse files Browse the repository at this point in the history
Run a single huge par_body_owners instead of many small ones after each other.

This improves parallel rustc parallelism by avoiding the bottleneck after each individual `par_body_owners` (because it needs to wait for queries to finish, so if there is one long running one, a lot of cores will be idle while waiting for the single query).
  • Loading branch information
bors committed Mar 11, 2024
2 parents d255c6a + 55ea944 commit 65cd843
Show file tree
Hide file tree
Showing 33 changed files with 419 additions and 443 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirTree => {
let tcx = ex.tcx();
let mut out = String::new();
if rustc_hir_analysis::check_crate(tcx).is_err() {
rustc_hir_analysis::check_crate(tcx);
if tcx.dcx().has_errors().is_some() {
FatalError.raise();
}
debug!("pretty printing THIR tree");
Expand All @@ -348,7 +349,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirFlat => {
let tcx = ex.tcx();
let mut out = String::new();
if rustc_hir_analysis::check_crate(tcx).is_err() {
rustc_hir_analysis::check_crate(tcx);
if tcx.dcx().has_errors().is_some() {
FatalError.raise();
}
debug!("pretty printing THIR flat");
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
use rustc_span::{sym, DUMMY_SP};

use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType};

pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let mut res = Ok(());
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) {
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
let type_of = tcx.type_of(id.owner_id).instantiate_identity();

res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
}
}
}
res
}

/// Checks "defining uses" of opaque `impl Trait` in associated types.
Expand Down
30 changes: 4 additions & 26 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ mod outlives;
pub mod structured_errors;
mod variance;

use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_middle::middle;
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -156,11 +155,13 @@ pub fn provide(providers: &mut Providers) {
hir_wf_check::provide(providers);
}

pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
pub fn check_crate(tcx: TyCtxt<'_>) {
let _prof_timer = tcx.sess.timer("type_check_crate");

if tcx.features().rustc_attrs {
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
collect::test_opaque_hidden_types(tcx);
}

tcx.sess.time("coherence_checking", || {
Expand All @@ -176,14 +177,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let _ = tcx.ensure().crate_inherent_impls_overlap_check(());
});

if tcx.features().rustc_attrs {
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
}

if tcx.features().rustc_attrs {
collect::test_opaque_hidden_types(tcx)?;
}

// Make sure we evaluate all static and (non-associated) const items, even if unused.
// If any of these fail to evaluate, we do not want this crate to pass compilation.
tcx.hir().par_body_owners(|item_def_id| {
Expand All @@ -198,21 +191,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
// Freeze definitions as we don't add new ones at this point. This improves performance by
// allowing lock-free access to them.
tcx.untracked().definitions.freeze();

// FIXME: Remove this when we implement creating `DefId`s
// for anon constants during their parents' typeck.
// Typeck all body owners in parallel will produce queries
// cycle errors because it may typeck on anon constants directly.
tcx.hir().par_body_owners(|item_def_id| {
let def_kind = tcx.def_kind(item_def_id);
if !matches!(def_kind, DefKind::AnonConst) {
tcx.ensure().typeck(item_def_id);
}
});

tcx.ensure().check_unused_traits(());

Ok(())
}

/// A quasi-deprecated helper used in rustdoc and clippy to get
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/outlives/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::sym, ErrorGuaranteed};
use rustc_span::symbol::sym;

pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let mut res = Ok(());
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
for id in tcx.hir().items() {
// For unit testing: check for a special "rustc_outlives"
// attribute and report an error with various results if found.
Expand All @@ -23,8 +22,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
for p in pred {
err.note(p);
}
res = Err(err.emit());
err.emit();
}
}
res
}
13 changes: 5 additions & 8 deletions compiler/rustc_hir_analysis/src/variance/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;
use rustc_span::ErrorGuaranteed;

use crate::errors;

pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let mut res = Ok(());
pub fn test_variance(tcx: TyCtxt<'_>) {
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
let variances_of = tcx.variances_of(id.owner_id);

res = Err(tcx.dcx().emit_err(errors::VariancesOf {
tcx.dcx().emit_err(errors::VariancesOf {
span: tcx.def_span(id.owner_id),
variances_of: format!("{variances_of:?}"),
}));
});
}
}
}
Expand All @@ -27,11 +25,10 @@ pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
let variances_of = tcx.variances_of(id.owner_id);

res = Err(tcx.dcx().emit_err(errors::VariancesOf {
tcx.dcx().emit_err(errors::VariancesOf {
span: tcx.def_span(id.owner_id),
variances_of: format!("{variances_of:?}"),
}));
});
}
}
res
}
33 changes: 18 additions & 15 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,19 +734,22 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
});

// passes are timed inside typeck
rustc_hir_analysis::check_crate(tcx)?;
rustc_hir_analysis::check_crate(tcx);

sess.time("MIR_borrow_checking", || {
sess.time("typeck_and_mir_analyses", || {
tcx.hir().par_body_owners(|def_id| {
let def_kind = tcx.def_kind(def_id);
// FIXME: Remove this when we implement creating `DefId`s
// for anon constants during their parents' typeck.
// Typeck all body owners in parallel will produce queries
// cycle errors because it may typeck on anon constants directly.
if !matches!(def_kind, rustc_hir::def::DefKind::AnonConst) {
tcx.ensure().typeck(def_id);
}
// Run unsafety check because it's responsible for stealing and
// deallocating THIR.
tcx.ensure().check_unsafety(def_id);
tcx.ensure().mir_borrowck(def_id)
});
});

sess.time("MIR_effect_checking", || {
for def_id in tcx.hir().body_owners() {
tcx.ensure().mir_borrowck(def_id);
if !tcx.sess.opts.unstable_opts.thir_unsafeck {
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);
}
Expand All @@ -761,16 +764,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
tcx.ensure().unused_generic_params(ty::InstanceDef::Item(def_id.to_def_id()));
}
}
});

tcx.hir().par_body_owners(|def_id| {
if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure().mir_coroutine_witnesses(def_id);
tcx.ensure().check_coroutine_obligations(def_id);
}
if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure().mir_coroutine_witnesses(def_id);
tcx.ensure().check_coroutine_obligations(def_id);
}
})
});

tcx.ensure().check_unused_traits(());

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

Expand Down
26 changes: 13 additions & 13 deletions tests/ui/binop/issue-77910-1.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
error[E0381]: used binding `xs` isn't initialized
--> $DIR/issue-77910-1.rs:3:5
|
LL | let xs;
| -- binding declared here but left uninitialized
LL | xs
| ^^ `xs` used here but it isn't initialized
|
help: consider assigning a value
|
LL | let xs = todo!();
| +++++++++

error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
--> $DIR/issue-77910-1.rs:8:5
|
Expand All @@ -22,19 +35,6 @@ LL | assert_eq!(foo, y);
= help: use parentheses to call this function: `foo(/* &i32 */)`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0381]: used binding `xs` isn't initialized
--> $DIR/issue-77910-1.rs:3:5
|
LL | let xs;
| -- binding declared here but left uninitialized
LL | xs
| ^^ `xs` used here but it isn't initialized
|
help: consider assigning a value
|
LL | let xs = todo!();
| +++++++++

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0369, E0381.
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/binop/issue-77910-2.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
--> $DIR/issue-77910-2.rs:7:12
|
LL | if foo == y {}
| --- ^^ - _
| |
| for<'a> fn(&'a i32) -> &'a i32 {foo}
|
help: use parentheses to call this function
|
LL | if foo(/* &i32 */) == y {}
| ++++++++++++

error[E0381]: used binding `xs` isn't initialized
--> $DIR/issue-77910-2.rs:3:5
|
Expand All @@ -24,6 +11,19 @@ help: consider assigning a value
LL | let xs = todo!();
| +++++++++

error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
--> $DIR/issue-77910-2.rs:7:12
|
LL | if foo == y {}
| --- ^^ - _
| |
| for<'a> fn(&'a i32) -> &'a i32 {foo}
|
help: use parentheses to call this function
|
LL | if foo(/* &i32 */) == y {}
| ++++++++++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0369, E0381.
Expand Down
46 changes: 23 additions & 23 deletions tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ help: use `addr_of_mut!` instead to create a raw pointer
LL | c1(addr_of_mut!(Y));
| ~~~~~~~~~~~~~~~

error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
|
LL | pub fn e(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
LL | static mut Y: isize = 3;
LL | let mut c1 = |y: &'static mut isize| x = y;
| ^^^^^ cannot assign

warning: creating a mutable reference to mutable static is discouraged
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16
|
Expand All @@ -27,29 +36,6 @@ help: use `addr_of_mut!` instead to create a raw pointer
LL | c1(addr_of_mut!(Z));
| ~~~~~~~~~~~~~~~

warning: creating a mutable reference to mutable static is discouraged
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
|
LL | borrowck_closures_unique::e(&mut X);
| ^^^^^^ mutable reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
help: use `addr_of_mut!` instead to create a raw pointer
|
LL | borrowck_closures_unique::e(addr_of_mut!(X));
| ~~~~~~~~~~~~~~~

error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
|
LL | pub fn e(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
LL | static mut Y: isize = 3;
LL | let mut c1 = |y: &'static mut isize| x = y;
| ^^^^^ cannot assign

error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50
|
Expand Down Expand Up @@ -95,6 +81,20 @@ LL | || {
LL | &mut x.0;
| ^^^^^^^^ cannot borrow as mutable

warning: creating a mutable reference to mutable static is discouraged
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
|
LL | borrowck_closures_unique::e(&mut X);
| ^^^^^^ mutable reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
help: use `addr_of_mut!` instead to create a raw pointer
|
LL | borrowck_closures_unique::e(addr_of_mut!(X));
| ~~~~~~~~~~~~~~~

error: aborting due to 6 previous errors; 3 warnings emitted

Some errors have detailed explanations: E0594, E0596.
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/const-generics/generic_const_exprs/type_mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ LL | impl<const N: u64> Q for [u8; N] {}
| |
| unsatisfied trait bound introduced here

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:8:31
|
LL | impl<const N: u64> Q for [u8; N] {}
| ^ expected `usize`, found `u64`

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:12:20
|
Expand All @@ -29,12 +35,6 @@ LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
| |
| implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:8:31
|
LL | impl<const N: u64> Q for [u8; N] {}
| ^ expected `usize`, found `u64`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0046, E0308.
Expand Down
Loading

0 comments on commit 65cd843

Please sign in to comment.