alexcrichton opened PR #4330 from component-model-slice-align
to main
:
This commit extends the
WasmList<T>
type to have an
as_slice
-lookalike method (now renamed toas_le_slice
) for all
integer types rather than just theu8
type. With the guarantees of the
component model it's known that all lists are aligned in linear memory.
Additionally linear memories themselves are also generally guaranteed to
be aligned. This means that hosts where the primitive integer alignment
is at most the size (which I think is basically all host platforms) can
get a raw view into memory for the wasm linear memory for slices of
these types.Note, though, that the remaining caveat after alignment is endianness.
Big-endian hosts need to be aware that the integers aren't stored in a
native format. Previously tools like wit-bindgen have added anLe<T>
wrapper but for now I've opted to instead use a method that has "le" in
the name -as_le_slice
. I'm hoping that this is a clear enough
indicator for users to little-endian conversions as appropriate when
reading the values within the slice.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
fitzgen submitted PR review.
fitzgen created PR review comment:
I guess if that isn't the case, this assertion will trip.
fitzgen submitted PR review.
fitzgen created PR review comment:
Do we trap if they are not aligned? That is, can we rely on these actually being aligned here?
alexcrichton merged PR #4330.
Last updated: Dec 23 2024 at 12:05 UTC