Skip to content

Commit d924a25

Browse files
committed
Use a constructor function per dep node instead of an enum and a single function
1 parent b248767 commit d924a25

File tree

5 files changed

+41
-57
lines changed

5 files changed

+41
-57
lines changed

src/librustc/dep_graph/dep_node.rs

+36-50
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ macro_rules! erase {
7676
($x:tt) => {{}};
7777
}
7878

79-
macro_rules! replace {
80-
($x:tt with $($y:tt)*) => ($($y)*)
81-
}
82-
8379
macro_rules! is_anon_attr {
8480
(anon) => {
8581
true
@@ -175,10 +171,43 @@ macro_rules! define_dep_nodes {
175171
}
176172
}
177173

178-
pub enum DepConstructor<$tcx> {
174+
pub struct DepConstructor;
175+
176+
impl DepConstructor {
179177
$(
180-
$variant $(( $tuple_arg_ty ))*
181-
),*
178+
#[inline(always)]
179+
#[allow(unreachable_code, non_snake_case)]
180+
pub fn $variant<'tcx>(_tcx: TyCtxt<'tcx>, $(arg: $tuple_arg_ty)*) -> DepNode {
181+
// tuple args
182+
$({
183+
erase!($tuple_arg_ty);
184+
let hash = DepNodeParams::to_fingerprint(&arg, _tcx);
185+
let dep_node = DepNode {
186+
kind: DepKind::$variant,
187+
hash
188+
};
189+
190+
#[cfg(debug_assertions)]
191+
{
192+
if !dep_node.kind.can_reconstruct_query_key() &&
193+
(_tcx.sess.opts.debugging_opts.incremental_info ||
194+
_tcx.sess.opts.debugging_opts.query_dep_graph)
195+
{
196+
_tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
197+
arg.to_debug_str(_tcx)
198+
});
199+
}
200+
}
201+
202+
return dep_node;
203+
})*
204+
205+
DepNode {
206+
kind: DepKind::$variant,
207+
hash: Fingerprint::ZERO,
208+
}
209+
}
210+
)*
182211
}
183212

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

191220
impl DepNode {
192-
#[allow(unreachable_code, non_snake_case)]
193-
pub fn new<'tcx>(tcx: TyCtxt<'tcx>,
194-
dep: DepConstructor<'tcx>)
195-
-> DepNode
196-
{
197-
match dep {
198-
$(
199-
DepConstructor :: $variant $(( replace!(($tuple_arg_ty) with arg) ))*
200-
=>
201-
{
202-
// tuple args
203-
$({
204-
erase!($tuple_arg_ty);
205-
let hash = DepNodeParams::to_fingerprint(&arg, tcx);
206-
let dep_node = DepNode {
207-
kind: DepKind::$variant,
208-
hash
209-
};
210-
211-
#[cfg(debug_assertions)]
212-
{
213-
if !dep_node.kind.can_reconstruct_query_key() &&
214-
(tcx.sess.opts.debugging_opts.incremental_info ||
215-
tcx.sess.opts.debugging_opts.query_dep_graph)
216-
{
217-
tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
218-
arg.to_debug_str(tcx)
219-
});
220-
}
221-
}
222-
223-
return dep_node;
224-
})*
225-
226-
DepNode {
227-
kind: DepKind::$variant,
228-
hash: Fingerprint::ZERO,
229-
}
230-
}
231-
)*
232-
}
233-
}
234-
235221
/// Construct a DepNode from the given DepKind and DefPathHash. This
236222
/// method will assert that the given DepKind actually requires a
237223
/// single DefId/DefPathHash parameter.

src/librustc/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'tcx> CodegenUnit<'tcx> {
362362
}
363363

364364
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
365-
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name()))
365+
DepConstructor::CompileCodegenUnit(tcx, self.name())
366366
}
367367
}
368368

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::arena::Arena;
44
use crate::dep_graph::DepGraph;
5-
use crate::dep_graph::{self, DepConstructor, DepNode};
5+
use crate::dep_graph::{self, DepConstructor};
66
use crate::hir::exports::Export;
77
use crate::hir::map as hir_map;
88
use crate::hir::map::DefPathHash;
@@ -1347,7 +1347,7 @@ impl<'tcx> TyCtxt<'tcx> {
13471347
// We cannot use the query versions of crates() and crate_hash(), since
13481348
// those would need the DepNodes that we are allocating here.
13491349
for cnum in self.cstore.crates_untracked() {
1350-
let dep_node = DepNode::new(self, DepConstructor::CrateMetadata(cnum));
1350+
let dep_node = DepConstructor::CrateMetadata(self, cnum);
13511351
let crate_hash = self.cstore.crate_hash_untracked(cnum);
13521352
self.dep_graph.with_task(
13531353
dep_node,

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::dep_graph::{self, DepNode};
1+
use crate::dep_graph::{self, DepConstructor, DepNode};
22
use crate::hir::exports::Export;
33
use crate::infer::canonical::{self, Canonical};
44
use crate::lint::LintLevelMap;

src/librustc/ty/query/plumbing.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,7 @@ macro_rules! define_queries_inner {
987987
#[allow(unused)]
988988
#[inline(always)]
989989
fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode {
990-
use crate::dep_graph::DepConstructor::*;
991-
992-
DepNode::new(tcx, $node(*key))
990+
DepConstructor::$node(tcx, *key)
993991
}
994992

995993
#[inline(always)]

0 commit comments

Comments
 (0)