Rollup merge of #99457 - SparrowLii:para_iter, r=fee1-dead

use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`

Using `par_iter` in non-parallel mode will cause the entire process to abort when any iteration panics.  So we can use `par_for_each_in` instead to make the error message consistent with parallel mode. This means that the compiler will output more error messages in some cases. This fixes the following ui tests when set `parallel-compiler = true`:
```
    [ui] src/test\ui\privacy\privacy2.rs
    [ui] src/test\ui\privacy\privacy3.rs
    [ui] src/test\ui\type_length_limit.rs
```

This refers to #68171

Updates #75760
This commit is contained in:
Matthias Krüger 2022-07-19 13:30:52 +02:00 committed by GitHub
commit e6904fc5b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 9 deletions

View File

@ -146,7 +146,7 @@ cfg_if! {
t.into_iter() t.into_iter()
} }
pub fn par_for_each_in<T: IntoIterator>(t: T, for_each: impl Fn(T::Item) + Sync + Send) { pub fn par_for_each_in<T: IntoIterator>(t: T, mut for_each: impl FnMut(T::Item) + Sync + Send) {
// We catch panics here ensuring that all the loop iterations execute. // We catch panics here ensuring that all the loop iterations execute.
// This makes behavior consistent with the parallel compiler. // This makes behavior consistent with the parallel compiler.
let mut panic = None; let mut panic = None;

View File

@ -491,9 +491,7 @@ impl<'hir> Map<'hir> {
} }
pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) { pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
use rustc_data_structures::sync::{par_iter, ParallelIterator}; par_for_each_in(&self.tcx.hir_crate_items(()).body_owners[..], |&def_id| f(def_id));
par_iter(&self.tcx.hir_crate_items(()).body_owners[..]).for_each(|&def_id| f(def_id));
} }
pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId { pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {

View File

@ -180,7 +180,7 @@
//! regardless of whether it is actually needed or not. //! regardless of whether it is actually needed or not.
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_data_structures::sync::{par_for_each_in, MTLock, MTRef};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
@ -346,7 +346,7 @@ pub fn collect_crate_mono_items(
let inlining_map: MTRef<'_, _> = &mut inlining_map; let inlining_map: MTRef<'_, _> = &mut inlining_map;
tcx.sess.time("monomorphization_collector_graph_walk", || { tcx.sess.time("monomorphization_collector_graph_walk", || {
par_iter(roots).for_each(|root| { par_for_each_in(roots, |root| {
let mut recursion_depths = DefIdMap::default(); let mut recursion_depths = DefIdMap::default();
collect_items_rec( collect_items_rec(
tcx, tcx,

View File

@ -23,7 +23,13 @@ LL | pub fn foo() {}
error: requires `sized` lang_item error: requires `sized` lang_item
error: aborting due to 3 previous errors error: requires `sized` lang_item
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0432, E0603. Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`. For more information about an error, try `rustc --explain E0432`.

View File

@ -6,6 +6,12 @@ LL | use bar::gpriv;
error: requires `sized` lang_item error: requires `sized` lang_item
error: aborting due to 2 previous errors error: requires `sized` lang_item
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0432`. For more information about this error, try `rustc --explain E0432`.

View File

@ -7,5 +7,14 @@ LL | pub fn drop<T>(_x: T) {}
= note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt'
= help: consider adding a `#![type_length_limit="8"]` attribute to your crate = help: consider adding a `#![type_length_limit="8"]` attribute to your crate
error: aborting due to previous error error: reached the type-length limit while instantiating `<[closure@std::rt::lang_start<()...e<()>>::call_once - shim(vtable)`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt'
= help: consider adding a `#![type_length_limit="8"]` attribute to your crate
error: aborting due to 2 previous errors