Skip to content

High-level Q: JS interop vs. core Wasm #36

@jakobkummerow

Description

@jakobkummerow

I think some of the opinions that folks have on their preferred design approaches are consequences of more general thoughts about how features and specifications should be organized, so I figured it might be productive to take a step back and talk about those.

In short:

Do we prefer it when JS-relevant things are kept out of core Wasm (and instead are e.g. confined to a custom section that non-JS embedders can ignore), or do we prefer to have them in core Wasm (so that custom sections don't become too load-bearing or too powerful)?

As a third option, is it perhaps time to resolve this by introducing a third kind of section, let's call them "embedder sections" for now, that are validated like regular sections, but specified in embedder/API specs rather than the core Wasm specification, and meant to be ignored by other embedders to whom they are not relevant?

Or is this not the dichotomy you see; would you characterize in different terms what you find most important/desirable about the way embedder-specific behavior is specified and integrated with core Wasm?

A concrete example from this proposal, illustrating what these principles could mean in practice:

Any declarative way to set up JS prototypes with methods fundamentally needs to express tuples
(which function, as which method name, on which prototype, and is it a method|getter|setter).
There are several ways how this can be accomplished:
A. We could define a new kind of export section entry for this. That would maintain the principle that there is only one export section that lists everything that the module exposes to the outside world. On the other hand, this export section would then contain a lot of JS-specific things that are most likely useless to non-JS embeddings.
B. We could specify a second kind of export section; that would either be a "Custom Section" as they stand today, or the new "embedder section" kind mentioned above. That would mean that the set of publicly exposed things is now defined by the union of two sections. It would also mean that for any tool/engine that doesn't care about JavaScript, it's very easy to ignore the things that are only relevant for exposure to JavaScript -- which reflects the reality that for, say, an AOT optimizer targeting maximally-efficient modules for non-Web embeddings, it would be desirable to only consider those exports as publicly exposed that are actually relevant in that context.
C. We could aim for a kind of middle ground: existing (or perhaps new) kinds of export section entries must ("passively") list everything that's exposed publicly, while a Custom Section contains the actual declarative instructions what to do with them (the 4-tuple sketched above). That would maintain the principle that the export section lists the module's entire public interface, and it would avoid adding JS-related spec text to core Wasm. But in actual modules the JS-related stuff would pollute the "core" part of the module: there would be a bunch of exports that are useless outside a JS embedding, yet are (probably?) impossible to ignore or strip out by engines or optimizers, because there's no way to identify them as ignorable.

I think that each of these approaches has pros and cons, and I expect that each will have its supporters. I assume that these individual opinions are to a large extent based on prior, more general idealizations of how embedder-specific behaviors should be specified. So before debating and tweaking the specific details, I think we might want to find consensus on the general approach first.

Further, I think this is largely a question of personal preference, so one way to resolve it is by majority vote, and a "temperature of the room" reading in that sense would be a fine outcome of this thread. That said, if you can articulate specific reasons why your preference goes one way or the other, that would be particularly valuable for finding consensus: you might convince someone else of your reasoning!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions