diff options
| author | bors <bors@rust-lang.org> | 2017-09-18 17:30:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-18 17:30:29 +0000 |
| commit | 0701b37d97d08da7074ece7a7dcb4449498f4bfa (patch) | |
| tree | 796f1ce756d1bce72a8462d6d74c28f11263895c /src/librustc/middle | |
| parent | 3a7b960731fd1cf86f1879b1a0d44196a0917c53 (diff) | |
| parent | 929215db7c598722410709022e69f71702f02e0b (diff) | |
| download | rust-0701b37d97d08da7074ece7a7dcb4449498f4bfa.tar.gz rust-0701b37d97d08da7074ece7a7dcb4449498f4bfa.zip | |
Auto merge of #44678 - alexcrichton:rollup, r=alexcrichton
Rollup of 11 pull requests - Successful merges: #44364, #44466, #44537, #44548, #44640, #44651, #44657, #44661, #44668, #44671, #44675 - Failed merges:
Diffstat (limited to 'src/librustc/middle')
| -rw-r--r-- | src/librustc/middle/cstore.rs | 24 | ||||
| -rw-r--r-- | src/librustc/middle/exported_symbols.rs | 5 | ||||
| -rw-r--r-- | src/librustc/middle/lang_items.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/reachable.rs | 10 | ||||
| -rw-r--r-- | src/librustc/middle/region.rs | 32 | ||||
| -rw-r--r-- | src/librustc/middle/resolve_lifetime.rs | 50 | ||||
| -rw-r--r-- | src/librustc/middle/stability.rs | 12 | ||||
| -rw-r--r-- | src/librustc/middle/trans.rs | 79 |
8 files changed, 193 insertions, 22 deletions
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index bea6ef4dc11..de647913f0f 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -22,6 +22,7 @@ //! are *mostly* used as a part of that interface, but these should //! probably get a better home if someone can find one. +use hir; use hir::def; use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; use hir::map as hir_map; @@ -34,6 +35,7 @@ use session::search_paths::PathKind; use util::nodemap::NodeSet; use std::any::Any; +use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use std::rc::Rc; use owning_ref::ErasedBoxRef; @@ -132,7 +134,7 @@ pub struct NativeLibrary { pub kind: NativeLibraryKind, pub name: Symbol, pub cfg: Option<ast::MetaItem>, - pub foreign_items: Vec<DefIndex>, + pub foreign_items: Vec<DefId>, } pub enum LoadedMacro { @@ -218,6 +220,26 @@ pub trait MetadataLoader { -> Result<ErasedBoxRef<[u8]>, String>; } +#[derive(Clone)] +pub struct ExternConstBody<'tcx> { + pub body: &'tcx hir::Body, + + // It would require a lot of infrastructure to enable stable-hashing Bodies + // from other crates, so we hash on export and just store the fingerprint + // with them. + pub fingerprint: ich::Fingerprint, +} + +#[derive(Clone)] +pub struct ExternBodyNestedBodies { + pub nested_bodies: Rc<BTreeMap<hir::BodyId, hir::Body>>, + + // It would require a lot of infrastructure to enable stable-hashing Bodies + // from other crates, so we hash on export and just store the fingerprint + // with them. + pub fingerprint: ich::Fingerprint, +} + /// A store of Rust crates, through with their metadata /// can be accessed. /// diff --git a/src/librustc/middle/exported_symbols.rs b/src/librustc/middle/exported_symbols.rs index 230878f8545..d650dbe88b5 100644 --- a/src/librustc/middle/exported_symbols.rs +++ b/src/librustc/middle/exported_symbols.rs @@ -19,6 +19,11 @@ pub enum SymbolExportLevel { Rust, } +impl_stable_hash_for!(enum self::SymbolExportLevel { + C, + Rust +}); + impl SymbolExportLevel { pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool { if threshold == SymbolExportLevel::Rust { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 7a6f4fdbb03..0c0b9697338 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -192,8 +192,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> { pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LanguageItems { let mut collector = LanguageItemCollector::new(tcx); for &cnum in tcx.crates().iter() { - for &(index, item_index) in tcx.defined_lang_items(cnum).iter() { - let def_id = DefId { krate: cnum, index: index }; + for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() { collector.collect_item(item_index, def_id); } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 7c442450901..fa29dda86dd 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -369,7 +369,13 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, } } -fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> Rc<NodeSet> { +// We introduce a new-type here, so we can have a specialized HashStable +// implementation for it. +#[derive(Clone)] +pub struct ReachableSet(pub Rc<NodeSet>); + + +fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet { debug_assert!(crate_num == LOCAL_CRATE); let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); @@ -414,7 +420,7 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> reachable_context.propagate(); // Return the set of reachable symbols. - Rc::new(reachable_context.reachable_symbols) + ReachableSet(Rc::new(reachable_context.reachable_symbols)) } pub fn provide(providers: &mut Providers) { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index ae9866edc53..5b286c6593b 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -14,6 +14,7 @@ //! Most of the documentation on regions can be found in //! `middle/infer/region_inference/README.md` +use ich::{StableHashingContext, NodeIdHashingMode}; use util::nodemap::{FxHashMap, FxHashSet}; use ty; @@ -31,6 +32,8 @@ use hir::def_id::DefId; use hir::intravisit::{self, Visitor, NestedVisitorMap}; use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local}; use mir::transform::MirSource; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher, + StableHasherResult}; /// Scope represents a statically-describable scope that can be /// used to bound the lifetime/region for values. @@ -1235,3 +1238,32 @@ pub fn provide(providers: &mut Providers) { ..*providers }; } + +impl<'gcx> HashStable<StableHashingContext<'gcx>> for ScopeTree { + fn hash_stable<W: StableHasherResult>(&self, + hcx: &mut StableHashingContext<'gcx>, + hasher: &mut StableHasher<W>) { + let ScopeTree { + root_body, + root_parent, + ref parent_map, + ref var_map, + ref destruction_scopes, + ref rvalue_scopes, + ref closure_tree, + ref yield_in_scope, + } = *self; + + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + root_body.hash_stable(hcx, hasher); + root_parent.hash_stable(hcx, hasher); + }); + + parent_map.hash_stable(hcx, hasher); + var_map.hash_stable(hcx, hasher); + destruction_scopes.hash_stable(hcx, hasher); + rvalue_scopes.hash_stable(hcx, hasher); + closure_tree.hash_stable(hcx, hasher); + yield_in_scope.hash_stable(hcx, hasher); + } +} diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 657c30289eb..2d201e5935e 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -39,22 +39,24 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap}; #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] pub enum Region { Static, - EarlyBound(/* index */ u32, /* lifetime decl */ ast::NodeId), - LateBound(ty::DebruijnIndex, /* lifetime decl */ ast::NodeId), + EarlyBound(/* index */ u32, /* lifetime decl */ DefId), + LateBound(ty::DebruijnIndex, /* lifetime decl */ DefId), LateBoundAnon(ty::DebruijnIndex, /* anon index */ u32), - Free(DefId, /* lifetime decl */ ast::NodeId), + Free(DefId, /* lifetime decl */ DefId), } impl Region { - fn early(index: &mut u32, def: &hir::LifetimeDef) -> (ast::Name, Region) { + fn early(hir_map: &Map, index: &mut u32, def: &hir::LifetimeDef) -> (ast::Name, Region) { let i = *index; *index += 1; - (def.lifetime.name, Region::EarlyBound(i, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + (def.lifetime.name, Region::EarlyBound(i, def_id)) } - fn late(def: &hir::LifetimeDef) -> (ast::Name, Region) { + fn late(hir_map: &Map, def: &hir::LifetimeDef) -> (ast::Name, Region) { let depth = ty::DebruijnIndex::new(1); - (def.lifetime.name, Region::LateBound(depth, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + (def.lifetime.name, Region::LateBound(depth, def_id)) } fn late_anon(index: &Cell<u32>) -> Region { @@ -64,7 +66,7 @@ impl Region { Region::LateBoundAnon(depth, i) } - fn id(&self) -> Option<ast::NodeId> { + fn id(&self) -> Option<DefId> { match *self { Region::Static | Region::LateBoundAnon(..) => None, @@ -337,7 +339,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { 0 }; let lifetimes = generics.lifetimes.iter().map(|def| { - Region::early(&mut index, def) + Region::early(self.hir_map, &mut index, def) }).collect(); let scope = Scope::Binder { lifetimes, @@ -368,7 +370,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { match ty.node { hir::TyBareFn(ref c) => { let scope = Scope::Binder { - lifetimes: c.lifetimes.iter().map(Region::late).collect(), + lifetimes: c.lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; self.with(scope, |old_scope, this| { @@ -467,7 +471,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if !bound_lifetimes.is_empty() { self.trait_ref_hack = true; let scope = Scope::Binder { - lifetimes: bound_lifetimes.iter().map(Region::late).collect(), + lifetimes: bound_lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; let result = self.with(scope, |old_scope, this| { @@ -512,7 +518,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { "nested quantification of lifetimes"); } let scope = Scope::Binder { - lifetimes: trait_ref.bound_lifetimes.iter().map(Region::late).collect(), + lifetimes: trait_ref.bound_lifetimes.iter().map(|def| { + Region::late(self.hir_map, def) + }).collect(), s: self.scope }; self.with(scope, |old_scope, this| { @@ -647,10 +655,13 @@ fn extract_labels(ctxt: &mut LifetimeContext, body: &hir::Body) { Scope::Binder { ref lifetimes, s } => { // FIXME (#24278): non-hygienic comparison if let Some(def) = lifetimes.get(&label) { + let node_id = hir_map.as_local_node_id(def.id().unwrap()) + .unwrap(); + signal_shadowing_problem( sess, label, - original_lifetime(hir_map.span(def.id().unwrap())), + original_lifetime(hir_map.span(node_id)), shadower_label(label_span)); return; } @@ -749,7 +760,8 @@ fn object_lifetime_defaults_for_item(hir_map: &Map, generics: &hir::Generics) generics.lifetimes.iter().enumerate().find(|&(_, def)| { def.lifetime.name == name }).map_or(Set1::Many, |(i, def)| { - Set1::One(Region::EarlyBound(i as u32, def.lifetime.id)) + let def_id = hir_map.local_def_id(def.lifetime.id); + Set1::One(Region::EarlyBound(i as u32, def_id)) }) } } @@ -835,9 +847,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let lifetimes = generics.lifetimes.iter().map(|def| { if self.map.late_bound.contains(&def.lifetime.id) { - Region::late(def) + Region::late(self.hir_map, def) } else { - Region::early(&mut index, def) + Region::early(self.hir_map, &mut index, def) } }).collect(); @@ -1483,10 +1495,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { Scope::Binder { ref lifetimes, s } => { if let Some(&def) = lifetimes.get(&lifetime.name) { + let node_id = self.hir_map + .as_local_node_id(def.id().unwrap()) + .unwrap(); + signal_shadowing_problem( self.sess, lifetime.name, - original_lifetime(self.hir_map.span(def.id().unwrap())), + original_lifetime(self.hir_map.span(node_id)), shadower_lifetime(&lifetime)); return; } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 977102ec1ad..89049958309 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -65,6 +65,11 @@ pub struct DeprecationEntry { origin: Option<HirId>, } +impl_stable_hash_for!(struct self::DeprecationEntry { + attr, + origin +}); + impl DeprecationEntry { fn local(attr: Deprecation, id: HirId) -> DeprecationEntry { DeprecationEntry { @@ -102,6 +107,13 @@ pub struct Index<'tcx> { active_features: FxHashSet<Symbol>, } +impl_stable_hash_for!(struct self::Index<'tcx> { + stab_map, + depr_map, + staged_api, + active_features +}); + // A private tree-walker for producing an Index. struct Annotator<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, diff --git a/src/librustc/middle/trans.rs b/src/librustc/middle/trans.rs index 9a501257548..7744c9c3d12 100644 --- a/src/librustc/middle/trans.rs +++ b/src/librustc/middle/trans.rs @@ -12,6 +12,9 @@ use syntax::ast::NodeId; use syntax::symbol::InternedString; use ty::Instance; use util::nodemap::FxHashMap; +use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult, + StableHasher}; +use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode}; #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] pub enum TransItem<'tcx> { @@ -20,6 +23,26 @@ pub enum TransItem<'tcx> { GlobalAsm(NodeId), } +impl<'tcx> HashStable<StableHashingContext<'tcx>> for TransItem<'tcx> { + fn hash_stable<W: StableHasherResult>(&self, + hcx: &mut StableHashingContext<'tcx>, + hasher: &mut StableHasher<W>) { + ::std::mem::discriminant(self).hash_stable(hcx, hasher); + + match *self { + TransItem::Fn(ref instance) => { + instance.hash_stable(hcx, hasher); + } + TransItem::Static(node_id) | + TransItem::GlobalAsm(node_id) => { + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + node_id.hash_stable(hcx, hasher); + }) + } + } + } +} + pub struct CodegenUnit<'tcx> { /// A name for this CGU. Incremental compilation requires that /// name be unique amongst **all** crates. Therefore, it should @@ -44,6 +67,20 @@ pub enum Linkage { Common, } +impl_stable_hash_for!(enum self::Linkage { + External, + AvailableExternally, + LinkOnceAny, + LinkOnceODR, + WeakAny, + WeakODR, + Appending, + Internal, + Private, + ExternalWeak, + Common +}); + #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum Visibility { Default, @@ -51,6 +88,12 @@ pub enum Visibility { Protected, } +impl_stable_hash_for!(enum self::Visibility { + Default, + Hidden, + Protected +}); + impl<'tcx> CodegenUnit<'tcx> { pub fn new(name: InternedString) -> CodegenUnit<'tcx> { CodegenUnit { @@ -78,6 +121,29 @@ impl<'tcx> CodegenUnit<'tcx> { } } +impl<'tcx> HashStable<StableHashingContext<'tcx>> for CodegenUnit<'tcx> { + fn hash_stable<W: StableHasherResult>(&self, + hcx: &mut StableHashingContext<'tcx>, + hasher: &mut StableHasher<W>) { + let CodegenUnit { + ref items, + name, + } = *self; + + name.hash_stable(hcx, hasher); + + let mut items: Vec<(Fingerprint, _)> = items.iter().map(|(trans_item, &attrs)| { + let mut hasher = StableHasher::new(); + trans_item.hash_stable(hcx, &mut hasher); + let trans_item_fingerprint = hasher.finish(); + (trans_item_fingerprint, attrs) + }).collect(); + + items.sort_unstable_by_key(|i| i.0); + items.hash_stable(hcx, hasher); + } +} + #[derive(Clone, Default)] pub struct Stats { pub n_glues_created: usize, @@ -92,6 +158,18 @@ pub struct Stats { pub fn_stats: Vec<(String, usize)>, } +impl_stable_hash_for!(struct self::Stats { + n_glues_created, + n_null_glues, + n_real_glues, + n_fns, + n_inlines, + n_closures, + n_llvm_insns, + llvm_insns, + fn_stats +}); + impl Stats { pub fn extend(&mut self, stats: Stats) { self.n_glues_created += stats.n_glues_created; @@ -108,3 +186,4 @@ impl Stats { self.fn_stats.extend(stats.fn_stats); } } + |
