Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0f6da4

Browse files
committed
Increase parallelism in various locations
1 parent 5ae50d3 commit b0f6da4

File tree

8 files changed

+139
-84
lines changed

8 files changed

+139
-84
lines changed

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,14 +2323,21 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23232323

23242324
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
23252325
let items = tcx.hir_module_items(module);
2326-
let res = items
2327-
.par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
2328-
.and(items.par_impl_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
2329-
.and(items.par_trait_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
2330-
.and(
2331-
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
2332-
)
2333-
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
2326+
let res =
2327+
items
2328+
.try_par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
2329+
.and(
2330+
items.try_par_impl_items(|item| {
2331+
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
2332+
}),
2333+
)
2334+
.and(items.try_par_trait_items(|item| {
2335+
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
2336+
}))
2337+
.and(items.try_par_foreign_items(|item| {
2338+
tcx.ensure_ok().check_well_formed(item.owner_id.def_id)
2339+
}))
2340+
.and(items.try_par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
23342341
if module == LocalModDefId::CRATE_DEF_ID {
23352342
super::entry::check_for_entry_fn(tcx);
23362343
}

‎compiler/rustc_hir_analysis/src/lib.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ mod variance;
9393

9494
pub use errors::NoVariantNamed;
9595
use rustc_abi::ExternAbi;
96+
use rustc_data_structures::sync::par_for_each_in;
9697
use rustc_hir as hir;
9798
use rustc_hir::def::DefKind;
9899
use rustc_middle::middle;
@@ -178,6 +179,9 @@ pub fn provide(providers: &mut Providers) {
178179
pub fn check_crate(tcx: TyCtxt<'_>) {
179180
let _prof_timer = tcx.sess.timer("type_check_crate");
180181

182+
// Run dependencies of type checking before entering the loops below
183+
tcx.ensure_done().inferred_outlives_crate(());
184+
181185
tcx.sess.time("coherence_checking", || {
182186
// When discarding query call results, use an explicit type to indicate
183187
// what we are intending to discard, to help future type-based refactoring.
@@ -187,9 +191,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
187191
let _: R = tcx.ensure_ok().check_mod_type_wf(module);
188192
});
189193

190-
for&trait_def_id intcx.all_local_trait_impls(()).keys() {
194+
par_for_each_in(tcx.all_local_trait_impls(()), |(trait_def_id, _)| {
191195
let _: R = tcx.ensure_ok().coherent_trait(trait_def_id);
192-
}
196+
});
197+
193198
// these queries are executed for side-effects (error reporting):
194199
let _: R = tcx.ensure_ok().crate_inherent_impls_validity_check(());
195200
let _: R = tcx.ensure_ok().crate_inherent_impls_overlap_check(());

‎compiler/rustc_interface/src/passes.rs‎

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,24 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
913913
CStore::from_tcx(tcx).report_unused_deps(tcx);
914914
},
915915
{
916+
// Prefetch this as it is used later by the loop below
917+
// to prevent multiple threads from blocking on it.
918+
tcx.ensure_done().get_lang_items(());
919+
920+
let _timer = tcx.sess.timer("misc_module_passes");
916921
tcx.par_hir_for_each_module(|module| {
917922
tcx.ensure_ok().check_mod_loops(module);
918923
tcx.ensure_ok().check_mod_attrs(module);
919924
tcx.ensure_ok().check_mod_naked_functions(module);
925+
});
926+
},
927+
{
928+
// Prefetch this as it is used later by the loop below
929+
// to prevent multiple threads from blocking on it.
930+
tcx.ensure_done().stability_index(());
931+
932+
let _timer = tcx.sess.timer("check_unstable_api_usage");
933+
tcx.par_hir_for_each_module(|module| {
920934
tcx.ensure_ok().check_mod_unstable_api_usage(module);
921935
});
922936
},
@@ -951,30 +965,47 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
951965
// This improves performance by allowing lock-free access to them.
952966
tcx.untracked().definitions.freeze();
953967

954-
sess.time("MIR_borrow_checking", || {
955-
tcx.par_hir_body_owners(|def_id| {
956-
// Run unsafety check because it's responsible for stealing and
957-
// deallocating THIR.
958-
tcx.ensure_ok().check_unsafety(def_id);
959-
if !tcx.is_typeck_child(def_id.to_def_id()) {
960-
tcx.ensure_ok().mir_borrowck(def_id)
961-
}
962-
});
963-
});
964-
sess.time("MIR_effect_checking", || {
965-
tcx.par_hir_body_owners(|def_id| {
966-
tcx.ensure_ok().has_ffi_unwind_calls(def_id);
967-
968-
// If we need to codegen, ensure that we emit all errors from
969-
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
970-
// them later during codegen.
971-
if tcx.sess.opts.output_types.should_codegen()
972-
|| tcx.hir_body_const_context(def_id).is_some()
968+
sess.time("misc_checking_2", || {
969+
parallel!(
970+
{
971+
// Prefetch this as it is used later by lint checking and privacy checking.
972+
tcx.ensure_done().effective_visibilities(());
973+
},
974+
{
975+
sess.time("MIR_borrow_checking", || {
976+
tcx.par_hir_body_owners(|def_id| {
977+
// Run unsafety check because it's responsible for stealing and
978+
// deallocating THIR.
979+
tcx.ensure_ok().check_unsafety(def_id);
980+
if !tcx.is_typeck_child(def_id.to_def_id()) {
981+
tcx.ensure_ok().mir_borrowck(def_id)
982+
}
983+
});
984+
});
985+
},
986+
{
987+
sess.time("MIR_effect_checking", || {
988+
tcx.par_hir_body_owners(|def_id| {
989+
tcx.ensure_ok().has_ffi_unwind_calls(def_id);
990+
991+
// If we need to codegen, ensure that we emit all errors from
992+
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
993+
// them later during codegen.
994+
if tcx.sess.opts.output_types.should_codegen()
995+
|| tcx.hir_body_const_context(def_id).is_some()
996+
{
997+
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
998+
}
999+
});
1000+
});
1001+
},
9731002
{
974-
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
1003+
sess.time("layout_testing", || layout_test::test_layout(tcx));
1004+
sess.time("abi_testing", || abi_test::test_abi(tcx));
9751005
}
976-
});
1006+
)
9771007
});
1008+
9781009
sess.time("coroutine_obligations", || {
9791010
tcx.par_hir_body_owners(|def_id| {
9801011
if tcx.is_coroutine(def_id.to_def_id()) {
@@ -991,9 +1022,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
9911022
});
9921023
});
9931024

994-
sess.time("layout_testing", || layout_test::test_layout(tcx));
995-
sess.time("abi_testing", || abi_test::test_abi(tcx));
996-
9971025
// If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
9981026
// (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
9991027
// in MIR optimizations that may only be reachable through codegen, or other codepaths
@@ -1029,26 +1057,18 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
10291057
sess.time("misc_checking_3", || {
10301058
parallel!(
10311059
{
1032-
tcx.ensure_ok().effective_visibilities(());
1033-
1034-
parallel!(
1035-
{
1036-
tcx.ensure_ok().check_private_in_public(());
1037-
},
1038-
{
1039-
tcx.par_hir_for_each_module(|module| {
1040-
tcx.ensure_ok().check_mod_deathness(module)
1041-
});
1042-
},
1043-
{
1044-
sess.time("lint_checking", || {
1045-
rustc_lint::check_crate(tcx);
1046-
});
1047-
},
1048-
{
1049-
tcx.ensure_ok().clashing_extern_declarations(());
1050-
}
1051-
);
1060+
tcx.ensure_ok().check_private_in_public(());
1061+
},
1062+
{
1063+
tcx.par_hir_for_each_module(|module| tcx.ensure_ok().check_mod_deathness(module));
1064+
},
1065+
{
1066+
sess.time("lint_checking", || {
1067+
rustc_lint::check_crate(tcx);
1068+
});
1069+
},
1070+
{
1071+
tcx.ensure_ok().clashing_extern_declarations(());
10521072
},
10531073
{
10541074
sess.time("privacy_checking_modules", || {

‎compiler/rustc_middle/src/hir/mod.rs‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod place;
99
use rustc_data_structures::fingerprint::Fingerprint;
1010
use rustc_data_structures::sorted_map::SortedMap;
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
12-
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
12+
use rustc_data_structures::sync::{DynSend, DynSync, par_for_each_in,try_par_for_each_in};
1313
use rustc_hir::def::DefKind;
1414
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1515
use rustc_hir::*;
@@ -79,40 +79,56 @@ impl ModuleItems {
7979
self.owners().map(|id| id.def_id)
8080
}
8181

82-
pub fn par_items(
82+
pub fn try_par_items(
8383
&self,
8484
f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
8585
) -> Result<(), ErrorGuaranteed> {
8686
try_par_for_each_in(&self.free_items[..], |&&id| f(id))
8787
}
8888

89-
pub fn par_trait_items(
89+
pub fn try_par_trait_items(
9090
&self,
9191
f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
9292
) -> Result<(), ErrorGuaranteed> {
9393
try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
9494
}
9595

96-
pub fn par_impl_items(
96+
pub fn try_par_impl_items(
9797
&self,
9898
f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
9999
) -> Result<(), ErrorGuaranteed> {
100100
try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
101101
}
102102

103-
pub fn par_foreign_items(
103+
pub fn try_par_foreign_items(
104104
&self,
105105
f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
106106
) -> Result<(), ErrorGuaranteed> {
107107
try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
108108
}
109109

110-
pub fn par_opaques(
110+
pub fn try_par_opaques(
111111
&self,
112112
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
113113
) -> Result<(), ErrorGuaranteed> {
114114
try_par_for_each_in(&self.opaques[..], |&&id| f(id))
115115
}
116+
117+
pub fn par_items(&self, f: impl Fn(ItemId) + DynSend + DynSync) {
118+
par_for_each_in(&self.free_items[..], |&id| f(id))
119+
}
120+
121+
pub fn par_trait_items(&self, f: impl Fn(TraitItemId) + DynSend + DynSync) {
122+
par_for_each_in(&self.trait_items[..], |&id| f(id))
123+
}
124+
125+
pub fn par_impl_items(&self, f: impl Fn(ImplItemId) + DynSend + DynSync) {
126+
par_for_each_in(&self.impl_items[..], |&id| f(id))
127+
}
128+
129+
pub fn par_foreign_items(&self, f: impl Fn(ForeignItemId) + DynSend + DynSync) {
130+
par_for_each_in(&self.foreign_items[..], |&id| f(id))
131+
}
116132
}
117133

118134
impl<'tcx> TyCtxt<'tcx> {

‎compiler/rustc_monomorphize/src/collector.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ use std::path::PathBuf;
209209

210210
use rustc_attr_parsing::InlineAttr;
211211
use rustc_data_structures::fx::FxIndexMap;
212-
use rustc_data_structures::sync::{MTLock, par_for_each_in};
212+
use rustc_data_structures::sync::{MTLock, join,par_for_each_in};
213213
use rustc_data_structures::unord::{UnordMap, UnordSet};
214214
use rustc_hir as hir;
215215
use rustc_hir::def::DefKind;
@@ -1672,9 +1672,20 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16721672
) -> (Vec<MonoItem<'tcx>>, UsageMap<'tcx>) {
16731673
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector");
16741674

1675-
let roots = tcx
1676-
.sess
1677-
.time("monomorphization_collector_root_collections", || collect_roots(tcx, strategy));
1675+
let (roots, _) = join(
1676+
|| {
1677+
tcx.sess.time("monomorphization_collector_root_collections", || {
1678+
collect_roots(tcx, strategy)
1679+
})
1680+
},
1681+
|| {
1682+
if tcx.sess.opts.share_generics() {
1683+
// Prefetch upstream_monomorphizations as it's very likely to be used in
1684+
// code generation later and this is decent spot to compute it.
1685+
tcx.ensure_ok().upstream_monomorphizations(());
1686+
}
1687+
},
1688+
);
16781689

16791690
debug!("building mono item graph, beginning at roots");
16801691

‎tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
error[E0391]: cycle detected when computing predicates of `Foo`
2-
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
3-
|
4-
LL | struct Foo {
5-
| ^^^^^^^^^^
6-
|
7-
note: ...which requires computing inferred outlives-predicates of `Foo`...
8-
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
1+
error[E0391]: cycle detected when computing the inferred outlives-predicates for items in this crate
92
|
10-
LL | struct Foo {
11-
| ^^^^^^^^^^
12-
= note: ...which requires computing the inferred outlives-predicates for items in this crate...
133
note: ...which requires computing type of `Foo::bar`...
144
--> $DIR/cycle-iat-inside-of-adt.rs:8:5
155
|
@@ -20,12 +10,18 @@ note: ...which requires computing normalized predicates of `Foo`...
2010
|
2111
LL | struct Foo {
2212
| ^^^^^^^^^^
23-
= note: ...which again requires computing predicates of `Foo`, completing the cycle
24-
note: cycle used when checking that `Foo` is well-formed
13+
note: ...which requires computing predicates of `Foo`...
14+
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
15+
|
16+
LL | struct Foo {
17+
| ^^^^^^^^^^
18+
note: ...which requires computing inferred outlives-predicates of `Foo`...
2519
--> $DIR/cycle-iat-inside-of-adt.rs:7:1
2620
|
2721
LL | struct Foo {
2822
| ^^^^^^^^^^
23+
= note: ...which again requires computing the inferred outlives-predicates for items in this crate, completing the cycle
24+
= note: cycle used when running analysis passes on this crate
2925
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
3026

3127
error: aborting due to 1 previous error

‎tests/ui/span/issue-35987.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ struct Foo<T: Clone>(T);
33
use std::ops::Add;
44

55
impl<T: Clone, Add> Add for Foo<T> {
6-
//~^ ERROR expected trait, found type parameter
6+
//~^ ERROR expected trait, found type parameter
77
type Output = usize;
88

99
fn add(self, rhs: Self) -> Self::Output {

‎tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ error[E0404]: expected trait, found builtin type `usize`
1616
LL | x: usize + 'a,
1717
| ^^^^^ not a trait
1818

19+
error[E0782]: expected a type, found a trait
20+
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
21+
|
22+
LL | x: usize + 'a,
23+
| ^^^^^^^^^^
24+
1925
error[E0782]: expected a type, found a trait
2026
--> $DIR/suggestion-trait-object-issue-139174.rs:3:36
2127
|
@@ -28,12 +34,6 @@ error[E0782]: expected a type, found a trait
2834
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
2935
| ^^^^^^^^^^
3036

31-
error[E0782]: expected a type, found a trait
32-
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
33-
|
34-
LL | x: usize + 'a,
35-
| ^^^^^^^^^^
36-
3737
error: aborting due to 6 previous errors
3838

3939
Some errors have detailed explanations: E0404, E0782.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /