From 1c7376e7979ee8179c030d101af2d7919369caa7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 7 Mar 2020 17:32:07 +0100 Subject: [PATCH] Monomorphise try_start. --- src/librustc_query_system/query/config.rs | 6 ++++ src/librustc_query_system/query/plumbing.rs | 38 +++++++++++---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/librustc_query_system/query/config.rs b/src/librustc_query_system/query/config.rs index baf9ca9df7f..48fbdfb153e 100644 --- a/src/librustc_query_system/query/config.rs +++ b/src/librustc_query_system/query/config.rs @@ -33,6 +33,7 @@ pub(crate) struct QueryVtable { pub compute: fn(CTX, K) -> V, pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option, + pub handle_cycle_error: fn(CTX, CycleError) -> V, pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool, pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option, } @@ -50,6 +51,10 @@ impl QueryVtable { (self.hash_result)(hcx, value) } + pub(crate) fn handle_cycle_error(&self, tcx: CTX, error: CycleError) -> V { + (self.handle_cycle_error)(tcx, error) + } + pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool { (self.cache_on_disk)(tcx, key, value) } @@ -110,6 +115,7 @@ where eval_always: Q::EVAL_ALWAYS, compute: Q::compute, hash_result: Q::hash_result, + handle_cycle_error: Q::handle_cycle_error, cache_on_disk: Q::cache_on_disk, try_load_from_disk: Q::try_load_from_disk, }; diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index f27c508fccf..ff01538d95e 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -168,14 +168,15 @@ where /// This function is inlined because that results in a noticeable speed-up /// for some compile-time benchmarks. #[inline(always)] - fn try_start<'a, 'b, Q>( + fn try_start<'a, 'b>( tcx: CTX, + state: &'b QueryState, span: Span, key: &C::Key, mut lookup: QueryLookup<'a, CTX, C::Key, C::Sharded>, + query: &QueryVtable, ) -> TryGetJob<'b, CTX, C> where - Q: QueryDescription, CTX: QueryContext, { let lock = &mut *lookup.lock; @@ -194,7 +195,7 @@ where }; // Create the id of the job we're waiting for - let id = QueryJobId::new(job.id, lookup.shard, Q::DEP_KIND); + let id = QueryJobId::new(job.id, lookup.shard, query.dep_kind); (job.latch(id), _query_blocked_prof_timer) } @@ -209,15 +210,14 @@ where lock.jobs = id; let id = QueryShardJobId(NonZeroU32::new(id).unwrap()); - let global_id = QueryJobId::new(id, lookup.shard, Q::DEP_KIND); + let global_id = QueryJobId::new(id, lookup.shard, query.dep_kind); let job = tcx.current_query_job(); let job = QueryJob::new(id, span, job); entry.insert(QueryResult::Started(job)); - let owner = - JobOwner { state: Q::query_state(tcx), id: global_id, key: (*key).clone() }; + let owner = JobOwner { state, id: global_id, key: (*key).clone() }; return TryGetJob::NotYetStarted(owner); } }; @@ -227,8 +227,8 @@ where // so we just return the error. #[cfg(not(parallel_compiler))] return TryGetJob::Cycle(cold_path(|| { - let value = Q::handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span)); - Q::query_state(tcx).cache.store_nocache(value) + let value = query.handle_cycle_error(tcx, latch.find_cycle_in_stack(tcx, span)); + state.cache.store_nocache(value) })); // With parallel queries we might just have to wait on some other @@ -238,14 +238,14 @@ where let result = latch.wait_on(tcx, span); if let Err(cycle) = result { - let value = Q::handle_cycle_error(tcx, cycle); - let value = Q::query_state(tcx).cache.store_nocache(value); + let value = query.handle_cycle_error(tcx, cycle); + let value = state.cache.store_nocache(value); return TryGetJob::Cycle(value); } let cached = try_get_cached( tcx, - Q::query_state(tcx), + state, (*key).clone(), |value, index| (value.clone(), index), |_, _| panic!("value must be in cache after waiting"), @@ -392,7 +392,7 @@ where Q: QueryDescription, CTX: QueryContext, { - let job = match JobOwner::try_start::(tcx, span, &key, lookup) { + let job = match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) { TryGetJob::NotYetStarted(job) => job, TryGetJob::Cycle(result) => return result, #[cfg(parallel_compiler)] @@ -697,12 +697,14 @@ where // Cache hit, do nothing }, |key, lookup| { - let job = match JobOwner::try_start::(tcx, span, &key, lookup) { - TryGetJob::NotYetStarted(job) => job, - TryGetJob::Cycle(_) => return, - #[cfg(parallel_compiler)] - TryGetJob::JobCompleted(_) => return, - }; + let job = + match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) + { + TryGetJob::NotYetStarted(job) => job, + TryGetJob::Cycle(_) => return, + #[cfg(parallel_compiler)] + TryGetJob::JobCompleted(_) => return, + }; force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE); }, );