From: Camille GILLOT Date: Sun, 8 Mar 2020 18:42:11 +0000 (+0100) Subject: Make QueryDescription parameter a type. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=57c3177b31ab56fa00ca919ad3154a7c12348b94;p=rust.git Make QueryDescription parameter a type. --- diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index eaa1006791b..e65f3094820 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -5,12 +5,12 @@ use crate::ty::query::caches::QueryCache; use crate::ty::query::plumbing::CycleError; use crate::ty::query::QueryState; -use crate::ty::TyCtxt; use rustc_data_structures::profiling::ProfileCategory; use rustc_hir::def_id::DefId; use crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; +use rustc_session::Session; use std::borrow::Cow; use std::fmt::Debug; use std::hash::Hash; @@ -25,6 +25,12 @@ pub trait QueryConfig { pub trait QueryContext: Copy { type Query; + + /// Access the session. + fn session(&self) -> &Session; + + /// Get string representation from DefPath. + fn def_path_str(&self, def_id: DefId) -> String; } pub(crate) trait QueryAccessors: QueryConfig { @@ -48,26 +54,25 @@ fn hash_result(hcx: &mut StableHashingContext<'_>, result: &Self::Value) fn handle_cycle_error(tcx: CTX, error: CycleError) -> Self::Value; } -pub(crate) trait QueryDescription<'tcx>: QueryAccessors> { - fn describe(tcx: TyCtxt<'_>, key: Self::Key) -> Cow<'static, str>; +pub(crate) trait QueryDescription: QueryAccessors { + fn describe(tcx: CTX, key: Self::Key) -> Cow<'static, str>; #[inline] - fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool { + fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool { false } - fn try_load_from_disk(_: TyCtxt<'tcx>, _: SerializedDepNodeIndex) -> Option { + fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option { bug!("QueryDescription::load_from_disk() called for an unsupported query.") } } -impl<'tcx, M> QueryDescription<'tcx> for M +impl QueryDescription for M where - M: QueryAccessors, Key = DefId>, - //M::Cache: QueryCache, + M: QueryAccessors, { - default fn describe(tcx: TyCtxt<'_>, def_id: DefId) -> Cow<'static, str> { - if !tcx.sess.verbose() { + default fn describe(tcx: CTX, def_id: DefId) -> Cow<'static, str> { + if !tcx.session().verbose() { format!("processing `{}`", tcx.def_path_str(def_id)).into() } else { let name = ::std::any::type_name::(); @@ -75,14 +80,11 @@ impl<'tcx, M> QueryDescription<'tcx> for M } } - default fn cache_on_disk(_: TyCtxt<'tcx>, _: Self::Key, _: Option<&Self::Value>) -> bool { + default fn cache_on_disk(_: CTX, _: Self::Key, _: Option<&Self::Value>) -> bool { false } - default fn try_load_from_disk( - _: TyCtxt<'tcx>, - _: SerializedDepNodeIndex, - ) -> Option { + default fn try_load_from_disk(_: CTX, _: SerializedDepNodeIndex) -> Option { bug!("QueryDescription::load_from_disk() called for an unsupported query.") } } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 155f792bd9d..14839e6ad50 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -994,7 +994,8 @@ fn encode_query_results<'a, 'tcx, Q, E>( query_result_index: &mut EncodedQueryResultIndex, ) -> Result<(), E::Error> where - Q: super::config::QueryDescription<'tcx, Value: Encodable>, + Q: super::config::QueryDescription>, + Q::Value: Encodable, E: 'a + TyEncoder, { let _timer = tcx diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 6506e1f83b4..c0f2c4a11bc 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -17,6 +17,8 @@ use rustc_data_structures::sync::{Lock, LockGuard}; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; +use rustc_session::Session; +use rustc_span::def_id::DefId; use rustc_span::source_map::DUMMY_SP; use rustc_span::Span; use std::collections::hash_map::Entry; @@ -181,7 +183,7 @@ fn try_start( mut lookup: QueryLookup<'tcx, TyCtxt<'tcx>, C::Key, C::Sharded>, ) -> TryGetJob<'tcx, C> where - Q: QueryDescription<'tcx, Key = C::Key, Value = C::Value, Cache = C>, + Q: QueryDescription, Key = C::Key, Value = C::Value, Cache = C>, { let lock = &mut *lookup.lock; @@ -356,6 +358,14 @@ enum TryGetJob<'tcx, C: QueryCache> impl QueryContext for TyCtxt<'tcx> { type Query = Query<'tcx>; + + fn session(&self) -> &Session { + &self.sess + } + + fn def_path_str(&self, def_id: DefId) -> String { + TyCtxt::def_path_str(*self, def_id) + } } impl<'tcx> TyCtxt<'tcx> { @@ -517,7 +527,7 @@ fn try_get_cached( } #[inline(never)] - pub(super) fn get_query + 'tcx>( + pub(super) fn get_query> + 'tcx>( self, span: Span, key: Q::Key, @@ -536,7 +546,7 @@ pub(super) fn get_query + 'tcx>( } #[inline(always)] - fn try_execute_query + 'tcx>( + fn try_execute_query> + 'tcx>( self, span: Span, key: Q::Key, @@ -614,7 +624,7 @@ fn try_execute_query + 'tcx>( result } - fn load_from_disk_and_cache_in_memory>( + fn load_from_disk_and_cache_in_memory>>( self, key: Q::Key, prev_dep_node_index: SerializedDepNodeIndex, @@ -671,7 +681,7 @@ fn load_from_disk_and_cache_in_memory>( #[inline(never)] #[cold] - fn incremental_verify_ich>( + fn incremental_verify_ich>>( self, result: &Q::Value, dep_node: &DepNode, @@ -698,7 +708,7 @@ fn incremental_verify_ich>( } #[inline(always)] - fn force_query_with_job + 'tcx>( + fn force_query_with_job> + 'tcx>( self, key: Q::Key, job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>, @@ -756,7 +766,7 @@ fn force_query_with_job + 'tcx>( /// side-effects -- e.g., in order to report errors for erroneous programs. /// /// Note: The optimization is only available during incr. comp. - pub(super) fn ensure_query + 'tcx>(self, key: Q::Key) { + pub(super) fn ensure_query> + 'tcx>(self, key: Q::Key) { if Q::EVAL_ALWAYS { let _ = self.get_query::(DUMMY_SP, key); return; @@ -784,7 +794,7 @@ pub(super) fn ensure_query + 'tcx>(self, key: Q::Key) } #[allow(dead_code)] - pub(super) fn force_query + 'tcx>( + pub(super) fn force_query> + 'tcx>( self, key: Q::Key, span: Span, @@ -920,7 +930,7 @@ pub fn name(&self) -> &'static str { } } - pub fn describe(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> { + pub fn describe(&self, tcx: TyCtxt<$tcx>) -> Cow<'static, str> { let (r, name) = match *self { $(Query::$name(key) => { (queries::$name::describe(tcx, key), stringify!($name)) diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index e7005f2f5ba..57fe8ede9d1 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -380,7 +380,7 @@ fn cache_on_disk( quote! { #[allow(unused_variables)] fn describe( - #tcx: TyCtxt<'_>, + #tcx: TyCtxt<'tcx>, #key: #arg, ) -> Cow<'static, str> { format!(#desc).into() @@ -393,7 +393,7 @@ fn describe( let desc = desc.unwrap_or(quote! {}); impls.extend(quote! { - impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> { + impl<'tcx> QueryDescription> for queries::#name<'tcx> { #desc #cache }