Skip to content

Commit cc2c33a

Browse files
Move Session to librustc_session
1 parent 52d4d47 commit cc2c33a

File tree

9 files changed

+87
-65
lines changed

9 files changed

+87
-65
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -3893,9 +3893,13 @@ name = "rustc_session"
38933893
version = "0.0.0"
38943894
dependencies = [
38953895
"log",
3896+
"num_cpus",
38963897
"rustc_data_structures",
38973898
"rustc_errors",
3899+
"rustc_feature",
3900+
"rustc_fs_util",
38983901
"rustc_index",
3902+
"rustc_target",
38993903
"serialize",
39003904
"syntax_pos",
39013905
]

src/librustc/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#![recursion_limit="512"]
6565

6666
#[macro_use] extern crate bitflags;
67-
extern crate getopts;
6867
#[macro_use] extern crate scoped_tls;
6968
#[cfg(windows)]
7069
extern crate libc;
@@ -74,10 +73,6 @@ extern crate libc;
7473
#[macro_use] extern crate syntax;
7574
#[macro_use] extern crate smallvec;
7675

77-
// Use the test crate here so we depend on getopts through it. This allow tools to link to both
78-
// librustc_driver and libtest.
79-
extern crate test as _;
80-
8176
#[cfg(test)]
8277
mod tests;
8378

@@ -113,7 +108,7 @@ pub mod middle {
113108
}
114109

115110
pub mod mir;
116-
pub mod session;
111+
pub use rustc_session as session;
117112
pub mod traits;
118113
pub mod ty;
119114

src/librustc_session/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ path = "lib.rs"
1111
[dependencies]
1212
log = "0.4"
1313
rustc_errors = { path = "../librustc_errors" }
14+
rustc_feature = { path = "../librustc_feature" }
15+
rustc_target = { path = "../librustc_target" }
1416
rustc_serialize = { path = "../libserialize", package = "serialize" }
1517
rustc_data_structures = { path = "../librustc_data_structures" }
1618
syntax_pos = { path = "../libsyntax_pos" }
1719
rustc_index = { path = "../librustc_index" }
20+
rustc_fs_util = { path = "../librustc_fs_util" }
21+
num_cpus = "1.0"
File renamed without changes.

src/librustc/session/config.rs src/librustc_session/config.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
//! Contains infrastructure for configuring the compiler, including parsing
22
//! command-line options.
33
4-
use rustc_session::lint;
5-
use rustc_session::utils::NativeLibraryKind;
6-
use crate::session::{early_error, early_warn, Session};
7-
use crate::session::search_paths::SearchPath;
4+
use crate::lint;
5+
use crate::utils::NativeLibraryKind;
6+
use crate::{early_error, early_warn, Session};
7+
use crate::search_paths::SearchPath;
88

99
use rustc_data_structures::fx::FxHashSet;
10-
use rustc_feature::UnstableFeatures;
10+
use rustc_data_structures::impl_stable_hash_via_hash;
1111

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

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

18-
use syntax::source_map::{FileName, FilePathMapping};
19-
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
20-
use syntax::symbol::{sym, Symbol};
18+
use syntax_pos::source_map::{FileName, FilePathMapping};
19+
use syntax_pos::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
20+
use syntax_pos::symbol::{sym, Symbol};
21+
use rustc_feature::UnstableFeatures;
2122

22-
use errors::emitter::HumanReadableErrorType;
23-
use errors::{ColorConfig, FatalError, Handler};
23+
use rustc_errors::emitter::HumanReadableErrorType;
24+
use rustc_errors::{ColorConfig, FatalError, Handler};
2425

2526
use getopts;
2627

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

703704
impl_stable_hash_via_hash!(EntryFnType);
704705

