Borrow the newtype, not the representation, on primitive newtypes - #56
Merged
Merged
Conversation
`as_slice()` yields `&[ChunkId]` while `column[i]` yielded `&[u8; 16]`, so the same column reported two element types depending on how it was read — and `Deref` put `first()` (the newtype, through `as_slice`) right next to `get()` (the representation). The `primitive` arm already requires `Pod` and layout compatibility, so `Ref = Self` is sound the same way `values()` is: `must_cast_ref` on the representation's `value_ref`, size and alignment checked at compile time. `value()` / `get()` still hand out the representation's view — that is `LogicalType::Value`, load-bearing for the fallible arm, and a separate question. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Related
Column<T>::as_slice()now yields&[T]for newtypes #41What
A
primitivenewtype reported two element types for the same column:as_slice()yielded&[ChunkId](since #41) whilecolumn[i]yielded&[u8; 16], and #43'sDerefthen putfirst()(the newtype) next toget()(the representation).For a
Column<ChunkId>, wherenewtype_data_type!(ChunkId, FixedSizeBinary<16>, primitive):column[i]&[u8; 16]&ChunkIdcolumn.first()&ChunkId&ChunkIdcolumn.as_slice()&[ChunkId]&[ChunkId]column.value_owned(i)ChunkIdChunkIdcolumn.value(i)&[u8; 16]&[u8; 16]column.get(i)Option<&[u8; 16]>Option<&[u8; 16]>So the change is
RefType::Ref: indexing (column[i], andIndex-based&column[i]) hands back the newtype, agreeing withas_slice,first(), andto_vec(). Theprimitivearm already requiresPodand layout compatibility, so this is sound the same wayvalues()is:bytemuck::must_cast_refon the representation'svalue_ref, size and alignment checked at compile time. Both macros get it —newtype_data_type!andtry_newtype_data_type!.value()/get()still hand out the representation's view. That isLogicalType::Value, which is load-bearing for the fallible arm, so it stays a separate question.Testing
New assertions on the
ChunkIdfixture:array[1],as_slice()[1], andvalue_owned(1)agree on the newtype;value()/get()still give the representation; a plain (non-primitive) newtype still indexes as the representation.cargo test --all-features,cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --checkpass.Compatibility
primitivenewtypes only, and only atcolumn[i]:Code that already went through
as_slice(),first(),to_vec(), orvalue_owned()is unaffected. Nothing new is rejected: a newtype that is not layout-compatible cannot beprimitivein the first place.🤖 Generated with Claude Code