-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement support for async
functions in Wasmtime
#2434
Merged
Merged
Commits on Feb 26, 2021
-
Implement support for
async
functions in WasmtimeThis is an implementation of [RFC 2] in Wasmtime which is to support `async`-defined host functions. At a high level support is added by executing WebAssembly code that might invoke an asynchronous host function on a separate native stack. When the host function's future is not ready we switch back to the main native stack to continue execution. There's a whole bunch of details in this commit, and it's a bit much to go over them all here in this commit message. The most important changes here are: * A new `wasmtime-fiber` crate has been written to manage the low-level details of stack-switching. Unixes use `mmap` to allocate a stack and Windows uses the native fibers implementation. We'll surely want to refactor this to move stack allocation elsewhere in the future. Fibers are intended to be relatively general with a lot of type paremters to fling values back and forth across suspension points. The whole crate is a giant wad of `unsafe` unfortunately and involves handwritten assembly with custom dwarf CFI directives to boot. Definitely deserves a close eye in review! * The `Store` type has two new methods -- `block_on` and `on_fiber` which bridge between the async and non-async worlds. Lots of unsafe fiddly bits here as we're trying to communicate context pointers between disparate portions of the code. Extra eyes and care in review is greatly appreciated. * The APIs for binding `async` functions are unfortunately pretty ugly in `Func`. This is mostly due to language limitations and compiler bugs (I believe) in Rust. Instead of `Func::wrap` we have a `Func::wrapN_async` family of methods, and we've also got a whole bunch of `Func::getN_async` methods now too. It may be worth rethinking the API of `Func` to try to make the documentation page actually grok'able. This isn't super heavily tested but the various test should suffice for engaging hopefully nearly all the infrastructure in one form or another. This is just the start though! [RFC 2]: bytecodealliance/rfcs#2
Configuration menu - View commit details
-
Copy full SHA for c471a1c - Browse repository at this point
Copy the full SHA c471a1cView commit details -
Configuration menu - View commit details
-
Copy full SHA for e46bccb - Browse repository at this point
Copy the full SHA e46bccbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 20833b5 - Browse repository at this point
Copy the full SHA 20833b5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 549461c - Browse repository at this point
Copy the full SHA 549461cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 30993d6 - Browse repository at this point
Copy the full SHA 30993d6View commit details -
Implement periodically yielding with fuel consumption
This commit implements APIs on `Store` to periodically yield execution of futures through the consumption of fuel. When fuel runs out a future's execution is yielded back to the caller, and then upon resumption fuel is re-injected. The goal of this is to allow cooperative multi-tasking with futures.
Configuration menu - View commit details
-
Copy full SHA for d94648c - Browse repository at this point
Copy the full SHA d94648cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 06974ac - Browse repository at this point
Copy the full SHA 06974acView commit details -
Save/restore the frame pointer in fiber switching
Turns out this is another caller-saved register!
Configuration menu - View commit details
-
Copy full SHA for 0e243da - Browse repository at this point
Copy the full SHA 0e243daView commit details -
Take a leaf out of aarch64's playbook and don't have extra memory to load/store these arguments, instead leverage how `wasmtime_fiber_switch` already loads a bunch of data into registers which we can then immediately start using on a fiber's start without any extra memory accesses.
Configuration menu - View commit details
-
Copy full SHA for f6a211b - Browse repository at this point
Copy the full SHA f6a211bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5996126 - Browse repository at this point
Copy the full SHA 5996126View commit details -
Configuration menu - View commit details
-
Copy full SHA for 44c73e8 - Browse repository at this point
Copy the full SHA 44c73e8View commit details -
Configuration menu - View commit details
-
Copy full SHA for d837e47 - Browse repository at this point
Copy the full SHA d837e47View commit details -
Configuration menu - View commit details
-
Copy full SHA for 625e9c9 - Browse repository at this point
Copy the full SHA 625e9c9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4951df8 - Browse repository at this point
Copy the full SHA 4951df8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5026144 - Browse repository at this point
Copy the full SHA 5026144View commit details -
Tweak async fuel to eventually run out.
With fuel it's probably best to not provide any way to inject infinite fuel.
Configuration menu - View commit details
-
Copy full SHA for ca4c492 - Browse repository at this point
Copy the full SHA ca4c492View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0aa739a - Browse repository at this point
Copy the full SHA 0aa739aView commit details -
* Use a shared header file to deduplicate some directives * Guarantee hidden visibility for functions * Enable gc-sections on macOS x86_64 * Add `.type` annotations for ARM
Configuration menu - View commit details
-
Copy full SHA for 77a2f7e - Browse repository at this point
Copy the full SHA 77a2f7eView commit details -
Configuration menu - View commit details
-
Copy full SHA for a8d73f0 - Browse repository at this point
Copy the full SHA a8d73f0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 663a3f7 - Browse repository at this point
Copy the full SHA 663a3f7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 807a226 - Browse repository at this point
Copy the full SHA 807a226View commit details
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.