Repository navigation
Keep UniversalRead<u8> bound, do bytemuck conversion at call site - #8953
Merged
Merged
Conversation
Drop the `+ UniversalRead<OptionalPointer>` / `+ UniversalWrite<OptionalPointer>` trait bounds added in the previous two commits. Reads and writes of `OptionalPointer` and `TrackerHeader` now go through `bytemuck::from_bytes` / `bytemuck::bytes_of` on the existing `u8` byte slices instead. This keeps the unsafe-transmute removal but avoids the turbofish noise (`UniversalWrite::<u8>::flusher(&self.storage)`, `<S as UniversalRead<u8>>::open`, …) that two `T`s on `S` forced everywhere. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
coszio
approved these changes
May 7, 2026
coszio
left a comment
Contributor
There was a problem hiding this comment.
TBH, I wish we didn't choose T to be part of the trait definition.
xzfc
reviewed
May 8, 2026
Comment on lines
+348
to
+352
| let bytes = self.storage.read::<Random>(ReadRange { | ||
| byte_offset: start_offset as u64, | ||
| length: size_of::<OptionalPointer>() as u64, | ||
| })?; | ||
| let opt: &OptionalPointer = bytemuck::from_bytes(bytes.as_ref()); |
Member
There was a problem hiding this comment.
This code reads u8 slice/vec then casting it into OptionalPointer. The issue: read might return unaligned Vec<u8>.
coszio
pushed a commit
that referenced
this pull request
May 8, 2026
…8953) Drop the `+ UniversalRead<OptionalPointer>` / `+ UniversalWrite<OptionalPointer>` trait bounds added in the previous two commits. Reads and writes of `OptionalPointer` and `TrackerHeader` now go through `bytemuck::from_bytes` / `bytemuck::bytes_of` on the existing `u8` byte slices instead. This keeps the unsafe-transmute removal but avoids the turbofish noise (`UniversalWrite::<u8>::flusher(&self.storage)`, `<S as UniversalRead<u8>>::open`, …) that two `T`s on `S` forced everywhere. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall
added a commit
that referenced
this pull request
May 8, 2026
* derive bytemuck::Pod on `OptionalPointer`, get rid of legacy transmute * remove one layer of Option in `get_raw` * keep `UniversalRead<u8>` bound, do bytemuck conversion at call site (#8953) Drop the `+ UniversalRead<OptionalPointer>` / `+ UniversalWrite<OptionalPointer>` trait bounds added in the previous two commits. Reads and writes of `OptionalPointer` and `TrackerHeader` now go through `bytemuck::from_bytes` / `bytemuck::bytes_of` on the existing `u8` byte slices instead. This keeps the unsafe-transmute removal but avoids the turbofish noise (`UniversalWrite::<u8>::flusher(&self.storage)`, `<S as UniversalRead<u8>>::open`, …) that two `T`s on `S` forced everywhere. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> * extra refactoring after #8955 * explicit zeroed instantiation --------- Co-authored-by: Andrey Vasnetsov <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall
added a commit
that referenced
this pull request
May 22, 2026
* derive bytemuck::Pod on `OptionalPointer`, get rid of legacy transmute * remove one layer of Option in `get_raw` * keep `UniversalRead<u8>` bound, do bytemuck conversion at call site (#8953) Drop the `+ UniversalRead<OptionalPointer>` / `+ UniversalWrite<OptionalPointer>` trait bounds added in the previous two commits. Reads and writes of `OptionalPointer` and `TrackerHeader` now go through `bytemuck::from_bytes` / `bytemuck::bytes_of` on the existing `u8` byte slices instead. This keeps the unsafe-transmute removal but avoids the turbofish noise (`UniversalWrite::<u8>::flusher(&self.storage)`, `<S as UniversalRead<u8>>::open`, …) that two `T`s on `S` forced everywhere. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> * extra refactoring after #8955 * explicit zeroed instantiation --------- Co-authored-by: Andrey Vasnetsov <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or 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
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.
Summary
The switch to
bytemuck::PodforOptionalPointer(and nowTrackerHeader) is nice, but I think having twoTs onS(UniversalRead<u8> + UniversalRead<OptionalPointer>/UniversalWrite<u8> + UniversalWrite<OptionalPointer>) creates too much turbofish noise — every method that exists on both impls (flusher,len,populate,open) has to be disambiguated withUniversalWrite::<u8>::flusher(&self.storage)/<S as UniversalRead<u8>>::open(...)etc., which is hard to read.I'd prefer doing the conversion manually at the call site instead. Since
OptionalPointeralready derivesbytemuck::Pod, we can keep the storage bound as plainUniversalRead<u8>/UniversalWrite<u8>and use:bytemuck::from_bytes::<OptionalPointer>(bytes.as_ref())for reads (returns&T, runtime-checks alignment — same shape and assumption as the originaltransmute_from_u8)bytemuck::bytes_of(&pointer)for writesThis keeps the unsafe-transmute removal from the previous two commits (and additionally drops the legacy
transmute_*forTrackerHeadertoo), but all the explicit-turbofish noise goes away —self.storage.flusher(),self.storage.len(),S::open(...)everywhere.Net change vs. branch HEAD: same safety improvement, no extra trait bounds, no turbofish.
Test plan
cargo test -p gridstore— all 58 tests pass (20 tracker, 38 gridstore)cargo check -p gridstorecleanread_multi_iter&OptionalPointer->to_option()is worth the small per-entry copy vs. the typed-storage approach (negligible at 16 bytes)🤖 Generated with Claude Code