Rollup merge of #40678 - michaelwoerister:dmi-prep, r=nikomatsakis

Some preparations for directly computing the ICH of crate-metadata.

This PR contains some small fixes in preparation for direct metadata hashing. It mostly just moves stuff into places where it will be needed (making the module structure slightly cleaner along the way) and it fixes some omissions in the MIR region eraser.

r? @nikomatsakis
This commit is contained in:
Corey Farwell 2017-03-22 23:38:02 -04:00 committed by GitHub
commit 39e4a27204
19 changed files with 87 additions and 60 deletions

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::ty::TyCtxt;
use ty::TyCtxt;
use std::rc::Rc;
use syntax::codemap::CodeMap;
use syntax_pos::{BytePos, FileMap};

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::hir::def_id::DefId;
use rustc::ty::TyCtxt;
use rustc::util::nodemap::DefIdMap;
use hir::def_id::DefId;
use ty::TyCtxt;
use util::nodemap::DefIdMap;
pub struct DefPathHashes<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,

34
src/librustc/ich/mod.rs Normal file
View File

@ -0,0 +1,34 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::fingerprint::Fingerprint;
pub use self::def_path_hash::DefPathHashes;
pub use self::caching_codemap_view::CachingCodemapView;
mod fingerprint;
mod def_path_hash;
mod caching_codemap_view;
pub const ATTR_DIRTY: &'static str = "rustc_dirty";
pub const ATTR_CLEAN: &'static str = "rustc_clean";
pub const ATTR_DIRTY_METADATA: &'static str = "rustc_metadata_dirty";
pub const ATTR_CLEAN_METADATA: &'static str = "rustc_metadata_clean";
pub const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
pub const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
pub 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
];

View File

@ -72,6 +72,7 @@ pub mod diagnostics;
pub mod cfg;
pub mod dep_graph;
pub mod hir;
pub mod ich;
pub mod infer;
pub mod lint;

View File

