Skip to content

Commit 7d60819

Browse files
committed
Auto merge of rust-lang#113519 - SparrowLii:parallel_typeck, r=cjgillot
typeck in parallel rust-lang#108118 caused `typeck` to be transferred to the serial part (`check_unused`), which made the performance of parallel rustc significantly reduced. This pr re-parallelize this part, which increases the average performance improvement of parallel rustc in `full` and `incr-full` scenarios from [14.4%](rust-lang#110284 (comment)) to [23.2%](rust-lang#110284 (comment)). r? `@cjgillot` cc `@oli-obk` `@Zoxc`
2 parents cca3373 + 50896c1 commit 7d60819

File tree

11 files changed

+47
-29
lines changed

11 files changed

+47
-29
lines changed

compiler/rustc_hir_analysis/src/check_unused.rs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use rustc_session::lint;
77
pub fn check_crate(tcx: TyCtxt<'_>) {
88
let mut used_trait_imports: UnordSet<LocalDefId> = Default::default();
99

10+
// FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s
11+
// for anon constants during their parents' typeck.
12+
// Doing so at current will produce queries cycle errors because it may typeck
13+
// on anon constants directly.
1014
for item_def_id in tcx.hir().body_owners() {
1115
let imports = tcx.used_trait_imports(item_def_id);
1216
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);

compiler/rustc_hir_analysis/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ use std::ops::Not;
116116

117117
use astconv::{AstConv, OnlySelfBounds};
118118
use bounds::Bounds;
119+
use rustc_hir::def::DefKind;
119120

120121
fluent_messages! { "../messages.ftl" }
121122

@@ -500,6 +501,17 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
500501
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
501502
});
502503

504+
// FIXME: Remove this when we implement creating `DefId`s
505+
// for anon constants during their parents' typeck.
506+
// Typeck all body owners in parallel will produce queries
507+
// cycle errors because it may typeck on anon constants directly.
508+
tcx.hir().par_body_owners(|item_def_id| {
509+
let def_kind = tcx.def_kind(item_def_id);
510+
if !matches!(def_kind, DefKind::AnonConst) {
511+
tcx.ensure().typeck(item_def_id);
512+
}
513+
});
514+
503515
check_unused::check_crate(tcx);
504516
check_for_entry_fn(tcx);
505517

tests/run-make/short-ice/check.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ echo "rustc_query_count_full: $rustc_query_count_full"
2828
## and marks are in pairs.
2929
if [ $short -lt $full ] &&
3030
[ $begin_count -eq $end_count ] &&
31-
[ $(($rustc_query_count + 10)) -lt $rustc_query_count_full ] &&
32-
[ $rustc_query_count_full -gt 10 ]; then
31+
[ $(($rustc_query_count + 5)) -lt $rustc_query_count_full ] &&
32+
[ $rustc_query_count_full -gt 5 ]; then
3333
exit 0
3434
else
3535
exit 1

tests/ui/const-generics/late-bound-vars/in_closure.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ error: query stack during panic:
66
#4 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}`
77
#5 [eval_to_valtree] evaluating type-level constant
88
#6 [typeck] type-checking `test`
9-
#7 [used_trait_imports] finding used_trait_imports `test`
10-
#8 [analysis] running analysis passes on this crate
9+
#7 [analysis] running analysis passes on this crate
1110
end of query stack
1211
error: aborting due to previous error
1312

tests/ui/const-generics/late-bound-vars/simple.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ error: query stack during panic:
66
#4 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#1}`
77
#5 [eval_to_valtree] evaluating type-level constant
88
#6 [typeck] type-checking `test`
9-
#7 [used_trait_imports] finding used_trait_imports `test`
10-
#8 [analysis] running analysis passes on this crate
9+
#7 [analysis] running analysis passes on this crate
1110
end of query stack
1211
error: aborting due to previous error
1312

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ 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-
3119
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
3220
--> $DIR/transmute-fail.rs:23:5
3321
|
@@ -46,6 +34,18 @@ LL | std::mem::transmute(v)
4634
= note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture)
4735
= note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture)
4836

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,12 +10,6 @@ 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-
1913
error[E0308]: mismatched types
2014
--> $DIR/type_mismatch.rs:6:26
2115
|
@@ -24,6 +18,12 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
2418
| |
2519
| implicitly returns `()` as its body has no tail or `return` expression
2620

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/privacy/privacy2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Zdeduplicate-diagnostics=yes
2+
13
#![feature(start, no_core)]
24
#![no_core] // makes debugging this test *a lot* easier (during resolve)
35

tests/ui/privacy/privacy2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error[E0432]: unresolved import `bar::foo`
2-
--> $DIR/privacy2.rs:17:9
2+
--> $DIR/privacy2.rs:19:9
33
|
44
LL | use bar::foo;
55
| ^^^^^^^^ no `foo` in `bar`
66

77
error[E0603]: function import `foo` is private
8-
--> $DIR/privacy2.rs:23:20
8+
--> $DIR/privacy2.rs:25:20
99
|
1010
LL | use bar::glob::foo;
1111
| ^^^ private function import
1212
|
1313
note: the function import `foo` is defined here...
14-
--> $DIR/privacy2.rs:10:13
14+
--> $DIR/privacy2.rs:12:13
1515
|
1616
LL | use foo;
1717
| ^^^
1818
note: ...and refers to the function `foo` which is defined here
19-
--> $DIR/privacy2.rs:14:1
19+
--> $DIR/privacy2.rs:16:1
2020
|
2121
LL | pub fn foo() {}
2222
| ^^^^^^^^^^^^ consider importing it directly

tests/ui/privacy/privacy3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Zdeduplicate-diagnostics=yes
2+
13
#![feature(start, no_core)]
24
#![no_core] // makes debugging this test *a lot* easier (during resolve)
35

tests/ui/privacy/privacy3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0432]: unresolved import `bar::gpriv`
2-
--> $DIR/privacy3.rs:18:9
2+
--> $DIR/privacy3.rs:20:9
33
|
44
LL | use bar::gpriv;
55
| ^^^^^^^^^^ no `gpriv` in `bar`

0 commit comments

Comments
 (0)