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

Initial skeleton of some component model processing #4005

Merged
merged 2 commits into from
May 20, 2022

Conversation

alexcrichton
Copy link
Member

This commit is the first of what will likely be many to implement the
component model proposal in Wasmtime. This will be structured as a
series of incremental commits, most of which haven't been written yet.
My hope is to make this incremental and over time to make this easier to
review and easier to test each step in isolation.

Here much of the skeleton of how components are going to work in
Wasmtime is sketched out. This is not a complete implementation of the
component model so it's not all that useful yet, but some things you can
do are:

  • Process the type section into a representation amenable for working
    with in Wasmtime.
  • Process the module section and register core wasm modules.
  • Process the instance section for core wasm modules.
  • Process core wasm module imports.
  • Process core wasm instance aliasing.
  • Ability to compile a component with core wasm embedded.
  • Ability to instantiate a component with no imports.
  • Ability to get functions from this component.

This is already starting to diverge from the previous module linking
representation where a Component will try to avoid unnecessary
metadata about the component and instead internally only have the bare
minimum necessary to instantiate the module. My hope is we can avoid
constructing most of the index spaces during instantiation only for it
to all ge thrown away. Additionally I'm predicting that we'll need to
see through processing where possible to know how to generate adapters
and where they are fused.

At this time you can't actually call a component's functions, and that's
the next PR that I would like to make.

@alexcrichton alexcrichton added the wasm-proposal:component-model Issues related to the WebAssembly Component Model proposal label Apr 7, 2022
@alexcrichton
Copy link
Member Author

It's worth pointing out that this is starting out as a draft PR. The main reason for this is that there aren't actually any tests in this PR for that. For tests I'm think we'll need bytecodealliance/wasm-tools#529 which is the text format for components. Tests can probably be written in the meantime with wasm-encoder but I'm hoping we won't have to resort to that.

@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Apr 7, 2022
@github-actions
Copy link

github-actions bot commented Apr 7, 2022

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasm-proposal: component-model", "wasmtime:api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions
Copy link

github-actions bot commented Apr 7, 2022

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo tests! I'll take another look at this once those are written

crates/environ/src/component/info.rs Outdated Show resolved Hide resolved
crates/environ/src/component/info.rs Outdated Show resolved Hide resolved
crates/environ/src/component/info.rs Outdated Show resolved Hide resolved
crates/environ/src/component/info.rs Outdated Show resolved Hide resolved
crates/environ/src/component/translate.rs Outdated Show resolved Hide resolved
crates/environ/src/component/translate.rs Outdated Show resolved Hide resolved
.translate(parser.clone(), &component[range.start..range.end])?;
let upvar_idx = self.result.upvars.push(translation);
self.result.modules.push(ModuleDef::Upvar(upvar_idx));
return Ok(Action::Skip(range.end - range.start));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we added a len method to wasmparser::Range.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider me sufficiently inspired

crates/environ/src/component/translate.rs Outdated Show resolved Hide resolved
crates/environ/src/component/types.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/instance.rs Outdated Show resolved Hide resolved
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Apr 15, 2022
This commit removes `wasmparser::Range` and instead uses
`std::ops::Range<usize>` instead. This is inspired by review on
bytecodealliance/wasmtime#4005 where it's more convenience to have all
the libstd methods available.
@alexcrichton
Copy link
Member Author

Ok with bytecodealliance/wasm-tools#529 landed I've now started writing tests for this PR. Once all the pending PRs on wasm-tools are landed I'll make a release and then this should be ready-for-landing after another round of review.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:wasm fuzzing Issues related to our fuzzing infrastructure labels May 18, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:wasm", "fuzzing"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions github-actions bot added cranelift:module wasmtime:c-api Issues pertaining to the C API. labels May 19, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "cranelift:module", "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request May 19, 2022
This commit updates these crates as used by Wasmtime for the recently
published versions to pull in changes necessary to support the component
model. I've split this out from bytecodealliance#4005 to make it clear what's impacted
here and bytecodealliance#4005 can simply rebase on top of this to pick up the necessary
changes.
alexcrichton added a commit that referenced this pull request May 19, 2022
* Update the wasm-tools family of crates

This commit updates these crates as used by Wasmtime for the recently
published versions to pull in changes necessary to support the component
model. I've split this out from #4005 to make it clear what's impacted
here and #4005 can simply rebase on top of this to pick up the necessary
changes.

* More test fixes
This commit is the first of what will likely be many to implement the
component model proposal in Wasmtime. This will be structured as a
series of incremental commits, most of which haven't been written yet.
My hope is to make this incremental and over time to make this easier to
review and easier to test each step in isolation.

Here much of the skeleton of how components are going to work in
Wasmtime is sketched out. This is not a complete implementation of the
component model so it's not all that useful yet, but some things you can
do are:

* Process the type section into a representation amenable for working
  with in Wasmtime.
* Process the module section and register core wasm modules.
* Process the instance section for core wasm modules.
* Process core wasm module imports.
* Process core wasm instance aliasing.
* Ability to compile a component with core wasm embedded.
* Ability to instantiate a component with no imports.
* Ability to get functions from this component.

This is already starting to diverge from the previous module linking
representation where a `Component` will try to avoid unnecessary
metadata about the component and instead internally only have the bare
minimum necessary to instantiate the module. My hope is we can avoid
constructing most of the index spaces during instantiation only for it
to all ge thrown away. Additionally I'm predicting that we'll need to
see through processing where possible to know how to generate adapters
and where they are fused.

At this time you can't actually call a component's functions, and that's
the next PR that I would like to make.
This commit uses the recently updated wasm-tools crates to add tests for
the component model added in the previous commit. This involved updating
the `wasmtime-wast` crate for component-model changes. Currently the
component support there is quite primitive, but enough to at least
instantiate components and verify the internals of Wasmtime are all
working correctly. Additionally some simple tests for the embedding API
have also been added.
@alexcrichton alexcrichton marked this pull request as ready for review May 19, 2022 19:13
@alexcrichton
Copy link
Member Author

Ok everything is now ready to go here and I think that this is good to land.

@fitzgen would you be up for reviewing the tests added here? (sorry I know this is quite late relative to the previous review and this is probably pretty far out of cache for you...)

@fitzgen
Copy link
Member

fitzgen commented May 19, 2022

Yeah I can take a look tomorrow.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@alexcrichton alexcrichton merged commit fcf6208 into bytecodealliance:main May 20, 2022
@alexcrichton alexcrichton deleted the component-model branch May 20, 2022 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:module cranelift:wasm cranelift Issues related to the Cranelift code generator fuzzing Issues related to our fuzzing infrastructure wasm-proposal:component-model Issues related to the WebAssembly Component Model proposal wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:config Issues related to the configuration of Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants