Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ template<typename Ctx> MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx) {
return ctx.makeRefType(ctx.makeStringType(), Nullable);
}
if (ctx.in.takeKeyword("stringview_wtf8"sv)) {
return ctx.makeRefType(ctx.makeStringViewWTF8Type(), Nullable);
return ctx.makeRefType(ctx.makeStringViewWTF8Type(), NonNullable);
}
if (ctx.in.takeKeyword("stringview_wtf16"sv)) {
return ctx.makeRefType(ctx.makeStringViewWTF16Type(), Nullable);
return ctx.makeRefType(ctx.makeStringViewWTF16Type(), NonNullable);
}
if (ctx.in.takeKeyword("stringview_iter"sv)) {
return ctx.makeRefType(ctx.makeStringViewIterType(), Nullable);
return ctx.makeRefType(ctx.makeStringViewIterType(), NonNullable);
}
if (ctx.in.takeKeyword("contref"sv)) {
return ctx.makeRefType(ctx.makeContType(), Nullable);
Expand Down
129 changes: 70 additions & 59 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,62 +1515,73 @@ void WasmBinaryWriter::writeType(Type type) {
WASM_UNREACHABLE("bad type without GC");
}
auto heapType = type.getHeapType();
if (heapType.isBasic() && type.isNullable()) {
switch (heapType.getBasic()) {
case HeapType::ext:
o << S32LEB(BinaryConsts::EncodedType::externref);
return;
case HeapType::any:
o << S32LEB(BinaryConsts::EncodedType::anyref);
return;
case HeapType::func:
o << S32LEB(BinaryConsts::EncodedType::funcref);
return;
case HeapType::cont:
o << S32LEB(BinaryConsts::EncodedType::contref);
return;
case HeapType::eq:
o << S32LEB(BinaryConsts::EncodedType::eqref);
return;
case HeapType::i31:
o << S32LEB(BinaryConsts::EncodedType::i31ref);
return;
case HeapType::struct_:
o << S32LEB(BinaryConsts::EncodedType::structref);
return;
case HeapType::array:
o << S32LEB(BinaryConsts::EncodedType::arrayref);
return;
case HeapType::exn:
o << S32LEB(BinaryConsts::EncodedType::exnref);
return;
case HeapType::string:
o << S32LEB(BinaryConsts::EncodedType::stringref);
return;
case HeapType::stringview_wtf8:
o << S32LEB(BinaryConsts::EncodedType::stringview_wtf8);
return;
case HeapType::stringview_wtf16:
o << S32LEB(BinaryConsts::EncodedType::stringview_wtf16);
return;
case HeapType::stringview_iter:
o << S32LEB(BinaryConsts::EncodedType::stringview_iter);
return;
case HeapType::none:
o << S32LEB(BinaryConsts::EncodedType::nullref);
return;
case HeapType::noext:
o << S32LEB(BinaryConsts::EncodedType::nullexternref);
return;
case HeapType::nofunc:
o << S32LEB(BinaryConsts::EncodedType::nullfuncref);
return;
case HeapType::noexn:
o << S32LEB(BinaryConsts::EncodedType::nullexnref);
return;
case HeapType::nocont:
o << S32LEB(BinaryConsts::EncodedType::nullcontref);
return;
if (heapType.isBasic()) {
if (type.isNullable()) {
switch (heapType.getBasic()) {
case HeapType::ext:
o << S32LEB(BinaryConsts::EncodedType::externref);
return;
case HeapType::any:
o << S32LEB(BinaryConsts::EncodedType::anyref);
return;
case HeapType::func:
o << S32LEB(BinaryConsts::EncodedType::funcref);
return;
case HeapType::cont:
o << S32LEB(BinaryConsts::EncodedType::contref);
return;
case HeapType::eq:
o << S32LEB(BinaryConsts::EncodedType::eqref);
return;
case HeapType::i31:
o << S32LEB(BinaryConsts::EncodedType::i31ref);
return;
case HeapType::struct_:
o << S32LEB(BinaryConsts::EncodedType::structref);
return;
case HeapType::array:
o << S32LEB(BinaryConsts::EncodedType::arrayref);
return;
case HeapType::exn:
o << S32LEB(BinaryConsts::EncodedType::exnref);
return;
case HeapType::string:
o << S32LEB(BinaryConsts::EncodedType::stringref);
return;
case HeapType::stringview_wtf8:
case HeapType::stringview_wtf16:
case HeapType::stringview_iter:
break;
case HeapType::none:
o << S32LEB(BinaryConsts::EncodedType::nullref);
return;
case HeapType::noext:
o << S32LEB(BinaryConsts::EncodedType::nullexternref);
return;
case HeapType::nofunc:
o << S32LEB(BinaryConsts::EncodedType::nullfuncref);
return;
case HeapType::noexn:
o << S32LEB(BinaryConsts::EncodedType::nullexnref);
return;
case HeapType::nocont:
o << S32LEB(BinaryConsts::EncodedType::nullcontref);
return;
}
} else {
switch (heapType.getBasic()) {
case HeapType::stringview_wtf8:
o << S32LEB(BinaryConsts::EncodedType::stringview_wtf8);
return;
case HeapType::stringview_wtf16:
o << S32LEB(BinaryConsts::EncodedType::stringview_wtf16);
return;
case HeapType::stringview_iter:
o << S32LEB(BinaryConsts::EncodedType::stringview_iter);
return;
default:
break;
}
}
}
if (type.isNullable()) {
Expand Down Expand Up @@ -2052,13 +2063,13 @@ bool WasmBinaryReader::getBasicType(int32_t code, Type& out) {
out = Type(HeapType::string, Nullable);
return true;
case BinaryConsts::EncodedType::stringview_wtf8:
out = Type(HeapType::stringview_wtf8, Nullable);
out = Type(HeapType::stringview_wtf8, NonNullable);
return true;
case BinaryConsts::EncodedType::stringview_wtf16:
out = Type(HeapType::stringview_wtf16, Nullable);
out = Type(HeapType::stringview_wtf16, NonNullable);
return true;
case BinaryConsts::EncodedType::stringview_iter:
out = Type(HeapType::stringview_iter, Nullable);
out = Type(HeapType::stringview_iter, NonNullable);
return true;
case BinaryConsts::EncodedType::nullref:
out = Type(HeapType::none, Nullable);
Expand Down
6 changes: 3 additions & 3 deletions src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,13 +1286,13 @@ Type SExpressionWasmBuilder::stringToType(std::string_view str,
return Type(HeapType::string, Nullable);
}
if (str.substr(0, 15) == "stringview_wtf8" && (prefix || str.size() == 15)) {
return Type(HeapType::stringview_wtf8, Nullable);
return Type(HeapType::stringview_wtf8, NonNullable);
}
if (str.substr(0, 16) == "stringview_wtf16" && (prefix || str.size() == 16)) {
return Type(HeapType::stringview_wtf16, Nullable);
return Type(HeapType::stringview_wtf16, NonNullable);
}
if (str.substr(0, 15) == "stringview_iter" && (prefix || str.size() == 15)) {
return Type(HeapType::stringview_iter, Nullable);
return Type(HeapType::stringview_iter, NonNullable);
}
if (str.substr(0, 7) == "nullref" && (prefix || str.size() == 7)) {
return Type(HeapType::none, Nullable);
Expand Down
15 changes: 12 additions & 3 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,11 +1906,9 @@ std::ostream& TypePrinter::print(Type type) {
case HeapType::string:
return os << "stringref";
case HeapType::stringview_wtf8:
return os << "stringview_wtf8";
case HeapType::stringview_wtf16:
return os << "stringview_wtf16";
case HeapType::stringview_iter:
return os << "stringview_iter";
break;
case HeapType::none:
return os << "nullref";
case HeapType::noext:
Expand All @@ -1922,6 +1920,17 @@ std::ostream& TypePrinter::print(Type type) {
case HeapType::noexn:
return os << "nullexnref";
}
} else {
switch (heapType.getBasic()) {
case HeapType::stringview_wtf8:
return os << "stringview_wtf8";
case HeapType::stringview_wtf16:
return os << "stringview_wtf16";
case HeapType::stringview_iter:
return os << "stringview_iter";
default:
break;
}
}
}
os << "(ref ";
Expand Down
2 changes: 1 addition & 1 deletion test/lit/ctor-eval/string_view.wast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(export "test" (func $test))

;; CHECK: (func $test (type $0)
;; CHECK-NEXT: (local $temp-view (ref stringview_wtf16))
;; CHECK-NEXT: (local $temp-view stringview_wtf16)
;; CHECK-NEXT: (local.set $temp-view
;; CHECK-NEXT: (string.as_wtf16
;; CHECK-NEXT: (string.const "test")
Expand Down
13 changes: 10 additions & 3 deletions test/lit/passes/j2cl-inline.wast
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
(module

;; A once function that has become empty
;; CHECK: (type $0 (func))

;; CHECK: (global $$class-initialized@Zoo (mut i32) (i32.const 0))

;; CHECK: (func $clinit-trivial-1_<once>_@Foo (type $0)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $clinit-trivial-1_<once>_@Foo )

;; A once function that just calls another
;; CHECK: (func $clinit-trivial-2_<once>_@Bar (type $0)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $clinit-trivial-2_<once>_@Bar
(call $clinit-trivial-1_<once>_@Foo)
)

;; CHECK: (type $0 (func))

;; CHECK: (global $$class-initialized@Zoo (mut i32) (i32.const 0))
(global $$class-initialized@Zoo (mut i32) (i32.const 0))

;; Not hoisted but trivial.
Expand Down
2 changes: 1 addition & 1 deletion test/lit/passes/roundtrip.wast
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
)

;; CHECK: (func $string_view_casts (type $2) (param $x stringview_wtf8) (param $y stringview_wtf16) (param $z stringview_iter)
;; CHECK: (func $string_view_casts (type $2) (param $x (ref null stringview_wtf8)) (param $y (ref null stringview_wtf16)) (param $z (ref null stringview_iter))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (local.get $x)
Expand Down
14 changes: 7 additions & 7 deletions test/lit/passes/string-lowering-instructions.wast
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@

;; CHECK: (type $13 (func (param externref) (result externref)))

;; CHECK: (type $14 (func (param externref) (result externref)))
;; CHECK: (type $14 (func (param (ref extern)) (result externref)))

;; CHECK: (type $15 (func (param externref) (result i32)))
;; CHECK: (type $15 (func (param (ref extern)) (result i32)))

;; CHECK: (type $16 (func (param externref externref) (result i32)))

Expand All @@ -54,7 +54,7 @@

;; CHECK: (type $19 (func (param (ref $0))))

;; CHECK: (type $20 (func (param externref (ref extern) externref externref externref (ref extern))))
;; CHECK: (type $20 (func (param externref (ref extern) (ref extern) (ref extern) (ref extern) (ref extern))))

;; CHECK: (type $21 (func (param (ref null $0) i32 i32) (result (ref extern))))

Expand Down Expand Up @@ -103,7 +103,7 @@

;; CHECK: (export "export.2" (func $exported-string-receiver))

;; CHECK: (func $string.as (type $20) (param $a externref) (param $a_nn (ref extern)) (param $b externref) (param $c externref) (param $d externref) (param $nn_view (ref extern))
;; CHECK: (func $string.as (type $20) (param $a externref) (param $a_nn (ref extern)) (param $b (ref extern)) (param $c (ref extern)) (param $d (ref extern)) (param $nn_view (ref extern))
;; CHECK-NEXT: (local.set $b
;; CHECK-NEXT: (ref.as_non_null
;; CHECK-NEXT: (local.get $a)
Expand Down Expand Up @@ -253,7 +253,7 @@
)
)

;; CHECK: (func $string.length (type $15) (param $ref externref) (result i32)
;; CHECK: (func $string.length (type $15) (param $ref (ref extern)) (result i32)
;; CHECK-NEXT: (call $length
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
Expand All @@ -264,7 +264,7 @@
)
)

;; CHECK: (func $string.get_codeunit (type $15) (param $ref externref) (result i32)
;; CHECK: (func $string.get_codeunit (type $15) (param $ref (ref extern)) (result i32)
;; CHECK-NEXT: (call $charCodeAt
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (i32.const 2)
Expand All @@ -277,7 +277,7 @@
)
)

;; CHECK: (func $string.slice (type $14) (param $ref externref) (result externref)
;; CHECK: (func $string.slice (type $14) (param $ref (ref extern)) (result externref)
;; CHECK-NEXT: (call $substring
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (i32.const 2)
Expand Down
4 changes: 2 additions & 2 deletions test/lit/strings.wast
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
;; CHECK: (type $array16 (sub (array (mut i16))))
(type $array16 (sub (array (mut i16))))

;; CHECK: (type $5 (func (param stringref stringview_wtf8 stringview_wtf16 stringview_iter stringref stringview_wtf8 stringview_wtf16 stringview_iter (ref string) (ref stringview_wtf8) (ref stringview_wtf16) (ref stringview_iter))))
;; CHECK: (type $5 (func (param stringref stringview_wtf8 stringview_wtf16 stringview_iter stringref (ref null stringview_wtf8) (ref null stringview_wtf16) (ref null stringview_iter) (ref string) stringview_wtf8 stringview_wtf16 stringview_iter)))

;; CHECK: (type $6 (func (param (ref string))))

Expand All @@ -46,7 +46,7 @@

;; CHECK: (memory $0 10 10)

;; CHECK: (func $string.new (type $5) (param $a stringref) (param $b stringview_wtf8) (param $c stringview_wtf16) (param $d stringview_iter) (param $e stringref) (param $f stringview_wtf8) (param $g stringview_wtf16) (param $h stringview_iter) (param $i (ref string)) (param $j (ref stringview_wtf8)) (param $k (ref stringview_wtf16)) (param $l (ref stringview_iter))
;; CHECK: (func $string.new (type $5) (param $a stringref) (param $b stringview_wtf8) (param $c stringview_wtf16) (param $d stringview_iter) (param $e stringref) (param $f (ref null stringview_wtf8)) (param $g (ref null stringview_wtf16)) (param $h (ref null stringview_iter)) (param $i (ref string)) (param $j stringview_wtf8) (param $k stringview_wtf16) (param $l stringview_iter)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (string.new_wtf16
;; CHECK-NEXT: (i32.const 7)
Expand Down
Loading