Skip to content

Fix/shared memory export waiters - #65

Merged
ncruces merged 2 commits into
ncruces:mainfrom
lbe:fix/shared-memory-export-waiters
Oct 16, 2026
Merged

ncruces merged 2 commits into
ncruces:mainfrom
lbe:fix/shared-memory-export-waiters

Conversation

@lbe

@lbe lbe commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #64

Summary

  • Fix codegen for modules with owned shared memory exported as memory. The generator used to cast the module []byte to *wasmMemory and emit Waiters() on that slice alias, which references m.waiters and does not compile.
  • For shared owned memory, wasmMemory is a struct with *[]byte and *sync.Map. The export returns wasmMemory{memory: &m.memory, waiters: m.waiters} so Waiters() uses the module waiter map.
  • Add testdata/regression/shared_export (WAT, WASM, golden Go) and Test_regression_shared_export. Cover this fixture with go test -args -unsafe; default go test skips its translate golden.

Problem

WAMR multi-thread samples (and similar modules) with (memory … shared) and (export "memory") produce output that fails go build, for example m.waiters undefined (type *wasmMemory has no field or method waiters) on the memory export.

@ncruces
ncruces force-pushed the fix/shared-memory-export-waiters branch 3 times, most recently from 292f4cd to 1aafc5b Compare October 12, 2026 12:35
@ncruces

ncruces commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

I rebased and fixed some formatting issues, just to make it easier to review.
But I'm still largely unconvinced for the reasons stated in #64.

@ncruces
ncruces force-pushed the fix/shared-memory-export-waiters branch 2 times, most recently from 2e1f175 to 4f6c22e Compare October 15, 2026 18:18
Owned shared memory modules exported a Memory view by casting the module's
[]byte to *wasmMemory, but Waiters() was generated on that slice alias and
referenced m.waiters, which does not exist on []byte. Generated packages
then failed to compile (e.g. m.waiters undefined).

Model shared owned memory as a wasmMemory struct holding *[]byte and
*sync.Map, and return a composite literal from memory exports so Waiters()
is wired to the module's waiter map. Add a minimal shared_export regression
fixture and test; refresh provided_helper golden output from translate.
@ncruces
ncruces force-pushed the fix/shared-memory-export-waiters branch from 4f6c22e to 3fe220e Compare October 16, 2026 13:18
Rather than special casing shared memory, make wasmMemory a struct
that holds the owned memory (and waiters), and embed it in Module.
Field promotion keeps m.memory/m.waiters working unchanged, Slice/Grow
operate on the embedded fields, and the memory export is &m.wasmMemory.

This gives shared and non-shared owned memory the same shape,
and removes the (*[]byte)(m) casts.
@ncruces
ncruces force-pushed the fix/shared-memory-export-waiters branch from 3fe220e to 9e39608 Compare October 16, 2026 13:34
@ncruces
ncruces merged commit 3acef44 into ncruces:main Oct 16, 2026
5 checks passed
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.

Generated package fails to compile when shared memory is owned and exported

2 participants