Skip to content

Collapse resource tables to be per-instance, not per-resource#10701

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:collapse-resource-tables
Apr 30, 2025
Merged

Collapse resource tables to be per-instance, not per-resource#10701
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:collapse-resource-tables

Conversation

@alexcrichton
Copy link
Member

This commit is an update to how Wasmtime represents and processes resource handles for components. The upstream specification changed in WebAssembly/component-model#427 and while it's been awhile since that change this is Wasmtime catching up to that change. It's expected that these paths are going to get stressed more with component model async and more kinds of handles so this additionally refactors things to leave sort of "holes" where async resources are going to go.

This notably will result in different behavior for guest programs. Previously if there were two resources imported into a guest they could have overlapping indices and now they're going to all have disjoint indices since they're all in the same index space. It's expected that this is will have a minimal, if any, impact on component guests as in theory they're all mostly treating handles as opaque indexes today anyway.

This commit is an update to how Wasmtime represents and processes
resource handles for components. The upstream specification changed in
WebAssembly/component-model#427 and while it's been awhile since that
change this is Wasmtime catching up to that change. It's expected that
these paths are going to get stressed more with component model async
and more kinds of handles so this additionally refactors things to leave
sort of "holes" where async resources are going to go.

This notably will result in different behavior for guest programs.
Previously if there were two resources imported into a guest they could
have overlapping indices and now they're going to all have disjoint
indices since they're all in the same index space. It's expected that
this is will have a minimal, if any, impact on component guests as in
theory they're all mostly treating handles as opaque indexes today
anyway.
@alexcrichton alexcrichton requested a review from a team as a code owner April 30, 2025 21:13
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team April 30, 2025 21:13
@alexcrichton
Copy link
Member Author

cc @dicej

@alexcrichton
Copy link
Member Author

I'll also note that the original motivation for this spec change, WebAssembly/component-model#395, also detailed improved error messages from runtime about mismatches in index types. For example the original issue was importing two versions of wasi:io/poll and accidentally crossing handle indexes between the two. This PR doesn't go so far to attach debugging names to resources so it's known how to inform the users/components what exactly a mismatch was, it only says "expected resource found different resource" effectively. I've left the improvement of error messages to a future PR.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alexcrichton alexcrichton added this pull request to the merge queue Apr 30, 2025
Merged via the queue into bytecodealliance:main with commit 28e26fd Apr 30, 2025
41 checks passed
@alexcrichton alexcrichton deleted the collapse-resource-tables branch April 30, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants