-
Notifications
You must be signed in to change notification settings - Fork 20
Add methods for use cases that align_to
does not cover
#164
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
Comments
Under which circumstances does code just ignore the head and tail? If it's about getting overaligned memory, wouldn't it be better to put it in an allocation API? |
Essentially yes, but I believe also for scratch space on the stack (getting a https://github.com/PsichiX/Oxygengine/blob/adef2107dee0cb6f5d816d5dec277479e801c5e7/engine/ha-renderer-debugger/src/system.rs#L245 |
All those cases look like they go to the same or smaller alignment, so
|
Maybe we can guarantee that |
Has seen no activity in 1 year, let's take it off the T-libs pile |
Proposal
Problem statement
The
align_to
slice method is only useful for optimizations that want to process all elements of the original slice, but has an optimized path for larger or more-aligned elements. The function may fall back to not producing a middle (aligned) slice and instead just return the original slice in the head or tail slice (for which, according toalign_to
's docs, an implementation must exist).There are many users in the ecosystem that use it for guaranteed alignment, which, while working most of the time, is not guaranteed by the API.
Related discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/align_to.20and.20other.20APIs.20with.20surprising.20const.20behavior
Motivation, use-cases
When you have a slice to primitives (like integers), it is sometimes convenient to convert said slice to a smaller or larger primitive. Especially common are conversions to and from
[u8]
.Solution sketches
Add two new slice methods (plus their
mut
counterparts):aligned_subslice
: Get a subslice where the first element is aligned to a given alignment and the size of the slice is a multiple of the alignment.transmute_elements
:aligned_subslice
for that instead.Alternatives:
We can also remove the fuzziness of the
align_to
method, but that would mean it could never be used in const eval.Links and related work
align_to
rust#105296 implements this changeWhat happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: