Skip to content

Commit

Permalink
Run a single huge par_body_owners instead of many small ones after …
Browse files Browse the repository at this point in the history
…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
oli-obk committed Mar 11, 2024
1 parent e2e751e commit 55ea944
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 275 deletions.
13 changes: 0 additions & 13 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
// 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(());
}

/// A quasi-deprecated helper used in rustdoc and clippy to get
Expand Down
31 changes: 17 additions & 14 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,20 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
// passes are timed inside typeck
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ LL + #[derive(ConstParamTy)]
LL | struct Foo(u8);
|

error: unconstrained generic constant
--> $DIR/unify-op-with-fn-call.rs:30:12
|
LL | bar2::<{ std::ops::Add::add(N, N) }>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`

error[E0015]: cannot call non-const operator in constants
--> $DIR/unify-op-with-fn-call.rs:20:39
|
Expand All @@ -65,6 +57,14 @@ LL | bar::<{ std::ops::Add::add(N, N) }>();
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(effects)]` to the crate attributes to enable

error: unconstrained generic constant
--> $DIR/unify-op-with-fn-call.rs:30:12
|
LL | bar2::<{ std::ops::Add::add(N, N) }>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`

error[E0015]: cannot call non-const fn `<usize as Add>::add` in constants
--> $DIR/unify-op-with-fn-call.rs:30:14
|
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/const-generics/transmute-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ LL | std::mem::transmute(v)
= note: source type: `[[u32; H]; W]` (this type does not have a fixed size)
= note: target type: `[[u32; W]; H]` (size can vary because of [u32; W])

error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:53
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`

error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:67
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:23:5
|
Expand All @@ -34,18 +46,6 @@ LL | std::mem::transmute(v)
= note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture)
= note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture)

error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:53
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`

error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:67
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0308, E0512.
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/const-generics/type_mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ note: required by a bound in `bar`
LL | fn bar<const N: u8>() -> [u8; N] {}
| ^^^^^^^^^^^ required by this bound in `bar`

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:2:11
|
LL | bar::<N>()
| ^ expected `u8`, found `usize`

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:6:26
|
Expand All @@ -18,12 +24,6 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
| |
| implicitly returns `()` as its body has no tail or `return` expression

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:2:11
|
LL | bar::<N>()
| ^ expected `u8`, found `usize`

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:6:31
|
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/explicit-tail-calls/return-mismatches.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ LL | become _g1();
= note: expected unit type `()`
found type `!`

error[E0308]: mismatched types
--> $DIR/return-mismatches.rs:21:5
|
LL | become _g2();
| ^^^^^^^^^^^^ expected `u32`, found `u16`

warning: function cannot return without recursing
--> $DIR/return-mismatches.rs:16:1
|
Expand All @@ -33,6 +27,12 @@ LL | become _g1();
= help: a `loop` may express intention better if this is on purpose
= note: `#[warn(unconditional_recursion)]` on by default

error[E0308]: mismatched types
--> $DIR/return-mismatches.rs:21:5
|
LL | become _g2();
| ^^^^^^^^^^^^ expected `u32`, found `u16`

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.
18 changes: 9 additions & 9 deletions tests/ui/expr/if/if-no-match-bindings.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
error[E0515]: cannot return reference to temporary value
--> $DIR/if-no-match-bindings.rs:8:38
|
LL | fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
| ^^^^^----
| | |
| | temporary value created here
| returns a reference to data owned by the current function

error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:19:8
|
Expand Down Expand Up @@ -90,15 +99,6 @@ LL - while &mut true {}
LL + while true {}
|

error[E0515]: cannot return reference to temporary value
--> $DIR/if-no-match-bindings.rs:8:38
|
LL | fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
| ^^^^^----
| | |
| | temporary value created here
| returns a reference to data owned by the current function

error: aborting due to 9 previous errors

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

0 comments on commit 55ea944

Please sign in to comment.