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

Implement the WebAssembly GC Proposal #5032

Open
9 tasks
Srinivasa314 opened this issue Oct 7, 2022 · 28 comments
Open
9 tasks

Implement the WebAssembly GC Proposal #5032

Srinivasa314 opened this issue Oct 7, 2022 · 28 comments
Assignees

Comments

@Srinivasa314
Copy link

Srinivasa314 commented Oct 7, 2022

Tracking issue for implementation of the WebAssembly GC proposal

Tasks

  1. 0 of 12
    cranelift:goal:optimize-speed performance wasmtime:ref-types
  2. cranelift:goal:optimize-speed performance wasmtime:ref-types
@sdeleuze
Copy link

FYI we are now able to run a Kotlin/Wasm HTTP server via KoWasm on Node.js and I would be happy to leverage Wasmtime to run it as soon as it will get GC support.

This would be a really good fit since we would like to leverage WASI Preview2+ and Wasm Component Model asap.

See also my blog post The huge potential of Kotlin/Wasm for more context.

@fitzgen
Copy link
Member

fitzgen commented Mar 30, 2023

Heads up: I am working on an RFC to work out the design of our Wasm GC support. I expect to start implementing Wasm GC once that RFC reaches consensus and merges and I've finished implementing Wasm tail calls.

@fitzgen
Copy link
Member

fitzgen commented Apr 15, 2023

RFC is up: bytecodealliance/rfcs#31

@tw-atroehrsm
Copy link

hey there! any updates on this front? Really looking forward to use Kotlin/WASM with this runtime.
For now only V8 is feasible, as it includes a GC and has implemented the proposal

@fitzgen
Copy link
Member

fitzgen commented Oct 25, 2023

There is work on parsing and validation, and refactors setting the stage for these things, happening in the wasm-tools repository, since we need to be able to parse and validate Wasm before we can compile and run it.

@smndtrl
Copy link

smndtrl commented Jan 4, 2024

@fitzgen could you provide links to the issues over there? I want to keep track with the progress due to the impact on Kotlin

@fitzgen
Copy link
Member

fitzgen commented Jan 4, 2024

@smndtrl since bytecodealliance/wasm-tools#1346 merged, all GC spec tests are passing in wasm-tools.

You can look at https://github.com/bytecodealliance/rfcs/blob/main/accepted/wasm-gc.md#incremental-implementation-plan and https://docs.wasmtime.dev/contributing-implementing-wasm-proposals.html to get an idea of what is still to be done.

@tw-atroehrsm
Copy link

tw-atroehrsm commented Feb 6, 2024

So it there any timeline, roadmap when this will be available at least with the null GC?

this was merged in may 2023 so can be marked as done?
image

#5288

what could one do to support this effort?

@fitzgen
Copy link
Member

fitzgen commented Feb 6, 2024

The function references proposal still needs to be exposed in the embedder API.

I am actively working on that and the rest of getting Wasm GC implemented. Right now it mostly involves some refactoring to the runtime's internals to pave the way for future changes. Unfortunately, there isn't much that can be split out and implemented in parallel right now.

@fitzgen
Copy link
Member

fitzgen commented Feb 15, 2024

FYI: #7943 finishes the function references proposal and takes the first baby steps towards Wasm GC inside Wasmtime, adding support for Wasm GC's nofunc and a Config::wasm_gc(enabled) knob.

@oovm
Copy link

oovm commented May 26, 2024

It looks like all gc types declarations are supported.

Can we create an issue to track the progress of the gc proposal, such as

  • gc instruction support
  • non-collection runtime
  • baseline gc runtime

@fitzgen
Copy link
Member

fitzgen commented May 29, 2024

Yes all the types are supported now, but instantiating them is not implemented yet; I'm working on it. Then the various instructions. Then the collector itself. (Right now we are reusing the deferred reference-counting collector that Wasmtime already has, so we can collect some garbage, but not cycles).

Personally, I'm not a huge fan of opening a bunch of tracking issues for things already effectively tracked by this issue. Happy to cross-link more PRs here as they come in though.

