Skip to content

Commit

Permalink
ICH: Add ability to test the ICH of exported metadata items.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Sep 23, 2016
1 parent f2c53ea commit 6a2666d
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 115 deletions.
10 changes: 4 additions & 6 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ use std::io::Write;
use syntax::ast;
use syntax::parse::token::InternedString;
use syntax_pos::Span;

const IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
const THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};

pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let _ignore = tcx.dep_graph.in_ignore();
Expand Down Expand Up @@ -91,7 +89,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
assert!(tcx.sess.opts.debugging_opts.query_dep_graph,
"cannot use the `#[{}]` or `#[{}]` annotations \
without supplying `-Z query-dep-graph`",
IF_THIS_CHANGED, THEN_THIS_WOULD_NEED);
ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED);
}

// Check paths.
Expand Down Expand Up @@ -125,7 +123,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
let def_id = self.tcx.map.local_def_id(node_id);
for attr in attrs {
if attr.check_name(IF_THIS_CHANGED) {
if attr.check_name(ATTR_IF_THIS_CHANGED) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
None => DepNode::Hir(def_id),
Expand All @@ -141,7 +139,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
}
};
self.if_this_changed.push((attr.span, def_id, dep_node));
} else if attr.check_name(THEN_THIS_WOULD_NEED) {
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
let dep_node_interned = self.argument(attr);
let dep_node = match dep_node_interned {
Some(ref n) => {
Expand Down
40 changes: 38 additions & 2 deletions src/librustc_incremental/calculate_svh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//! at the beginning.

use syntax::ast;
use std::cell::RefCell;
use std::hash::{Hash, SipHasher, Hasher};
use rustc::dep_graph::DepNode;
use rustc::hir;
Expand All @@ -46,7 +47,42 @@ mod def_path_hash;
mod svh_visitor;
mod caching_codemap_view;

pub type IncrementalHashesMap = FnvHashMap<DepNode<DefId>, u64>;
pub struct IncrementalHashesMap {
hashes: FnvHashMap<DepNode<DefId>, u64>,

// These are the metadata hashes for the current crate as they were stored
// during the last compilation session. They are only loaded if
// -Z query-dep-graph was specified and are needed for auto-tests using
// the #[rustc_metadata_dirty] and #[rustc_metadata_clean] attributes to
// check whether some metadata hash has changed in between two revisions.
pub prev_metadata_hashes: RefCell<FnvHashMap<DefId, u64>>,
}

impl IncrementalHashesMap {
pub fn new() -> IncrementalHashesMap {
IncrementalHashesMap {
hashes: FnvHashMap(),
prev_metadata_hashes: RefCell::new(FnvHashMap()),
}
}

pub fn insert(&mut self, k: DepNode<DefId>, v: u64) -> Option<u64> {
self.hashes.insert(k, v)
}

pub fn iter<'a>(&'a self) -> ::std::collections::hash_map::Iter<'a, DepNode<DefId>, u64> {
self.hashes.iter()
}
}

impl<'a> ::std::ops::Index<&'a DepNode<DefId>> for IncrementalHashesMap {
type Output = u64;

fn index(&self, index: &'a DepNode<DefId>) -> &u64 {
&self.hashes[index]
}
}


pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> IncrementalHashesMap {
Expand All @@ -55,7 +91,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
let hash_spans = tcx.sess.opts.debuginfo != NoDebugInfo;
let mut visitor = HashItemsVisitor {
tcx: tcx,
hashes: FnvHashMap(),
hashes: IncrementalHashesMap::new(),
def_path_hashes: DefPathHashes::new(tcx),
codemap: CachingCodemapView::new(tcx),
hash_spans: hash_spans,
Expand Down
12 changes: 9 additions & 3 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ use std::hash::{Hash, SipHasher};
use super::def_path_hash::DefPathHashes;
use super::caching_codemap_view::CachingCodemapView;

const IGNORED_ATTRIBUTES: &'static [&'static str] = &["cfg",
"rustc_clean",
"rustc_dirty"];
const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
"cfg",
::ATTR_IF_THIS_CHANGED,
::ATTR_THEN_THIS_WOULD_NEED,
::ATTR_DIRTY,
::ATTR_CLEAN,
::ATTR_DIRTY_METADATA,
::ATTR_CLEAN_METADATA
];

pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> {
pub tcx: TyCtxt<'hash, 'tcx, 'tcx>,
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ extern crate serialize as rustc_serialize;
#[macro_use] extern crate syntax;
extern crate syntax_pos;

const ATTR_DIRTY: &'static str = "rustc_dirty";
const ATTR_CLEAN: &'static str = "rustc_clean";
const ATTR_DIRTY_METADATA: &'static str = "rustc_metadata_dirty";
const ATTR_CLEAN_METADATA: &'static str = "rustc_metadata_clean";
const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";

mod assert_dep_graph;
mod calculate_svh;
mod persist;
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_incremental/persist/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use rustc::dep_graph::{DepNode, WorkProduct, WorkProductId};
use rustc::hir::def_id::DefIndex;
use std::sync::Arc;
use rustc_data_structures::fnv::FnvHashMap;

use super::directory::DefPathIndex;

Expand Down Expand Up @@ -93,6 +94,18 @@ pub struct SerializedMetadataHashes {
/// a `DefPathIndex` that gets retracted to the current `DefId`
/// (matching the one found in this structure).
pub hashes: Vec<SerializedMetadataHash>,

/// For each DefIndex (as it occurs in SerializedMetadataHash), this
/// map stores the DefPathIndex (as it occurs in DefIdDirectory), so
/// that we can find the new DefId for a SerializedMetadataHash in a
/// subsequent compilation session.
///
/// This map is only needed for running auto-tests using the
/// #[rustc_metadata_dirty] and #[rustc_metadata_clean] attributes, and
/// is only populated if -Z query-dep-graph is specified. It will be
/// empty otherwise. Importing crates are perfectly happy with just having
/// the DefIndex.
pub index_map: FnvHashMap<DefIndex, DefPathIndex>
}

/// The hash for some metadata that (when saving) will be exported
Expand Down
1 change: 0 additions & 1 deletion src/librustc_incremental/persist/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ impl<'a,'tcx> DefIdDirectoryBuilder<'a,'tcx> {
&self.directory.paths[id.index as usize]
}


pub fn map(&mut self, node: &DepNode<DefId>) -> DepNode<DefPathIndex> {
node.map_def(|&def_id| Some(self.add(def_id))).unwrap()
}
Expand Down
Loading

0 comments on commit 6a2666d

Please sign in to comment.