I'm trying to run a Kotlin-produced Wasm module in Rust-embedded Wasmtime. Kotlin requires Wasm GC proposal support from the runtime which Wasmtime officially has now since version 27.0.0.
Unfortunately it fails at module init. I'm new to Rust and maybe I'm making some obvious mistake so I would appreciate any pointers on how to debug/fix this issue.
Actually I am able to run the Kotlin-produced guest when Wasmtime is embedded in Go with wasmtime-go bindings (manually updated to use Wasmtime 27.0.0). There are some issues with that too (#wasmtime > How to deal with "GC heap out of memory" errors? ) but at least it doesn't fail on module init so I assume it should work when Wasmtime is embedded in Rust too.
I've removed almost everything from the Kotlin guest, it only contains this now:
fun main() {}
And this is the host code, taken from the docs with very few modifications:
use wasmtime::*;
use wasi_common::sync::WasiCtxBuilder;
fn main() -> Result<()> {
let mut config = Config::new();
config
.wasm_gc(true)
.wasm_function_references(true);
let engine = Engine::new(&mut config)?;
let mut linker = Linker::new(&engine);
wasi_common::sync::add_to_linker(&mut linker, |s| s)?;
let wasi = WasiCtxBuilder::new()
.inherit_stderr()
.inherit_stdout()
.build();
let mut store = Store::new(&engine, wasi);
let module = Module::from_file(&engine, "kotlin.wasm")?;
linker.instantiate(&mut store, &module)?;
Ok(())
}
This fails at linker.instantiate
call with an error:
thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/type_registry.rs:271:17:
assertion `left == right` failed
left: WasmSubType { is_final: true, supertype: None, composite_type: WasmCompositeType { inner: Struct(WasmStructType { fields: [] }), shared: false } }
right: WasmSubType { is_final: true, supertype: Some(Engine(VMSharedTypeIndex(19))), composite_type: WasmCompositeType { inner: Struct(WasmStructType { fields: [] }), shared: false } }
stack backtrace:
0: rust_begin_unwind
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:662:5
1: core::panicking::panic_fmt
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:74:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:367:5
4: <wasmtime::runtime::type_registry::RegisteredType as core::cmp::PartialEq>::eq
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/type_registry.rs:271:17
5: core::cmp::impls::<impl core::cmp::PartialEq<&B> for &A>::eq
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/cmp.rs:1661:13
6: <Q as hashbrown::Equivalent<K>>::equivalent
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/lib.rs:172:9
7: hashbrown::map::equivalent_key::{{closure}}
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/map.rs:229:14
8: hashbrown::raw::inner::RawTable<T,A>::find_or_find_insert_slot::{{closure}}
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/raw/mod.rs:1425:68
9: hashbrown::raw::inner::RawTableInner::find_or_find_insert_slot_inner
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/raw/mod.rs:1983:27
10: hashbrown::raw::inner::RawTable<T,A>::find_or_find_insert_slot
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/raw/mod.rs:1423:19
11: hashbrown::map::HashMap<K,V,S,A>::insert
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/map.rs:1754:15
12: hashbrown::set::HashSet<T,S,A>::insert
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/set.rs:1115:9
13: wasmtime::runtime::store::StoreOpaque::insert_gc_host_alloc_type
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/store.rs:1797:9
14: wasmtime::runtime::gc::enabled::structref::StructRefPre::_new
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/gc/enabled/structref.rs:74:9
15: wasmtime::runtime::vm::const_expr::ConstEvalContext::struct_new
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/const_expr.rs:93:25
16: wasmtime::runtime::vm::const_expr::ConstEvalContext::struct_new_default
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/const_expr.rs:153:18
17: wasmtime::runtime::vm::const_expr::ConstExprEvaluator::eval
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/const_expr.rs:278:31
18: wasmtime::runtime::vm::instance::allocator::initialize_globals
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/instance/allocator.rs:779:13
19: wasmtime::runtime::vm::instance::allocator::initialize_instance
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/instance/allocator.rs:826:5
20: wasmtime::runtime::vm::instance::InstanceHandle::initialize
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/vm/instance.rs:1541:9
21: wasmtime::runtime::instance::Instance::new_raw
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/instance.rs:343:9
22: wasmtime::runtime::instance::Instance::new_started_impl
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/instance.rs:206:33
23: wasmtime::runtime::instance::Instance::new_started
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/instance.rs:194:9
24: wasmtime::runtime::instance::InstancePre<T>::instantiate
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/instance.rs:876:18
25: wasmtime::runtime::linker::Linker<T>::instantiate
at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-27.0.0/src/runtime/linker.rs:1112:9
26: jobexecutor::main
at ./src/main.rs:25:5
27: core::ops::function::FnOnce::call_once
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
It seems to be Wasm GC-related, it could have been some incompatibility between Wasmtime and Kotlin-produced Wasm but then it is not clear how is it possible that Go-embedded Wasmtime is able to init the module without issues.
The same Wasm file can be executed successfully in the standalone mode with wasmtime -W function-references,gc
.
Thanks for the report! Could you file an issue in the Wasmtime repository for this?
Sure, created a Github issue: https://github.com/bytecodealliance/wasmtime/issues/9714
Last updated: Dec 23 2024 at 14:03 UTC