Skip to content

Function references unresolved issues #6455

@dhil

Description

@dhil

PR #5288 implements the function references proposal modulo a few missing bits. The missing bits are:

  • Support for function references in the embedder API.
  • Failing tests:
    • type-equivalence.wast: type canonicalisation is currently broken due to #[derive(hash)] not considering that two distinct typed function reference indices may point to structurally equivalent types.
    • br_table.wast: this fails due to incomplete support for the various syntactic sugar in the wasm-tools/wast crate. See Support for Wast table initialisation syntactic sugar with typeful references wasm-tools#952.
    • ref_null.wast and local_init.wast: fail due to lack of support in the embedder API.
    • return_call_ref.wast, return_call_indirect.wast, and return_call.wast: fail due to lack of tail call support.

At the time of writing the implementation does not take advantage of the static non-null safety to elide null checks when executing call_ref:

fn translate_call_ref(
&mut self,
builder: &mut FunctionBuilder,
sig_ref: ir::SigRef,
callee: ir::Value,
call_args: &[ir::Value],
) -> WasmResult<ir::Inst> {
// Check for whether the callee is null, and trap if so.
//
// FIXME: the wasm type system tracks enough information to know whether
// `callee` is a null reference or not. In some situations it can be
// statically known here that `callee` cannot be null in which case this
// null check can be elided. This requires feeding type information from
// wasmparser's validator into this function, however, which is not
// easily done at this time.
builder.ins().trapz(callee, ir::TrapCode::NullReference);
self.call_function_unchecked(builder, sig_ref, callee, call_args)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions