-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc_interface
cleanups
#117268
rustc_interface
cleanups
#117268
Changes from all commits
98c469c
3feec48
2142d01
32986d8
75e415b
5e54997
5438004
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,13 @@ use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; | |
use crate::{lint, HashStableContext}; | ||
use crate::{EarlyErrorHandler, Session}; | ||
|
||
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; | ||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; | ||
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; | ||
use rustc_target::abi::Align; | ||
use rustc_target::spec::LinkSelfContainedComponents; | ||
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo}; | ||
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS}; | ||
|
||
use crate::parse::{CrateCheckConfig, CrateConfig}; | ||
use rustc_feature::UnstableFeatures; | ||
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION}; | ||
use rustc_span::source_map::{FileName, FilePathMapping}; | ||
|
@@ -1248,8 +1247,8 @@ pub const fn default_lib_output() -> CrateType { | |
CrateType::Rlib | ||
} | ||
|
||
fn default_configuration(sess: &Session) -> CrateConfig { | ||
// NOTE: This should be kept in sync with `CrateCheckConfig::fill_well_known` below. | ||
fn default_configuration(sess: &Session) -> Cfg<Symbol> { | ||
// NOTE: This should be kept in sync with `CheckCfg::<Symbol>::fill_well_known` below. | ||
let end = &sess.target.endian; | ||
let arch = &sess.target.arch; | ||
let wordsz = sess.target.pointer_width.to_string(); | ||
|
@@ -1265,7 +1264,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { | |
sess.emit_fatal(err); | ||
}); | ||
|
||
let mut ret = CrateConfig::default(); | ||
let mut ret = Cfg::default(); | ||
ret.reserve(7); // the minimum number of insertions | ||
// Target bindings. | ||
ret.insert((sym::target_os, Some(Symbol::intern(os)))); | ||
|
@@ -1358,15 +1357,17 @@ fn default_configuration(sess: &Session) -> CrateConfig { | |
ret | ||
} | ||
|
||
/// 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>)>) -> CrateConfig { | ||
cfg.into_iter().map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b)))).collect() | ||
} | ||
/// 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. | ||
/// | ||
/// An `FxIndexSet` is used to ensure deterministic ordering of error messages | ||
/// relating to `--cfg`. | ||
pub type Cfg<T> = FxIndexSet<(T, Option<T>)>; | ||
|
||
/// The parsed `--check-cfg` options | ||
pub struct CheckCfg<T = String> { | ||
/// The parsed `--check-cfg` options. The `<T>` structure is similar to `Cfg`. | ||
pub struct CheckCfg<T> { | ||
/// Is well known names activated | ||
pub exhaustive_names: bool, | ||
/// Is well known values activated | ||
|
@@ -1385,8 +1386,8 @@ impl<T> Default for CheckCfg<T> { | |
} | ||
} | ||
|
||
impl<T> CheckCfg<T> { | ||
fn map_data<O: Eq + Hash>(self, f: impl Fn(T) -> O) -> CheckCfg<O> { | ||
impl CheckCfg<String> { | ||
pub fn intern(self) -> CheckCfg<Symbol> { | ||
CheckCfg { | ||
exhaustive_names: self.exhaustive_names, | ||
exhaustive_values: self.exhaustive_values, | ||
|
@@ -1395,10 +1396,10 @@ impl<T> CheckCfg<T> { | |
.into_iter() | ||
.map(|(name, values)| { | ||
( | ||
f(name), | ||
Symbol::intern(&name), | ||
match values { | ||
ExpectedValues::Some(values) => ExpectedValues::Some( | ||
values.into_iter().map(|b| b.map(|b| f(b))).collect(), | ||
values.into_iter().map(|b| b.map(|b| Symbol::intern(&b))).collect(), | ||
), | ||
ExpectedValues::Any => ExpectedValues::Any, | ||
}, | ||
|
@@ -1441,14 +1442,7 @@ impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues<T> { | |
} | ||
} | ||
|
||
/// Converts the crate `--check-cfg` options 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. | ||
Comment on lines
-1444
to
-1446
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it is worth keeping this comment? by moving it to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other new comments that communicate the same ideas, so I think that's good enough. |
||
pub fn to_crate_check_config(cfg: CheckCfg) -> CrateCheckConfig { | ||
cfg.map_data(|s| Symbol::intern(&s)) | ||
} | ||
|
||
impl CrateCheckConfig { | ||
impl CheckCfg<Symbol> { | ||
pub fn fill_well_known(&mut self, current_target: &Target) { | ||
if !self.exhaustive_values && !self.exhaustive_names { | ||
return; | ||
|
@@ -1588,7 +1582,13 @@ impl CrateCheckConfig { | |
} | ||
} | ||
|
||
pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig { | ||
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(); | ||
|
||
// Combine the configuration requested by the session (command line) with | ||
// some default and generated configuration items. | ||
let default_cfg = default_configuration(sess); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