Auto merge of #53073 - Mark-Simulacrum:data-structures, r=pnkfelix
Cleanup to librustc::session and related code No functional changes, just some cleanup. This also creates the `rustc_fs_util` crate, but I can remove that change if desired. It felt a little odd to force crates to depend on librustc for some fs utilities; and also seemed good to generally keep the size of librustc lower (for compile times); fs_util will compile in parallel with essentially the first crate since it has no dependencies beyond std.
This commit is contained in:
commit
db1acaac7f
@ -1887,6 +1887,7 @@ dependencies = [
|
||||
"rustc_apfloat 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"rustc_errors 0.0.0",
|
||||
"rustc_fs_util 0.0.0",
|
||||
"rustc_target 0.0.0",
|
||||
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serialize 0.0.0",
|
||||
@ -2185,6 +2186,10 @@ dependencies = [
|
||||
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_fs_util"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_incremental"
|
||||
version = "0.0.0"
|
||||
@ -2194,6 +2199,7 @@ dependencies = [
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"rustc_fs_util 0.0.0",
|
||||
"serialize 0.0.0",
|
||||
"syntax 0.0.0",
|
||||
"syntax_pos 0.0.0",
|
||||
|
@ -32,6 +32,7 @@ backtrace = "0.3.3"
|
||||
parking_lot = "0.5.5"
|
||||
byteorder = { version = "1.1", features = ["i128"]}
|
||||
chalk-engine = { version = "0.6.0", default-features=false }
|
||||
rustc_fs_util = { path = "../librustc_fs_util" }
|
||||
|
||||
# Note that these dependencies are a lie, they're just here to get linkage to
|
||||
# work.
|
||||
|
@ -12,7 +12,7 @@ use super::*;
|
||||
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
|
||||
use hir::def_id::{LOCAL_CRATE, CrateNum};
|
||||
use hir::intravisit::{Visitor, NestedVisitorMap};
|
||||
use hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use ich::Fingerprint;
|
||||
use middle::cstore::CrateStore;
|
||||
use session::CrateDisambiguator;
|
||||
|
@ -22,6 +22,7 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
|
||||
use middle::cstore::CrateStore;
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::ext::base::MacroKind;
|
||||
@ -29,7 +30,6 @@ use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
use hir::*;
|
||||
use hir::print::Nested;
|
||||
use hir::svh::Svh;
|
||||
use util::nodemap::FxHashMap;
|
||||
|
||||
use std::io;
|
||||
|
@ -70,7 +70,6 @@ pub mod lowering;
|
||||
pub mod map;
|
||||
pub mod pat_util;
|
||||
pub mod print;
|
||||
pub mod svh;
|
||||
|
||||
/// A HirId uniquely identifies a node in the HIR of the current crate. It is
|
||||
/// composed of the `owner`, which is the DefIndex of the directly enclosing
|
||||
|
@ -37,7 +37,7 @@ use rustc_data_structures::stable_hasher::{HashStable,
|
||||
use rustc_data_structures::accumulate_vec::AccumulateVec;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
||||
|
||||
pub fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
|
||||
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
|
||||
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
|
||||
ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect()
|
||||
}
|
||||
@ -183,7 +183,10 @@ impl<'a> StableHashingContext<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_ignored_attr(&self, name: Symbol) -> bool {
|
||||
self.sess.ignored_attr_names.contains(&name)
|
||||
thread_local! {
|
||||
static IGNORED_ATTRIBUTES: FxHashSet<Symbol> = compute_ignored_attr_names();
|
||||
}
|
||||
IGNORED_ATTRIBUTES.with(|attrs| attrs.contains(&name))
|
||||
}
|
||||
|
||||
pub fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {
|
||||
|
@ -10,11 +10,10 @@
|
||||
|
||||
//! ICH - Incremental Compilation Hash
|
||||
|
||||
pub use self::fingerprint::Fingerprint;
|
||||
crate use rustc_data_structures::fingerprint::Fingerprint;
|
||||
pub use self::caching_codemap_view::CachingCodemapView;
|
||||
pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
|
||||
hash_stable_trait_impls, compute_ignored_attr_names};
|
||||
mod fingerprint;
|
||||
hash_stable_trait_impls};
|
||||
mod caching_codemap_view;
|
||||
mod hcx;
|
||||
|
||||
|
@ -72,6 +72,7 @@
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(macro_at_most_once_rep)]
|
||||
#![feature(crate_in_paths)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
|
||||
#![recursion_limit="512"]
|
||||
|
||||
@ -99,6 +100,7 @@ extern crate syntax_pos;
|
||||
extern crate jobserver;
|
||||
extern crate proc_macro;
|
||||
extern crate chalk_engine;
|
||||
extern crate rustc_fs_util;
|
||||
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
|
||||
@ -162,9 +164,9 @@ pub mod util {
|
||||
pub mod common;
|
||||
pub mod ppaux;
|
||||
pub mod nodemap;
|
||||
pub mod fs;
|
||||
pub mod time_graph;
|
||||
pub mod profiling;
|
||||
pub mod bug;
|
||||
}
|
||||
|
||||
// A private module so that macro-expanded idents like
|
||||
|
@ -51,14 +51,14 @@ macro_rules! enum_from_u32 {
|
||||
macro_rules! bug {
|
||||
() => ( bug!("impossible case reached") );
|
||||
($($message:tt)*) => ({
|
||||
$crate::session::bug_fmt(file!(), line!(), format_args!($($message)*))
|
||||
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
|
||||
})
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! span_bug {
|
||||
($span:expr, $($message:tt)*) => ({
|
||||
$crate::session::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
|
||||
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use hir::map as hir_map;
|
||||
use hir::map::definitions::{DefKey, DefPathTable};
|
||||
use hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use ty::{self, TyCtxt};
|
||||
use session::{Session, CrateDisambiguator};
|
||||
use session::search_paths::PathKind;
|
||||
|
@ -8,11 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use ty::AdtKind;
|
||||
use ty::layout::{Align, Size};
|
||||
|
||||
use rustc_target::abi::{Align, Size};
|
||||
use rustc_data_structures::fx::{FxHashSet};
|
||||
|
||||
use std::cmp::{self, Ordering};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
@ -38,16 +35,6 @@ pub struct FieldInfo {
|
||||
pub align: u64,
|
||||
}
|
||||
|
||||
impl From<AdtKind> for DataTypeKind {
|
||||
fn from(kind: AdtKind) -> Self {
|
||||
match kind {
|
||||
AdtKind::Struct => DataTypeKind::Struct,
|
||||
AdtKind::Enum => DataTypeKind::Enum,
|
||||
AdtKind::Union => DataTypeKind::Union,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum DataTypeKind {
|
||||
Struct,
|
||||
|
@ -16,10 +16,8 @@ use std::str::FromStr;
|
||||
use session::{early_error, early_warn, Session};
|
||||
use session::search_paths::SearchPaths;
|
||||
|
||||
use ich::StableHashingContext;
|
||||
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
|
||||
use rustc_target::spec::{Target, TargetTriple};
|
||||
use rustc_data_structures::stable_hasher::ToStableHashKey;
|
||||
use lint;
|
||||
use middle::cstore;
|
||||
|
||||
@ -126,25 +124,7 @@ pub enum OutputType {
|
||||
DepInfo,
|
||||
}
|
||||
|
||||
|
||||
impl_stable_hash_for!(enum self::OutputType {
|
||||
Bitcode,
|
||||
Assembly,
|
||||
LlvmAssembly,
|
||||
Mir,
|
||||
Metadata,
|
||||
Object,
|
||||
Exe,
|
||||
DepInfo
|
||||
});
|
||||
|
||||
impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for OutputType {
|
||||
type KeyType = OutputType;
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self::KeyType {
|
||||
*self
|
||||
}
|
||||
}
|
||||
impl_stable_hash_via_hash!(OutputType);
|
||||
|
||||
impl OutputType {
|
||||
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
||||
@ -233,9 +213,7 @@ impl Default for ErrorOutputType {
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>);
|
||||
|
||||
impl_stable_hash_for!(tuple_struct self::OutputTypes {
|
||||
map
|
||||
});
|
||||
impl_stable_hash_via_hash!(OutputTypes);
|
||||
|
||||
impl OutputTypes {
|
||||
pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes {
|
||||
@ -512,7 +490,7 @@ impl Input {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Hash)]
|
||||
pub struct OutputFilenames {
|
||||
pub out_directory: PathBuf,
|
||||
pub out_filestem: String,
|
||||
@ -521,13 +499,7 @@ pub struct OutputFilenames {
|
||||
pub outputs: OutputTypes,
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct self::OutputFilenames {
|
||||
out_directory,
|
||||
out_filestem,
|
||||
single_output_file,
|
||||
extra,
|
||||
outputs
|
||||
});
|
||||
impl_stable_hash_via_hash!(OutputFilenames);
|
||||
|
||||
pub const RUST_CGU_EXT: &str = "rcgu";
|
||||
|
||||
|
@ -19,7 +19,7 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use session::search_paths::{SearchPaths, PathKind};
|
||||
use util::fs as rustcfs;
|
||||
use rustc_fs_util::fix_windows_verbatim_for_gcc;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum FileMatch {
|
||||
@ -151,7 +151,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
||||
// See comments on this target function, but the gist is that
|
||||
// gcc chokes on verbatim paths which fs::canonicalize generates
|
||||
// so we try to avoid those kinds of paths.
|
||||
Ok(canon) => Some(rustcfs::fix_windows_verbatim_for_gcc(&canon)),
|
||||
Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
|
||||
Err(e) => bug!("failed to get realpath: {}", e),
|
||||
}
|
||||
})
|
||||
|
@ -12,16 +12,14 @@ pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
|
||||
use self::code_stats::CodeStats;
|
||||
|
||||
use hir::def_id::CrateNum;
|
||||
use ich::Fingerprint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
||||
use ich;
|
||||
use lint;
|
||||
use lint::builtin::BuiltinLintDiagnostics;
|
||||
use middle::allocator::AllocatorKind;
|
||||
use middle::dependency_format;
|
||||
use session::search_paths::PathKind;
|
||||
use session::config::{OutputType, Lto};
|
||||
use ty::tls;
|
||||
use util::nodemap::{FxHashMap, FxHashSet};
|
||||
use util::common::{duration_to_secs_str, ErrorReported};
|
||||
use util::common::ProfileQueriesMsg;
|
||||
@ -34,7 +32,6 @@ use errors::emitter::{Emitter, EmitterWriter};
|
||||
use syntax::edition::Edition;
|
||||
use syntax::json::JsonEmitter;
|
||||
use syntax::feature_gate;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::parse;
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax::{ast, codemap};
|
||||
@ -51,7 +48,6 @@ use std;
|
||||
use std::cell::{self, Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fmt;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
@ -128,9 +124,6 @@ pub struct Session {
|
||||
|
||||
incr_comp_session: OneThread<RefCell<IncrCompSession>>,
|
||||
|
||||
/// A cache of attributes ignored by StableHashingContext
|
||||
pub ignored_attr_names: FxHashSet<Symbol>,
|
||||
|
||||
/// Used by -Z profile-queries in util::common
|
||||
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,
|
||||
|
||||
@ -1143,7 +1136,6 @@ pub fn build_session_(
|
||||
injected_panic_runtime: Once::new(),
|
||||
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
|
||||
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
|
||||
ignored_attr_names: ich::compute_ignored_attr_names(),
|
||||
self_profiling: Lock::new(SelfProfiler::new()),
|
||||
profile_channel: Lock::new(None),
|
||||
perf_stats: PerfStats {
|
||||
@ -1235,7 +1227,7 @@ impl From<Fingerprint> for CrateDisambiguator {
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(tuple_struct CrateDisambiguator { fingerprint });
|
||||
impl_stable_hash_via_hash!(CrateDisambiguator);
|
||||
|
||||
/// Holds data on the current incremental compilation session, if there is one.
|
||||
#[derive(Debug)]
|
||||
@ -1307,39 +1299,3 @@ pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
|
||||
Err(CompileIncomplete::Errored(ErrorReported))
|
||||
}
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
|
||||
// this wrapper mostly exists so I don't have to write a fully
|
||||
// qualified path of None::<Span> inside the bug!() macro definition
|
||||
opt_span_bug_fmt(file, line, None::<Span>, args);
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn span_bug_fmt<S: Into<MultiSpan>>(
|
||||
file: &'static str,
|
||||
line: u32,
|
||||
span: S,
|
||||
args: fmt::Arguments,
|
||||
) -> ! {
|
||||
opt_span_bug_fmt(file, line, Some(span), args);
|
||||
}
|
||||
|
||||
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
|
||||
file: &'static str,
|
||||
line: u32,
|
||||
span: Option<S>,
|
||||
args: fmt::Arguments,
|
||||
) -> ! {
|
||||
tls::with_opt(move |tcx| {
|
||||
let msg = format!("{}:{}: {}", file, line, args);
|
||||
match (tcx, span) {
|
||||
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
|
||||
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
|
||||
(None, _) => panic!(msg),
|
||||
}
|
||||
});
|
||||
unreachable!();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ use hir::{map as hir_map, FreevarMap, TraitMap};
|
||||
use hir::def::{Def, CtorKind, ExportMap};
|
||||
use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use hir::map::DefPathData;
|
||||
use hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use ich::Fingerprint;
|
||||
use ich::StableHashingContext;
|
||||
use infer::canonical::Canonical;
|
||||
@ -37,6 +37,7 @@ use ty::walk::TypeWalker;
|
||||
use util::captures::Captures;
|
||||
use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
|
||||
use arena::SyncDroplessArena;
|
||||
use session::DataTypeKind;
|
||||
|
||||
use serialize::{self, Encodable, Encoder};
|
||||
use std::cell::RefCell;
|
||||
@ -1810,6 +1811,16 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDef {
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum AdtKind { Struct, Union, Enum }
|
||||
|
||||
impl Into<DataTypeKind> for AdtKind {
|
||||
fn into(self) -> DataTypeKind {
|
||||
match self {
|
||||
AdtKind::Struct => DataTypeKind::Struct,
|
||||
AdtKind::Union => DataTypeKind::Union,
|
||||
AdtKind::Enum => DataTypeKind::Enum,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(RustcEncodable, RustcDecodable, Default)]
|
||||
pub struct ReprFlags: u8 {
|
||||
|
@ -13,7 +13,7 @@ use errors::DiagnosticBuilder;
|
||||
use hir::def_id::{CrateNum, DefId, DefIndex};
|
||||
use hir::def::{Def, Export};
|
||||
use hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
|
||||
use hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use infer::canonical::{self, Canonical};
|
||||
use lint;
|
||||
use middle::borrowck::BorrowCheckResult;
|
||||
|
51
src/librustc/util/bug.rs
Normal file
51
src/librustc/util/bug.rs
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
// These functions are used by macro expansion for bug! and span_bug!
|
||||
|
||||
use ty::tls;
|
||||
use std::fmt;
|
||||
use syntax_pos::{Span, MultiSpan};
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
|
||||
// this wrapper mostly exists so I don't have to write a fully
|
||||
// qualified path of None::<Span> inside the bug!() macro definition
|
||||
opt_span_bug_fmt(file, line, None::<Span>, args);
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn span_bug_fmt<S: Into<MultiSpan>>(
|
||||
file: &'static str,
|
||||
line: u32,
|
||||
span: S,
|
||||
args: fmt::Arguments,
|
||||
) -> ! {
|
||||
opt_span_bug_fmt(file, line, Some(span), args);
|
||||
}
|
||||
|
||||
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
|
||||
file: &'static str,
|
||||
line: u32,
|
||||
span: Option<S>,
|
||||
args: fmt::Arguments,
|
||||
) -> ! {
|
||||
tls::with_opt(move |tcx| {
|
||||
let msg = format!("{}:{}: {}", file, line, args);
|
||||
match (tcx, span) {
|
||||
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
|
||||
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
|
||||
(None, _) => panic!(msg),
|
||||
}
|
||||
});
|
||||
unreachable!();
|
||||
}
|
@ -14,12 +14,10 @@ use rustc_data_structures::sync::Lock;
|
||||
|
||||
use std::cell::{RefCell, Cell};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::{Hash, BuildHasher};
|
||||
use std::panic;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use std::sync::mpsc::{Sender};
|
||||
@ -376,19 +374,6 @@ impl<K, V, S> MemoizationMap for RefCell<HashMap<K,V,S>>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
use std::os::unix::prelude::*;
|
||||
use std::ffi::OsStr;
|
||||
let p: &OsStr = p.as_ref();
|
||||
CString::new(p.as_bytes()).unwrap()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
CString::new(p.to_str().unwrap()).unwrap()
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_to_readable_str() {
|
||||
assert_eq!("0", to_readable_str(0));
|
||||
|
@ -26,7 +26,7 @@ use rustc::middle::cstore::{NativeLibrary, LibSource, NativeLibraryKind};
|
||||
use rustc::middle::dependency_format::Linkage;
|
||||
use {CodegenResults, CrateInfo};
|
||||
use rustc::util::common::time;
|
||||
use rustc::util::fs::fix_windows_verbatim_for_gcc;
|
||||
use rustc_fs_util::fix_windows_verbatim_for_gcc;
|
||||
use rustc::hir::def_id::CrateNum;
|
||||
use tempfile::{Builder as TempFileBuilder, TempDir};
|
||||
use rustc_target::spec::{PanicStrategy, RelroLevel, LinkerFlavor};
|
||||
|
@ -15,7 +15,7 @@ use monomorphize::Instance;
|
||||
use rustc::hir;
|
||||
use rustc::hir::CodegenFnAttrFlags;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
|
||||
use rustc::ich::Fingerprint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadata_symbol_name};
|
||||
use rustc::session::config;
|
||||
use rustc::ty::{TyCtxt, SymbolName};
|
||||
|
@ -30,8 +30,7 @@ use CrateInfo;
|
||||
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passes_entry};
|
||||
use rustc::util::common::path2cstr;
|
||||
use rustc::util::fs::{link_or_copy};
|
||||
use rustc_fs_util::{path2cstr, link_or_copy};
|
||||
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
|
||||
use errors::emitter::{Emitter};
|
||||
use syntax::attr;
|
||||
|
@ -28,14 +28,15 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc::hir::CodegenFnAttrFlags;
|
||||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
|
||||
use rustc::ich::{Fingerprint, NodeIdHashingMode};
|
||||
use rustc::ich::NodeIdHashingMode;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc::ty::Instance;
|
||||
use common::CodegenCx;
|
||||
use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
|
||||
use rustc::ty::layout::{self, Align, LayoutOf, PrimitiveExt, Size, TyLayout};
|
||||
use rustc::session::config;
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc::util::common::path2cstr;
|
||||
use rustc_fs_util::path2cstr;
|
||||
|
||||
use libc::{c_uint, c_longlong};
|
||||
use std::ffi::CString;
|
||||
|
@ -55,6 +55,7 @@ extern crate rustc_incremental;
|
||||
extern crate rustc_llvm;
|
||||
extern crate rustc_platform_intrinsics as intrinsics;
|
||||
extern crate rustc_codegen_utils;
|
||||
extern crate rustc_fs_util;
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
@ -8,7 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::util::common;
|
||||
use rustc::middle::cstore::MetadataLoader;
|
||||
use rustc_target::spec::Target;
|
||||
use llvm;
|
||||
@ -19,6 +18,7 @@ use rustc_data_structures::owning_ref::OwningRef;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use rustc_fs_util::path2cstr;
|
||||
|
||||
pub use rustc_data_structures::sync::MetadataRef;
|
||||
|
||||
@ -57,7 +57,7 @@ impl MetadataLoader for LlvmMetadataLoader {
|
||||
filename: &Path)
|
||||
-> Result<MetadataRef, String> {
|
||||
unsafe {
|
||||
let buf = common::path2cstr(filename);
|
||||
let buf = path2cstr(filename);
|
||||
let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr())
|
||||
.ok_or_else(|| format!("error reading library: '{}'", filename.display()))?;
|
||||
let of = ObjectFile::new(mb)
|
||||
|
@ -11,7 +11,7 @@
|
||||
use rustc::session::config::{self, OutputFilenames, Input, OutputType};
|
||||
use rustc::session::Session;
|
||||
use rustc::middle::cstore::LinkMeta;
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use std::path::{Path, PathBuf};
|
||||
use syntax::{ast, attr};
|
||||
use syntax_pos::Span;
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use std::mem;
|
||||
use rustc_data_structures::stable_hasher;
|
||||
use stable_hasher;
|
||||
use serialize;
|
||||
use serialize::opaque::{EncodeResult, Encoder, Decoder};
|
||||
|
||||
@ -92,14 +92,7 @@ impl stable_hasher::StableHasherResult for Fingerprint {
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> stable_hasher::HashStable<CTX> for Fingerprint {
|
||||
#[inline]
|
||||
fn hash_stable<W: stable_hasher::StableHasherResult>(&self,
|
||||
_: &mut CTX,
|
||||
hasher: &mut stable_hasher::StableHasher<W>) {
|
||||
::std::hash::Hash::hash(self, hasher);
|
||||
}
|
||||
}
|
||||
impl_stable_hash_via_hash!(Fingerprint);
|
||||
|
||||
impl serialize::UseSpecializedEncodable for Fingerprint { }
|
||||
|
@ -46,6 +46,7 @@ extern crate stable_deref_trait;
|
||||
extern crate rustc_rayon as rayon;
|
||||
extern crate rustc_rayon_core as rayon_core;
|
||||
extern crate rustc_hash;
|
||||
extern crate serialize;
|
||||
|
||||
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
|
||||
#[allow(unused_extern_crates)]
|
||||
@ -53,6 +54,7 @@ extern crate rustc_cratesio_shim;
|
||||
|
||||
pub use rustc_serialize::hex::ToHex;
|
||||
|
||||
pub mod svh;
|
||||
pub mod accumulate_vec;
|
||||
pub mod array_vec;
|
||||
pub mod base_n;
|
||||
@ -71,13 +73,14 @@ pub mod small_vec;
|
||||
pub mod snapshot_map;
|
||||
pub use ena::snapshot_vec;
|
||||
pub mod sorted_map;
|
||||
pub mod stable_hasher;
|
||||
#[macro_use] pub mod stable_hasher;
|
||||
pub mod sync;
|
||||
pub mod tiny_list;
|
||||
pub mod transitive_relation;
|
||||
pub mod tuple_slice;
|
||||
pub use ena::unify;
|
||||
pub mod work_queue;
|
||||
pub mod fingerprint;
|
||||
|
||||
pub struct OnDrop<F: Fn()>(pub F);
|
||||
|
||||
|
@ -183,13 +183,16 @@ pub trait ToStableHashKey<HCX> {
|
||||
|
||||
// Implement HashStable by just calling `Hash::hash()`. This works fine for
|
||||
// self-contained values that don't depend on the hashing context `CTX`.
|
||||
#[macro_export]
|
||||
macro_rules! impl_stable_hash_via_hash {
|
||||
($t:ty) => (
|
||||
impl<CTX> HashStable<CTX> for $t {
|
||||
impl<CTX> $crate::stable_hasher::HashStable<CTX> for $t {
|
||||
#[inline]
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
_: &mut CTX,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
fn hash_stable<W: $crate::stable_hasher::StableHasherResult>(
|
||||
&self,
|
||||
_: &mut CTX,
|
||||
hasher: &mut $crate::stable_hasher::StableHasher<W>
|
||||
) {
|
||||
::std::hash::Hash::hash(self, hasher);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
|
||||
use stable_hasher;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Svh {
|
||||
hash: u64,
|
||||
@ -67,6 +69,16 @@ impl Decodable for Svh {
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct Svh {
|
||||
hash
|
||||
});
|
||||
impl<T> stable_hasher::HashStable<T> for Svh {
|
||||
#[inline]
|
||||
fn hash_stable<W: stable_hasher::StableHasherResult>(
|
||||
&self,
|
||||
ctx: &mut T,
|
||||
hasher: &mut stable_hasher::StableHasher<W>
|
||||
) {
|
||||
let Svh {
|
||||
hash
|
||||
} = *self;
|
||||
hash.hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::hir::{self, map as hir_map};
|
||||
use rustc::hir::lowering::lower_crate;
|
||||
use rustc::ich::Fingerprint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::stable_hasher::StableHasher;
|
||||
use rustc_mir as mir;
|
||||
use rustc::session::{CompileResult, CrateDisambiguator, Session};
|
||||
|
11
src/librustc_fs_util/Cargo.toml
Normal file
11
src/librustc_fs_util/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
authors = ["The Rust Project Developers"]
|
||||
name = "rustc_fs_util"
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
name = "rustc_fs_util"
|
||||
path = "lib.rs"
|
||||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::path::{self, Path, PathBuf};
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::ffi::CString;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
|
||||
@ -29,10 +29,10 @@ use std::io;
|
||||
//
|
||||
// For some more information, see this comment:
|
||||
// https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
|
||||
#[cfg(windows)]
|
||||
pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
|
||||
if !cfg!(windows) {
|
||||
return p.to_path_buf();
|
||||
}
|
||||
use std::path;
|
||||
use std::ffi::OsString;
|
||||
let mut components = p.components();
|
||||
let prefix = match components.next() {
|
||||
Some(path::Component::Prefix(p)) => p,
|
||||
@ -56,6 +56,11 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
|
||||
p.to_path_buf()
|
||||
}
|
||||
|
||||
pub enum LinkOrCopy {
|
||||
Link,
|
||||
Copy,
|
||||
@ -109,3 +114,15 @@ pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
use std::os::unix::prelude::*;
|
||||
use std::ffi::OsStr;
|
||||
let p: &OsStr = p.as_ref();
|
||||
CString::new(p.as_bytes()).unwrap()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
CString::new(p.to_str().unwrap()).unwrap()
|
||||
}
|
@ -17,3 +17,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
serialize = { path = "../libserialize" }
|
||||
syntax = { path = "../libsyntax" }
|
||||
syntax_pos = { path = "../libsyntax_pos" }
|
||||
rustc_fs_util = { path = "../librustc_fs_util" }
|
||||
|
@ -24,6 +24,7 @@ extern crate graphviz;
|
||||
extern crate rustc_data_structures;
|
||||
extern crate serialize as rustc_serialize;
|
||||
extern crate rand;
|
||||
extern crate rustc_fs_util;
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
extern crate syntax;
|
||||
|
@ -114,11 +114,11 @@
|
||||
//! unsupported file system and emit a warning in that case. This is not yet
|
||||
//! implemented.
|
||||
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc::session::{Session, CrateDisambiguator};
|
||||
use rustc::util::fs as fs_util;
|
||||
use rustc_fs_util::{link_or_copy, LinkOrCopy};
|
||||
use rustc_data_structures::{flock, base_n};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
|
||||
use std::fs as std_fs;
|
||||
use std::io;
|
||||
@ -429,11 +429,11 @@ fn copy_files(sess: &Session,
|
||||
let source_path = entry.path();
|
||||
|
||||
debug!("copying into session dir: {}", source_path.display());
|
||||
match fs_util::link_or_copy(source_path, target_file_path) {
|
||||
Ok(fs_util::LinkOrCopy::Link) => {
|
||||
match link_or_copy(source_path, target_file_path) {
|
||||
Ok(LinkOrCopy::Link) => {
|
||||
files_linked += 1
|
||||
}
|
||||
Ok(fs_util::LinkOrCopy::Copy) => {
|
||||
Ok(LinkOrCopy::Copy) => {
|
||||
files_copied += 1
|
||||
}
|
||||
Err(_) => return Err(())
|
||||
|
@ -13,7 +13,7 @@
|
||||
use persist::fs::*;
|
||||
use rustc::dep_graph::{WorkProduct, WorkProductId, WorkProductFileKind};
|
||||
use rustc::session::Session;
|
||||
use rustc::util::fs::link_or_copy;
|
||||
use rustc_fs_util::link_or_copy;
|
||||
use std::path::PathBuf;
|
||||
use std::fs as std_fs;
|
||||
|
||||
|
@ -16,7 +16,7 @@ use schema::CrateRoot;
|
||||
use rustc_data_structures::sync::{Lrc, RwLock, Lock};
|
||||
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc::middle::allocator::AllocatorKind;
|
||||
use rustc::middle::cstore::DepKind;
|
||||
use rustc::mir::interpret::AllocDecodingState;
|
||||
|
@ -30,6 +30,7 @@ use rustc::hir::map::{DefKey, DefPath, DefPathHash};
|
||||
use rustc::hir::map::blocks::FnLikeNode;
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::util::nodemap::DefIdMap;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
|
||||
use std::any::Any;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
@ -515,7 +516,7 @@ impl CrateStore for cstore::CStore {
|
||||
self.get_crate_data(cnum).root.disambiguator
|
||||
}
|
||||
|
||||
fn crate_hash_untracked(&self, cnum: CrateNum) -> hir::svh::Svh
|
||||
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh
|
||||
{
|
||||
self.get_crate_data(cnum).root.hash
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc::hir::def::{self, Def, CtorKind};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, DefIndex,
|
||||
CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId};
|
||||
use rustc::ich::Fingerprint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::mir::{self, interpret};
|
||||
use rustc::mir::interpret::AllocDecodingSession;
|
||||
|
@ -18,7 +18,7 @@ use rustc::middle::cstore::{LinkMeta, LinkagePreference, NativeLibrary,
|
||||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::ich::Fingerprint;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc::middle::dependency_format::Linkage;
|
||||
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel,
|
||||
metadata_symbol_name};
|
||||
|
@ -226,7 +226,7 @@ use cstore::{MetadataRef, MetadataBlob};
|
||||
use creader::Library;
|
||||
use schema::{METADATA_HEADER, rustc_version};
|
||||
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc::middle::cstore::MetadataLoader;
|
||||
use rustc::session::{config, Session};
|
||||
use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
|
||||
|
@ -20,6 +20,7 @@ use rustc::mir;
|
||||
use rustc::session::CrateDisambiguator;
|
||||
use rustc::ty::{self, Ty, ReprOptions};
|
||||
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
|
||||
use rustc_serialize as serialize;
|
||||
use syntax::{ast, attr};
|
||||
@ -187,7 +188,7 @@ pub struct CrateRoot {
|
||||
pub name: Symbol,
|
||||
pub triple: TargetTriple,
|
||||
pub extra_filename: String,
|
||||
pub hash: hir::svh::Svh,
|
||||
pub hash: Svh,
|
||||
pub disambiguator: CrateDisambiguator,
|
||||
pub panic_strategy: PanicStrategy,
|
||||
pub edition: Edition,
|
||||
@ -223,7 +224,7 @@ pub struct CrateRoot {
|
||||
#[derive(RustcEncodable, RustcDecodable)]
|
||||
pub struct CrateDep {
|
||||
pub name: ast::Name,
|
||||
pub hash: hir::svh::Svh,
|
||||
pub hash: Svh,
|
||||
pub kind: DepKind,
|
||||
pub extra_filename: String,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user