Skip to content

Commit 5ce8335

Browse files
committed
Load all builtin targets at once instead of one by one
This should give us some performance improvements as we won't need to do the lookup for the _currently_ 287 targets we have.
1 parent 3f33b30 commit 5ce8335

File tree

2 files changed

+13
-6
lines changed
  • compiler

2 files changed

+13
-6
lines changed

compiler/rustc_session/src/config/cfg.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
2929
use rustc_lint_defs::BuiltinLintDiag;
3030
use rustc_lint_defs::builtin::EXPLICIT_BUILTIN_CFGS_IN_FLAGS;
3131
use rustc_span::{Symbol, sym};
32-
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, TARGETS, Target, TargetTuple};
32+
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, Target};
3333

3434
use crate::Session;
3535
use crate::config::{CrateType, FmtDebug};
@@ -426,11 +426,7 @@ impl CheckCfg {
426426
panic!("unable to get all the check-cfg values buckets");
427427
};
428428

429-
for target in TARGETS
430-
.iter()
431-
.map(|target| Target::expect_builtin(&TargetTuple::from_tuple(target)))
432-
.chain(iter::once(current_target.clone()))
433-
{
429+
for target in Target::builtins().chain(iter::once(current_target.clone())) {
434430
values_target_abi.insert(Symbol::intern(&target.options.abi));
435431
values_target_arch.insert(Symbol::intern(&target.arch));
436432
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));

compiler/rustc_target/src/spec/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,12 @@ macro_rules! supported_targets {
16621662
Some(t)
16631663
}
16641664

1665+
fn load_all_builtins() -> impl Iterator<Item = Target> {
1666+
[
1667+
$( targets::$module::target(), )+
1668+
].into_iter()
1669+
}
1670+
16651671
#[cfg(test)]
16661672
mod tests {
16671673
// Cannot put this into a separate file without duplication, make an exception.
@@ -3360,6 +3366,11 @@ impl Target {
33603366
}
33613367
}
33623368

3369+
/// Load all built-in targets
3370+
pub fn builtins() -> impl Iterator<Item = Target> {
3371+
load_all_builtins()
3372+
}
3373+
33633374
/// Search for a JSON file specifying the given target tuple.
33643375
///
33653376
/// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the

0 commit comments

Comments
 (0)