Skip to content

Commit f12bdf2

Browse files
committed
Monomorphise try_start.
1 parent 3e259b9 commit f12bdf2

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/librustc/ty/query/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) struct QueryVtable<'tcx, K, V> {
3636
pub compute: fn(TyCtxt<'tcx>, K) -> V,
3737

3838
pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
39+
pub handle_cycle_error: fn(TyCtxt<'tcx>, CycleError<'tcx>) -> V,
3940
pub cache_on_disk: fn(TyCtxt<'tcx>, K, Option<&V>) -> bool,
4041
pub try_load_from_disk: fn(TyCtxt<'tcx>, SerializedDepNodeIndex) -> Option<V>,
4142
}
@@ -53,6 +54,10 @@ impl<'tcx, K, V> QueryVtable<'tcx, K, V> {
5354
(self.hash_result)(hcx, value)
5455
}
5556

57+
pub(crate) fn handle_cycle_error(&self, tcx: TyCtxt<'tcx>, error: CycleError<'tcx>) -> V {
58+
(self.handle_cycle_error)(tcx, error)
59+
}
60+
5661
pub(crate) fn cache_on_disk(&self, tcx: TyCtxt<'tcx>, key: K, value: Option<&V>) -> bool {
5762
(self.cache_on_disk)(tcx, key, value)
5863
}
@@ -106,6 +111,7 @@ pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
106111
name: Self::NAME,
107112
compute: Self::COMPUTE_FN,
108113
hash_result: Self::hash_result,
114+
handle_cycle_error: Self::handle_cycle_error,
109115
cache_on_disk: Self::cache_on_disk,
110116
try_load_from_disk: Self::try_load_from_disk,
111117
};

src/librustc/ty/query/plumbing.rs

+28-22
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,14 @@ where
175175
/// This function is inlined because that results in a noticeable speed-up
176176
/// for some compile-time benchmarks.
177177
#[inline(always)]
178-
pub(super) fn try_start<Q>(
178+
pub(super) fn try_start(
179179
tcx: TyCtxt<'tcx>,
180+
state: &'tcx QueryState<'tcx, C>,
180181
span: Span,
181182
key: &C::Key,
182183
mut lookup: QueryLookup<'tcx, C::Key, C::Sharded>,
183-
) -> TryGetJob<'tcx, C>
184-
where
185-
Q: QueryDescription<'tcx, Key = C::Key, Value = C::Value, Cache = C>,
186-
{
184+
query: &QueryVtable<'tcx, C::Key, C::Value>,
185+
) -> TryGetJob<'tcx, C> {
187186
let lock = &mut *lookup.lock;
188187

189188
let (latch, mut _query_blocked_prof_timer) = match lock.active.entry((*key).clone()) {
@@ -200,7 +199,7 @@ where
200199
};
201200

202201
// Create the id of the job we're waiting for
203-
let id = QueryJobId::new(job.id, lookup.shard, Q::DEP_KIND);
202+
let id = QueryJobId::new(job.id, lookup.shard, query.dep_kind);
204203

205204
(job.latch(id), _query_blocked_prof_timer)
206205
}
@@ -215,14 +214,13 @@ where
215214
lock.jobs = id;
216215
let id = QueryShardJobId(NonZeroU32::new(id).unwrap());
217216

218-
let global_id = QueryJobId::new(id, lookup.shard, Q::DEP_KIND);
217+
let global_id = QueryJobId::new(id, lookup.shard, query.dep_kind);
219218

220219
let job = tls::with_related_context(tcx, |icx| QueryJob::new(id, span, icx.query));
221220

222221
entry.insert(QueryResult::Started(job));
223222

224-
let owner =
225-
JobOwner { state: Q::query_state(tcx), id: global_id, key: (*key).clone() };
223+
let owner = JobOwner { state, id: global_id, key: (*key).clone() };
226224
return TryGetJob::NotYetStarted(owner);
227225
}
228226
};
@@ -232,7 +230,7 @@ where
232230
// so we just return the error.
233231
#[cfg(not(parallel_compiler))]
234232
return TryGetJob::Cycle(cold_path(|| {
235-
Q::handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span))
233+
query.handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span))
236234
}));
237235

238236
// With parallel queries we might just have to wait on some other
@@ -242,11 +240,11 @@ where
242240
let result = latch.wait_on(tcx, span);
243241

244242
if let Err(cycle) = result {
245-
return TryGetJob::Cycle(Q::handle_cycle_error(tcx, cycle));
243+
return TryGetJob::Cycle(query.handle_cycle_error(tcx, cycle));
246244
}
247245

248246
let cached = tcx.try_get_cached(
249-
Q::query_state(self),
247+
state,
250248
(*key).clone(),
251249
|value, index| (value.clone(), index),
252250
|_, _| panic!("value must be in cache after waiting"),
@@ -531,15 +529,16 @@ impl<'tcx> TyCtxt<'tcx> {
531529
key: Q::Key,
532530
lookup: QueryLookup<'tcx, Q::Key, <Q::Cache as QueryCache>::Sharded>,
533531
) -> Q::Value {
534-
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
535-
TryGetJob::NotYetStarted(job) => job,
536-
TryGetJob::Cycle(result) => return result,
537-
#[cfg(parallel_compiler)]
538-
TryGetJob::JobCompleted((v, index)) => {
539-
self.dep_graph.read_index(index);
540-
return v;
541-
}
542-
};
532+
let job =
533+
match JobOwner::try_start(self, Q::query_state(self), span, &key, lookup, &Q::VTABLE) {
534+
TryGetJob::NotYetStarted(job) => job,
535+
TryGetJob::Cycle(result) => return result,
536+
#[cfg(parallel_compiler)]
537+
TryGetJob::JobCompleted((v, index)) => {
538+
self.dep_graph.read_index(index);
539+
return v;
540+
}
541+
};
543542

544543
// Fast path for when incr. comp. is off. `to_dep_node` is
545544
// expensive for some `DepKind`s.
@@ -826,7 +825,14 @@ impl<'tcx> TyCtxt<'tcx> {
826825
// Cache hit, do nothing
827826
},
828827
|key, lookup| {
829-
let job = match JobOwner::try_start::<Q>(self, span, &key, lookup) {
828+
let job = match JobOwner::try_start(
829+
self,
830+
Q::query_state(self),
831+
span,
832+
&key,
833+
lookup,
834+
&Q::VTABLE,
835+
) {
830836
TryGetJob::NotYetStarted(job) => job,
831837
TryGetJob::Cycle(_) => return,
832838
#[cfg(parallel_compiler)]

0 commit comments

Comments
 (0)