Skip to content

Commit 39e4a27

Browse files
authored
Rollup merge of rust-lang#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
2 parents a419ce9 + 45deab4 commit 39e4a27

File tree

19 files changed

+87
-60
lines changed

19 files changed

+87
-60
lines changed

src/librustc_incremental/calculate_svh/caching_codemap_view.rs src/librustc/ich/caching_codemap_view.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::ty::TyCtxt;
11+
use ty::TyCtxt;
1212
use std::rc::Rc;
1313
use syntax::codemap::CodeMap;
1414
use syntax_pos::{BytePos, FileMap};

src/librustc_incremental/calculate_svh/def_path_hash.rs src/librustc/ich/def_path_hash.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::hir::def_id::DefId;
12-
use rustc::ty::TyCtxt;
13-
use rustc::util::nodemap::DefIdMap;
11+
use hir::def_id::DefId;
12+
use ty::TyCtxt;
13+
use util::nodemap::DefIdMap;
1414

1515
pub struct DefPathHashes<'a, 'tcx: 'a> {
1616
tcx: TyCtxt<'a, 'tcx, 'tcx>,
File renamed without changes.

src/librustc/ich/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub use self::fingerprint::Fingerprint;
12+
pub use self::def_path_hash::DefPathHashes;
13+
pub use self::caching_codemap_view::CachingCodemapView;
14+
15+
mod fingerprint;
16+
mod def_path_hash;
17+
mod caching_codemap_view;
18+
19+
pub const ATTR_DIRTY: &'static str = "rustc_dirty";
20+
pub const ATTR_CLEAN: &'static str = "rustc_clean";
21+
pub const ATTR_DIRTY_METADATA: &'static str = "rustc_metadata_dirty";
22+
pub const ATTR_CLEAN_METADATA: &'static str = "rustc_metadata_clean";
23+
pub const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
24+
pub const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
25+
26+
pub const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
27+
"cfg",
28+
ATTR_IF_THIS_CHANGED,
29+
ATTR_THEN_THIS_WOULD_NEED,
30+
ATTR_DIRTY,
31+
ATTR_CLEAN,
32+
ATTR_DIRTY_METADATA,
33+
ATTR_CLEAN_METADATA
34+
];

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub mod diagnostics;
7272
pub mod cfg;
7373
pub mod dep_graph;
7474
pub mod hir;
75+
pub mod ich;
7576
pub mod infer;
7677
pub mod lint;
7778

src/librustc/ty/util.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,21 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
509509
}
510510

