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

Add support for Wasmer in Witty #945

Merged
merged 14 commits into from
Aug 14, 2023
Merged

Add support for Wasmer in Witty #945

merged 14 commits into from
Aug 14, 2023

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Aug 11, 2023

Motivation

The new Witty crate should generate host code that's compatible with the Wasmer runtime.

Proposal

Create a feature gated wasmer module in linera_witty::runtime, with implementations for the Witty traits. There are two Instance implementations, one for newly created instances (EntrypointInstance) and one for instances made available inside host functions called by the guest module (ReentrantInstance).

Test Plan

Reuse the integration tests for wit_import.

Links

Part of #906

Release Plan

  • All good!
  • Need to bump the major/minor version number in the next release of the crates.
  • Need to update the developer manual.
  • This PR is adding or removing Cargo features.
  • Release is blocked and/or tracked by other issues (see links above)

Reviewer Checklist

  • The title and the summary of the PR are short and descriptive.
  • The proposed solution achieves the goals stated in the PR.
  • The test plan is reproducible and provides sufficient coverage.
  • The release plan is adequate.
  • The commits correspond to distinct logical changes.
  • The code follows the coding guidelines.
  • The proposed changes look correct.
  • The CI is passing.
  • All of the above!

jvff added 5 commits August 11, 2023 15:32
Prepare to add support for Wasmer in an optional manner.
Implement the `Runtime` trait for it.
A type to make it easier to handle a Wasmer guest instance while it is
being initialized.
Share the actual `wasmer::Instance` type with reentrant calls.
A type to help with the construction of an `EntrypointInstance`.
@jvff jvff added the enhancement New feature or request label Aug 11, 2023
@jvff jvff added this to the Devnet milestone Aug 11, 2023
@jvff jvff requested a review from ma2bd August 11, 2023 15:36
@jvff jvff self-assigned this Aug 11, 2023
@jvff jvff mentioned this pull request Aug 10, 2023
14 tasks
jvff added 4 commits August 12, 2023 02:55
Add a trait to help with the implementation of `InstanceWithFunction`
for Wasmer instance types.
Add a trait to help with the implementation of `InstanceWithFunction`
for Wasmer instance types.
Allow calling imported functions using Wasmer.
Allow loading and storing `WitType`s in the memory of Wasmer guest
instances.
@jvff jvff force-pushed the witty-wasmer branch 3 times, most recently from 26b236b to 9e0f76a Compare August 12, 2023 11:06
Copy link
Contributor

@ma2bd ma2bd left a comment

Choose a reason for hiding this comment

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

LGTM!

impl_instance_with_function!(@generate(ReentrantInstance<'_>) $( $names: $types ),*);
};

(@generate($instance:ty) $( $names:ident : $types:ident ),*) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Seems like you just need another macro instead of using @generate(..) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

///
/// The maximum number of parameters is defined by the [canonical
/// ABI](https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#flattening)
/// as the `MAX_FLAT_PARAMS` constant.
Copy link
Contributor

Choose a reason for hiding this comment

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

The value 16 is hardcoded in this library in various places, right? Maybe explain this in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I tried to improve the related documentation and mentioned the MAX_FLAT_* constants so it's easier to grep for them.

jvff added 4 commits August 14, 2023 20:56
Allow the type that exported host functions receive to be able to call
imported guest functions reentrantly.
Some simple Wasm modules that will be used during some integration
tests.
Reuse the integration tests for `wit_import` using a Wasmer instance.
Build the test modules and run the integration tests with the `wasmer`
feature enabled.
Include the name of the constant from the specification, to improve
searchability and describe how it's handled in Witty.
@jvff jvff merged commit 271199e into linera-io:main Aug 14, 2023
@jvff jvff deleted the witty-wasmer branch August 14, 2023 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants