Skip to content

Commit

Permalink
Auto merge of rust-lang#100946 - jyn514:query-system-3, r=cjgillot
Browse files Browse the repository at this point in the history
Simplify the arguments to macros generated by the `rustc_queries` proc macro

Very small cleanup. Based on rust-lang#100436 which modifies some of the same code.

r? `@cjgillot`
  • Loading branch information
bors committed Aug 27, 2022
2 parents d0e1491 + b061550 commit 4065b89
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,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<fn(QueryCtxt<$tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
= Some(|#tcx, #id| { #block });
}
} else {
// Use the default code to load the query from disk
quote! {
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<$tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
= Some(|tcx, id| tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id));
}
};
Expand All @@ -298,7 +298,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
false
}

const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<$tcx>, SerializedDepNodeIndex) -> Option<Self::Value>> = None;
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>> = None;
}
};

Expand All @@ -307,7 +307,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)
Expand All @@ -316,7 +316,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
};

impls.extend(quote! {
(#name<$tcx:tt>) => {
(#name) => {
#desc
#cache
};
Expand Down Expand Up @@ -411,15 +411,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
Expand All @@ -428,8 +428,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]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ macro_rules! define_queries {
}

impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> {
rustc_query_description! { $name<'tcx> }
rustc_query_description! { $name }

type Cache = query_storage::$name<'tcx>;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/profiling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
}
}

rustc_query_append! { [alloc_once!] }
rustc_query_append! { alloc_once! }
}

0 comments on commit 4065b89

Please sign in to comment.