Skip to content

Commit 55ea944

Browse files
committed
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).
1 parent e2e751e commit 55ea944

24 files changed

+265
-275
lines changed

compiler/rustc_hir_analysis/src/lib.rs

-13
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
191191
// Freeze definitions as we don't add new ones at this point. This improves performance by
192192
// allowing lock-free access to them.
193193
tcx.untracked().definitions.freeze();
194-
195-
// FIXME: Remove this when we implement creating `DefId`s
196-
// for anon constants during their parents' typeck.
197-
// Typeck all body owners in parallel will produce queries
198-
// cycle errors because it may typeck on anon constants directly.
199-
tcx.hir().par_body_owners(|item_def_id| {
200-
let def_kind = tcx.def_kind(item_def_id);
201-
if !matches!(def_kind, DefKind::AnonConst) {
202-
tcx.ensure().typeck(item_def_id);
203-
}
204-
});
205-
206-
tcx.ensure().check_unused_traits(());
207194
}
208195

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

compiler/rustc_interface/src/passes.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
736736
// passes are timed inside typeck
737737
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.

tests/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ LL + #[derive(ConstParamTy)]
3434
LL | struct Foo(u8);
3535
|
3636

37-
error: unconstrained generic constant
38-
--> $DIR/unify-op-with-fn-call.rs:30:12
39-
|
40-
LL | bar2::<{ std::ops::Add::add(N, N) }>();
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`
44-
4537
error[E0015]: cannot call non-const operator in constants
4638
--> $DIR/unify-op-with-fn-call.rs:20:39
4739
|
@@ -65,6 +57,14 @@ LL | bar::<{ std::ops::Add::add(N, N) }>();
6557
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
6658
= help: add `#![feature(effects)]` to the crate attributes to enable
6759

60+
error: unconstrained generic constant
61+
--> $DIR/unify-op-with-fn-call.rs:30:12
62+
|
63+
LL | bar2::<{ std::ops::Add::add(N, N) }>();
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
65+
|
66+
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`
67+
6868
error[E0015]: cannot call non-const fn `<usize as Add>::add` in constants
6969
--> $DIR/unify-op-with-fn-call.rs:30:14
7070
|

tests/ui/const-generics/transmute-fail.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ LL | std::mem::transmute(v)
1616
= note: source type: `[[u32; H]; W]` (this type does not have a fixed size)
1717
= note: target type: `[[u32; W]; H]` (size can vary because of [u32; W])
1818

19+
error[E0308]: mismatched types
20+
--> $DIR/transmute-fail.rs:12:53
21+
|
22+
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
23+
| ^ expected `usize`, found `bool`
24+
25+
error[E0308]: mismatched types
26+
--> $DIR/transmute-fail.rs:12:67
27+
|
28+
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
29+
| ^ expected `usize`, found `bool`
30+
1931
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2032
--> $DIR/transmute-fail.rs:23:5
2133
|
@@ -34,18 +46,6 @@ LL | std::mem::transmute(v)
3446
= note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture)
3547
= note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture)
3648

37-
error[E0308]: mismatched types
38-
--> $DIR/transmute-fail.rs:12:53
39-
|
40-
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
41-
| ^ expected `usize`, found `bool`
42-
43-
error[E0308]: mismatched types
44-
--> $DIR/transmute-fail.rs:12:67
45-
|
46-
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
47-
| ^ expected `usize`, found `bool`
48-
4949
error: aborting due to 6 previous errors
5050

5151
Some errors have detailed explanations: E0308, E0512.

tests/ui/const-generics/type_mismatch.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ note: required by a bound in `bar`
1010
LL | fn bar<const N: u8>() -> [u8; N] {}
1111
| ^^^^^^^^^^^ required by this bound in `bar`
1212

13+
error[E0308]: mismatched types
14+
--> $DIR/type_mismatch.rs:2:11
15+
|
16+
LL | bar::<N>()
17+
| ^ expected `u8`, found `usize`
18+
1319
error[E0308]: mismatched types
1420
--> $DIR/type_mismatch.rs:6:26
1521
|
@@ -18,12 +24,6 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
1824
| |
1925
| implicitly returns `()` as its body has no tail or `return` expression
2026

21-
error[E0308]: mismatched types
22-
--> $DIR/type_mismatch.rs:2:11
23-
|
24-
LL | bar::<N>()
25-
| ^ expected `u8`, found `usize`
26-
2727
error[E0308]: mismatched types
2828
--> $DIR/type_mismatch.rs:6:31
2929
|

tests/ui/explicit-tail-calls/return-mismatches.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ LL | become _g1();
1616
= note: expected unit type `()`
1717
found type `!`
1818

19-
error[E0308]: mismatched types
20-
--> $DIR/return-mismatches.rs:21:5
21-
|
22-
LL | become _g2();
23-
| ^^^^^^^^^^^^ expected `u32`, found `u16`
24-
2519
warning: function cannot return without recursing
2620
--> $DIR/return-mismatches.rs:16:1
2721
|
@@ -33,6 +27,12 @@ LL | become _g1();
3327
= help: a `loop` may express intention better if this is on purpose
3428
= note: `#[warn(unconditional_recursion)]` on by default
3529

30+
error[E0308]: mismatched types
31+
--> $DIR/return-mismatches.rs:21:5
32+
|
33+
LL | become _g2();
34+
| ^^^^^^^^^^^^ expected `u32`, found `u16`
35+
3636
error: aborting due to 3 previous errors; 1 warning emitted
3737

3838
For more information about this error, try `rustc --explain E0308`.

tests/ui/expr/if/if-no-match-bindings.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
error[E0515]: cannot return reference to temporary value
2+
--> $DIR/if-no-match-bindings.rs:8:38
3+
|
4+
LL | fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
5+
| ^^^^^----
6+
| | |
7+
| | temporary value created here
8+
| returns a reference to data owned by the current function
9+
110
error[E0308]: mismatched types
211
--> $DIR/if-no-match-bindings.rs:19:8
312
|
@@ -90,15 +99,6 @@ LL - while &mut true {}
9099
LL + while true {}
91100
|
92101

93-
error[E0515]: cannot return reference to temporary value
94-
--> $DIR/if-no-match-bindings.rs:8:38
95-
|
96-
LL | fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
97-
| ^^^^^----
98-
| | |
99-
| | temporary value created here
100-
| returns a reference to data owned by the current function
101-
102102
error: aborting due to 9 previous errors
103103

104104
Some errors have detailed explanations: E0308, E0515.

0 commit comments

Comments
 (0)