Commit Graph

170 Commits

Author SHA1 Message Date
Pat Hickey
ab4f5bb674 move dummy executor out to wiggle:: for reuse 2021-04-29 16:26:50 -07:00
Pat Hickey
228096c840 wiggle: convenient syntax for marking all funcs async 2021-04-14 14:51:24 -07:00
Pat Hickey
201da20c63 make wasmtime-wasi configurable at macro whether its real async or block_on 2021-04-13 17:51:18 -07:00
Pat Hickey
c62d7f9ea1 wasmtime_wiggle: when async feature is disabled, run async on dummy executor 2021-04-13 17:51:18 -07:00
Chris Fallin
6bec13da04 Bump versions: Wasmtime to 0.26.0, Cranelift to 0.73.0. 2021-04-05 10:48:42 -07:00
Pat Hickey
0508394c62 Revert "wiggle: generate a span that is present at all levels"
This reverts commit 0466f47cb4.
2021-04-01 09:33:37 -07:00
Pat Hickey
e38166ac3f wiggle::async_trait is defined as async_trait::async_trait(?Send)
async methods used by wiggle currently need to Not have the Send
constraint, so rather than make all use sites pass the argument
to the re-exported async_trait macro, define a new macro that
applies the argument.
2021-03-29 10:04:42 -07:00
Pat Hickey
0a255c19de Merge pull request #2782 from bytecodealliance/pch/wiggle_tracing_span_fix
wiggle: generate a span that is present at all levels
2021-03-28 15:04:33 -07:00
Pat Hickey
8da3de6756 wiggle-wasmtime: use fully qualified std::rc::Rc<std::cell::RefCell<>> in expansion 2021-03-26 17:21:51 -07:00
Pat Hickey
0466f47cb4 wiggle: generate a span that is present at all levels
The code I wrote here prior was incorrect: a span is present at the
level specified and below; previously I thought it was present at the
level specified and above. So, previously, a TRACE-level event inside
this span would be associated with the module and function name provided
here. Now all events inside this span should be associated with it.
2021-03-26 14:25:10 -07:00
Pat Hickey
8bb1f8adc9 wasmtime-wiggle: make it possible to add host funcs to a config under an alias (#2761)
* wasmtime-wiggle: make it possible to add host funcs to a config under an alias

* remove debugging printlns
2021-03-25 15:31:45 -05:00
Pat Hickey
df18b44c53 oops 2021-03-24 11:37:42 -07:00
Pat Hickey
1c4af27f2d delete GuestErrorConversion from docs, tests 2021-03-23 22:20:29 -07:00
Pat Hickey
f74b0291ad dead code: remove GuestErrorConversion, it now is never called 2021-03-23 22:14:49 -07:00
Pat Hickey
4a9ce90d34 GuestError::InDataField never constructed, so delete it 2021-03-23 22:04:34 -07:00
Pat Hickey
1151f630b8 wiggle GuestError: improve Display of InFunc, InDataField 2021-03-23 22:03:25 -07:00
Benjamin Bouvier
4603b3b292 Bump dependencies to get a single version of rand (#2733)
This removes a few crates in the dependencies, and a few exceptions (at
the price of a new one) in the cargo-deny configuration.
2021-03-17 09:07:50 -05:00
Nick Fitzgerald
d081ef9c2e Bump Wasmtime to 0.25.0; Cranelift to 0.72.0 2021-03-16 11:02:56 -07:00
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