bytecodealliance / bytecodealliance/wasmtime

Add static type information to exported resources

Open
#8,562 8 comments 0 reactions 0 assignees View on GitHub
wasm-proposal:component-model wasmtime:api
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
121

Description

#### Problem

I use the following `.wit` to describe a WASM component which provides a long living _operator_ that is initialized once and then invoked multiple times to perform some operation:
````wit
world example {
export exports: interface {
resource operator {
init: static func(...) -> operator;
run: func(...) -> ...;
}
}
}
````

Using this component from a `wasmtime` host is somewhat unergonomic, because calling `call_init`
returns a `ResourceAny` instance, which doesn't carry any (static) type information.
Calling methods on this resource is thus very verbose (see below), and there is a risk of mixing up resources of different types.
````rust
let resource = component.exports().operator().call_init(&mut store, ...)
component.exports().operator().call_run(&mut store, resource, ...)
````

#### Feature

Ideally, the rust-representation of the resource returned from a WASM component would contain sufficient type information to allow its (and only its) methods to be called with standard method syntax.

#### Benefit

Better ergonomics when working with resources (reduced error potential, less verbose syntax).

#### Implementation

It feels like this should not be too complicated, but maybe I'm missing something and what I'm suggesting isn't actually possible.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.