Skip to content

Should importing or exporting a function count as declaring it for ref.func? #2072

@eqrion

Description

@eqrion

A function must be 'declared' by use outside of the function section in order to be allowed to be used with ref.func.

I recently discovered that just importing a function doesn't count:

(module
  (import "" "" (func $f))
  (func
    ref.func $f
    drop
  )
)

This code fails to validate in V8, SM, and JSC complaining that $f wasn't pre-declared.

This seems odd to me, and I can't think of any reason we shouldn't consider it valid. But maybe I'm missing something?

I then double checked the spec here, and I believe this is the relevant rule in module validation:
Image
The refs field on C is the set of valid targets for ref.func. If I'm reading it right, that means that both exports and imports aren't included in refs.

SM and V8 treat exporting a function as declaring it, while it looks like JSC does not do that. So there's inconsistent handling on exports.

I personally think that exporting/importing a function should count as declaring it. I'm pretty sure imports/exports and declaring was discussed a long time ago, but can't find anything relevant.

cc @tlively @kmiller68 @rossberg

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