typeck in parallel

This commit is contained in:
SparrowLii 2023-07-11 17:24:59 +08:00
parent 5b733e2bca
commit 50896c13db
11 changed files with 47 additions and 29 deletions

View file

@ -7,6 +7,10 @@ use rustc_session::lint;
pub fn check_crate(tcx: TyCtxt<'_>) { pub fn check_crate(tcx: TyCtxt<'_>) {
let mut used_trait_imports: UnordSet<LocalDefId> = Default::default(); let mut used_trait_imports: UnordSet<LocalDefId> = Default::default();
// FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s
// for anon constants during their parents' typeck.
// Doing so at current will produce queries cycle errors because it may typeck
// on anon constants directly.
for item_def_id in tcx.hir().body_owners() { for item_def_id in tcx.hir().body_owners() {
let imports = tcx.used_trait_imports(item_def_id); let imports = tcx.used_trait_imports(item_def_id);
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);

View file

@ -116,6 +116,7 @@ use std::ops::Not;
use astconv::{AstConv, OnlySelfBounds}; use astconv::{AstConv, OnlySelfBounds};
use bounds::Bounds; use bounds::Bounds;
use rustc_hir::def::DefKind;
fluent_messages! { "../messages.ftl" } fluent_messages! { "../messages.ftl" }
@ -500,6 +501,17 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module)) tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
}); });
// 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);
}
});
check_unused::check_crate(tcx); check_unused::check_crate(tcx);
check_for_entry_fn(tcx); check_for_entry_fn(tcx);

View file

@ -28,8 +28,8 @@ echo "rustc_query_count_full: $rustc_query_count_full"
## and marks are in pairs. ## and marks are in pairs.
if [ $short -lt $full ] && if [ $short -lt $full ] &&
[ $begin_count -eq $end_count ] && [ $begin_count -eq $end_count ] &&
[ $(($rustc_query_count + 10)) -lt $rustc_query_count_full ] && [ $(($rustc_query_count + 5)) -lt $rustc_query_count_full ] &&
[ $rustc_query_count_full -gt 10 ]; then [ $rustc_query_count_full -gt 5 ]; then
exit 0 exit 0
else else
exit 1 exit 1

View file

@ -6,8 +6,7 @@ error: query stack during panic:
#4 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}` #4 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}`
#5 [eval_to_valtree] evaluating type-level constant #5 [eval_to_valtree] evaluating type-level constant
#6 [typeck] type-checking `test` #6 [typeck] type-checking `test`
#7 [used_trait_imports] finding used_trait_imports `test` #7 [analysis] running analysis passes on this crate
#8 [analysis] running analysis passes on this crate
end of query stack end of query stack
error: aborting due to previous error error: aborting due to previous error

View file

@ -6,8 +6,7 @@ error: query stack during panic:
#4 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#1}` #4 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#1}`
#5 [eval_to_valtree] evaluating type-level constant #5 [eval_to_valtree] evaluating type-level constant
#6 [typeck] type-checking `test` #6 [typeck] type-checking `test`
#7 [used_trait_imports] finding used_trait_imports `test` #7 [analysis] running analysis passes on this crate
#8 [analysis] running analysis passes on this crate
end of query stack end of query stack
error: aborting due to previous error error: aborting due to previous error

View file

@ -16,18 +16,6 @@ LL | std::mem::transmute(v)
= note: source type: `[[u32; H]; W]` (this type does not have a fixed size) = 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]) = 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 error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:23:5 --> $DIR/transmute-fail.rs:23:5
| |
@ -46,6 +34,18 @@ 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: 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) = 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 error: aborting due to 6 previous errors
Some errors have detailed explanations: E0308, E0512. Some errors have detailed explanations: E0308, E0512.

View file

@ -10,12 +10,6 @@ note: required by a bound in `bar`
LL | fn bar<const N: u8>() -> [u8; N] {} LL | fn bar<const N: u8>() -> [u8; N] {}
| ^^^^^^^^^^^ required by this bound in `bar` | ^^^^^^^^^^^ 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 error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:6:26 --> $DIR/type_mismatch.rs:6:26
| |
@ -24,6 +18,12 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
| | | |
| implicitly returns `()` as its body has no tail or `return` expression | 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 error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:6:31 --> $DIR/type_mismatch.rs:6:31
| |

View file

@ -1,3 +1,5 @@
// compile-flags: -Zdeduplicate-diagnostics=yes
#![feature(start, no_core)] #![feature(start, no_core)]
#![no_core] // makes debugging this test *a lot* easier (during resolve) #![no_core] // makes debugging this test *a lot* easier (during resolve)

View file

@ -1,22 +1,22 @@
error[E0432]: unresolved import `bar::foo` error[E0432]: unresolved import `bar::foo`
--> $DIR/privacy2.rs:17:9 --> $DIR/privacy2.rs:19:9
| |
LL | use bar::foo; LL | use bar::foo;
| ^^^^^^^^ no `foo` in `bar` | ^^^^^^^^ no `foo` in `bar`
error[E0603]: function import `foo` is private error[E0603]: function import `foo` is private
--> $DIR/privacy2.rs:23:20 --> $DIR/privacy2.rs:25:20
| |
LL | use bar::glob::foo; LL | use bar::glob::foo;
| ^^^ private function import | ^^^ private function import
| |
note: the function import `foo` is defined here... note: the function import `foo` is defined here...
--> $DIR/privacy2.rs:10:13 --> $DIR/privacy2.rs:12:13
| |
LL | use foo; LL | use foo;
| ^^^ | ^^^
note: ...and refers to the function `foo` which is defined here note: ...and refers to the function `foo` which is defined here
--> $DIR/privacy2.rs:14:1 --> $DIR/privacy2.rs:16:1
| |
LL | pub fn foo() {} LL | pub fn foo() {}
| ^^^^^^^^^^^^ consider importing it directly | ^^^^^^^^^^^^ consider importing it directly

View file

@ -1,3 +1,5 @@
// compile-flags: -Zdeduplicate-diagnostics=yes
#![feature(start, no_core)] #![feature(start, no_core)]
#![no_core] // makes debugging this test *a lot* easier (during resolve) #![no_core] // makes debugging this test *a lot* easier (during resolve)

View file

@ -1,5 +1,5 @@
error[E0432]: unresolved import `bar::gpriv` error[E0432]: unresolved import `bar::gpriv`
--> $DIR/privacy3.rs:18:9 --> $DIR/privacy3.rs:20:9
| |
LL | use bar::gpriv; LL | use bar::gpriv;
| ^^^^^^^^^^ no `gpriv` in `bar` | ^^^^^^^^^^ no `gpriv` in `bar`