Commit Graph

202 Commits

Author SHA1 Message Date
Peter Huene
54c07d8f16 Implement shared host functions. (#2625)
* Implement defining host functions at the Config level.

This commit introduces defining host functions at the `Config` rather than with
`Func` tied to a `Store`.

The intention here is to enable a host to define all of the functions once
with a `Config` and then use a `Linker` (or directly with
`Store::get_host_func`) to use the functions when instantiating a module.

This should help improve the performance of use cases where a `Store` is
short-lived and redefining the functions at every module instantiation is a
noticeable performance hit.

This commit adds `add_to_config` to the code generation for Wasmtime's `Wasi`
type.

The new method adds the WASI functions to the given config as host functions.

This commit adds context functions to `Store`: `get` to get a context of a
particular type and `set` to set the context on the store.

For safety, `set` cannot replace an existing context value of the same type.

`Wasi::set_context` was added to set the WASI context for a `Store` when using
`Wasi::add_to_config`.

* Add `Config::define_host_func_async`.

* Make config "async" rather than store.

This commit moves the concept of "async-ness" to `Config` rather than `Store`.

Note: this is a breaking API change for anyone that's already adopted the new
async support in Wasmtime.

Now `Config::new_async` is used to create an "async" config and any `Store`
associated with that config is inherently "async".

This is needed for async shared host functions to have some sanity check during their
execution (async host functions, like "async" `Func`, need to be called with
the "async" variants).

* Update async function tests to smoke async shared host functions.

This commit updates the async function tests to also smoke the shared host
functions, plus `Func::wrap0_async`.

This also changes the "wrap async" method names on `Config` to
`wrap$N_host_func_async` to slightly better match what is on `Func`.

* Move the instance allocator into `Engine`.

This commit moves the instantiated instance allocator from `Config` into
`Engine`.

This makes certain settings in `Config` no longer order-dependent, which is how
`Config` should ideally be.

This also removes the confusing concept of the "default" instance allocator,
instead opting to construct the on-demand instance allocator when needed.

This does alter the semantics of the instance allocator as now each `Engine`
gets its own instance allocator rather than sharing a single one between all
engines created from a configuration.

* Make `Engine::new` return `Result`.

This is a breaking API change for anyone using `Engine::new`.

As creating the pooling instance allocator may fail (likely cause is not enough
memory for the provided limits), instead of panicking when creating an
`Engine`, `Engine::new` now returns a `Result`.

* Remove `Config::new_async`.

This commit removes `Config::new_async` in favor of treating "async support" as
any other setting on `Config`.

The setting is `Config::async_support`.

* Remove order dependency when defining async host functions in `Config`.

This commit removes the order dependency where async support must be enabled on
the `Config` prior to defining async host functions.

The check is now delayed to when an `Engine` is created from the config.

* Update WASI example to use shared `Wasi::add_to_config`.

This commit updates the WASI example to use `Wasi::add_to_config`.

As only a single store and instance are used in the example, it has no semantic
difference from the previous example, but the intention is to steer users
towards defining WASI on the config and only using `Wasi::add_to_linker` when
more explicit scoping of the WASI context is required.
2021-03-11 10:14:03 -06:00
Pat Hickey
ccdf6ec0b1 Merge pull request #2701 from bytecodealliance/pch/wiggle_async
wiggle: support for Rust async
2021-03-05 10:43:55 -08:00
Pat Hickey
84df5fa54a use the async keyword as syntax in the macro invocation 2021-03-05 08:58:54 -08:00
Dan Gohman
8854dec01d Bump version to 0.24.0
I used a specially modified version of the publish script to avoid
bumping the `witx` version.
2021-03-04 18:17:03 -08:00
Pat Hickey
ff59797ad0 wasmtime_wiggle: support for async, and add an integration test 2021-03-04 18:16:37 -08:00
Pat Hickey
c4d8e2323a wiggle tests: fixes for new syntax 2021-03-04 18:16:36 -08:00
Pat Hickey
f11cd8e7b1 wiggle: add support for async traits; ABI func is now generic of ctx
* ctx parameter no longer accepted by wiggle::from_witx macro.
* optional async_ parameter specifies which functions are async.
* re-export async_trait::async_trait, so users don't have to take a dep.
2021-03-04 18:16:36 -08:00
Pat Hickey
1fe97ea31e rename some wiggle tests to reflect new witx ast names
arrays are now lists
structs are now records
unions are now variants

this ruins some of my union puns, oh well
2021-02-18 15:06:16 -08:00
Alex Crichton
136755ade2 Fix wiggle trace example 2021-02-18 14:45:20 -08:00
Alex Crichton
fa98f0bc91 Fix wiggle tests 2021-02-18 14:45:20 -08:00
Alex Crichton
df9c725fa0 Update to the next version of the witx crate
This commit updates to the 0.9 version of the witx crate implemented in
WebAssembly/wasi#395. This new version drastically changes code
generation and how we interface with the crate. The intention is to
abstract the code generation aspects and allow code generators to
implement much more low-level instructions to enable more flexible APIs
in the future. Additionally a bunch of `*.witx` files were updated in
the WASI repository.

It's worth pointing out, however, that `wasi-common` does not change as
a result of this change. The shape of the APIs that we need to implement
are effectively the same and the only difference is that the shim
functions generated by wiggle are a bit different.
2021-02-18 14:45:20 -08:00
Dan Gohman
8d90ea0390 Bump version to 0.23.0
I used a specially modified version of the publish script to avoid
bumping the `witx` version.
2021-02-17 15:35:43 -08:00
Pat Hickey
70f8288ec9 wasmtime-wiggle: take an Rc<RefCell<ctx>> instead of construct one
so that if users wish to share a ctx between modules they may!
2021-01-29 12:18:21 -08:00
Pat Hickey
ed44a19e5e wiggle: use bitflags to generate flags
more consistient with the rest of the ecosystem.
2021-01-11 18:20:57 -08:00
Pat Hickey
e2fb99af86 wiggle: depend on bitflags, and re-export it. 2021-01-11 18:04:43 -08:00
Pat Hickey
94467bcd9a wiggle: bugfix, generated code should use Names::runtime_mod not wiggle
as the crate from which these deps come.

I worked around this in lucet, but I'll be able to revert that
workaround.
2021-01-11 18:03:48 -08:00
Nick Fitzgerald
5de5bf1565 Merge pull request #2550 from bytecodealliance/pch/wiggle_trapping
wiggle: introduce Trap enum
2021-01-07 16:23:21 -08:00
Nick Fitzgerald
5ad82de3c5 Bump Wasmtime to 0.22.0; Cranelift to 0.69.0 2021-01-07 14:51:12 -08:00
Pat Hickey
07c9b65fa4 fix 2021-01-07 11:45:11 -08:00
Pat Hickey
ec1bfeefb3 fix tests 2021-01-07 11:45:11 -08:00
Pat Hickey
cd3adb1abd Trap::I32Exit is a better name 2021-01-07 11:45:11 -08:00
Pat Hickey
745c592863 readme: expand wiggle docs 2021-01-07 11:45:11 -08:00
Pat Hickey
f8f9b14c6f wiggle: introduce wiggle::Trap, which can be either a String or I32
also, make noreturn functions always return a Trap

wasmtime-wiggle can trivially turn a wiggle::Trap into a wasmtime::Trap.
lucet will have to do the same.
2021-01-07 11:45:11 -08:00
Pat Hickey
46b1864c9e wiggle-wasmtime: get rid of "missing_memory" error code, we can Trap now
the missing memory behavior was always a silly thing, that we generate a
function for wasmtime which is Result<_, Trap> we can just Err(Trap)
when the memory export is missing.
2021-01-05 17:28:03 -08:00
Tanya L. Crenshaw
b06ed39c1e Fixes #2418: Enhance wiggle to generate its UserErrorConverstion trait with a function that returns Result<abi_err, String> (#2419)
* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance the wiggle/wasmtime integration to leverage new work in ab7e9c6.  Hostcall
implementations generated by wiggle now return an Result<abi_error, Trap>.  As a
result, hostcalls experiencing fatal errors may trap, thereby terminating the
wasmtime instance.  This enhancement has been performed for both wasi snapshot1
and wasi snapshot0.

* Update wasi-nn crate to reflect enhancement in issue #2418.

* Update wiggle test-helpers for wiggle enhancement made in issue #2418.

* Address PR feedback; omit verbose return statement.

* Address PR feedback; manually format within a proc macro.

* Address PR feedback; manually format proc macro.

* Restore return statements to wasi.rs.

* Restore return statements in funcs.rs.

* Address PR feedback; omit TODO and fix formatting.

* Ok-wrap error type in assert statement.
2020-11-24 14:06:57 -06:00
Pat Hickey
2a937f06db fixes 2020-11-20 11:42:42 -08:00
Pat Hickey
6681e6786e debug assert could catch double-free 2020-11-20 11:20:40 -08:00
Pat Hickey
f5f180a8fe refactor is_borrowed/unborrow into shared/mut variants 2020-11-19 15:29:12 -08:00
Pat Hickey
f9de1d3e5c rename immutable borrows to shared borrows 2020-11-19 14:42:31 -08:00
Pat Hickey
3509883f2d wiggle: add test of overlapping immutable borrows 2020-11-18 15:02:02 -08:00
Pat Hickey
fc608e392b wiggle: make Mut variants of GuestStr, GuestPtr 2020-11-18 12:32:21 -08:00
Pat Hickey
78db3ff13b wiggle: borrow checker lives in own crate, and supports both mut/immut 2020-11-18 12:19:47 -08:00
Ulrich Weigand
a9d8abbf53 Support big-endian hosts with GuestType (#2383)
The GuestType trait is used to access data elements in guest memory.
According to the WebAssembly spec, those are always stored in
little-endian byte order, even on big-endian hosts.  Accessing such
elements on big-endian hosts therefore requires byte swapping.

Fixed by adding from_le_bytes / to_le_bytes.
2020-11-09 10:59:30 -06:00
Alex Crichton
e4c3fc5cf2 Update immediate and transitive dependencies
I don't think this has happened in awhile but I've run a `cargo update`
as well as trimming some of the duplicate/older dependencies in
`Cargo.lock` by updating some of our immediate dependencies as well.
2020-11-05 08:34:09 -08:00
Alex Crichton
ab1958434a Bump to 0.21.0 (#2359) 2020-11-05 09:39:53 -06:00
Alex Crichton
5e08eb3b83 Bump wasmtime to 0.20.0 (#2222)
At the same time bump cranelift crates to 0.67.0
2020-09-23 13:54:02 -05:00
Andrew Brown
31165d0e9b Print more information about types that cannot be generated by wiggle 2020-09-21 10:26:26 -07:00
Andrew Brown
97e0f4864c Fix typo 2020-09-21 10:26:26 -07:00
Pat Hickey
776f12ae3c tests: exercise array getters 2020-09-03 16:41:10 -07:00
Pat Hickey
580c236dee wiggle: implement array get/get_range in terms of ptr/add/as_array
hard to get it wrong when you use the safe primitives i already made!
2020-09-03 16:40:45 -07:00
Pat Hickey
b63e974014 code review fixes 2020-09-02 13:39:32 -07:00
Pat Hickey
7eb607b076 bugfix! 2020-09-02 10:55:27 -07:00
Pat Hickey
6213a05c85 wiggle: add array indexing methods to GuestPtr<[T]> 2020-09-01 13:50:31 -07:00
Pat Hickey
335886134c fix test 2020-08-28 17:11:11 -07:00
Pat Hickey
edefbf7c73 fix tests 2020-08-28 15:58:16 -07:00
Pat Hickey
91dac9c7e8 wiggle: witx paths use shell expansion
instead of always being relative to CARGO_MANIFEST_DIR, each use site is
responsible for either putting that variable or another one (set by a
build.rs) at the start of witx paths.
2020-08-28 15:42:48 -07:00
Pat Hickey
5c6ed0c736 wip - didnt have time to finish this before quittin time 2020-08-27 18:19:53 -07:00
Pat Hickey
82d2a48896 wiggle-wasmtime: witx paths should be relative to CARGO_MANIFEST_DIR, not WASI_ROOT
the WASI_ROOT was leftover from when this code was part of `wig`.
2020-08-27 16:03:05 -07:00
Pat Hickey
19e2a46aaf bump to latest wasi submodule
witx is now 0.8.6.
2020-08-17 15:58:56 -07:00
Pat Hickey
c268c9e79b wiggle: doc fixes 2020-08-13 11:20:19 -07:00