Skip to content

Commit 20bc5f6

Browse files
committed
Auto merge of #137072 - Urgau:check-cfg-load-builtins-at-once, r=<try>
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. 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 8c07d14 + 5ce8335 commit 20bc5f6

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};
@@ -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

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

1661+
fn load_all_builtins() -> impl Iterator<Item = Target> {
1662+
[
1663+
$( targets::$module::target(), )+
1664+
].into_iter()
1665+
}
1666+
16611667
#[cfg(test)]
16621668
mod tests {
16631669
// 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)