Skip to content

Commit ad43389

Browse files
committed
Auto merge of #58010 - Zoxc:parallel-passes, r=michaelwoerister
Move privacy checking later in the pipeline and make some passes run in parallel r? @michaelwoerister
2 parents 626e74d + 38bcd4b commit ad43389

File tree

15 files changed

+157
-104
lines changed

15 files changed

+157
-104
lines changed

src/librustc/hir/mod.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use syntax::util::parser::ExprPrecedence;
3030
use crate::ty::AdtKind;
3131
use crate::ty::query::Providers;
3232

33-
use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope};
33+
use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync};
3434
use rustc_data_structures::thin_vec::ThinVec;
3535

3636
use serialize::{self, Encoder, Encodable, Decoder, Decodable};
@@ -763,23 +763,17 @@ impl Crate {
763763
pub fn par_visit_all_item_likes<'hir, V>(&'hir self, visitor: &V)
764764
where V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send
765765
{
766-
scope(|s| {
767-
s.spawn(|_| {
768-
par_iter(&self.items).for_each(|(_, item)| {
769-
visitor.visit_item(item);
770-
});
766+
parallel!({
767+
par_iter(&self.items).for_each(|(_, item)| {
768+
visitor.visit_item(item);
771769
});
772-
773-
s.spawn(|_| {
774-
par_iter(&self.trait_items).for_each(|(_, trait_item)| {
775-
visitor.visit_trait_item(trait_item);
776-
});
770+
}, {
771+
par_iter(&self.trait_items).for_each(|(_, trait_item)| {
772+
visitor.visit_trait_item(trait_item);
777773
});
778-
779-
s.spawn(|_| {
780-
par_iter(&self.impl_items).for_each(|(_, impl_item)| {
781-
visitor.visit_impl_item(impl_item);
782-
});
774+
}, {
775+
par_iter(&self.impl_items).for_each(|(_, impl_item)| {
776+
visitor.visit_impl_item(impl_item);
783777
});
784778
});
785779
}

src/librustc/middle/liveness.rs

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
189189
for &module in tcx.hir().krate().modules.keys() {
190190
tcx.ensure().check_mod_liveness(tcx.hir().local_def_id(module));
191191
}
192-
tcx.sess.abort_if_errors();
193192
}
194193

195194
pub fn provide(providers: &mut Providers<'_>) {

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct Session {
8585
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
8686
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
8787
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
88-
pub plugin_attributes: OneThread<RefCell<Vec<(String, AttributeType)>>>,
88+
pub plugin_attributes: Lock<Vec<(String, AttributeType)>>,
8989
pub crate_types: Once<Vec<config::CrateType>>,
9090
pub dependency_formats: Once<dependency_format::Dependencies>,
9191
/// The crate_disambiguator is constructed out of all the `-C metadata`
@@ -1178,7 +1178,7 @@ pub fn build_session_(
11781178
buffered_lints: Lock::new(Some(Default::default())),
11791179
one_time_diagnostics: Default::default(),
11801180
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
1181-
plugin_attributes: OneThread::new(RefCell::new(Vec::new())),
1181+
plugin_attributes: Lock::new(Vec::new()),
11821182
crate_types: Once::new(),
11831183
dependency_formats: Once::new(),
11841184
crate_disambiguator: Once::new(),

src/librustc_data_structures/sync.rs

+27
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ cfg_if! {
127127
pub use self::serial_join as join;
128128
pub use self::serial_scope as scope;
129129

130+
#[macro_export]
131+
macro_rules! parallel {
132+
($($blocks:tt),*) => {
133+
$($blocks)*;
134+
}
135+
}
136+
130137
pub use std::iter::Iterator as ParallelIterator;
131138

132139
pub fn par_iter<T: IntoIterator>(t: T) -> T::IntoIter {
@@ -271,6 +278,26 @@ cfg_if! {
271278
use std::thread;
272279
pub use rayon::{join, scope};
273280

281+
#[macro_export]
282+
macro_rules! parallel {
283+
(impl [$($c:tt,)*] [$block:tt $(, $rest:tt)*]) => {
284+
parallel!(impl [$block, $($c,)*] [$($rest),*])
285+
};
286+
(impl [$($blocks:tt,)*] []) => {
287+
::rustc_data_structures::sync::scope(|s| {
288+
$(
289+
s.spawn(|_| $blocks);
290+
)*
291+
})
292+
};
293+
($($blocks:tt),*) => {
294+
// Reverse the order of the blocks since Rayon executes them in reverse order
295+
// when using a single thread. This ensures the execution order matches that
296+
// of a single threaded rustc
297+
parallel!(impl [] [$($blocks),*]);
298+
};
299+
}
300+
274301
pub use rayon_core::WorkerLocal;
275302

276303
pub use rayon::iter::ParallelIterator;

src/librustc_driver/driver.rs

+58-44
Original file line numberDiff line numberDiff line change
@@ -1222,26 +1222,28 @@ where
12221222
// tcx available.
12231223
time(sess, "dep graph tcx init", || rustc_incremental::dep_graph_tcx_init(tcx));
12241224

1225-
time(sess, "looking for entry point", || {
1226-
middle::entry::find_entry_point(tcx)
1227-
});
1228-
1229-
time(sess, "looking for plugin registrar", || {
1230-
plugin::build::find_plugin_registrar(tcx)
1231-
});
1232-
1233-
time(sess, "looking for derive registrar", || {
1234-
proc_macro_decls::find(tcx)
1235-
});
1236-
1237-
time(sess, "loop checking", || loops::check_crate(tcx));
1225+
parallel!({
1226+
time(sess, "looking for entry point", || {
1227+
middle::entry::find_entry_point(tcx)
1228+
});
12381229

1239-
time(sess, "attribute checking", || {
1240-
hir::check_attr::check_crate(tcx)
1241-
});
1230+
time(sess, "looking for plugin registrar", || {
1231+
plugin::build::find_plugin_registrar(tcx)
1232+
});
12421233

1243-
time(sess, "stability checking", || {
1244-
stability::check_unstable_api_usage(tcx)
1234+
time(sess, "looking for derive registrar", || {
1235+
proc_macro_decls::find(tcx)
1236+
});
1237+
}, {
1238+
time(sess, "loop checking", || loops::check_crate(tcx));
1239+
}, {
1240+
time(sess, "attribute checking", || {
1241+
hir::check_attr::check_crate(tcx)
1242+
});
1243+
}, {
1244+
time(sess, "stability checking", || {
1245+
stability::check_unstable_api_usage(tcx)
1246+
});
12451247
});
12461248

12471249
// passes are timed inside typeck
@@ -1253,27 +1255,31 @@ where
12531255
}
12541256
}
12551257

1256-
time(sess, "rvalue promotion", || {
1257-
rvalue_promotion::check_crate(tcx)
1258-
});
1259-
1260-
time(sess, "privacy checking", || {
1261-
rustc_privacy::check_crate(tcx)
1262-
});
1263-
1264-
time(sess, "intrinsic checking", || {
1265-
middle::intrinsicck::check_crate(tcx)
1258+
time(sess, "misc checking", || {
1259+
parallel!({
1260+
time(sess, "rvalue promotion", || {
1261+
rvalue_promotion::check_crate(tcx)
1262+
});
1263+
}, {
1264+
time(sess, "intrinsic checking", || {
1265+
middle::intrinsicck::check_crate(tcx)
1266+
});
1267+
}, {
1268+
time(sess, "match checking", || mir::matchck_crate(tcx));
1269+
}, {
1270+
// this must run before MIR dump, because
1271+
// "not all control paths return a value" is reported here.
1272+
//
1273+
// maybe move the check to a MIR pass?
1274+
time(sess, "liveness checking", || {
1275+
middle::liveness::check_crate(tcx)
1276+
});
1277+
});
12661278
});
12671279

1268-
time(sess, "match checking", || mir::matchck_crate(tcx));
1269-
1270-
// this must run before MIR dump, because
1271-
// "not all control paths return a value" is reported here.
1272-
//
1273-
// maybe move the check to a MIR pass?
1274-
time(sess, "liveness checking", || {
1275-
middle::liveness::check_crate(tcx)
1276-
});
1280+
// Abort so we don't try to construct MIR with liveness errors.
1281+
// We also won't want to continue with errors from rvalue promotion
1282+
tcx.sess.abort_if_errors();
12771283

12781284
time(sess, "borrow checking", || {
12791285
if tcx.use_ast_borrowck() {
@@ -1297,7 +1303,7 @@ where
12971303

12981304
time(sess, "layout testing", || layout_test::test_layout(tcx));
12991305

1300-
// Avoid overwhelming user with errors if type checking failed.
1306+
// Avoid overwhelming user with errors if borrow checking failed.
13011307
// I'm not sure how helpful this is, to be honest, but it avoids
13021308
// a
13031309
// lot of annoying errors in the compile-fail tests (basically,
@@ -1307,14 +1313,22 @@ where
13071313
return Ok(f(tcx, rx, sess.compile_status()));
13081314
}
13091315

1310-
time(sess, "death checking", || middle::dead::check_crate(tcx));
1311-
1312-
time(sess, "unused lib feature checking", || {
1313-
stability::check_unused_or_stable_features(tcx)
1316+
time(sess, "misc checking", || {
1317+
parallel!({
1318+
time(sess, "privacy checking", || {
1319+
rustc_privacy::check_crate(tcx)
1320+
});
1321+
}, {
1322+
time(sess, "death checking", || middle::dead::check_crate(tcx));
1323+
}, {
1324+
time(sess, "unused lib feature checking", || {
1325+
stability::check_unused_or_stable_features(tcx)
1326+
});
1327+
}, {
1328+
time(sess, "lint checking", || lint::check_crate(tcx));
1329+
});
13141330
});
13151331

1316-
time(sess, "lint checking", || lint::check_crate(tcx));
1317-
13181332
return Ok(f(tcx, rx, tcx.sess.compile_status()));
13191333
},
13201334
)

src/librustc_driver/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern crate rustc;
3030
extern crate rustc_allocator;
3131
extern crate rustc_target;
3232
extern crate rustc_borrowck;
33+
#[macro_use]
3334
extern crate rustc_data_structures;
3435
extern crate rustc_errors as errors;
3536
extern crate rustc_passes;

src/librustc_passes/rvalue_promotion.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
4444
let def_id = tcx.hir().body_owner_def_id(body_id);
4545
tcx.const_is_rvalue_promotable_to_static(def_id);
4646
}
47-
tcx.sess.abort_if_errors();
4847
}
4948

5049
fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/test/ui/error-codes/E0446.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod Foo {
1+
mod foo {
22
struct Bar(u32);
33

44
pub fn bar() -> Bar { //~ ERROR E0446

src/test/ui/error-codes/E0446.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0446]: private type `Foo::Bar` in public interface
1+
error[E0446]: private type `foo::Bar` in public interface
22
--> $DIR/E0446.rs:4:5
33
|
44
LL | struct Bar(u32);
5-
| - `Foo::Bar` declared as private
5+
| - `foo::Bar` declared as private
66
LL |
77
LL | / pub fn bar() -> Bar { //~ ERROR E0446
88
LL | | Bar(0)

src/test/ui/error-codes/E0451.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod Bar {
1+
mod bar {
22
pub struct Foo {
33
pub a: isize,
44
b: isize,
@@ -10,10 +10,10 @@ mod Bar {
1010
);
1111
}
1212

13-
fn pat_match(foo: Bar::Foo) {
14-
let Bar::Foo{a:a, b:b} = foo; //~ ERROR E0451
13+
fn pat_match(foo: bar::Foo) {
14+
let bar::Foo{a, b} = foo; //~ ERROR E0451
1515
}
1616

1717
fn main() {
18-
let f = Bar::Foo{ a: 0, b: 0 }; //~ ERROR E0451
18+
let f = bar::Foo{ a: 0, b: 0 }; //~ ERROR E0451
1919
}

src/test/ui/error-codes/E0451.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0451]: field `b` of struct `Bar::Foo` is private
2-
--> $DIR/E0451.rs:14:23
1+
error[E0451]: field `b` of struct `bar::Foo` is private
2+
--> $DIR/E0451.rs:14:21
33
|
4-
LL | let Bar::Foo{a:a, b:b} = foo; //~ ERROR E0451
5-
| ^^^ field `b` is private
4+
LL | let bar::Foo{a, b} = foo; //~ ERROR E0451
5+
| ^ field `b` is private
66

7-
error[E0451]: field `b` of struct `Bar::Foo` is private
7+
error[E0451]: field `b` of struct `bar::Foo` is private
88
--> $DIR/E0451.rs:18:29
99
|
10-
LL | let f = Bar::Foo{ a: 0, b: 0 }; //~ ERROR E0451
10+
LL | let f = bar::Foo{ a: 0, b: 0 }; //~ ERROR E0451
1111
| ^^^^ field `b` is private
1212

1313
error: aborting due to 2 previous errors

src/test/ui/functional-struct-update/functional-struct-update-respects-privacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use self::foo::S;
66
mod foo {
77
use std::cell::{UnsafeCell};
88

9-
static mut count : UnsafeCell<u64> = UnsafeCell::new(1);
9+
static mut COUNT : UnsafeCell<u64> = UnsafeCell::new(1);
1010

1111
pub struct S { pub a: u8, pub b: String, secret_uid: u64 }
1212

1313
pub fn make_secrets(a: u8, b: String) -> S {
14-
let val = unsafe { let p = count.get(); let val = *p; *p = val + 1; val };
14+
let val = unsafe { let p = COUNT.get(); let val = *p; *p = val + 1; val };
1515
println!("creating {}, uid {}", b, val);
1616
S { a: a, b: b, secret_uid: val }
1717
}

src/test/ui/privacy/private-in-public-warn.rs

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mod traits {
4949

5050
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
5151
//~| WARNING hard error
52+
//~| WARNING bounds on generic parameters are not enforced in type aliases
5253
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
5354
//~^ WARNING hard error
5455
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
@@ -74,6 +75,7 @@ mod traits_where {
7475
pub type Alias<T> where T: PrivTr = T;
7576
//~^ ERROR private trait `traits_where::PrivTr` in public interface
7677
//~| WARNING hard error
78+
//~| WARNING where clauses are not enforced in type aliases
7779
pub trait Tr2<T> where T: PrivTr {}
7880
//~^ ERROR private trait `traits_where::PrivTr` in public interface
7981
//~| WARNING hard error

0 commit comments

Comments
 (0)