-
Notifications
You must be signed in to change notification settings - Fork 95
Description
I've brought this up at WASI meeting on 2022-06-16. This is also partially related to memory sharing, though the most simple case might make do without memory access.
At its core, this isn't a very complicated problem. The gist is how to express interfaces requiring callback functions. For example consider classic sort
, which takes two arrays and a function index, the latter taking two elements and returning a signed integer indicating less/equal/greater. I am curious how something like this can be represented in component model.
As an extreme simplification consider sort taking only scalars, or structs that can be represented as scalars. This makes callback representation really simple, but doesn't eliminate sharing memory between caller and sort
implementation. I would like to understand what would the representation be in this case and if that is possible to do at the moment. My first question is how to represent this in current state of Component Mode? And what if instead of sort
it would be something even more simple, say function that only reads memory, would that make it easier?
However, in a more general case, callback would be aware of the memory, and would take pointer parameters. In case of sorting, this is true for std::sort
(with some caveats) and C standard library's qsort
. It easy to imagine other uses.
It is important to note that this functionality is expressible within core Wasm syntax and available in existing toolchains. In fact, we even have aforementioned qsort
is wasi-libc.
Would use of pointer parameters change representation in component model? Do we expect this to apply to libc
as well?