Bug 260039

Summary: [Wasm-GC] Module linking should take subtyping into account
Product: WebKit Reporter: Asumu Takikawa <asumu>
Component: WebAssemblyAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 247394    

Description Asumu Takikawa 2023-08-10 13:58:01 PDT
Right now, module linking checks for exact type index equality to make sure linked functions satisfy their types. The GC proposal extends this to work with subtypes, instead of exact match, but this isn't implemented yet.

For example, this test fragment is from the GC proposal repo test suite:

```
(module
  (type $t0 (sub (func (result (ref null func)))))
  (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
  (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))

  (func (export "f0") (type $t0) (ref.null func))
  (func (export "f1") (type $t1) (ref.null $t1))
  (func (export "f2") (type $t2) (ref.null $t2))
)
(register "M")

(module
  (type $t0 (sub (func (result (ref null func)))))
  (rec (type $t1 (sub $t0 (func (result (ref null $t1))))))
  (rec (type $t2 (sub $t1 (func (result (ref null $t2))))))

  (func (import "M" "f0") (type $t0))
  (func (import "M" "f1") (type $t0))
  (func (import "M" "f1") (type $t1))
  (func (import "M" "f2") (type $t0))
  (func (import "M" "f2") (type $t1))
  (func (import "M" "f2") (type $t2))
)
```

The import "f1" takes a function that has type `$t1` (subtype of `$t0`) and tries to import it under type `$t0`. This currently fails, but is supposed to succeed.

It should be relatively easy to fix, by changing the index equality check to a `isSubtype` call.
Comment 1 Radar WebKit Bug Importer 2023-08-17 13:58:15 PDT
<rdar://problem/114045477>
Comment 2 Asumu Takikawa 2023-12-15 10:28:12 PST
Pull request: https://github.com/WebKit/WebKit/pull/21875
Comment 3 EWS 2023-12-18 09:55:06 PST
Committed 272226@main (3015bbe0e8ab): <https://commits.webkit.org/272226@main>

Reviewed commits have been landed. Closing PR #21875 and removing active labels.