Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DepKind by trait objects #78314

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 55 additions & 35 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,64 +110,84 @@ macro_rules! define_dep_nodes {
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
,)*
) => (
pub mod dep_kind {
use super::*;

$(
#[allow(non_camel_case_types)]
pub struct $variant;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to rename $variant to $name here to be consistent with the proc macro and compiler/rustc_middle/src/ty/query/mod.rs
Specifically the inconsistency with the line $(impl dep_kind::$name { bothers me.


impl $variant {
#[inline]
#[allow(unreachable_code)]
#[allow(unused_lifetimes)] // inside `tuple_arg_ty`
pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
if contains_anon_attr!($($attrs)*) {
return false;
}

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

true
}

#[inline]
pub fn is_anon(&self) -> bool {
contains_anon_attr!($($attrs)*)
}

#[inline]
pub fn is_eval_always(&self) -> bool {
contains_eval_always_attr!($($attrs)*)
}

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

false
}
}
)*
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
#[allow(non_camel_case_types)]
pub enum DepKind {
$($variant),*
}

impl DepKind {
#[allow(unreachable_code)]
pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
pub fn can_reconstruct_query_key(&self) -> bool {
match *self {
$(
DepKind :: $variant => {
if contains_anon_attr!($($attrs)*) {
return false;
}

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

true
}
)*
$(DepKind::$variant => dep_kind::$variant.can_reconstruct_query_key()),*
}
}

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

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

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

false
}
)*
$(DepKind::$variant => dep_kind::$variant.has_params()),*
}
}
}
Expand Down