Stream: wit-bindgen

Topic: borrowing records? (shared data)


view this post on Zulip Christof Petig (Jul 29 2023 at 09:42):

When designing a WIT based API for a publisher subscriber scheme at AUTOSAR we came across the problem how to model single producer multiple consumer (with zero copy).
While I perfectly understand that full zero copy needs support from the host side, being able to express that the result of a host call has a specific structure (potentially containing lists and strings) but shouldn't be freed by the guest would help a lot. Basically returning a borrow<record-type> would be my preferred solution.
I can work around this by returning pointers or opaque resources but then I lose the easy language interoperability provided by WIT.

view this post on Zulip Lann Martin (Jul 29 2023 at 15:16):

I think the closest you will get will be approximating records with resource getters/setters

view this post on Zulip Lann Martin (Jul 29 2023 at 15:20):

You could potentially roll your own via multi-memories, but as you say that would require some host work and you'd be on your own for safety

view this post on Zulip Christof Petig (Jul 29 2023 at 21:22):

Lann Martin said:

I think the closest you will get will be approximating records with resource getters/setters

But then to avoid creating copies I would need to repeat the procedure for any lists/strings returned from the getter, wouldn't I.
[I have seen the stringref proposal which seems to solve a similar problem]

view this post on Zulip Robin Brown (Jul 31 2023 at 16:49):

This is a neat idea, and I talked about it with a few people last fall at CN Wasm Day. I think it would be a useful tool to have (if we could figure out what the resource API for each value type should be) but even if we did decide to do something like this it would be a while before we could get started on it because we only have so many resources working on the Component Model and we need to focus on things like building up resources and finalizing/implementing the structured concurrency model.

view this post on Zulip Robin Brown (Jul 31 2023 at 16:51):

I originally proposed it with the hope of reducing/avoiding copying the arguments passed to Wasm User-Defined Functions in SQL databases.

view this post on Zulip Christof Petig (Jul 31 2023 at 22:14):

Kyle Brown said:

This is a neat idea, and I talked about it with a few people last fall at CN Wasm Day. I think it would be a useful tool to have (if we could figure out what the resource API for each value type should be) but even if we did decide to do something like this it would be a while before we could get started on it because we only have so many resources working on the Component Model and we need to focus on things like building up resources and finalizing/implementing the structured concurrency model.

I can already start supporting it for c++ and Rust if we agree that it is the right direction, I would guess that a read only reference would be the right api and the abi would be identical to the owned case without the transfer of ownership (aka freeing of the list, string, etc after use)

view this post on Zulip Christof Petig (Aug 01 2023 at 05:51):

And likely just implementing it in the ABI code might already cover some more languages.

view this post on Zulip Robin Brown (Aug 01 2023 at 15:27):

Borrowed value types would require Component Model and Canonical ABI specification that would need to be discussed and implemented there first.

view this post on Zulip Robin Brown (Aug 01 2023 at 15:28):

I also only talked about it with a few people, so it's far from having a consensus emerge that its the right way to go.


Last updated: Nov 22 2024 at 16:03 UTC