Skip to content

fix(wasm): track reexport bindings beyond the static capacity - #136

Open
BridgeAR wants to merge 2 commits into
mainfrom
BridgeAR/2026-10-05-cjs-binding-overflow
Open

BridgeAR wants to merge 2 commits into
mainfrom
BridgeAR/2026-10-05-cjs-binding-overflow

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

The Wasm parser stops recording require bindings after 255 declarations, so later Babel-style reexports disappear. Binding records now share per-source analysis memory and reset between parses.

@guybedford guybedford left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fix is correct. Verified locally: the new test fails against the main wasm (binding 255 is dropped), the committed lib/lexer.wasm reproduces byte-identically via build-wasm-local, and the analysis memory budget holds under stress (100k minimal var a=require("a") declarations at both analysis_base alignments, since the shortest tracked declaration reserves 34 bytes against the 20-byte record).

Main suggestion is structural: with the overflow path in place, the static array is now just a fast path for the first 255 entries at the cost of two storage paths and two lookup loops. Putting all bindings in analysis memory as a single linked list ends up simpler and smaller, see inline comment.

Also worth rebasing on main (#131 landed, no overlap).

Comment thread src/lexer.c Outdated
Comment thread src/lexer.c Outdated
Comment thread test/_unit.js Outdated
The Wasm parser stops recording bindings when its fixed array fills, so later
Babel-style reexports disappear from the result. Overflow bindings use the
existing per-source analysis memory, and files within the static capacity
retain the existing storage path.

Signed-off-by: Ruben Bridgewater <ruben.bridgewater@datadoghq.com>
A minimal declaration reserves 34 analysis bytes for a 20-byte Wasm binding
record. This lets the existing source allocation hold bindings without a
separate overflow representation.

Signed-off-by: Ruben Bridgewater <ruben.bridgewater@datadoghq.com>
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-10-05-cjs-binding-overflow branch from 73e1781 to 0cf6148 Compare October 11, 2026 09:41
@BridgeAR
BridgeAR marked this pull request as ready for review October 11, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants