Stream: git-wasmtime

Topic: wasmtime / PR #12550 Refactor borrow state tracking for a...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 19:47):

alexcrichton opened PR #12550 from alexcrichton:remove-call-contexts to bytecodealliance:main:

This commit is a somewhat deep refactoring of how the state of
borrow<T> is managed for both the host and the guest with respect to
async tasks. This additionally refactors how some async task management
is done for host-called functions.

The fundamental problem being tackled here is https://github.com/bytecodealliance/wasmtime/issues/12510. In that issue it
was discovered that the way CallContext, the borrow tracking mechanism
in Wasmtime, is managed is incompatible with async tasks. Specifically
the previous assumption of the scope being mutated for a borrow is
somewhere on the call stack is no longer true. It's possible for an
async task to be suspended, for example, and then a sibling task drops a
borrow which should update the scope of the suspended task. There were a
number of other small issues I noticed here and there which this PR
additionally has tests for, all of which failed before this change and
pass afterwards.

The manner in which borrow state is manipulated is a pretty old part of
the component model implementation dating back to the original
implementation of resources. I decided to forgo any possible quick fix
and have attempted to more deeply refactor and integrate async tasks
into all of this infrastructure. A list of the changes made here are:

Overall this enables the *.wast test for https://github.com/bytecodealliance/wasmtime/issues/12510 to fix the original
issue. This then adds new tests to ensure that cleanup of various
constructs happens appropriately, such as cancelling a host task should
clean up its associated resources. Additionally synchronously calling an
async host task no longer leaks resources in a Store and should
properly clean up everything.

There is still more work to do in this area (e.g. https://github.com/bytecodealliance/wasmtime/issues/12544) but that's
going to be deferred to a future PR at this point.

Closes https://github.com/bytecodealliance/wasmtime/issues/12510

Depends on https://github.com/bytecodealliance/wasmtime/pull/12545, https://github.com/bytecodealliance/wasmtime/pull/12546, https://github.com/bytecodealliance/wasmtime/pull/12547, https://github.com/bytecodealliance/wasmtime/pull/12548, and https://github.com/bytecodealliance/wasmtime/pull/12549

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 19:47):

alexcrichton requested wasmtime-core-reviewers for a review on PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 19:47):

alexcrichton requested fitzgen for a review on PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 19:47):

alexcrichton requested wasmtime-compiler-reviewers for a review on PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 19:47):

alexcrichton updated PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 20:57):

github-actions[bot] added the label wasmtime:api on PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 22:02):

alexcrichton updated PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 22:02):

alexcrichton edited PR #12550:

This commit is a somewhat deep refactoring of how the state of
borrow<T> is managed for both the host and the guest with respect to
async tasks. This additionally refactors how some async task management
is done for host-called functions.

The fundamental problem being tackled here is https://github.com/bytecodealliance/wasmtime/issues/12510. In that issue it
was discovered that the way CallContext, the borrow tracking mechanism
in Wasmtime, is managed is incompatible with async tasks. Specifically
the previous assumption of the scope being mutated for a borrow is
somewhere on the call stack is no longer true. It's possible for an
async task to be suspended, for example, and then a sibling task drops a
borrow which should update the scope of the suspended task. There were a
number of other small issues I noticed here and there which this PR
additionally has tests for, all of which failed before this change and
pass afterwards.

The manner in which borrow state is manipulated is a pretty old part of
the component model implementation dating back to the original
implementation of resources. I decided to forgo any possible quick fix
and have attempted to more deeply refactor and integrate async tasks
into all of this infrastructure. A list of the changes made here are:

Overall this enables the *.wast test for https://github.com/bytecodealliance/wasmtime/issues/12510 to fix the original
issue. This then adds new tests to ensure that cleanup of various
constructs happens appropriately, such as cancelling a host task should
clean up its associated resources. Additionally synchronously calling an
async host task no longer leaks resources in a Store and should
properly clean up everything.

There is still more work to do in this area (e.g. https://github.com/bytecodealliance/wasmtime/issues/12544) but that's
going to be deferred to a future PR at this point.

Closes https://github.com/bytecodealliance/wasmtime/issues/12510

~~Depends on https://github.com/bytecodealliance/wasmtime/pull/12545, https://github.com/bytecodealliance/wasmtime/pull/12546, https://github.com/bytecodealliance/wasmtime/pull/12547, https://github.com/bytecodealliance/wasmtime/pull/12548, and https://github.com/bytecodealliance/wasmtime/pull/12549~~

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 22:47):

fitzgen submitted PR review:

I'm not too familiar with the CM async stuff, but this LGTM in general. If you want more detailed feedback, flag another reviewer :)

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 22:51):

alexcrichton requested dicej for a review on PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 23:49):

dicej created PR review comment:

Consider renaming expected_caller_instance to expected_caller here since it's no longer an instance.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 23:49):

dicej created PR review comment:

As above, consider renaming this to expected_caller.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2026 at 23:49):

dicej submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 02:52):

alexcrichton updated PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 02:52):

alexcrichton has enabled auto merge for PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 03:15):

alexcrichton added PR #12550 Refactor borrow state tracking for async tasks to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 03:41):

alexcrichton merged PR #12550.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 03:41):

alexcrichton removed PR #12550 Refactor borrow state tracking for async tasks from the merge queue.


Last updated: Feb 24 2026 at 04:36 UTC