Skip to content

Commit

Permalink
incr.comp.: Fix rebase fallout.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Sep 18, 2017
1 parent d5b1fee commit 74d6b85
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hir::map::definitions::Definitions;
use ich::{self, CachingCodemapView};
use middle::cstore::CrateStore;
use session::config::DebugInfoLevel::NoDebugInfo;
use ty::{self, TyCtxt, fast_reject};
use ty::{TyCtxt, fast_reject};
use session::Session;

use std::cmp::Ord;
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'gcx> StableHashingContext<'gcx> {
}
}

impl<'a, 'gcx, 'lcx> StableHashingContextProvider for ty::TyCtxt<'a, 'gcx, 'lcx> {
impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
type ContextType = StableHashingContext<'gcx>;
fn create_stable_hashing_context(&self) -> Self::ContextType {
(*self).create_stable_hashing_context()
Expand Down
12 changes: 4 additions & 8 deletions src/librustc/infer/error_reporting/different_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {

(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
debug!("EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
def_id={:?}",
self.infcx.tcx.hir.local_def_id(id),
def_id);
if self.infcx.tcx.hir.local_def_id(id) == def_id {
def_id={:?}", id, def_id);
if id == def_id {
self.found_it = true;
return; // we can stop visiting now
}
Expand All @@ -344,11 +342,9 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
(Some(rl::Region::LateBound(debruijn_index, id)), ty::BrNamed(def_id, _)) => {
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
debruijn_index.depth);
debug!("self.infcx.tcx.hir.local_def_id(id)={:?}",
self.infcx.tcx.hir.local_def_id(id));
debug!("id={:?}", id);
debug!("def_id={:?}", def_id);
if debruijn_index.depth == self.depth &&
self.infcx.tcx.hir.local_def_id(id) == def_id {
if debruijn_index.depth == self.depth && id == def_id {
self.found_it = true;
return; // we can stop visiting now
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
79 changes: 79 additions & 0 deletions src/librustc/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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
Expand All @@ -44,13 +67,33 @@ 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,
Hidden,
Protected,
}

impl_stable_hash_for!(enum self::Visibility {
Default,
Hidden,
Protected
});

impl<'tcx> CodegenUnit<'tcx> {
pub fn new(name: InternedString) -> CodegenUnit<'tcx> {
CodegenUnit {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -108,3 +186,4 @@ impl Stats {
self.fn_stats.extend(stats.fn_stats);
}
}

33 changes: 33 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ pub use self::DebugInfoLevel::*;
use session::{early_error, early_warn, Session};
use session::search_paths::SearchPaths;

use ich::StableHashingContext;
use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
use rustc_back::target::Target;
use rustc_data_structures::stable_hasher::ToStableHashKey;
use lint;
use middle::cstore;

Expand Down Expand Up @@ -90,6 +92,25 @@ pub enum OutputType {
DepInfo,
}

impl_stable_hash_for!(enum self::OutputType {
Bitcode,
Assembly,
LlvmAssembly,
Mir,
Metadata,
Object,
Exe,
DepInfo
});

impl<'tcx> ToStableHashKey<StableHashingContext<'tcx>> for OutputType {
type KeyType = OutputType;
#[inline]
fn to_stable_hash_key(&self, _: &StableHashingContext<'tcx>) -> Self::KeyType {
*self
}
}

impl OutputType {
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
match *self {
Expand Down Expand Up @@ -149,6 +170,10 @@ impl Default for ErrorOutputType {
#[derive(Clone, Hash)]
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);

impl_stable_hash_for!(tuple_struct self::OutputTypes {
map
});

impl OutputTypes {
pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
OutputTypes(BTreeMap::from_iter(entries.iter()
Expand Down Expand Up @@ -373,6 +398,14 @@ pub struct OutputFilenames {
pub outputs: OutputTypes,
}

impl_stable_hash_for!(struct self::OutputFilenames {
out_directory,
out_filestem,
single_output_file,
extra,
outputs
});

/// Codegen unit names generated by the numbered naming scheme will contain this
/// marker right before the index of the codegen unit.
pub const NUMBERED_CODEGEN_UNIT_MARKER: &'static str = ".cgu-";
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_data_structures/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ impl<CTX> HashStable<CTX> for String {
}
}

impl<HCX> ToStableHashKey<HCX> for String {
type KeyType = String;
#[inline]
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
self.clone()
}
}

impl<CTX> HashStable<CTX> for bool {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
Expand Down
25 changes: 6 additions & 19 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use rustc::middle::trans::{Linkage, Visibility, Stats};
use rustc::middle::cstore::{EncodedMetadata, EncodedMetadataHashes};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::dep_graph::AssertDepGraphSafe;
use rustc::middle::cstore::{self, LinkMeta, LinkagePreference};
use rustc::hir::map as hir_map;
use rustc::util::common::{time, print_time_passes_entry};
Expand Down Expand Up @@ -894,7 +893,7 @@ fn iter_globals(llmod: llvm::ModuleRef) -> ValueIter {
/// This list is later used by linkers to determine the set of symbols needed to
/// be exposed from a dynamic library and it's also encoded into the metadata.
pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
tcx.reachable_set(LOCAL_CRATE).iter().cloned().filter(|&id| {
tcx.reachable_set(LOCAL_CRATE).0.iter().cloned().filter(|&id| {
// Next, we want to ignore some FFI functions that are not exposed from
// this crate. Reachable FFI functions can be lumped into two
// categories:
Expand Down Expand Up @@ -1370,8 +1369,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let dep_node = cgu.work_product_dep_node();
let ((stats, module), _) =
tcx.dep_graph.with_task(dep_node,
AssertDepGraphSafe(tcx),
AssertDepGraphSafe(cgu),
tcx,
cgu,
module_translation);
let time_to_translate = start_time.elapsed();

Expand All @@ -1392,14 +1391,10 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return stats;

fn module_translation<'a, 'tcx>(
tcx: AssertDepGraphSafe<TyCtxt<'a, 'tcx, 'tcx>>,
args: AssertDepGraphSafe<Arc<CodegenUnit<'tcx>>>)
tcx: TyCtxt<'a, 'tcx, 'tcx>,
cgu: Arc<CodegenUnit<'tcx>>)
-> (Stats, ModuleTranslation)
{
// FIXME(#40304): We ought to be using the id as a key and some queries, I think.
let AssertDepGraphSafe(tcx) = tcx;
let AssertDepGraphSafe(cgu) = args;

let cgu_name = cgu.name().to_string();
let cgu_id = cgu.work_product_id();
let symbol_name_hash = cgu.compute_symbol_name_hash(tcx);
Expand Down Expand Up @@ -1564,6 +1559,7 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
Visibility::Default => llvm::Visibility::Default,
Visibility::Hidden => llvm::Visibility::Hidden,
Visibility::Protected => llvm::Visibility::Protected,
}
}

// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
Expand All @@ -1577,17 +1573,8 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
mod temp_stable_hash_impls {
use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
HashStable};
use context::Stats;
use ModuleTranslation;

impl<HCX> HashStable<HCX> for Stats {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut HCX,
_: &mut StableHasher<W>) {
// do nothing
}
}

impl<HCX> HashStable<HCX> for ModuleTranslation {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut HCX,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ use type_::Type;
use rustc_data_structures::base_n;
use rustc::middle::trans::Stats;
use rustc_data_structures::stable_hasher::StableHashingContextProvider;
use rustc::session::config::{self, NoDebugInfo, OutputFilenames};
use rustc::session::Session;
use rustc::session::config::{self, NoDebugInfo};
use rustc::session::Session;
use rustc::ty::layout::{LayoutCx, LayoutError, LayoutTyper, TyLayout};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::util::nodemap::FxHashMap;
Expand Down

0 comments on commit 74d6b85

Please sign in to comment.