Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 20bc5f6

Browse filesBrowse files
committed
Auto merge of rust-lang#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
Copy full SHA for 20bc5f6

File tree

Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed
Filter options
  • compiler
Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed

‎compiler/rustc_session/src/config/cfg.rs

Copy file name to clipboardExpand all lines: compiler/rustc_session/src/config/cfg.rs
+2-6Lines changed: 2 additions & 6 deletions
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

Copy file name to clipboardExpand all lines: compiler/rustc_target/src/spec/mod.rs
+11Lines changed: 11 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.