Skip to content

Commit 54fa2f8

Browse files
Rollup merge of rust-lang#137072 - Urgau:check-cfg-load-builtins-at-once, r=Noratrieb
Load all builtin targets at once instead of one by one in check-cfg This PR adds a method on `rustc_target::Target` to load all the builtin targets at once, and then uses that method when constructing the `target_*` values in check-cfg instead of load loading each target one by one by their name, which requires a lookup and was more of a hack anyway. This may give us some performance improvements as we won't need to do the lookup for the _currently_ 287 targets we have.
2 parents a4964fc + 6ec3cf9 commit 54fa2f8

File tree

2 files changed

+15
-6
lines changed
  • compiler

2 files changed

+15
-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};
@@ -432,11 +432,7 @@ impl CheckCfg {
432432
panic!("unable to get all the check-cfg values buckets");
433433
};
434434

435-
for target in TARGETS
436-
.iter()
437-
.map(|target| Target::expect_builtin(&TargetTuple::from_tuple(target)))
438-
.chain(iter::once(current_target.clone()))
439-
{
435+
for target in Target::builtins().chain(iter::once(current_target.clone())) {
440436
values_target_abi.insert(Symbol::intern(&target.options.abi));
441437
values_target_arch.insert(Symbol::intern(&target.arch));
442438
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));

compiler/rustc_target/src/spec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,14 @@ macro_rules! supported_targets {
16581658
Some(t)
16591659
}
16601660

1661+
fn load_all_builtins() -> impl Iterator<Item = Target> {
1662+
[
1663+
$( targets::$module::target, )+
1664+
]
1665+
.into_iter()
1666+
.map(|f| f())
1667+
}
1668+
16611669
#[cfg(test)]
16621670
mod tests {
16631671
// Cannot put this into a separate file without duplication, make an exception.
@@ -3360,6 +3368,11 @@ impl Target {
33603368
}
33613369
}
33623370

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

0 commit comments

Comments
 (0)