Skip to content

Commit 33eb3c0

Browse files
authored
Rollup merge of #98214 - petrochenkov:islike, r=compiler-errors
rustc_target: Remove some redundant target properties `is_like_emscripten` is equivalent to `os == "emscripten"`, so it's removed. `is_like_fuchsia` is equivalent to `os == "fuchsia"`, so it's removed. `is_like_osx` also falls into the same category and is equivalent to `vendor == "apple"`, but it's commonly used so I kept it as is for now. `is_like_(solaris,windows,wasm)` are combinations of different operating systems or architectures (see compiler/rustc_target/src/spec/tests/tests_impl.rs) so they are also kept as is. I think `is_like_wasm` (and maybe `is_like_osx`) are sufficiently closed sets, so we can remove these fields as well and replace them with methods like `fn is_like_wasm() { arch == "wasm32" || arch == "wasm64" }`. On other hand, `is_like_solaris` and `is_like_windows` are sufficiently open and I can imagine custom targets introducing other values for `os`. This is kind of a gray area.
2 parents 6580d7e + 37fd294 commit 33eb3c0

File tree

9 files changed

+11
-20
lines changed

9 files changed

+11
-20
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl<'ll> CodegenCx<'ll, '_> {
906906
return eh_catch_typeinfo;
907907
}
908908
let tcx = self.tcx;
909-
assert!(self.sess().target.is_like_emscripten);
909+
assert!(self.sess().target.os == "emscripten");
910910
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
911911
Some(def_id) => self.get_static(def_id),
912912
_ => {

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn try_intrinsic<'ll>(
441441
bx.store(bx.const_i32(0), dest, ret_align);
442442
} else if wants_msvc_seh(bx.sess()) {
443443
codegen_msvc_try(bx, try_func, data, catch_func, dest);
444-
} else if bx.sess().target.is_like_emscripten {
444+
} else if bx.sess().target.os == "emscripten" {
445445
codegen_emcc_try(bx, try_func, data, catch_func, dest);
446446
} else {
447447
codegen_gnu_try(bx, try_func, data, catch_func, dest);

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ fn add_order_independent_options(
20312031

20322032
add_link_script(cmd, sess, tmpdir, crate_type);
20332033

2034-
if sess.target.is_like_fuchsia && crate_type == CrateType::Executable {
2034+
if sess.target.os == "fuchsia" && crate_type == CrateType::Executable {
20352035
let prefix = if sess.opts.debugging_opts.sanitizer.contains(SanitizerSet::ADDRESS) {
20362036
"asan/"
20372037
} else {
@@ -2051,7 +2051,7 @@ fn add_order_independent_options(
20512051
cmd.no_crt_objects();
20522052
}
20532053

2054-
if sess.target.is_like_emscripten {
2054+
if sess.target.os == "emscripten" {
20552055
cmd.arg("-s");
20562056
cmd.arg(if sess.panic_strategy() == PanicStrategy::Abort {
20572057
"DISABLE_EXCEPTION_CATCHING=1"

compiler/rustc_passes/src/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
1717
if items.eh_personality().is_none() {
1818
items.missing.push(LangItem::EhPersonality);
1919
}
20-
if tcx.sess.target.is_like_emscripten && items.eh_catch_typeinfo().is_none() {
20+
if tcx.sess.target.os == "emscripten" && items.eh_catch_typeinfo().is_none() {
2121
items.missing.push(LangItem::EhCatchTypeinfo);
2222
}
2323

compiler/rustc_target/src/asm/aarch64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl AArch64InlineAsmRegClass {
7474
}
7575

7676
pub fn target_reserves_x18(target: &Target) -> bool {
77-
target.os == "android" || target.is_like_fuchsia || target.is_like_osx || target.is_like_windows
77+
target.os == "android" || target.os == "fuchsia" || target.is_like_osx || target.is_like_windows
7878
}
7979

8080
fn reserved_x18(

compiler/rustc_target/src/spec/fuchsia_base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub fn opts() -> TargetOptions {
2828
dynamic_linking: true,
2929
executables: true,
3030
families: cvs!["unix"],
31-
is_like_fuchsia: true,
3231
pre_link_args,
3332
pre_link_objects: crt_objects::new(&[
3433
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),

compiler/rustc_target/src/spec/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,6 @@ pub struct TargetOptions {
12731273
/// - uses SEH-based unwinding,
12741274
/// - supports control flow guard mechanism.
12751275
pub is_like_msvc: bool,
1276-
/// Whether the target toolchain is like Emscripten's. Only useful for compiling with
1277-
/// Emscripten toolchain.
1278-
/// Defaults to false.
1279-
pub is_like_emscripten: bool,
1280-
/// Whether the target toolchain is like Fuchsia's.
1281-
pub is_like_fuchsia: bool,
12821276
/// Whether a target toolchain is like WASM.
12831277
pub is_like_wasm: bool,
12841278
/// Version of DWARF to use if not using the default.
@@ -1505,9 +1499,7 @@ impl Default for TargetOptions {
15051499
is_like_osx: false,
15061500
is_like_solaris: false,
15071501
is_like_windows: false,
1508-
is_like_emscripten: false,
15091502
is_like_msvc: false,
1510-
is_like_fuchsia: false,
15111503
is_like_wasm: false,
15121504
dwarf_version: None,
15131505
linker_is_gnu: true,
@@ -2112,8 +2104,6 @@ impl Target {
21122104
key!(is_like_solaris, bool);
21132105
key!(is_like_windows, bool);
21142106
key!(is_like_msvc, bool);
2115-
key!(is_like_emscripten, bool);
2116-
key!(is_like_fuchsia, bool);
21172107
key!(is_like_wasm, bool);
21182108
key!(dwarf_version, Option<u32>);
21192109
key!(linker_is_gnu, bool);
@@ -2358,8 +2348,6 @@ impl ToJson for Target {
23582348
target_option_val!(is_like_solaris);
23592349
target_option_val!(is_like_windows);
23602350
target_option_val!(is_like_msvc);
2361-
target_option_val!(is_like_emscripten);
2362-
target_option_val!(is_like_fuchsia);
23632351
target_option_val!(is_like_wasm);
23642352
target_option_val!(dwarf_version);
23652353
target_option_val!(linker_is_gnu);

compiler/rustc_target/src/spec/tests/tests_impl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ pub(super) fn test_target(target: Target) {
88

99
impl Target {
1010
fn check_consistency(&self) {
11+
assert_eq!(self.is_like_osx, self.vendor == "apple");
12+
assert_eq!(self.is_like_solaris, self.os == "solaris" || self.os == "illumos");
13+
assert_eq!(self.is_like_windows, self.os == "windows" || self.os == "uefi");
14+
assert_eq!(self.is_like_wasm, self.arch == "wasm32" || self.arch == "wasm64");
1115
assert!(self.is_like_windows || !self.is_like_msvc);
16+
1217
// Check that LLD with the given flavor is treated identically to the linker it emulates.
1318
// If your target really needs to deviate from the rules below, except it and document the
1419
// reasons.

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub fn target() -> Target {
2626
// functionality, and a .wasm file.
2727
exe_suffix: ".js".into(),
2828
linker: None,
29-
is_like_emscripten: true,
3029
panic_strategy: PanicStrategy::Unwind,
3130
no_default_libraries: false,
3231
post_link_args,

0 commit comments

Comments
 (0)