Skip to content

Commit 2d03fd5

Browse files
committed
compiler: intern architecture at compile time
1 parent 23b2e59 commit 2d03fd5

File tree

6 files changed

+75
-41
lines changed

6 files changed

+75
-41
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
621621
// -Zfixed-x18
622622
if sess.opts.unstable_opts.fixed_x18 {
623623
if sess.target.arch != Architecture::AArch64 {
624-
sess.dcx().emit_fatal(errors::FixedX18InvalidArch { arch: sess.target.arch.as_str() });
624+
sess.dcx().emit_fatal(errors::FixedX18InvalidArch {
625+
arch: sess.target.arch.desc_symbol().as_str(),
626+
});
625627
} else {
626628
features.push("+reserve-x18".into());
627629
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,11 @@ fn link_natively(
882882
// four digit numbers in the range 1000 to 9999 inclusive
883883
if is_msvc_link_exe && (code < 1000 || code > 9999) {
884884
let is_vs_installed = find_msvc_tools::find_vs_version().is_ok();
885-
let has_linker =
886-
find_msvc_tools::find_tool(sess.target.arch.as_str(), "link.exe")
887-
.is_some();
885+
let has_linker = find_msvc_tools::find_tool(
886+
sess.target.arch.desc_symbol().as_str(),
887+
"link.exe",
888+
)
889+
.is_some();
888890

889891
sess.dcx().emit_note(errors::LinkExeUnexpectedError);
890892

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn get_linker<'a>(
5353
target_cpu: &'a str,
5454
codegen_backend: &'static str,
5555
) -> Box<dyn Linker + 'a> {
56-
let msvc_tool = find_msvc_tools::find_tool(sess.target.arch.as_str(), "link.exe");
56+
let msvc_tool = find_msvc_tools::find_tool(sess.target.arch.desc_symbol().as_str(), "link.exe");
5757

5858
// If our linker looks like a batch script on Windows then to execute this
5959
// we'll need to spawn `cmd` explicitly. This is primarily done to handle

compiler/rustc_session/src/config/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
240240
}
241241

242242
ins_str!(sym::target_abi, &sess.target.abi);
243-
ins_str!(sym::target_arch, sess.target.arch.as_str());
243+
ins_sym!(sym::target_arch, sess.target.arch.desc_symbol());
244244
ins_str!(sym::target_endian, sess.target.endian.as_str());
245245
ins_str!(sym::target_env, &sess.target.env);
246246

@@ -448,7 +448,7 @@ impl CheckCfg {
448448

449449
for target in Target::builtins().chain(iter::once(current_target.clone())) {
450450
values_target_abi.insert(Symbol::intern(&target.options.abi));
451-
values_target_arch.insert(Symbol::intern(target.arch.as_str()));
451+
values_target_arch.insert(target.arch.desc_symbol());
452452
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));
453453
values_target_env.insert(Symbol::intern(&target.options.env));
454454
values_target_family.extend(

compiler/rustc_span/src/symbol.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ symbols! {
400400
_t,
401401
_task_context,
402402
a32,
403+
aarch64,
403404
aarch64_target_feature,
404405
aarch64_unstable_target_feature,
405406
aarch64_ver_target_feature,
@@ -449,6 +450,7 @@ symbols! {
449450
altivec,
450451
alu32,
451452
always,
453+
amdgpu,
452454
analysis,
453455
and,
454456
and_then,
@@ -466,6 +468,7 @@ symbols! {
466468
args,
467469
arith_offset,
468470
arm,
471+
arm64ec,
469472
arm_target_feature,
470473
array,
471474
as_dash_needed: "as-needed",
@@ -554,6 +557,7 @@ symbols! {
554557
autodiff_reverse,
555558
automatically_derived,
556559
available_externally,
560+
avr,
557561
avx,
558562
avx10_target_feature,
559563
avx512_target_feature,
@@ -586,6 +590,7 @@ symbols! {
586590
box_patterns,
587591
box_syntax,
588592
boxed_slice,
593+
bpf,
589594
bpf_target_feature,
590595
braced_empty_structs,
591596
branch,
@@ -790,6 +795,7 @@ symbols! {
790795
crate_type,
791796
crate_visibility_modifier,
792797
crt_dash_static: "crt-static",
798+
csky,
793799
csky_target_feature,
794800
cstr_type,
795801
cstring_as_c_str,
@@ -1156,6 +1162,7 @@ symbols! {
11561162
hashset_drain_ty,
11571163
hashset_iter,
11581164
hashset_iter_ty,
1165+
hexagon,
11591166
hexagon_target_feature,
11601167
hidden,
11611168
hide,
@@ -1342,11 +1349,14 @@ symbols! {
13421349
logf32,
13431350
logf64,
13441351
logf128,
1352+
loongarch32,
1353+
loongarch64,
13451354
loongarch_target_feature,
13461355
loop_break_value,
13471356
loop_match,
13481357
lr,
13491358
lt,
1359+
m68k,
13501360
m68k_target_feature,
13511361
macro_at_most_once_rep,
13521362
macro_attr,
@@ -1420,6 +1430,10 @@ symbols! {
14201430
minnumf32,
14211431
minnumf64,
14221432
minnumf128,
1433+
mips,
1434+
mips32r6,
1435+
mips64,
1436+
mips64r6,
14231437
mips_target_feature,
14241438
mir_assume,
14251439
mir_basic_block,
@@ -1468,6 +1482,7 @@ symbols! {
14681482
move_ref_pattern,
14691483
move_size_limit,
14701484
movrs_target_feature,
1485+
msp430,
14711486
mul,
14721487
mul_assign,
14731488
mul_with_overflow,
@@ -1554,6 +1569,7 @@ symbols! {
15541569
not,
15551570
notable_trait,
15561571
note,
1572+
nvptx64,
15571573
nvptx_target_feature,
15581574
object_safe_for_dispatch,
15591575
of,
@@ -1678,6 +1694,9 @@ symbols! {
16781694
post_cleanup: "post-cleanup",
16791695
post_dash_lto: "post-lto",
16801696
postfix_match,
1697+
powerpc,
1698+
powerpc64,
1699+
powerpc64le,
16811700
powerpc_target_feature,
16821701
powf16,
16831702
powf32,
@@ -1825,6 +1844,8 @@ symbols! {
18251844
resume,
18261845
return_position_impl_trait_in_trait,
18271846
return_type_notation,
1847+
riscv32,
1848+
riscv64,
18281849
riscv_target_feature,
18291850
rlib,
18301851
ropi,
@@ -1971,6 +1992,7 @@ symbols! {
19711992
rvalue_static_promotion,
19721993
rwpi,
19731994
s,
1995+
s390x,
19741996
s390x_target_feature,
19751997
safety,
19761998
sanitize,
@@ -2099,9 +2121,12 @@ symbols! {
20992121
slice_patterns,
21002122
slicing_syntax,
21012123
soft,
2124+
sparc,
2125+
sparc64,
21022126
sparc_target_feature,
21032127
specialization,
21042128
speed,
2129+
spirv,
21052130
spotlight,
21062131
sqrtf16,
21072132
sqrtf32,
@@ -2415,6 +2440,8 @@ symbols! {
24152440
vtable_size,
24162441
warn,
24172442
wasip2,
2443+
wasm32,
2444+
wasm64,
24182445
wasm_abi,
24192446
wasm_import_module,
24202447
wasm_target_feature,
@@ -2441,12 +2468,15 @@ symbols! {
24412468
write_str,
24422469
write_via_move,
24432470
writeln_macro,
2471+
x86,
2472+
x86_64,
24442473
x86_amx_intrinsics,
24452474
x87_reg,
24462475
x87_target_feature,
24472476
xer,
24482477
xmm_reg,
24492478
xop_target_feature,
2479+
xtensa,
24502480
yeet_desugar_details,
24512481
yeet_expr,
24522482
yes,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,46 +1877,46 @@ pub enum Architecture {
18771877
}
18781878

18791879
impl Architecture {
1880-
pub fn as_str(&self) -> &'static str {
1880+
pub const fn desc_symbol(&self) -> Symbol {
18811881
match self {
1882-
Self::AArch64 => "aarch64",
1883-
Self::AmdGpu => "amdgpu",
1884-
Self::Arm => "arm",
1885-
Self::Arm64EC => "arm64ec",
1886-
Self::Avr => "avr",
1887-
Self::Bpf => "bpf",
1888-
Self::CSKY => "csky",
1889-
Self::Hexagon => "hexagon",
1890-
Self::LoongArch32 => "loongarch32",
1891-
Self::LoongArch64 => "loongarch64",
1892-
Self::M68k => "m68k",
1893-
Self::Mips => "mips",
1894-
Self::Mips32r6 => "mips32r6",
1895-
Self::Mips64 => "mips64",
1896-
Self::Mips64r6 => "mips64r6",
1897-
Self::Msp430 => "msp430",
1898-
Self::Nvptx64 => "nvptx64",
1899-
Self::PowerPC => "powerpc",
1900-
Self::PowerPC64 => "powerpc64",
1901-
Self::PowerPC64LE => "powerpc64le",
1902-
Self::RiscV32 => "riscv32",
1903-
Self::RiscV64 => "riscv64",
1904-
Self::S390x => "s390x",
1905-
Self::Sparc => "sparc",
1906-
Self::Sparc64 => "sparc64",
1907-
Self::SpirV => "spirv",
1908-
Self::Wasm32 => "wasm32",
1909-
Self::Wasm64 => "wasm64",
1910-
Self::X86 => "x86",
1911-
Self::X86_64 => "x86_64",
1912-
Self::Xtensa => "xtensa",
1882+
Self::AArch64 => sym::aarch64,
1883+
Self::AmdGpu => sym::amdgpu,
1884+
Self::Arm => sym::arm,
1885+
Self::Arm64EC => sym::arm64ec,
1886+
Self::Avr => sym::avr,
1887+
Self::Bpf => sym::bpf,
1888+
Self::CSKY => sym::csky,
1889+
Self::Hexagon => sym::hexagon,
1890+
Self::LoongArch32 => sym::loongarch32,
1891+
Self::LoongArch64 => sym::loongarch64,
1892+
Self::M68k => sym::m68k,
1893+
Self::Mips => sym::mips,
1894+
Self::Mips32r6 => sym::mips32r6,
1895+
Self::Mips64 => sym::mips64,
1896+
Self::Mips64r6 => sym::mips64r6,
1897+
Self::Msp430 => sym::msp430,
1898+
Self::Nvptx64 => sym::nvptx64,
1899+
Self::PowerPC => sym::powerpc,
1900+
Self::PowerPC64 => sym::powerpc64,
1901+
Self::PowerPC64LE => sym::powerpc64le,
1902+
Self::RiscV32 => sym::riscv32,
1903+
Self::RiscV64 => sym::riscv64,
1904+
Self::S390x => sym::s390x,
1905+
Self::Sparc => sym::sparc,
1906+
Self::Sparc64 => sym::sparc64,
1907+
Self::SpirV => sym::spirv,
1908+
Self::Wasm32 => sym::wasm32,
1909+
Self::Wasm64 => sym::wasm64,
1910+
Self::X86 => sym::x86,
1911+
Self::X86_64 => sym::x86_64,
1912+
Self::Xtensa => sym::xtensa,
19131913
}
19141914
}
19151915
}
19161916

19171917
impl fmt::Display for Architecture {
19181918
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919-
f.write_str(self.as_str())
1919+
f.write_str(self.desc_symbol().as_str())
19201920
}
19211921
}
19221922

@@ -1965,7 +1965,7 @@ pub struct TargetMetadata {
19651965

19661966
impl ToJson for Architecture {
19671967
fn to_json(&self) -> Json {
1968-
self.as_str().to_json()
1968+
self.desc_symbol().as_str().to_json()
19691969
}
19701970
}
19711971

0 commit comments

Comments
 (0)