WebAssembly / design

WebAssembly Design Documents
http://webassembly.org
Apache License 2.0
11.38k stars 694 forks source link

Exporting / importing passive data segments? #1347

Open nomeata opened 4 years ago

nomeata commented 4 years ago

[Please tell me if this is not the right forum to discuss possible extensions like this.]

With this proposals (data) sections no longer “just” initialize memory, but are really things of their own, which can be addressed within the module (by index), and even change (by dropping). This leads me to the question: Should it be maybe possible to export and import (data) sections, just like one can export and import functions, globals, memories (and in the future other things)?

One vauge use case that I could see is modules (possibly even host modules) providing static data (e.g. Unicode tables, machine-learned models) to other modules.

A wrinkle that would have to be solved is what does dropping such an imported data segment mean. Should dropping only affect the “local reference”, e.g. by reference counting (less interaction between modules), or should one module dropping the segment suffice (makes it easier to merge modules).

lars-t-hansen commented 4 years ago

It might be useful to kick this over to the design repository for a more general discussion. @rossberg, do you have the powers to do that?

On the one hand, the alternative to importing and exporting data is to create a "data container" module that exports initialization functions for the exported data on a memory (ie I would import the "initwithUnicodeData(atLocation)" method from that module and share my memory with it).

On the other hand, the data container module would probably have to be instantiated once for each memory that wants the data it provides, and I wouldn't necessarily want to share my memory with it.

rossberg commented 4 years ago

@lars-t-hansen, done.

nomeata commented 4 years ago

On the other hand, the data container module would probably have to be instantiated once for each memory that wants the data it provides, and I wouldn't necessarily want to share my memory with it.

Right, that’s my thinking as well: Importing a “passive memory segment” has much stronger guarantees about what can happen than “importing an arbitrary function and giving it access to my memory”

binji commented 4 years ago

We discussed this briefly here: https://github.com/WebAssembly/bulk-memory-operations/issues/15