forked from google/zerocopy
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
renamed to as_mut_bytes #5
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dorryspears
force-pushed
the
rename-as_bytes_mut
branch
2 times, most recently
from
February 13, 2024 01:36
c39b863
to
bff9148
Compare
dorryspears
force-pushed
the
rename-as_bytes_mut
branch
from
February 13, 2024 01:49
bff9148
to
0347a27
Compare
dorryspears
pushed a commit
that referenced
this pull request
Feb 24, 2024
Previously, our test harness for `TryFromBytes` types assumed that those types also implemented `NoCell`. This commit introduces machinery that allows us to conditionally execute certain steps of our tests depending on whether or not the type under test implements `NoCell`. This commit also lifts the `T: NoCell` bound in `TryFromBytes for MaybeUninit<T>` in order to test this machinery. Makes progress on #5 Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
dorryspears
pushed a commit
that referenced
this pull request
Feb 24, 2024
This allows the callback passed to `with_passing_test_cases` to access its argument mutably. We don't make use of this ability in this commit, but it will become important later when we implement `TryFromBytes` for `UnsafeCell`. Makes progress on #5
dorryspears
pushed a commit
that referenced
this pull request
Mar 3, 2024
Credit to jswrenn@amazon.com for figuring out how to make this design more misuse-proof. Implementing `TryFromBytes` for `UnsafeCell` isn't possible without changes to `TryFromBytes`. Previously, we passed `is_bit_valid` a `Ptr` with shared aliasing. There is no way to soundly implement `is_bit_valid` for `UnsafeCell` with a shared-aliased pointer, as there's no way to soundly inspect the bytes of an `UnsafeCell` when other references may exist to the same memory. The only way to inspect the bytes of an `UnsafeCell` in a generic context is given a mutable reference to one. This is in principle possible from `TryFromBytes`. Notably, `try_read_from` reads a `MaybeUninit<Self>` into its local stack frame, and that has `UnsafeCell`s at the same byte ranges as `Self`, so it is sound to construct a mutably-aliased `Ptr` to that local variable. Unfortunately, `is_bit_valid` previously had no way of reasoning about a mutably-aliased pointer. In order to lift this restriction, we modify `is_bit_valid` to be generic over aliasing using `A: invariant::at_least::Shared`. When `A` is `invariant::Exclusive`, we can implement `TryFromBytes::is_bit_valid` for `UnsafeCell`. However, this isn't the whole story. We need to implement `TryFromBytes` for `UnsafeCell` in the general case, even when a shared-aliased `Ptr` is passed to `is_bit_valid`. Our first design was to define calling `UnsafeCell::is_bit_valid` with a shared-aliased to be a panic condition of `is_bit_valid`. Since we only call `is_bit_valid` from our own code (`is_bit_valid` is `#[doc(hidden)]`), we can in theory simply avoid calling `UnsafeCell::is_bit_valid` with a shared-aliased pointer. However, that's very error-prone. jswrenn had the idea to instead use a post-monomorphization error, which is implemented in `Ptr::into_exclusive_or_post_monomorphization_error`. This allows us to test *at compile time* to see whether the argument to `UnsafeCell::is_bit_valid` is a shared or exclusive pointer, and fail compilation in the former case. Some readers might wonder why we couldn't use a `NoCell` bound to enforce that `is_bit_valid` could only be called with a shared-aliased pointer when `Self: NoCell`. We experimented with this, but it turns out that there is some existing code that cannot be made to work with this pattern - the type system isn't smart enough to infer bounds in some cases. Makes progress on #5
dorryspears
pushed a commit
that referenced
this pull request
Mar 3, 2024
Makes progress towards #5.
dorryspears
pushed a commit
that referenced
this pull request
Mar 3, 2024
Makes progress on #5 Closes google#962 Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
joshlf
pushed a commit
that referenced
this pull request
May 3, 2024
…le#1119) For example, `try_from_ref` is now `try_ref_from`. See: google#1095 Makes progress on #5
dorryspears
pushed a commit
that referenced
this pull request
Jul 1, 2024
dorryspears
pushed a commit
that referenced
this pull request
Jul 1, 2024
Closes google#1013. Makes progress towards #5.
dorryspears
pushed a commit
that referenced
this pull request
Jul 1, 2024
We do support deriving `TryFromBytes` on unions, and our conservative assumptions of their validity match intuition. Makes progress towards #5.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
test