Skip to content

Commit 702bd6d

Browse files
committed
Auto merge of rust-lang#122140 - oli-obk:track_errors13, r=<try>
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). based on rust-lang#121500
2 parents 74acabe + c531269 commit 702bd6d

33 files changed

+408
-432
lines changed

compiler/rustc_driver_impl/src/pretty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
336336
ThirTree => {
337337
let tcx = ex.tcx();
338338
let mut out = String::new();
339-
if rustc_hir_analysis::check_crate(tcx).is_err() {
339+
rustc_hir_analysis::check_crate(tcx);
340+
if tcx.dcx().has_errors().is_some() {
340341
FatalError.raise();
341342
}
342343
debug!("pretty printing THIR tree");
@@ -348,7 +349,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
348349
ThirFlat => {
349350
let tcx = ex.tcx();
350351
let mut out = String::new();
351-
if rustc_hir_analysis::check_crate(tcx).is_err() {
352+
rustc_hir_analysis::check_crate(tcx);
353+
if tcx.dcx().has_errors().is_some() {
352354
FatalError.raise();
353355
}
354356
debug!("pretty printing THIR flat");

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
66
use rustc_middle::hir::nested_filter;
77
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
8-
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
8+
use rustc_span::{sym, DUMMY_SP};
99

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

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

19-
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
18+
tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
2019
}
2120
}
2221
}
23-
res
2422
}
2523

2624
/// Checks "defining uses" of opaque `impl Trait` in associated types.

compiler/rustc_hir_analysis/src/lib.rs

+4-26
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ mod outlives;
9898
pub mod structured_errors;
9999
mod variance;
100100

101-
use rustc_errors::ErrorGuaranteed;
102101
use rustc_hir as hir;
103102
use rustc_middle::middle;
104103
use rustc_middle::query::Providers;
@@ -156,11 +155,13 @@ pub fn provide(providers: &mut Providers) {
156155
hir_wf_check::provide(providers);
157156
}
158157

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

162161
if tcx.features().rustc_attrs {
163-
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
162+
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
163+
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
164+
collect::test_opaque_hidden_types(tcx);
164165
}
165166

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

179-
if tcx.features().rustc_attrs {
180-
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
181-
}
182-
183-
if tcx.features().rustc_attrs {
184-
collect::test_opaque_hidden_types(tcx)?;
185-
}
186-
187180
// Make sure we evaluate all static and (non-associated) const items, even if unused.
188181
// If any of these fail to evaluate, we do not want this crate to pass compilation.
189182
tcx.hir().par_body_owners(|item_def_id| {
@@ -198,21 +191,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
198191
// Freeze definitions as we don't add new ones at this point. This improves performance by
199192
// allowing lock-free access to them.
200193
tcx.untracked().definitions.freeze();
201-
202-
// FIXME: Remove this when we implement creating `DefId`s
203-
// for anon constants during their parents' typeck.
204-
// Typeck all body owners in parallel will produce queries
205-
// cycle errors because it may typeck on anon constants directly.
206-
tcx.hir().par_body_owners(|item_def_id| {
207-
let def_kind = tcx.def_kind(item_def_id);
208-
if !matches!(def_kind, DefKind::AnonConst) {
209-
tcx.ensure().typeck(item_def_id);
210-
}
211-
});
212-
213-
tcx.ensure().check_unused_traits(());
214-
215-
Ok(())
216194
}
217195

218196
/// A quasi-deprecated helper used in rustdoc and clippy to get

compiler/rustc_hir_analysis/src/outlives/test.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use rustc_middle::ty::{self, TyCtxt};
2-
use rustc_span::{symbol::sym, ErrorGuaranteed};
2+
use rustc_span::symbol::sym;
33

4-
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
5-
let mut res = Ok(());
4+
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
65
for id in tcx.hir().items() {
76
// For unit testing: check for a special "rustc_outlives"
87
// attribute and report an error with various results if found.
@@ -23,8 +22,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
2322
for p in pred {
2423
err.note(p);
2524
}
26-
res = Err(err.emit());
25+
err.emit();
2726
}
2827
}
29-
res
3028
}

compiler/rustc_hir_analysis/src/variance/test.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ use rustc_hir::def::DefKind;
22
use rustc_hir::def_id::CRATE_DEF_ID;
33
use rustc_middle::ty::TyCtxt;
44
use rustc_span::symbol::sym;
5-
use rustc_span::ErrorGuaranteed;
65

76
use crate::errors;
87

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