511511
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
512+
self.hash_discriminant_u8(r);
512513
match *r {
513-
ty::ReErased => {
514-
self.hash::<u32>(0);
514+
ty::ReErased |
515+
ty::ReStatic |
516+
ty::ReEmpty => {
517+
// No variant fields to hash for these ...
515518
}
516519
ty::ReLateBound(db, ty::BrAnon(i)) => {
517-
assert!(db.depth > 0);
518-
self.hash::<u32>(db.depth);
520+
self.hash(db.depth);
519521
self.hash(i);
520522
}
521-
ty::ReStatic |
522-
ty::ReEmpty |
523-
ty::ReEarlyBound(..) |
523+
ty::ReEarlyBound(ty::EarlyBoundRegion { index, name }) => {
524+
self.hash(index);
525+
self.hash(name.as_str());
526+
}
524527
ty::ReLateBound(..) |
525528
ty::ReFree(..) |
526529
ty::ReScope(..) |

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use rustc::hir::{self, map as hir_map};
1212
use rustc::hir::lowering::lower_crate;
13+
use rustc::ich::Fingerprint;
1314
use rustc_data_structures::stable_hasher::StableHasher;
1415
use rustc_mir as mir;
1516
use rustc::session::{Session, CompileResult, compile_result_from_err_count};
@@ -25,7 +26,6 @@ use rustc::util::nodemap::NodeSet;
2526
use rustc::util::fs::rename_or_copy_remove;
2627
use rustc_borrowck as borrowck;
2728
use rustc_incremental::{self, IncrementalHashesMap};
28-
use rustc_incremental::ich::Fingerprint;
2929
use rustc_resolve::{MakeGlobMap, Resolver};
3030
use rustc_metadata::creader::CrateLoader;
3131
use rustc_metadata::cstore::{self, CStore};

src/librustc_incremental/assert_dep_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ use rustc_data_structures::fx::FxHashSet;
5252
use rustc_data_structures::graph::{Direction, INCOMING, OUTGOING, NodeIndex};
5353
use rustc::hir;
5454
use rustc::hir::itemlikevisit::ItemLikeVisitor;
55+
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
5556
use graphviz::IntoCow;
5657
use std::env;
5758
use std::fs::File;
5859
use std::io::Write;
5960
use syntax::ast;
6061
use syntax_pos::Span;
61-
use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
6262

6363
pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6464
let _ignore = tcx.dep_graph.in_ignore();

src/librustc_incremental/calculate_svh/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,16 @@ use rustc::hir;
3535
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
3636
use rustc::hir::intravisit as visit;
3737
use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
38+
use rustc::ich::{Fingerprint, DefPathHashes, CachingCodemapView};
3839
use rustc::ty::TyCtxt;
3940
use rustc_data_structures::stable_hasher::StableHasher;
40-
use ich::Fingerprint;
4141
use rustc_data_structures::fx::FxHashMap;
4242
use rustc::util::common::record_time;
4343
use rustc::session::config::DebugInfoLevel::NoDebugInfo;
4444

45-
use self::def_path_hash::DefPathHashes;
4645
use self::svh_visitor::StrictVersionHashVisitor;
47-
use self::caching_codemap_view::CachingCodemapView;
4846

49-
mod def_path_hash;
5047
mod svh_visitor;
51-
mod caching_codemap_view;
5248

5349
pub type IchHasher = StableHasher<Fingerprint>;
5450

src/librustc_incremental/calculate_svh/svh_visitor.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,12 @@ use rustc::hir::*;
2626
use rustc::hir::def::Def;
2727
use rustc::hir::def_id::DefId;
2828
use rustc::hir::intravisit::{self as visit, Visitor};
29+
use rustc::ich::{DefPathHashes, CachingCodemapView, IGNORED_ATTRIBUTES};
2930
use rustc::ty::TyCtxt;
3031
use std::hash::{Hash, Hasher};
3132

32-
use super::def_path_hash::DefPathHashes;
33-
use super::caching_codemap_view::CachingCodemapView;
3433
use super::IchHasher;
3534

36-
const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
37-
"cfg",
38-
::ATTR_IF_THIS_CHANGED,
39-
::ATTR_THEN_THIS_WOULD_NEED,
40-
::ATTR_DIRTY,
41-
::ATTR_CLEAN,
42-
::ATTR_DIRTY_METADATA,
43-
::ATTR_CLEAN_METADATA
44-
];
45-
4635
pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> {
4736
pub tcx: TyCtxt<'hash, 'tcx, 'tcx>,
4837
pub st: &'a mut IchHasher,

src/librustc_incremental/ich/mod.rs

-13
This file was deleted.

src/librustc_incremental/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,9 @@ extern crate serialize as rustc_serialize;
3636
extern crate syntax;
3737
extern crate syntax_pos;
3838

39-
const ATTR_DIRTY: &'static str = "rustc_dirty";
40-
const ATTR_CLEAN: &'static str = "rustc_clean";
41-
const ATTR_DIRTY_METADATA: &'static str = "rustc_metadata_dirty";
42-
const ATTR_CLEAN_METADATA: &'static str = "rustc_metadata_clean";
43-
const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
44-
const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
45-
4639
mod assert_dep_graph;
4740
mod calculate_svh;
4841
mod persist;
49-
pub mod ich;
5042

5143
pub use assert_dep_graph::assert_dep_graph;
5244
pub use calculate_svh::compute_incremental_hashes_map;

src/librustc_incremental/persist/data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
1313
use rustc::dep_graph::{DepNode, WorkProduct, WorkProductId};
1414
use rustc::hir::def_id::DefIndex;
15+
use rustc::ich::Fingerprint;
1516
use std::sync::Arc;
1617
use rustc_data_structures::fx::FxHashMap;
17-
use ich::Fingerprint;
1818

1919
use super::directory::DefPathIndex;
2020

src/librustc_incremental/persist/dirty_clean.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ use rustc::hir;
4747
use rustc::hir::def_id::DefId;
4848
use rustc::hir::itemlikevisit::ItemLikeVisitor;
4949
use rustc::hir::intravisit;
50+
use rustc::ich::{Fingerprint, ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA,
51+
ATTR_CLEAN_METADATA};
5052
use syntax::ast::{self, Attribute, NestedMetaItem};
5153
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
5254
use syntax_pos::Span;
5355
use rustc::ty::TyCtxt;
54-
use ich::Fingerprint;
55-
56-
use {ATTR_DIRTY, ATTR_CLEAN, ATTR_DIRTY_METADATA, ATTR_CLEAN_METADATA};
5756

5857
const LABEL: &'static str = "label";
5958
const CFG: &'static str = "cfg";

src/librustc_incremental/persist/hash.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
use rustc::dep_graph::DepNode;
1212
use rustc::hir::def_id::{CrateNum, DefId};
1313
use rustc::hir::svh::Svh;
14+
use rustc::ich::Fingerprint;
1415
use rustc::ty::TyCtxt;
1516
use rustc_data_structures::fx::FxHashMap;
1617
use rustc_data_structures::flock;
1718
use rustc_serialize::Decodable;
1819
use rustc_serialize::opaque::Decoder;
1920

2021
use IncrementalHashesMap;
21-
use ich::Fingerprint;
2222
use super::data::*;
2323
use super::fs::*;
2424
use super::file_format;

src/librustc_incremental/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use rustc::dep_graph::{DepNode, WorkProductId};
1414
use rustc::hir::def_id::DefId;
1515
use rustc::hir::svh::Svh;
16+
use rustc::ich::Fingerprint;
1617
use rustc::session::Session;
1718
use rustc::ty::TyCtxt;
1819
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
@@ -22,7 +23,6 @@ use std::path::{Path};
2223
use std::sync::Arc;
2324

2425
use IncrementalHashesMap;
25-
use ich::Fingerprint;
2626
use super::data::*;
2727
use super::directory::*;
2828
use super::dirty_clean;

src/librustc_incremental/persist/preds/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
use rustc::dep_graph::{DepGraphQuery, DepNode};
1212
use rustc::hir::def_id::DefId;
13+
use rustc::ich::Fingerprint;
1314
use rustc_data_structures::fx::FxHashMap;
1415
use rustc_data_structures::graph::{Graph, NodeIndex};
1516

1617
use super::hash::*;
17-
use ich::Fingerprint;
1818

1919
mod compress;
2020

src/librustc_incremental/persist/save.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use rustc::dep_graph::DepNode;
1212
use rustc::hir::def_id::DefId;
1313
use rustc::hir::svh::Svh;
14+
use rustc::ich::Fingerprint;
1415
use rustc::session::Session;
1516
use rustc::ty::TyCtxt;
1617
use rustc_data_structures::fx::FxHashMap;
@@ -23,7 +24,6 @@ use std::fs::{self, File};
2324
use std::path::PathBuf;
2425

2526
use IncrementalHashesMap;
26-
use ich::Fingerprint;
2727
use super::data::*;
2828
use super::directory::*;
2929
use super::hash::*;

src/librustc_mir/transform/erase_regions.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! care erasing regions all over the place.
1414
1515
use rustc::ty::subst::Substs;
16-
use rustc::ty::{Ty, TyCtxt};
16+
use rustc::ty::{Ty, TyCtxt, ReErased, ClosureSubsts};
1717
use rustc::mir::*;
1818
use rustc::mir::visit::MutVisitor;
1919
use rustc::mir::transform::{MirPass, MirSource, Pass};
@@ -39,6 +39,32 @@ impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
3939
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
4040
*substs = self.tcx.erase_regions(&{*substs});
4141
}
42+
43+
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
44+
match *rvalue {
45+
Rvalue::Ref(ref mut r, _, _) => {
46+
*r = self.tcx.mk_region(ReErased);
47+
}
48+
Rvalue::Use(..) |
49+
Rvalue::Repeat(..) |
50+
Rvalue::Len(..) |
51+
Rvalue::Cast(..) |
52+
Rvalue::BinaryOp(..) |
53+
Rvalue::CheckedBinaryOp(..) |
54+
Rvalue::UnaryOp(..) |
55+
Rvalue::Discriminant(..) |
56+
Rvalue::Box(..) |
57+
Rvalue::Aggregate(..) => {
58+
// These variants don't contain regions.
59+
}
60+
}
61+
self.super_rvalue(rvalue, location);
62+
}
63+
64+
fn visit_closure_substs(&mut self,
65+
substs: &mut ClosureSubsts<'tcx>) {
66+
*substs = self.tcx.erase_regions(substs);
67+
}
4268
}
4369

4470
pub struct EraseRegions;

0 commit comments

Comments
 (0)