Skip to content

Commit 2158f47

Browse files
committed
compiler: intern architecture at compile time
1 parent 1d0e4f3 commit 2158f47

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",
@@ -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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,44 @@ crate::target_spec_enum! {
18781878
parse_error_type = "architecture";
18791879
}
18801880

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

0 commit comments

Comments
 (0)