Skip to content

call_indirect #488

Closed
Closed
@ghost

Description

There appear to be a deficiency with the current thinking around call_indirect:

A call_indirect specifies the expected signature of the target function with
an index into a signature table defined by the module. An indirect call to a
function with a mismatched signature causes a trap.

The problems here are three-fold (at least):

  1. A higher-order function (where the arguments to the function can contain a function, or where the function returns a function) cannot be invoked. The reason is that a call_indirect assumes that the function to be called is in the same module as the caller. A higher-order function cannot know where its argument functions are located.
  2. A higher-order function will have a type signature that does not correspond with int32->int32 style types. Its arguments and/or its return type will not be a normal value.
  3. In a language with generics (which includes C++), the actual type of a function may not correspond literally with the call site and yet still be perfectly valid. (e.g., a function with type X->X can be invoked with integer arguments, float arguments, even function arguments).

BTW, this applies to C/C++ as well as to functional languages.

Given that the current function table approach is fixed, call_indirect must be extended to allow inter-module calls where the module of the callee is dynamically determined.

An alternate is to invent something along the lines of the MethodHandle from the JVM. (Except that that also embeds 'free variables' - another issue with call_indirect).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions