diff options
author | Thomas Lively <tlively@google.com> | 2024-07-17 19:35:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-17 16:35:26 -0700 |
commit | 29746f14b8acd987ae137e2054391fc7afd3b3db (patch) | |
tree | 83b45befa174dfa12c31e89330b158d06bf9d899 | |
parent | 1434591fbd62f611cc530ed024a1b1477e2e7614 (diff) | |
download | binaryen-29746f14b8acd987ae137e2054391fc7afd3b3db.tar.gz binaryen-29746f14b8acd987ae137e2054391fc7afd3b3db.tar.bz2 binaryen-29746f14b8acd987ae137e2054391fc7afd3b3db.zip |
[threads] Simplify and generalize heap type writing without GC (#6765)
We represent `ref.null`s as having bottom heap types, even when GC is
not enabled. Bottom heap types are a feature of the GC proposal, so in
that case the binary writer needs to write the corresponding top type
instead. We previously had separate logic for this for each type
hierarchy in the binary writer, but that did not handle shared types and
would not have automatically handled other new types, either. Simplify
and generalize the implementation and test that we can write `ref.null`s
of shared types without GC enabled.
-rwxr-xr-x | scripts/fuzz_opt.py | 1 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 15 | ||||
-rw-r--r-- | test/lit/basic/shared-null-no-gc.wast | 19 |
3 files changed, 21 insertions, 14 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index b9d42d634..a591f9414 100755 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -361,6 +361,7 @@ INITIAL_CONTENTS_IGNORE = [ 'shared-absheaptype.wast', 'type-ssa-shared.wast', 'shared-ref_eq.wast', + 'shared-null-no-gc.wast', ] diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ee8afeb93..d35edadc8 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1629,20 +1629,7 @@ void WasmBinaryWriter::writeHeapType(HeapType type) { // only actually valid with GC. Otherwise, emit the corresponding valid top // types instead. if (!wasm->features.hasGC()) { - if (HeapType::isSubType(type, HeapType::func)) { - type = HeapType::func; - } else if (HeapType::isSubType(type, HeapType::ext)) { - type = HeapType::ext; - } else if (HeapType::isSubType(type, HeapType::exn)) { - type = HeapType::exn; - } else if (wasm->features.hasStrings()) { - // Strings are enabled, and this isn't a func or an ext, so it must be a - // string type (string or stringview), which we'll emit below, or a bottom - // type (which we must allow, because we wouldn't know whether to emit a - // string or stringview for it). - } else { - WASM_UNREACHABLE("invalid type without GC"); - } + type = type.getTop(); } if (!type.isBasic()) { diff --git a/test/lit/basic/shared-null-no-gc.wast b/test/lit/basic/shared-null-no-gc.wast new file mode 100644 index 000000000..b920f80f8 --- /dev/null +++ b/test/lit/basic/shared-null-no-gc.wast @@ -0,0 +1,19 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; Test that we can write a binary without crashing when using a shared bottom +;; type without GC enabled. + +;; RUN: wasm-opt %s --enable-reference-types --enable-shared-everything --roundtrip -S -o - | filecheck %s + +(module + ;; CHECK: (func $test + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.null (shared nofunc)) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test + (drop + (ref.null (shared func)) + ) + ) +) |