Skip to content

Commit 4992a08

Browse files
authored
Rollup merge of rust-lang#64722 - Mark-Simulacrum:alt-parallel, r=alexcrichton
Make all alt builders produce parallel-enabled compilers We're not quite ready to ship parallel compilers by default, but the alt builders are not used too much (in theory), so we believe that shipping a possibly-broken compiler there is not too problematic. r? @nikomatsakis
2 parents afc2bcc + 1a1067d commit 4992a08

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

src/ci/run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
5555
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
5656
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
5757
elif [ "$DEPLOY_ALT" != "" ]; then
58+
if [ "$NO_PARALLEL_COMPILER" = "" ]; then
59+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.parallel-compiler"
60+
fi
5861
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-assertions"
5962
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
6063
fi

src/librustc/session/config.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ macro_rules! options {
805805
pub const parse_list: Option<&str> = Some("a space-separated list of strings");
806806
pub const parse_opt_list: Option<&str> = Some("a space-separated list of strings");
807807
pub const parse_opt_comma_list: Option<&str> = Some("a comma-separated list of strings");
808+
pub const parse_threads: Option<&str> = Some("a number");
808809
pub const parse_uint: Option<&str> = Some("a number");
809810
pub const parse_passes: Option<&str> =
810811
Some("a space-separated list of passes, or `all`");
@@ -948,6 +949,14 @@ macro_rules! options {
948949
}
949950
}
950951

952+
fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
953+
match v.and_then(|s| s.parse().ok()) {
954+
Some(0) => { *slot = ::num_cpus::get(); true },
955+
Some(i) => { *slot = i; true },
956+
None => false
957+
}
958+
}
959+
951960
fn parse_uint(slot: &mut usize, v: Option<&str>) -> bool {
952961
match v.and_then(|s| s.parse().ok()) {
953962
Some(i) => { *slot = i; true },
@@ -1251,7 +1260,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12511260
"prints the LLVM optimization passes being run"),
12521261
ast_json: bool = (false, parse_bool, [UNTRACKED],
12531262
"print the AST as JSON and halt"),
1254-
threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
1263+
// We default to 1 here since we want to behave like
1264+
// a sequential compiler for now. This'll likely be adjusted
1265+
// in the future. Note that -Zthreads=0 is the way to get
1266+
// the num_cpus behavior.
1267+
threads: usize = (1, parse_threads, [UNTRACKED],
12551268
"use a thread pool with N threads"),
12561269
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
12571270
"print the pre-expansion AST as JSON and halt"),
@@ -2146,14 +2159,14 @@ pub fn build_session_options_and_crate_config(
21462159
}
21472160
}
21482161

2149-
if debugging_opts.threads == Some(0) {
2162+
if debugging_opts.threads == 0 {
21502163
early_error(
21512164
error_format,
21522165
"value for threads must be a positive non-zero integer",
21532166
);
21542167
}
21552168

2156-
if debugging_opts.threads.unwrap_or(1) > 1 && debugging_opts.fuel.is_some() {
2169+
if debugging_opts.threads > 1 && debugging_opts.fuel.is_some() {
21572170
early_error(
21582171
error_format,
21592172
"optimization fuel is incompatible with multiple threads",

src/librustc/session/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -896,16 +896,10 @@ impl Session {
896896
ret
897897
}
898898

899-
/// Returns the number of query threads that should be used for this
900-
/// compilation
901-
pub fn threads_from_count(query_threads: Option<usize>) -> usize {
902-
query_threads.unwrap_or(::num_cpus::get())
903-
}
904-
905899
/// Returns the number of query threads that should be used for this
906900
/// compilation
907901
pub fn threads(&self) -> usize {
908-
Self::threads_from_count(self.opts.debugging_opts.threads)
902+
self.opts.debugging_opts.threads
909903
}
910904

911905
/// Returns the number of codegen units that should be used for this

src/librustc_interface/interface.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,8 @@ where
147147
F: FnOnce() -> R + Send,
148148
R: Send,
149149
{
150-
util::spawn_thread_pool(edition, None, &None, f)
150+
// the 1 here is duplicating code in config.opts.debugging_opts.threads
151+
// which also defaults to 1; it ultimately doesn't matter as the default
152+
// isn't threaded, and just ignores this parameter
153+
util::spawn_thread_pool(edition, 1, &None, f)
151154
}

src/librustc_interface/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f:
173173
#[cfg(not(parallel_compiler))]
174174
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
175175
edition: Edition,
176-
_threads: Option<usize>,
176+
_threads: usize,
177177
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
178178
f: F,
179179
) -> R {
@@ -198,7 +198,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
198198
#[cfg(parallel_compiler)]
199199
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
200200
edition: Edition,
201-
threads: Option<usize>,
201+
threads: usize,
202202
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
203203
f: F,
204204
) -> R {
@@ -209,7 +209,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
209209
let mut config = ThreadPoolBuilder::new()
210210
.acquire_thread_handler(jobserver::acquire_thread)
211211
.release_thread_handler(jobserver::release_thread)
212-
.num_threads(Session::threads_from_count(threads))
212+
.num_threads(threads)
213213
.deadlock_handler(|| unsafe { ty::query::handle_deadlock() });
214214

215215
if let Some(size) = get_stack_size() {

0 commit comments

Comments
 (0)