Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 88531f4

Browse files
committedDec 11, 2018
Refactor task system for efficiency
1 parent 3499575 commit 88531f4

File tree

4 files changed

+240
-199
lines changed

4 files changed

+240
-199
lines changed
 

‎src/librustc/dep_graph/graph.rs

+188-139
Original file line numberDiff line numberDiff line change
@@ -202,196 +202,245 @@ impl DepGraph {
202202
arg: A,
203203
task: fn(C, A) -> R)
204204
-> (R, DepNodeIndex)
205-
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
205+
where C: DepGraphSafe + StableHashingContextProvider<'gcx> + Clone,
206206
R: HashStable<StableHashingContext<'gcx>>,
207207
{
208-
self.with_task_impl(key, cx, arg, false, task,
209-
|key| OpenTask::Regular(Lock::new(RegularOpenTask {
208+
if let Some(ref data) = self.data {
209+
let open_task = OpenTask::Regular(Lock::new(RegularOpenTask {
210210
node: key,
211211
reads: SmallVec::new(),
212212
read_set: Default::default(),
213-
})),
214-
|data, key, task| data.borrow_mut().complete_task(key, task))
213+
}));
214+
let result = ty::tls::with_context(|icx| {
215+
let icx = ty::tls::ImplicitCtxt {
216+
task: &open_task,
217+
..icx.clone()
218+
};
219+
220+
ty::tls::enter_context(&icx, |_| {
221+
task(cx.clone(), arg)
222+
})
223+
});
224+
let dep_node_index = data.current.borrow_mut().complete_task(key, open_task);
225+
self.finish_task_incr_on(data, key, cx, &result, dep_node_index);
226+
(result, dep_node_index)
227+
} else {
228+
let result = task(cx.clone(), arg);
229+
self.finish_task_incr_off(key, cx, &result);
230+
(result, DepNodeIndex::INVALID)
231+
}
215232
}
216233

217-
/// Creates a new dep-graph input with value `input`
218-
pub fn input_task<'gcx, C, R>(&self,
219-
key: DepNode,
220-
cx: C,
221-
input: R)
222-
-> (R, DepNodeIndex)
223-
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
224-
R: HashStable<StableHashingContext<'gcx>>,
234+
/// Execute something within an "eval-always" task which is a task
235+
// that runs whenever anything changes.
236+
// FIXME: Find a way to make F: DepGraphSafe
237+
pub fn with_eval_always_task<'a, F, R>(
238+
&self,
239+
tcx: TyCtxt<'a, '_, '_>,
240+
key: DepNode,
241+
task: F,
242+
) -> (R, DepNodeIndex)
243+
where F: FnOnce(&OpenTask) -> R,
244+
R: HashStable<StableHashingContext<'a>>,
225245
{
226-
fn identity_fn<C, A>(_: C, arg: A) -> A {
227-
arg
246+
if let Some(ref data) = self.data {
247+
let open_task = OpenTask::EvalAlways { node: key };
248+
let result = task(&open_task);
249+
let dep_node_index = data.current.borrow_mut()
250+
.complete_eval_always_task(key, open_task);
251+
self.finish_task_incr_on(data, key, tcx, &result, dep_node_index);
252+
(result, dep_node_index)
253+
} else {
254+
debug_assert!(!key.kind.fingerprint_needed_for_crate_hash());
255+
(task(&OpenTask::Ignore), DepNodeIndex::INVALID)
228256
}
257+
}
229258

230-
self.with_task_impl(key, cx, input, true, identity_fn,
231-
|_| OpenTask::Ignore,
232-
|data, key, _| data.borrow_mut().alloc_node(key, SmallVec::new()))
259+
// FIXME: Merge with with_task?
260+
pub fn with_query_task<'a, F, R>(
261+
&self,
262+
tcx: TyCtxt<'a, '_, '_>,
263+
key: DepNode,
264+
task: F,
265+
) -> (R, DepNodeIndex)
266+
where F: FnOnce(&OpenTask) -> R,
267+
R: HashStable<StableHashingContext<'a>>,
268+
{
269+
if let Some(ref data) = self.data {
270+
let open_task = OpenTask::Regular(Lock::new(RegularOpenTask {
271+
node: key,
272+
reads: SmallVec::new(),
273+
read_set: Default::default(),
274+
}));
275+
let result = task(&open_task);
276+
// FIXME: Look at `complete_task` and the same for other functions
277+
let dep_node_index = data.current.borrow_mut().complete_task(key, open_task);
278+
self.finish_task_incr_on(data, key, tcx, &result, dep_node_index);
279+
(result, dep_node_index)
280+
} else {
281+
debug_assert!(!key.kind.fingerprint_needed_for_crate_hash());
282+
// with_task runs finish_task_incr_off here
283+
(task(&OpenTask::Ignore), DepNodeIndex::INVALID)
284+
}
285+
}
286+
287+
/// Creates a new dep-graph input with value `input`
288+
pub fn input_dep_index<'gcx, R>(
289+
&self,
290+
key: DepNode,
291+
cx: &StableHashingContext<'gcx>,
292+
input: &R
293+
) -> DepNodeIndex
294+
where R: HashStable<StableHashingContext<'gcx>>,
295+
{
296+
// This assumes that we don't have an ImplicitCtxt and thus have
297+
// an implicit OpenTask::Ignore task
298+
debug_assert!(ty::tls::with_opt(|tcx| tcx.is_none()));
299+
300+
if let Some(ref data) = self.data {
301+
let dep_node_index = data.current.borrow_mut().alloc_node(key, SmallVec::new());
302+
self.finish_task_incr_on(data, key, cx, input, dep_node_index);
303+
dep_node_index
304+
} else {
305+
self.finish_task_incr_off(key, cx, input)
306+
}
233307
}
234308

