Skip to content

Commit f97437e

Browse files
committed
avoid use threads pool when single thread
1 parent a7068db commit f97437e

File tree

2 files changed

+5
-3
lines changed
  • compiler

2 files changed

+5
-3
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ fn get_stack_size() -> Option<usize> {
126126
env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE)
127127
}
128128

129-
#[cfg(not(parallel_compiler))]
130129
pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
131130
edition: Edition,
132131
_threads: usize,
133132
f: F,
134133
) -> R {
134+
#[cfg(parallel_compiler)]
135+
if _threads > 1 {
136+
return run_in_threads_pool_with_globals(edition, _threads, f);
137+
}
135138
// The "thread pool" is a single spawned thread in the non-parallel
136139
// compiler. We run on a spawned thread instead of the main thread (a) to
137140
// provide control over the stack size, and (b) to increase similarity with
@@ -161,7 +164,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
161164
}
162165

163166
#[cfg(parallel_compiler)]
164-
pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
167+
pub(crate) fn run_in_threads_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
165168
edition: Edition,
166169
threads: usize,
167170
f: F,

compiler/rustc_query_system/src/query/job.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ impl<D: DepKind> QueryJob<D> {
124124
}
125125

126126
impl QueryJobId {
127-
#[cfg(not(parallel_compiler))]
128127
pub(super) fn find_cycle_in_stack<D: DepKind>(
129128
&self,
130129
query_map: QueryMap<D>,

0 commit comments

Comments
 (0)