@lppedd
Copy link

lppedd commented Sep 25, 2024

Hi there! Just wondering if there are noteworthy updates on this front.

@fitzgen
Copy link
Member

fitzgen commented Sep 25, 2024

All the struct-related instructions are implemented.

Almost done with array-related instructions.

Still to do:

  • ref.test
  • ref.cast
  • branch-on-cast instructions
  • conversions between anyref and externref
  • support for funcrefs in the GC heap
  • lots of various optimizations
  • better pooling allocator integration

@fitzgen
Copy link
Member

fitzgen commented Oct 1, 2024

Two notes:

  1. All array instructions other than array.{copy,init_elem} have been implemented. Those last two will be coming very soon.

  2. Folks following this issue might also be interested in following List of future optimizations for Wasm GC performance #9351

@bashor
Copy link

bashor commented Oct 1, 2024

@fitzgen Great news! Thanks for the updates!

@bashor
Copy link

bashor commented Oct 10, 2024

@fitzgen, do I understand correctly that storing a funcref in a struct's field is not supported yet?

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2024

That was true before a few days ago. Now, funcrefs inside GC objects should be fully supported.

And FWIW, all Wasm GC spec tests are now passing on main!

@bashor
Copy link

bashor commented Oct 10, 2024

@fitzgen, but I got the following error on dev build from f59cad10572b9618b300af9e8fecf2ce13dba373

thread 'main' panicked at crates/wasmtime/src/runtime/vm/gc/enabled/structref.rs:331:17:
not yet implemented: funcrefs in GC objects
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: wasmtime::runtime::vm::gc::enabled::structref::VMStructRef::initialize_field
   3: wasmtime::runtime::gc::enabled::structref::StructRef::_new
   4: wasmtime::runtime::vm::const_expr::ConstEvalContext::struct_new
   5: wasmtime::runtime::vm::const_expr::ConstExprEvaluator::eval
   6: wasmtime::runtime::vm::instance::allocator::initialize_instance
   7: wasmtime::runtime::instance::Instance::new_raw
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
zsh: abort      RUST_BACKTRACE=1 ./wasmtime -W function-references=y -W gc=y

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2024

@bashor ah! looks like I missed a spot, thanks for finding it. FWIW, I think this should only be reachable from const expressions and host APIs. Will whip up a fix in a minute.

@fitzgen
Copy link
Member

fitzgen commented Oct 10, 2024

@bashor fix is over in #9454 !

@bashor
Copy link

bashor commented Oct 11, 2024

@fitzgen Thanks!

Now it works! 🚀 https://x.com/bashorov/status/1844725893752553957

@fitzgen
Copy link
Member

fitzgen commented Oct 11, 2024

@bashor awesome!! Thanks for kicking the tires :)

@hoangpq
Copy link

hoangpq commented Oct 13, 2024

Hi @bashor

I'm interested in running Kotlin WASI on Wasmtime, so I gave it a try, but I encountered an error. Do you have any ideas

RUST_BACKTRACE=1 ./target/debug/wasmtime -W function-references,gc ./kotlin-wasm-wasi-example-wasm-wasi.wasm
Error: failed to parse WebAssembly module

Caused by:
    exceptions proposal not enabled (at offset 0x6750)

Envs:

@alexcrichton
Copy link
Member

@hoangpq you might be interested in this comment perhaps. Wasmtime doesn't yet implement the exception-handling proposal for WebAssembly, so Kotlin won't run until that's implemented.

@hoangpq
Copy link

hoangpq commented Oct 13, 2024

Thank you @alexcrichton.

@bashor
Copy link

bashor commented Oct 13, 2024

Hi, @hoangpq!

You can uncomment/add these lines to prevent using EH by Kotlin/Wasm toolchain.

Note that the option was added only to allow earlier experimentation with VMs with limited/lack of EH support. In this mode, throwing an exception will lead to a trap (~program termination).

@hoangpq
Copy link

hoangpq commented Oct 14, 2024

Got it. Thanks, @bashor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants