js-types icon indicating copy to clipboard operation
js-types copied to clipboard

Support reference types in spec

Open SPY opened this issue 2 years ago • 2 comments

The PR is supposed to address issues #20 and #30 by replacing funcref and externref with more detailed {ref: HeapType, nullable: bool} dictionary. WebAssembly.Function.type() will return {ref: 'any', nullable} for any GC type, but new WebAssembly.Function will throw an error if it will be called with a signature containing {ref: 'any', nullable} types. This behaviour is supposed to be replaced with more detailed support in the future under cover of GC subgroup.

SPY avatar Dec 15 '23 20:12 SPY

@SPY . So if I export a function like:

(type $s (struct ...))
(func (param (ref $s))

And call .type() on it, I will get:

{
  params: [{ref: 'any', nullable: false}]
}

Effectively taking the more precise type of ref $s and replacing it with ref any.

My understanding from the last in-person CG meeting is that this is not the behavior we want. This would mean that anyone reading .type to construct functions that are compatible with that function would create it with an incorrect type and get a link error.

We should instead throw an exception here.

eqrion avatar Dec 17 '23 18:12 eqrion

@eqrion I think I misunderstood in-person discussion, thanks for correction. Throwing on "unsupported" types in type() is even easier and sounds right to me as well. I will propose the change to the spec in the separate PR then.

SPY avatar Dec 18 '23 17:12 SPY