Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main interner is running. They each use a short-lived interner and convert all interned symbols to strings in their output data structures. Once the main interner starts up, these data structures get converted into new data structures that are identical except with the strings converted to symbols. All is not obvious from the current code, which is a mess, particularly with inconsistent naming that obscures the parallel string/symbol data structures. This commit clean things up a lot. - The existing `CheckCfg` type is generic, allowing both `CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really useful, but it defaults to `String`. The commit removes the default so we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly, which makes things clearer. - Introduces `Cfg`, which is generic over `String` and `Symbol`, similar to `CheckCfg`. - Renames some things. - `parse_cfgspecs` -> `parse_cfg` - `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather than the underlying `FxHashSet` type. - `CrateConfig` -> `Cfg<Symbol>`. - `CrateCheckConfig` -> `CheckCfg<Symbol>` - Adds some comments explaining the string-to-symbol conversions. - `to_crate_check_config`, which converts `CheckCfg<String>` to `CheckCfg<Symbol>`, is inlined and removed and combined with the overly-general `CheckCfg::map_data` to produce `CheckCfg::<String>::intern`. - `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>` conversion, so callers don't need to, which removes the need for `to_crate_config`. The diff for two of the fields in `Config` is a good example of the improved clarity: ``` - pub crate_cfg: FxHashSet<(String, Option<String>)>, - pub crate_check_cfg: CheckCfg, + pub crate_cfg: Cfg<String>, + pub crate_check_cfg: CheckCfg<String>, ``` Compare that with the diff for the corresponding fields in `ParseSess`, and the relationship to `Config` is much clearer than before: ``` - pub config: CrateConfig, - pub check_config: CrateCheckConfig, + pub config: Cfg<Symbol>, + pub check_config: CheckCfg<Symbol>, ```
This commit is contained in:
parent
75e415ba86
commit
5e54997157
8 changed files with 65 additions and 71 deletions
|
@ -3,18 +3,17 @@ use info;
|
|||
use libloading::Library;
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
#[cfg(parallel_compiler)]
|
||||
use rustc_data_structures::sync;
|
||||
use rustc_errors::registry::Registry;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session as session;
|
||||
use rustc_session::config::CheckCfg;
|
||||
use rustc_session::config::{self, CrateType};
|
||||
use rustc_session::config::{OutFileName, OutputFilenames, OutputTypes};
|
||||
use rustc_session::config::{
|
||||
self, Cfg, CheckCfg, CrateType, OutFileName, OutputFilenames, OutputTypes,
|
||||
};
|
||||
use rustc_session::filesearch::sysroot_candidates;
|
||||
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
|
||||
use rustc_session::parse::CrateConfig;
|
||||
use rustc_session::{filesearch, output, Session};
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::edition::Edition;
|
||||
|
@ -38,7 +37,7 @@ pub type MakeBackendFn = fn() -> Box<dyn CodegenBackend>;
|
|||
/// 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 CrateConfig,
|
||||
cfg: &mut Cfg<Symbol>,
|
||||
sess: &mut Session,
|
||||
codegen_backend: &dyn CodegenBackend,
|
||||
) {
|
||||
|
@ -60,8 +59,8 @@ pub fn add_configuration(
|
|||
pub fn create_session(
|
||||
handler: &EarlyErrorHandler,
|
||||
sopts: config::Options,
|
||||
cfg: FxHashSet<(String, Option<String>)>,
|
||||
check_cfg: CheckCfg,
|
||||
cfg: Cfg<String>,
|
||||
check_cfg: CheckCfg<String>,
|
||||
locale_resources: &'static [&'static str],
|
||||
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
|
||||
io: CompilerIO,
|
||||
|
@ -121,12 +120,13 @@ pub fn create_session(
|
|||
|
||||
codegen_backend.init(&sess);
|
||||
|
||||
let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg));
|
||||
let mut cfg = config::build_configuration(&sess, cfg);
|
||||
add_configuration(&mut cfg, &mut sess, &*codegen_backend);
|
||||
|
||||
let mut check_cfg = config::to_crate_check_config(check_cfg);
|
||||
let mut check_cfg = check_cfg.intern();
|
||||
check_cfg.fill_well_known(&sess.target);
|
||||
|
||||
// These configs use symbols, rather than strings.
|
||||
sess.parse_sess.config = cfg;
|
||||
sess.parse_sess.check_config = check_cfg;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue