Make Cfg
and CheckCfg
non-generic.
They now only ever contains symbols.
This commit is contained in:
parent
8e4ac980fd
commit
5c6a12c1af
5 changed files with 20 additions and 40 deletions
|
@ -24,7 +24,6 @@ use rustc_session::Session;
|
||||||
use rustc_session::{lint, EarlyErrorHandler};
|
use rustc_session::{lint, EarlyErrorHandler};
|
||||||
use rustc_span::source_map::{FileLoader, FileName};
|
use rustc_span::source_map::{FileLoader, FileName};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Symbol;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -65,7 +64,7 @@ impl Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
|
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
|
||||||
pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<Symbol> {
|
pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg {
|
||||||
cfgs.into_iter()
|
cfgs.into_iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
let sess = ParseSess::with_silent_emitter(Some(format!(
|
let sess = ParseSess::with_silent_emitter(Some(format!(
|
||||||
|
@ -116,11 +115,11 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
|
||||||
error!(r#"expected `key` or `key="value"`"#);
|
error!(r#"expected `key` or `key="value"`"#);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Cfg<Symbol>>()
|
.collect::<Cfg>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
|
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
|
||||||
pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg<Symbol> {
|
pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg {
|
||||||
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
|
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
|
||||||
// are enabled by default.
|
// are enabled by default.
|
||||||
let exhaustive_names = !specs.is_empty();
|
let exhaustive_names = !specs.is_empty();
|
||||||
|
|
|
@ -26,8 +26,7 @@ use rustc_session::{build_session, getopts, Session};
|
||||||
use rustc_session::{CompilerIO, EarlyErrorHandler};
|
use rustc_session::{CompilerIO, EarlyErrorHandler};
|
||||||
use rustc_span::edition::{Edition, DEFAULT_EDITION};
|
use rustc_span::edition::{Edition, DEFAULT_EDITION};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::SourceFileHashAlgorithm;
|
use rustc_span::{FileName, SourceFileHashAlgorithm};
|
||||||
use rustc_span::{FileName, Symbol};
|
|
||||||
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel};
|
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel};
|
||||||
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
|
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
|
@ -35,10 +34,7 @@ use std::num::NonZeroUsize;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn mk_session(
|
fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) {
|
||||||
handler: &mut EarlyErrorHandler,
|
|
||||||
matches: getopts::Matches,
|
|
||||||
) -> (Session, Cfg<Symbol>) {
|
|
||||||
let registry = registry::Registry::new(&[]);
|
let registry = registry::Registry::new(&[]);
|
||||||
let sessopts = build_session_options(handler, &matches);
|
let sessopts = build_session_options(handler, &matches);
|
||||||
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));
|
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));
|
||||||
|
|
|
@ -36,11 +36,7 @@ pub type MakeBackendFn = fn() -> Box<dyn CodegenBackend>;
|
||||||
///
|
///
|
||||||
/// This is performed by checking whether a set of permitted features
|
/// This is performed by checking whether a set of permitted features
|
||||||
/// is available on the target machine, by querying the codegen backend.
|
/// is available on the target machine, by querying the codegen backend.
|
||||||
pub fn add_configuration(
|
pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dyn CodegenBackend) {
|
||||||
cfg: &mut Cfg<Symbol>,
|
|
||||||
sess: &mut Session,
|
|
||||||
codegen_backend: &dyn CodegenBackend,
|
|
||||||
) {
|
|
||||||
let tf = sym::target_feature;
|
let tf = sym::target_feature;
|
||||||
|
|
||||||
let unstable_target_features = codegen_backend.target_features(sess, true);
|
let unstable_target_features = codegen_backend.target_features(sess, true);
|
||||||
|
@ -59,8 +55,8 @@ pub fn add_configuration(
|
||||||
pub fn create_session(
|
pub fn create_session(
|
||||||
handler: &EarlyErrorHandler,
|
handler: &EarlyErrorHandler,
|
||||||
sopts: config::Options,
|
sopts: config::Options,
|
||||||
cfg: Cfg<Symbol>,
|
cfg: Cfg,
|
||||||
mut check_cfg: CheckCfg<Symbol>,
|
mut check_cfg: CheckCfg,
|
||||||
locale_resources: &'static [&'static str],
|
locale_resources: &'static [&'static str],
|
||||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||||
io: CompilerIO,
|
io: CompilerIO,
|
||||||
|
|
|
@ -1247,8 +1247,8 @@ pub const fn default_lib_output() -> CrateType {
|
||||||
CrateType::Rlib
|
CrateType::Rlib
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_configuration(sess: &Session) -> Cfg<Symbol> {
|
fn default_configuration(sess: &Session) -> Cfg {
|
||||||
// NOTE: This should be kept in sync with `CheckCfg::<Symbol>::fill_well_known` below.
|
// NOTE: This should be kept in sync with `CheckCfg::fill_well_known` below.
|
||||||
let end = &sess.target.endian;
|
let end = &sess.target.endian;
|
||||||
let arch = &sess.target.arch;
|
let arch = &sess.target.arch;
|
||||||
let wordsz = sess.target.pointer_width.to_string();
|
let wordsz = sess.target.pointer_width.to_string();
|
||||||
|
@ -1358,32 +1358,21 @@ fn default_configuration(sess: &Session) -> Cfg<Symbol> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The parsed `--cfg` options that define the compilation environment of the
|
/// The parsed `--cfg` options that define the compilation environment of the
|
||||||
/// crate, used to drive conditional compilation. `T` is always `String` or
|
/// crate, used to drive conditional compilation.
|
||||||
/// `Symbol`. Strings are used temporarily very early on. Once the the main
|
|
||||||
/// symbol interner is running, they are converted to symbols.
|
|
||||||
///
|
///
|
||||||
/// An `FxIndexSet` is used to ensure deterministic ordering of error messages
|
/// An `FxIndexSet` is used to ensure deterministic ordering of error messages
|
||||||
/// relating to `--cfg`.
|
/// relating to `--cfg`.
|
||||||
pub type Cfg<T> = FxIndexSet<(T, Option<T>)>;
|
pub type Cfg = FxIndexSet<(Symbol, Option<Symbol>)>;
|
||||||
|
|
||||||
/// The parsed `--check-cfg` options. The `<T>` structure is similar to `Cfg`.
|
/// The parsed `--check-cfg` options.
|
||||||
pub struct CheckCfg<T> {
|
#[derive(Default)]
|
||||||
|
pub struct CheckCfg {
|
||||||
/// Is well known names activated
|
/// Is well known names activated
|
||||||
pub exhaustive_names: bool,
|
pub exhaustive_names: bool,
|
||||||
/// Is well known values activated
|
/// Is well known values activated
|
||||||
pub exhaustive_values: bool,
|
pub exhaustive_values: bool,
|
||||||
/// All the expected values for a config name
|
/// All the expected values for a config name
|
||||||
pub expecteds: FxHashMap<T, ExpectedValues<T>>,
|
pub expecteds: FxHashMap<Symbol, ExpectedValues<Symbol>>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Default for CheckCfg<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
CheckCfg {
|
|
||||||
exhaustive_names: false,
|
|
||||||
exhaustive_values: false,
|
|
||||||
expecteds: FxHashMap::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ExpectedValues<T> {
|
pub enum ExpectedValues<T> {
|
||||||
|
@ -1418,7 +1407,7 @@ impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckCfg<Symbol> {
|
impl CheckCfg {
|
||||||
pub fn fill_well_known(&mut self, current_target: &Target) {
|
pub fn fill_well_known(&mut self, current_target: &Target) {
|
||||||
if !self.exhaustive_values && !self.exhaustive_names {
|
if !self.exhaustive_values && !self.exhaustive_names {
|
||||||
return;
|
return;
|
||||||
|
@ -1558,7 +1547,7 @@ impl CheckCfg<Symbol> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_configuration(sess: &Session, mut user_cfg: Cfg<Symbol>) -> Cfg<Symbol> {
|
pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
|
||||||
// Combine the configuration requested by the session (command line) with
|
// Combine the configuration requested by the session (command line) with
|
||||||
// some default and generated configuration items.
|
// some default and generated configuration items.
|
||||||
let default_cfg = default_configuration(sess);
|
let default_cfg = default_configuration(sess);
|
||||||
|
|
|
@ -188,8 +188,8 @@ pub fn add_feature_diagnostics_for_issue(
|
||||||
pub struct ParseSess {
|
pub struct ParseSess {
|
||||||
pub span_diagnostic: Handler,
|
pub span_diagnostic: Handler,
|
||||||
pub unstable_features: UnstableFeatures,
|
pub unstable_features: UnstableFeatures,
|
||||||
pub config: Cfg<Symbol>,
|
pub config: Cfg,
|
||||||
pub check_config: CheckCfg<Symbol>,
|
pub check_config: CheckCfg,
|
||||||
pub edition: Edition,
|
pub edition: Edition,
|
||||||
/// Places where raw identifiers were used. This is used to avoid complaining about idents
|
/// Places where raw identifiers were used. This is used to avoid complaining about idents
|
||||||
/// clashing with keywords in new editions.
|
/// clashing with keywords in new editions.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue