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

Update proposal to accommodate need for type imports #13

Merged
merged 1 commit into from
Feb 15, 2019

Conversation

linclark
Copy link
Member

This PR makes some fundamental changes in the way that wasm ES modules will be instantiated. Instead of running instantiate during the ES module system's instantiation phase.

This change is motivated by work going on to share types between JS and wasm. This will require importing types. Because types defined in JS would only be initialized during evaluation, we need JS modules exporting types to evaluate before the importing wasm module snapshots them.

During the instantiation phase, we create live bindings for every declared export of a wasm module and link to the import memory locations but do not snapshot them yet. Unlike functions in JavaScript, function exports in WebAssembly will not be hoisted and are instead like every other kind of export. They get filled in when you evaluate the module.

During evaluation, the wasm module will take a snapshot of all of its imported bindings and initialize all of its exports.

I will add an item to the next CG agenda to discuss this further.

@rossberg
Copy link
Member

I think this makes sense, provided I interpret it right. There is an unfortunate clash of terminology here. In particular, where the PR speaks of "evaluating a Wasm module" I think it means "instantiating" in Wasm vocabulary, and where it speaks of "instantiating a Wasm module" it means creating the JS side wrapper objects for it(?). Without such a reinterpretation, e.g., it is difficult to assign meaning to statements like

wasm module is instantiated. All exports are set to undefined.

Would it be possible to clarify these terminology differences and perhaps use less ambiguous words to bridge the two specs involved? For example, instead of "instantiating a module" speak of "defining" it (or some other word not pre-occupied in either spec) and specify what concept that maps to on both sides. Or short of that, at least qualify the ambiguous uses in some suitable fashion.

@domenic
Copy link
Member

domenic commented Aug 13, 2018

+1 on doing whatever possible to clarify terminology confusion. My initial idea is to never say "instantiate" but instead "wasm-instantiate" / "ES-instantiate". (Same for evaluate?) There may be better ideas though, such as Andreas's suggestion of introducing a third set of words.

@tschneidereit
Copy link
Member

I wonder if we could change the language in one of the specs. It seems like that'd be possible in the ES spec because the module instantiation phases are internal in that case?

@linclark
Copy link
Member Author

Till and I discussed his idea of changing the terminology in the ES spec. I like the idea of using the term "linking" instead of "instantiate". For evaluation, I don't know what an appropriate term would be.

@tschneidereit, do you have a feel for how the committee would receive this?

In the meantime, it is difficult to fully disambiguate this. If the ES spec doesn't change, we will need to have a method in the wasm JS embedding spec called Instantiate (which would not perform instantiation as it's defined in the core spec) and another called Evaluate (in which the work of WebAssembly.instantiate would happen).

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.

None yet

5 participants