Bug 251874 - [Wasm-GC] Update element segments to account for typed funcrefs and GC types
Summary: [Wasm-GC] Update element segments to account for typed funcrefs and GC types
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebAssembly (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks: 247394 253029
  Show dependency treegraph
 
Reported: 2023-02-07 12:00 PST by Tim Chevalier
Modified: 2023-12-12 14:16 PST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Chevalier 2023-02-07 12:00:53 PST
The following test:

```
function testElem() {
    let m = instantiate(`  
        (module
            (type $bvec (array i8))
            (elem $e (ref $bvec)
              (array.new_canon $bvec (i32.const 7) (i32.const 3))))`);
}
```

fails with:

```
Exception: CompileError: WebAssembly.Module doesn't parse at byte 30: opcode for exp in element section's should be either ref.func or ref.null 0th element's 0th index (evaluating 'new WebAssembly.Module(binary)')
```

This is because `SectionParser::parseElementSegmentVectorOfExpressions()` requires the members of the elements vector to be either a `RefFunc` or `RefNull`.

The test should compile (this is taken from https://github.com/WebAssembly/gc/blob/main/test/core/gc/array.wast#L203 )

A related bug is https://bugs.webkit.org/show_bug.cgi?id=251041 , but that one covers tables rather than element segments.
Comment 1 Tim Chevalier 2023-02-09 15:13:09 PST
externrefs also aren't allowed in element segments, and should be:

```
(module
  (elem $elem0 externref (ref.null extern)))
```

fails with:

```
Exception: CompileError: WebAssembly.Module doesn't parse at byte 17: reftype in element section should be funcref (evaluating 'new WebAssembly.Module(binary)')
```

but is accepted by the reference interpreter.
Comment 2 Radar WebKit Bug Importer 2023-02-14 12:01:32 PST
<rdar://problem/105461451>
Comment 3 Tim Chevalier 2023-02-15 17:25:51 PST
This should also work:

```
(module
      (type $fty (func (result i32)))
      (func $f (result i32)
         (i32.const 2))
      (elem $e (ref $fty) (ref.func $f)))
```

As it is, the element segment type is restricted to either `funcref` or `externref`.
Comment 4 Asumu Takikawa 2023-12-11 12:49:03 PST
Pull request: https://github.com/WebKit/WebKit/pull/21647
Comment 5 EWS 2023-12-12 14:16:35 PST
Committed 271952@main (7e71e7282468): <https://commits.webkit.org/271952@main>

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