[wasm] Encode struct alignment in thunk signatures - #132248
Draft
davidwrighton wants to merge 2 commits into
Draft
[wasm] Encode struct alignment in thunk signatures#132248davidwrighton wants to merge 2 commits into
davidwrighton wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b1af492e-7431-46af-b519-dcc504b62300
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Wasm thunk signature-string encoding to preserve by-reference struct alignment requirements (notably 16-byte alignment) so that signature raising and transition-block layout remain correct when two same-sized structs differ in alignment.
Changes:
- Extends struct tokens from
S<N>to optionally include alignment for parameters:S!<N>:<A>(while keeping struct returns asS<N>). - Threads alignment through signature generation/parsing paths (runtime, WasmAppBuilder thunk generator, and crossgen2 tooling) and updates caching to disambiguate same-sized structs by
(size, alignment)when needed. - Adds ReadyToRun tests and updates design documentation for the extended encoding.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/WasmAppBuilder/coreclr/SignatureMapper.cs | Adds parsing/formatting support for alignment-qualified struct tokens and exposes helpers to extract size/alignment. |
| src/tasks/WasmAppBuilder/coreclr/InterpToNativeGenerator.cs | Aligns interpreter-stack slot offsets for indirect struct args when token alignment exceeds 8, and normalizes struct-return typedef naming. |
| src/coreclr/vm/wasm/helpers.cpp | Encodes parameter struct alignment into thunk signature keys while forcing return structs to remain size-only. |
| src/coreclr/vm/jitinterface.cpp | Adjusts Wasm alignment requirement computation to account for explicit layout and elevated field alignment in auto-layout structs. |
| src/coreclr/tools/Common/JitInterface/WasmLowering.cs | Implements parsing/emission for S!<N>:<A>, raises signatures using cached structs keyed by layout, and emits alignment only for parameters. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Mirrors Wasm alignment requirement logic in the tool-side JIT interface implementation. |
| src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Wasm.cs | Changes struct caching to key by (size, alignment) when alignment is part of the signature encoding. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/WasmArgumentLayoutTests.cs | Adds/updates tests ensuring signatures and computed offsets remain correct for same-sized structs with different alignment. |
| docs/design/coreclr/botr/readytorun-format.md | Documents S!<N>:<A> encoding rules and clarifies slot sizing for struct tokens. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b1af492e-7431-46af-b519-dcc504b62300
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/coreclr/vm/jitinterface.cpp:1964
- The comment mentions "beyond the pointer size", but the logic only adjusts the alignment when
fieldAlignment > 8. On Wasm32 the pointer size is 4, so this is misleading and makes it harder to reason about why the threshold is 8.
// Auto-layout structs can contain fields aligned beyond the pointer size on Wasm.
This was referenced Aug 13, 2026
Open
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.
Supports structs with 16 byte alignment. Alternative PR to #132244
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com