235-
fn with_task_impl<'gcx, C, A, R>(
309+
fn finish_task_incr_on<'gcx, C, R>(
236310
&self,
311+
data: &DepGraphData,
237312
key: DepNode,
238313
cx: C,
239-
arg: A,
240-
no_tcx: bool,
241-
task: fn(C, A) -> R,
242-
create_task: fn(DepNode) -> OpenTask,
243-
finish_task_and_alloc_depnode: fn(&Lock<CurrentDepGraph>,
244-
DepNode,
245-
OpenTask) -> DepNodeIndex
246-
) -> (R, DepNodeIndex)
314+
result: &R,
315+
dep_node_index: DepNodeIndex,
316+
)
247317
where
248318
C: DepGraphSafe + StableHashingContextProvider<'gcx>,
249319
R: HashStable<StableHashingContext<'gcx>>,
250320
{
251-
if let Some(ref data) = self.data {
252-
let open_task = create_task(key);
321+
// In incremental mode, hash the result of the task. We don't
322+
// do anything with the hash yet, but we are computing it
323+
// anyway so that
324+
// - we make sure that the infrastructure works and
325+
// - we can get an idea of the runtime cost.
326+
let mut hcx = cx.get_stable_hashing_context();
327+
328+
if cfg!(debug_assertions) {
329+
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
330+
};
253331

254-
// In incremental mode, hash the result of the task. We don't
255-
// do anything with the hash yet, but we are computing it
256-
// anyway so that
257-
// - we make sure that the infrastructure works and
258-
// - we can get an idea of the runtime cost.
259-
let mut hcx = cx.get_stable_hashing_context();
332+
if cfg!(debug_assertions) {
333+
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd)
334+
};
260335

261-
if cfg!(debug_assertions) {
262-
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
263-
};
336+
let mut stable_hasher = StableHasher::new();
337+
result.hash_stable(&mut hcx, &mut stable_hasher);
264338

265-
let result = if no_tcx {
266-
task(cx, arg)
267-
} else {
268-
ty::tls::with_context(|icx| {
269-
let icx = ty::tls::ImplicitCtxt {
270-
task: &open_task,
271-
..icx.clone()
272-
};
273-
274-
ty::tls::enter_context(&icx, |_| {
275-
task(cx, arg)
276-
})
277-
})
278-
};
339+
let current_fingerprint = stable_hasher.finish();
279340

280-
if cfg!(debug_assertions) {
281-
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd)
282-
};
341+
// Store the current fingerprint
342+
{
343+
let mut fingerprints = self.fingerprints.borrow_mut();
283344

284-
let dep_node_index = finish_task_and_alloc_depnode(&data.current, key, open_task);
345+
if dep_node_index.index() >= fingerprints.len() {
346+
fingerprints.resize(dep_node_index.index() + 1, Fingerprint::ZERO);
347+
}
285348

286-
let mut stable_hasher = StableHasher::new();
287-
result.hash_stable(&mut hcx, &mut stable_hasher);
349+
debug_assert!(fingerprints[dep_node_index] == Fingerprint::ZERO,
350+
"DepGraph::with_task() - Duplicate fingerprint \
351+
insertion for {:?}", key);
352+
fingerprints[dep_node_index] = current_fingerprint;
353+
}
288354

289-
let current_fingerprint = stable_hasher.finish();
355+
// Determine the color of the new DepNode.
356+
if let Some(prev_index) = data.previous.node_to_index_opt(&key) {
357+
let prev_fingerprint = data.previous.fingerprint_by_index(prev_index);
290358

291-
// Store the current fingerprint
292-
{
293-
let mut fingerprints = self.fingerprints.borrow_mut();
359+
let color = if current_fingerprint == prev_fingerprint {
360+
DepNodeColor::Green(dep_node_index)
361+
} else {
362+
DepNodeColor::Red
363+
};
294364

295-
if dep_node_index.index() >= fingerprints.len() {
296-
fingerprints.resize(dep_node_index.index() + 1, Fingerprint::ZERO);
297-
}
365+
let mut colors = data.colors.borrow_mut();
366+
debug_assert!(colors.get(prev_index).is_none(),
367+
"DepGraph::with_task() - Duplicate DepNodeColor \
368+
insertion for {:?}", key);
298369

299-
debug_assert!(fingerprints[dep_node_index] == Fingerprint::ZERO,
300-
"DepGraph::with_task() - Duplicate fingerprint \
301-
insertion for {:?}", key);
302-
fingerprints[dep_node_index] = current_fingerprint;
303-
}
370+
colors.insert(prev_index, color);
371+
}
372+
}
304373

305-
// Determine the color of the new DepNode.
306-
if let Some(prev_index) = data.previous.node_to_index_opt(&key) {
307-
let prev_fingerprint = data.previous.fingerprint_by_index(prev_index);
374+
fn finish_task_incr_off<'gcx, C, R>(
375+
&self,
376+
key: DepNode,
377+
cx: C,
378+
result: &R,
379+
) -> DepNodeIndex
380+
where
381+
C: DepGraphSafe + StableHashingContextProvider<'gcx>,
382+
R: HashStable<StableHashingContext<'gcx>>,
383+
{
384+
debug_assert!(self.data.is_none());
308385

309-
let color = if current_fingerprint == prev_fingerprint {
310-
DepNodeColor::Green(dep_node_index)
311-
} else {
312-
DepNodeColor::Red
313-
};
386+
if key.kind.fingerprint_needed_for_crate_hash() {
387+
let mut hcx = cx.get_stable_hashing_context();
388+
let mut stable_hasher = StableHasher::new();
389+
result.hash_stable(&mut hcx, &mut stable_hasher);
390+
let fingerprint = stable_hasher.finish();
314391

315-
let mut colors = data.colors.borrow_mut();
316-
debug_assert!(colors.get(prev_index).is_none(),
317-
"DepGraph::with_task() - Duplicate DepNodeColor \
318-
insertion for {:?}", key);
392+
let mut fingerprints = self.fingerprints.borrow_mut();
393+
let dep_node_index = DepNodeIndex::new(fingerprints.len());
394+
fingerprints.push(fingerprint);
319395

320-
colors.insert(prev_index, color);
321-
}
396+
debug_assert!(fingerprints[dep_node_index] == fingerprint,
397+
"DepGraph::with_task() - Assigned fingerprint to \
398+
unexpected index for {:?}", key);
322399

323-
(result, dep_node_index)
400+
dep_node_index
324401
} else {
325-
if key.kind.fingerprint_needed_for_crate_hash() {
326-
let mut hcx = cx.get_stable_hashing_context();
327-
let result = task(cx, arg);
328-
let mut stable_hasher = StableHasher::new();
329-
result.hash_stable(&mut hcx, &mut stable_hasher);
330-
let fingerprint = stable_hasher.finish();
331-
332-
let mut fingerprints = self.fingerprints.borrow_mut();
333-
let dep_node_index = DepNodeIndex::new(fingerprints.len());
334-
fingerprints.push(fingerprint);
335-
336-
debug_assert!(fingerprints[dep_node_index] == fingerprint,
337-
"DepGraph::with_task() - Assigned fingerprint to \
338-
unexpected index for {:?}", key);
339-
340-
(result, dep_node_index)
341-
} else {
342-
(task(cx, arg), DepNodeIndex::INVALID)
343-
}
402+
DepNodeIndex::INVALID
344403
}
345404
}
346405

347406
/// Execute something within an "anonymous" task, that is, a task the
348407
/// DepNode of which is determined by the list of inputs it read from.
349-
pub fn with_anon_task<OP,R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeIndex)
350-
where OP: FnOnce() -> R
408+
pub fn with_anon_open_task<OP,R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeIndex)
409+
where OP: FnOnce(&OpenTask) -> R
351410
{
352411
if let Some(ref data) = self.data {
353-
let (result, open_task) = ty::tls::with_context(|icx| {
354-
let task = OpenTask::Anon(Lock::new(AnonOpenTask {
355-
reads: SmallVec::new(),
356-
read_set: Default::default(),
357-
}));
358-
359-
let r = {
360-
let icx = ty::tls::ImplicitCtxt {
361-
task: &task,
362-
..icx.clone()
363-
};
364-
365-
ty::tls::enter_context(&icx, |_| {
366-
op()
367-
})
368-
};
412+
let task = OpenTask::Anon(Lock::new(AnonOpenTask {
413+
reads: SmallVec::new(),
414+
read_set: Default::default(),
415+
}));
369416

370-
(r, task)
371-
});
417+
let result = op(&task);
372418
let dep_node_index = data.current
373419
.borrow_mut()
374-
.pop_anon_task(dep_kind, open_task);
420+
.pop_anon_task(dep_kind, task);
375421
(result, dep_node_index)
376422
} else {
377-
(op(), DepNodeIndex::INVALID)
423+
(op(&OpenTask::Ignore), DepNodeIndex::INVALID)
378424
}
379425
}
380426

381-
/// Execute something within an "eval-always" task which is a task
382-
// that runs whenever anything changes.
383-
pub fn with_eval_always_task<'gcx, C, A, R>(&self,
384-
key: DepNode,
385-
cx: C,
386-
arg: A,
387-
task: fn(C, A) -> R)
388-
-> (R, DepNodeIndex)
389-
where C: DepGraphSafe + StableHashingContextProvider<'gcx>,
390-
R: HashStable<StableHashingContext<'gcx>>,
427+
/// Execute something within an "anonymous" task, that is, a task the
428+
/// DepNode of which is determined by the list of inputs it read from.
429+
pub fn with_anon_task<OP,R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeIndex)
430+
where OP: FnOnce() -> R
391431
{
392-
self.with_task_impl(key, cx, arg, false, task,
393-
|key| OpenTask::EvalAlways { node: key },
394-
|data, key, task| data.borrow_mut().complete_eval_always_task(key, task))
432+
self.with_anon_open_task(dep_kind, |task| {
433+
ty::tls::with_context(|icx| {
434+
let icx = ty::tls::ImplicitCtxt {
435+
task,
436+
..icx.clone()
437+
};
438+
439+
ty::tls::enter_context(&icx, |_| {
440+
op()
441+
})
442+
})
443+
})
395444
}
396445

