From 61fe79f627779b9181091065cff2b8d0eb136970 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 18 Jun 2022 04:01:02 +0900 Subject: [PATCH] Remove use of feature(integer_atomics) Fixes subtle behavior differences between stable and nightly. --- build.rs | 38 ++++++++++---------------------------- no_atomic.rs | 26 -------------------------- src/imp/core_atomic.rs | 2 -- src/imp/mod.rs | 22 ++-------------------- src/lib.rs | 20 ++------------------ tools/no_atomic.sh | 12 +----------- 6 files changed, 15 insertions(+), 105 deletions(-) diff --git a/build.rs b/build.rs index 718691f19..4fe30cfce 100644 --- a/build.rs +++ b/build.rs @@ -19,15 +19,6 @@ const LATEST_STABLE: Version = // Probe if unstable features can be compiled with the expected API. // This prevents accidental depends on them if the upstream changes its API. // This is the same approach used in autocfg, anyhow, etc. -// for aarch64 and x86_64 macos -const PROBE_ATOMIC_128: &str = r#" -#![no_std] -#![feature(integer_atomics)] -fn _probe() { - let v = core::sync::atomic::AtomicU128::new(0_u128); - let _: u128 = v.swap(1_u128, core::sync::atomic::Ordering::Relaxed); -} -"#; // for x86_64 const PROBE_CMPXCHG16B: &str = r#" #![no_std] @@ -172,11 +163,8 @@ fn main() { println!("cargo:rustc-cfg=portable_atomic_armv5te"); } - let aarch64 = target.starts_with("aarch64"); - let x86_64 = target.starts_with("x86_64"); - // aarch64 macos always support lse and lse2 because it is armv8.6: /~https://github.com/rust-lang/rust/blob/1.61.0/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs#L5 - if aarch64 && (version.minor >= 59 || version.nightly) { + if target.starts_with("aarch64") && (version.minor >= 59 || version.nightly) { // aarch64_target_feature stabilized in Rust 1.61. if has_target_feature("lse", target == "aarch64-apple-darwin", &version, Some(61), true) { println!("cargo:rustc-cfg=portable_atomic_target_feature=\"lse\""); @@ -189,7 +177,8 @@ fn main() { } // cmpxchg16b is available via asm (1.59+) or stdsimd (nightly). - let may_use_cmpxchg16b = x86_64 && (version.minor >= 59 || version.nightly); + let may_use_cmpxchg16b = + target.starts_with("x86_64") && (version.minor >= 59 || version.nightly); let mut has_cmpxchg16b = false; if may_use_cmpxchg16b { // x86_64 macos always support cmpxchg16b: /~https://github.com/rust-lang/rust/blob/1.61.0/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs#L7 @@ -209,20 +198,13 @@ fn main() { println!("cargo:rustc-cfg=sanitize_thread"); } - if aarch64 || x86_64 { - if HAS_ATOMIC_128.contains(&&*target) - && probe(PROBE_ATOMIC_128, &target).unwrap_or(false) - { - println!("cargo:rustc-cfg=portable_atomic_core_atomic_128"); - } else if may_use_cmpxchg16b - && (has_cmpxchg16b - || cfg!(feature = "fallback") && cfg!(feature = "outline-atomics")) - && probe(PROBE_CMPXCHG16B, &target).unwrap_or(false) - { - println!("cargo:rustc-cfg=portable_atomic_cmpxchg16b_stdsimd"); - if cfg!(feature = "fallback") && cfg!(feature = "outline-atomics") { - println!("cargo:rustc-cfg=portable_atomic_cmpxchg16b_dynamic"); - } + if may_use_cmpxchg16b + && (has_cmpxchg16b || cfg!(feature = "fallback") && cfg!(feature = "outline-atomics")) + && probe(PROBE_CMPXCHG16B, &target).unwrap_or(false) + { + println!("cargo:rustc-cfg=portable_atomic_cmpxchg16b_stdsimd"); + if cfg!(feature = "fallback") && cfg!(feature = "outline-atomics") { + println!("cargo:rustc-cfg=portable_atomic_cmpxchg16b_dynamic"); } } else if target.starts_with("s390x") && probe(PROBE_ATOMIC_INTRINSICS, &target).unwrap_or(false) diff --git a/no_atomic.rs b/no_atomic.rs index dc9774c97..3cdfa00f9 100644 --- a/no_atomic.rs +++ b/no_atomic.rs @@ -70,29 +70,3 @@ const NO_ATOMIC: &[&str] = &[ "riscv32im-unknown-none-elf", "riscv32imc-unknown-none-elf", ]; - -const HAS_ATOMIC_128: &[&str] = &[ - "aarch64-apple-darwin", - "aarch64-apple-ios", - "aarch64-apple-ios-macabi", - "aarch64-apple-ios-sim", - "aarch64-apple-tvos", - "aarch64-apple-watchos-sim", - "aarch64-fuchsia", - "aarch64-kmc-solid_asp3", - "aarch64-linux-android", - "aarch64-unknown-freebsd", - "aarch64-unknown-hermit", - "aarch64-unknown-linux-gnu", - "aarch64-unknown-linux-gnu_ilp32", - "aarch64-unknown-linux-musl", - "aarch64-unknown-netbsd", - "aarch64-unknown-none", - "aarch64-unknown-none-softfloat", - "aarch64-unknown-openbsd", - "aarch64-unknown-redox", - "aarch64-wrs-vxworks", - "aarch64_be-unknown-linux-gnu", - "aarch64_be-unknown-linux-gnu_ilp32", - "x86_64-apple-darwin", -]; diff --git a/src/imp/core_atomic.rs b/src/imp/core_atomic.rs index b1f4c22da..e3e18c911 100644 --- a/src/imp/core_atomic.rs +++ b/src/imp/core_atomic.rs @@ -32,5 +32,3 @@ atomic!(AtomicI32, AtomicU32); cfg(any(target_has_atomic = "64", target_pointer_width = "64")) // cfg(target_has_atomic_load_store = "64") )] atomic!(AtomicI64, AtomicU64); -#[cfg(portable_atomic_core_atomic_128)] -atomic!(AtomicI128, AtomicU128); diff --git a/src/imp/mod.rs b/src/imp/mod.rs index 7dbb15389..dc00aa01f 100644 --- a/src/imp/mod.rs +++ b/src/imp/mod.rs @@ -5,13 +5,11 @@ #[cfg(not(portable_atomic_no_atomic_load_store))] mod core_atomic; -#[cfg(any(test, not(portable_atomic_core_atomic_128)))] #[cfg(any(not(portable_atomic_no_asm), portable_atomic_nightly))] #[cfg(target_arch = "aarch64")] #[path = "atomic128/aarch64.rs"] mod aarch64; -#[cfg(any(test, not(portable_atomic_core_atomic_128)))] #[cfg(any(not(portable_atomic_no_asm), portable_atomic_nightly))] #[cfg(any( target_feature = "cmpxchg16b", @@ -51,15 +49,9 @@ mod riscv; #[cfg(any( test, not(any( - portable_atomic_core_atomic_128, portable_atomic_s390x_atomic_128, + all(any(not(portable_atomic_no_asm), portable_atomic_nightly), target_arch = "aarch64"), all( - not(portable_atomic_core_atomic_128), - any(not(portable_atomic_no_asm), portable_atomic_nightly), - target_arch = "aarch64" - ), - all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), any(target_feature = "cmpxchg16b", portable_atomic_target_feature = "cmpxchg16b"), target_arch = "x86_64", @@ -206,18 +198,14 @@ pub(crate) use self::fallback::{AtomicI64, AtomicU64}; pub(crate) use self::interrupt::{AtomicI64, AtomicU64}; // Atomic{I,U}128 -#[cfg(portable_atomic_core_atomic_128)] -pub(crate) use self::core_atomic::{AtomicI128, AtomicU128}; // aarch64 stable #[cfg(all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), target_arch = "aarch64" ))] pub(crate) use self::aarch64::{AtomicI128, AtomicU128}; // no core Atomic{I,U}128 & has cmpxchg16b => use cmpxchg16b #[cfg(all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), any( target_feature = "cmpxchg16b", @@ -238,15 +226,9 @@ pub(crate) use self::s390x::{AtomicI128, AtomicU128}; // no core Atomic{I,U}128 & has CAS => use lock-base fallback #[cfg(feature = "fallback")] #[cfg(not(any( - portable_atomic_core_atomic_128, portable_atomic_s390x_atomic_128, + all(any(not(portable_atomic_no_asm), portable_atomic_nightly), target_arch = "aarch64"), all( - not(portable_atomic_core_atomic_128), - any(not(portable_atomic_no_asm), portable_atomic_nightly), - target_arch = "aarch64" - ), - all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), any( target_feature = "cmpxchg16b", diff --git a/src/lib.rs b/src/lib.rs index 5c9cf4b68..d64cbe4ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,10 +108,6 @@ On x86_64, when the `outline-atomics` optional feature is not enabled and `cmpxc clippy::type_complexity )] // 128-bit atomic -#![cfg_attr( - any(all(test, portable_atomic_nightly), portable_atomic_core_atomic_128), - feature(integer_atomics) -)] #![cfg_attr( all( target_arch = "x86_64", @@ -2036,15 +2032,9 @@ atomic_int!(AtomicU64, u64, 8); #[cfg_attr( not(feature = "fallback"), cfg(any( - portable_atomic_core_atomic_128, portable_atomic_s390x_atomic_128, + all(any(not(portable_atomic_no_asm), portable_atomic_nightly), target_arch = "aarch64"), all( - not(portable_atomic_core_atomic_128), - any(not(portable_atomic_no_asm), portable_atomic_nightly), - target_arch = "aarch64" - ), - all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), any( target_feature = "cmpxchg16b", @@ -2072,15 +2062,9 @@ atomic_int!(AtomicI128, i128, 16); #[cfg_attr( not(feature = "fallback"), cfg(any( - portable_atomic_core_atomic_128, portable_atomic_s390x_atomic_128, + all(any(not(portable_atomic_no_asm), portable_atomic_nightly), target_arch = "aarch64"), all( - not(portable_atomic_core_atomic_128), - any(not(portable_atomic_no_asm), portable_atomic_nightly), - target_arch = "aarch64" - ), - all( - not(portable_atomic_core_atomic_128), any(not(portable_atomic_no_asm), portable_atomic_nightly), any( target_feature = "cmpxchg16b", diff --git a/tools/no_atomic.sh b/tools/no_atomic.sh index 3237edf43..bd7b894b7 100755 --- a/tools/no_atomic.sh +++ b/tools/no_atomic.sh @@ -13,7 +13,6 @@ file="no_atomic.rs" no_atomic_cas=() no_atomic_64=() no_atomic=() -has_atomic_128=() for target in $(rustc --print target-list); do target_spec=$(rustc --print target-spec-json -Z unstable-options --target "${target}") res=$(jq <<<"${target_spec}" -r 'select(."atomic-cas" == false)') @@ -32,8 +31,7 @@ for target in $(rustc --print target-list); do no_atomic_64+=("${target}") no_atomic+=("${target}") ;; - 64) ;; - 128) has_atomic_128+=("${target}") ;; + 64 | 128) ;; # There is no `"max-atomic-width" == 16` or `"max-atomic-width" == 8` targets. *) echo "${target}" && exit 1 ;; esac @@ -66,12 +64,4 @@ for target in "${no_atomic[@]}"; do done cat >>"${file}" <>"${file}" -done -cat >>"${file}" <