Skip to content
15 changes: 14 additions & 1 deletion compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
});

TokenStream::from(quote! {
#[macro_export]
macro_rules! rustc_query_append {
([$($macro:tt)*][$($other:tt)*]) => {
$($macro)* {
Expand All @@ -537,6 +538,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
}
}
}
#[macro_export]
macro_rules! rustc_dep_node_append {
([$($macro:tt)*][$($other:tt)*]) => {
$($macro)*(
Expand All @@ -546,6 +548,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
);
}
}
#[macro_export]
macro_rules! rustc_dep_node_force {
([$dep_node:expr, $tcx:expr] $($other:tt)*) => {
match $dep_node.kind {
Expand All @@ -555,14 +558,24 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
}
}
}
#[macro_export]
macro_rules! rustc_cached_queries {
($($macro:tt)*) => {
$($macro)*(#cached_queries);
}
}

#query_description_stream
#[macro_export]
macro_rules! query_description_stream {
// capture all needed `use` statements.
($($uses:tt)*) => {
$($uses)*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can surround thins expansion by an ad-hoc module to avoid polluting the namespace.


#query_description_stream
}
}

#[macro_export]
macro_rules! rustc_dep_node_try_load_from_on_disk_cache {
($dep_node:expr, $tcx:expr) => {
match $dep_node.kind {
Expand Down
65 changes: 10 additions & 55 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,26 @@ macro_rules! is_anon_attr {
};
}

macro_rules! is_eval_always_attr {
(eval_always) => {
true
};
($attr:ident) => {
false
};
}

macro_rules! contains_anon_attr {
($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_anon_attr!($attr) | )* false});
}

macro_rules! contains_eval_always_attr {
($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_eval_always_attr!($attr) | )* false});
}

macro_rules! define_dep_nodes {
(<$tcx:tt>
$(
[$($attrs:tt)*]
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
,)*
) => (
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
#[allow(non_camel_case_types)]
pub enum DepKind {
$($variant),*
pub use rustc_query_system::dep_graph::dep_kind::DepKind;

trait DepKindExt {
fn can_reconstruct_query_key<$tcx>(&self) -> bool;
}

impl DepKind {
impl DepKindExt for DepKind {
#[allow(unreachable_code)]
pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
fn can_reconstruct_query_key<$tcx>(&self) -> bool {
match *self {
$(
DepKind :: $variant => {
Expand All @@ -128,7 +115,7 @@ macro_rules! define_dep_nodes {

// tuple args
$({
return <$tuple_arg_ty as DepNodeParams<TyCtxt<'_>>>
return <$tuple_arg_ty as DepNodeParams<TyCtxt<$tcx>>>
::can_reconstruct_query_key();
})*

Expand All @@ -137,39 +124,6 @@ macro_rules! define_dep_nodes {
)*
}
}

pub fn is_anon(&self) -> bool {
match *self {
$(
DepKind :: $variant => { contains_anon_attr!($($attrs)*) }
)*
}
}

pub fn is_eval_always(&self) -> bool {
match *self {
$(
DepKind :: $variant => { contains_eval_always_attr!($($attrs)*) }
)*
}
}

#[allow(unreachable_code)]
pub fn has_params(&self) -> bool {
match *self {
$(
DepKind :: $variant => {
// tuple args
$({
erase!($tuple_arg_ty);
return true;
})*

false
}
)*
}
}
}

pub struct DepConstructor;
Expand All @@ -191,7 +145,7 @@ macro_rules! define_dep_nodes {
)*
}

pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
pub type DepNode = rustc_query_system::dep_graph::DepNode<rustc_query_system::dep_graph::dep_kind::DepKind>;

pub trait DepNodeExt: Sized {
/// Construct a DepNode from the given DepKind and DefPathHash. This
Expand Down Expand Up @@ -292,7 +246,8 @@ macro_rules! define_dep_nodes {
);
}

rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
#[allow(unused_lifetimes)]
rustc_query_system::rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// We use this for most things when incr. comp. is turned off.
[] Null,

Expand Down
27 changes: 8 additions & 19 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::ich::StableHashingContext;
use crate::ty::query::try_load_from_on_disk_cache;
use crate::ty::{self, TyCtxt};
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock;
//use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::LocalDefId;
Expand All @@ -17,22 +17,14 @@ pub use rustc_query_system::dep_graph::{

pub use dep_node::{label_strs, DepConstructor, DepKind, DepNode, DepNodeExt};

pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepKind>;
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
pub type DepGraph = rustc_query_system::dep_graph::DepGraph;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps;
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery;
pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph;
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph;

/*
impl rustc_query_system::dep_graph::DepKind for DepKind {
const NULL: Self = DepKind::Null;

fn is_eval_always(&self) -> bool {
DepKind::is_eval_always(self)
}

fn has_params(&self) -> bool {
DepKind::has_params(self)
}

fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", node.kind)?;
Expand Down Expand Up @@ -81,11 +73,8 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
op(icx.task_deps)
})
}

fn can_reconstruct_query_key(&self) -> bool {
DepKind::can_reconstruct_query_key(self)
}
}
*/

impl<'tcx> DepContext for TyCtxt<'tcx> {
type DepKind = DepKind;
Expand Down
Loading