Skip to content

Commit d170379

Browse files
committed
Auto merge of #46370 - michaelwoerister:rm-metadata-hashing, r=eddyb
incr.comp.: Remove ability to produce incr. comp. hashes during metadata export. This functionality has been superseded by on-import hashing, which can be less conservative and does not require extra infrastructure. r? @nikomatsakis
2 parents 4fa202d + 7ebccbb commit d170379

Some content is hidden

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

45 files changed

+44
-1720
lines changed

src/librustc/ich/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ mod impls_syntax;
2828

2929
pub const ATTR_DIRTY: &'static str = "rustc_dirty";
3030
pub const ATTR_CLEAN: &'static str = "rustc_clean";
31-
pub const ATTR_DIRTY_METADATA: &'static str = "rustc_metadata_dirty";
32-
pub const ATTR_CLEAN_METADATA: &'static str = "rustc_metadata_clean";
3331
pub const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
3432
pub const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
3533
pub const ATTR_PARTITION_REUSED: &'static str = "rustc_partition_reused";
@@ -41,8 +39,6 @@ pub const DEP_GRAPH_ASSERT_ATTRS: &'static [&'static str] = &[
4139
ATTR_THEN_THIS_WOULD_NEED,
4240
ATTR_DIRTY,
4341
ATTR_CLEAN,
44-
ATTR_DIRTY_METADATA,
45-
ATTR_CLEAN_METADATA,
4642
ATTR_PARTITION_REUSED,
4743
ATTR_PARTITION_TRANSLATED,
4844
];
@@ -53,8 +49,6 @@ pub const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
5349
ATTR_THEN_THIS_WOULD_NEED,
5450
ATTR_DIRTY,
5551
ATTR_CLEAN,
56-
ATTR_DIRTY_METADATA,
57-
ATTR_CLEAN_METADATA,
5852
ATTR_PARTITION_REUSED,
5953
ATTR_PARTITION_TRANSLATED,
6054
];

src/librustc/middle/cstore.rs

+2-28
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,6 @@ impl EncodedMetadata {
175175
}
176176
}
177177

178-
/// The hash for some metadata that (when saving) will be exported
179-
/// from this crate, or which (when importing) was exported by an
180-
/// upstream crate.
181-
#[derive(Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
182-
pub struct EncodedMetadataHash {
183-
pub def_index: u32,
184-
pub hash: ich::Fingerprint,
185-
}
186-
187-
/// The hash for some metadata that (when saving) will be exported
188-
/// from this crate, or which (when importing) was exported by an
189-
/// upstream crate.
190-
#[derive(Debug, RustcEncodable, RustcDecodable, Clone)]
191-
pub struct EncodedMetadataHashes {
192-
// Stable content hashes for things in crate metadata, indexed by DefIndex.
193-
pub hashes: Vec<EncodedMetadataHash>,
194-
}
195-
196-
impl EncodedMetadataHashes {
197-
pub fn new() -> EncodedMetadataHashes {
198-
EncodedMetadataHashes {
199-
hashes: Vec::new(),
200-
}
201-
}
202-
}
203-
204178
/// The backend's way to give the crate store access to the metadata in a library.
205179
/// Note that it returns the raw metadata bytes stored in the library file, whether
206180
/// it is compressed, uncompressed, some weird mix, etc.
@@ -286,7 +260,7 @@ pub trait CrateStore {
286260
tcx: TyCtxt<'a, 'tcx, 'tcx>,
287261
link_meta: &LinkMeta,
288262
reachable: &NodeSet)
289-
-> (EncodedMetadata, EncodedMetadataHashes);
263+
-> EncodedMetadata;
290264
fn metadata_encoding_version(&self) -> &[u8];
291265
}
292266

@@ -370,7 +344,7 @@ impl CrateStore for DummyCrateStore {
370344
tcx: TyCtxt<'a, 'tcx, 'tcx>,
371345
link_meta: &LinkMeta,
372346
reachable: &NodeSet)
373-
-> (EncodedMetadata, EncodedMetadataHashes) {
347+
-> EncodedMetadata {
374348
bug!("encode_metadata")
375349
}
376350
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }

