Skip to content

Commit 5c6a12c

Browse files
committed
Make Cfg and CheckCfg non-generic.
They now only ever contains symbols.
1 parent 8e4ac98 commit 5c6a12c

File tree

5 files changed

+20
-40
lines changed

5 files changed

+20
-40
lines changed

compiler/rustc_interface/src/interface.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_session::Session;
2424
use rustc_session::{lint, EarlyErrorHandler};
2525
use rustc_span::source_map::{FileLoader, FileName};
2626
use rustc_span::symbol::sym;
27-
use rustc_span::Symbol;
2827
use std::path::PathBuf;
2928
use std::result;
3029
use std::sync::Arc;
@@ -65,7 +64,7 @@ impl Compiler {
6564
}
6665

6766
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
68-
pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<Symbol> {
67+
pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg {
6968
cfgs.into_iter()
7069
.map(|s| {
7170
let sess = ParseSess::with_silent_emitter(Some(format!(
@@ -116,11 +115,11 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
116115
error!(r#"expected `key` or `key="value"`"#);
117116
}
118117
})
119-
.collect::<Cfg<Symbol>>()
118+
.collect::<Cfg>()
120119
}
121120

122121
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
123-
pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg<Symbol> {
122+
pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg {
124123
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
125124
// are enabled by default.
126125
let exhaustive_names = !specs.is_empty();

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@ use rustc_session::{build_session, getopts, Session};
2626
use rustc_session::{CompilerIO, EarlyErrorHandler};
2727
use rustc_span::edition::{Edition, DEFAULT_EDITION};
2828
use rustc_span::symbol::sym;
29-
use rustc_span::SourceFileHashAlgorithm;
30-
use rustc_span::{FileName, Symbol};
29+
use rustc_span::{FileName, SourceFileHashAlgorithm};
3130
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel};
3231
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel};
3332
use std::collections::{BTreeMap, BTreeSet};
3433
use std::num::NonZeroUsize;
3534
use std::path::{Path, PathBuf};
3635
use std::sync::Arc;
3736

38-
fn mk_session(
39-
handler: &mut EarlyErrorHandler,
40-
matches: getopts::Matches,
41-
) -> (Session, Cfg<Symbol>) {
37+
fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) {
4238
let registry = registry::Registry::new(&[]);
4339
let sessopts = build_session_options(handler, &matches);
4440
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));

compiler/rustc_interface/src/util.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ pub type MakeBackendFn = fn() -> Box<dyn CodegenBackend>;
3636
///
3737
/// This is performed by checking whether a set of permitted features
3838
/// is available on the target machine, by querying the codegen backend.
39-
pub fn add_configuration(
40-
cfg: &mut Cfg<Symbol>,
41-
sess: &mut Session,
42-
codegen_backend: &dyn CodegenBackend,
43-
) {
39+
pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dyn CodegenBackend) {
4440
let tf = sym::target_feature;
4541

4642
let unstable_target_features = codegen_backend.target_features(sess, true);
@@ -59,8 +55,8 @@ pub fn add_configuration(
5955
pub fn create_session(
6056
handler: &EarlyErrorHandler,
6157
sopts: config::Options,
62-
cfg: Cfg<Symbol>,
63-
mut check_cfg: CheckCfg<Symbol>,
58+
cfg: Cfg,
59+
mut check_cfg: CheckCfg,
6460
locale_resources: &'static [&'static str],
6561
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
6662
io: CompilerIO,

compiler/rustc_session/src/config.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,8 @@ pub const fn default_lib_output() -> CrateType {
12471247
CrateType::Rlib
12481248
}
12491249

1250-
fn default_configuration(sess: &Session) -> Cfg<Symbol> {
1251-
// NOTE: This should be kept in sync with `CheckCfg::<Symbol>::fill_well_known` below.
1250+
fn default_configuration(sess: &Session) -> Cfg {
1251+
// NOTE: This should be kept in sync with `CheckCfg::fill_well_known` below.
12521252
let end = &sess.target.endian;
12531253
let arch = &sess.target.arch;
12541254
let wordsz = sess.target.pointer_width.to_string();
@@ -1358,32 +1358,21 @@ fn default_configuration(sess: &Session) -> Cfg<Symbol> {
13581358
}
13591359

13601360
/// The parsed `--cfg` options that define the compilation environment of the
1361-
/// crate, used to drive conditional compilation. `T` is always `String` or
1362-
/// `Symbol`. Strings are used temporarily very early on. Once the the main
1363-
/// symbol interner is running, they are converted to symbols.
1361+
/// crate, used to drive conditional compilation.
13641362
///
13651363
/// An `FxIndexSet` is used to ensure deterministic ordering of error messages
13661364
/// relating to `--cfg`.
1367-
pub type Cfg<T> = FxIndexSet<(T, Option<T>)>;
1365+
pub type Cfg = FxIndexSet<(Symbol, Option<Symbol>)>;
13681366

1369-
/// The parsed `--check-cfg` options. The `<T>` structure is similar to `Cfg`.
1370-
pub struct CheckCfg<T> {
1367+
/// The parsed `--check-cfg` options.
1368+
#[derive(Default)]
1369+
pub struct CheckCfg {
13711370
/// Is well known names activated
13721371
pub exhaustive_names: bool,
13731372
/// Is well known values activated
13741373
pub exhaustive_values: bool,
13751374
/// All the expected values for a config name
1376-
pub expecteds: FxHashMap<T, ExpectedValues<T>>,
1377-
}
1378-
1379-
impl<T> Default for CheckCfg<T> {
1380-
fn default() -> Self {
1381-
CheckCfg {
1382-
exhaustive_names: false,
1383-
exhaustive_values: false,
1384-
expecteds: FxHashMap::default(),
1385-
}
1386-
}
1375+
pub expecteds: FxHashMap<Symbol, ExpectedValues<Symbol>>,
13871376
}
13881377

13891378
pub enum ExpectedValues<T> {
@@ -1418,7 +1407,7 @@ impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues<T> {
14181407
}
14191408
}
14201409

1421-
impl CheckCfg<Symbol> {
1410+
impl CheckCfg {
14221411
pub fn fill_well_known(&mut self, current_target: &Target) {
14231412
if !self.exhaustive_values && !self.exhaustive_names {
14241413
return;
@@ -1558,7 +1547,7 @@ impl CheckCfg<Symbol> {
15581547
}
15591548
}
15601549

1561-
pub fn build_configuration(sess: &Session, mut user_cfg: Cfg<Symbol>) -> Cfg<Symbol> {
1550+
pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
15621551
// Combine the configuration requested by the session (command line) with
15631552
// some default and generated configuration items.
15641553
let default_cfg = default_configuration(sess);

compiler/rustc_session/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ pub fn add_feature_diagnostics_for_issue(
188188
pub struct ParseSess {
189189
pub span_diagnostic: Handler,
190190
pub unstable_features: UnstableFeatures,
191-
pub config: Cfg<Symbol>,
192-
pub check_config: CheckCfg<Symbol>,
191+
pub config: Cfg,
192+
pub check_config: CheckCfg,
193193
pub edition: Edition,
194194
/// Places where raw identifiers were used. This is used to avoid complaining about idents
195195
/// clashing with keywords in new editions.

0 commit comments

Comments
 (0)