705-
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, HashStable)]
706+
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)]
706707
pub enum CrateType {
707708
Executable,
708709
Dylib,
@@ -712,6 +713,8 @@ pub enum CrateType {
712713
ProcMacro,
713714
}
714715

716+
impl_stable_hash_via_hash!(CrateType);
717+
715718
#[derive(Clone, Hash)]
716719
pub enum Passes {
717720
Some(Vec<String>),
@@ -782,7 +785,7 @@ macro_rules! options {
782785
value, $outputname,
783786
key, type_desc))
784787
}
785-
(None, None) => bug!()
788+
(None, None) => panic!()
786789
}
787790
}
788791
found = true;
@@ -2720,7 +2723,7 @@ pub mod nightly_options {
27202723
use getopts;
27212724
use rustc_feature::UnstableFeatures;
27222725
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
2723-
use crate::session::early_error;
2726+
use crate::early_error;
27242727

27252728
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
27262729
is_nightly_build()
@@ -2858,18 +2861,18 @@ impl PpMode {
28582861
/// we have an opt-in scheme here, so one is hopefully forced to think about
28592862
/// how the hash should be calculated when adding a new command-line argument.
28602863
mod dep_tracking {
2861-
use rustc_session::lint;
2862-
use rustc_session::utils::NativeLibraryKind;
2864+
use crate::lint;
2865+
use crate::utils::NativeLibraryKind;
28632866
use std::collections::BTreeMap;
28642867
use std::hash::Hash;
28652868
use std::path::PathBuf;
28662869
use std::collections::hash_map::DefaultHasher;
28672870
use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
28682871
Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
28692872
SymbolManglingVersion};
2870-
use rustc_feature::UnstableFeatures;
28712873
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
2872-
use syntax::edition::Edition;
2874+
use syntax_pos::edition::Edition;
2875+
use rustc_feature::UnstableFeatures;
28732876

28742877
pub trait DepTrackingHash {
28752878
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);

src/librustc/session/filesearch.rs src/librustc_session/filesearch.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use std::env;
77
use std::fs;
88
use std::path::{Path, PathBuf};
99

10-
use crate::session::search_paths::{SearchPath, PathKind};
10+
use crate::search_paths::{SearchPath, PathKind};
1111
use rustc_fs_util::fix_windows_verbatim_for_gcc;
12+
use log::debug;
1213

1314
#[derive(Copy, Clone)]
1415
pub enum FileMatch {
@@ -124,7 +125,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
124125
// gcc chokes on verbatim paths which fs::canonicalize generates
125126
// so we try to avoid those kinds of paths.
126127
Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)),
127-
Err(e) => bug!("failed to get realpath: {}", e),
128+
Err(e) => panic!("failed to get realpath: {}", e),
128129
}
129130
})
130131
}
@@ -133,7 +134,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
133134
Ok(exe) => {
134135
match canonicalize(Some(exe)) {
135136
Some(mut p) => { p.pop(); p.pop(); p },
136-
None => bug!("can't determine value for sysroot")
137+
None => panic!("can't determine value for sysroot")
137138
}
138139
}
139140
Err(ref e) => panic!(format!("failed to get current_exe: {}", e))

src/librustc_session/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
#![feature(test)]
2+
3+
// Use the test crate here so we depend on getopts through it. This allow tools to link to both
4+
// librustc_session and libtest.
5+
extern crate test as _;
6+
extern crate getopts;
7+
18
pub mod cgu_reuse_tracker;
29
pub mod utils;
310
#[macro_use]
411
pub mod lint;
512
pub mod node_id;
613
pub mod parse;
14+
15+
mod code_stats;
16+
pub mod config;
17+
pub mod filesearch;
18+
pub mod search_paths;
19+
20+
mod session;
21+
pub use session::*;

src/librustc/session/search_paths.rs src/librustc_session/search_paths.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::{Path, PathBuf};
2-
use crate::session::{early_error, config};
3-
use crate::session::filesearch::make_target_lib_path;
2+
use crate::{early_error, config};
3+
use crate::filesearch::make_target_lib_path;
44

55
#[derive(Clone, Debug)]
66
pub struct SearchPath {
@@ -9,7 +9,7 @@ pub struct SearchPath {
99
pub files: Vec<PathBuf>,
1010
}
1111

12-
#[derive(PartialEq, Clone, Copy, Debug, HashStable)]
12+
#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq)]
1313
pub enum PathKind {
1414
Native,
1515
Crate,
@@ -19,6 +19,8 @@ pub enum PathKind {
1919
All,
2020
}
2121

22+
rustc_data_structures::impl_stable_hash_via_hash!(PathKind);
23+
2224
impl PathKind {
2325
pub fn matches(&self, kind: PathKind) -> bool {
2426
match (self, kind) {

0 commit comments

Comments
 (0)