Skip to content

Commit

Permalink
Release 0.9.0-alpha.0 (#1881)
Browse files Browse the repository at this point in the history
Upgrade our MSRV to 1.65 and remove version detection logic prior to
that version.
  • Loading branch information
joshlf authored Oct 12, 2024
1 parent 5b5d5a6 commit e7217b5
Show file tree
Hide file tree
Showing 81 changed files with 1,266 additions and 839 deletions.
64 changes: 0 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ jobs:
# which a particular feature is supported.
"zerocopy-core-error",
"zerocopy-diagnostic-on-unimplemented",
"zerocopy-generic-bounds-in-const-fn",
"zerocopy-target-has-atomics",
"zerocopy-aarch64-simd",
"zerocopy-panic-in-const-and-vec-try-reserve"
]
target: [
"i686-unknown-linux-gnu",
Expand Down Expand Up @@ -89,14 +85,6 @@ jobs:
features: "--all-features"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
features: "--all-features"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
features: "--all-features"
- toolchain: "zerocopy-target-has-atomics"
features: "--all-features"
- toolchain: "zerocopy-aarch64-simd"
features: "--all-features"
- toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
features: "--all-features"
# Exclude any combination for the zerocopy-derive crate which
# uses zerocopy features.
- crate: "zerocopy-derive"
Expand All @@ -113,36 +101,6 @@ jobs:
toolchain: "zerocopy-core-error"
- crate: "zerocopy-derive"
toolchain: "zerocopy-diagnostic-on-unimplemented"
- crate: "zerocopy-derive"
toolchain: "zerocopy-generic-bounds-in-const-fn"
- crate: "zerocopy-derive"
toolchain: "zerocopy-target-has-atomics"
- crate: "zerocopy-derive"
toolchain: "zerocopy-aarch64-simd"
- crate: "zerocopy-derive"
toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
# Exclude non-aarch64 targets from the `zerocopy-aarch64-simd`
# toolchain.
- toolchain: "zerocopy-aarch64-simd"
target: "i686-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-aarch64-simd"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-aarch64-simd"
target: "wasm32-wasi"
# Exclude most targets targets from the `zerocopy-core-error`
# toolchain since the `zerocopy-core-error` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
Expand Down Expand Up @@ -186,28 +144,6 @@ jobs:
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
target: "wasm32-wasi"
# Exclude most targets targets from the
# `zerocopy-generic-bounds-in-const-fn` toolchain since the
# `zerocopy-generic-bounds-in-const-fn` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "aarch64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "wasm32-wasi"
# Exclude `thumbv6m-none-eabi` combined with any feature that implies
# the `std` feature since `thumbv6m-none-eabi` does not include a
# pre-compiled std.
Expand Down
25 changes: 5 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
[package]
edition = "2021"
name = "zerocopy"
version = "0.8.5"
version = "0.9.0-alpha.0"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
categories = ["embedded", "encoding", "no-std::no-alloc", "parsing", "rust-patterns"]
keywords = ["cast", "convert", "transmute", "transmutation", "type-punning"]
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/google/zerocopy"
rust-version = "1.56.0"
rust-version = "1.65.0"

exclude = [".*"]

Expand All @@ -38,21 +38,6 @@ zerocopy-core-error = "1.81.0"
# From 1.78.0, Rust supports the `#[diagnostic::on_unimplemented]` attribute.
zerocopy-diagnostic-on-unimplemented = "1.78.0"

# From 1.61.0, Rust supports generic types with trait bounds in `const fn`.
zerocopy-generic-bounds-in-const-fn = "1.61.0"

# From 1.60.0, Rust supports `cfg(target_has_atomics)`, which allows us to
# detect whether a target supports particular sets of atomics.
zerocopy-target-has-atomics = "1.60.0"

# When the "simd" feature is enabled, include SIMD types from the
# `core::arch::aarch64` module, which was stabilized in 1.59.0. On earlier Rust
# versions, these types require the "simd-nightly" feature.
zerocopy-aarch64-simd = "1.59.0"

# Permit panicking in `const fn`s and calling `Vec::try_reserve`.
zerocopy-panic-in-const-and-vec-try-reserve = "1.57.0"

[package.metadata.ci]
# The versions of the stable and nightly compiler toolchains to use in CI.
pinned-stable = "1.81.0"
Expand All @@ -77,13 +62,13 @@ std = ["alloc"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd", "std"]

[dependencies]
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }

[dev-dependencies]
itertools = "0.11"
Expand All @@ -97,6 +82,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
58 changes: 27 additions & 31 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,33 +539,29 @@ example of how it can be used for parsing UDP packets.
}

impl<O: ByteOrder> $name<O> {
maybe_const_trait_bounded_fn! {
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};

$name(bytes, PhantomData)
}
$name(bytes, PhantomData)
}

maybe_const_trait_bounded_fn! {
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
}

Expand Down Expand Up @@ -1057,8 +1053,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.is_nan()).then(|| self);
let other = (!other.is_nan()).then(|| other);
let slf = (!self.is_nan()).then_some(self);
let other = (!other.is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1088,8 +1084,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.get().is_nan()).then(|| self);
let other = (!other.get().is_nan()).then(|| other);
let slf = (!self.get().is_nan()).then_some(self);
let other = (!other.get().is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1396,11 +1392,11 @@ mod tests {
// For `f32` and `f64`, NaN values are not considered equal to
// themselves. We store `Option<f32>`/`Option<f64>` and store
// NaN as `None` so they can still be compared.
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then(|| t.get());
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then_some(t.get());
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = val_or_none(n_t_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then(|| n_n_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then_some(n_n_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand All @@ -1418,7 +1414,7 @@ mod tests {
// NaN as `None` so they can still be compared.
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then(|| n_t_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then_some(n_t_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand Down
18 changes: 7 additions & 11 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,12 @@ safety_comment! {
unsafe_impl_for_power_set!(A, B, C, D, E, F, G, H, I, J, K, L -> M => Immutable for opt_extern_c_fn!(...));
}

#[cfg(all(
zerocopy_target_has_atomics,
any(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
)
#[cfg(any(
target_has_atomic = "8",
target_has_atomic = "16",
target_has_atomic = "32",
target_has_atomic = "64",
target_has_atomic = "ptr"
))]
mod atomics {
use super::*;
Expand Down Expand Up @@ -933,7 +930,6 @@ mod simd {
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc64"))]
powerpc64, powerpc64, vector_bool_long, vector_double, vector_signed_long, vector_unsigned_long
);
#[cfg(zerocopy_aarch64_simd)]
simd_arch_mod!(
// NOTE(https://github.com/rust-lang/stdarch/issues/1484): NEON intrinsics are currently
// broken on big-endian platforms.
Expand Down Expand Up @@ -1882,7 +1878,7 @@ mod tests {
vector_signed_long,
vector_unsigned_long
);
#[cfg(all(target_arch = "aarch64", zerocopy_aarch64_simd))]
#[cfg(target_arch = "aarch64")]
#[rustfmt::skip]
test_simd_arch_mod!(
aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
Expand Down
Loading

0 comments on commit e7217b5

Please sign in to comment.