Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dart2wasm to interop with other wasm code & provide wasm data structures (e.g. in dart:wasm) #55856

Open
3 tasks
mkustermann opened this issue May 28, 2024 · 3 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler.

Comments

@mkustermann
Copy link
Member

mkustermann commented May 28, 2024

Currently dart2wasm compiled apps are full apps that have a main function which can be invoked - there's no (official) capability to call out to imported wasm functions or export wasm functions to be consumed by other wasm modules.

This issue tracks (possibly in a dart:wasm):

  • Export / Export functionality based on wasm types
  • Defining & operating on rich set of wasm types (wasm primitives, user-defined wasm structs, etc)
  • Only allow operating on the wasm types in a static way (i.e. they are not real objects, no dynamic dispatch, no tear-offs of functions using wasm types, etc - possibly with CFE/analyzer compile-time checks) and restrict user-defined Wasm structs, ...

WasmGC interop: For User-defined wasm structs the compiler would need to ensure that the types end up in the right recursion groups in order to ensure they will match with other wasm modules, ensuring interop works.

LinearWasm interop: We'd need to ensure the design is considering a future where multiple linear memories are supported (see https://github.com/WebAssembly/multi-memory).

We may want to expose this in a dart:wasm (possibly with same or separate dart:wasmgc)

@mkustermann mkustermann added the area-dart2wasm Issues for the dart2wasm compiler. label May 28, 2024
@osa1 osa1 changed the title Allows dart2wasm to interop with other wasm code & provide wasm data structures (e.g. in dart:wasm) Allow dart2wasm to interop with other wasm code & provide wasm data structures (e.g. in dart:wasm) May 28, 2024
@bivens-dev
Copy link

bivens-dev commented May 28, 2024

is this something akin to building on top of something like wasmtime via their C interop to pick up the ability to run and load wasm modules or is that something you’re thinking about implementing yourselves? Or did I misunderstand the point of this entirely?

@maks
Copy link

maks commented May 28, 2024

I'm not sure how feasible it is from a Dart compiler/runtime point of view, but in respect to exporting functions, I would love to have the ability to just export one or more global Dart functions to be able to them call them from either JS in a browser environment or even better in a non JS WASM runtime, eg running serverside in wasmer, wasmtime etc, though of course that relies on at least one of those actually getting support for WASM-GC

@mkustermann
Copy link
Member Author

I'm not sure how feasible it is from a Dart compiler/runtime point of view, but in respect to exporting functions, I would love to have the ability to just export one or more global Dart functions to be able to them call them from either JS in a browser environment

Currently with the new JS interop one can expose Dart functions to JS via procedurally setting properties on globalThis which JS can then call via globalThis.foo(...), see #55715

or even better in a non JS WASM runtime, eg running serverside in wasmer, wasmtime etc, though of course that relies on at least one of those actually getting support for WASM-GC

Right now dart2wasm relies on JS environment for certain functionality (e.g. regular expressions, weak references, expandos, finalizers, etc). Before we can fully run in non-JS environments we need to find a way to implement them without relying on JS, possibly requiring the pure-wasm runtimes to provide some of those (e.g. weak refs & expandos) or shipping our own regexp compiler. Please subscribe to #53884 for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler.
Projects
None yet
Development

No branches or pull requests

3 participants