Skip to content

Commit

Permalink
Use a constructor function per dep node instead of an enum and a sing…
Browse files Browse the repository at this point in the history
…le function
  • Loading branch information
Zoxc committed Feb 19, 2020
1 parent b248767 commit d924a25
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 57 deletions.
86 changes: 36 additions & 50 deletions src/librustc/dep_graph/dep_node.rs
Expand Up @@ -76,10 +76,6 @@ macro_rules! erase {
($x:tt) => {{}};
}

macro_rules! replace {
($x:tt with $($y:tt)*) => ($($y)*)
}

macro_rules! is_anon_attr {
(anon) => {
true
Expand Down Expand Up @@ -175,10 +171,43 @@ macro_rules! define_dep_nodes {
}
}

pub enum DepConstructor<$tcx> {
pub struct DepConstructor;

impl DepConstructor {
$(
$variant $(( $tuple_arg_ty ))*
),*
#[inline(always)]
#[allow(unreachable_code, non_snake_case)]
pub fn $variant<'tcx>(_tcx: TyCtxt<'tcx>, $(arg: $tuple_arg_ty)*) -> DepNode {
// tuple args
$({
erase!($tuple_arg_ty);
let hash = DepNodeParams::to_fingerprint(&arg, _tcx);
let dep_node = DepNode {
kind: DepKind::$variant,
hash
};

#[cfg(debug_assertions)]
{
if !dep_node.kind.can_reconstruct_query_key() &&
(_tcx.sess.opts.debugging_opts.incremental_info ||
_tcx.sess.opts.debugging_opts.query_dep_graph)
{
_tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
arg.to_debug_str(_tcx)
});
}
}

return dep_node;
})*

DepNode {
kind: DepKind::$variant,
hash: Fingerprint::ZERO,
}
}
)*
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
Expand All @@ -189,49 +218,6 @@ macro_rules! define_dep_nodes {
}

impl DepNode {
#[allow(unreachable_code, non_snake_case)]
pub fn new<'tcx>(tcx: TyCtxt<'tcx>,
dep: DepConstructor<'tcx>)
-> DepNode
{
match dep {
$(
DepConstructor :: $variant $(( replace!(($tuple_arg_ty) with arg) ))*
=>
{
// tuple args
$({
erase!($tuple_arg_ty);
let hash = DepNodeParams::to_fingerprint(&arg, tcx);
let dep_node = DepNode {
kind: DepKind::$variant,
hash
};

#[cfg(debug_assertions)]
{
if !dep_node.kind.can_reconstruct_query_key() &&
(tcx.sess.opts.debugging_opts.incremental_info ||
tcx.sess.opts.debugging_opts.query_dep_graph)
{
tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
arg.to_debug_str(tcx)
});
}
}

return dep_node;
})*

DepNode {
kind: DepKind::$variant,
hash: Fingerprint::ZERO,
}
}
)*
}
}

/// Construct a DepNode from the given DepKind and DefPathHash. This
/// method will assert that the given DepKind actually requires a
/// single DefId/DefPathHash parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mono.rs
Expand Up @@ -362,7 +362,7 @@ impl<'tcx> CodegenUnit<'tcx> {
}

pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name()))
DepConstructor::CompileCodegenUnit(tcx, self.name())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Expand Up @@ -2,7 +2,7 @@

use crate::arena::Arena;
use crate::dep_graph::DepGraph;
use crate::dep_graph::{self, DepConstructor, DepNode};
use crate::dep_graph::{self, DepConstructor};
use crate::hir::exports::Export;
use crate::hir::map as hir_map;
use crate::hir::map::DefPathHash;
Expand Down Expand Up @@ -1347,7 +1347,7 @@ impl<'tcx> TyCtxt<'tcx> {
// We cannot use the query versions of crates() and crate_hash(), since
// those would need the DepNodes that we are allocating here.
for cnum in self.cstore.crates_untracked() {
let dep_node = DepNode::new(self, DepConstructor::CrateMetadata(cnum));
let dep_node = DepConstructor::CrateMetadata(self, cnum);
let crate_hash = self.cstore.crate_hash_untracked(cnum);
self.dep_graph.with_task(
dep_node,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/mod.rs
@@ -1,4 +1,4 @@
use crate::dep_graph::{self, DepNode};
use crate::dep_graph::{self, DepConstructor, DepNode};
use crate::hir::exports::Export;
use crate::infer::canonical::{self, Canonical};
use crate::lint::LintLevelMap;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/query/plumbing.rs
Expand Up @@ -987,9 +987,7 @@ macro_rules! define_queries_inner {
#[allow(unused)]
#[inline(always)]
fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode {
use crate::dep_graph::DepConstructor::*;

DepNode::new(tcx, $node(*key))
DepConstructor::$node(tcx, *key)
}

#[inline(always)]
Expand Down

0 comments on commit d924a25

Please sign in to comment.