Skip to content

0.13.0

Choose a tag to compare

@benoitc benoitc released this 28 Nov 00:16
· 48 commits to main since this release
638f701

Adds an encoder: a module written as text or built in Erlang can be written
out as .wasm bytes, and text loads with the same handle as its binary. One
fix: a module that leaves out a data count section it needs is refused.

Changes

  • New: encode a module to the binary format. wasm:encode/1 writes a
    module as .wasm bytes. It takes text as {wat, Source}, a module you
    compiled or built in Erlang, or a handle from wasm:load/1, so you can
    turn text into a .wasm file without a toolchain, or hand a module you
    changed to another engine. The same module always gives the same bytes. A
    later release that changed those bytes would change the SHA-256 of every
    module encoded with it, and so break anything that names modules by their
    digest; it will be announced as a breaking change.
  • New: load the text format. wasm:load/1 and wasm:load/2 take
    {wat, Source}, and wasm:load_file/1 reads a .wat file as text; both
    encode it before loading. A module loaded from text and the same module
    loaded from its .wasm share one cache entry and one handle. Until now
    text could only be compiled, and each compile gave it a new identity that
    nothing shared.
  • Fixed: a module could leave out its data count section in two cases.
    The binary format requires the data count section whenever code names a
    data segment, and a module is malformed without it. The check looked
    inside every kind of block but try_table, and did not count the garbage
    collection instructions array.new_data and array.init_data, so a module
    that named a data segment only in those ways was read. It is refused now,
    as it is elsewhere.