Test Case
I'm trying to run a Kotlin-produced Wasm module in Rust-embedded Wasmtime. Kotlin requires support for the Wasm GC proposal, which Wasmtime officially has since version 27.0.0. Unfortunately, when initializing the Kotlin-generated Wasm module, a Wasmtime assertion error occurs, seemingly related to the Wasm GC code.
I initially assumed some incompatibility between Wasmtime and Kotlin-produced Wasm but the same file can be executed successfully in the standalone mode with wasmtime -W function-references,gc.
The minimal Kotlin guest code that reproduces this issue looks like this:
And this is the corresponding host code:
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
Versions and Environment
Wasmtime version or commit: 27.0.0
Operating system: macOS
Architecture: arm64
Test Case
I'm trying to run a Kotlin-produced Wasm module in Rust-embedded Wasmtime. Kotlin requires support for the Wasm GC proposal, which Wasmtime officially has since version 27.0.0. Unfortunately, when initializing the Kotlin-generated Wasm module, a Wasmtime assertion error occurs, seemingly related to the Wasm GC code.
I initially assumed some incompatibility between Wasmtime and Kotlin-produced Wasm but the same file can be executed successfully in the standalone mode with
wasmtime -W function-references,gc.The minimal Kotlin guest code that reproduces this issue looks like this:
And this is the corresponding host code:
This fails at
linker.instantiatecall with an error:Versions and Environment
Wasmtime version or commit: 27.0.0
Operating system: macOS
Architecture: arm64