Repository navigation
js: Take a component as input, not interfaces - #373
Merged
Merged
Conversation
Member
Author
|
Procedurally this is built on #372 and additionally depends on bytecodealliance/wasmtime#5053, so will want to hold off on merging until those are both in. |
alexcrichton
force-pushed
the
rewrite-js
branch
from
October 13, 2022 17:25
2d77939 to
e44d0ff
Compare
pchickey
reviewed
Oct 13, 2022
pchickey
left a comment
Contributor
There was a problem hiding this comment.
review still in progress, just pushing these easy ones
pchickey
approved these changes
Oct 13, 2022
pchickey
left a comment
Contributor
There was a problem hiding this comment.
This is awesome, lets ship it. I spent some time going through this with @guybedford and we satisfied a bunch of curiosity we had about why the generated code looks like it does.
This commit is the implementation of bytecodealliance#314 for the JS host generator. The commit here covers basically everything in that issue for JS except it generates a slightly different structure of the JS output. Otherwise the main highlights are: * The JS host generator no longer implements the core `Generator` trait since it doesn't really fit in the component-as-input world. For now I created an `InterfaceGenerator` trait since similar functionality is used just not precisely the same. I expect that this will get iterated on over time as worlds and other host generators take shape. * The `wasmtime-environ` crate from Wasmtime itself, typically a "private" dependency of Wasmtime, is used to parse the input component and generate an `instantiate` function in JS. Wasmtime does all the heavy lifting of creating a linear list of initializers for the component and this empowers the generator to simply generate JS that is the list of initializers. * The `wit-component` crate is used to "extract" the `Interface` descriptions from the input component. This is used to generate type information for TypeScript as well as types for lifting/lowering. Internally a correlation is done from a lowering/lifting to an `Interface` function to connect the dots when instantiating a component. Lots of pieces needed updating here such as the runtime tests, the `wit-bindgen` CLI tool, and the demo web page. These are all updated for the new structure of the JS host generator. Overall this surprisingly went much more smoothly than I expected. With `wit-bindgen` being able to extract `Interface` representations from a component most of the prior JS host code generation was able to be reused. Along the way I also felt that the addition of "worlds" would have relatively obvious insertion points and would be relatively easily handled in all the places. The demo and runtime tests are proof enough to me at least that this all works internally, and this feels like a solid foundation to iterate from with the addition of worlds and continued support for JS hosts.
* Pull in latest `wasmtime` where `main` now works * Add a `testwasi` implementation for JS and use it in all tests * Add a dummy `printf` to a C test to ensure it imports `testwasi` like the other languages. * Add a `fd_fdstat_get` stub to make C happy * Update `fd_write` to only work for fd 1
alexcrichton
force-pushed
the
rewrite-js
branch
from
October 13, 2022 21:25
e9197ba to
7908cb5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit is the implementation of #314 for the JS host generator.
The commit here covers basically everything in that issue for JS except
it generates a slightly different structure of the JS output. Otherwise
the main highlights are:
The JS host generator no longer implements the core
Generatortraitsince it doesn't really fit in the component-as-input world. For now I
created an
InterfaceGeneratortrait since similar functionality isused just not precisely the same. I expect that this will get iterated
on over time as worlds and other host generators take shape.
The
wasmtime-environcrate from Wasmtime itself, typically a "private"dependency of Wasmtime, is used to parse the input component and
generate an
instantiatefunction in JS. Wasmtime does all the heavylifting of creating a linear list of initializers for the component
and this empowers the generator to simply generate JS that is the list
of initializers.
The
wit-componentcrate is used to "extract" theInterfacedescriptions from the input component. This is used to generate type
information for TypeScript as well as types for lifting/lowering.
Internally a correlation is done from a lowering/lifting to an
Interfacefunction to connect the dots when instantiating a component.Lots of pieces needed updating here such as the runtime tests, the
wit-bindgenCLI tool, and the demo web page. These are all updated forthe new structure of the JS host generator.
Overall this surprisingly went much more smoothly than I expected. With
wit-bindgenbeing able to extractInterfacerepresentations from acomponent most of the prior JS host code generation was able to be
reused. Along the way I also felt that the addition of "worlds" would
have relatively obvious insertion points and would be relatively easily
handled in all the places.
The demo and runtime tests are proof enough to me at least that this all
works internally, and this feels like a solid foundation to iterate from
with the addition of worlds and continued support for JS hosts.