Stream: git-wasmtime

Topic: wasmtime / PR #14384 component: fix ResourceAny conversio...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 00:28):

Byte-Naut opened PR #14384 from Byte-Naut:issue-7793 to bytecodealliance:main:

Closes #7793.

Motivation

Converting a Resource::<T>::new_borrow(rep) (or ResourceDynamic::new_borrow) into a ResourceAny eagerly inserted a borrow into the host resource table. That operation requires an active component call scope, so performing the conversion outside of a call reached bail_bug!("no current scope"), which panics in debug builds and returns a WasmtimeBug error in release builds. @rvolosatovs reported this in #7793 with a minimal reproducer, and @alexcrichton pointed out that borrow lowering has to be deferred until a call is actually in progress, the way Resource<T> already does it. The reproducer has been sitting commented out in can_use_own_for_borrow since then.

Changes

Design

The synthetic variant has no host table slot, so conversion, the typed round-trip, and resource_drop no longer need a call scope; resource_drop on such a value is a documented no-op. When the value is lowered into a guest borrow parameter, lower_to_index passes the rep straight to guest_resource_lower_borrow, which runs during the call and keeps guest-side borrow accounting intact: a guest that fails to drop the handle still traps with "borrow handles still remain at the end of the call". Lowering a synthetic borrow as own keeps producing the existing "cannot lower a borrow resource into an own" error, and resource type checks run before either lowering path. Borrows lifted from a guest remain table-backed and keep their drop obligation, so nothing changes for embedders who never call new_borrow.

One behavior change worth calling out for review: previously, converting a new_borrow resource while a call was already active would create a table-backed borrow that had to be dropped before that call returned. That obligation no longer exists, which matches how Resource<T> borrows behave when passed directly. Happy to adjust if a different policy is preferred.

Testing

cargo test --test all component_model::resources

Locally: fmt, clippy, and the full component_model test suite pass. The baseline reproduces the BUG: no current scope panic on main.

Thanks to @rvolosatovs for the clear reproducer and root-cause analysis, and to @alexcrichton for pointing at the deferred-lowering approach. In line with the Bytecode Alliance AI tool policy: Claude was used to assist with analysis and drafting; I have reviewed and tested every change here and am accountable for it.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 00:28):

Byte-Naut requested dicej for a review on PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 00:28):

Byte-Naut requested wasmtime-core-reviewers for a review on PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 00:28):

Byte-Naut requested fitzgen for a review on PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 00:28):

Byte-Naut requested wasmtime-default-reviewers for a review on PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 01:52):

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

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 01:52):

github-actions[bot] added the label wasmtime:docs on PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 22:12):

fitzgen unassigned fitzgen from PR #14384 component: fix ResourceAny conversion of synthetic borrowed host resources.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 23 2026 at 22:12):

fitzgen commented on PR #14384:

Not particularly familiar with this area of code; gonna let @dicej handle this review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 25 2026 at 14:47):

:thumbs_up: dicej submitted PR review:

Thanks, @Byte-Naut!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 25 2026 at 14:48):

dicej added PR #14384 component: fix ResourceAny conversion of synthetic borrowed host resources to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 25 2026 at 15:15):

:check: dicej merged PR #14384.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 25 2026 at 15:15):

dicej removed PR #14384 component: fix ResourceAny conversion of synthetic borrowed host resources from the merge queue.


Last updated: Oct 11 2026 at 02:20 UTC