From 8e4ac980fd775d311bc63642c8d6b5739aa6f34c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 30 Oct 2023 14:01:33 +1100 Subject: Change cfg parsers to produce symbols instead of strings. --- compiler/rustc_session/src/config.rs | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'compiler/rustc_session') diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 854e2b77993..4a0bdd511a3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1386,30 +1386,6 @@ impl Default for CheckCfg { } } -impl CheckCfg { - pub fn intern(self) -> CheckCfg { - CheckCfg { - exhaustive_names: self.exhaustive_names, - exhaustive_values: self.exhaustive_values, - expecteds: self - .expecteds - .into_iter() - .map(|(name, values)| { - ( - Symbol::intern(&name), - match values { - ExpectedValues::Some(values) => ExpectedValues::Some( - values.into_iter().map(|b| b.map(|b| Symbol::intern(&b))).collect(), - ), - ExpectedValues::Any => ExpectedValues::Any, - }, - ) - }) - .collect(), - } - } -} - pub enum ExpectedValues { Some(FxHashSet>), Any, @@ -1582,13 +1558,7 @@ impl CheckCfg { } } -pub fn build_configuration(sess: &Session, user_cfg: Cfg) -> Cfg { - // We can now intern these strings. - let mut user_cfg: Cfg = user_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: Cfg) -> Cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. let default_cfg = default_configuration(sess); -- cgit 1.4.1-3-g733a5 From 5c6a12c1affd7759eb793f3bcd2a97577fab7ab4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 30 Oct 2023 14:05:06 +1100 Subject: Make `Cfg` and `CheckCfg` non-generic. They now only ever contains symbols. --- compiler/rustc_interface/src/interface.rs | 7 +++---- compiler/rustc_interface/src/tests.rs | 8 ++------ compiler/rustc_interface/src/util.rs | 10 +++------- compiler/rustc_session/src/config.rs | 31 ++++++++++--------------------- compiler/rustc_session/src/parse.rs | 4 ++-- 5 files changed, 20 insertions(+), 40 deletions(-) (limited to 'compiler/rustc_session') diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index cf887bc665b..66bcb199709 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -24,7 +24,6 @@ use rustc_session::Session; use rustc_session::{lint, EarlyErrorHandler}; use rustc_span::source_map::{FileLoader, FileName}; use rustc_span::symbol::sym; -use rustc_span::Symbol; use std::path::PathBuf; use std::result; use std::sync::Arc; @@ -65,7 +64,7 @@ impl Compiler { } /// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`. -pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec) -> Cfg { +pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { let sess = ParseSess::with_silent_emitter(Some(format!( @@ -116,11 +115,11 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec) -> Cfg>() + .collect::() } /// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`. -pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec) -> CheckCfg { +pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec) -> CheckCfg { // If any --check-cfg is passed then exhaustive_values and exhaustive_names // are enabled by default. let exhaustive_names = !specs.is_empty(); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 466aa21ad8e..41ccb25f789 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -26,8 +26,7 @@ use rustc_session::{build_session, getopts, Session}; use rustc_session::{CompilerIO, EarlyErrorHandler}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::symbol::sym; -use rustc_span::SourceFileHashAlgorithm; -use rustc_span::{FileName, Symbol}; +use rustc_span::{FileName, SourceFileHashAlgorithm}; use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel}; use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel}; use std::collections::{BTreeMap, BTreeSet}; @@ -35,10 +34,7 @@ use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use std::sync::Arc; -fn mk_session( - handler: &mut EarlyErrorHandler, - matches: getopts::Matches, -) -> (Session, Cfg) { +fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) { let registry = registry::Registry::new(&[]); let sessopts = build_session_options(handler, &matches); let cfg = parse_cfg(handler, matches.opt_strs("cfg")); diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index a974bdd3c0e..9bda685df01 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -36,11 +36,7 @@ pub type MakeBackendFn = fn() -> Box; /// /// This is performed by checking whether a set of permitted features /// is available on the target machine, by querying the codegen backend. -pub fn add_configuration( - cfg: &mut Cfg, - sess: &mut Session, - codegen_backend: &dyn CodegenBackend, -) { +pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dyn CodegenBackend) { let tf = sym::target_feature; let unstable_target_features = codegen_backend.target_features(sess, true); @@ -59,8 +55,8 @@ pub fn add_configuration( pub fn create_session( handler: &EarlyErrorHandler, sopts: config::Options, - cfg: Cfg, - mut check_cfg: CheckCfg, + cfg: Cfg, + mut check_cfg: CheckCfg, locale_resources: &'static [&'static str], file_loader: Option>, io: CompilerIO, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 4a0bdd511a3..a8ebab4ae33 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1247,8 +1247,8 @@ pub const fn default_lib_output() -> CrateType { CrateType::Rlib } -fn default_configuration(sess: &Session) -> Cfg { - // NOTE: This should be kept in sync with `CheckCfg::::fill_well_known` below. +fn default_configuration(sess: &Session) -> Cfg { + // NOTE: This should be kept in sync with `CheckCfg::fill_well_known` below. let end = &sess.target.endian; let arch = &sess.target.arch; let wordsz = sess.target.pointer_width.to_string(); @@ -1358,32 +1358,21 @@ fn default_configuration(sess: &Session) -> Cfg { } /// The parsed `--cfg` options that define the compilation environment of the -/// crate, used to drive conditional compilation. `T` is always `String` or -/// `Symbol`. Strings are used temporarily very early on. Once the the main -/// symbol interner is running, they are converted to symbols. +/// crate, used to drive conditional compilation. /// /// An `FxIndexSet` is used to ensure deterministic ordering of error messages /// relating to `--cfg`. -pub type Cfg = FxIndexSet<(T, Option)>; +pub type Cfg = FxIndexSet<(Symbol, Option)>; -/// The parsed `--check-cfg` options. The `` structure is similar to `Cfg`. -pub struct CheckCfg { +/// The parsed `--check-cfg` options. +#[derive(Default)] +pub struct CheckCfg { /// Is well known names activated pub exhaustive_names: bool, /// Is well known values activated pub exhaustive_values: bool, /// All the expected values for a config name - pub expecteds: FxHashMap>, -} - -impl Default for CheckCfg { - fn default() -> Self { - CheckCfg { - exhaustive_names: false, - exhaustive_values: false, - expecteds: FxHashMap::default(), - } - } + pub expecteds: FxHashMap>, } pub enum ExpectedValues { @@ -1418,7 +1407,7 @@ impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues { } } -impl CheckCfg { +impl CheckCfg { pub fn fill_well_known(&mut self, current_target: &Target) { if !self.exhaustive_values && !self.exhaustive_names { return; @@ -1558,7 +1547,7 @@ impl CheckCfg { } } -pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { +pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. let default_cfg = default_configuration(sess); diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 5b98ee5d992..4d20d6d4187 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -188,8 +188,8 @@ pub fn add_feature_diagnostics_for_issue( pub struct ParseSess { pub span_diagnostic: Handler, pub unstable_features: UnstableFeatures, - pub config: Cfg, - pub check_config: CheckCfg, + pub config: Cfg, + pub check_config: CheckCfg, pub edition: Edition, /// Places where raw identifiers were used. This is used to avoid complaining about idents /// clashing with keywords in new editions. -- cgit 1.4.1-3-g733a5