Skip to content

Commit 0c8533d

Browse files
committed
compiler: intern architecture at compile time
1 parent 270e49b commit 0c8533d

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

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.desc());
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.desc()));
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",
@@ -555,6 +558,7 @@ symbols! {
555558
autodiff_reverse,
556559
automatically_derived,
557560
available_externally,
561+
avr,
558562
avx,
559563
avx10_target_feature,
560564
avx512_target_feature,
@@ -587,6 +591,7 @@ symbols! {
587591
box_patterns,
588592
box_syntax,
589593
boxed_slice,
594+
bpf,
590595
bpf_target_feature,
591596
braced_empty_structs,
592597
branch,
@@ -791,6 +796,7 @@ symbols! {
791796
crate_type,
792797
crate_visibility_modifier,
793798
crt_dash_static: "crt-static",
799+
csky,
794800
csky_target_feature,
795801
cstr_type,
796802
cstring_as_c_str,
@@ -1157,6 +1163,7 @@ symbols! {
11571163
hashset_drain_ty,
11581164
hashset_iter,
11591165
hashset_iter_ty,
1166+
hexagon,
11601167
hexagon_target_feature,
11611168
hidden,
11621169
hide,
@@ -1343,11 +1350,14 @@ symbols! {
13431350
logf32,
13441351
logf64,
13451352
logf128,
1353+
loongarch32,
1354+
loongarch64,
13461355
loongarch_target_feature,
13471356
loop_break_value,
13481357
loop_match,
13491358
lr,
13501359
lt,
1360+
m68k,
13511361
m68k_target_feature,
13521362
macro_at_most_once_rep,
13531363
macro_attr,
@@ -1423,6 +1433,10 @@ symbols! {
14231433
minnumf32,
14241434
minnumf64,
14251435
minnumf128,
1436+
mips,
1437+
mips32r6,
1438+
mips64,
1439+
mips64r6,
14261440
mips_target_feature,
14271441
mir_assume,
14281442
mir_basic_block,
@@ -1471,6 +1485,7 @@ symbols! {
14711485
move_ref_pattern,
14721486
move_size_limit,
14731487
movrs_target_feature,
1488+
msp430,
14741489
mul,
14751490
mul_assign,
14761491
mul_with_overflow,
@@ -1558,6 +1573,7 @@ symbols! {
15581573
notable_trait,
15591574
note,
15601575
null,
1576+
nvptx64,
15611577
nvptx_target_feature,
15621578
object_safe_for_dispatch,
15631579
of,
@@ -1683,6 +1699,9 @@ symbols! {
16831699
post_cleanup: "post-cleanup",
16841700
post_dash_lto: "post-lto",
16851701
postfix_match,
1702+
powerpc,
1703+
powerpc64,
1704+
powerpc64le,
16861705
powerpc_target_feature,
16871706
powf16,
16881707
powf32,
@@ -1830,6 +1849,8 @@ symbols! {
18301849
resume,
18311850
return_position_impl_trait_in_trait,
18321851
return_type_notation,
1852+
riscv32,
1853+
riscv64,
18331854
riscv_target_feature,
18341855
rlib,
18351856
ropi,
@@ -1977,6 +1998,7 @@ symbols! {
19771998
rvalue_static_promotion,
19781999
rwpi,
19792000
s,
2001+
s390x,
19802002
s390x_target_feature,
19812003
safety,
19822004
sanitize,
@@ -2105,9 +2127,12 @@ symbols! {
21052127
slice_patterns,
21062128
slicing_syntax,
21072129
soft,
2130+
sparc,
2131+
sparc64,
21082132
sparc_target_feature,
21092133
specialization,
21102134
speed,
2135+
spirv,
21112136
spotlight,
21122137
sqrtf16,
21132138
sqrtf32,
@@ -2422,6 +2447,8 @@ symbols! {
24222447
vtable_size,
24232448
warn,
24242449
wasip2,
2450+
wasm32,
2451+
wasm64,
24252452
wasm_abi,
24262453
wasm_import_module,
24272454
wasm_target_feature,
@@ -2448,12 +2475,15 @@ symbols! {
24482475
write_str,
24492476
write_via_move,
24502477
writeln_macro,
2478+
x86,
2479+
x86_64,
24512480
x86_amx_intrinsics,
24522481
x87_reg,
24532482
x87_target_feature,
24542483
xer,
24552484
xmm_reg,
24562485
xop_target_feature,
2486+
xtensa,
24572487
yeet_desugar_details,
24582488
yeet_expr,
24592489
yes,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,44 @@ crate::target_spec_enum! {
18851885
parse_error_type = "architecture";
18861886
}
18871887

1888+
impl Arch {
1889+
pub const fn desc_symbol(&self) -> Symbol {
1890+
match self {
1891+
Self::AArch64 => sym::aarch64,
1892+
Self::AmdGpu => sym::amdgpu,
1893+
Self::Arm => sym::arm,
1894+
Self::Arm64EC => sym::arm64ec,
1895+
Self::Avr => sym::avr,
1896+
Self::Bpf => sym::bpf,
1897+
Self::CSky => sym::csky,
1898+
Self::Hexagon => sym::hexagon,
1899+
Self::LoongArch32 => sym::loongarch32,
1900+
Self::LoongArch64 => sym::loongarch64,
1901+
Self::M68k => sym::m68k,
1902+
Self::Mips => sym::mips,
1903+
Self::Mips32r6 => sym::mips32r6,
1904+
Self::Mips64 => sym::mips64,
1905+
Self::Mips64r6 => sym::mips64r6,
1906+
Self::Msp430 => sym::msp430,
1907+
Self::Nvptx64 => sym::nvptx64,
1908+
Self::PowerPC => sym::powerpc,
1909+
Self::PowerPC64 => sym::powerpc64,
1910+
Self::PowerPC64LE => sym::powerpc64le,
1911+
Self::RiscV32 => sym::riscv32,
1912+
Self::RiscV64 => sym::riscv64,
1913+
Self::S390x => sym::s390x,
1914+
Self::Sparc => sym::sparc,
1915+
Self::Sparc64 => sym::sparc64,
1916+
Self::SpirV => sym::spirv,
1917+
Self::Wasm32 => sym::wasm32,
1918+
Self::Wasm64 => sym::wasm64,
1919+
Self::X86 => sym::x86,
1920+
Self::X86_64 => sym::x86_64,
1921+
Self::Xtensa => sym::xtensa,
1922+
}
1923+
}
1924+
}
1925+
18881926
/// Everything `rustc` knows about how to compile for a specific target.
18891927
///
18901928
/// Every field here must be specified, and has no default value.

0 commit comments

Comments
 (0)