<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>251874</bug_id>
          
          <creation_ts>2023-02-07 12:00:53 -0800</creation_ts>
          <short_desc>[Wasm-GC] Update element segments to account for typed funcrefs and GC types</short_desc>
          <delta_ts>2023-12-12 14:16:37 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebAssembly</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=251041</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=252349</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>247394</blocked>
    
    <blocked>253029</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Chevalier">tjc</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1931798</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Chevalier">tjc</who>
    <bug_when>2023-02-07 12:00:53 -0800</bug_when>
    <thetext>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&apos;t parse at byte 30: opcode for exp in element section&apos;s should be either ref.func or ref.null 0th element&apos;s 0th index (evaluating &apos;new WebAssembly.Module(binary)&apos;)
```

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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1932476</commentid>
    <comment_count>1</comment_count>
    <who name="Tim Chevalier">tjc</who>
    <bug_when>2023-02-09 15:13:09 -0800</bug_when>
    <thetext>externrefs also aren&apos;t allowed in element segments, and should be:

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

fails with:

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

but is accepted by the reference interpreter.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1933554</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-02-14 12:01:32 -0800</bug_when>
    <thetext>&lt;rdar://problem/105461451&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1934019</commentid>
    <comment_count>3</comment_count>
    <who name="Tim Chevalier">tjc</who>
    <bug_when>2023-02-15 17:25:51 -0800</bug_when>
    <thetext>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`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1998758</commentid>
    <comment_count>4</comment_count>
    <who name="Asumu Takikawa">asumu</who>
    <bug_when>2023-12-11 12:49:03 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/21647</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1999088</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-12-12 14:16:35 -0800</bug_when>
    <thetext>Committed 271952@main (7e71e7282468): &lt;https://commits.webkit.org/271952@main&gt;

Reviewed commits have been landed. Closing PR #21647 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>