Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
34 changes: 34 additions & 0 deletions src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
@@ -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
];
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 10 additions & 7 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_incremental/calculate_svh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down
13 changes: 1 addition & 12 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions src/librustc_incremental/ich/mod.rs

This file was deleted.

8 changes: 0 additions & 8 deletions src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
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;
use rustc_serialize::Decodable;
use rustc_serialize::opaque::Decoder;

use IncrementalHashesMap;
use ich::Fingerprint;
use super::data::*;
use super::fs::*;
use super::file_format;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/preds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::*;
Expand Down
28 changes: 27 additions & 1 deletion src/librustc_mir/transform/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down