Skip to content

Commit 10fb113

Browse files
committed
Handle diagnostics in the DepGraph.
1 parent ff3c463 commit 10fb113

File tree

2 files changed

+36
-49
lines changed

2 files changed

+36
-49
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::steal::Steal;
77
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
88
use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_data_structures::unlikely;
10-
use rustc_errors::Diagnostic;
1110
use rustc_index::vec::IndexVec;
1211
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
1312

@@ -235,21 +234,31 @@ impl DepGraph {
235234
cx: Ctxt,
236235
arg: A,
237236
token: QueryJobId,
238-
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
239237
task: fn(Ctxt::DepContext, A) -> R,
240238
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
241239
) -> (R, DepNodeIndex) {
242-
self.with_task_impl(
240+
let prof_timer = cx.dep_context().profiler().query_provider();
241+
let diagnostics = Lock::new(ThinVec::new());
242+
let (result, dep_node_index) = self.with_task_impl(
243243
key,
244244
cx,
245245
arg,
246246
|arg, task_deps| {
247-
crate::tls::start_query(token, diagnostics, task_deps, || {
247+
crate::tls::start_query(token, Some(&diagnostics), task_deps, || {
248248
task(*cx.dep_context(), arg)
249249
})
250250
},
251251
hash_result,
252-
)
252+
);
253+
let diagnostics = diagnostics.into_inner();
254+
let side_effects = QuerySideEffects { diagnostics };
255+
256+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
257+
258+
if unlikely!(!side_effects.is_empty()) {
259+
cx.store_side_effects(dep_node_index, side_effects);
260+
}
261+
(result, dep_node_index)
253262
}
254263

255264
fn with_task_impl<Ctxt: HasDepContext, A: Debug, R>(
@@ -356,14 +365,26 @@ impl DepGraph {
356365
cx: Ctxt,
357366
arg: A,
358367
token: QueryJobId,
359-
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
360368
task: fn(Ctxt::DepContext, A) -> R,
361369
) -> (R, DepNodeIndex) {
362-
debug_assert!(!cx.dep_context().is_eval_always(dep_kind));
370+
let dcx = *cx.dep_context();
371+
debug_assert!(!dcx.is_eval_always(dep_kind));
363372

364-
self.with_anon_task_impl(*cx.dep_context(), dep_kind, |task_deps| {
365-
crate::tls::start_query(token, diagnostics, task_deps, || task(*cx.dep_context(), arg))
366-
})
373+
let prof_timer = dcx.profiler().query_provider();
374+
let diagnostics = Lock::new(ThinVec::new());
375+
376+
let (result, dep_node_index) = self.with_anon_task_impl(dcx, dep_kind, |task_deps| {
377+
crate::tls::start_query(token, Some(&diagnostics), task_deps, || task(dcx, arg))
378+
});
379+
let diagnostics = diagnostics.into_inner();
380+
381+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
382+
383+
let side_effects = QuerySideEffects { diagnostics };
384+
if unlikely!(!side_effects.is_empty()) {
385+
cx.store_side_effects_for_anon_node(dep_node_index, side_effects);
386+
}
387+
(result, dep_node_index)
367388
}
368389

369390
fn with_anon_task_impl<Ctxt: DepContext, R>(

compiler/rustc_query_system/src/query/plumbing.rs

+5-39
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
88
use crate::query::job::{
99
report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId,
1010
};
11-
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
11+
use crate::query::{QueryContext, QueryMap, QueryStackFrame};
1212

1313
use rustc_data_structures::fingerprint::Fingerprint;
1414
use rustc_data_structures::fx::{FxHashMap, FxHasher};
1515
#[cfg(parallel_compiler)]
1616
use rustc_data_structures::profiling::TimingGuard;
1717
use rustc_data_structures::sharded::{get_shard_index_by_hash, Sharded};
18-
use rustc_data_structures::sync::{Lock, LockGuard};
19-
use rustc_data_structures::thin_vec::ThinVec;
18+
use rustc_data_structures::sync::LockGuard;
2019
use rustc_errors::{DiagnosticBuilder, FatalError};
2120
use rustc_span::{Span, DUMMY_SP};
2221
use std::cell::Cell;
@@ -449,47 +448,14 @@ where
449448
}
450449
}
451450

452-
let prof_timer = tcx.dep_context().profiler().query_provider();
453-
let diagnostics = Lock::new(ThinVec::new());
454-
455-
let (result, dep_node_index) = if query.anon {
456-
dep_graph.with_anon_query(
457-
query.dep_kind,
458-
tcx,
459-
key,
460-
job_id,
461-
Some(&diagnostics),
462-
query.compute,
463-
)
451+
if query.anon {
452+
dep_graph.with_anon_query(query.dep_kind, tcx, key, job_id, query.compute)
464453
} else {
465454
// `to_dep_node` is expensive for some `DepKind`s.
466455
let dep_node = dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key));
467456

468-
dep_graph.with_query(
469-
dep_node,
470-
tcx,
471-
key,
472-
job_id,
473-
Some(&diagnostics),
474-
query.compute,
475-
query.hash_result,
476-
)
477-
};
478-
479-
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
480-
481-
let diagnostics = diagnostics.into_inner();
482-
let side_effects = QuerySideEffects { diagnostics };
483-
484-
if unlikely!(!side_effects.is_empty()) {
485-
if query.anon {
486-
tcx.store_side_effects_for_anon_node(dep_node_index, side_effects);
487-
} else {
488-
tcx.store_side_effects(dep_node_index, side_effects);
489-
}
457+
dep_graph.with_query(dep_node, tcx, key, job_id, query.compute, query.hash_result)
490458
}
491-
492-
(result, dep_node_index)
493459
}
494460

495461
fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(

0 commit comments

Comments
 (0)