Skip to content

Commit eeb3c8f

Browse files
committed
Unify with_task functions.
Remove with_eval_always_task.
1 parent f2c8707 commit eeb3c8f

File tree

2 files changed

+76
-103
lines changed

2 files changed

+76
-103
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+69-86
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,17 @@ impl<K: DepKind> DepGraph<K> {
215215
cx: Ctxt,
216216
arg: A,
217217
task: fn(Ctxt, A) -> R,
218-
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
218+
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
219219
) -> (R, DepNodeIndex) {
220-
self.with_task_impl(
221-
key,
222-
cx,
223-
arg,
224-
task,
225-
|_key| {
226-
Some(TaskDeps {
227-
#[cfg(debug_assertions)]
228-
node: Some(_key),
229-
reads: SmallVec::new(),
230-
read_set: Default::default(),
231-
phantom_data: PhantomData,
232-
})
233-
},
234-
hash_result,
235-
)
220+
if self.is_fully_enabled() {
221+
self.with_task_impl(key, cx, arg, task, hash_result)
222+
} else {
223+
// Incremental compilation is turned off. We just execute the task
224+
// without tracking. We still provide a dep-node index that uniquely
225+
// identifies the task so that we have a cheap way of referring to
226+
// the query for self-profiling.
227+
(task(cx, arg), self.next_virtual_depnode_index())
228+
}
236229
}
237230

238231
fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
@@ -241,71 +234,74 @@ impl<K: DepKind> DepGraph<K> {
241234
cx: Ctxt,
242235
arg: A,
243236
task: fn(Ctxt, A) -> R,
244-
create_task: fn(DepNode<K>) -> Option<TaskDeps<K>>,
245-
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
237+
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
246238
) -> (R, DepNodeIndex) {
247-
if let Some(ref data) = self.data {
248-
// If the following assertion triggers, it can have two reasons:
249-
// 1. Something is wrong with DepNode creation, either here or
250-
// in `DepGraph::try_mark_green()`.
251-
// 2. Two distinct query keys get mapped to the same `DepNode`
252-
// (see for example #48923).
253-
assert!(
254-
!self.dep_node_exists(&key),
255-
"forcing query with already existing `DepNode`\n\
239+
// This function is only called when the graph is enabled.
240+
let data = self.data.as_ref().unwrap();
241+
242+
// If the following assertion triggers, it can have two reasons:
243+
// 1. Something is wrong with DepNode creation, either here or
244+
// in `DepGraph::try_mark_green()`.
245+
// 2. Two distinct query keys get mapped to the same `DepNode`
246+
// (see for example #48923).
247+
assert!(
248+
!self.dep_node_exists(&key),
249+
"forcing query with already existing `DepNode`\n\
256250
- query-key: {:?}\n\
257251
- dep-node: {:?}",
258-
arg,
259-
key
260-
);
252+
arg,
253+
key
254+
);
261255

262-
let dcx = cx.dep_context();
263-
let task_deps = create_task(key).map(Lock::new);
264-
let result = K::with_deps(task_deps.as_ref(), || task(cx, arg));
265-
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
266-
267-
let mut hcx = dcx.create_stable_hashing_context();
268-
let hashing_timer = dcx.profiler().incr_result_hashing();
269-
let current_fingerprint = hash_result(&mut hcx, &result);
270-
271-
let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
272-
273-
// Get timer for profiling `DepNode` interning
274-
let node_intern_timer = self
275-
.node_intern_event_id
276-
.map(|eid| dcx.profiler().generic_activity_with_event_id(eid));
277-
// Intern the new `DepNode`.
278-
let (dep_node_index, prev_and_color) = data.current.intern_node(
279-
dcx.profiler(),
280-
&data.previous,
281-
key,
282-
edges,
283-
current_fingerprint,
284-
print_status,
285-
);
286-
drop(node_intern_timer);
256+
let task_deps = if key.kind.is_eval_always() {
257+
None
258+
} else {
259+
Some(Lock::new(TaskDeps {
260+
#[cfg(debug_assertions)]
261+
node: Some(key),
262+
reads: SmallVec::new(),
263+
read_set: Default::default(),
264+
phantom_data: PhantomData,
265+
}))
266+
};
267+
let result = K::with_deps(task_deps.as_ref(), || task(cx, arg));
268+
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
269+
270+
let dcx = cx.dep_context();
271+
let mut hcx = dcx.create_stable_hashing_context();
272+
let hashing_timer = dcx.profiler().incr_result_hashing();
273+
let current_fingerprint = hash_result(&mut hcx, &result);
274+
275+
let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
276+
277+
// Get timer for profiling `DepNode` interning
278+
let node_intern_timer =
279+
self.node_intern_event_id.map(|eid| dcx.profiler().generic_activity_with_event_id(eid));
280+
// Intern the new `DepNode`.
281+
let (dep_node_index, prev_and_color) = data.current.intern_node(
282+
dcx.profiler(),
283+
&data.previous,
284+
key,
285+
edges,
286+
current_fingerprint,
287+
print_status,
288+
);
289+
drop(node_intern_timer);
287290

288-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
291+
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
289292

290-
if let Some((prev_index, color)) = prev_and_color {
291-
debug_assert!(
292-
data.colors.get(prev_index).is_none(),
293-
"DepGraph::with_task() - Duplicate DepNodeColor \
293+
if let Some((prev_index, color)) = prev_and_color {
294+
debug_assert!(
295+
data.colors.get(prev_index).is_none(),
296+
"DepGraph::with_task() - Duplicate DepNodeColor \
294297
insertion for {:?}",
295-
key
296-
);
297-
298-
data.colors.insert(prev_index, color);
299-
}
298+
key
299+
);
300300

301-
(result, dep_node_index)
302-
} else {
303-
// Incremental compilation is turned off. We just execute the task
304-
// without tracking. We still provide a dep-node index that uniquely
305-
// identifies the task so that we have a cheap way of referring to
306-
// the query for self-profiling.
307-
(task(cx, arg), self.next_virtual_depnode_index())
301+
data.colors.insert(prev_index, color);
308302
}
303+
304+
(result, dep_node_index)
309305
}
310306

311307
/// Executes something within an "anonymous" task, that is, a task the
@@ -372,19 +368,6 @@ impl<K: DepKind> DepGraph<K> {
372368
}
373369
}
374370

