diff --git a/src/Cargo.lock b/src/Cargo.lock index 2a7dbce2ddc91..1ef6b2a571e9c 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -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", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 457a9f2f625ec..088b9436d0fc9 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -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. diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 0150ba659c900..3934475bea90c 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -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; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index b05bcadf82649..81897322b6f6b 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 0003790e6d552..521499e476689 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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 diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 05361b6564170..329cc2216a498 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -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 { +fn compute_ignored_attr_names() -> FxHashSet { 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 = compute_ignored_attr_names(); + } + IGNORED_ATTRIBUTES.with(|attrs| attrs.contains(&name)) } pub fn hash_hir_item_like(&mut self, f: F) { diff --git a/src/librustc/ich/mod.rs b/src/librustc/ich/mod.rs index d58eb64c366e7..b00d8c565694a 100644 --- a/src/librustc/ich/mod.rs +++ b/src/librustc/ich/mod.rs @@ -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; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 804481846afdc..55a5e342947fb 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -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 diff --git a/src/librustc/macros.rs b/src/librustc/macros.rs index 0bf1f4decc430..e599b0704f957 100644 --- a/src/librustc/macros.rs +++ b/src/librustc/macros.rs @@ -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)*)) }) } diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 0e84104245dcb..b91a9644b211a 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -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; diff --git a/src/librustc/session/code_stats.rs b/src/librustc/session/code_stats.rs index 1eee6508c59cc..32865acb298fa 100644 --- a/src/librustc/session/code_stats.rs +++ b/src/librustc/session/code_stats.rs @@ -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 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, diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index dddf921aec68c..ef1052d562e55 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -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> 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>); -impl_stable_hash_for!(tuple_struct self::OutputTypes { - map -}); +impl_stable_hash_via_hash!(OutputTypes); impl OutputTypes { pub fn new(entries: &[(OutputType, Option)]) -> 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"; diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index b636fc6c9950a..32044fdf2a8cb 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -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), } }) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 9a3ce50fcbdce..f474f21430544 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -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>, - /// A cache of attributes ignored by StableHashingContext - pub ignored_attr_names: FxHashSet, - /// Used by -Z profile-queries in util::common pub profile_channel: Lock>>, @@ -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 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:: inside the bug!() macro definition - opt_span_bug_fmt(file, line, None::, args); -} - -#[cold] -#[inline(never)] -pub fn span_bug_fmt>( - file: &'static str, - line: u32, - span: S, - args: fmt::Arguments, -) -> ! { - opt_span_bug_fmt(file, line, Some(span), args); -} - -fn opt_span_bug_fmt>( - file: &'static str, - line: u32, - span: Option, - 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!(); -} diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 4fda3bdca3dfc..0c962fff272fb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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> for AdtDef { #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub enum AdtKind { Struct, Union, Enum } +impl Into 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 { diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 35080123d3e10..ef22ebef9d7d4 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -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; diff --git a/src/librustc/util/bug.rs b/src/librustc/util/bug.rs new file mode 100644 index 0000000000000..f2593e4d4b5ee --- /dev/null +++ b/src/librustc/util/bug.rs @@ -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 or the MIT license +// , 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:: inside the bug!() macro definition + opt_span_bug_fmt(file, line, None::, args); +} + +#[cold] +#[inline(never)] +pub fn span_bug_fmt>( + file: &'static str, + line: u32, + span: S, + args: fmt::Arguments, +) -> ! { + opt_span_bug_fmt(file, line, Some(span), args); +} + +fn opt_span_bug_fmt>( + file: &'static str, + line: u32, + span: Option, + 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!(); +} diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 990fbc4bc917e..1ec025f78c9ac 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -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 MemoizationMap for RefCell> } } -#[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)); diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs index 50d41d76986fb..bbe1ccf3696f4 100644 --- a/src/librustc_codegen_llvm/back/link.rs +++ b/src/librustc_codegen_llvm/back/link.rs @@ -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}; diff --git a/src/librustc_codegen_llvm/back/symbol_export.rs b/src/librustc_codegen_llvm/back/symbol_export.rs index 02434b7be0bda..c78d061a39bad 100644 --- a/src/librustc_codegen_llvm/back/symbol_export.rs +++ b/src/librustc_codegen_llvm/back/symbol_export.rs @@ -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}; diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 640e1c1f3d4f1..cdfa874b1772a 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -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; diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 69ef92ed98e52..8ee2404e10cdf 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -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; diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 9599ccfe97964..4572f5891a420 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -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; diff --git a/src/librustc_codegen_llvm/metadata.rs b/src/librustc_codegen_llvm/metadata.rs index fcb704413ef11..a4526a53769ba 100644 --- a/src/librustc_codegen_llvm/metadata.rs +++ b/src/librustc_codegen_llvm/metadata.rs @@ -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 { 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) diff --git a/src/librustc_codegen_utils/link.rs b/src/librustc_codegen_utils/link.rs index 73cffdf7d491d..a0d88ccae0f13 100644 --- a/src/librustc_codegen_utils/link.rs +++ b/src/librustc_codegen_utils/link.rs @@ -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; diff --git a/src/librustc/ich/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs similarity index 89% rename from src/librustc/ich/fingerprint.rs rename to src/librustc_data_structures/fingerprint.rs index a6e35d78dcb5a..aa9ddda2b9364 100644 --- a/src/librustc/ich/fingerprint.rs +++ b/src/librustc_data_structures/fingerprint.rs @@ -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 stable_hasher::HashStable for Fingerprint { - #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut stable_hasher::StableHasher) { - ::std::hash::Hash::hash(self, hasher); - } -} +impl_stable_hash_via_hash!(Fingerprint); impl serialize::UseSpecializedEncodable for Fingerprint { } diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index dd90cf7ae19e4..3aa15f472a274 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -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(pub F); diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index a8f689e5c81a3..9f1c7dac1194e 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -183,13 +183,16 @@ pub trait ToStableHashKey { // 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 HashStable for $t { + impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable( + &self, + _: &mut CTX, + hasher: &mut $crate::stable_hasher::StableHasher + ) { ::std::hash::Hash::hash(self, hasher); } } diff --git a/src/librustc/hir/svh.rs b/src/librustc_data_structures/svh.rs similarity index 85% rename from src/librustc/hir/svh.rs rename to src/librustc_data_structures/svh.rs index a6cfcb710edad..94f132562b5ea 100644 --- a/src/librustc/hir/svh.rs +++ b/src/librustc_data_structures/svh.rs @@ -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 stable_hasher::HashStable for Svh { + #[inline] + fn hash_stable( + &self, + ctx: &mut T, + hasher: &mut stable_hasher::StableHasher + ) { + let Svh { + hash + } = *self; + hash.hash_stable(ctx, hasher); + } +} diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 805a5ecd99130..b6e03b66510e5 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -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}; diff --git a/src/librustc_fs_util/Cargo.toml b/src/librustc_fs_util/Cargo.toml new file mode 100644 index 0000000000000..e40b44204b349 --- /dev/null +++ b/src/librustc_fs_util/Cargo.toml @@ -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] diff --git a/src/librustc/util/fs.rs b/src/librustc_fs_util/lib.rs similarity index 86% rename from src/librustc/util/fs.rs rename to src/librustc_fs_util/lib.rs index 090753b18c0ba..ffe420b109d3e 100644 --- a/src/librustc/util/fs.rs +++ b/src/librustc_fs_util/lib.rs @@ -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, Q: AsRef>(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() +} diff --git a/src/librustc_incremental/Cargo.toml b/src/librustc_incremental/Cargo.toml index dd05679589e7e..c3f6062e799d9 100644 --- a/src/librustc_incremental/Cargo.toml +++ b/src/librustc_incremental/Cargo.toml @@ -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" } diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index 73886e5e2816c..c17af24b4d5bb 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -23,6 +23,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; diff --git a/src/librustc_incremental/persist/fs.rs b/src/librustc_incremental/persist/fs.rs index 795825f180c9d..28d53dc7fb3c4 100644 --- a/src/librustc_incremental/persist/fs.rs +++ b/src/librustc_incremental/persist/fs.rs @@ -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(()) diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs index c0ccbd67a3160..cfe59b1f67262 100644 --- a/src/librustc_incremental/persist/work_product.rs +++ b/src/librustc_incremental/persist/work_product.rs @@ -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; diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 62c06aac1df0e..d3b70933e2cd4 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -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; diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 060dddd534388..4926da3b880e7 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -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 } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 5121b682d36a7..33d4cf26c0395 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -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; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 96d6c5b75f49e..7c445cb715e7c 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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}; diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index f68bcdd62c695..52777e5f6b90d 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -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}; diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index 894c7cbf683dc..781652e1985d6 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -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, }