From 4faf701d2028dd6031a3c772ae4b3e844d51c3c3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Mar 2020 07:35:32 +0100 Subject: [PATCH] Remove the QueryGetter trait. --- src/librustc/ty/query/plumbing.rs | 4 +- src/librustc_macros/src/query.rs | 3 +- src/librustc_query_system/query/plumbing.rs | 158 +++++++++----------- 3 files changed, 74 insertions(+), 91 deletions(-) diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index c60fdd2f4fc..0fabacb5f69 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -381,7 +381,7 @@ impl TyCtxtEnsure<$tcx> { $($(#[$attr])* #[inline(always)] pub fn $name(self, key: $K) { - self.tcx.ensure_query::>(key) + ensure_query::, _>(self.tcx, key) })* } @@ -459,7 +459,7 @@ impl TyCtxtAt<$tcx> { $($(#[$attr])* #[inline(always)] pub fn $name(self, key: $K) -> $V { - self.tcx.get_query::>(self.span, key) + get_query::, _>(self.tcx, self.span, key) })* } diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index 57fe8ede9d1..26c3bce4a9a 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -489,7 +489,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { ::rustc::dep_graph::DepKind::#name => { if <#arg as DepNodeParams>>::CAN_RECONSTRUCT_QUERY_KEY { if let Some(key) = <#arg as DepNodeParams>>::recover($tcx, $dep_node) { - $tcx.force_query::>( + force_query::, _>( + $tcx, key, DUMMY_SP, *$dep_node diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index 97b68042039..bec45b29d30 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -606,105 +606,87 @@ fn force_query_with_job( (result, dep_node_index) } -pub trait QueryGetter: QueryContext { - fn get_query>(self, span: Span, key: Q::Key) -> Q::Value; - - /// Ensure that either this query has all green inputs or been executed. - /// Executing `query::ensure(D)` is considered a read of the dep-node `D`. - /// - /// This function is particularly useful when executing passes for their - /// side-effects -- e.g., in order to report errors for erroneous programs. - /// - /// Note: The optimization is only available during incr. comp. - fn ensure_query>(self, key: Q::Key); +#[inline(never)] +pub fn get_query(tcx: CTX, span: Span, key: Q::Key) -> Q::Value +where + Q: QueryDescription, + CTX: QueryContext, +{ + debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span); - fn force_query>( - self, - key: Q::Key, - span: Span, - dep_node: DepNode, - ); + try_get_cached( + tcx, + Q::query_state(tcx), + key, + |value, index| { + tcx.dep_graph().read_index(index); + value.clone() + }, + |key, lookup| try_execute_query::(tcx, span, key, lookup), + ) } -impl QueryGetter for CTX +/// Ensure that either this query has all green inputs or been executed. +/// Executing `query::ensure(D)` is considered a read of the dep-node `D`. +/// +/// This function is particularly useful when executing passes for their +/// side-effects -- e.g., in order to report errors for erroneous programs. +/// +/// Note: The optimization is only available during incr. comp. +pub fn ensure_query(tcx: CTX, key: Q::Key) where + Q: QueryDescription, CTX: QueryContext, { - #[inline(never)] - fn get_query>(self, span: Span, key: Q::Key) -> Q::Value { - debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span); - - try_get_cached( - self, - Q::query_state(self), - key, - |value, index| { - self.dep_graph().read_index(index); - value.clone() - }, - |key, lookup| try_execute_query::(self, span, key, lookup), - ) + if Q::EVAL_ALWAYS { + let _ = get_query::(tcx, DUMMY_SP, key); + return; } - /// Ensure that either this query has all green inputs or been executed. - /// Executing `query::ensure(D)` is considered a read of the dep-node `D`. - /// - /// This function is particularly useful when executing passes for their - /// side-effects -- e.g., in order to report errors for erroneous programs. - /// - /// Note: The optimization is only available during incr. comp. - fn ensure_query>(self, key: Q::Key) { - if Q::EVAL_ALWAYS { - let _ = self.get_query::(DUMMY_SP, key); - return; - } + // Ensuring an anonymous query makes no sense + assert!(!Q::ANON); - // Ensuring an anonymous query makes no sense - assert!(!Q::ANON); - - let dep_node = Q::to_dep_node(self, &key); + let dep_node = Q::to_dep_node(tcx, &key); - match self.dep_graph().try_mark_green_and_read(self, &dep_node) { - None => { - // A None return from `try_mark_green_and_read` means that this is either - // a new dep node or that the dep node has already been marked red. - // Either way, we can't call `dep_graph.read()` as we don't have the - // DepNodeIndex. We must invoke the query itself. The performance cost - // this introduces should be negligible as we'll immediately hit the - // in-memory cache, or another query down the line will. - let _ = self.get_query::(DUMMY_SP, key); - } - Some((_, dep_node_index)) => { - self.profiler().query_cache_hit(dep_node_index.into()); - } + match tcx.dep_graph().try_mark_green_and_read(tcx, &dep_node) { + None => { + // A None return from `try_mark_green_and_read` means that this is either + // a new dep node or that the dep node has already been marked red. + // Either way, we can't call `dep_graph.read()` as we don't have the + // DepNodeIndex. We must invoke the query itself. The performance cost + // this introduces should be negligible as we'll immediately hit the + // in-memory cache, or another query down the line will. + let _ = get_query::(tcx, DUMMY_SP, key); + } + Some((_, dep_node_index)) => { + tcx.profiler().query_cache_hit(dep_node_index.into()); } } +} - fn force_query>( - self, - key: Q::Key, - span: Span, - dep_node: DepNode, - ) { - // We may be concurrently trying both execute and force a query. - // Ensure that only one of them runs the query. - - try_get_cached( - self, - Q::query_state(self), - key, - |_, _| { - // Cache hit, do nothing - }, - |key, lookup| { - let job = match JobOwner::try_start::(self, span, &key, lookup) { - TryGetJob::NotYetStarted(job) => job, - TryGetJob::Cycle(_) => return, - #[cfg(parallel_compiler)] - TryGetJob::JobCompleted(_) => return, - }; - force_query_with_job::(self, key, job, dep_node); - }, - ); - } +pub fn force_query(tcx: CTX, key: Q::Key, span: Span, dep_node: DepNode) +where + Q: QueryDescription, + CTX: QueryContext, +{ + // We may be concurrently trying both execute and force a query. + // Ensure that only one of them runs the query. + + try_get_cached( + tcx, + Q::query_state(tcx), + key, + |_, _| { + // 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, + }; + force_query_with_job::(tcx, key, job, dep_node); + }, + ); } -- 2.44.0