16-
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
14+
tcx.dcx().emit_err(errors::VariancesOf {
1715
span: tcx.def_span(id.owner_id),
1816
variances_of: format!("{variances_of:?}"),
19-
}));
17+
});
2018
}
2119
}
2220
}
@@ -27,11 +25,10 @@ pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
2725
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
2826
let variances_of = tcx.variances_of(id.owner_id);
2927

30-
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
28+
tcx.dcx().emit_err(errors::VariancesOf {
3129
span: tcx.def_span(id.owner_id),
3230
variances_of: format!("{variances_of:?}"),
33-
}));
31+
});
3432
}
3533
}
36-
res
3734
}

compiler/rustc_interface/src/passes.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -734,19 +734,22 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
734734
});
735735

736736
// passes are timed inside typeck
737-
rustc_hir_analysis::check_crate(tcx)?;
737+
rustc_hir_analysis::check_crate(tcx);
738738

739-
sess.time("MIR_borrow_checking", || {
739+
sess.time("typeck_and_mir_analyses", || {
740740
tcx.hir().par_body_owners(|def_id| {
741+
let def_kind = tcx.def_kind(def_id);
742+
// FIXME: Remove this when we implement creating `DefId`s
743+
// for anon constants during their parents' typeck.
744+
// Typeck all body owners in parallel will produce queries
745+
// cycle errors because it may typeck on anon constants directly.
746+
if !matches!(def_kind, rustc_hir::def::DefKind::AnonConst) {
747+
tcx.ensure().typeck(def_id);
748+
}
741749
// Run unsafety check because it's responsible for stealing and
742750
// deallocating THIR.
743751
tcx.ensure().check_unsafety(def_id);
744-
tcx.ensure().mir_borrowck(def_id)
745-
});
746-
});
747-
748-
sess.time("MIR_effect_checking", || {
749-
for def_id in tcx.hir().body_owners() {
752+
tcx.ensure().mir_borrowck(def_id);
750753
if !tcx.sess.opts.unstable_opts.thir_unsafeck {
751754
rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id);
752755
}
@@ -761,16 +764,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
761764
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
762765
tcx.ensure().unused_generic_params(ty::InstanceDef::Item(def_id.to_def_id()));
763766
}
764-
}
765-
});
766767

767-
tcx.hir().par_body_owners(|def_id| {
768-
if tcx.is_coroutine(def_id.to_def_id()) {
769-
tcx.ensure().mir_coroutine_witnesses(def_id);
770-
tcx.ensure().check_coroutine_obligations(def_id);
771-
}
768+
if tcx.is_coroutine(def_id.to_def_id()) {
769+
tcx.ensure().mir_coroutine_witnesses(def_id);
770+
tcx.ensure().check_coroutine_obligations(def_id);
771+
}
772+
})
772773
});
773774

775+
tcx.ensure().check_unused_traits(());
776+
774777
sess.time("layout_testing", || layout_test::test_layout(tcx));
775778
sess.time("abi_testing", || abi_test::test_abi(tcx));
776779

tests/ui/binop/issue-77910-1.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
error[E0381]: used binding `xs` isn't initialized
2+
--> $DIR/issue-77910-1.rs:3:5
3+
|
4+
LL | let xs;
5+
| -- binding declared here but left uninitialized
6+
LL | xs
7+
| ^^ `xs` used here but it isn't initialized
8+
|
9+
help: consider assigning a value
10+
|
11+
LL | let xs = todo!();
12+
| +++++++++
13+
114
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
215
--> $DIR/issue-77910-1.rs:8:5
316
|
@@ -22,19 +35,6 @@ LL | assert_eq!(foo, y);
2235
= help: use parentheses to call this function: `foo(/* &i32 */)`
2336
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2437

25-
error[E0381]: used binding `xs` isn't initialized
26-
--> $DIR/issue-77910-1.rs:3:5
27-
|
28-
LL | let xs;
29-
| -- binding declared here but left uninitialized
30-
LL | xs
31-
| ^^ `xs` used here but it isn't initialized
32-
|
33-
help: consider assigning a value
34-
|
35-
LL | let xs = todo!();
36-
| +++++++++
37-
3838
error: aborting due to 3 previous errors
3939

4040
Some errors have detailed explanations: E0277, E0369, E0381.

tests/ui/binop/issue-77910-2.stderr

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
2-
--> $DIR/issue-77910-2.rs:7:12
3-
|
4-
LL | if foo == y {}
5-
| --- ^^ - _
6-
| |
7-
| for<'a> fn(&'a i32) -> &'a i32 {foo}
8-
|
9-
help: use parentheses to call this function
10-
|
11-
LL | if foo(/* &i32 */) == y {}
12-
| ++++++++++++
13-
141
error[E0381]: used binding `xs` isn't initialized
152
--> $DIR/issue-77910-2.rs:3:5
163
|
@@ -24,6 +11,19 @@ help: consider assigning a value
2411
LL | let xs = todo!();
2512
| +++++++++
2613

