diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-10-30 17:33:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-30 17:33:18 +0100 |
| commit | d96bdbe2188f1ff1a3b1a9b91b23301d849ca621 (patch) | |
| tree | e7b9bdb9d95891e9438476fa1216c43c97e1f563 /compiler/rustc_session | |
| parent | 784f04b36751c0659292ab4f372105b4eab96331 (diff) | |
| parent | 0c381ec05afd1f51f12c9727fc05eead2400d500 (diff) | |
| download | rust-d96bdbe2188f1ff1a3b1a9b91b23301d849ca621.tar.gz rust-d96bdbe2188f1ff1a3b1a9b91b23301d849ca621.zip | |
Rollup merge of #117376 - nnethercote:rustc_interface-more, r=oli-obk
More `rustc_interface` cleanups In particular, following up #117268 with more improvement to `--cfg`/`--check-cfg` handling. r? ``@oli-obk``
Diffstat (limited to 'compiler/rustc_session')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 61 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 4 |
2 files changed, 12 insertions, 53 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 854e2b77993..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<Symbol> { - // NOTE: This should be kept in sync with `CheckCfg::<Symbol>::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,56 +1358,21 @@ fn default_configuration(sess: &Session) -> Cfg<Symbol> { } /// 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<T> = FxIndexSet<(T, Option<T>)>; +pub type Cfg = FxIndexSet<(Symbol, Option<Symbol>)>; -/// The parsed `--check-cfg` options. The `<T>` structure is similar to `Cfg`. -pub struct CheckCfg<T> { +/// 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<T, ExpectedValues<T>>, -} - -impl<T> Default for CheckCfg<T> { - fn default() -> Self { - CheckCfg { - exhaustive_names: false, - exhaustive_values: false, - expecteds: FxHashMap::default(), - } - } -} - -impl CheckCfg<String> { - pub fn intern(self) -> CheckCfg<Symbol> { - 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 expecteds: FxHashMap<Symbol, ExpectedValues<Symbol>>, } pub enum ExpectedValues<T> { @@ -1442,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) { if !self.exhaustive_values && !self.exhaustive_names { return; @@ -1582,13 +1547,7 @@ impl CheckCfg<Symbol> { } } -pub fn build_configuration(sess: &Session, user_cfg: Cfg<String>) -> Cfg<Symbol> { - // We can now intern these strings. - let mut user_cfg: Cfg<Symbol> = 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); 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<Symbol>, - pub check_config: CheckCfg<Symbol>, + 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. |
