Skip to content

Commit eb82187

Browse files
committed
Make the fast path faster.
1 parent 91444af commit eb82187

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl<K: DepKind> DepGraph<K> {
792792
}
793793
}
794794

795-
fn next_virtual_depnode_index(&self) -> DepNodeIndex {
795+
pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex {
796796
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
797797
DepNodeIndex::from_u32(index)
798798
}

compiler/rustc_query_system/src/query/plumbing.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -452,29 +452,30 @@ where
452452
}
453453
};
454454

455-
// Fast path for when incr. comp. is off. `to_dep_node` is
456-
// expensive for some `DepKind`s.
457-
if !tcx.dep_context().dep_graph().is_fully_enabled() {
458-
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
459-
return force_query_with_job(tcx, key, job, null_dep_node, query).0;
455+
let dep_graph = tcx.dep_context().dep_graph();
456+
457+
// Fast path for when incr. comp. is off.
458+
if !dep_graph.is_fully_enabled() {
459+
let prof_timer = tcx.dep_context().profiler().query_provider();
460+
let result = tcx.start_query(job.id, None, || query.compute(tcx, key));
461+
let dep_node_index = dep_graph.next_virtual_depnode_index();
462+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
463+
return job.complete(result, dep_node_index);
460464
}
461465

462466
if query.anon {
463467
let prof_timer = tcx.dep_context().profiler().query_provider();
464468

465469
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
466470
tcx.start_query(job.id, diagnostics, || {
467-
tcx.dep_context().dep_graph().with_anon_task(
468-
*tcx.dep_context(),
469-
query.dep_kind,
470-
|| query.compute(tcx, key),
471-
)
471+
dep_graph
472+
.with_anon_task(*tcx.dep_context(), query.dep_kind, || query.compute(tcx, key))
472473
})
473474
});
474475

475476
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
476477

477-
tcx.dep_context().dep_graph().read_index(dep_node_index);
478+
dep_graph.read_index(dep_node_index);
478479

479480
if unlikely!(!diagnostics.is_empty()) {
480481
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
@@ -490,7 +491,7 @@ where
490491
// promoted to the current session during
491492
// `try_mark_green()`, so we can ignore them here.
492493
let loaded = tcx.start_query(job.id, None, || {
493-
let marked = tcx.dep_context().dep_graph().try_mark_green_and_read(tcx, &dep_node);
494+
let marked = dep_graph.try_mark_green_and_read(tcx, &dep_node);
494495
marked.map(|(prev_dep_node_index, dep_node_index)| {
495496
(
496497
load_from_disk_and_cache_in_memory(
@@ -511,7 +512,7 @@ where
511512
}
512513

513514
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
514-
tcx.dep_context().dep_graph().read_index(dep_node_index);
515+
dep_graph.read_index(dep_node_index);
515516
result
516517
}
517518

0 commit comments

Comments
 (0)