Skip to content

Commit dc3be9f

Browse files
committed
use deadlock handler in query system
1 parent 3507254 commit dc3be9f

File tree

4 files changed

+7
-59
lines changed

4 files changed

+7
-59
lines changed

compiler/rustc_query_system/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1616
rustc_hir = { path = "../rustc_hir" }
1717
rustc_index = { path = "../rustc_index" }
1818
rustc_macros = { path = "../rustc_macros" }
19-
rustc-rayon-core = { version = "0.5.0", optional = true }
19+
rustc-rayon-core = { version = "0.5.0" }
2020
rustc_serialize = { path = "../rustc_serialize" }
2121
rustc_session = { path = "../rustc_session" }
2222
rustc_span = { path = "../rustc_span" }
@@ -27,4 +27,4 @@ thin-vec = "0.2.12"
2727
tracing = "0.1"
2828

2929
[features]
30-
rustc_use_parallel_compiler = ["rustc-rayon-core"]
30+
rustc_use_parallel_compiler = []

compiler/rustc_query_system/src/query/job.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_span::Span;
1515
use std::hash::Hash;
1616
use std::num::NonZeroU64;
1717

18-
#[cfg(parallel_compiler)]
1918
use {
2019
parking_lot::{Condvar, Mutex},
2120
rayon_core,
@@ -47,17 +46,14 @@ impl QueryJobId {
4746
map.get(&self).unwrap().query.clone()
4847
}
4948

50-
#[cfg(parallel_compiler)]
5149
fn span<D: DepKind>(self, map: &QueryMap<D>) -> Span {
5250
map.get(&self).unwrap().job.span
5351
}
5452

55-
#[cfg(parallel_compiler)]
5653
fn parent<D: DepKind>(self, map: &QueryMap<D>) -> Option<QueryJobId> {
5754
map.get(&self).unwrap().job.parent
5855
}
5956

60-
#[cfg(parallel_compiler)]
6157
fn latch<D: DepKind>(self, map: &QueryMap<D>) -> Option<&QueryLatch<D>> {
6258
map.get(&self).unwrap().job.latch.as_ref()
6359
}
@@ -81,7 +77,6 @@ pub struct QueryJob<D: DepKind> {
8177
pub parent: Option<QueryJobId>,
8278

8379
/// The latch that is used to wait on this job.
84-
#[cfg(parallel_compiler)]
8580
latch: Option<QueryLatch<D>>,
8681
spooky: core::marker::PhantomData<D>,
8782
}
@@ -90,17 +85,9 @@ impl<D: DepKind> QueryJob<D> {
9085
/// Creates a new query job.
9186
#[inline]
9287
pub fn new(id: QueryJobId, span: Span, parent: Option<QueryJobId>) -> Self {
93-
QueryJob {
94-
id,
95-
span,
96-
parent,
97-
#[cfg(parallel_compiler)]
98-
latch: None,
99-
spooky: PhantomData,
100-
}
88+
QueryJob { id, span, parent, latch: None, spooky: PhantomData }
10189
}
10290

103-
#[cfg(parallel_compiler)]
10491
pub(super) fn latch(&mut self) -> QueryLatch<D> {
10592
if self.latch.is_none() {
10693
self.latch = Some(QueryLatch::new());
@@ -114,11 +101,8 @@ impl<D: DepKind> QueryJob<D> {
114101
/// as there are no concurrent jobs which could be waiting on us
115102
#[inline]
116103
pub fn signal_complete(self) {
117-
#[cfg(parallel_compiler)]
118-
{
119-
if let Some(latch) = self.latch {
120-
latch.set();
121-
}
104+
if let Some(latch) = self.latch {
105+
latch.set();
122106
}
123107
}
124108
}
@@ -184,35 +168,30 @@ impl QueryJobId {
184168
}
185169
}
186170

187-
#[cfg(parallel_compiler)]
188171
struct QueryWaiter<D: DepKind> {
189172
query: Option<QueryJobId>,
190173
condvar: Condvar,
191174
span: Span,
192175
cycle: Lock<Option<CycleError<D>>>,
193176
}
194177

195-
#[cfg(parallel_compiler)]
196178
impl<D: DepKind> QueryWaiter<D> {
197179
fn notify(&self, registry: &rayon_core::Registry) {
198180
rayon_core::mark_unblocked(registry);
199181
self.condvar.notify_one();
200182
}
201183
}
202184

203-
#[cfg(parallel_compiler)]
204185
struct QueryLatchInfo<D: DepKind> {
205186
complete: bool,
206187
waiters: Vec<Lrc<QueryWaiter<D>>>,
207188
}
208189

209-
#[cfg(parallel_compiler)]
210190
#[derive(Clone)]
211191
pub(super) struct QueryLatch<D: DepKind> {
212192
info: Lrc<Mutex<QueryLatchInfo<D>>>,
213193
}
214194

215-
#[cfg(parallel_compiler)]
216195
impl<D: DepKind> QueryLatch<D> {
217196
fn new() -> Self {
218197
QueryLatch {
@@ -283,7 +262,6 @@ impl<D: DepKind> QueryLatch<D> {
283262
}
284263

285264
/// A resumable waiter of a query. The usize is the index into waiters in the query's latch
286-
#[cfg(parallel_compiler)]
287265
type Waiter = (QueryJobId, usize);
288266

289267
/// Visits all the non-resumable and resumable waiters of a query.
@@ -295,7 +273,6 @@ type Waiter = (QueryJobId, usize);
295273
/// For visits of resumable waiters it returns Some(Some(Waiter)) which has the
296274
/// required information to resume the waiter.
297275
/// If all `visit` calls returns None, this function also returns None.
298-
#[cfg(parallel_compiler)]
299276
fn visit_waiters<F, D>(
300277
query_map: &QueryMap<D>,
301278
query: QueryJobId,
@@ -331,7 +308,6 @@ where
331308
/// `span` is the reason for the `query` to execute. This is initially DUMMY_SP.
332309
/// If a cycle is detected, this initial value is replaced with the span causing
333310
/// the cycle.
334-
#[cfg(parallel_compiler)]
335311
fn cycle_check<D: DepKind>(
336312
query_map: &QueryMap<D>,
337313
query: QueryJobId,
@@ -372,7 +348,6 @@ fn cycle_check<D: DepKind>(
372348
/// Finds out if there's a path to the compiler root (aka. code which isn't in a query)
373349
/// from `query` without going through any of the queries in `visited`.
374350
/// This is achieved with a depth first search.
375-
#[cfg(parallel_compiler)]
376351
fn connected_to_root<D: DepKind>(
377352
query_map: &QueryMap<D>,
378353
query: QueryJobId,
@@ -395,7 +370,6 @@ fn connected_to_root<D: DepKind>(
395370
}
396371

397372
// Deterministically pick an query from a list
398-
#[cfg(parallel_compiler)]
399373
fn pick_query<'a, T, F, D>(query_map: &QueryMap<D>, queries: &'a [T], f: F) -> &'a T
400374
where
401375
F: Fn(&T) -> (Span, QueryJobId),
@@ -422,7 +396,6 @@ where
422396
/// the function return true.
423397
/// If a cycle was not found, the starting query is removed from `jobs` and
424398
/// the function returns false.
425-
#[cfg(parallel_compiler)]
426399
fn remove_cycle<D: DepKind>(
427400
query_map: &QueryMap<D>,
428401
jobs: &mut Vec<QueryJobId>,
@@ -527,7 +500,6 @@ fn remove_cycle<D: DepKind>(
527500
/// uses a query latch and then resuming that waiter.
528501
/// There may be multiple cycles involved in a deadlock, so this searches
529502
/// all active queries for cycles before finally resuming all the waiters at once.
530-
#[cfg(parallel_compiler)]
531503
pub fn deadlock<D: DepKind>(query_map: QueryMap<D>, registry: &rayon_core::Registry) {
532504
let on_panic = OnDrop(|| {
533505
eprintln!("deadlock handler panicked, aborting process");

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod plumbing;
22
pub use self::plumbing::*;
33

44
mod job;
5-
#[cfg(parallel_compiler)]
65
pub use self::job::deadlock;
76
pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap};
87

@@ -37,7 +36,6 @@ pub struct QueryStackFrame<D: DepKind> {
3736
pub dep_kind: D,
3837
/// This hash is used to deterministically pick
3938
/// a query to remove cycles in the parallel compiler.
40-
#[cfg(parallel_compiler)]
4139
hash: Hash64,
4240
}
4341

@@ -52,16 +50,7 @@ impl<D: DepKind> QueryStackFrame<D> {
5250
ty_adt_id: Option<DefId>,
5351
_hash: impl FnOnce() -> Hash64,
5452
) -> Self {
55-
Self {
56-
description,
57-
span,
58-
def_id,
59-
def_kind,
60-
ty_adt_id,
61-
dep_kind,
62-
#[cfg(parallel_compiler)]
63-
hash: _hash(),
64-
}
53+
Self { description, span, def_id, def_kind, ty_adt_id, dep_kind, hash: _hash() }
6554
}
6655

6756
// FIXME(eddyb) Get more valid `Span`s on queries.

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeIndex, DepNodeParams
66
use crate::dep_graph::{DepGraphData, HasDepContext};
77
use crate::ich::StableHashingContext;
88
use crate::query::caches::QueryCache;
9-
#[cfg(parallel_compiler)]
109
use crate::query::job::QueryLatch;
1110
use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo};
1211
use crate::query::SerializedDepNodeIndex;
1312
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
1413
use crate::HandleCycleError;
15-
#[cfg(parallel_compiler)]
1614
use rustc_data_structures::cold_path;
1715
use rustc_data_structures::fingerprint::Fingerprint;
1816
use rustc_data_structures::fx::FxHashMap;
@@ -244,7 +242,6 @@ where
244242
}
245243

246244
#[inline(always)]
247-
#[cfg(parallel_compiler)]
248245
fn wait_for_query<Q, Qcx>(
249246
query: Q,
250247
qcx: Qcx,
@@ -301,7 +298,7 @@ where
301298
// re-executing the query since `try_start` only checks that the query is not currently
302299
// executing, but another thread may have already completed the query and stores it result
303300
// in the query cache.
304-
if cfg!(parallel_compiler) && qcx.dep_context().sess().threads() > 1 {
301+
if qcx.dep_context().sess().threads() > 1 {
305302
if let Some((value, index)) = query.query_cache(qcx).lookup(&key) {
306303
qcx.dep_context().profiler().query_cache_hit(index.into());
307304
return (value, Some(index));
@@ -325,16 +322,6 @@ where
325322
}
326323
Entry::Occupied(mut entry) => {
327324
match entry.get_mut() {
328-
#[cfg(not(parallel_compiler))]
329-
QueryResult::Started(job) => {
330-
let id = job.id;
331-
drop(state_lock);
332-
333-
// If we are single-threaded we know that we have cycle error,
334-
// so we just return the error.
335-
cycle_error(query, qcx, id, span)
336-
}
337-
#[cfg(parallel_compiler)]
338325
QueryResult::Started(job) => {
339326
if !rustc_data_structures::sync::active() {
340327
let id = job.id;

0 commit comments

Comments
 (0)