Skip to content

Commit 450cce3

Browse files
committed
Auto merge of #64850 - Mark-Simulacrum:dedup-dep-node, r=<try>
Remove duplicate DepNode::new Locally this shaves off about 3 seconds of compile time for librustc, which while not much, is something for a simple PR like this. Code is merely duplicated up from the main `DepNode::new` body. Across 3 runs for each branch I obtained these times for compiling librustc: master: 286.244, 285.208, 303.577 this branch: 282.175, 281.891, 282.968 r? @michaelwoerister
2 parents a37fe2d + d3bc8d0 commit 450cce3

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/librustc/dep_graph/dep_node.rs

+40
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,46 @@ macro_rules! define_dep_nodes {
198198
}
199199

200200
impl DepNode {
201+
pub fn new_compile_codegen_unit(tcx: TyCtxt<'tcx>, s: InternedString) -> DepNode {
202+
let hash = DepNodeParams::to_fingerprint(&s, tcx);
203+
let dep_node = DepNode {
204+
kind: DepKind::CompileCodegenUnit,
205+
hash
206+
};
207+
208+
if cfg!(debug_assertions) &&
209+
!dep_node.kind.can_reconstruct_query_key() &&
210+
(tcx.sess.opts.debugging_opts.incremental_info ||
211+
tcx.sess.opts.debugging_opts.query_dep_graph)
212+
{
213+
tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
214+
s.to_debug_str(tcx)
215+
});
216+
}
217+
218+
dep_node
219+
}
220+
221+
pub fn new_crate_metadata(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DepNode {
222+
let hash = DepNodeParams::to_fingerprint(&cnum, tcx);
223+
let dep_node = DepNode {
224+
kind: DepKind::CrateMetadata,
225+
hash
226+
};
227+
228+
if cfg!(debug_assertions) &&
229+
!dep_node.kind.can_reconstruct_query_key() &&
230+
(tcx.sess.opts.debugging_opts.incremental_info ||
231+
tcx.sess.opts.debugging_opts.query_dep_graph)
232+
{
233+
tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
234+
cnum.to_debug_str(tcx)
235+
});
236+
}
237+
238+
dep_node
239+
}
240+
201241
#[allow(unreachable_code, non_snake_case)]
202242
#[inline(always)]
203243
pub fn new<'tcx>(tcx: TyCtxt<'tcx>,

src/librustc/mir/mono.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syntax::source_map::Span;
66
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
77
use crate::util::nodemap::FxHashMap;
88
use crate::ty::print::obsolete::DefPathBasedNames;
9-
use crate::dep_graph::{WorkProductId, DepNode, WorkProduct, DepConstructor};
9+
use crate::dep_graph::{WorkProductId, DepNode, WorkProduct};
1010
use rustc_data_structures::base_n;
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
1212
StableHasher};
@@ -414,7 +414,8 @@ impl<'tcx> CodegenUnit<'tcx> {
414414
}
415415

416416
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
417-
DepNode::new(tcx, DepConstructor::CompileCodegenUnit(self.name().clone()))
417+
// N.B. don't use DepNode::new here as we then inline an enormous function
418+
DepNode::new_compile_codegen_unit(tcx, self.name().clone())
418419
}
419420
}
420421

src/librustc/ty/context.rs

+3-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, DepNode, DepConstructor};
5+
use crate::dep_graph::{self, DepNode};
66
use crate::session::Session;
77
use crate::session::config::{BorrowckMode, OutputFilenames};
88
use crate::session::config::CrateType;
@@ -1416,7 +1416,8 @@ impl<'tcx> TyCtxt<'tcx> {
14161416
// We cannot use the query versions of crates() and crate_hash(), since
14171417
// those would need the DepNodes that we are allocating here.
14181418
for cnum in self.cstore.crates_untracked() {
1419-
let dep_node = DepNode::new(self, DepConstructor::CrateMetadata(cnum));
1419+
// N.B. don't use DepNode::new here as we then inline an enormous function
1420+
let dep_node = DepNode::new_crate_metadata(self, cnum);
14201421
let crate_hash = self.cstore.crate_hash_untracked(cnum);
14211422
self.dep_graph.with_task(dep_node,
14221423
self,

0 commit comments

Comments
 (0)