Repository navigation
[spec] Fix the default alignment of memarg in the text format - #2314
Merged
Merged
Conversation
memarg in the text format
rossberg
reviewed
Nov 2, 2026
rossberg
left a comment
Member
There was a problem hiding this comment.
Thanks! Can you also backport this to the 1.0 and 2.0 specs?
Contributor
Author
|
Thanks! |
rossberg
approved these changes
Nov 2, 2026
rossberg
left a comment
Member
There was a problem hiding this comment.
Ah, sorry, indeed we haven't recreated the text format for 1.0 and 2.0 in SpecTec yet.
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.
Problem
The text format section on memory instructions says the alignment defaults to the natural alignment, but the grammar right below it does not:
(§6.5.6 of the Release 3.0 PDF, 2026-10-28)
align_N(Talign_in 6.3-text.instructions.spectec L184-L186) receives the access sizeNin bytes and should return the alignment exponent thatmemargstores. The explicit case converts the byte valuemto the exponentn, but the default case returns the byte valueNunchanged. For example,i32.loadusesTmemarg_(4)(L192), soi32.loadwithoutalign=getsALIGN 4instead ofALIGN 2.Memarg_okrequires2^n <= N/8withNin bits, i.e.2^nmust not exceed the access size in bytes. With the default,nis the byte size itself, and2^n <= nnever holds. So every load and store that omitsalign=is invalid under this grammar, for example:The reference interpreter follows the prose: it uses the natural alignment as an exponent (lexer.mll L249-L256, e.g.
opt a 2fori32.load).In Wasm 2.0,
align_Nreturned the byte value andmemarg_Nconverted it witha = 2^n(wg-2.0 text/instructions.rst L288-L295), soε ⇒ Nwas correct there. The SpecTec version moved the conversion intoTalign_, and #2107 fixed its explicit case to returnn, but the default case was left asN.Fix
Convert the default in the same way as the explicit case:
The rendered grammar becomes
ε ⇒ n if N = 2^n, matching the line above it.This PR changes
6.3-text.instructions.spectecinwasm-3.0andwasm-latestand updates thespectec/test-*/TEST.mdoutputs. No test is added, since the reference interpreter's parser already uses the natural alignment.