Skip to content

Cleanup to librustc::session and related code #53073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ 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;
use syntax_pos::{Span, DUMMY_SP};

use hir::*;
use hir::print::Nested;
use hir::svh::Svh;
use util::nodemap::FxHashMap;

use std::io;
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*))
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 1 addition & 14 deletions src/librustc/session/code_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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,
Expand Down
36 changes: 4 additions & 32 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -512,7 +490,7 @@ impl Input {
}
}

#[derive(Clone)]
#[derive(Clone, Hash)]
pub struct OutputFilenames {
pub out_directory: PathBuf,
pub out_filestem: String,
Expand All @@ -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";

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
})
Expand Down
48 changes: 2 additions & 46 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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>>>,

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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!();
}
Loading