375-
/// Executes something within an "eval-always" task which is a task
376-
/// that runs whenever anything changes.
377-
pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
378-
&self,
379-
key: DepNode<K>,
380-
cx: Ctxt,
381-
arg: A,
382-
task: fn(Ctxt, A) -> R,
383-
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
384-
) -> (R, DepNodeIndex) {
385-
self.with_task_impl(key, cx, arg, task, |_| None, hash_result)
386-
}
387-
388371
#[inline]
389372
pub fn read_index(&self, dep_node_index: DepNodeIndex) {
390373
if let Some(ref data) = self.data {

compiler/rustc_query_system/src/query/plumbing.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -491,23 +491,13 @@ where
491491
// `to_dep_node` is expensive for some `DepKind`s.
492492
let dep_node = dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key));
493493

494-
if query.eval_always {
495-
tcx.dep_context().dep_graph().with_eval_always_task(
496-
dep_node,
497-
*tcx.dep_context(),
498-
key,
499-
compute,
500-
query.hash_result,
501-
)
502-
} else {
503-
tcx.dep_context().dep_graph().with_task(
504-
dep_node,
505-
*tcx.dep_context(),
506-
key,
507-
compute,
508-
query.hash_result,
509-
)
510-
}
494+
tcx.dep_context().dep_graph().with_task(
495+
dep_node,
496+
*tcx.dep_context(),
497+
key,
498+
compute,
499+
query.hash_result,
500+
)
511501
});
512502

513503
prof_timer.finish_with_query_invocation_id(dep_node_index.into());

0 commit comments

Comments
 (0)