binaryen
binaryen copied to clipboard
Memory packing is not safe with imported memory
The MemoryPacking pass assumes that the initial memory is zero, so it is free to remove spans of zeroes from active segments. This is not technically true with an imported memory. Do we care? This has not been a problem in practice because toolchains generally assume that memory is fresh and owned by the wasm module.
Good point. We should perhaps make variations on the pass that either make that assumption or do not, but a downside is that most code will likely assume this, so forcing people to opt-in means some would miss out. Still, it's probably the right thing to do.