]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/session/config.rs
Directly use types from libsyntax::ast
[rust.git] / src / librustc / session / config.rs
index 5d01025c5b508a6b7a3c4ab9d7297cebafb9d74b..1f9fd9e0319a264d62682318a43e01b5fcb472e5 100644 (file)
@@ -1,22 +1,21 @@
 //! Contains infrastructure for configuring the compiler, including parsing
 //! command-line options.
 
-use crate::lint;
-use crate::middle::cstore;
+use rustc_session::lint;
+use rustc_session::utils::NativeLibraryKind;
 use crate::session::{early_error, early_warn, Session};
 use crate::session::search_paths::SearchPath;
 
 use rustc_data_structures::fx::FxHashSet;
+use rustc_feature::UnstableFeatures;
 
 use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
 use rustc_target::spec::{Target, TargetTriple};
 
-use syntax;
-use syntax::ast::{self, IntTy, UintTy};
+use syntax::ast::CrateConfig;
 use syntax::source_map::{FileName, FilePathMapping};
 use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
 use syntax::symbol::{sym, Symbol};
-use syntax::feature_gate::UnstableFeatures;
 
 use errors::emitter::HumanReadableErrorType;
 use errors::{ColorConfig, FatalError, Handler};
@@ -36,8 +35,7 @@
 
 pub struct Config {
     pub target: Target,
-    pub isize_ty: IntTy,
-    pub usize_ty: UintTy,
+    pub ptr_width: u32,
 }
 
 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
@@ -48,6 +46,17 @@ pub enum Sanitizer {
     Thread,
 }
 
+impl fmt::Display for Sanitizer {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            Sanitizer::Address => "address".fmt(f),
+            Sanitizer::Leak => "leak".fmt(f),
+            Sanitizer::Memory => "memory".fmt(f),
+            Sanitizer::Thread => "thread".fmt(f),
+        }
+    }
+}
+
 impl FromStr for Sanitizer {
     type Err = ();
     fn from_str(s: &str) -> Result<Sanitizer, ()> {
@@ -405,7 +414,7 @@ pub struct Options {
         describe_lints: bool [UNTRACKED],
         output_types: OutputTypes [TRACKED],
         search_paths: Vec<SearchPath> [UNTRACKED],
-        libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
+        libs: Vec<(String, Option<String>, Option<NativeLibraryKind>)> [TRACKED],
         maybe_sysroot: Option<PathBuf> [UNTRACKED],
 
         target_triple: TargetTriple [TRACKED],
@@ -1365,8 +1374,6 @@ fn parse_symbol_mangling_version(
         "enable queries of the dependency graph for regression testing"),
     no_analysis: bool = (false, parse_bool, [UNTRACKED],
         "parse and expand the source, but run no analysis"),
-    extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
-        "load extra plugins"),
     unstable_options: bool = (false, parse_bool, [UNTRACKED],
         "adds unstable command line options to rustc interface"),
     force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
@@ -1527,7 +1534,7 @@ pub const fn default_lib_output() -> CrateType {
     CrateType::Rlib
 }
 
-pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
+pub fn default_configuration(sess: &Session) -> CrateConfig {
     let end = &sess.target.target.target_endian;
     let arch = &sess.target.target.arch;
     let wordsz = &sess.target.target.target_pointer_width;
@@ -1583,6 +1590,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
             }
         }
     }
+    if let Some(s) = &sess.opts.debugging_opts.sanitizer {
+        let symbol = Symbol::intern(&s.to_string());
+        ret.insert((sym::sanitize, Some(symbol)));
+    }
     if sess.opts.debug_assertions {
         ret.insert((Symbol::intern("debug_assertions"), None));
     }
@@ -1595,13 +1606,13 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
 /// Converts the crate `cfg!` configuration from `String` to `Symbol`.
 /// `rustc_interface::interface::Config` accepts this in the compiler configuration,
 /// but the symbol interner is not yet set up then, so we must convert it later.
-pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> ast::CrateConfig {
+pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> CrateConfig {
     cfg.into_iter()
        .map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b))))
        .collect()
 }
 
-pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig {
+pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig {
     // Combine the configuration requested by the session (command line) with
     // some default and generated configuration items.
     let default_cfg = default_configuration(sess);
@@ -1621,10 +1632,10 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
         FatalError.raise();
     });
 
