Skip to content

Commit 9ad5473

Browse files
authored
Rollup merge of rust-lang#44364 - michaelwoerister:hash-all-the-things2, r=nikomatsakis
incr.comp.: Compute fingerprint for all query results. This PR enables query result fingerprinting in incremental mode. This is an essential piece of infrastructure for red/green tracking. We don't do anything with the fingerprints yet but merging the infrastructure should protect it from bit-rotting and will make it easier to start measuring its performance impact (and thus let us determine if we should switch to a faster hashing algorithm rather sooner than later). Note, this PR also includes the changes from rust-lang#43887 which I'm therefore closing. No need to re-review the first commit though. r? @nikomatsakis
2 parents 3a7b960 + 4961a8e commit 9ad5473

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1827
-731
lines changed

src/librustc/dep_graph/dep_node.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
603603
}
604604

605605
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
606-
where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> + fmt::Debug
606+
where T: HashStable<StableHashingContext<'gcx>> + fmt::Debug
607607
{
608608
default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
609609

610610
default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
611-
let mut hcx = StableHashingContext::new(tcx);
611+
let mut hcx = tcx.create_stable_hashing_context();
612612
let mut hasher = StableHasher::new();
613613

614614
self.hash_stable(&mut hcx, &mut hasher);
@@ -633,6 +633,18 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
633633
}
634634
}
635635

636+
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
637+
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
638+
639+
fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
640+
tcx.hir.definitions().def_path_hash(self.0).0
641+
}
642+
643+
fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
644+
tcx.item_path_str(DefId::local(self.0))
645+
}
646+
}
647+
636648
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
637649
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
638650

src/librustc/dep_graph/graph.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::fx::FxHashMap;
12+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
13+
StableHashingContextProvider};
1214
use session::config::OutputType;
1315
use std::cell::{Ref, RefCell};
1416
use std::rc::Rc;
1517
use util::common::{ProfileQueriesMsg, profq_msg};
1618

19+
use ich::Fingerprint;
20+
1721
use super::dep_node::{DepNode, DepKind, WorkProductId};
1822
use super::query::DepGraphQuery;
1923
use super::raii;
@@ -71,10 +75,6 @@ impl DepGraph {
7175
self.data.as_ref().map(|data| raii::IgnoreTask::new(&data.edges))
7276
}
7377

74-
pub fn in_task<'graph>(&'graph self, key: DepNode) -> Option<raii::DepTask<'graph>> {
75-
self.data.as_ref().map(|data| raii::DepTask::new(&data.edges, key))
76-
}
77-
7878
pub fn with_ignore<OP,R>(&self, op: OP) -> R
7979
where OP: FnOnce() -> R
8080
{
@@ -109,24 +109,38 @@ impl DepGraph {
109109
/// `arg` parameter.
110110
///
111111
/// [README]: README.md
112-
pub fn with_task<C, A, R>(&self,
113-
key: DepNode,
114-
cx: C,
115-
arg: A,
116-
task: fn(C, A) -> R)
117-
-> (R, DepNodeIndex)
118-
where C: DepGraphSafe
112+
pub fn with_task<C, A, R, HCX>(&self,
113+
key: DepNode,
114+
cx: C,
115+
arg: A,
116+
task: fn(C, A) -> R)
117+
-> (R, DepNodeIndex)
118+
where C: DepGraphSafe + StableHashingContextProvider<ContextType=HCX>,
119+
R: HashStable<HCX>,
119120
{
120121
if let Some(ref data) = self.data {
121122
data.edges.borrow_mut().push_task(key);
122123
if cfg!(debug_assertions) {
123124
profq_msg(ProfileQueriesMsg::TaskBegin(key.clone()))
124125
};
126+
127+
// In incremental mode, hash the result of the task. We don't
128+
// do anything with the hash yet, but we are computing it
129+
// anyway so that
130+
// - we make sure that the infrastructure works and
131+
// - we can get an idea of the runtime cost.
132+
let mut hcx = cx.create_stable_hashing_context();
133+
125134
let result = task(cx, arg);
126135
if cfg!(debug_assertions) {
127136
profq_msg(ProfileQueriesMsg::TaskEnd)
128137
};
129138
let dep_node_index = data.edges.borrow_mut().pop_task(key);
139+
140+
let mut stable_hasher = StableHasher::new();
141+
result.hash_stable(&mut hcx, &mut stable_hasher);
142+
let _: Fingerprint = stable_hasher.finish();
143+
130144
(result, dep_node_index)
131145
} else {
132146
(task(cx, arg), DepNodeIndex::INVALID)

src/librustc/dep_graph/safe.rs

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ impl<'a, A> DepGraphSafe for &'a A
5858
{
5959
}
6060

61+
/// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
62+
impl<'a, A> DepGraphSafe for &'a mut A
63+
where A: DepGraphSafe,
64+
{
65+
}
66+
67+
6168
/// No data here! :)
6269
impl DepGraphSafe for () {
6370
}

src/librustc/hir/map/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub struct Map<'hir> {
247247
/// plain old integers.
248248
map: Vec<MapEntry<'hir>>,
249249

250-
definitions: Definitions,
250+
definitions: &'hir Definitions,
251251

252252
/// Bodies inlined from other crates are cached here.
253253
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
@@ -304,8 +304,8 @@ impl<'hir> Map<'hir> {
304304
}
305305

306306
#[inline]
307-
pub fn definitions(&self) -> &Definitions {
308-
&self.definitions
307+
pub fn definitions(&self) -> &'hir Definitions {
308+
self.definitions
309309
}
310310

311311
pub fn def_key(&self, def_id: DefId) -> DefKey {
@@ -1013,7 +1013,7 @@ impl Named for TraitItem { fn name(&self) -> Name { self.name } }
10131013
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
10141014

10151015
pub fn map_crate<'hir>(forest: &'hir mut Forest,
1016-
definitions: Definitions)
1016+
definitions: &'hir Definitions)
10171017
-> Map<'hir> {
10181018
let map = {
10191019
let mut collector = NodeCollector::root(&forest.krate,

src/librustc/ich/caching_codemap_view.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::rc::Rc;
1212
use syntax::codemap::CodeMap;
1313
use syntax_pos::{BytePos, FileMap};
14-
use ty::TyCtxt;
1514

1615
#[derive(Clone)]
1716
struct CacheEntry {
@@ -23,15 +22,14 @@ struct CacheEntry {
2322
file_index: usize,
2423
}
2524

26-
pub struct CachingCodemapView<'tcx> {
27-
codemap: &'tcx CodeMap,
25+
pub struct CachingCodemapView<'cm> {
26+
codemap: &'cm CodeMap,
2827
line_cache: [CacheEntry; 3],
2928
time_stamp: usize,
3029
}
3130

32-
impl<'gcx> CachingCodemapView<'gcx> {
33-
pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CachingCodemapView<'gcx> {
34-
let codemap = tcx.sess.codemap();
31+
impl<'cm> CachingCodemapView<'cm> {
32+
pub fn new(codemap: &'cm CodeMap) -> CachingCodemapView<'cm> {
3533
let files = codemap.files();
3634
let first_file = files[0].clone();
3735
let entry = CacheEntry {

0 commit comments

Comments
 (0)