bytecodealliance / bytecodealliance/wit-bindgen

Ownership of resource handles

Offen
#148 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
resources
Vorherrschende Sprache
Rust
Sterne
1.5k
Forks
286
Ø Merge
6 Std. 32 Min.
Gemergte PRs (30 T.)
19

Beschreibung

I'm would like to use wit to generate host/wasmtime and guest/rust bindings for [lunatic](https://github.com/lunatic-solutions/lunatic). However, I'm still not sure how to correctly model a specific use case.

In lunatic some of the host resources can be sent between different instances. This means that they are consumed by some host functions and removed from the resource table. This doesn't work well with the current [Canonical ABI proposal](https://github.com/WebAssembly/interface-types/blob/40f157ad429772c2b6a8b66ce7b4df01e83ae76d/proposals/interface-types/CanonicalABI.md) that requires all resources to expose a `clone` and `drop` API and implies reference counting.

One workaround is to keep the host resource inside of an `Option` and remove it once it needs to be sent to another instance. Then on every invocation of a host function dealing with the resource check if the value is `Some(T)`. This works okish.

The bigger issues here is that the guest side generated code also generates a `Clone` and `Drop` implementation. We would like to avoid exposing the `Clone` functionality to developers though. It would make the API better reflect the underlaying properties of the resource. Is there a way of disabling this `Clone` option, and ideally not even use reference counting inside of the host in this case?

I guess my question i more general. How to handle this specific scenario with interface types, when the function "consumes" the resource?

I also feel like I didn't completely understand the difference between a resource and a resource handle. Maybe the automatic cloning can be avoided if using resources directly, instead of handles?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit dem verlinkten Canonical ABI proposal und den im Issue beschriebenen host/wasmtime- und guest/rust-bindings. Ermittle, wie das Konsumieren von Ressourcen, das Deaktivieren generierter Clone- und Drop-Implementierungen und das Vermeiden der Referenzzählung auf der Host-Seite modelliert werden sollten; dokumentiere den unterstützten Ansatz und dessen Abschlusskriterien.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust, wasm
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.