From 50896c13db5e1efb3879f3721cae77eb247b9e6f Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Tue, 11 Jul 2023 17:24:59 +0800 Subject: [PATCH] typeck in parallel --- .../rustc_hir_analysis/src/check_unused.rs | 4 ++++ compiler/rustc_hir_analysis/src/lib.rs | 12 ++++++++++ tests/run-make/short-ice/check.sh | 4 ++-- .../late-bound-vars/in_closure.stderr | 3 +-- .../late-bound-vars/simple.stderr | 3 +-- tests/ui/const-generics/transmute-fail.stderr | 24 +++++++++---------- tests/ui/const-generics/type_mismatch.stderr | 12 +++++----- tests/ui/privacy/privacy2.rs | 2 ++ tests/ui/privacy/privacy2.stderr | 8 +++---- tests/ui/privacy/privacy3.rs | 2 ++ tests/ui/privacy/privacy3.stderr | 2 +- 11 files changed, 47 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check_unused.rs b/compiler/rustc_hir_analysis/src/check_unused.rs index 268b9ac530f18..3471d5f1e7724 100644 --- a/compiler/rustc_hir_analysis/src/check_unused.rs +++ b/compiler/rustc_hir_analysis/src/check_unused.rs @@ -7,6 +7,10 @@ use rustc_session::lint; pub fn check_crate(tcx: TyCtxt<'_>) { let mut used_trait_imports: UnordSet = 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() { let imports = tcx.used_trait_imports(item_def_id); debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index a68832d96a654..8312ec74c437c 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -116,6 +116,7 @@ use std::ops::Not; use astconv::{AstConv, OnlySelfBounds}; use bounds::Bounds; +use rustc_hir::def::DefKind; 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)) }); + // 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_for_entry_fn(tcx); diff --git a/tests/run-make/short-ice/check.sh b/tests/run-make/short-ice/check.sh index 96cd8fe86bc30..a13b7eeca8f35 100644 --- a/tests/run-make/short-ice/check.sh +++ b/tests/run-make/short-ice/check.sh @@ -28,8 +28,8 @@ echo "rustc_query_count_full: $rustc_query_count_full" ## and marks are in pairs. if [ $short -lt $full ] && [ $begin_count -eq $end_count ] && - [ $(($rustc_query_count + 10)) -lt $rustc_query_count_full ] && - [ $rustc_query_count_full -gt 10 ]; then + [ $(($rustc_query_count + 5)) -lt $rustc_query_count_full ] && + [ $rustc_query_count_full -gt 5 ]; then exit 0 else exit 1 diff --git a/tests/ui/const-generics/late-bound-vars/in_closure.stderr b/tests/ui/const-generics/late-bound-vars/in_closure.stderr index 557fbea2e056e..9dc5ea1f16a5e 100644 --- a/tests/ui/const-generics/late-bound-vars/in_closure.stderr +++ b/tests/ui/const-generics/late-bound-vars/in_closure.stderr @@ -6,8 +6,7 @@ error: query stack during panic: #4 [eval_to_allocation_raw] const-evaluating + checking `test::{closure#0}::{constant#1}` #5 [eval_to_valtree] evaluating type-level constant #6 [typeck] type-checking `test` -#7 [used_trait_imports] finding used_trait_imports `test` -#8 [analysis] running analysis passes on this crate +#7 [analysis] running analysis passes on this crate end of query stack error: aborting due to previous error diff --git a/tests/ui/const-generics/late-bound-vars/simple.stderr b/tests/ui/const-generics/late-bound-vars/simple.stderr index c0568f5a5cfa3..c9f2164b63519 100644 --- a/tests/ui/const-generics/late-bound-vars/simple.stderr +++ b/tests/ui/const-generics/late-bound-vars/simple.stderr @@ -6,8 +6,7 @@ error: query stack during panic: #4 [eval_to_allocation_raw] const-evaluating + checking `test::{constant#1}` #5 [eval_to_valtree] evaluating type-level constant #6 [typeck] type-checking `test` -#7 [used_trait_imports] finding used_trait_imports `test` -#8 [analysis] running analysis passes on this crate +#7 [analysis] running analysis passes on this crate end of query stack error: aborting due to previous error diff --git a/tests/ui/const-generics/transmute-fail.stderr b/tests/ui/const-generics/transmute-fail.stderr index 9e308620a9c2e..12644b9f36d00 100644 --- a/tests/ui/const-generics/transmute-fail.stderr +++ b/tests/ui/const-generics/transmute-fail.stderr @@ -16,18 +16,6 @@ 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(v: [[u32; H]; W]) -> [[u32; W]; H] { - | ^ expected `usize`, found `bool` - -error[E0308]: mismatched types - --> $DIR/transmute-fail.rs:12:67 - | -LL | fn bar(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 | @@ -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: 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(v: [[u32; H]; W]) -> [[u32; W]; H] { + | ^ expected `usize`, found `bool` + +error[E0308]: mismatched types + --> $DIR/transmute-fail.rs:12:67 + | +LL | fn bar(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. diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr index 394dd44d40d33..07476ae76c65e 100644 --- a/tests/ui/const-generics/type_mismatch.stderr +++ b/tests/ui/const-generics/type_mismatch.stderr @@ -10,12 +10,6 @@ note: required by a bound in `bar` LL | fn bar() -> [u8; N] {} | ^^^^^^^^^^^ required by this bound in `bar` -error[E0308]: mismatched types - --> $DIR/type_mismatch.rs:2:11 - | -LL | bar::() - | ^ expected `u8`, found `usize` - error[E0308]: mismatched types --> $DIR/type_mismatch.rs:6:26 | @@ -24,6 +18,12 @@ LL | fn bar() -> [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::() + | ^ expected `u8`, found `usize` + error[E0308]: mismatched types --> $DIR/type_mismatch.rs:6:31 | diff --git a/tests/ui/privacy/privacy2.rs b/tests/ui/privacy/privacy2.rs index c8fa436bd14fc..212bc003e075c 100644 --- a/tests/ui/privacy/privacy2.rs +++ b/tests/ui/privacy/privacy2.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zdeduplicate-diagnostics=yes + #![feature(start, no_core)] #![no_core] // makes debugging this test *a lot* easier (during resolve) diff --git a/tests/ui/privacy/privacy2.stderr b/tests/ui/privacy/privacy2.stderr index c2a33ce1f59b3..e7135d3fd8a61 100644 --- a/tests/ui/privacy/privacy2.stderr +++ b/tests/ui/privacy/privacy2.stderr @@ -1,22 +1,22 @@ error[E0432]: unresolved import `bar::foo` - --> $DIR/privacy2.rs:17:9 + --> $DIR/privacy2.rs:19:9 | LL | use bar::foo; | ^^^^^^^^ no `foo` in `bar` error[E0603]: function import `foo` is private - --> $DIR/privacy2.rs:23:20 + --> $DIR/privacy2.rs:25:20 | LL | use bar::glob::foo; | ^^^ private function import | note: the function import `foo` is defined here... - --> $DIR/privacy2.rs:10:13 + --> $DIR/privacy2.rs:12:13 | LL | use foo; | ^^^ 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() {} | ^^^^^^^^^^^^ consider importing it directly diff --git a/tests/ui/privacy/privacy3.rs b/tests/ui/privacy/privacy3.rs index 5a7cd76a98f6e..3466f5bb1d207 100644 --- a/tests/ui/privacy/privacy3.rs +++ b/tests/ui/privacy/privacy3.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zdeduplicate-diagnostics=yes + #![feature(start, no_core)] #![no_core] // makes debugging this test *a lot* easier (during resolve) diff --git a/tests/ui/privacy/privacy3.stderr b/tests/ui/privacy/privacy3.stderr index 22c1e48b07d94..df66c84751b74 100644 --- a/tests/ui/privacy/privacy3.stderr +++ b/tests/ui/privacy/privacy3.stderr @@ -1,5 +1,5 @@ error[E0432]: unresolved import `bar::gpriv` - --> $DIR/privacy3.rs:18:9 + --> $DIR/privacy3.rs:20:9 | LL | use bar::gpriv; | ^^^^^^^^^^ no `gpriv` in `bar`