From aec911675788dff017429f616968bc12b5c88adf Mon Sep 17 00:00:00 2001 From: Slanterns Date: Wed, 14 Aug 2024 18:35:58 +0800 Subject: [PATCH 1/7] stabilize `option_get_or_insert_default` --- compiler/rustc_mir_transform/src/lib.rs | 1 - compiler/rustc_session/src/lib.rs | 1 - library/core/src/option.rs | 4 +--- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 1f214bc42cbe6..386c9e07efa40 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -9,7 +9,6 @@ #![feature(let_chains)] #![feature(map_try_insert)] #![feature(never_type)] -#![feature(option_get_or_insert_default)] #![feature(round_char_boundary)] #![feature(try_blocks)] #![feature(yeet_expr)] diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index d93b3eac08040..c3199043c1330 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -3,7 +3,6 @@ #![feature(iter_intersperse)] #![feature(let_chains)] #![feature(map_many_mut)] -#![feature(option_get_or_insert_default)] #![feature(rustc_attrs)] // tidy-alphabetical-end diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 6c89c81018038..69f0d716cc7b6 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1650,8 +1650,6 @@ impl Option { /// # Examples /// /// ``` - /// #![feature(option_get_or_insert_default)] - /// /// let mut x = None; /// /// { @@ -1664,7 +1662,7 @@ impl Option { /// assert_eq!(x, Some(7)); /// ``` #[inline] - #[unstable(feature = "option_get_or_insert_default", issue = "82901")] + #[stable(feature = "option_get_or_insert_default", since = "CURRENT_RUSTC_VERSION")] pub fn get_or_insert_default(&mut self) -> &mut T where T: Default, From d2c58ec6c4b23cbaa3b68ff3fb10853e6a59a45c Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 17 Sep 2024 07:53:19 +0300 Subject: [PATCH 2/7] delete sub directory "debug" to not delete the change-id file Signed-off-by: onur-ozkan --- src/bootstrap/bootstrap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 666df49012c13..04909cd792147 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -625,9 +625,9 @@ def download_toolchain(self): try: # FIXME: A cheap workaround for https://github.com/rust-lang/rust/issues/125578, # remove this once the issue is closed. - bootstrap_out = self.bootstrap_out() - if os.path.exists(bootstrap_out): - shutil.rmtree(bootstrap_out) + bootstrap_build_artifacts = os.path.join(self.bootstrap_out(), "debug") + if os.path.exists(bootstrap_build_artifacts): + shutil.rmtree(bootstrap_build_artifacts) p.map(unpack_component, tarballs_download_info) finally: From 36455c6f6b6e4e626bbcb0144dfac5ccfb30e5ba Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 26 Sep 2024 16:43:04 +0900 Subject: [PATCH 3/7] rustc_target: Add powerpc64 atomic-related features --- compiler/rustc_target/src/target_features.rs | 2 ++ tests/ui/check-cfg/mix.stderr | 2 +- tests/ui/check-cfg/well-known-values.stderr | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index b9e86269d4595..be14107baa97e 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -352,11 +352,13 @@ const HEXAGON_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ const POWERPC_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // tidy-alphabetical-start ("altivec", Unstable(sym::powerpc_target_feature), &[]), + ("partword-atomics", Unstable(sym::powerpc_target_feature), &[]), ("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]), ("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]), ("power8-vector", Unstable(sym::powerpc_target_feature), &["vsx", "power8-altivec"]), ("power9-altivec", Unstable(sym::powerpc_target_feature), &["power8-altivec"]), ("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]), + ("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]), ("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]), // tidy-alphabetical-end ]; diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr index a163728b51d1d..653c1c983e292 100644 --- a/tests/ui/check-cfg/mix.stderr +++ b/tests/ui/check-cfg/mix.stderr @@ -251,7 +251,7 @@ warning: unexpected `cfg` condition value: `zebra` LL | cfg!(target_feature = "zebra"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 239 more + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 241 more = note: see for more information about checking conditional configuration warning: 27 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 144a67025b308..14832e7ff4381 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -174,7 +174,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_feature = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `cssc`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `ecv`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `faminmax`, `fcma`, `fdivdu`, `fhm`, `flagm`, `flagm2`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fp8`, `fp8dot2`, `fp8dot4`, `fp8fma`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `hbc`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lse128`, `lse2`, `lsx`, `lut`, `lvz`, `lzcnt`, `m`, `mclass`, `mops`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rcpc3`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sha512`, `sign-ext`, `simd128`, `sm3`, `sm4`, `sme`, `sme-f16f16`, `sme-f64f64`, `sme-f8f16`, `sme-f8f32`, `sme-fa64`, `sme-i16i64`, `sme-lutv2`, `sme2`, `sme2p1`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `ssve-fp8dot2`, `ssve-fp8dot4`, `ssve-fp8fma`, `sve`, `sve-b16b16`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `sve2p1`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `v8.8a`, `v8.9a`, `v9.1a`, `v9.2a`, `v9.3a`, `v9.4a`, `v9.5a`, `v9a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `wfxt`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `cssc`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `ecv`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `faminmax`, `fcma`, `fdivdu`, `fhm`, `flagm`, `flagm2`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fp8`, `fp8dot2`, `fp8dot4`, `fp8fma`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `hbc`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lse128`, `lse2`, `lsx`, `lut`, `lvz`, `lzcnt`, `m`, `mclass`, `mops`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `partword-atomics`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `quadword-atomics`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rcpc3`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sha512`, `sign-ext`, `simd128`, `sm3`, `sm4`, `sme`, `sme-f16f16`, `sme-f64f64`, `sme-f8f16`, `sme-f8f32`, `sme-fa64`, `sme-i16i64`, `sme-lutv2`, `sme2`, `sme2p1`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `ssve-fp8dot2`, `ssve-fp8dot4`, `ssve-fp8fma`, `sve`, `sve-b16b16`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `sve2p1`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `v8.8a`, `v8.9a`, `v9.1a`, `v9.2a`, `v9.3a`, `v9.4a`, `v9.5a`, `v9a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `wfxt`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From fb10eeb42b0389961d12c432f476b63ea23851a9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 14 Sep 2024 21:17:50 +0200 Subject: [PATCH 4/7] Move Apple linker args from `rustc_target` to `rustc_codegen_ssa` They are dependent on the deployment target and SDK version, but having these in `rustc_target` makes it hard to introduce that dependency. --- compiler/rustc_codegen_ssa/src/back/link.rs | 133 +++++++++++++++++- .../rustc_target/src/spec/base/apple/mod.rs | 122 +--------------- 2 files changed, 134 insertions(+), 121 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 69693230ce070..80e8111516ee1 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -40,7 +40,7 @@ use rustc_target::spec::crt_objects::CrtObjects; use rustc_target::spec::{ Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, - SplitDebuginfo, + SplitDebuginfo, current_apple_deployment_target, }; use tempfile::Builder as TempFileBuilder; use tracing::{debug, info, warn}; @@ -2405,6 +2405,8 @@ fn add_order_independent_options( // Take care of the flavors and CLI options requesting the `lld` linker. add_lld_args(cmd, sess, flavor, self_contained_components); + add_apple_link_args(cmd, sess, flavor); + let apple_sdk_root = add_apple_sdk(cmd, sess, flavor); add_link_script(cmd, sess, tmpdir, crate_type); @@ -2957,6 +2959,135 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool } } +/// We need to communicate four things to the linker on Apple/Darwin targets: +/// - The architecture. +/// - The operating system (and that it's an Apple platform). +/// - The deployment target. +/// - The environment / ABI. +fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { + if !sess.target.is_like_osx { + return; + } + let LinkerFlavor::Darwin(cc, _) = flavor else { + return; + }; + + // `sess.target.arch` (`target_arch`) is not detailed enough. + let llvm_arch = sess.target.llvm_target.split_once('-').expect("LLVM target must have arch").0; + let target_os = &*sess.target.os; + let target_abi = &*sess.target.abi; + + // The architecture name to forward to the linker. + // + // Supported architecture names can be found in the source: + // https://github.com/apple-oss-distributions/ld64/blob/ld64-951.9/src/abstraction/MachOFileAbstraction.hpp#L578-L648 + // + // Intentially verbose to ensure that the list always matches correctly + // with the list in the source above. + let ld64_arch = match llvm_arch { + "armv7k" => "armv7k", + "armv7s" => "armv7s", + "arm64" => "arm64", + "arm64e" => "arm64e", + "arm64_32" => "arm64_32", + // ld64 doesn't understand i686, so fall back to i386 instead. + // + // Same story when linking with cc, since that ends up invoking ld64. + "i386" | "i686" => "i386", + "x86_64" => "x86_64", + "x86_64h" => "x86_64h", + _ => bug!("unsupported architecture in Apple target: {}", sess.target.llvm_target), + }; + + if cc == Cc::No { + // From the man page for ld64 (`man ld`): + // > The linker accepts universal (multiple-architecture) input files, + // > but always creates a "thin" (single-architecture), standard + // > Mach-O output file. The architecture for the output file is + // > specified using the -arch option. + // + // The linker has heuristics to determine the desired architecture, + // but to be safe, and to avoid a warning, we set the architecture + // explicitly. + cmd.link_args(&["-arch", ld64_arch]); + + // Man page says that ld64 supports the following platform names: + // > - macos + // > - ios + // > - tvos + // > - watchos + // > - bridgeos + // > - visionos + // > - xros + // > - mac-catalyst + // > - ios-simulator + // > - tvos-simulator + // > - watchos-simulator + // > - visionos-simulator + // > - xros-simulator + // > - driverkit + let platform_name = match (target_os, target_abi) { + (os, "") => os, + ("ios", "macabi") => "mac-catalyst", + ("ios", "sim") => "ios-simulator", + ("tvos", "sim") => "tvos-simulator", + ("watchos", "sim") => "watchos-simulator", + ("visionos", "sim") => "visionos-simulator", + _ => bug!("invalid OS/ABI combination for Apple target: {target_os}, {target_abi}"), + }; + + let (major, minor, patch) = current_apple_deployment_target(&sess.target); + let min_version = format!("{major}.{minor}.{patch}"); + + // Lie about the SDK version, we don't know it here + let sdk_version = &*min_version; + + // From the man page for ld64 (`man ld`): + // > This is set to indicate the platform, oldest supported version of + // > that platform that output is to be used on, and the SDK that the + // > output was built against. + // + // Like with `-arch`, the linker can figure out the platform versions + // itself from the binaries being linked, but to be safe, we specify + // the desired versions here explicitly. + cmd.link_args(&["-platform_version", platform_name, &*min_version, sdk_version]); + } else { + // cc == Cc::Yes + // We'd _like_ to use `-target` everywhere, since that can uniquely + // communicate all the required details, but that doesn't work on GCC, + // and since we don't know whether the `cc` compiler is Clang, GCC, or + // something else, we fall back to other options that also work on GCC + // when compiling for macOS. + // + // Targets other than macOS are ill-supported by GCC (it doesn't even + // support e.g. `-miphoneos-version-min`), so in those cases we can + // fairly safely use `-target`. See also the following, where it is + // made explicit that the recommendation by LLVM developers is to use + // `-target`: + if target_os == "macos" { + // `-arch` communicates the architecture. + // + // CC forwards the `-arch` to the linker, so we use the same value + // here intentionally. + cmd.cc_args(&["-arch", ld64_arch]); + + // The presence of `-mmacosx-version-min` makes CC default to + // macOS, and it sets the deployment target. + let (major, minor, patch) = current_apple_deployment_target(&sess.target); + // Intentionally pass this as a single argument, Clang doesn't + // seem to like it otherwise. + cmd.cc_arg(&format!("-mmacosx-version-min={major}.{minor}.{patch}")); + + // macOS has no environment, so with these two, we've told CC the + // four desired parameters. + // + // We avoid `-m32`/`-m64`, as this is already encoded by `-arch`. + } else { + cmd.cc_args(&["-target", &sess.target.llvm_target]); + } + } +} + fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option { let arch = &sess.target.arch; let os = &sess.target.os; diff --git a/compiler/rustc_target/src/spec/base/apple/mod.rs b/compiler/rustc_target/src/spec/base/apple/mod.rs index fdecd330c2d85..81b5a936d35ff 100644 --- a/compiler/rustc_target/src/spec/base/apple/mod.rs +++ b/compiler/rustc_target/src/spec/base/apple/mod.rs @@ -3,8 +3,8 @@ use std::env; use std::num::ParseIntError; use crate::spec::{ - Cc, DebuginfoKind, FramePointer, LinkArgs, LinkerFlavor, Lld, SplitDebuginfo, StackProbeType, - StaticCow, Target, TargetOptions, add_link_args, add_link_args_iter, cvs, + Cc, DebuginfoKind, FramePointer, LinkerFlavor, Lld, SplitDebuginfo, StackProbeType, StaticCow, + Target, TargetOptions, cvs, }; #[cfg(test)] @@ -40,25 +40,6 @@ impl Arch { } } - /// The architecture name to forward to the linker. - fn ld_arch(self) -> &'static str { - // Supported architecture names can be found in the source: - // https://github.com/apple-oss-distributions/ld64/blob/ld64-951.9/src/abstraction/MachOFileAbstraction.hpp#L578-L648 - match self { - Armv7k => "armv7k", - Armv7s => "armv7s", - Arm64 => "arm64", - Arm64e => "arm64e", - Arm64_32 => "arm64_32", - // ld64 doesn't understand i686, so fall back to i386 instead - // - // Same story when linking with cc, since that ends up invoking ld64. - I386 | I686 => "i386", - X86_64 => "x86_64", - X86_64h => "x86_64h", - } - } - pub(crate) fn target_arch(self) -> Cow<'static, str> { Cow::Borrowed(match self { Armv7k | Armv7s => "arm", @@ -116,104 +97,6 @@ impl TargetAbi { } } -fn pre_link_args(os: &'static str, arch: Arch, abi: TargetAbi) -> LinkArgs { - // From the man page for ld64 (`man ld`): - // > The linker accepts universal (multiple-architecture) input files, - // > but always creates a "thin" (single-architecture), standard Mach-O - // > output file. The architecture for the output file is specified using - // > the -arch option. - // - // The linker has heuristics to determine the desired architecture, but to - // be safe, and to avoid a warning, we set the architecture explicitly. - let mut args = - TargetOptions::link_args(LinkerFlavor::Darwin(Cc::No, Lld::No), &["-arch", arch.ld_arch()]); - - // From the man page for ld64 (`man ld`): - // > This is set to indicate the platform, oldest supported version of - // > that platform that output is to be used on, and the SDK that the - // > output was built against. platform [...] may be one of the following - // > strings: - // > - macos - // > - ios - // > - tvos - // > - watchos - // > - bridgeos - // > - visionos - // > - xros - // > - mac-catalyst - // > - ios-simulator - // > - tvos-simulator - // > - watchos-simulator - // > - visionos-simulator - // > - xros-simulator - // > - driverkit - // - // Like with `-arch`, the linker can figure out the platform versions - // itself from the binaries being linked, but to be safe, we specify the - // desired versions here explicitly. - let platform_name: StaticCow = match abi { - TargetAbi::Normal => os.into(), - TargetAbi::Simulator => format!("{os}-simulator").into(), - TargetAbi::MacCatalyst => "mac-catalyst".into(), - }; - let min_version: StaticCow = { - let (major, minor, patch) = deployment_target(os, arch, abi); - format!("{major}.{minor}.{patch}").into() - }; - // Lie about the SDK version, we don't know it here - let sdk_version = min_version.clone(); - add_link_args_iter( - &mut args, - LinkerFlavor::Darwin(Cc::No, Lld::No), - ["-platform_version".into(), platform_name, min_version, sdk_version].into_iter(), - ); - - // We need to communicate four things to the C compiler to be able to link: - // - The architecture. - // - The operating system (and that it's an Apple platform). - // - The deployment target. - // - The environment / ABI. - // - // We'd like to use `-target` everywhere, since that can uniquely - // communicate all of these, but that doesn't work on GCC, and since we - // don't know whether the `cc` compiler is Clang, GCC, or something else, - // we fall back to other options that also work on GCC when compiling for - // macOS. - // - // Targets other than macOS are ill-supported by GCC (it doesn't even - // support e.g. `-miphoneos-version-min`), so in those cases we can fairly - // safely use `-target`. See also the following, where it is made explicit - // that the recommendation by LLVM developers is to use `-target`: - // - if os == "macos" { - // `-arch` communicates the architecture. - // - // CC forwards the `-arch` to the linker, so we use the same value - // here intentionally. - add_link_args(&mut args, LinkerFlavor::Darwin(Cc::Yes, Lld::No), &[ - "-arch", - arch.ld_arch(), - ]); - // The presence of `-mmacosx-version-min` makes CC default to macOS, - // and it sets the deployment target. - let (major, minor, patch) = deployment_target(os, arch, abi); - let opt = format!("-mmacosx-version-min={major}.{minor}.{patch}").into(); - add_link_args_iter(&mut args, LinkerFlavor::Darwin(Cc::Yes, Lld::No), [opt].into_iter()); - // macOS has no environment, so with these two, we've told CC all the - // desired parameters. - // - // We avoid `-m32`/`-m64`, as this is already encoded by `-arch`. - } else { - add_link_args_iter( - &mut args, - LinkerFlavor::Darwin(Cc::Yes, Lld::No), - ["-target".into(), llvm_target(os, arch, abi)].into_iter(), - ); - } - - args -} - /// Get the base target options, LLVM target and `target_arch` from the three /// things that uniquely identify Rust's Apple targets: The OS, the /// architecture, and the ABI. @@ -232,7 +115,6 @@ pub(crate) fn base( // macOS has -dead_strip, which doesn't rely on function_sections function_sections: false, dynamic_linking: true, - pre_link_args: pre_link_args(os, arch, abi), families: cvs!["unix"], is_like_osx: true, // LLVM notes that macOS 10.11+ and iOS 9+ default From 4160a54dc5751d08dd23c7e5b0dc6cbc0889ce32 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 26 Sep 2024 20:33:26 -0700 Subject: [PATCH 5/7] Use `&raw` in the compiler Like #130865 did for the standard library, we can use `&raw` in the compiler now that stage0 supports it. Also like the other issue, I did not make any doc or test changes at this time. --- compiler/rustc_codegen_llvm/src/back/archive.rs | 2 +- compiler/rustc_codegen_llvm/src/lib.rs | 4 ++-- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_data_structures/src/sync.rs | 2 +- compiler/rustc_middle/src/query/on_disk_cache.rs | 4 ++-- compiler/rustc_middle/src/ty/list.rs | 10 +++++----- compiler/stable_mir/src/compiler_interface.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 1b4f6682af02d..33a956e552fbe 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -123,7 +123,7 @@ fn get_llvm_object_symbols( llvm::LLVMRustGetSymbols( buf.as_ptr(), buf.len(), - std::ptr::addr_of_mut!(*state) as *mut c_void, + (&raw mut *state) as *mut c_void, callback, error_callback, ) diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index bdfc0f626f801..b85d28a2f1f71 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -167,7 +167,7 @@ impl WriteBackendMethods for LlvmCodegenBackend { fn print_pass_timings(&self) { unsafe { let mut size = 0; - let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size)); + let cstr = llvm::LLVMRustPrintPassTimings(&raw mut size); if cstr.is_null() { println!("failed to get pass timings"); } else { @@ -180,7 +180,7 @@ impl WriteBackendMethods for LlvmCodegenBackend { fn print_statistics(&self) { unsafe { let mut size = 0; - let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size)); + let cstr = llvm::LLVMRustPrintStatistics(&raw mut size); if cstr.is_null() { println!("failed to get pass stats"); } else { diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 71fd7afb148c4..a2a5499597c34 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -478,7 +478,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) { &tm, cpu_cstring.as_ptr(), callback, - std::ptr::addr_of_mut!(out) as *mut c_void, + (&raw mut out) as *mut c_void, ); } } diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index 6df94bc0e9444..a3491dbfec7d4 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -437,7 +437,7 @@ impl RwLock { #[inline(always)] pub fn leak(&self) -> &T { let guard = self.read(); - let ret = unsafe { &*std::ptr::addr_of!(*guard) }; + let ret = unsafe { &*(&raw const *guard) }; std::mem::forget(guard); ret } diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 06c9ebc87b5ab..35a16684615d6 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -233,7 +233,7 @@ impl<'sess> OnDiskCache<'sess> { for (index, file) in files.iter().enumerate() { let index = SourceFileIndex(index as u32); - let file_ptr: *const SourceFile = std::ptr::addr_of!(**file); + let file_ptr: *const SourceFile = &raw const **file; file_to_file_index.insert(file_ptr, index); let source_file_id = EncodedSourceFileId::new(tcx, file); file_index_to_stable_id.insert(index, source_file_id); @@ -827,7 +827,7 @@ pub struct CacheEncoder<'a, 'tcx> { impl<'a, 'tcx> CacheEncoder<'a, 'tcx> { #[inline] fn source_file_index(&mut self, source_file: Lrc) -> SourceFileIndex { - self.file_to_file_index[&std::ptr::addr_of!(*source_file)] + self.file_to_file_index[&(&raw const *source_file)] } /// Encode something with additional information that allows to do some diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index ec9ca65dbda83..ea07cd3a1b9f3 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -103,13 +103,13 @@ impl RawList { let mem = arena.dropless.alloc_raw(layout) as *mut RawList; unsafe { // Write the header - ptr::addr_of_mut!((*mem).skel.header).write(header); + (&raw mut (*mem).skel.header).write(header); // Write the length - ptr::addr_of_mut!((*mem).skel.len).write(slice.len()); + (&raw mut (*mem).skel.len).write(slice.len()); // Write the elements - ptr::addr_of_mut!((*mem).skel.data) + (&raw mut (*mem).skel.data) .cast::() .copy_from_nonoverlapping(slice.as_ptr(), slice.len()); @@ -160,7 +160,7 @@ macro_rules! impl_list_empty { // SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all // types with `align_of(T) <= align_of(MaxAlign)`, which we checked above. - unsafe { &*(std::ptr::addr_of!(EMPTY) as *const RawList<$header_ty, T>) } + unsafe { &*((&raw const EMPTY) as *const RawList<$header_ty, T>) } } } }; @@ -238,7 +238,7 @@ impl Deref for RawList { impl AsRef<[T]> for RawList { #[inline(always)] fn as_ref(&self) -> &[T] { - let data_ptr = ptr::addr_of!(self.skel.data).cast::(); + let data_ptr = (&raw const self.skel.data).cast::(); // SAFETY: `data_ptr` has the same provenance as `self` and can therefore // access the `self.skel.len` elements stored at `self.skel.data`. // Note that we specifically don't reborrow `&self.skel.data`, because that diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index 9060a869f7fb1..4b7707ebccfed 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -255,7 +255,7 @@ where if TLV.is_set() { Err(Error::from("StableMIR already running")) } else { - let ptr: *const () = std::ptr::addr_of!(context) as _; + let ptr: *const () = (&raw const context) as _; TLV.set(&Cell::new(ptr), || Ok(f())) } } From 3dd583d5407c1d459c6539a4673e6d329903da66 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Fri, 27 Sep 2024 09:49:15 +0530 Subject: [PATCH 6/7] Fix error span when arg to asm!() is a macro call When the template string passed to asm!() is produced by a macro call like concat!() we were producing wrong error spans. Now in the case of a macro call we just use the entire arg to asm!(), macro call and all, as the error span. --- compiler/rustc_builtin_macros/src/asm.rs | 10 ++++++- tests/crashes/129503.rs | 7 ----- .../ice-bad-err-span-in-template-129503.rs | 26 +++++++++++++++++ ...ice-bad-err-span-in-template-129503.stderr | 28 +++++++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) delete mode 100644 tests/crashes/129503.rs create mode 100644 tests/ui/asm/ice-bad-err-span-in-template-129503.rs create mode 100644 tests/ui/asm/ice-bad-err-span-in-template-129503.stderr diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 0e1ec3b3cad1b..486d1dada84f1 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -507,6 +507,7 @@ fn expand_preparsed_asm( let msg = "asm template must be a string literal"; let template_sp = template_expr.span; + let template_is_mac_call = matches!(template_expr.kind, ast::ExprKind::MacCall(_)); let (template_str, template_style, template_span) = { let ExpandResult::Ready(mac) = expr_to_spanned_string(ecx, template_expr, msg) else { return ExpandResult::Retry(()); @@ -596,7 +597,14 @@ fn expand_preparsed_asm( if !parser.errors.is_empty() { let err = parser.errors.remove(0); - let err_sp = template_span.from_inner(InnerSpan::new(err.span.start, err.span.end)); + let err_sp = if template_is_mac_call { + // If the template is a macro call we can't reliably point to the error's + // span so just use the template's span as the error span (fixes #129503) + template_span + } else { + template_span.from_inner(InnerSpan::new(err.span.start, err.span.end)) + }; + let msg = format!("invalid asm template string: {}", err.description); let mut e = ecx.dcx().struct_span_err(err_sp, msg); e.span_label(err_sp, err.label + " in asm template string"); diff --git a/tests/crashes/129503.rs b/tests/crashes/129503.rs deleted file mode 100644 index c1ed46e595570..0000000000000 --- a/tests/crashes/129503.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ known-bug: rust-lang/rust#129503 - -use std::arch::asm; - -unsafe fn f6() { - asm!(concat!(r#"lJ𐏿Æ�.𐏿�"#, "r} {}")); -} diff --git a/tests/ui/asm/ice-bad-err-span-in-template-129503.rs b/tests/ui/asm/ice-bad-err-span-in-template-129503.rs new file mode 100644 index 0000000000000..3b4390f881a7e --- /dev/null +++ b/tests/ui/asm/ice-bad-err-span-in-template-129503.rs @@ -0,0 +1,26 @@ +// Regression test for ICE #129503 + + +// Tests that we come up with decent error spans +// when the template fed to `asm!()` is itself a +// macro call like `concat!()` and should not ICE + +use std::arch::asm; + +fn main() { + // Should not ICE + asm!(concat!(r#"lJ𐏿Æ�.𐏿�"#, "r} {}")); + //~^ ERROR invalid asm template string: unmatched `}` found + + + // Macro call template: should point to + // everything within `asm!()` as error span + asm!(concat!("abc", "r} {}")); + //~^ ERROR invalid asm template string: unmatched `}` found + + + // Literal template: should point precisely to + // just the `}` as error span + asm!("abc", "r} {}"); + //~^ ERROR invalid asm template string: unmatched `}` found +} diff --git a/tests/ui/asm/ice-bad-err-span-in-template-129503.stderr b/tests/ui/asm/ice-bad-err-span-in-template-129503.stderr new file mode 100644 index 0000000000000..ffa9362ed9538 --- /dev/null +++ b/tests/ui/asm/ice-bad-err-span-in-template-129503.stderr @@ -0,0 +1,28 @@ +error: invalid asm template string: unmatched `}` found + --> $DIR/ice-bad-err-span-in-template-129503.rs:12:10 + | +LL | asm!(concat!(r#"lJ𐏿Æ�.𐏿�"#, "r} {}")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` in asm template string + | + = note: if you intended to print `}`, you can escape it using `}}` + = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: invalid asm template string: unmatched `}` found + --> $DIR/ice-bad-err-span-in-template-129503.rs:18:10 + | +LL | asm!(concat!("abc", "r} {}")); + | ^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` in asm template string + | + = note: if you intended to print `}`, you can escape it using `}}` + = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: invalid asm template string: unmatched `}` found + --> $DIR/ice-bad-err-span-in-template-129503.rs:24:19 + | +LL | asm!("abc", "r} {}"); + | ^ unmatched `}` in asm template string + | + = note: if you intended to print `}`, you can escape it using `}}` + +error: aborting due to 3 previous errors + From 9766192545190027b3c087f78cdc7dc5a51f0204 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 27 Sep 2024 13:48:11 +0200 Subject: [PATCH 7/7] update outdated comments --- compiler/rustc_type_ir/src/predicate.rs | 4 ++-- compiler/rustc_type_ir/src/predicate_kind.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 7e300fe02dca4..76065c10d190e 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -668,8 +668,8 @@ impl fmt::Debug for ProjectionPredicate { } } -/// Used by the new solver. Unlike a `ProjectionPredicate` this can only be -/// proven by actually normalizing `alias`. +/// Used by the new solver to normalize an alias. This always expects the `term` to +/// be an unconstrained inference variable which is used as the output. #[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index c8a2102858832..55015e6e20232 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -74,13 +74,13 @@ pub enum PredicateKind { Ambiguous, /// This should only be used inside of the new solver for `AliasRelate` and expects - /// the `term` to be an unconstrained inference variable. + /// the `term` to be always be an unconstrained inference variable. It is used to + /// normalize `alias` as much as possible. In case the alias is rigid - i.e. it cannot + /// be normalized in the current environment - this constrains `term` to be equal to + /// the alias itself. /// - /// The alias normalizes to `term`. Unlike `Projection`, this always fails if the - /// alias cannot be normalized in the current context. For the rigid alias - /// `T as Trait>::Assoc`, `Projection(::Assoc, ?x)` constrains `?x` - /// to `::Assoc` while `NormalizesTo(::Assoc, ?x)` - /// results in `NoSolution`. + /// It is likely more useful to think of this as a function `normalizes_to(alias)`, + /// whose return value is written into `term`. NormalizesTo(ty::NormalizesTo), /// Separate from `ClauseKind::Projection` which is used for normalization in new solver.