Repository navigation
Fix import section count when using compact imports - #2870
Merged
Merged
Conversation
Under the compact import section proposal the import section is encoded as `section_2(list(imports))`, where a single `imports` entry can contain multiple imports. The leading count is therefore the number of entries in the section, not the total number of imports. Previously both the writer and the reader used the total number of imports, so modules written by wabt could not be read by other tools and conforming modules (such as those in the proposal's spec tests) were rejected by wabt. - binary-writer: Write the number of entries as the section count. - binary-reader: Loop over the entries, keeping a separate running import index. OnImportCount now reports the number of entries. - wasm-objdump: Count the imports during the prepass so that the total number of imports is still reported. Fixes: WebAssembly#2845
sbc100
reviewed
Oct 1, 2026
Member
There was a problem hiding this comment.
So i still counts total imports, is that what we want? Do could we use j here and completely remove i?
Contributor
Author
There was a problem hiding this comment.
j restarts at 0 for each compact group, but OnImport/OnImport* take the index of the import within the whole section (it shows up in the -v logging output and objdump uses it), so we still need that. However it doesn't need to be tracked separately: ReadImport already bumps exactly one of the per-kind counters for each import, so the index is just their sum. I've removed i from ReadImportSection and the ReadImport parameter, and compute the index there instead.
The index of each import can be derived from the per-kind import counters that ReadImport already maintains, so there is no need to track it separately while iterating over the import section entries.
sbc100
approved these changes
Oct 2, 2026
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.
The compact import section proposal encodes the import section as
section_2(list(imports)), where a single entry can contain several imports, so the section count is the number of entries rather than the number of imports. wabt's writer and reader both used the total import count, which made wabt's output unreadable by other decoders and caused wabt to reject conforming modules.OnImportCountnow reports the entry count.--enable-alldump tests would printImport[1]followed by two imports; happy to print the raw entry count and update those tests instead if preferred).test/binary/compact-imports.txt(hand-written binary, now with a single entry after the compact runs) andtest/dump/compact-imports.txt.Non-compact encoding is unchanged.
run-tests.pypasses.Fixes #2845