Closed Bug 1559921 Opened 5 years ago Closed 4 years ago

GC feature: call_indirect should have a notion of subtypes in its signature check

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

enhancement

Tracking

()

RESOLVED WONTFIX

People

(Reporter: lth, Unassigned)

References

Details

See https://github.com/lars-t-hansen/moz-gc-experiments/issues/11 for some preliminary details. We probably want to / need to upgrade the signature check logic for call_indirect to handle cases where there's an implicit upcast.

A more simpler sample:

(module (gc_feature_opt_in 3)
  (type $Abc1 (struct         ;; super type with one field
    (field $Abc1.a (mut i32))
  ))
  (type $Abc2 (struct         ;; extended type with two fields
    (field $Abc2.a (mut i32))
    (field $Abc2.b (mut i64))
  ))

  (type $t1 (func(param (ref $Abc1))))
  (type $t2 (func(param (ref $Abc2))))

  (export "callVirtualMethod" (func $callVirtualMethod))
  (func $callVirtualMethod(result i32)(local $val (ref $Abc2))
    i32.const 0        ;; default for field $Abc2.a
    i64.const 0        ;; default for field $Abc2.b
    struct.new $Abc2
    local.tee $val

	i32.const 2        ;; idx of $Abc2.bar
    call_indirect $t1  ;; <-- $t2 would work but this is the runtime type

    local.get $val
    struct.get $Abc1 $Abc1.a
    return
  )

  (func $Abc1.bar(param $this (ref $Abc1)) ;; virtual func "bar" for super type $Abc1
    local.get $this
    i32.const 1                            ;; set the value 1
    struct.set $Abc1 $Abc1.a
  )

  (func $Abc2.bar(param $this (ref $Abc2)) ;; virtual func "bar" for extended type $Abc2
    local.get $this
    i32.const 2                            ;; set the value 1
    struct.set $Abc2 $Abc2.a
  )

  (table 3 3 anyfunc)
  (elem (i32.const 0) $callVirtualMethod $Abc1.bar $Abc2.bar )
)

Subtype checking can be rather expensive -- much moreso than the current 2-4 instruction sequence.

The current function-references/GC proposals do not have subtyping with call_indirect.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX
See Also: → 1850028
You need to log in before you can comment on or make changes to this bug.