WebAssembly / component-model

Repository for design and specification of the Component Model
Other
933 stars 79 forks source link

How do ownership get enforced in component model? #189

Closed dannypsnl closed 1 year ago

dannypsnl commented 1 year ago

ownership & moving approach is only safe with linearly, how does component model ensure each component implements it?

lukewagner commented 1 year ago

Linearity is enforced dynamically by the component model's lifting/lowering rules; in particular, lifting an own handle removes (clears) the element in the source component instance's handle table such that subsequent uses of the same i32 handle index by core wasm will fail. You can see this dynamic logic in the Python pseudo-code described in CanonicalABI.md (see lift_own, which transitively calls transfer_or_drop). Thus, it's up to the source language toolchain/bindings to figure out how to avoid the error conditions either by static typing or dynamic proxy-object semantics (or not prevent it at all, as would be the case for C).

dannypsnl commented 1 year ago

This is a wrong question (by misunderstood own/borrow of CM), close this for now