Use stabilized Layout::repeat#24006
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Apr 28, 2026
Merged
Conversation
Move the check that `size == stride` earlier so that it does not abort the process.
alice-i-cecile
approved these changes
Apr 28, 2026
Victoronz
approved these changes
Apr 28, 2026
Contributor
Victoronz
left a comment
There was a problem hiding this comment.
Makes sense!
My understanding of the reason for Layout not enforcing this property on its own is that Rust types have the requirement, but allocations do not.
I think in practice however, most allocators already comply anyway, and we may one day get some updated Allocator trait with a version of Layout that properly enshrines this.
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.
Objective
BlobArrayhas copies ofLayout::repeatwith a note to replace them when it stabilizes.Layout::repeatstabilized in Rust 1.95, so let's use it!Fix some UB in an edge case.
BlobArrayassumes that thesize()of a type is a multiple of itsalign(). That's true for all Rust types, but a user may register a component usingregister_component_with_descriptorpassing aLayoutwhere it's not true. In release mode, that causes UB due to unaligned memory access. In debug mode, it triggers adebug_assert!, and thenTable::alloc_columnsaborts the process withAbortOnPanic.Solution
Ensure that the
Layoutused byBlobArrayhas asize()that is a multiple of itsalign(), by making it a safety requirement ofBlobArrayand havingComponentDescriptorenforce it.Remove the
repeat_layoutmethods. Replace calls toarray_layoutwithLayout::repeat_packed. Sincesize()is a multiple ofalign(), that has the same behavior asLayout::repeat, but is simpler. Replace calls toarray_layout_uncheckedwithLayout::repeat_packedfollowed bydebug_checked_unwrap.