-    let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
-        "16" => (ast::IntTy::I16, ast::UintTy::U16),
-        "32" => (ast::IntTy::I32, ast::UintTy::U32),
-        "64" => (ast::IntTy::I64, ast::UintTy::U64),
+    let ptr_width = match &target.target_pointer_width[..] {
+        "16" => 16,
+        "32" => 32,
+        "64" => 64,
         w => sp.fatal(&format!(
             "target specification was invalid: \
              unrecognized target-pointer-width {}",
@@ -1634,8 +1645,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
 
     Config {
         target,
-        isize_ty,
-        usize_ty,
+        ptr_width,
     }
 }
 
@@ -2368,7 +2378,7 @@ fn select_debuginfo(
 fn parse_libs(
     matches: &getopts::Matches,
     error_format: ErrorOutputType,
-) -> Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> {
+) -> Vec<(String, Option<String>, Option<NativeLibraryKind>)> {
     matches
         .opt_strs("l")
         .into_iter()
@@ -2379,10 +2389,12 @@ fn parse_libs(
             let kind = parts.next().unwrap();
             let (name, kind) = match (parts.next(), kind) {
                 (None, name) => (name, None),
-                (Some(name), "dylib") => (name, Some(cstore::NativeUnknown)),
-                (Some(name), "framework") => (name, Some(cstore::NativeFramework)),
-                (Some(name), "static") => (name, Some(cstore::NativeStatic)),
-                (Some(name), "static-nobundle") => (name, Some(cstore::NativeStaticNobundle)),
+                (Some(name), "dylib") => (name, Some(NativeLibraryKind::NativeUnknown)),
+                (Some(name), "framework") => (name, Some(NativeLibraryKind::NativeFramework)),
+                (Some(name), "static") => (name, Some(NativeLibraryKind::NativeStatic)),
+                (Some(name), "static-nobundle") => {
+                    (name, Some(NativeLibraryKind::NativeStaticNobundle))
+                }
                 (_, s) => {
                     early_error(
                         error_format,
@@ -2394,7 +2406,8 @@ fn parse_libs(
                     );
                 }
             };
-            if kind == Some(cstore::NativeStaticNobundle) && !nightly_options::is_nightly_build() {
+            if kind == Some(NativeLibraryKind::NativeStaticNobundle) &&
+                !nightly_options::is_nightly_build() {
                 early_error(
                     error_format,
                     &format!(
@@ -2703,7 +2716,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
 
 pub mod nightly_options {
     use getopts;
-    use syntax::feature_gate::UnstableFeatures;
+    use rustc_feature::UnstableFeatures;
     use super::{ErrorOutputType, OptionStability, RustcOptGroup};
     use crate::session::early_error;
 
@@ -2843,8 +2856,8 @@ pub fn needs_analysis(&self) -> bool {
 /// 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 crate::lint;
-    use crate::middle::cstore;
+    use rustc_session::lint;
+    use rustc_session::utils::NativeLibraryKind;
     use std::collections::BTreeMap;
     use std::hash::Hash;
     use std::path::PathBuf;
@@ -2852,9 +2865,9 @@ mod dep_tracking {
     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::feature_gate::UnstableFeatures;
 
     pub trait DepTrackingHash {
         fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
@@ -2902,7 +2915,7 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
     impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
     impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
     impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
-    impl_dep_tracking_hash_via_hash!(Option<cstore::NativeLibraryKind>);
+    impl_dep_tracking_hash_via_hash!(Option<NativeLibraryKind>);
     impl_dep_tracking_hash_via_hash!(CrateType);
     impl_dep_tracking_hash_via_hash!(MergeFunctions);
     impl_dep_tracking_hash_via_hash!(PanicStrategy);
@@ -2913,7 +2926,7 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
     impl_dep_tracking_hash_via_hash!(DebugInfo);
     impl_dep_tracking_hash_via_hash!(UnstableFeatures);
     impl_dep_tracking_hash_via_hash!(OutputTypes);
-    impl_dep_tracking_hash_via_hash!(cstore::NativeLibraryKind);
+    impl_dep_tracking_hash_via_hash!(NativeLibraryKind);
     impl_dep_tracking_hash_via_hash!(Sanitizer);
     impl_dep_tracking_hash_via_hash!(Option<Sanitizer>);
     impl_dep_tracking_hash_via_hash!(TargetTriple);
@@ -2929,7 +2942,7 @@ fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
     impl_dep_tracking_hash_for_sortable_vec_of!((
         String,
         Option<String>,
-        Option<cstore::NativeLibraryKind>
+        Option<NativeLibraryKind>
     ));
     impl_dep_tracking_hash_for_sortable_vec_of!((String, u64));
     impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer);