Skip to content

Commit

Permalink
Auto merge of #64850 - Mark-Simulacrum:dedup-dep-node, r=<try>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 27, 2019
2 parents a37fe2d + d3bc8d0 commit 450cce3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,46 @@ macro_rules! define_dep_nodes {
}

impl DepNode {
pub fn new_compile_codegen_unit(tcx: TyCtxt<'tcx>, s: InternedString) -> DepNode {
let hash = DepNodeParams::to_fingerprint(&s, tcx);
let dep_node = DepNode {
kind: DepKind::CompileCodegenUnit,
hash
};

if cfg!(debug_assertions) &&
!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, || {
s.to_debug_str(tcx)
});
}

dep_node
}

pub fn new_crate_metadata(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DepNode {
let hash = DepNodeParams::to_fingerprint(&cnum, tcx);
let dep_node = DepNode {
kind: DepKind::CrateMetadata,
hash
};

if cfg!(debug_assertions) &&
!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, || {
cnum.to_debug_str(tcx)
});
}

dep_node
}

#[allow(unreachable_code, non_snake_case)]
#[inline(always)]
pub fn new<'tcx>(tcx: TyCtxt<'tcx>,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syntax::source_map::Span;
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
use crate::util::nodemap::FxHashMap;
use crate::ty::print::obsolete::DefPathBasedNames;
use crate::dep_graph::{WorkProductId, DepNode, WorkProduct, DepConstructor};
use crate::dep_graph::{WorkProductId, DepNode, WorkProduct};
use rustc_data_structures::base_n;
use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
StableHasher};
Expand Down Expand Up @@ -414,7 +414,8 @@ impl<'tcx> CodegenUnit<'tcx> {
}

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

Expand Down
5 changes: 3 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::arena::Arena;
use crate::dep_graph::DepGraph;
use crate::dep_graph::{self, DepNode, DepConstructor};
use crate::dep_graph::{self, DepNode};
use crate::session::Session;
use crate::session::config::{BorrowckMode, OutputFilenames};
use crate::session::config::CrateType;
Expand Down Expand Up @@ -1416,7 +1416,8 @@ 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));
// N.B. don't use DepNode::new here as we then inline an enormous function
let dep_node = DepNode::new_crate_metadata(self, cnum);
let crate_hash = self.cstore.crate_hash_untracked(cnum);
self.dep_graph.with_task(dep_node,
self,
Expand Down

0 comments on commit 450cce3

Please sign in to comment.