Skip to content

Commit

Permalink
Move Session to librustc_session
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Dec 3, 2019
1 parent 52d4d47 commit cc2c33a
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 65 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock
Expand Up @@ -3893,9 +3893,13 @@ name = "rustc_session"
version = "0.0.0"
dependencies = [
"log",
"num_cpus",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fs_util",
"rustc_index",
"rustc_target",
"serialize",
"syntax_pos",
]
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/lib.rs
Expand Up @@ -64,7 +64,6 @@
#![recursion_limit="512"]

#[macro_use] extern crate bitflags;
extern crate getopts;
#[macro_use] extern crate scoped_tls;
#[cfg(windows)]
extern crate libc;
Expand All @@ -74,10 +73,6 @@ extern crate libc;
#[macro_use] extern crate syntax;
#[macro_use] extern crate smallvec;

// Use the test crate here so we depend on getopts through it. This allow tools to link to both
// librustc_driver and libtest.
extern crate test as _;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -113,7 +108,7 @@ pub mod middle {
}

pub mod mir;
pub mod session;
pub use rustc_session as session;
pub mod traits;
pub mod ty;

Expand Down
4 changes: 4 additions & 0 deletions src/librustc_session/Cargo.toml
Expand Up @@ -11,7 +11,11 @@ path = "lib.rs"
[dependencies]
log = "0.4"
rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" }
rustc_target = { path = "../librustc_target" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_data_structures = { path = "../librustc_data_structures" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_index = { path = "../librustc_index" }
rustc_fs_util = { path = "../librustc_fs_util" }
num_cpus = "1.0"
File renamed without changes.
39 changes: 21 additions & 18 deletions src/librustc/session/config.rs → src/librustc_session/config.rs
@@ -1,26 +1,27 @@
//! Contains infrastructure for configuring the compiler, including parsing
//! command-line options.

use rustc_session::lint;
use rustc_session::utils::NativeLibraryKind;
use crate::session::{early_error, early_warn, Session};
use crate::session::search_paths::SearchPath;
use crate::lint;
use crate::utils::NativeLibraryKind;
use crate::{early_error, early_warn, Session};
use crate::search_paths::SearchPath;

use rustc_data_structures::fx::FxHashSet;
use rustc_feature::UnstableFeatures;
use rustc_data_structures::impl_stable_hash_via_hash;

use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
use rustc_target::spec::{Target, TargetTriple};

// Duplicated from syntax::ast for now
type CrateConfig = FxHashSet<(Symbol, Option<Symbol>)>;

use syntax::source_map::{FileName, FilePathMapping};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax::symbol::{sym, Symbol};
use syntax_pos::source_map::{FileName, FilePathMapping};
use syntax_pos::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax_pos::symbol::{sym, Symbol};
use rustc_feature::UnstableFeatures;

use errors::emitter::HumanReadableErrorType;
use errors::{ColorConfig, FatalError, Handler};
use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, FatalError, Handler};

use getopts;

Expand Down Expand Up @@ -349,7 +350,7 @@ macro_rules! hash_option {
($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [TRACKED]) => ({
if $sub_hashes.insert(stringify!($opt_name),
$opt_expr as &dyn dep_tracking::DepTrackingHash).is_some() {
bug!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
}
});
}
Expand Down Expand Up @@ -702,7 +703,7 @@ pub enum EntryFnType {

impl_stable_hash_via_hash!(EntryFnType);

#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, HashStable)]
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)]
pub enum CrateType {
Executable,
Dylib,
Expand All @@ -712,6 +713,8 @@ pub enum CrateType {
ProcMacro,
}

impl_stable_hash_via_hash!(CrateType);

#[derive(Clone, Hash)]
pub enum Passes {
Some(Vec<String>),
Expand Down Expand Up @@ -782,7 +785,7 @@ macro_rules! options {
value, $outputname,
key, type_desc))
}
(None, None) => bug!()
(None, None) => panic!()
}
}
found = true;
Expand Down Expand Up @@ -2720,7 +2723,7 @@ pub mod nightly_options {
use getopts;
use rustc_feature::UnstableFeatures;
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
use crate::session::early_error;
use crate::early_error;

pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
is_nightly_build()
Expand Down Expand Up @@ -2858,18 +2861,18 @@ impl PpMode {
/// we have an opt-in scheme here, so one is hopefully forced to think about
/// how the hash should be calculated when adding a new command-line argument.
mod dep_tracking {
use rustc_session::lint;
use rustc_session::utils::NativeLibraryKind;
use crate::lint;
use crate::utils::NativeLibraryKind;
use std::collections::BTreeMap;
use std::hash::Hash;
use std::path::PathBuf;
use std::collections::hash_map::DefaultHasher;
use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
SymbolManglingVersion};
use rustc_feature::UnstableFeatures;
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
use syntax::edition::Edition;
use syntax_pos::edition::Edition;
use rustc_feature::UnstableFeatures;

pub trait DepTrackingHash {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
Expand Down
Expand Up @@ -7,8 +7,9 @@ use std::env;
use std::fs;
use std::path::{Path, PathBuf};

use crate::session::search_paths::{SearchPath, PathKind};
use crate::search_paths::{SearchPath, PathKind};
use rustc_fs_util::fix_windows_verbatim_for_gcc;
use log::debug;

#[derive(Copy, Clone)]
pub enum FileMatch {
Expand Down Expand Up @@ -124,7 +125,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
// gcc chokes on verbatim paths which fs::canonicalize generates
// so we try to avoid those kinds of paths.
Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
Err(e) => bug!("failed to get realpath: {}", e),
Err(e) => panic!("failed to get realpath: {}", e),
}
})
}
Expand All @@ -133,7 +134,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
Ok(exe) => {
match canonicalize(Some(exe)) {
Some(mut p) => { p.pop(); p.pop(); p },
None => bug!("can't determine value for sysroot")
None => panic!("can't determine value for sysroot")
}
}
Err(ref e) => panic!(format!("failed to get current_exe: {}", e))
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_session/lib.rs
@@ -1,6 +1,21 @@
#![feature(test)]

// Use the test crate here so we depend on getopts through it. This allow tools to link to both
// librustc_session and libtest.
extern crate test as _;
extern crate getopts;

pub mod cgu_reuse_tracker;
pub mod utils;
#[macro_use]
pub mod lint;
pub mod node_id;
pub mod parse;

mod code_stats;
pub mod config;
pub mod filesearch;
pub mod search_paths;

mod session;
pub use session::*;
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
use crate::session::{early_error, config};
use crate::session::filesearch::make_target_lib_path;
use crate::{early_error, config};
use crate::filesearch::make_target_lib_path;

#[derive(Clone, Debug)]
pub struct SearchPath {
Expand All @@ -9,7 +9,7 @@ pub struct SearchPath {
pub files: Vec<PathBuf>,
}

#[derive(PartialEq, Clone, Copy, Debug, HashStable)]
#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq)]
pub enum PathKind {
Native,
Crate,
Expand All @@ -19,6 +19,8 @@ pub enum PathKind {
All,
}

rustc_data_structures::impl_stable_hash_via_hash!(PathKind);

impl PathKind {
pub fn matches(&self, kind: PathKind) -> bool {
match (self, kind) {
Expand Down

0 comments on commit cc2c33a

Please sign in to comment.