Commit Graph

407 Commits

Author SHA1 Message Date
MaulingMonkey
8f130f2b79
must_cast (#187) 2023-06-06 15:50:39 -06:00
Daniel Henry-Mantilla
e528c1662f
Add missing ?Sized for TransparentWrapperAlloc extension trait (#185)
* Add missing `?Sized` for `TransparentWrapperAlloc` extension trait

* chore: Release bytemuck version 1.13.2
2023-06-06 15:48:41 -06:00
Charles Lew
df5262b19c
Add #[doc(hidden)] on derive generated items. (#189) 2023-05-31 08:46:00 -06:00
C. K. Young
8391afa876
Make AnyBitPattern derive work for generic structs (#101)
* Allow generic structs to use `AnyBitPattern` derive.

* Attempt to nudge the CI into retrying.
2023-03-23 18:22:56 -06:00
Lokathor
b41f4cc1af chore: Release bytemuck_derive version 1.4.1 2023-03-23 15:40:54 -06:00
Lokathor
12c9871a71 changelog 2023-03-23 15:21:33 -06:00
Christopher Serr
b97dee7f90
Switch to syn 2.0 (#183)
This upgrades the derives from `syn` 1.0 to `syn` 2.0. While the MSRV
for `syn` 2.0 is not Rust 1.56 which is higher than the MSRV of
`bytemuck`, the derives don't fall under the MSRV policy.
2023-03-21 13:52:18 -06:00
Lokathor
b19f8abfe3 chore: Release bytemuck version 1.13.1 2023-02-28 13:40:46 -07:00
Lokathor
01011f76a8 update changelog. 2023-02-28 13:40:17 -07:00
Lokathor
1b1b9a0e89
Fix 177 (#178)
* reduce required bounds.

* clippy get off my case

* spelling

* clippy lints on tests.
2023-02-28 13:29:34 -07:00
zachs18
1039388f0b
Fix soundness issue of TransparentWrapper derive macro. (#173)
Uses the compiler to check that all non-wrapped fields are actually 1-ZSTs,
and uses Zeroable to check that all non-wrapped fields are "conjurable".

Additionally, relaxes the bound of `PhantomData<T: Zeroable>: Zeroable` to all `T: ?Sized`.
2023-02-17 12:24:16 -07:00
Dirk Stolle
d1655f541b
Fix a few typos (#169) 2023-01-29 16:41:40 -07:00
Tom Dohrmann
2d1f876216
various small fixes to the derive macros (#168)
* parse `repr(usize)` and `repr(isize)`

This can be used with enums.

* emit packed repr without type suffix

Previously we emitted the packed attribute with a type suffix for the
value `packed(4u32)`. This is not allowed. Instead we should emit
`packed(4)`.

* read bits instead of creating reference

This is required for packed structs where creating a reference to
fields is not allowed. We can make a copy of the bits because the bits
are `AnyBitPattern` which implies `Copy`.

* emit generics on implied traits
2023-01-25 21:49:46 -07:00
Lokathor
49c23727fa (cargo-release) version 1.13.0 2023-01-19 23:05:43 -07:00
Lokathor
0e65f1e64d bump bytemuck_derive min version. 2023-01-19 22:58:28 -07:00
Lokathor
2bcc0ef6de chore: Release bytemuck_derive version 1.4.0 2023-01-19 17:45:46 -07:00
Lokathor
28d3aa7ba9 changelog 2023-01-19 17:44:21 -07:00
Lokathor
cb5caf7bf8 (cargo-release) version 1.12.4 2023-01-19 13:48:06 -07:00
Lokathor
a8d44503f5 changelog 2023-01-19 13:41:17 -07:00
Alphyr
fa5e5dd1d2
Simplify try_zeroed_box and try_zeroed_slice_box (#162) 2023-01-19 13:33:27 -07:00
Alphyr
2548e460cb
Add more Zeroable and ZeroableInOption impls (#158) 2023-01-19 10:03:41 -07:00
Alphyr
f276289a9a
Update actions in CI to avoid deprecation (#163) 2023-01-19 10:01:19 -07:00
zachs18
117222d3e4
Implement AnyBitPattern for MaybeUninit<T> where T: AnyBitPattern. (#160) 2023-01-11 00:24:05 -07:00
zachs18
dbb776d443
Allow byte literals as enum discriminants in CheckedBitPattern derive macro. (#155) 2022-12-29 17:23:14 -07:00
Christofer Nolander
a758c0956e
impl Zeroable for Atomic* (#157)
* `impl Zeroable for Atomic*`

fixes #74

* added feature flag for `zeroable_atomics`

Added documentation for some feature flags on the `Zeroable` trait.
Also fixed some invalid references in doc-comments.
2022-12-21 13:54:31 -07:00
zachs18
4eea45e218
Refactor simd impls. (#156) 2022-12-18 13:44:25 -07:00
Scallop Ye
2c8ce95548
Experimental support for stdsimd types (#154) 2022-12-17 16:13:52 -07:00
zachs18
4c37652113
Implement CheckedBitPattern for core::num::NonZero*. (#151)
* Implement CheckedBitPattern for core::num::NonZero*.

* Add tests for CheckedBitPattern.

* Fix stacked borrows violation.

`<&mut T>::as_ptr` gives a `*const T` which is read-only. `<&mut T>::as_mut_ptr` is necessary to get a `*mut T`.

* MSRV fix.

* Add layout checks for CheckedBitPattern for NonZero*.

(Until Rust guarantees the layout of NonZero[int] matches [int].)
Also adds a test that will fail if any NonZero[int] has a different size or alignment than [int].
2022-11-30 12:09:17 -07:00
zachs18
911f43db98
Make checked::pod_read_unaligned require T: CheckedBitPattern (#150)
Currently, `checked::pod_read_unaligned` requires `T: AnyBitPattern`. (This was likely just a copy-paste error from when the function was introduced in #91.)
There should be no current UB nor semver breakage, since this only relaxes the bound (any type this previously worked with was already sound and will continue to work).
`checked::try_pod_read_unaligned has the correct `T: CheckedBitPattern` bound.
2022-11-28 15:12:32 -07:00
yvt
f14410f329
Implement Zeroable on {Cell,Reverse}<impl Zeroable> (#149)
* Implement `Zeroable` on `Cell<impl Zeroable>`

* Implement `Zeroable` on `Reverse<impl Zeroable>`
2022-11-20 21:28:55 -07:00
yvt
0da8f3a28f
Implement Zeroable on UnsafeCell<impl Zeroable> (#148) 2022-11-20 16:40:41 -07:00
zachs18
c9e1ae1373
Remove where clause from derived TransparentWrapper impls. (#146)
* Remove where clause from derived TransparentWrapper impls.

* Add test for TransparentWrapper trait bound regression.
2022-11-20 16:40:20 -07:00
Christopher Serr
7311e9b4b8
Implement ByteEq and ByteHash derives (#144)
* Implement `ByteEq` and `ByteHash` derives

This adds the derives `ByteEq` and `ByteHash` that can be used as an
alternative to the `Eq` / `PartialEq` and `Hash` derives from the
standard library. The difference is that these variants use `bytemuck`
to convert their values to byte slices before comparing / hashing them.
This allows the comparisons to turn into a simple `memcmp` / `bcmp` (or
completely inlined as a few vector instructions) and allows hashers to
process all bytes at once, possibly allowing for some vector operations
as well.

Here's a quick comparison of the generated assembly:
![https://i.imgur.com/CGTSWTZ.png](https://i.imgur.com/CGTSWTZ.png)

* Address review comments
2022-11-17 13:13:24 -07:00
Lokathor
6b1b7cecd3
Update README.md 2022-11-07 09:17:28 -07:00
Lokathor
06a62314a3 (cargo-release) version 1.12.3 2022-11-05 15:53:28 -06:00
Lokathor
46e816c710 changelog. 2022-11-05 15:53:11 -06:00
Lokathor
5c9d81ca1a (cargo-release) version 1.3.0 2022-11-05 15:49:51 -06:00
Lokathor
86226cefc4 changelog. 2022-11-05 15:48:37 -06:00
Christopher Serr
02021fba24
Conditionally compile in Arc (#140)
Apparently the latest release of `bytemuck` doesn't compile on some of
the targets that it used to because it uses `Arc`. `Arc` is not a type
that exists on every target, because not every targets supports atomics.
2022-11-05 07:00:40 -06:00
John Nunley
518baf9c0b
Allow repr(transparent) to be used generically in derive(Pod) (#139)
* Enabled transparent generics

* Move trait checks to implementation block

* Replace add_trait_marker impl
2022-11-03 07:53:01 -06:00
Lokathor
7b67524a43 (cargo-release) version 1.12.2 2022-10-30 16:23:59 -06:00
Lokathor
579950fdb5 changelog 2022-10-30 16:23:27 -06:00
Lokathor
12f5bfd62e clippy you are often a pain in my butt 2022-10-30 16:18:16 -06:00
Dennis Duda
f1571512d2
fix try_pod_read_unaligned... never having worked correctly (#138)
It seems like a copy-paste error has happened between `try_from_bytes`/`try_from_bytes_mut` and `try_pod_read_unaligned`, causing `internal::try_pod_read_unaligned` to try to read a &T::Bits instead of a T::Bits, usually failing with a `SizeMismatch` error. In the worst case, this allows UB in safe code by having a type allowing any bit pattern and being pointer-sized.
2022-10-30 16:06:55 -06:00
zachs18
09dd2ffd68
Add cast_{arc,rc} (and slice and try), and {wrap,peel}_{arc,rc}. (#132)
* Add `allocation::{try_,}cast_{arc,rc}`, and add `{wrap,peel}_{arc,rc}` to `TransparentWrapperAlloc`.

* Avoid intermediate slice reference in `try_cast_slice_{arc,rc}`.

* remove `unsafe` block; run `cargo +nightly fmt` (ignoring files I didn't modify)

* Make `cast_rc` (etc) have the same bounds as `cast_mut`, due to the existence of `Rc::get_mut_unchecked`.
2022-09-01 17:23:28 -06:00
Lokathor
950a3ed3b9 use the new derive updates. 2022-08-16 21:03:48 -06:00
Lokathor
3f2e91d3a6 (cargo-release) version 1.2.1 2022-08-16 21:01:26 -06:00
Lokathor
b7b438026d derive changlog. 2022-08-16 21:00:48 -06:00
Daniel Henry-Mantilla
d47d527ac2
Fix regression #127: support align in reprs again (#128) 2022-08-16 12:42:07 -06:00
Lokathor
995205de23 version bump 2022-08-14 10:10:45 -06:00