@@ -9,14 +9,13 @@ use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
9
9
use crate :: { lint, HashStableContext } ;
10
10
use crate :: { EarlyErrorHandler , Session } ;
11
11
12
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
13
13
use rustc_data_structures:: stable_hasher:: { StableOrd , ToStableHashKey } ;
14
14
use rustc_target:: abi:: Align ;
15
15
use rustc_target:: spec:: LinkSelfContainedComponents ;
16
16
use rustc_target:: spec:: { PanicStrategy , RelocModel , SanitizerSet , SplitDebuginfo } ;
17
17
use rustc_target:: spec:: { Target , TargetTriple , TargetWarnings , TARGETS } ;
18
18
19
- use crate :: parse:: { CrateCheckConfig , CrateConfig } ;
20
19
use rustc_feature:: UnstableFeatures ;
21
20
use rustc_span:: edition:: { Edition , DEFAULT_EDITION , EDITION_NAME_LIST , LATEST_STABLE_EDITION } ;
22
21
use rustc_span:: source_map:: { FileName , FilePathMapping } ;
@@ -1248,8 +1247,8 @@ pub const fn default_lib_output() -> CrateType {
1248
1247
CrateType :: Rlib
1249
1248
}
1250
1249
1251
- fn default_configuration ( sess : & Session ) -> CrateConfig {
1252
- // NOTE: This should be kept in sync with `CrateCheckConfig ::fill_well_known` below.
1250
+ fn default_configuration ( sess : & Session ) -> Cfg < Symbol > {
1251
+ // NOTE: This should be kept in sync with `CheckCfg::<Symbol> ::fill_well_known` below.
1253
1252
let end = & sess. target . endian ;
1254
1253
let arch = & sess. target . arch ;
1255
1254
let wordsz = sess. target . pointer_width . to_string ( ) ;
@@ -1265,7 +1264,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
1265
1264
sess. emit_fatal ( err) ;
1266
1265
} ) ;
1267
1266
1268
- let mut ret = CrateConfig :: default ( ) ;
1267
+ let mut ret = Cfg :: default ( ) ;
1269
1268
ret. reserve ( 7 ) ; // the minimum number of insertions
1270
1269
// Target bindings.
1271
1270
ret. insert ( ( sym:: target_os, Some ( Symbol :: intern ( os) ) ) ) ;
@@ -1358,15 +1357,17 @@ fn default_configuration(sess: &Session) -> CrateConfig {
1358
1357
ret
1359
1358
}
1360
1359
1361
- /// Converts the crate `cfg!` configuration from `String` to `Symbol`.
1362
- /// `rustc_interface::interface::Config` accepts this in the compiler configuration,
1363
- /// but the symbol interner is not yet set up then, so we must convert it later.
1364
- pub fn to_crate_config ( cfg : FxHashSet < ( String , Option < String > ) > ) -> CrateConfig {
1365
- cfg. into_iter ( ) . map ( |( a, b) | ( Symbol :: intern ( & a) , b. map ( |b| Symbol :: intern ( & b) ) ) ) . collect ( )
1366
- }
1360
+ /// 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.
1364
+ ///
1365
+ /// An `FxIndexSet` is used to ensure deterministic ordering of error messages
1366
+ /// relating to `--cfg`.
1367
+ pub type Cfg < T > = FxIndexSet < ( T , Option < T > ) > ;
1367
1368
1368
- /// The parsed `--check-cfg` options
1369
- pub struct CheckCfg < T = String > {
1369
+ /// The parsed `--check-cfg` options. The `<T>` structure is similar to `Cfg`.
1370
+ pub struct CheckCfg < T > {
1370
1371
/// Is well known names activated
1371
1372
pub exhaustive_names : bool ,
1372
1373
/// Is well known values activated
@@ -1385,8 +1386,8 @@ impl<T> Default for CheckCfg<T> {
1385
1386
}
1386
1387
}
1387
1388
1388
- impl < T > CheckCfg < T > {
1389
- fn map_data < O : Eq + Hash > ( self , f : impl Fn ( T ) -> O ) -> CheckCfg < O > {
1389
+ impl CheckCfg < String > {
1390
+ pub fn intern ( self ) -> CheckCfg < Symbol > {
1390
1391
CheckCfg {
1391
1392
exhaustive_names : self . exhaustive_names ,
1392
1393
exhaustive_values : self . exhaustive_values ,
@@ -1395,10 +1396,10 @@ impl<T> CheckCfg<T> {
1395
1396
. into_iter ( )
1396
1397
. map ( |( name, values) | {
1397
1398
(
1398
- f ( name) ,
1399
+ Symbol :: intern ( & name) ,
1399
1400
match values {
1400
1401
ExpectedValues :: Some ( values) => ExpectedValues :: Some (
1401
- values. into_iter ( ) . map ( |b| b. map ( |b| f ( b) ) ) . collect ( ) ,
1402
+ values. into_iter ( ) . map ( |b| b. map ( |b| Symbol :: intern ( & b) ) ) . collect ( ) ,
1402
1403
) ,
1403
1404
ExpectedValues :: Any => ExpectedValues :: Any ,
1404
1405
} ,
@@ -1441,14 +1442,7 @@ impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues<T> {
1441
1442
}
1442
1443
}
1443
1444
1444
- /// Converts the crate `--check-cfg` options from `String` to `Symbol`.
1445
- /// `rustc_interface::interface::Config` accepts this in the compiler configuration,
1446
- /// but the symbol interner is not yet set up then, so we must convert it later.
1447
- pub fn to_crate_check_config ( cfg : CheckCfg ) -> CrateCheckConfig {
1448
- cfg. map_data ( |s| Symbol :: intern ( & s) )
1449
- }
1450
-
1451
- impl CrateCheckConfig {
1445
+ impl CheckCfg < Symbol > {
1452
1446
pub fn fill_well_known ( & mut self , current_target : & Target ) {
1453
1447
if !self . exhaustive_values && !self . exhaustive_names {
1454
1448
return ;
@@ -1588,7 +1582,13 @@ impl CrateCheckConfig {
1588
1582
}
1589
1583
}
1590
1584
1591
- pub fn build_configuration ( sess : & Session , mut user_cfg : CrateConfig ) -> CrateConfig {
1585
+ pub fn build_configuration ( sess : & Session , user_cfg : Cfg < String > ) -> Cfg < Symbol > {
1586
+ // We can now intern these strings.
1587
+ let mut user_cfg: Cfg < Symbol > = user_cfg
1588
+ . into_iter ( )
1589
+ . map ( |( a, b) | ( Symbol :: intern ( & a) , b. map ( |b| Symbol :: intern ( & b) ) ) )
1590
+ . collect ( ) ;
1591
+
1592
1592
// Combine the configuration requested by the session (command line) with
1593
1593
// some default and generated configuration items.
1594
1594
let default_cfg = default_configuration ( sess) ;
0 commit comments