Skip to content

Commit

Permalink
Auto merge of #100436 - jyn514:macro-query-system, r=cjgillot
Browse files Browse the repository at this point in the history
try and simplify some things in the query system
  • Loading branch information
bors committed Aug 25, 2022
2 parents 9b9bc63 + e188868 commit 76531be
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 113 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl ProcessQueryValue<'_, Option<DeprecationEntry>> for Option<Deprecation> {
}

macro_rules! provide_one {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table }) => {
provide_one! {
<$lt> $tcx, $def_id, $other, $cdata, $name => {
$tcx, $def_id, $other, $cdata, $name => {
$cdata
.root
.tables
Expand All @@ -89,9 +89,9 @@ macro_rules! provide_one {
}
}
};
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_direct }) => {
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_direct }) => {
provide_one! {
<$lt> $tcx, $def_id, $other, $cdata, $name => {
$tcx, $def_id, $other, $cdata, $name => {
// We don't decode `table_direct`, since it's not a Lazy, but an actual value
$cdata
.root
Expand All @@ -102,11 +102,11 @@ macro_rules! provide_one {
}
}
};
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
fn $name<$lt>(
$tcx: TyCtxt<$lt>,
def_id_arg: ty::query::query_keys::$name<$lt>,
) -> ty::query::query_values::$name<$lt> {
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => $compute:block) => {
fn $name<'tcx>(
$tcx: TyCtxt<'tcx>,
def_id_arg: ty::query::query_keys::$name<'tcx>,
) -> ty::query::query_values::$name<'tcx> {
let _prof_timer =
$tcx.prof.generic_activity(concat!("metadata_decode_entry_", stringify!($name)));

Expand All @@ -130,11 +130,11 @@ macro_rules! provide_one {
}

macro_rules! provide {
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
$($name:ident => { $($compute:tt)* })*) => {
pub fn provide_extern(providers: &mut ExternProviders) {
$(provide_one! {
<$lt> $tcx, $def_id, $other, $cdata, $name => { $($compute)* }
$tcx, $def_id, $other, $cdata, $name => { $($compute)* }
})*

*providers = ExternProviders {
Expand Down Expand Up @@ -187,7 +187,7 @@ impl IntoArgs for (CrateNum, SimplifiedType) {
}
}

provide! { <'tcx> tcx, def_id, other, cdata,
provide! { tcx, def_id, other, cdata,
explicit_item_bounds => { table }
explicit_predicates_of => { table }
generics_of => { table }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl DepKind {
}

macro_rules! define_dep_nodes {
(<$tcx:tt>
(
$(
[$($attrs:tt)*]
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
Expand Down Expand Up @@ -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,

Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_middle/src/ty/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)*) => {

Expand All @@ -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> = <query_storage::$name<$tcx> as QueryStorage>::Stored;)*
$(pub type $name<'tcx> = <query_storage::$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)*)) {
Expand All @@ -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]);
Expand Down Expand Up @@ -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<query_stored::$name<$tcx>>;)*
) -> Option<query_stored::$name<'tcx>>;)*
}
};
}
Expand All @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -55,7 +54,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.
Expand Down
Loading

0 comments on commit 76531be

Please sign in to comment.