Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-encoder: add method to allow fetching raw Function bytes. #1630

Merged
merged 1 commit into from
Jun 23, 2024

Commits on Jun 22, 2024

  1. wasm-encoder: add method to allow fetching raw Function bytes.

    When generating function bodies with `wasm-encoder`, it is sometimes
    useful to take the function bytecode, cache it, then reuse it later.
    (For my specific use-case, in weval, I would like to cache
    weval-specialized function bodies and reuse them when creating new
    modules.)
    
    Unfortunately the existing API of `wasm-encoder` makes this *almost* but
    *not quite* easy: `Function` implements `Encode::encode`, but this will
    produce a function body *with* the length prefixed. However there's no
    way to use this unmodified with the next level up the entity hierarchy:
    `CodeSection::raw` wants the function bytes *without* the length
    prefixed.
    
    This is a fairly annoying if small API gap, and otherwise requires
    manually stripping the length prefix, a leb128-encoded integer. It's
    also a small footgun: I naively did not realize this mismatch and tried
    to do the above, only to get perplexing type errors with locals.
    
    This PR adds one method on `wasm_encoder::Function` to return the inner
    bytes directly, and the doc-comment contains an example showing the
    intended use-case.
    cfallin committed Jun 22, 2024
    Configuration menu
    Copy the full SHA
    ad6d593 View commit details
    Browse the repository at this point in the history