about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSparrowLii <liyuan179@huawei.com>2023-07-11 17:24:59 +0800
committerSparrowLii <liyuan179@huawei.com>2023-07-11 17:52:43 +0800
commit50896c13db5e1efb3879f3721cae77eb247b9e6f (patch)
treedff537bd4dfea9f9d9c8ffba1421caf84847ef0e
parent5b733e2bcaf784e6a8c523a6d5e74d7263ec7915 (diff)
downloadrust-50896c13db5e1efb3879f3721cae77eb247b9e6f.tar.gz
rust-50896c13db5e1efb3879f3721cae77eb247b9e6f.zip
typeck in parallel
-rw-r--r--compiler/rustc_hir_analysis/src/check_unused.rs4
-rw-r--r--compiler/rustc_hir_analysis/src/lib.rs12
-rw-r--r--tests/run-make/short-ice/check.sh4
-rw-r--r--tests/ui/const-generics/late-bound-vars/in_closure.stderr3
-rw-r--r--tests/ui/const-generics/late-bound-vars/simple.stderr3
-rw-r--r--tests/ui/const-generics/transmute-fail.stderr24
-rw-r--r--tests/ui/const-generics/type_mismatch.stderr12
-rw-r--r--tests/ui/privacy/privacy2.rs2
-rw-r--r--tests/ui/privacy/privacy2.stderr8
-rw-r--r--tests/ui/privacy/privacy3.rs2
-rw-r--r--tests/ui/privacy/privacy3.stderr2
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 268b9ac530f..3471d5f1e77 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<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() {
         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 a68832d96a6..8312ec74c43 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 96cd8fe86bc..a13b7eeca8f 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 557fbea2e05..9dc5ea1f16a 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 c0568f5a5cf..c9f2164b635 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 9e308620a9c..12644b9f36d 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<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
    |
@@ -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<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.
diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr
index 394dd44d40d..07476ae76c6 100644
--- a/tests/ui/const-generics/type_mismatch.stderr
+++ b/tests/ui/const-generics/type_mismatch.stderr
@@ -11,12 +11,6 @@ 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
    |
 LL | fn bar<const N: u8>() -> [u8; N] {}
@@ -25,6 +19,12 @@ 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
    |
 LL | fn bar<const N: u8>() -> [u8; N] {}
diff --git a/tests/ui/privacy/privacy2.rs b/tests/ui/privacy/privacy2.rs
index c8fa436bd14..212bc003e07 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 c2a33ce1f59..e7135d3fd8a 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 5a7cd76a98f..3466f5bb1d2 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 22c1e48b07d..df66c84751b 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`