14+
error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
15+
--> $DIR/issue-77910-2.rs:7:12
16+
|
17+
LL | if foo == y {}
18+
| --- ^^ - _
19+
| |
20+
| for<'a> fn(&'a i32) -> &'a i32 {foo}
21+
|
22+
help: use parentheses to call this function
23+
|
24+
LL | if foo(/* &i32 */) == y {}
25+
| ++++++++++++
26+
2727
error: aborting due to 2 previous errors
2828

2929
Some errors have detailed explanations: E0369, E0381.

tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr

+23-23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ help: use `addr_of_mut!` instead to create a raw pointer
1313
LL | c1(addr_of_mut!(Y));
1414
| ~~~~~~~~~~~~~~~
1515

16+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
17+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
18+
|
19+
LL | pub fn e(x: &'static mut isize) {
20+
| - help: consider changing this to be mutable: `mut x`
21+
LL | static mut Y: isize = 3;
22+
LL | let mut c1 = |y: &'static mut isize| x = y;
23+
| ^^^^^ cannot assign
24+
1625
warning: creating a mutable reference to mutable static is discouraged
1726
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16
1827
|
@@ -27,29 +36,6 @@ help: use `addr_of_mut!` instead to create a raw pointer
2736
LL | c1(addr_of_mut!(Z));
2837
| ~~~~~~~~~~~~~~~
2938

30-
warning: creating a mutable reference to mutable static is discouraged
31-
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
32-
|
33-
LL | borrowck_closures_unique::e(&mut X);
34-
| ^^^^^^ mutable reference to mutable static
35-
|
36-
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
37-
= note: this will be a hard error in the 2024 edition
38-
= 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
39-
help: use `addr_of_mut!` instead to create a raw pointer
40-
|
41-
LL | borrowck_closures_unique::e(addr_of_mut!(X));
42-
| ~~~~~~~~~~~~~~~
43-
44-
error[E0594]: cannot assign to `x`, as it is not declared as mutable
45-
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
46-
|
47-
LL | pub fn e(x: &'static mut isize) {
48-
| - help: consider changing this to be mutable: `mut x`
49-
LL | static mut Y: isize = 3;
50-
LL | let mut c1 = |y: &'static mut isize| x = y;
51-
| ^^^^^ cannot assign
52-
5339
error[E0594]: cannot assign to `x`, as it is not declared as mutable
5440
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50
5541
|
@@ -95,6 +81,20 @@ LL | || {
9581
LL | &mut x.0;
9682
| ^^^^^^^^ cannot borrow as mutable
9783

84+
warning: creating a mutable reference to mutable static is discouraged
85+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
86+
|
87+
LL | borrowck_closures_unique::e(&mut X);
88+
| ^^^^^^ mutable reference to mutable static
89+
|
90+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
91+
= note: this will be a hard error in the 2024 edition
92+
= 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
93+
help: use `addr_of_mut!` instead to create a raw pointer
94+
|
95+
LL | borrowck_closures_unique::e(addr_of_mut!(X));
96+
| ~~~~~~~~~~~~~~~
97+
9898
error: aborting due to 6 previous errors; 3 warnings emitted
9999

100100
Some errors have detailed explanations: E0594, E0596.

tests/ui/const-generics/generic_const_exprs/type_mismatch.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ LL | impl<const N: u64> Q for [u8; N] {}
2121
| |
2222
| unsatisfied trait bound introduced here
2323

24+
error[E0308]: mismatched types
25+
--> $DIR/type_mismatch.rs:8:31
26+
|
27+
LL | impl<const N: u64> Q for [u8; N] {}
28+
| ^ expected `usize`, found `u64`
29+
2430
error[E0308]: mismatched types
2531
--> $DIR/type_mismatch.rs:12:20
2632
|
@@ -29,12 +35,6 @@ LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
2935
| |
3036
| implicitly returns `()` as its body has no tail or `return` expression
3137

32-
error[E0308]: mismatched types
33-
--> $DIR/type_mismatch.rs:8:31
34-
|
35-
LL | impl<const N: u64> Q for [u8; N] {}
36-
| ^ expected `usize`, found `u64`
37-
3838
error: aborting due to 4 previous errors
3939

4040
Some errors have detailed explanations: E0046, E0308.

0 commit comments

Comments
 (0)