alexcrichton opened PR #7130 from alexcrichton:refactor-subscribe
to bytecodealliance:main
:
This commit refactors how the
Pollable
resource is created in WASI. Previously this was created manually via two variants of aPollable
enum but this was somewhat error prone for a few reasons:
The more common representation,
TableEntry
, had boilerplate associated with it that had dynamic downcasts and such. This is now all hidden behind a more typed API.Callers had to remember to use
push_child_resource
which is easy to forget.The previous signature of the readiness check returned a
Result<()>
which made it accidentally easy for errors to be propagated into traps rather than being returned as a "last operation failed" error.This commit replaces the previous API with a single
subscribe
function which takes aResource<T>
and returns aResource<Pollable>
. TheT
type must implement a new trait,Subscribe
, which indicates the asynchronous readiness check. This readiness check additionally returns()
so it's no longer possible to accidentally return errors (or trap).This namely required refactoring the
HostOutputStream
trait and implementations. The trait itself now has acheck_write
method corresponding to to the same WASI function. The oldwrite_ready
function is now a convenience helper combo betweenready
andcheck_write
. Concrete implementations are refactored to store errors discovered duringready
to get communicated throughcheck-write
later on.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested pchickey for a review on PR #7130.
alexcrichton requested wasmtime-core-reviewers for a review on PR #7130.
pchickey requested elliottt for a review on PR #7130.
pchickey submitted PR review:
This is a really nice improvement given all the safety changes. Thanks!
alexcrichton merged PR #7130.
Last updated: Dec 23 2024 at 13:07 UTC