@ -509,18 +509,21 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
}
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
self.hash_discriminant_u8(r);
match *r {
ty::ReErased => {
self.hash::<u32>(0);
ty::ReErased |
ty::ReStatic |
ty::ReEmpty => {
// No variant fields to hash for these ...
}
ty::ReLateBound(db, ty::BrAnon(i)) => {
assert!(db.depth > 0);
self.hash::<u32>(db.depth);
self.hash(db.depth);
self.hash(i);
}
ty::ReStatic |
ty::ReEmpty |
ty::ReEarlyBound(..) |
ty::ReEarlyBound(ty::EarlyBoundRegion { index, name }) => {
self.hash(index);
self.hash(name.as_str());
}
ty::ReLateBound(..) |
ty::ReFree(..) |
ty::ReScope(..) |

View File

@ -10,6 +10,7 @@
use rustc::hir::{self, map as hir_map};
use rustc::hir::lowering::lower_crate;
use rustc::ich::Fingerprint;
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_mir as mir;
use rustc::session::{Session, CompileResult, compile_result_from_err_count};
@ -25,7 +26,6 @@ use rustc::util::nodemap::NodeSet;
use rustc::util::fs::rename_or_copy_remove;
use rustc_borrowck as borrowck;
use rustc_incremental::{self, IncrementalHashesMap};
use rustc_incremental::ich::Fingerprint;
use rustc_resolve::{MakeGlobMap, Resolver};
use rustc_metadata::creader::CrateLoader;
use rustc_metadata::cstore::{self, CStore};

View File

@ -52,13 +52,13 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::{Direction, INCOMING, OUTGOING, NodeIndex};
use rustc::hir;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
use graphviz::IntoCow;
use std::env;
use std::fs::File;
use std::io::Write;
use syntax::ast;
use syntax_pos::Span;
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();

View File

@ -35,20 +35,16 @@ use rustc::hir;
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::hir::intravisit as visit;
use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
use rustc::ich::{Fingerprint, DefPathHashes, CachingCodemapView};
use rustc::ty::TyCtxt;
use rustc_data_structures::stable_hasher::StableHasher;
use ich::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc::util::common::record_time;
use rustc::session::config::DebugInfoLevel::NoDebugInfo;
use self::def_path_hash::DefPathHashes;
use self::svh_visitor::StrictVersionHashVisitor;
use self::caching_codemap_view::CachingCodemapView;
mod def_path_hash;
mod svh_visitor;
mod caching_codemap_view;
pub type IchHasher = StableHasher<Fingerprint>;

View File

@ -26,23 +26,12 @@ use rustc::hir::*;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use rustc::hir::intravisit::{self as visit, Visitor};
use rustc::ich::{DefPathHashes, CachingCodemapView, IGNORED_ATTRIBUTES};
use rustc::ty::TyCtxt;
use std::hash::{Hash, Hasher};
use super::def_path_hash::DefPathHashes;
use super::caching_codemap_view::CachingCodemapView;
use super::IchHasher;
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>,
pub st: &'a mut IchHasher,

View File

@ -1,13 +0,0 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::fingerprint::Fingerprint;
mod fingerprint;

View File

@ -36,17 +36,9 @@ extern crate serialize as rustc_serialize;
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;
pub mod ich;
pub use assert_dep_graph::assert_dep_graph;
pub use calculate_svh::compute_incremental_hashes_map;

View File

@ -12,9 +12,9 @@
use rustc::dep_graph::{DepNode, WorkProduct, WorkProductId};
use rustc::hir::def_id::DefIndex;
use rustc::ich::Fingerprint;
use std::sync::Arc;
use rustc_data_structures::fx::FxHashMap;
use ich::Fingerprint;
use super::directory::DefPathIndex;

View File

@ -47,13 +47,12 @@ use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::intravisit;
use rustc::ich::{Fingerprint, ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA,
ATTR_CLEAN_METADATA};
use syntax::ast::{self, Attribute, NestedMetaItem};
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use syntax_pos::Span;
use rustc::ty::TyCtxt;
use ich::Fingerprint;
use {ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA, ATTR_CLEAN_METADATA};
const LABEL: &'static str = "label";
const CFG: &'static str = "cfg";

View File

@ -11,6 +11,7 @@
use rustc::dep_graph::DepNode;
use rustc::hir::def_id::{CrateNum, DefId};
use rustc::hir::svh::Svh;
use rustc::ich::Fingerprint;
use rustc::ty::TyCtxt;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::flock;
@ -18,7 +19,6 @@ use rustc_serialize::Decodable;
use rustc_serialize::opaque::Decoder;
use IncrementalHashesMap;
use ich::Fingerprint;
use super::data::*;
use super::fs::*;
use super::file_format;

View File

@ -13,6 +13,7 @@
use rustc::dep_graph::{DepNode, WorkProductId};
use rustc::hir::def_id::DefId;
use rustc::hir::svh::Svh;
use rustc::ich::Fingerprint;
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
@ -22,7 +23,6 @@ use std::path::{Path};
use std::sync::Arc;
use IncrementalHashesMap;
use ich::Fingerprint;
use super::data::*;
use super::directory::*;
use super::dirty_clean;

View File

@ -10,11 +10,11 @@
use rustc::dep_graph::{DepGraphQuery, DepNode};
use rustc::hir::def_id::DefId;
use rustc::ich::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::{Graph, NodeIndex};
use super::hash::*;
use ich::Fingerprint;
mod compress;

View File

@ -11,6 +11,7 @@
use rustc::dep_graph::DepNode;
use rustc::hir::def_id::DefId;
use rustc::hir::svh::Svh;
use rustc::ich::Fingerprint;
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_data_structures::fx::FxHashMap;
@ -23,7 +24,6 @@ use std::fs::{self, File};
use std::path::PathBuf;
use IncrementalHashesMap;
use ich::Fingerprint;
use super::data::*;
use super::directory::*;
use super::hash::*;

View File

@ -13,7 +13,7 @@
//! care erasing regions all over the place.
use rustc::ty::subst::Substs;
use rustc::ty::{Ty, TyCtxt};
use rustc::ty::{Ty, TyCtxt, ReErased, ClosureSubsts};
use rustc::mir::*;
use rustc::mir::visit::MutVisitor;
use rustc::mir::transform::{MirPass, MirSource, Pass};
@ -39,6 +39,32 @@ impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
*substs = self.tcx.erase_regions(&{*substs});
}
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
match *rvalue {
Rvalue::Ref(ref mut r, _, _) => {
*r = self.tcx.mk_region(ReErased);
}
Rvalue::Use(..) |
Rvalue::Repeat(..) |
Rvalue::Len(..) |
Rvalue::Cast(..) |
Rvalue::BinaryOp(..) |
Rvalue::CheckedBinaryOp(..) |
Rvalue::UnaryOp(..) |
Rvalue::Discriminant(..) |
Rvalue::Box(..) |
Rvalue::Aggregate(..) => {
// These variants don't contain regions.
}
}
self.super_rvalue(rvalue, location);
}
fn visit_closure_substs(&mut self,
substs: &mut ClosureSubsts<'tcx>) {
*substs = self.tcx.erase_regions(substs);
}
}
pub struct EraseRegions;