Add initial support for unsized MaybeUninit wrapper type#2055
Conversation
271b768 to
96b54d1
Compare
joshlf
left a comment
There was a problem hiding this comment.
Haven't looked at most of zerocopy-derive yet, but looked at all of zerocopy.
9844c1f to
9751180
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v0.8.x #2055 +/- ##
==========================================
- Coverage 88.04% 87.42% -0.63%
==========================================
Files 16 16
Lines 5983 6115 +132
==========================================
+ Hits 5268 5346 +78
- Misses 715 769 +54 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
235989d to
bb140d0
Compare
|
The remaining CI failures are from |
We should report this upstream. In particular, given that |
joshlf
left a comment
There was a problem hiding this comment.
A few more nits, but otherwise LGTM!
src/util/mod.rs
Outdated
| // fields both start at the safe offset and the types of those fields are | ||
| // transparent wrappers around `Src` and `Dst` [1]. Consequently, | ||
| // initializng `Transmute` with with `src` and then reading out `dst` is | ||
| // equivalent to transmuting from `Src` to `Dst` [2]. |
There was a problem hiding this comment.
Also need to prove that such a transmute is sound (guaranteed by the caller).
There was a problem hiding this comment.
Is that latter change semantically meaningful? Or do you just prefer that wording?
bb140d0 to
b573d83
Compare
Filed: obi1kenobi/cargo-semver-checks#997 In the meantime, I think we should permit |
b573d83 to
9f151e8
Compare
d94bda0 to
944a13e
Compare
944a13e to
167b002
Compare
This is achieved by adding a `MaybeUninit` associated type to `KnownLayout`, whose layout is identical to `Self` except that it admits uninitialized bytes in all positions. For sized types, this is bound to `mem::MaybeUninit<Self>`. For potentially unsized structs, we synthesize a doppelganger with the same `repr`, whose leading fields are wrapped in `mem::MaybeUninit` and whose trailing field is the `MaybeUninit` associated type of struct's original trailing field type. This type-level recursion bottoms out at `[T]`, whose `MaybeUninit` associated type is bound to `[mem::MaybeUninit<T>]`. Makes progress towards #1797 SKIP_CARGO_SEMVER_CHECKS=1
167b002 to
60f0a43
Compare
This is achieved by adding a `MaybeUninit` associated type to `KnownLayout`, whose layout is identical to `Self` except that it admits uninitialized bytes in all positions. For sized types, this is bound to `mem::MaybeUninit<Self>`. For potentially unsized structs, we synthesize a doppelganger with the same `repr`, whose leading fields are wrapped in `mem::MaybeUninit` and whose trailing field is the `MaybeUninit` associated type of struct's original trailing field type. This type-level recursion bottoms out at `[T]`, whose `MaybeUninit` associated type is bound to `[mem::MaybeUninit<T>]`. Makes progress towards #1797 SKIP_CARGO_SEMVER_CHECKS=1 gherrit-pr-id: Idfc357094e28b54a15d947141241ca2da83dcc91
|
Backporting in #2310 |
This is achieved by adding a `MaybeUninit` associated type to `KnownLayout`, whose layout is identical to `Self` except that it admits uninitialized bytes in all positions. For sized types, this is bound to `mem::MaybeUninit<Self>`. For potentially unsized structs, we synthesize a doppelganger with the same `repr`, whose leading fields are wrapped in `mem::MaybeUninit` and whose trailing field is the `MaybeUninit` associated type of struct's original trailing field type. This type-level recursion bottoms out at `[T]`, whose `MaybeUninit` associated type is bound to `[mem::MaybeUninit<T>]`. Makes progress towards #1797 SKIP_CARGO_SEMVER_CHECKS=1 gherrit-pr-id: Idfc357094e28b54a15d947141241ca2da83dcc91
This is achieved by adding a `MaybeUninit` associated type to `KnownLayout`, whose layout is identical to `Self` except that it admits uninitialized bytes in all positions. For sized types, this is bound to `mem::MaybeUninit<Self>`. For potentially unsized structs, we synthesize a doppelganger with the same `repr`, whose leading fields are wrapped in `mem::MaybeUninit` and whose trailing field is the `MaybeUninit` associated type of struct's original trailing field type. This type-level recursion bottoms out at `[T]`, whose `MaybeUninit` associated type is bound to `[mem::MaybeUninit<T>]`. Makes progress towards #1797 SKIP_CARGO_SEMVER_CHECKS=1 gherrit-pr-id: Idfc357094e28b54a15d947141241ca2da83dcc91
…2310) This is achieved by adding a `MaybeUninit` associated type to `KnownLayout`, whose layout is identical to `Self` except that it admits uninitialized bytes in all positions. For sized types, this is bound to `mem::MaybeUninit<Self>`. For potentially unsized structs, we synthesize a doppelganger with the same `repr`, whose leading fields are wrapped in `mem::MaybeUninit` and whose trailing field is the `MaybeUninit` associated type of struct's original trailing field type. This type-level recursion bottoms out at `[T]`, whose `MaybeUninit` associated type is bound to `[mem::MaybeUninit<T>]`. Makes progress towards #1797 SKIP_CARGO_SEMVER_CHECKS=1 gherrit-pr-id: Idfc357094e28b54a15d947141241ca2da83dcc91 Co-authored-by: Jack Wrenn <[email protected]>
This is achieved by adding a
MaybeUninitassociated type toKnownLayout, whose layout is identical toSelfexcept that it admits uninitialized bytes in all positions.For sized types, this is bound to
mem::MaybeUninit<Self>. For potentially unsized structs, we synthesize a doppelganger with the samerepr, whose leading fields are wrapped inmem::MaybeUninitand whose trailing field is theMaybeUninitassociated type of struct's original trailing field type. This type-level recursion bottoms out at[T], whoseMaybeUninitassociated type is bound to[mem::MaybeUninit<T>].Next Steps and Future Possibilities
MaybeUninit<T: ?Sized>In the near term, we may remove
doc(hidden)from ourMaybeUninitwrapper. In doing so, we'd be quick-to-ship a gadget that extends the present capabilities of Rust. We might, then, be able to use this feature as a demonstration of our approach, potentially suitable for upstreaming into rustc.UnalignUnsized<T: ?Sized>Presently, our
Unalignwrapper requiresT: Sized, because we could not figure out how to drop unsized values. For sized values, we copy them onto the stack, then run their destructor. WithMaybeUninit<T: ?Sized>, we can extend unalign support to unsized values, by first copying them into aBox<MaybeUninit<T>>, casting the box toBox<T>, and dropping it. This process would be skipped for types with trivial drops, keeping the common case simple and efficient.Value<T, I> where I: Invariants<Validity = Any>Combining the above two approaches, we could create an invariant-parameterized
Ptranalogue for values that generalizes over initialization and alignment.