Skip to content

Commit ef16611

Browse files
authored
Unrolled build for #144592
Rollup merge of #144592 - fee1-dead-contrib:target_spec, r=Noratrieb generate list of all variants with `target_spec_enum` This helps us avoid the hardcoded lists elsewhere. r? ``@Noratrieb``
2 parents 9f2ef0f + 4841d8c commit ef16611

File tree

4 files changed

+19
-42
lines changed

4 files changed

+19
-42
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_middle::util::Providers;
4545
use rustc_session::Session;
4646
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4747
use rustc_span::Symbol;
48+
use rustc_target::spec::{RelocModel, TlsModel};
4849

4950
mod abi;
5051
mod allocator;
@@ -244,16 +245,7 @@ impl CodegenBackend for LlvmCodegenBackend {
244245
match req.kind {
245246
PrintKind::RelocationModels => {
246247
writeln!(out, "Available relocation models:").unwrap();
247-
for name in &[
248-
"static",
249-
"pic",
250-
"pie",
251-
"dynamic-no-pic",
252-
"ropi",
253-
"rwpi",
254-
"ropi-rwpi",
255-
"default",
256-
] {
248+
for name in RelocModel::ALL.iter().map(RelocModel::desc).chain(["default"]) {
257249
writeln!(out, " {name}").unwrap();
258250
}
259251
writeln!(out).unwrap();
@@ -267,9 +259,7 @@ impl CodegenBackend for LlvmCodegenBackend {
267259
}
268260
PrintKind::TlsModels => {
269261
writeln!(out, "Available TLS models:").unwrap();
270-
for name in
271-
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
272-
{
262+
for name in TlsModel::ALL.iter().map(TlsModel::desc) {
273263
writeln!(out, " {name}").unwrap();
274264
}
275265
writeln!(out).unwrap();

compiler/rustc_session/src/config/cfg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,13 @@ impl CheckCfg {
374374

375375
ins!(sym::overflow_checks, no_values);
376376

377-
ins!(sym::panic, empty_values).extend(&PanicStrategy::all());
377+
ins!(sym::panic, empty_values)
378+
.extend(PanicStrategy::ALL.iter().map(PanicStrategy::desc_symbol));
378379

379380
ins!(sym::proc_macro, no_values);
380381

381-
ins!(sym::relocation_model, empty_values).extend(RelocModel::all());
382+
ins!(sym::relocation_model, empty_values)
383+
.extend(RelocModel::ALL.iter().map(RelocModel::desc_symbol));
382384

383385
let sanitize_values = SanitizerSet::all()
384386
.into_iter()

compiler/rustc_target/src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,31 @@ fn find_relative_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
7676
macro_rules! target_spec_enum {
7777
(
7878
$( #[$attr:meta] )*
79-
pub enum $name:ident {
79+
pub enum $Name:ident {
8080
$(
8181
$( #[$variant_attr:meta] )*
82-
$variant:ident = $string:literal,
82+
$Variant:ident = $string:literal,
8383
)*
8484
}
8585
parse_error_type = $parse_error_type:literal;
8686
) => {
8787
$( #[$attr] )*
8888
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
8989
#[derive(schemars::JsonSchema)]
90-
pub enum $name {
90+
pub enum $Name {
9191
$(
9292
$( #[$variant_attr] )*
9393
#[serde(rename = $string)] // for JSON schema generation only
94-
$variant,
94+
$Variant,
9595
)*
9696
}
9797

98-
impl FromStr for $name {
98+
impl FromStr for $Name {
9999
type Err = String;
100100

101101
fn from_str(s: &str) -> Result<Self, Self::Err> {
102102
Ok(match s {
103-
$( $string => Self::$variant, )*
103+
$( $string => Self::$Variant, )*
104104
_ => {
105105
let all = [$( concat!("'", $string, "'") ),*].join(", ");
106106
return Err(format!("invalid {}: '{s}'. allowed values: {all}", $parse_error_type));
@@ -109,24 +109,25 @@ macro_rules! target_spec_enum {
109109
}
110110
}
111111

112-
impl $name {
112+
impl $Name {
113+
pub const ALL: &'static [$Name] = &[ $( $Name::$Variant, )* ];
113114
pub fn desc(&self) -> &'static str {
114115
match self {
115-
$( Self::$variant => $string, )*
116+
$( Self::$Variant => $string, )*
116117
}
117118
}
118119
}
119120

120-
impl crate::json::ToJson for $name {
121+
impl crate::json::ToJson for $Name {
121122
fn to_json(&self) -> crate::json::Json {
122123
self.desc().to_json()
123124
}
124125
}
125126

126-
crate::json::serde_deserialize_from_str!($name);
127+
crate::json::serde_deserialize_from_str!($Name);
127128

128129

129-
impl std::fmt::Display for $name {
130+
impl std::fmt::Display for $Name {
130131
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
131132
f.write_str(self.desc())
132133
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,6 @@ impl PanicStrategy {
854854
PanicStrategy::Abort => sym::abort,
855855
}
856856
}
857-
858-
pub const fn all() -> [Symbol; 2] {
859-
[Self::Abort.desc_symbol(), Self::Unwind.desc_symbol()]
860-
}
861857
}
862858

863859
crate::target_spec_enum! {
@@ -974,18 +970,6 @@ impl RelocModel {
974970
RelocModel::RopiRwpi => sym::ropi_rwpi,
975971
}
976972
}
977-
978-
pub const fn all() -> [Symbol; 7] {
979-
[
980-
RelocModel::Static.desc_symbol(),
981-
RelocModel::Pic.desc_symbol(),
982-
RelocModel::Pie.desc_symbol(),
983-
RelocModel::DynamicNoPic.desc_symbol(),
984-
RelocModel::Ropi.desc_symbol(),
985-
RelocModel::Rwpi.desc_symbol(),
986-
RelocModel::RopiRwpi.desc_symbol(),
987-
]
988-
}
989973
}
990974

991975
crate::target_spec_enum! {

0 commit comments

Comments
 (0)