-
Notifications
You must be signed in to change notification settings - Fork 513
Description
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:
![]()
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.