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

Fix calculation of gc refs in functions #8355

Merged
merged 2 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,8 @@ impl TypeTrace for WasmFuncType {
impl WasmFuncType {
#[inline]
pub fn new(params: Box<[WasmValType]>, returns: Box<[WasmValType]>) -> Self {
let non_i31_gc_ref_params_count = params
.iter()
.filter(|p| match **p {
WasmValType::Ref(rt) => rt.heap_type != WasmHeapType::I31,
_ => false,
})
.count();
let non_i31_gc_ref_returns_count = returns
.iter()
.filter(|r| match **r {
WasmValType::Ref(rt) => rt.heap_type != WasmHeapType::I31,
_ => false,
})
.count();
let non_i31_gc_ref_params_count = params.iter().filter(|p| p.is_gc_heap_type()).count();
let non_i31_gc_ref_returns_count = returns.iter().filter(|r| r.is_gc_heap_type()).count();
WasmFuncType {
params,
non_i31_gc_ref_params_count,
Expand Down
17 changes: 17 additions & 0 deletions tests/all/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,3 +2112,20 @@ fn wrap_and_typed_i31ref() -> Result<()> {
assert_eq!(HITS.load(Ordering::SeqCst), 2);
Ok(())
}

#[test]
fn call_func_with_funcref_both_typed_and_untyped() -> Result<()> {
let mut config = Config::new();
config.wasm_function_references(true);
config.wasm_gc(true);

let engine = Engine::new(&config)?;
let mut store = Store::new(&engine, ());

let f1 = Func::wrap(&mut store, |_: Option<Func>| {});
let f2 = Func::wrap(&mut store, || {});

f1.typed::<Func, ()>(&mut store)?.call(&mut store, f2)?;
f1.call(&mut store, &[Val::FuncRef(Some(f2))], &mut [])?;
Ok(())
}