397446
#[inline]

‎src/librustc/hir/map/collector.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
8383
body_ids: _,
8484
} = *krate;
8585

86-
root_mod_sig_dep_index = dep_graph.input_task(
86+
root_mod_sig_dep_index = dep_graph.input_dep_index(
8787
root_mod_def_path_hash.to_dep_node(DepKind::Hir),
8888
&hcx,
89-
HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
90-
).1;
91-
root_mod_full_dep_index = dep_graph.input_task(
89+
&HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
90+
);
91+
root_mod_full_dep_index = dep_graph.input_dep_index(
9292
root_mod_def_path_hash.to_dep_node(DepKind::HirBody),
9393
&hcx,
94-
HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
95-
).1;
94+
&HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
95+
);
9696
}
9797

9898
{
99-
dep_graph.input_task(
99+
dep_graph.input_dep_index(
100100
DepNode::new_no_params(DepKind::AllLocalTraitImpls),
101101
&hcx,
102102
&krate.trait_impls,
@@ -169,11 +169,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
169169

170170
source_file_names.sort_unstable();
171171

172-
let (_, crate_dep_node_index) = self
172+
let crate_dep_node_index = self
173173
.dep_graph
174-
.input_task(DepNode::new_no_params(DepKind::Krate),
174+
.input_dep_index(DepNode::new_no_params(DepKind::Krate),
175175
&self.hcx,
176-
(((node_hashes, upstream_crates), source_file_names),
176+
&(((node_hashes, upstream_crates), source_file_names),
177177
(commandline_args_hash,
178178
crate_disambiguator.to_fingerprint())));
179179

@@ -261,17 +261,17 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
261261

262262
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
263263

264-
self.current_signature_dep_index = self.dep_graph.input_task(
264+
self.current_signature_dep_index = self.dep_graph.input_dep_index(
265265
def_path_hash.to_dep_node(DepKind::Hir),
266266
&self.hcx,
267-
HirItemLike { item_like, hash_bodies: false },
268-
).1;
267+
&HirItemLike { item_like, hash_bodies: false },
268+
);
269269

270-
self.current_full_dep_index = self.dep_graph.input_task(
270+
self.current_full_dep_index = self.dep_graph.input_dep_index(
271271
def_path_hash.to_dep_node(DepKind::HirBody),
272272
&self.hcx,
273-
HirItemLike { item_like, hash_bodies: true },
274-
).1;
273+
&HirItemLike { item_like, hash_bodies: true },
274+
);
275275

276276
self.hir_body_nodes.push((def_path_hash, self.current_full_dep_index));
277277

‎src/librustc/ty/query/job.rs

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ impl<'tcx> QueryJob<'tcx> {
7979
}
8080
}
8181

82+
pub fn extract_diagnostics(&self) -> Vec<Diagnostic> {
83+
mem::replace(&mut *self.diagnostics.lock(), Vec::new())
84+
}
85+
8286
/// Awaits for the query job to complete.
8387
///
8488
/// For single threaded rustc there's no concurrent jobs running, so if we are waiting for any

‎src/librustc/ty/query/plumbing.rs

+32-44
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
//! that generate the actual methods on tcx which find and execute the
1313
//! provider, manage the caches, and so forth.
1414
15-
use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
15+
use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor, OpenTask};
1616
use errors::DiagnosticBuilder;
1717
use errors::Level;
18-
use errors::Diagnostic;
1918
use errors::FatalError;
2019
use ty::tls;
2120
use ty::{TyCtxt};
@@ -30,6 +29,7 @@ use rustc_data_structures::fx::{FxHashMap};
3029
use rustc_data_structures::sync::{Lrc, Lock};
3130
use std::mem;
3231
use std::ptr;
32+
use std::intrinsics::unlikely;
3333
use std::collections::hash_map::Entry;
3434
use syntax_pos::Span;
3535
use syntax::source_map::DUMMY_SP;
@@ -183,36 +183,33 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
183183
/// Executes a job by changing the ImplicitCtxt to point to the
184184
/// new query job while it executes. It returns the diagnostics
185185
/// captured during execution and the actual result.
186-
pub(super) fn start<'lcx, F, R>(
186+
pub(super) fn with_context<'lcx, F, R>(
187187
&self,
188188
tcx: TyCtxt<'_, 'tcx, 'lcx>,
189+
task: &OpenTask,
189190
compute: F)
190-
-> (R, Vec<Diagnostic>)
191+
-> R
191192
where
192193
F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'lcx>) -> R
193194
{
194195
// The TyCtxt stored in TLS has the same global interner lifetime
195196
// as `tcx`, so we use `with_related_context` to relate the 'gcx lifetimes
196197
// when accessing the ImplicitCtxt
197-
let r = tls::with_related_context(tcx, move |current_icx| {
198+
tls::with_related_context(tcx, move |current_icx| {
198199
// Update the ImplicitCtxt to point to our new query job
199200
let new_icx = tls::ImplicitCtxt {
200201
tcx,
201202
query: Some(self.job.clone()),
203+
// FIXME: Remove `layout_depth` to avoid accessing ImplicitCtxt here
202204
layout_depth: current_icx.layout_depth,
203-
task: current_icx.task,
205+
task,
204206
};
205207

206208
// Use the ImplicitCtxt while we execute the query
207209
tls::enter_context(&new_icx, |_| {
208210
compute(tcx)
209211
})
210-
});
211-
212-
// Extract the diagnostic from the job
213-
let diagnostics = mem::replace(&mut *self.job.diagnostics.lock(), Vec::new());
214-
215-
(r, diagnostics)
212+
})
216213
}
217214
}
218215

@@ -389,20 +386,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
389386
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
390387
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
391388

392-
let res = job.start(self, |tcx| {
393-
tcx.dep_graph.with_anon_task(dep_node.kind, || {
394-
Q::compute(tcx.global_tcx(), key)
395-
})
389+
let res = self.dep_graph.with_anon_open_task(dep_node.kind, |open_task| {
390+
job.with_context(self, open_task, |tcx | Q::compute(tcx.global_tcx(), key))
396391
});
397392

398393
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
399394
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
400-
let ((result, dep_node_index), diagnostics) = res;
395+
let (result, dep_node_index) = res;
401396

402397
self.dep_graph.read_index(dep_node_index);
403398

404399
self.queries.on_disk_cache
405-
.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
400+
.store_diagnostics_for_anon_node(dep_node_index, job.job.extract_diagnostics());
406401

407402
job.complete(&result, dep_node_index);
408403

@@ -472,19 +467,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
472467
// The diagnostics for this query have already been
473468
// promoted to the current session during
474469
// try_mark_green(), so we can ignore them here.
475-
let (result, _) = job.start(self, |tcx| {
476-
// The dep-graph for this computation is already in
477-
// place
478-
tcx.dep_graph.with_ignore(|| {
479-
Q::compute(tcx, key)
480-
})
481-
});
482-
result
470+
// The dep-graph for this computation is already in
471+
// place so we pass OpenTask::Ignore.
472+
job.with_context(self, &OpenTask::Ignore, |tcx| Q::compute(tcx, key))
483473
};
484474

485475
// If -Zincremental-verify-ich is specified, re-hash results from
486476
// the cache and make sure that they have the expected fingerprint.
487-
if self.sess.opts.debugging_opts.incremental_verify_ich {
477+
if unsafe { unlikely(self.sess.opts.debugging_opts.incremental_verify_ich) } {
488478
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
489479
use ich::Fingerprint;
490480

@@ -508,7 +498,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
508498
for {:?}", dep_node);
509499
}
510500

511-
if self.sess.opts.debugging_opts.query_dep_graph {
501+
if unsafe { unlikely(self.sess.opts.debugging_opts.query_dep_graph) } {
512502
self.dep_graph.mark_loaded_from_cache(dep_node_index, true);
513503
}
514504

@@ -517,6 +507,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
517507
Ok(result)
518508
}
519509

510+
// FIXME: Inline this so LLVM can tell what kind of DepNode we are using
511+
#[inline(always)]
520512
fn force_query_with_job<Q: QueryDescription<'gcx>>(
521513
self,
522514
key: Q::Key,
@@ -540,32 +532,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
540532
p.record_query(Q::CATEGORY);
541533
});
542534

543-
let res = job.start(self, |tcx| {
544-
if dep_node.kind.is_eval_always() {
545-
tcx.dep_graph.with_eval_always_task(dep_node,
546-
tcx,
547-
key,
548-
Q::compute)
549-
} else {
550-
tcx.dep_graph.with_task(dep_node,
551-
tcx,
552-
key,
553-
Q::compute)
554-
}
555-
});
535+
let res = if dep_node.kind.is_eval_always() {
536+
self.dep_graph.with_eval_always_task(self, dep_node, |task| {
537+
job.with_context(self, task, |tcx| Q::compute(tcx, key))
538+
})
539+
} else {
540+
self.dep_graph.with_query_task(self, dep_node, |task| {
541+
job.with_context(self, task, |tcx| Q::compute(tcx, key))
542+
})
543+
};
556544

557545
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
558546
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
559547

560-
let ((result, dep_node_index), diagnostics) = res;
548+
let (result, dep_node_index) = res;
561549

562-
if self.sess.opts.debugging_opts.query_dep_graph {
550+
if unsafe { unlikely(self.sess.opts.debugging_opts.query_dep_graph) } {
563551
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
564552
}
565553

566554
if dep_node.kind != ::dep_graph::DepKind::Null {
567555
self.queries.on_disk_cache
568-
.store_diagnostics(dep_node_index, diagnostics);
556+
.store_diagnostics(dep_node_index, job.job.extract_diagnostics());
569557
}
570558

571559
job.complete(&result, dep_node_index);

0 commit comments

Comments
 (0)
Please sign in to comment.