Stream: git-wasmtime

Topic: wasmtime / issue #10171 Understanding `ref.test` failing


view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 11:46):

apoorvaanand1998 opened issue #10171:

(module
    (type $appNode
        (struct (field $left anyref)
                (field $right anyref)))

    (type $comb (struct (field $asciiTag i32)))

    (func $prob1 (export "prob1") (param $p (ref null $appNode)) (result i32)
        (local.get $p)
        (struct.get $appNode $left)
        (ref.cast (ref null $appNode))
        (struct.get $appNode $right)
        (ref.test (ref null $comb))
    )

    (func $prob2 (export "prob2") (param $p (ref null $appNode)) (result i32)
        (local.get $p)
        (struct.get $appNode $left)
        (ref.cast (ref null $appNode))
        (struct.get $appNode $left)
        (ref.test (ref null $comb))
    )

    (func $main (export "main") (result i32)
        (struct.new $appNode (struct.new $appNode (struct.new $comb (i32.const 67))
                                                  (struct.new $comb (i32.const 73)))
                             (ref.i31 (i32.const 2)))
        (call $prob2)
    )
)

Hey Wasmtime team! calling $prob1 returns 1 but $prob2 returns 2. Why is that? Shouldn't it be reading the struct.new $comb (i32.const 67) which indeed is a comb? I've tried reading the GC spec but haven't been able to figure out why the runtime behaves this way.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 11:47):

apoorvaanand1998 edited issue #10171:

(module
    (type $appNode
        (struct (field $left anyref)
                (field $right anyref)))

    (type $comb (struct (field $asciiTag i32)))

    (func $prob1 (export "prob1") (param $p (ref null $appNode)) (result i32)
        (local.get $p)
        (struct.get $appNode $left)
        (ref.cast (ref null $appNode))
        (struct.get $appNode $right)
        (ref.test (ref null $comb))
    )

    (func $prob2 (export "prob2") (param $p (ref null $appNode)) (result i32)
        (local.get $p)
        (struct.get $appNode $left)
        (ref.cast (ref null $appNode))
        (struct.get $appNode $left)
        (ref.test (ref null $comb))
    )

    (func $main (export "main") (result i32)
        (struct.new $appNode (struct.new $appNode (struct.new $comb (i32.const 67))
                                                  (struct.new $comb (i32.const 73)))
                             (ref.i31 (i32.const 2)))
        (call $prob2)
    )
)

Hey Wasmtime team! calling $prob1 returns 1 but $prob2 returns 0. Why is that? Shouldn't it be reading the (struct.new $comb (i32.const 67)) which indeed is a comb? I've tried reading the GC spec but haven't been able to figure out why the runtime behaves this way.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 15:42):

alexcrichton assigned fitzgen to issue #10171.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 18:22):

fitzgen commented on issue #10171:

This looks like a bug in Wasmtime, I think prob2 should indeed return 1.

FWIW, it also returns 1 in Firefox.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 18:27):

fitzgen commented on issue #10171:

Interestingly enough, removing $right makes the test pass.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 18:27):

fitzgen added the bug label to Issue #10171.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2025 at 18:27):

fitzgen added the wasm-proposal:gc label to Issue #10171.


Last updated: Feb 28 2025 at 01:30 UTC