src/librustc/session/config.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10721072
"attempt to recover from parse errors (experimental)"),
10731073
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
10741074
"enable incremental compilation (experimental)"),
1075-
incremental_cc: bool = (false, parse_bool, [UNTRACKED],
1076-
"enable cross-crate incremental compilation (even more experimental)"),
10771075
incremental_queries: bool = (true, parse_bool, [UNTRACKED],
10781076
"enable incremental compilation support for queries (experimental)"),
10791077
incremental_info: bool = (false, parse_bool, [UNTRACKED],

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use hir::map::DefPathHash;
2424
use lint::{self, Lint};
2525
use ich::{StableHashingContext, NodeIdHashingMode};
2626
use middle::const_val::ConstVal;
27-
use middle::cstore::{CrateStore, LinkMeta, EncodedMetadataHashes};
27+
use middle::cstore::{CrateStore, LinkMeta};
2828
use middle::cstore::EncodedMetadata;
2929
use middle::free_region::FreeRegionMap;
3030
use middle::lang_items;
@@ -1242,7 +1242,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12421242

12431243
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
12441244
pub fn encode_metadata(self, link_meta: &LinkMeta, reachable: &NodeSet)
1245-
-> (EncodedMetadata, EncodedMetadataHashes)
1245+
-> EncodedMetadata
12461246
{
12471247
self.cstore.encode_metadata(self, link_meta, reachable)
12481248
}

src/librustc_incremental/persist/data.rs

-39
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
//! The data that we will serialize and deserialize.
1212
1313
use rustc::dep_graph::{WorkProduct, WorkProductId};
14-
use rustc::hir::map::DefPathHash;
15-
use rustc::middle::cstore::EncodedMetadataHash;
16-
use rustc_data_structures::fx::FxHashMap;
1714

1815
#[derive(Debug, RustcEncodable, RustcDecodable)]
1916
pub struct SerializedWorkProduct {
@@ -23,39 +20,3 @@ pub struct SerializedWorkProduct {
2320
/// work-product data itself
2421
pub work_product: WorkProduct,
2522
}
26-
27-
/// Data for use when downstream crates get recompiled.
28-
#[derive(Debug, RustcEncodable, RustcDecodable)]
29-
pub struct SerializedMetadataHashes {
30-
/// For each def-id defined in this crate that appears in the
31-
/// metadata, we hash all the inputs that were used when producing
32-
/// the metadata. We save this after compilation is done. Then,
33-
/// when some downstream crate is being recompiled, it can compare
34-
/// the hashes we saved against the hashes that it saw from
35-
/// before; this will tell it which of the items in this crate
36-
/// changed, which in turn implies what items in the downstream
37-
/// crate need to be recompiled.
38-
///
39-
/// Note that we store the def-ids here. This is because we don't
40-
/// reload this file when we recompile this crate, we will just
41-
/// regenerate it completely with the current hashes and new def-ids.
42-
///
43-
/// Then downstream creates will load up their
44-
/// `SerializedDepGraph`, which may contain `MetaData(X)` nodes
45-
/// where `X` refers to some item in this crate. That `X` will be
46-
/// a `DefPathIndex` that gets retracted to the current `DefId`
47-
/// (matching the one found in this structure).
48-
pub entry_hashes: Vec<EncodedMetadataHash>,
49-
50-
/// For each DefIndex (as it occurs in SerializedMetadataHash), this
51-
/// map stores the DefPathIndex (as it occurs in DefIdDirectory), so
52-
/// that we can find the new DefId for a SerializedMetadataHash in a
53-
/// subsequent compilation session.
54-
///
55-
/// This map is only needed for running auto-tests using the
56-
/// #[rustc_metadata_dirty] and #[rustc_metadata_clean] attributes, and
57-
/// is only populated if -Z query-dep-graph is specified. It will be
58-
/// empty otherwise. Importing crates are perfectly happy with just having
59-
/// the DefIndex.
60-
pub index_map: FxHashMap<u32, DefPathHash>
61-
}

src/librustc_incremental/persist/dirty_clean.rs

+2-170
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@
2323
//! Errors are reported if we are in the suitable configuration but
2424
//! the required condition is not met.
2525
//!
26-
//! The `#[rustc_metadata_dirty]` and `#[rustc_metadata_clean]` attributes
27-
//! can be used to check the incremental compilation hash (ICH) values of
28-
//! metadata exported in rlibs.
29-
//!
30-
//! - If a node is marked with `#[rustc_metadata_clean(cfg="rev2")]` we
31-
//! check that the metadata hash for that node is the same for "rev2"
32-
//! it was for "rev1".
33-
//! - If a node is marked with `#[rustc_metadata_dirty(cfg="rev2")]` we
34-
//! check that the metadata hash for that node is *different* for "rev2"
35-
//! than it was for "rev1".
36-
//!
37-
//! Note that the metadata-testing attributes must never specify the
38-
//! first revision. This would lead to a crash since there is no
39-
//! previous revision to compare things to.
40-
//!
4126
4227
use std::collections::HashSet;
4328
use std::iter::FromIterator;
@@ -49,10 +34,9 @@ use rustc::hir::map::Node as HirNode;
4934
use rustc::hir::def_id::DefId;
5035
use rustc::hir::itemlikevisit::ItemLikeVisitor;
5136
use rustc::hir::intravisit;
52-
use rustc::ich::{Fingerprint, ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA,
53-
ATTR_CLEAN_METADATA};
37+
use rustc::ich::{ATTR_DIRTY, ATTR_CLEAN};
5438
use syntax::ast::{self, Attribute, NestedMetaItem};
55-
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
39+
use rustc_data_structures::fx::FxHashSet;
5640
use syntax_pos::Span;
5741
use rustc::ty::TyCtxt;
5842

@@ -553,157 +537,6 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'a, 'tcx> {
553537
}
554538
}
555539

556-
pub fn check_dirty_clean_metadata<'a, 'tcx>(
557-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
558-
prev_metadata_hashes: &FxHashMap<DefId, Fingerprint>,
559-
current_metadata_hashes: &FxHashMap<DefId, Fingerprint>)
560-
{
561-
if !tcx.sess.opts.debugging_opts.query_dep_graph {
562-
return;
563-
}
564-
565-
tcx.dep_graph.with_ignore(||{
566-
let krate = tcx.hir.krate();
567-
let mut dirty_clean_visitor = DirtyCleanMetadataVisitor {
568-
tcx,
569-
prev_metadata_hashes,
570-
current_metadata_hashes,
571-
checked_attrs: FxHashSet(),
572-
};
573-
intravisit::walk_crate(&mut dirty_clean_visitor, krate);
574-
575-
let mut all_attrs = FindAllAttrs {
576-
tcx,
577-
attr_names: vec![ATTR_DIRTY_METADATA, ATTR_CLEAN_METADATA],
578-
found_attrs: vec![],
579-
};
580-
intravisit::walk_crate(&mut all_attrs, krate);
581-
582-
// Note that we cannot use the existing "unused attribute"-infrastructure
583-
// here, since that is running before trans. This is also the reason why
584-
// all trans-specific attributes are `Whitelisted` in syntax::feature_gate.
585-
all_attrs.report_unchecked_attrs(&dirty_clean_visitor.checked_attrs);
586-
});
587-
}
588-
589-
pub struct DirtyCleanMetadataVisitor<'a, 'tcx: 'a, 'm> {
590-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
591-
prev_metadata_hashes: &'m FxHashMap<DefId, Fingerprint>,
592-
current_metadata_hashes: &'m FxHashMap<DefId, Fingerprint>,
593-
checked_attrs: FxHashSet<ast::AttrId>,
594-
}
595-
596-
impl<'a, 'tcx, 'm> intravisit::Visitor<'tcx> for DirtyCleanMetadataVisitor<'a, 'tcx, 'm> {
597-
598-
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
599-
intravisit::NestedVisitorMap::All(&self.tcx.hir)
600-
}
601-
602-
fn visit_item(&mut self, item: &'tcx hir::Item) {
603-
self.check_item(item.id, item.span);
604-
intravisit::walk_item(self, item);
605-
}
606-
607-
fn visit_variant(&mut self,
608-
variant: &'tcx hir::Variant,
609-
generics: &'tcx hir::Generics,
610-
parent_id: ast::NodeId) {
611-
if let Some(e) = variant.node.disr_expr {
612-
self.check_item(e.node_id, variant.span);
613-
}
614-
615-
intravisit::walk_variant(self, variant, generics, parent_id);
616-
}
617-
618-
fn visit_variant_data(&mut self,
619-
variant_data: &'tcx hir::VariantData,
620-
_: ast::Name,
621-
_: &'tcx hir::Generics,
622-
_parent_id: ast::NodeId,
623-
span: Span) {
624-
if self.tcx.hir.find(variant_data.id()).is_some() {
625-
// VariantData that represent structs or tuples don't have a
626-
// separate entry in the HIR map and checking them would error,
627-
// so only check if this is an enum or union variant.
628-
self.check_item(variant_data.id(), span);
629-
}
630-
631-
intravisit::walk_struct_def(self, variant_data);
632-
}
633-
634-
fn visit_trait_item(&mut self, item: &'tcx hir::TraitItem) {
635-
self.check_item(item.id, item.span);
636-
intravisit::walk_trait_item(self, item);
637-
}
638-
639-
fn visit_impl_item(&mut self, item: &'tcx hir::ImplItem) {
640-
self.check_item(item.id, item.span);
641-
intravisit::walk_impl_item(self, item);
642-
}
643-
644-
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) {
645-
self.check_item(i.id, i.span);
646-
intravisit::walk_foreign_item(self, i);
647-
}
648-
649-
fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
650-
self.check_item(s.id, s.span);
651-
intravisit::walk_struct_field(self, s);
652-
}
653-
}
654-
655-
impl<'a, 'tcx, 'm> DirtyCleanMetadataVisitor<'a, 'tcx, 'm> {
656-
657-
fn check_item(&mut self, item_id: ast::NodeId, item_span: Span) {
658-
let def_id = self.tcx.hir.local_def_id(item_id);
659-
660-
for attr in self.tcx.get_attrs(def_id).iter() {
661-
if attr.check_name(ATTR_DIRTY_METADATA) {
662-
if check_config(self.tcx, attr) {
663-
if self.checked_attrs.insert(attr.id) {
664-
self.assert_state(false, def_id, item_span);
665-
}
666-
}
667-
} else if attr.check_name(ATTR_CLEAN_METADATA) {
668-
if check_config(self.tcx, attr) {
669-
if self.checked_attrs.insert(attr.id) {
670-
self.assert_state(true, def_id, item_span);
671-
}
672-
}
673-
}
674-
}
675-
}
676-
677-
fn assert_state(&self, should_be_clean: bool, def_id: DefId, span: Span) {
678-
let item_path = self.tcx.item_path_str(def_id);
679-
debug!("assert_state({})", item_path);
680-
681-
if let Some(&prev_hash) = self.prev_metadata_hashes.get(&def_id) {
682-
let hashes_are_equal = prev_hash == self.current_metadata_hashes[&def_id];
683-
684-
if should_be_clean && !hashes_are_equal {
685-
self.tcx.sess.span_err(
686-
span,
687-
&format!("Metadata hash of `{}` is dirty, but should be clean",
688-
item_path));
689-
}
690-
691-
let should_be_dirty = !should_be_clean;
692-
if should_be_dirty && hashes_are_equal {
693-
self.tcx.sess.span_err(
694-
span,
695-
&format!("Metadata hash of `{}` is clean, but should be dirty",
696-
item_path));
697-
}
698-
} else {
699-
self.tcx.sess.span_err(
700-
span,
701-
&format!("Could not find previous metadata hash of `{}`",
702-
item_path));
703-
}
704-
}
705-
}
706-
707540
/// Given a `#[rustc_dirty]` or `#[rustc_clean]` attribute, scan
708541
/// for a `cfg="foo"` attribute and check whether we have a cfg
709542
/// flag called `foo`.
@@ -759,7 +592,6 @@ fn expect_associated_value(tcx: TyCtxt, item: &NestedMetaItem) -> ast::Name {
759592
}
760593
}
761594

762-
763595
// A visitor that collects all #[rustc_dirty]/#[rustc_clean] attributes from
764596
// the HIR. It is used to verfiy that we really ran checks for all annotated
765597
// nodes.

src/librustc_incremental/persist/fs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ use rand::{thread_rng, Rng};
131131
const LOCK_FILE_EXT: &'static str = ".lock";
132132
const DEP_GRAPH_FILENAME: &'static str = "dep-graph.bin";
133133
const WORK_PRODUCTS_FILENAME: &'static str = "work-products.bin";
134-
const METADATA_HASHES_FILENAME: &'static str = "metadata.bin";
135134
const QUERY_CACHE_FILENAME: &'static str = "query-cache.bin";
136135

137136
// We encode integers using the following base, so they are shorter than decimal
@@ -148,10 +147,6 @@ pub fn work_products_path(sess: &Session) -> PathBuf {
148147
in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME)
149148
}
150149

151-
pub fn metadata_hash_export_path(sess: &Session) -> PathBuf {
152-
in_incr_comp_dir_sess(sess, METADATA_HASHES_FILENAME)
153-
}
154-
155150
pub fn query_cache_path(sess: &Session) -> PathBuf {
156151
in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME)
157152
}

0 commit comments

Comments
 (0)