From 09ea9f0a87be489250bdb8d9171c7deb20fd04b1 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Thu, 18 Aug 2022 19:27:29 +0100 Subject: Add diagnostic translation lints to crates that don't emit them --- compiler/rustc_query_impl/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index eda61df7700..df187ea0c94 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -7,6 +7,8 @@ #![feature(rustc_attrs)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] #[macro_use] extern crate rustc_macros; -- cgit 1.4.1-3-g733a5 From f6329485a83c1d241635e0dedbf62929e193b10a Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 20 Aug 2022 15:39:21 +0300 Subject: rmeta/query cache: don't write string values of preinterned symbols --- compiler/rustc_metadata/src/rmeta/decoder.rs | 4 +++ compiler/rustc_metadata/src/rmeta/encoder.rs | 29 +++++++++++++--------- compiler/rustc_metadata/src/rmeta/mod.rs | 1 + compiler/rustc_query_impl/src/on_disk_cache.rs | 34 +++++++++++++++++--------- compiler/rustc_span/src/symbol.rs | 5 ++++ 5 files changed, 51 insertions(+), 22 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 889001d0a84..d0e0aa91480 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -631,6 +631,10 @@ impl<'a, 'tcx> Decodable> for Symbol { sym } + SYMBOL_PREINTERNED => { + let symbol_index = d.read_u32(); + Symbol::new_from_decoded(symbol_index) + } _ => unreachable!(), } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0d3a3efb0d3..cd5da40150d 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -317,17 +317,24 @@ impl<'a, 'tcx> Encodable> for Span { impl<'a, 'tcx> Encodable> for Symbol { fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) { - match s.symbol_table.entry(*self) { - Entry::Vacant(o) => { - s.opaque.emit_u8(SYMBOL_STR); - let pos = s.opaque.position(); - o.insert(pos); - s.emit_str(self.as_str()); - } - Entry::Occupied(o) => { - let x = o.get().clone(); - s.emit_u8(SYMBOL_OFFSET); - s.emit_usize(x); + // if symbol preinterned, emit tag and symbol index + if self.is_preinterned() { + s.opaque.emit_u8(SYMBOL_PREINTERNED); + s.opaque.emit_u32(self.as_u32()); + } else { + // otherwise write it as string or as offset to it + match s.symbol_table.entry(*self) { + Entry::Vacant(o) => { + s.opaque.emit_u8(SYMBOL_STR); + let pos = s.opaque.position(); + o.insert(pos); + s.emit_str(self.as_str()); + } + Entry::Occupied(o) => { + let x = o.get().clone(); + s.emit_u8(SYMBOL_OFFSET); + s.emit_usize(x); + } } } } diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 91d744879fd..e6cceaf29d5 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -448,6 +448,7 @@ const TAG_PARTIAL_SPAN: u8 = 2; // Tags for encoding Symbol's const SYMBOL_STR: u8 = 0; const SYMBOL_OFFSET: u8 = 1; +const SYMBOL_PREINTERNED: u8 = 2; pub fn provide(providers: &mut Providers) { encoder::provide(providers); diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 6711dd3d5c5..5ef95911f56 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -42,6 +42,7 @@ const TAG_EXPN_DATA: u8 = 1; // Tags for encoding Symbol's const SYMBOL_STR: u8 = 0; const SYMBOL_OFFSET: u8 = 1; +const SYMBOL_PREINTERNED: u8 = 2; /// Provides an interface to incremental compilation data cached from the /// previous compilation session. This data will eventually include the results @@ -745,6 +746,10 @@ impl<'a, 'tcx> Decodable> for Symbol { sym } + SYMBOL_PREINTERNED => { + let symbol_index = d.read_u32(); + Symbol::new_from_decoded(symbol_index) + } _ => unreachable!(), } } @@ -939,17 +944,24 @@ impl<'a, 'tcx> Encodable> for Span { // copy&paste impl from rustc_metadata impl<'a, 'tcx> Encodable> for Symbol { fn encode(&self, s: &mut CacheEncoder<'a, 'tcx>) { - match s.symbol_table.entry(*self) { - Entry::Vacant(o) => { - s.encoder.emit_u8(SYMBOL_STR); - let pos = s.encoder.position(); - o.insert(pos); - s.emit_str(self.as_str()); - } - Entry::Occupied(o) => { - let x = o.get().clone(); - s.emit_u8(SYMBOL_OFFSET); - s.emit_usize(x); + // if symbol preinterned, emit tag and symbol index + if self.is_preinterned() { + s.encoder.emit_u8(SYMBOL_PREINTERNED); + s.encoder.emit_u32(self.as_u32()); + } else { + // otherwise write it as string or as offset to it + match s.symbol_table.entry(*self) { + Entry::Vacant(o) => { + s.encoder.emit_u8(SYMBOL_STR); + let pos = s.encoder.position(); + o.insert(pos); + s.emit_str(self.as_str()); + } + Entry::Occupied(o) => { + let x = o.get().clone(); + s.emit_u8(SYMBOL_OFFSET); + s.emit_usize(x); + } } } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 70e78682c65..ac166e09843 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1803,6 +1803,11 @@ impl Symbol { Symbol(SymbolIndex::from_u32(n)) } + /// for use in Decoder only + pub fn new_from_decoded(n: u32) -> Self { + Self::new(n) + } + /// Maps a string to its interned representation. pub fn intern(string: &str) -> Self { with_session_globals(|session_globals| session_globals.symbol_interner.intern(string)) -- cgit 1.4.1-3-g733a5 From cbc6bd20191554421b3d4a377cd01169212da23b Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Wed, 24 Aug 2022 09:42:12 +0800 Subject: add `depth_limit` in `QueryVTable` --- compiler/rustc_macros/src/query.rs | 13 ++++- compiler/rustc_middle/src/query/mod.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 6 +-- compiler/rustc_middle/src/ty/layout.rs | 61 ++++++++++------------- compiler/rustc_query_impl/src/plumbing.rs | 20 +++++++- compiler/rustc_query_system/src/query/config.rs | 1 + compiler/rustc_query_system/src/query/mod.rs | 7 ++- compiler/rustc_query_system/src/query/plumbing.rs | 28 ++++++----- 8 files changed, 83 insertions(+), 54 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 52c93133f79..6f27144910f 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -106,9 +106,12 @@ struct QueryModifiers { /// Generate a dep node based on the dependencies of the query anon: Option, - // Always evaluate the query, ignoring its dependencies + /// Always evaluate the query, ignoring its dependencies eval_always: Option, + /// Whether the query has a call depth limit + depth_limit: Option, + /// Use a separate query provider for local and extern crates separate_provide_extern: Option, @@ -126,6 +129,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result { let mut no_hash = None; let mut anon = None; let mut eval_always = None; + let mut depth_limit = None; let mut separate_provide_extern = None; let mut remap_env_constness = None; @@ -194,6 +198,8 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result { try_insert!(anon = modifier); } else if modifier == "eval_always" { try_insert!(eval_always = modifier); + } else if modifier == "depth_limit" { + try_insert!(depth_limit = modifier); } else if modifier == "separate_provide_extern" { try_insert!(separate_provide_extern = modifier); } else if modifier == "remap_env_constness" { @@ -215,6 +221,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result { no_hash, anon, eval_always, + depth_limit, separate_provide_extern, remap_env_constness, }) @@ -365,6 +372,10 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { if let Some(eval_always) = &modifiers.eval_always { attributes.push(quote! { (#eval_always) }); }; + // Pass on the depth_limit modifier + if let Some(depth_limit) = &modifiers.depth_limit { + attributes.push(quote! { (#depth_limit) }); + }; // Pass on the separate_provide_extern modifier if let Some(separate_provide_extern) = &modifiers.separate_provide_extern { attributes.push(quote! { (#separate_provide_extern) }); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index f78f62e31d2..fc87c1ddae9 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1309,6 +1309,7 @@ rustc_queries! { query layout_of( key: ty::ParamEnvAnd<'tcx, Ty<'tcx>> ) -> Result, ty::layout::LayoutError<'tcx>> { + depth_limit desc { "computing layout of `{}`", key.value } remap_env_constness } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 0a0f45ce1a0..0f34aa10a12 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1857,8 +1857,8 @@ pub mod tls { /// This is updated by `JobOwner::start` in `ty::query::plumbing` when executing a query. pub diagnostics: Option<&'a Lock>>, - /// Used to prevent layout from recursing too deeply. - pub layout_depth: usize, + /// Used to prevent queries from calling too deeply. + pub query_depth: usize, /// The current dep graph task. This is used to add dependencies to queries /// when executing them. @@ -1872,7 +1872,7 @@ pub mod tls { tcx, query: None, diagnostics: None, - layout_depth: 0, + query_depth: 0, task_deps: TaskDepsRef::Ignore, } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index f5505590168..384f17b3cdf 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -229,49 +229,38 @@ fn layout_of<'tcx>( tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, ) -> Result, LayoutError<'tcx>> { - ty::tls::with_related_context(tcx, move |icx| { - let (param_env, ty) = query.into_parts(); - debug!(?ty); - - if !tcx.recursion_limit().value_within_limit(icx.layout_depth) { - tcx.sess.fatal(&format!("overflow representing the type `{}`", ty)); + let (param_env, ty) = query.into_parts(); + debug!(?ty); + + let param_env = param_env.with_reveal_all_normalized(tcx); + let unnormalized_ty = ty; + + // FIXME: We might want to have two different versions of `layout_of`: + // One that can be called after typecheck has completed and can use + // `normalize_erasing_regions` here and another one that can be called + // before typecheck has completed and uses `try_normalize_erasing_regions`. + let ty = match tcx.try_normalize_erasing_regions(param_env, ty) { + Ok(t) => t, + Err(normalization_error) => { + return Err(LayoutError::NormalizationFailure(ty, normalization_error)); } + }; - // Update the ImplicitCtxt to increase the layout_depth - let icx = ty::tls::ImplicitCtxt { layout_depth: icx.layout_depth + 1, ..icx.clone() }; - - ty::tls::enter_context(&icx, |_| { - let param_env = param_env.with_reveal_all_normalized(tcx); - let unnormalized_ty = ty; - - // FIXME: We might want to have two different versions of `layout_of`: - // One that can be called after typecheck has completed and can use - // `normalize_erasing_regions` here and another one that can be called - // before typecheck has completed and uses `try_normalize_erasing_regions`. - let ty = match tcx.try_normalize_erasing_regions(param_env, ty) { - Ok(t) => t, - Err(normalization_error) => { - return Err(LayoutError::NormalizationFailure(ty, normalization_error)); - } - }; - - if ty != unnormalized_ty { - // Ensure this layout is also cached for the normalized type. - return tcx.layout_of(param_env.and(ty)); - } + if ty != unnormalized_ty { + // Ensure this layout is also cached for the normalized type. + return tcx.layout_of(param_env.and(ty)); + } - let cx = LayoutCx { tcx, param_env }; + let cx = LayoutCx { tcx, param_env }; - let layout = cx.layout_of_uncached(ty)?; - let layout = TyAndLayout { ty, layout }; + let layout = cx.layout_of_uncached(ty)?; + let layout = TyAndLayout { ty, layout }; - cx.record_layout_for_printing(layout); + cx.record_layout_for_printing(layout); - sanity_check_layout(&cx, &layout); + sanity_check_layout(&cx, &layout); - Ok(layout) - }) - }) + Ok(layout) } pub struct LayoutCx<'tcx, C> { diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 339683cf689..ecabe74218b 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -91,6 +91,7 @@ impl QueryContext for QueryCtxt<'_> { fn start_query( &self, token: QueryJobId, + depth_limit: bool, diagnostics: Option<&Lock>>, compute: impl FnOnce() -> R, ) -> R { @@ -98,12 +99,16 @@ impl QueryContext for QueryCtxt<'_> { // as `self`, so we use `with_related_context` to relate the 'tcx lifetimes // when accessing the `ImplicitCtxt`. tls::with_related_context(**self, move |current_icx| { + if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) { + self.depth_limit_error(); + } + // Update the `ImplicitCtxt` to point to our new query job. let new_icx = ImplicitCtxt { tcx: **self, query: Some(token), diagnostics, - layout_depth: current_icx.layout_depth, + query_depth: current_icx.query_depth + depth_limit as usize, task_deps: current_icx.task_deps, }; @@ -205,6 +210,18 @@ macro_rules! is_eval_always { }; } +macro_rules! depth_limit { + ([]) => {{ + false + }}; + ([(depth_limit) $($rest:tt)*]) => {{ + true + }}; + ([$other:tt $($modifiers:tt)*]) => { + depth_limit!([$($modifiers)*]) + }; +} + macro_rules! hash_result { ([]) => {{ Some(dep_graph::hash_result) @@ -335,6 +352,7 @@ macro_rules! define_queries { QueryVTable { anon: is_anon!([$($modifiers)*]), eval_always: is_eval_always!([$($modifiers)*]), + depth_limit: depth_limit!([$($modifiers)*]), dep_kind: dep_graph::DepKind::$name, hash_result: hash_result!([$($modifiers)*]), handle_cycle_error: |tcx, mut error| handle_cycle_error!([$($modifiers)*][tcx, error]), diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index 964914a1326..bd0fd7ac350 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -23,6 +23,7 @@ pub struct QueryVTable { pub anon: bool, pub dep_kind: CTX::DepKind, pub eval_always: bool, + pub depth_limit: bool, pub cache_on_disk: bool, pub compute: fn(CTX::DepContext, K) -> V, diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index fb2258434f4..a1f2b081d43 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -14,7 +14,7 @@ pub use self::caches::{ mod config; pub use self::config::{QueryConfig, QueryDescription, QueryVTable}; -use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; +use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; use rustc_data_structures::sync::Lock; use rustc_data_structures::thin_vec::ThinVec; @@ -119,7 +119,12 @@ pub trait QueryContext: HasDepContext { fn start_query( &self, token: QueryJobId, + depth_limit: bool, diagnostics: Option<&Lock>>, compute: impl FnOnce() -> R, ) -> R; + + fn depth_limit_error(&self) { + self.dep_context().sess().fatal("queries overflow the depth limit!"); + } } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 5e8ea07d00f..6ae9147ff77 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -381,7 +381,9 @@ where // Fast path for when incr. comp. is off. if !dep_graph.is_fully_enabled() { let prof_timer = tcx.dep_context().profiler().query_provider(); - let result = tcx.start_query(job_id, None, || query.compute(*tcx.dep_context(), key)); + let result = tcx.start_query(job_id, query.depth_limit, None, || { + query.compute(*tcx.dep_context(), key) + }); let dep_node_index = dep_graph.next_virtual_depnode_index(); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); return (result, dep_node_index); @@ -394,7 +396,7 @@ where // The diagnostics for this query will be promoted to the current session during // `try_mark_green()`, so we can ignore them here. - if let Some(ret) = tcx.start_query(job_id, None, || { + if let Some(ret) = tcx.start_query(job_id, false, None, || { try_load_from_disk_and_cache_in_memory(tcx, &key, &dep_node, query) }) { return ret; @@ -404,18 +406,20 @@ where let prof_timer = tcx.dep_context().profiler().query_provider(); let diagnostics = Lock::new(ThinVec::new()); - let (result, dep_node_index) = tcx.start_query(job_id, Some(&diagnostics), || { - if query.anon { - return dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { - query.compute(*tcx.dep_context(), key) - }); - } + let (result, dep_node_index) = + tcx.start_query(job_id, query.depth_limit, Some(&diagnostics), || { + if query.anon { + return dep_graph.with_anon_task(*tcx.dep_context(), query.dep_kind, || { + query.compute(*tcx.dep_context(), key) + }); + } - // `to_dep_node` is expensive for some `DepKind`s. - let dep_node = dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); + // `to_dep_node` is expensive for some `DepKind`s. + let dep_node = + dep_node_opt.unwrap_or_else(|| query.to_dep_node(*tcx.dep_context(), &key)); - dep_graph.with_task(dep_node, *tcx.dep_context(), key, query.compute, query.hash_result) - }); + dep_graph.with_task(dep_node, *tcx.dep_context(), key, query.compute, query.hash_result) + }); prof_timer.finish_with_query_invocation_id(dep_node_index.into()); -- cgit 1.4.1-3-g733a5 From b53761969fa7954e4de4d6bb890addc23d668608 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 11 Aug 2022 19:54:42 -0500 Subject: Remove `$tcx` metavariable from `rustc_query_append` It's not actually necessary and it makes the code harder to read. --- compiler/rustc_macros/src/query.rs | 4 +- compiler/rustc_middle/src/dep_graph/dep_node.rs | 4 +- compiler/rustc_middle/src/ty/query.rs | 32 ++++++------ compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/plumbing.rs | 58 ++++++++++------------ compiler/rustc_query_impl/src/profiling_support.rs | 4 +- 6 files changed, 49 insertions(+), 55 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 52c93133f79..32a15413c6f 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -400,10 +400,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { TokenStream::from(quote! { #[macro_export] macro_rules! rustc_query_append { - ([$($macro:tt)*][$($other:tt)*]) => { + ([$($macro:tt)*]) => { $($macro)* { - $($other)* - #query_stream } } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 2d095438fc4..156a9641272 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -143,7 +143,7 @@ impl DepKind { } macro_rules! define_dep_nodes { - (<$tcx:tt> + ( $( [$($attrs:tt)*] $variant:ident $(( $tuple_arg_ty:ty $(,)? ))* @@ -179,7 +179,7 @@ macro_rules! define_dep_nodes { ); } -rustc_dep_node_append!([define_dep_nodes!][ <'tcx> +rustc_dep_node_append!([define_dep_nodes!][ // We use this for most things when incr. comp. is turned off. [] Null, diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 2452bcf6a61..736ab69c812 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -173,7 +173,7 @@ macro_rules! opt_remap_env_constness { } macro_rules! define_callbacks { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { @@ -187,33 +187,33 @@ macro_rules! define_callbacks { pub mod query_keys { use super::*; - $(pub type $name<$tcx> = $($K)*;)* + $(pub type $name<'tcx> = $($K)*;)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_values { use super::*; - $(pub type $name<$tcx> = $V;)* + $(pub type $name<'tcx> = $V;)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_storage { use super::*; - $(pub type $name<$tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* + $(pub type $name<'tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* } #[allow(nonstandard_style, unused_lifetimes)] pub mod query_stored { use super::*; - $(pub type $name<$tcx> = as QueryStorage>::Stored;)* + $(pub type $name<'tcx> = as QueryStorage>::Stored;)* } #[derive(Default)] - pub struct QueryCaches<$tcx> { - $($(#[$attr])* pub $name: query_storage::$name<$tcx>,)* + pub struct QueryCaches<'tcx> { + $($(#[$attr])* pub $name: query_storage::$name<'tcx>,)* } - impl<$tcx> TyCtxtEnsure<$tcx> { + impl<'tcx> TyCtxtEnsure<'tcx> { $($(#[$attr])* #[inline(always)] pub fn $name(self, key: query_helper_param_ty!($($K)*)) { @@ -231,20 +231,20 @@ macro_rules! define_callbacks { })* } - impl<$tcx> TyCtxt<$tcx> { + impl<'tcx> TyCtxt<'tcx> { $($(#[$attr])* #[inline(always)] #[must_use] - pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx> + pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> { self.at(DUMMY_SP).$name(key) })* } - impl<$tcx> TyCtxtAt<$tcx> { + impl<'tcx> TyCtxtAt<'tcx> { $($(#[$attr])* #[inline(always)] - pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$tcx> + pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> { let key = key.into_query_param(); opt_remap_env_constness!([$($modifiers)*][key]); @@ -311,11 +311,11 @@ macro_rules! define_callbacks { $($(#[$attr])* fn $name( &'tcx self, - tcx: TyCtxt<$tcx>, + tcx: TyCtxt<'tcx>, span: Span, - key: query_keys::$name<$tcx>, + key: query_keys::$name<'tcx>, mode: QueryMode, - ) -> Option>;)* + ) -> Option>;)* } }; } @@ -332,7 +332,7 @@ macro_rules! define_callbacks { // Queries marked with `fatal_cycle` do not need the latter implementation, // as they will raise an fatal error on query cycles instead. -rustc_query_append! { [define_callbacks!][<'tcx>] } +rustc_query_append! { [define_callbacks!] } mod sealed { use super::{DefId, LocalDefId}; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index df187ea0c94..d8c85ab9faa 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -55,7 +55,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { } } -rustc_query_append! { [define_queries!][<'tcx>] } +rustc_query_append! { [define_queries!] } impl<'tcx> Queries<'tcx> { // Force codegen in the dyn-trait transformation in this crate. diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 339683cf689..cb54edb2952 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -234,11 +234,10 @@ macro_rules! get_provider { } macro_rules! define_queries { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { define_queries_struct! { - tcx: $tcx, input: ($(([$($modifiers)*] [$($attr)*] [$name]))*) } @@ -247,7 +246,7 @@ macro_rules! define_queries { // Create an eponymous constructor for each query. $(#[allow(nonstandard_style)] $(#[$attr])* - pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame { + pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: query_keys::$name<'tcx>) -> QueryStackFrame { let kind = dep_graph::DepKind::$name; let name = stringify!($name); // Disable visible paths printing for performance reasons. @@ -295,32 +294,32 @@ macro_rules! define_queries { mod queries { use std::marker::PhantomData; - $(pub struct $name<$tcx> { - data: PhantomData<&$tcx ()> + $(pub struct $name<'tcx> { + data: PhantomData<&'tcx ()> })* } - $(impl<$tcx> QueryConfig for queries::$name<$tcx> { - type Key = query_keys::$name<$tcx>; - type Value = query_values::$name<$tcx>; - type Stored = query_stored::$name<$tcx>; + $(impl<'tcx> QueryConfig for queries::$name<'tcx> { + type Key = query_keys::$name<'tcx>; + type Value = query_values::$name<'tcx>; + type Stored = query_stored::$name<'tcx>; const NAME: &'static str = stringify!($name); } - impl<$tcx> QueryDescription> for queries::$name<$tcx> { - rustc_query_description! { $name<$tcx> } + impl<'tcx> QueryDescription> for queries::$name<'tcx> { + rustc_query_description! { $name<'tcx> } - type Cache = query_storage::$name<$tcx>; + type Cache = query_storage::$name<'tcx>; #[inline(always)] - fn query_state<'a>(tcx: QueryCtxt<$tcx>) -> &'a QueryState - where QueryCtxt<$tcx>: 'a + fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState + where QueryCtxt<'tcx>: 'a { &tcx.queries.$name } #[inline(always)] - fn query_cache<'a>(tcx: QueryCtxt<$tcx>) -> &'a Self::Cache + fn query_cache<'a>(tcx: QueryCtxt<'tcx>) -> &'a Self::Cache where 'tcx:'a { &tcx.query_caches.$name @@ -328,7 +327,7 @@ macro_rules! define_queries { #[inline] fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) -> - QueryVTable, Self::Key, Self::Value> + QueryVTable, Self::Key, Self::Value> { let compute = get_provider!([$($modifiers)*][tcx, $name, key]); let cache_on_disk = Self::cache_on_disk(tcx.tcx, key); @@ -465,28 +464,25 @@ macro_rules! define_queries { } } -// FIXME(eddyb) this macro (and others?) use `$tcx` and `'tcx` interchangeably. -// We should either not take `$tcx` at all and use `'tcx` everywhere, or use -// `$tcx` everywhere (even if that isn't necessary due to lack of hygiene). macro_rules! define_queries_struct { - (tcx: $tcx:tt, + ( input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => { - pub struct Queries<$tcx> { + pub struct Queries<'tcx> { local_providers: Box, extern_providers: Box, - pub on_disk_cache: Option>, + pub on_disk_cache: Option>, jobs: AtomicU64, - $($(#[$attr])* $name: QueryState>,)* + $($(#[$attr])* $name: QueryState>,)* } - impl<$tcx> Queries<$tcx> { + impl<'tcx> Queries<'tcx> { pub fn new( local_providers: Providers, extern_providers: ExternProviders, - on_disk_cache: Option>, + on_disk_cache: Option>, ) -> Self { Queries { local_providers: Box::new(local_providers), @@ -498,8 +494,8 @@ macro_rules! define_queries_struct { } pub(crate) fn try_collect_active_jobs( - &$tcx self, - tcx: TyCtxt<$tcx>, + &'tcx self, + tcx: TyCtxt<'tcx>, ) -> Option { let tcx = QueryCtxt { tcx, queries: self }; let mut jobs = QueryMap::default(); @@ -532,13 +528,13 @@ macro_rules! define_queries_struct { #[tracing::instrument(level = "trace", skip(self, tcx))] fn $name( &'tcx self, - tcx: TyCtxt<$tcx>, + tcx: TyCtxt<'tcx>, span: Span, - key: query_keys::$name<$tcx>, + key: query_keys::$name<'tcx>, mode: QueryMode, - ) -> Option> { + ) -> Option> { let qcx = QueryCtxt { tcx, queries: self }; - get_query::, _>(qcx, span, key, mode) + get_query::, _>(qcx, span, key, mode) })* } }; diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 551f094209e..34586750947 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -306,7 +306,7 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { let mut string_cache = QueryKeyStringCache::new(); macro_rules! alloc_once { - (<$tcx:tt> + ( $($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)* ) => { $({ @@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { } } - rustc_query_append! { [alloc_once!][<'tcx>] } + rustc_query_append! { [alloc_once!] } } -- cgit 1.4.1-3-g733a5 From 1de08b19d1ee7ae337b93b11fb971d37ffbb6968 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 11 Aug 2022 20:20:46 -0500 Subject: Get rid of some usages of `query_keys` Rustdoc documents these with the name of the type alias instead of normalizing them to the underlying type. Use associated types instead so that the generated docs for nightly-rustc are easier to read. --- compiler/rustc_query_impl/src/plumbing.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index cb54edb2952..30ca93c7233 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -246,7 +246,7 @@ macro_rules! define_queries { // Create an eponymous constructor for each query. $(#[allow(nonstandard_style)] $(#[$attr])* - pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: query_keys::$name<'tcx>) -> QueryStackFrame { + pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: as QueryConfig>::Key) -> QueryStackFrame { let kind = dep_graph::DepKind::$name; let name = stringify!($name); // Disable visible paths printing for performance reasons. @@ -348,7 +348,6 @@ macro_rules! define_queries { mod query_callbacks { use super::*; use rustc_middle::dep_graph::DepNode; - use rustc_middle::ty::query::query_keys; use rustc_query_system::dep_graph::DepNodeParams; use rustc_query_system::query::{force_query, QueryDescription}; use rustc_query_system::dep_graph::FingerprintStyle; @@ -410,7 +409,7 @@ macro_rules! define_queries { let is_eval_always = is_eval_always!([$($modifiers)*]); let fingerprint_style = - as DepNodeParams>>::fingerprint_style(); + < as QueryConfig>::Key as DepNodeParams>>::fingerprint_style(); if is_anon || !fingerprint_style.reconstructible() { return DepKindStruct { @@ -423,8 +422,8 @@ macro_rules! define_queries { } #[inline(always)] - fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> Option> { - as DepNodeParams>>::recover(tcx, &dep_node) + fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> Option< as QueryConfig>::Key> { + < as QueryConfig>::Key as DepNodeParams>>::recover(tcx, &dep_node) } fn force_from_dep_node(tcx: TyCtxt<'_>, dep_node: DepNode) -> bool { @@ -475,7 +474,7 @@ macro_rules! define_queries_struct { jobs: AtomicU64, - $($(#[$attr])* $name: QueryState>,)* + $($(#[$attr])* $name: QueryState< as QueryConfig>::Key>,)* } impl<'tcx> Queries<'tcx> { @@ -530,7 +529,7 @@ macro_rules! define_queries_struct { &'tcx self, tcx: TyCtxt<'tcx>, span: Span, - key: query_keys::$name<'tcx>, + key: as QueryConfig>::Key, mode: QueryMode, ) -> Option> { let qcx = QueryCtxt { tcx, queries: self }; -- cgit 1.4.1-3-g733a5 From 0bedd354ca3c5438f5f5a3b0b06b3ead6ffec374 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 11 Aug 2022 20:36:13 -0500 Subject: Move most of `make_query` into a generic function, away from the macro This should both make the code easier to read and also greatly reduce the amount of codegen the compiler has to do, since it only needs to monomorphize `create_query_frame` for each new key and not for each query. --- compiler/rustc_query_impl/src/lib.rs | 1 - compiler/rustc_query_impl/src/plumbing.rs | 97 ++++++++++++++++++------------- 2 files changed, 56 insertions(+), 42 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index d8c85ab9faa..946bc34fea1 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -15,7 +15,6 @@ extern crate rustc_macros; #[macro_use] extern crate rustc_middle; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::AtomicU64; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex}; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 30ca93c7233..7b4ff850df6 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -2,13 +2,18 @@ //! generate the actual methods on tcx which find and execute the provider, //! manage the caches, and so forth. +use crate::keys::Key; use crate::{on_disk_cache, Queries}; -use rustc_middle::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; +use rustc_middle::dep_graph::{self, DepKind, DepNodeIndex, SerializedDepNodeIndex}; use rustc_middle::ty::tls::{self, ImplicitCtxt}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{self, TyCtxt}; use rustc_query_system::dep_graph::HasDepContext; -use rustc_query_system::query::{QueryContext, QueryJobId, QueryMap, QuerySideEffects}; +use rustc_query_system::ich::StableHashingContext; +use rustc_query_system::query::{ + QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, +}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lock; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::{Diagnostic, Handler}; @@ -233,6 +238,53 @@ macro_rules! get_provider { }; } +pub(crate) fn create_query_frame< + 'tcx, + K: Copy + Key + for<'a> HashStable>, +>( + tcx: QueryCtxt<'tcx>, + do_describe: fn(QueryCtxt<'tcx>, K) -> String, + key: K, + kind: DepKind, + name: &'static str, +) -> QueryStackFrame { + // Disable visible paths printing for performance reasons. + // Showing visible path instead of any path is not that important in production. + let description = ty::print::with_no_visible_paths!( + // Force filename-line mode to avoid invoking `type_of` query. + ty::print::with_forced_impl_filename_line!(do_describe(tcx, key)) + ); + let description = + if tcx.sess.verbose() { format!("{} [{}]", description, name) } else { description }; + let span = if kind == dep_graph::DepKind::def_span { + // The `def_span` query is used to calculate `default_span`, + // so exit to avoid infinite recursion. + None + } else { + Some(key.default_span(*tcx)) + }; + let def_kind = if kind == dep_graph::DepKind::opt_def_kind { + // Try to avoid infinite recursion. + None + } else { + key.key_as_def_id() + .and_then(|def_id| def_id.as_local()) + .and_then(|def_id| tcx.opt_def_kind(def_id)) + }; + let hash = || { + tcx.with_stable_hashing_context(|mut hcx| { + let mut hasher = StableHasher::new(); + std::mem::discriminant(&kind).hash_stable(&mut hcx, &mut hasher); + key.hash_stable(&mut hcx, &mut hasher); + hasher.finish::() + }) + }; + + QueryStackFrame::new(name, description, span, def_kind, hash) +} + +// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros +// invoked by `rustc_query_append`. macro_rules! define_queries { ( $($(#[$attr:meta])* @@ -249,44 +301,7 @@ macro_rules! define_queries { pub fn $name<'tcx>(tcx: QueryCtxt<'tcx>, key: as QueryConfig>::Key) -> QueryStackFrame { let kind = dep_graph::DepKind::$name; let name = stringify!($name); - // Disable visible paths printing for performance reasons. - // Showing visible path instead of any path is not that important in production. - let description = ty::print::with_no_visible_paths!( - // Force filename-line mode to avoid invoking `type_of` query. - ty::print::with_forced_impl_filename_line!( - queries::$name::describe(tcx, key) - ) - ); - let description = if tcx.sess.verbose() { - format!("{} [{}]", description, name) - } else { - description - }; - let span = if kind == dep_graph::DepKind::def_span { - // The `def_span` query is used to calculate `default_span`, - // so exit to avoid infinite recursion. - None - } else { - Some(key.default_span(*tcx)) - }; - let def_kind = if kind == dep_graph::DepKind::opt_def_kind { - // Try to avoid infinite recursion. - None - } else { - key.key_as_def_id() - .and_then(|def_id| def_id.as_local()) - .and_then(|def_id| tcx.opt_def_kind(def_id)) - }; - let hash = || { - tcx.with_stable_hashing_context(|mut hcx|{ - let mut hasher = StableHasher::new(); - std::mem::discriminant(&kind).hash_stable(&mut hcx, &mut hasher); - key.hash_stable(&mut hcx, &mut hasher); - hasher.finish::() - }) - }; - - QueryStackFrame::new(name, description, span, def_kind, hash) + $crate::plumbing::create_query_frame(tcx, queries::$name::describe, key, kind, name) })* } -- cgit 1.4.1-3-g733a5 From 7b8e2a52ff29d400b4d869fad1d917ffa9bdce59 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 24 Aug 2022 00:02:37 -0500 Subject: Simplify the syntax for macros generated by `rustc_queries` - Disallow multiple macros callbacks in the same invocation. In practice, this was never used. - Remove the `[]` brackets around the macro name - Require an `ident`, not an arbitrary `tt` --- compiler/rustc_macros/src/query.rs | 12 ++++++------ compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 +- compiler/rustc_middle/src/ty/query.rs | 2 +- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/profiling_support.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 32a15413c6f..d80d35cb1fa 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -400,15 +400,15 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { TokenStream::from(quote! { #[macro_export] macro_rules! rustc_query_append { - ([$($macro:tt)*]) => { - $($macro)* { + ($macro:ident !) => { + $macro! { #query_stream } } } macro_rules! rustc_dep_node_append { - ([$($macro:tt)*][$($other:tt)*]) => { - $($macro)*( + ($macro:ident! [$($other:tt)*]) => { + $macro!( $($other)* #dep_node_def_stream @@ -417,8 +417,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { } #[macro_export] macro_rules! rustc_cached_queries { - ($($macro:tt)*) => { - $($macro)*(#cached_queries); + ( $macro:ident! ) => { + $macro!(#cached_queries); } } #[macro_export] diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 156a9641272..65fc8a2e9cf 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -179,7 +179,7 @@ macro_rules! define_dep_nodes { ); } -rustc_dep_node_append!([define_dep_nodes!][ +rustc_dep_node_append!(define_dep_nodes![ // We use this for most things when incr. comp. is turned off. [] Null, diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 736ab69c812..5665bb866d4 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -332,7 +332,7 @@ macro_rules! define_callbacks { // Queries marked with `fatal_cycle` do not need the latter implementation, // as they will raise an fatal error on query cycles instead. -rustc_query_append! { [define_callbacks!] } +rustc_query_append! { define_callbacks! } mod sealed { use super::{DefId, LocalDefId}; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 946bc34fea1..8ea09880694 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -54,7 +54,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { } } -rustc_query_append! { [define_queries!] } +rustc_query_append! { define_queries! } impl<'tcx> Queries<'tcx> { // Force codegen in the dyn-trait transformation in this crate. diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 34586750947..260af0d5408 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { } } - rustc_query_append! { [alloc_once!] } + rustc_query_append! { alloc_once! } } -- cgit 1.4.1-3-g733a5 From b061550ed351751db4bb3dcc356f44daa9a3542d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 24 Aug 2022 00:22:27 -0500 Subject: Remove the `$tcx:tt` parameter from `rustc_query_description` It's unnecessary. --- compiler/rustc_macros/src/query.rs | 10 +++++----- compiler/rustc_query_impl/src/plumbing.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_query_impl/src') diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index d80d35cb1fa..cfbc80b9756 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -258,13 +258,13 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea let try_load_from_disk = if let Some((tcx, id, block)) = modifiers.load_cached.as_ref() { // Use custom code to load the query from disk quote! { - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = Some(|#tcx, #id| { #block }); } } else { // Use the default code to load the query from disk quote! { - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = Some(|tcx, id| tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id)); } }; @@ -291,7 +291,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea false } - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = None; + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = None; } }; @@ -300,7 +300,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea let desc = quote! { #[allow(unused_variables)] - fn describe(tcx: QueryCtxt<$tcx>, key: Self::Key) -> String { + fn describe(tcx: QueryCtxt<'tcx>, key: Self::Key) -> String { let (#tcx, #key) = (*tcx, key); ::rustc_middle::ty::print::with_no_trimmed_paths!( format!(#desc) @@ -309,7 +309,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea }; impls.extend(quote! { - (#name<$tcx:tt>) => { + (#name) => { #desc #cache }; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 7b4ff850df6..462f9a42aea 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -322,7 +322,7 @@ macro_rules! define_queries { } impl<'tcx> QueryDescription> for queries::$name<'tcx> { - rustc_query_description! { $name<'tcx> } + rustc_query_description! { $name } type Cache = query_storage::$name<'tcx>; -- cgit 1.4.1-3-g733a5