summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp12
-rw-r--r--src/binaryen-c.h4
-rw-r--r--src/gen-s-parser.inc40
-rw-r--r--src/ir/subtypes.h7
-rw-r--r--src/js/binaryen.js-post.js6
-rw-r--r--src/passes/Print.cpp18
-rw-r--r--src/tools/fuzzing/fuzzing.cpp67
-rw-r--r--src/tools/fuzzing/heap-types.cpp14
-rw-r--r--src/wasm-binary.h22
-rw-r--r--src/wasm-type.h4
-rw-r--r--src/wasm/literal.cpp4
-rw-r--r--src/wasm/wasm-binary.cpp40
-rw-r--r--src/wasm/wasm-s-parser.cpp10
-rw-r--r--src/wasm/wasm-stack.cpp14
-rw-r--r--src/wasm/wasm-type.cpp46
-rw-r--r--src/wasm/wat-parser.cpp14
16 files changed, 126 insertions, 196 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index e37270f61..f195e6c59 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -85,7 +85,7 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
WASM_UNREACHABLE("TODO: extern literals");
case HeapType::eq:
case HeapType::func:
- case HeapType::data:
+ case HeapType::struct_:
case HeapType::array:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
@@ -138,7 +138,7 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
WASM_UNREACHABLE("TODO: extern literals");
case HeapType::eq:
case HeapType::func:
- case HeapType::data:
+ case HeapType::struct_:
case HeapType::array:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
@@ -199,8 +199,8 @@ BinaryenType BinaryenTypeEqref(void) {
BinaryenType BinaryenTypeI31ref(void) {
return Type(HeapType::i31, Nullable).getID();
}
-BinaryenType BinaryenTypeDataref(void) {
- return Type(HeapType::data, Nullable).getID();
+BinaryenType BinaryenTypeStructref(void) {
+ return Type(HeapType::struct_, Nullable).getID();
}
BinaryenType BinaryenTypeArrayref(void) {
return Type(HeapType::array, Nullable).getID();
@@ -284,8 +284,8 @@ BinaryenHeapType BinaryenHeapTypeEq() {
BinaryenHeapType BinaryenHeapTypeI31() {
return static_cast<BinaryenHeapType>(HeapType::BasicHeapType::i31);
}
-BinaryenHeapType BinaryenHeapTypeData() {
- return static_cast<BinaryenHeapType>(HeapType::BasicHeapType::data);
+BinaryenHeapType BinaryenHeapTypeStruct() {
+ return static_cast<BinaryenHeapType>(HeapType::BasicHeapType::struct_);
}
BinaryenHeapType BinaryenHeapTypeArray() {
return static_cast<BinaryenHeapType>(HeapType::BasicHeapType::array);
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index b9f78e2a7..cd5bd6735 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -104,7 +104,7 @@ BINARYEN_API BinaryenType BinaryenTypeExternref(void);
BINARYEN_API BinaryenType BinaryenTypeAnyref(void);
BINARYEN_API BinaryenType BinaryenTypeEqref(void);
BINARYEN_API BinaryenType BinaryenTypeI31ref(void);
-BINARYEN_API BinaryenType BinaryenTypeDataref(void);
+BINARYEN_API BinaryenType BinaryenTypeStructref(void);
BINARYEN_API BinaryenType BinaryenTypeArrayref(void);
BINARYEN_API BinaryenType BinaryenTypeStringref(void);
BINARYEN_API BinaryenType BinaryenTypeStringviewWTF8(void);
@@ -146,7 +146,7 @@ BINARYEN_API BinaryenHeapType BinaryenHeapTypeFunc(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeAny(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeEq(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeI31(void);
-BINARYEN_API BinaryenHeapType BinaryenHeapTypeData(void);
+BINARYEN_API BinaryenHeapType BinaryenHeapTypeStruct(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeArray(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeString(void);
BINARYEN_API BinaryenHeapType BinaryenHeapTypeStringviewWTF8(void);
diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc
index dbf3b71bf..b44329388 100644
--- a/src/gen-s-parser.inc
+++ b/src/gen-s-parser.inc
@@ -124,9 +124,6 @@ switch (buf[0]) {
default: goto parse_error;
}
}
- case 'd':
- if (op == "br_on_data"sv) { return makeBrOnCast(s, Type(HeapType::data, NonNullable)); }
- goto parse_error;
case 'f':
if (op == "br_on_func"sv) { return makeBrOnCast(s, Type(HeapType::func, NonNullable)); }
goto parse_error;
@@ -137,9 +134,6 @@ switch (buf[0]) {
switch (buf[7]) {
case 'o': {
switch (buf[10]) {
- case 'd':
- if (op == "br_on_non_data"sv) { return makeBrOnCast(s, Type(HeapType::data, NonNullable), true); }
- goto parse_error;
case 'f':
if (op == "br_on_non_func"sv) { return makeBrOnCast(s, Type(HeapType::func, NonNullable), true); }
goto parse_error;
@@ -2999,9 +2993,6 @@ switch (buf[0]) {
switch (buf[4]) {
case 'a': {
switch (buf[7]) {
- case 'd':
- if (op == "ref.as_data"sv) { return makeRefCast(s, Type(HeapType::data, NonNullable)); }
- goto parse_error;
case 'f':
if (op == "ref.as_func"sv) { return makeRefCast(s, Type(HeapType::func, NonNullable)); }
goto parse_error;
@@ -3049,9 +3040,6 @@ switch (buf[0]) {
goto parse_error;
case 'i': {
switch (buf[7]) {
- case 'd':
- if (op == "ref.is_data"sv) { return makeRefTest(s, Type(HeapType::data, NonNullable)); }
- goto parse_error;
case 'f':
if (op == "ref.is_func"sv) { return makeRefTest(s, Type(HeapType::func, NonNullable)); }
goto parse_error;
@@ -3766,13 +3754,6 @@ switch (buf[0]) {
default: goto parse_error;
}
}
- case 'd':
- if (op == "br_on_data"sv) {
- auto ret = makeBrOnCast(ctx, pos, Type(HeapType::data, NonNullable));
- CHECK_ERR(ret);
- return *ret;
- }
- goto parse_error;
case 'f':
if (op == "br_on_func"sv) {
auto ret = makeBrOnCast(ctx, pos, Type(HeapType::func, NonNullable));
@@ -3791,13 +3772,6 @@ switch (buf[0]) {
switch (buf[7]) {
case 'o': {
switch (buf[10]) {
- case 'd':
- if (op == "br_on_non_data"sv) {
- auto ret = makeBrOnCast(ctx, pos, Type(HeapType::data, NonNullable), true);
- CHECK_ERR(ret);
- return *ret;
- }
- goto parse_error;
case 'f':
if (op == "br_on_non_func"sv) {
auto ret = makeBrOnCast(ctx, pos, Type(HeapType::func, NonNullable), true);
@@ -8597,13 +8571,6 @@ switch (buf[0]) {
switch (buf[4]) {
case 'a': {
switch (buf[7]) {
- case 'd':
- if (op == "ref.as_data"sv) {
- auto ret = makeRefCast(ctx, pos, Type(HeapType::data, NonNullable));
- CHECK_ERR(ret);
- return *ret;
- }
- goto parse_error;
case 'f':
if (op == "ref.as_func"sv) {
auto ret = makeRefCast(ctx, pos, Type(HeapType::func, NonNullable));
@@ -8687,13 +8654,6 @@ switch (buf[0]) {
goto parse_error;
case 'i': {
switch (buf[7]) {
- case 'd':
- if (op == "ref.is_data"sv) {
- auto ret = makeRefTest(ctx, pos, Type(HeapType::data, NonNullable));
- CHECK_ERR(ret);
- return *ret;
- }
- goto parse_error;
case 'f':
if (op == "ref.is_func"sv) {
auto ret = makeRefTest(ctx, pos, Type(HeapType::func, NonNullable));
diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h
index bc14c1d4f..c895828f1 100644
--- a/src/ir/subtypes.h
+++ b/src/ir/subtypes.h
@@ -113,7 +113,7 @@ struct SubTypes {
for (auto type : types) {
HeapType basic;
if (type.isStruct()) {
- basic = HeapType::data;
+ basic = HeapType::struct_;
} else if (type.isArray()) {
basic = HeapType::array;
} else {
@@ -123,9 +123,8 @@ struct SubTypes {
depths[basic] = std::max(depths[basic], depths[type] + 1);
}
- depths[HeapType::data] =
- std::max(depths[HeapType::data], depths[HeapType::array] + 1);
- depths[HeapType::eq] = std::max(Index(1), depths[HeapType::data] + 1);
+ depths[HeapType::eq] =
+ std::max(depths[HeapType::struct_], depths[HeapType::array]) + 1;
depths[HeapType::any] = depths[HeapType::eq] + 1;
return depths;
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index da121e23a..86b063c0e 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -38,7 +38,7 @@ function initializeConstants() {
['anyref', 'Anyref'],
['eqref', 'Eqref'],
['i31ref', 'I31ref'],
- ['dataref', 'Dataref'],
+ ['structref', 'Structref'],
['stringref', 'Stringref'],
['stringview_wtf8', 'StringviewWTF8'],
['stringview_wtf16', 'StringviewWTF16'],
@@ -2302,9 +2302,9 @@ function wrapModule(module, self = {}) {
}
};
- self['dataref'] = {
+ self['structref'] = {
'pop'() {
- return Module['_BinaryenPop'](module, Module['dataref']);
+ return Module['_BinaryenPop'](module, Module['structref']);
}
};
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index e0d9a46a3..38e88fde5 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -105,8 +105,8 @@ bool maybePrintRefShorthand(std::ostream& o, Type type) {
case HeapType::i31:
o << "i31ref";
return true;
- case HeapType::data:
- o << "dataref";
+ case HeapType::struct_:
+ o << "structref";
return true;
case HeapType::array:
o << "arrayref";
@@ -2099,9 +2099,6 @@ struct PrintExpressionContents
case HeapType::func:
printMedium(o, "ref.is_func");
return;
- case HeapType::data:
- printMedium(o, "ref.is_data");
- return;
case HeapType::i31:
printMedium(o, "ref.is_i31");
return;
@@ -2129,9 +2126,6 @@ struct PrintExpressionContents
case HeapType::func:
printMedium(o, "ref.as_func");
return;
- case HeapType::data:
- printMedium(o, "ref.as_data");
- return;
case HeapType::i31:
printMedium(o, "ref.as_i31");
return;
@@ -2167,10 +2161,6 @@ struct PrintExpressionContents
printMedium(o, "br_on_func ");
printName(curr->name, o);
return;
- case HeapType::data:
- printMedium(o, "br_on_data ");
- printName(curr->name, o);
- return;
case HeapType::i31:
printMedium(o, "br_on_i31 ");
printName(curr->name, o);
@@ -2196,10 +2186,6 @@ struct PrintExpressionContents
printMedium(o, "br_on_non_func ");
printName(curr->name, o);
return;
- case HeapType::data:
- printMedium(o, "br_on_non_data ");
- printName(curr->name, o);
- return;
case HeapType::i31:
printMedium(o, "br_on_non_i31 ");
printName(curr->name, o);
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 18568271b..98f9ea733 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -2041,7 +2041,18 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) {
// Choose a subtype we can materialize a constant for. We cannot
// materialize non-nullable refs to func or i31 in global contexts.
Nullability nullability = getSubType(type.getNullability());
- HeapType subtype = oneIn(2) ? HeapType::i31 : HeapType::data;
+ HeapType subtype;
+ switch (upTo(3)) {
+ case 0:
+ subtype = HeapType::i31;
+ break;
+ case 1:
+ subtype = HeapType::struct_;
+ break;
+ case 2:
+ subtype = HeapType::array;
+ break;
+ }
return makeConst(Type(subtype, nullability));
}
case HeapType::eq: {
@@ -2055,10 +2066,16 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) {
auto nullability = getSubType(type.getNullability());
// i31.new is not allowed in initializer expressions.
HeapType subtype;
- if (funcContext) {
- subtype = pick(HeapType::i31, HeapType::data);
- } else {
- subtype = HeapType::data;
+ switch (upTo(3)) {
+ case 0:
+ subtype = HeapType::i31;
+ break;
+ case 1:
+ subtype = HeapType::struct_;
+ break;
+ case 2:
+ subtype = HeapType::array;
+ break;
}
return makeConst(Type(subtype, nullability));
}
@@ -2069,17 +2086,15 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) {
}
return builder.makeI31New(makeConst(Type::i32));
}
- case HeapType::data:
+ case HeapType::struct_: {
assert(wasm.features.hasGC());
// TODO: Construct nontrivial types. For now just create a hard coded
- // struct or array.
- if (oneIn(2)) {
- // Use a local static to avoid creating a fresh nominal types in
- // --nominal mode.
- static HeapType trivialStruct = HeapType(Struct());
- return builder.makeStructNew(trivialStruct, std::vector<Expression*>{});
- }
- [[fallthrough]];
+ // struct.
+ // Use a local static to avoid creating a fresh nominal types in
+ // --nominal mode.
+ static HeapType trivialStruct = HeapType(Struct());
+ return builder.makeStructNew(trivialStruct, std::vector<Expression*>{});
+ }
case HeapType::array: {
// Use a local static to avoid creating a fresh nominal types in
// --nominal mode.
@@ -3051,8 +3066,8 @@ Type TranslateToFuzzReader::getSingleConcreteType() {
Type(HeapType::eq, NonNullable),
Type(HeapType::i31, Nullable),
// Type(HeapType::i31, NonNullable),
- Type(HeapType::data, Nullable),
- Type(HeapType::data, NonNullable),
+ Type(HeapType::struct_, Nullable),
+ Type(HeapType::struct_, NonNullable),
Type(HeapType::array, Nullable),
Type(HeapType::array, NonNullable)));
}
@@ -3068,8 +3083,10 @@ Type TranslateToFuzzReader::getReferenceType() {
Type(HeapType::eq, NonNullable),
Type(HeapType::i31, Nullable),
Type(HeapType::i31, NonNullable),
- Type(HeapType::data, Nullable),
- Type(HeapType::data, NonNullable)));
+ Type(HeapType::struct_, Nullable),
+ Type(HeapType::struct_, NonNullable),
+ Type(HeapType::array, Nullable),
+ Type(HeapType::array, NonNullable)));
}
Type TranslateToFuzzReader::getEqReferenceType() {
@@ -3079,8 +3096,10 @@ Type TranslateToFuzzReader::getEqReferenceType() {
Type(HeapType::eq, NonNullable),
Type(HeapType::i31, Nullable),
Type(HeapType::i31, NonNullable),
- Type(HeapType::data, Nullable),
- Type(HeapType::data, NonNullable)));
+ Type(HeapType::struct_, Nullable),
+ Type(HeapType::struct_, NonNullable),
+ Type(HeapType::array, Nullable),
+ Type(HeapType::array, NonNullable)));
}
Type TranslateToFuzzReader::getMVPType() {
@@ -3172,7 +3191,7 @@ HeapType TranslateToFuzzReader::getSubType(HeapType type) {
return pick(HeapType::any,
HeapType::eq,
HeapType::i31,
- HeapType::data,
+ HeapType::struct_,
HeapType::array,
HeapType::none);
case HeapType::eq:
@@ -3181,14 +3200,14 @@ HeapType TranslateToFuzzReader::getSubType(HeapType type) {
assert(wasm.features.hasGC());
return pick(HeapType::eq,
HeapType::i31,
- HeapType::data,
+ HeapType::struct_,
HeapType::array,
HeapType::none);
case HeapType::i31:
return pick(HeapType::i31, HeapType::none);
- case HeapType::data:
+ case HeapType::struct_:
// TODO: nontrivial types as well.
- return pick(HeapType::data, HeapType::array, HeapType::none);
+ return pick(HeapType::struct_, HeapType::none);
case HeapType::array:
return pick(HeapType::array, HeapType::none);
case HeapType::string:
diff --git a/src/tools/fuzzing/heap-types.cpp b/src/tools/fuzzing/heap-types.cpp
index 7d7b4cb8d..8b9d824d1 100644
--- a/src/tools/fuzzing/heap-types.cpp
+++ b/src/tools/fuzzing/heap-types.cpp
@@ -158,7 +158,7 @@ struct HeapTypeGeneratorImpl {
HeapType::any,
HeapType::eq,
HeapType::i31,
- HeapType::data,
+ HeapType::struct_,
HeapType::array);
}
@@ -273,7 +273,7 @@ struct HeapTypeGeneratorImpl {
} else if (rand.oneIn(2)) {
return HeapType::none;
} else {
- return HeapType::data;
+ return HeapType::struct_;
}
}
@@ -339,7 +339,7 @@ struct HeapTypeGeneratorImpl {
return pickSubEq();
case HeapType::i31:
return HeapType::i31;
- case HeapType::data:
+ case HeapType::struct_:
return pickSubStruct();
case HeapType::array:
return pickSubArray();
@@ -466,18 +466,16 @@ struct HeapTypeGeneratorImpl {
}
[[fallthrough]];
case HeapType::eq:
- switch (rand.upTo(4)) {
+ switch (rand.upTo(3)) {
case 0:
return HeapType::i31;
case 1:
- return HeapType::data;
- case 2:
return StructKind{};
- case 3:
+ case 2:
return ArrayKind{};
}
WASM_UNREACHABLE("unexpected index");
- case HeapType::data:
+ case HeapType::struct_:
return StructKind{};
case HeapType::array:
return ArrayKind{};
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index b2e1ef0c6..afb48106e 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -373,7 +373,7 @@ enum EncodedType {
// integer reference type
i31ref = -0x16, // 0x6a
// gc and string reference types
- dataref = -0x19, // 0x67
+ structref = -0x19, // 0x67
arrayref = -0x1a, // 0x66
stringref = -0x1c, // 0x64
stringview_wtf8 = -0x1d, // 0x63
@@ -399,14 +399,14 @@ enum EncodedType {
};
enum EncodedHeapType {
- func = -0x10, // 0x70
- ext = -0x11, // 0x6f
- any = -0x12, // 0x6e
- eq = -0x13, // 0x6d
- i31 = -0x16, // 0x6a
- data = -0x19, // 0x67
- array = -0x1a, // 0x66
- string = -0x1c, // 0x64
+ func = -0x10, // 0x70
+ ext = -0x11, // 0x6f
+ any = -0x12, // 0x6e
+ eq = -0x13, // 0x6d
+ i31 = -0x16, // 0x6a
+ struct_ = -0x19, // 0x67
+ array = -0x1a, // 0x66
+ string = -0x1c, // 0x64
// stringview/iter constants are identical to type, and cannot be duplicated
// here as that would be a compiler error, so add _heap suffixes. See
// https://github.com/WebAssembly/stringref/issues/12
@@ -1131,16 +1131,12 @@ enum ASTNodes {
BrOnCastFailNull = 0x4b,
RefCastNop = 0x4c,
RefIsFunc = 0x50,
- RefIsData = 0x51,
RefIsI31 = 0x52,
RefAsFunc = 0x58,
- RefAsData = 0x59,
RefAsI31 = 0x5a,
BrOnFunc = 0x60,
- BrOnData = 0x61,
BrOnI31 = 0x62,
BrOnNonFunc = 0x63,
- BrOnNonData = 0x64,
BrOnNonI31 = 0x65,
ExternInternalize = 0x70,
ExternExternalize = 0x71,
diff --git a/src/wasm-type.h b/src/wasm-type.h
index cfd57dd02..a359ea794 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -144,7 +144,7 @@ public:
// │ anyref ║ x │ │ x │ x │ f? n │ │ f_unc
// │ eqref ║ x │ │ x │ x │ n │ │ n_ullable
// │ i31ref ║ x │ │ x │ x │ n │ │
- // │ dataref ║ x │ │ x │ x │ n │ │
+ // │ structref ║ x │ │ x │ x │ n │ │
// ├─ Compound ──╫───┼───┼───┼───┤───────┤ │
// │ Ref ║ │ x │ x │ x │ f? n? │◄┘
// │ Tuple ║ │ x │ │ x │ │
@@ -323,7 +323,7 @@ public:
any,
eq,
i31,
- data,
+ struct_,
array,
string,
stringview_wtf8,
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index 7890c7a42..34f3d250d 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -125,7 +125,7 @@ Literal::Literal(const Literal& other) : type(other.type) {
WASM_UNREACHABLE("TODO: extern literals");
case HeapType::eq:
case HeapType::func:
- case HeapType::data:
+ case HeapType::struct_:
case HeapType::array:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
@@ -574,7 +574,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
WASM_UNREACHABLE("TODO: extern literals");
case HeapType::eq:
case HeapType::func:
- case HeapType::data:
+ case HeapType::struct_:
case HeapType::array:
WASM_UNREACHABLE("invalid type");
case HeapType::string:
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 767e0c2ab..abd51fcef 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1408,8 +1408,8 @@ void WasmBinaryWriter::writeType(Type type) {
case HeapType::i31:
o << S32LEB(BinaryConsts::EncodedType::i31ref);
return;
- case HeapType::data:
- o << S32LEB(BinaryConsts::EncodedType::dataref);
+ case HeapType::struct_:
+ o << S32LEB(BinaryConsts::EncodedType::structref);
return;
case HeapType::array:
o << S32LEB(BinaryConsts::EncodedType::arrayref);
@@ -1517,8 +1517,8 @@ void WasmBinaryWriter::writeHeapType(HeapType type) {
case HeapType::i31:
ret = BinaryConsts::EncodedHeapType::i31;
break;
- case HeapType::data:
- ret = BinaryConsts::EncodedHeapType::data;
+ case HeapType::struct_:
+ ret = BinaryConsts::EncodedHeapType::struct_;
break;
case HeapType::array:
ret = BinaryConsts::EncodedHeapType::array;
@@ -1887,8 +1887,8 @@ bool WasmBinaryBuilder::getBasicType(int32_t code, Type& out) {
case BinaryConsts::EncodedType::i31ref:
out = Type(HeapType::i31, Nullable);
return true;
- case BinaryConsts::EncodedType::dataref:
- out = Type(HeapType::data, Nullable);
+ case BinaryConsts::EncodedType::structref:
+ out = Type(HeapType::struct_, Nullable);
return true;
case BinaryConsts::EncodedType::arrayref:
out = Type(HeapType::array, Nullable);
@@ -1936,8 +1936,8 @@ bool WasmBinaryBuilder::getBasicHeapType(int64_t code, HeapType& out) {
case BinaryConsts::EncodedHeapType::i31:
out = HeapType::i31;
return true;
- case BinaryConsts::EncodedHeapType::data:
- out = HeapType::data;
+ case BinaryConsts::EncodedHeapType::struct_:
+ out = HeapType::struct_;
return true;
case BinaryConsts::EncodedHeapType::array:
out = HeapType::array;
@@ -2240,7 +2240,13 @@ void WasmBinaryBuilder::readTypes() {
"The only allowed trivial supertype for functions is func");
}
} else {
- if (basicSuper != HeapType::data) {
+ // Check for "struct" here even if we are parsing an array definition.
+ // This is the old nonstandard "struct_subtype" or "array_subtype"
+ // form of type definitions that used the old "data" type as the
+ // supertype placeholder when there was no nontrivial supertype.
+ // "data" no longer exists, but "struct" has the same encoding it used
+ // to have.
+ if (basicSuper != HeapType::struct_) {
throwError("The only allowed trivial supertype for structs and "
"arrays is data");
}
@@ -4024,14 +4030,12 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
break;
}
if (opcode == BinaryConsts::RefIsFunc ||
- opcode == BinaryConsts::RefIsData ||
opcode == BinaryConsts::RefIsI31) {
visitRefIs((curr = allocator.alloc<RefTest>())->cast<RefTest>(),
opcode);
break;
}
if (opcode == BinaryConsts::RefAsFunc ||
- opcode == BinaryConsts::RefAsData ||
opcode == BinaryConsts::RefAsI31) {
visitRefAsCast((curr = allocator.alloc<RefCast>())->cast<RefCast>(),
opcode);
@@ -6608,9 +6612,6 @@ void WasmBinaryBuilder::visitRefIs(RefTest* curr, uint8_t code) {
case BinaryConsts::RefIsFunc:
curr->castType = Type(HeapType::func, NonNullable);
break;
- case BinaryConsts::RefIsData:
- curr->castType = Type(HeapType::data, NonNullable);
- break;
case BinaryConsts::RefIsI31:
curr->castType = Type(HeapType::i31, NonNullable);
break;
@@ -6920,9 +6921,6 @@ void WasmBinaryBuilder::visitRefAsCast(RefCast* curr, uint32_t code) {
case BinaryConsts::RefAsFunc:
curr->type = Type(HeapType::func, NonNullable);
break;
- case BinaryConsts::RefAsData:
- curr->type = Type(HeapType::data, NonNullable);
- break;
case BinaryConsts::RefAsI31:
curr->type = Type(HeapType::i31, NonNullable);
break;
@@ -6985,14 +6983,6 @@ bool WasmBinaryBuilder::maybeVisitBrOn(Expression*& out, uint32_t code) {
op = BrOnCastFail;
castType = Type(HeapType::func, NonNullable);
break;
- case BinaryConsts::BrOnData:
- op = BrOnCast;
- castType = Type(HeapType::data, NonNullable);
- break;
- case BinaryConsts::BrOnNonData:
- op = BrOnCastFail;
- castType = Type(HeapType::data, NonNullable);
- break;
case BinaryConsts::BrOnI31:
op = BrOnCast;
castType = Type(HeapType::i31, NonNullable);
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 03dba223b..1087eedc6 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1190,9 +1190,8 @@ Type SExpressionWasmBuilder::stringToType(std::string_view str,
if (str.substr(0, 6) == "i31ref" && (prefix || str.size() == 6)) {
return Type(HeapType::i31, Nullable);
}
- if ((str.substr(0, 7) == "dataref" && (prefix || str.size() == 7)) ||
- (str.substr(0, 9) == "structref" && (prefix || str.size() == 9))) {
- return Type(HeapType::data, Nullable);
+ if (str.substr(0, 9) == "structref" && (prefix || str.size() == 9)) {
+ return Type(HeapType::struct_, Nullable);
}
if (str.substr(0, 8) == "arrayref" && (prefix || str.size() == 8)) {
return Type(HeapType::array, Nullable);
@@ -1242,9 +1241,8 @@ HeapType SExpressionWasmBuilder::stringToHeapType(std::string_view str,
if (str.substr(0, 3) == "i31" && (prefix || str.size() == 3)) {
return HeapType::i31;
}
- if ((str.substr(0, 4) == "data" && (prefix || str.size() == 4)) ||
- (str.substr(0, 6) == "struct" && (prefix || str.size() == 6))) {
- return HeapType::data;
+ if (str.substr(0, 6) == "struct" && (prefix || str.size() == 6)) {
+ return HeapType::struct_;
}
if (str.substr(0, 5) == "array" && (prefix || str.size() == 5)) {
return HeapType::array;
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index c4e1a863c..35ef12993 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2017,9 +2017,6 @@ void BinaryInstWriter::visitRefTest(RefTest* curr) {
case HeapType::func:
o << U32LEB(BinaryConsts::RefIsFunc);
return;
- case HeapType::data:
- o << U32LEB(BinaryConsts::RefIsData);
- return;
case HeapType::i31:
o << U32LEB(BinaryConsts::RefIsI31);
return;
@@ -2048,9 +2045,6 @@ void BinaryInstWriter::visitRefCast(RefCast* curr) {
case HeapType::func:
o << U32LEB(BinaryConsts::RefAsFunc);
return;
- case HeapType::data:
- o << U32LEB(BinaryConsts::RefAsData);
- return;
case HeapType::i31:
o << U32LEB(BinaryConsts::RefAsI31);
return;
@@ -2087,10 +2081,6 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
o << U32LEB(BinaryConsts::BrOnFunc);
o << U32LEB(getBreakIndex(curr->name));
return;
- case HeapType::data:
- o << U32LEB(BinaryConsts::BrOnData);
- o << U32LEB(getBreakIndex(curr->name));
- return;
case HeapType::i31:
o << U32LEB(BinaryConsts::BrOnI31);
o << U32LEB(getBreakIndex(curr->name));
@@ -2117,10 +2107,6 @@ void BinaryInstWriter::visitBrOn(BrOn* curr) {
o << U32LEB(BinaryConsts::BrOnNonFunc);
o << U32LEB(getBreakIndex(curr->name));
return;
- case HeapType::data:
- o << U32LEB(BinaryConsts::BrOnNonData);
- o << U32LEB(getBreakIndex(curr->name));
- return;
case HeapType::i31:
o << U32LEB(BinaryConsts::BrOnNonI31);
o << U32LEB(getBreakIndex(curr->name));
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index b65debc73..d06bfcbe7 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -486,7 +486,7 @@ HeapType::BasicHeapType getBasicHeapSupertype(HeapType type) {
case HeapTypeInfo::SignatureKind:
return HeapType::func;
case HeapTypeInfo::StructKind:
- return HeapType::data;
+ return HeapType::struct_;
case HeapTypeInfo::ArrayKind:
return HeapType::array;
}
@@ -518,18 +518,19 @@ std::optional<HeapType> getBasicHeapTypeLUB(HeapType::BasicHeapType a,
case HeapType::any:
return {HeapType::any};
case HeapType::eq:
- if (b == HeapType::i31 || b == HeapType::data || b == HeapType::array) {
+ if (b == HeapType::i31 || b == HeapType::struct_ ||
+ b == HeapType::array) {
return {HeapType::eq};
}
return {HeapType::any};
case HeapType::i31:
- if (b == HeapType::data || b == HeapType::array) {
+ if (b == HeapType::struct_ || b == HeapType::array) {
return {HeapType::eq};
}
return {HeapType::any};
- case HeapType::data:
+ case HeapType::struct_:
if (b == HeapType::array) {
- return {HeapType::data};
+ return {HeapType::eq};
}
return {HeapType::any};
case HeapType::array:
@@ -1014,7 +1015,7 @@ FeatureSet Type::getFeatures() const {
case HeapType::any:
case HeapType::eq:
case HeapType::i31:
- case HeapType::data:
+ case HeapType::struct_:
case HeapType::array:
return FeatureSet::ReferenceTypes | FeatureSet::GC;
case HeapType::string:
@@ -1266,7 +1267,7 @@ bool HeapType::isFunction() const {
bool HeapType::isData() const {
if (isBasic()) {
- return id == data;
+ return id == struct_ || id == array;
} else {
return getHeapTypeInfo(*this)->isData();
}
@@ -1304,7 +1305,7 @@ bool HeapType::isBottom() const {
case any:
case eq:
case i31:
- case data:
+ case struct_:
case array:
case string:
case stringview_wtf8:
@@ -1359,11 +1360,11 @@ size_t HeapType::getDepth() const {
if (isFunction()) {
depth++;
} else if (isStruct()) {
- // specific struct types <: data <: eq <: any
+ // specific struct types <: struct <: eq <: any
depth += 3;
} else if (isArray()) {
- // specific array types <: array <: data <: eq <: any
- depth += 4;
+ // specific array types <: array <: eq <: any
+ depth += 3;
}
} else {
// Some basic types have supers.
@@ -1376,16 +1377,14 @@ size_t HeapType::getDepth() const {
depth++;
break;
case HeapType::i31:
- case HeapType::data:
+ case HeapType::struct_:
+ case HeapType::array:
case HeapType::string:
case HeapType::stringview_wtf8:
case HeapType::stringview_wtf16:
case HeapType::stringview_iter:
depth += 2;
break;
- case HeapType::array:
- depth += 3;
- break;
case HeapType::none:
case HeapType::nofunc:
case HeapType::noext:
@@ -1406,7 +1405,7 @@ HeapType::BasicHeapType HeapType::getBottom() const {
case any:
case eq:
case i31:
- case data:
+ case struct_:
case array:
case string:
case stringview_wtf8:
@@ -1673,12 +1672,11 @@ bool SubTyper::isSubType(HeapType a, HeapType b) {
case HeapType::any:
return a.getBottom() == HeapType::none;
case HeapType::eq:
- return a == HeapType::i31 || a == HeapType::data ||
- a == HeapType::array || a == HeapType::none || a.isData();
+ return a == HeapType::i31 || a == HeapType::none || a.isData();
case HeapType::i31:
return a == HeapType::none;
- case HeapType::data:
- return a == HeapType::array || a == HeapType::none || a.isData();
+ case HeapType::struct_:
+ return a == HeapType::none || a.isStruct();
case HeapType::array:
return a == HeapType::none || a.isArray();
case HeapType::string:
@@ -1805,8 +1803,8 @@ std::ostream& TypePrinter::print(Type type) {
return os << "eqref";
case HeapType::i31:
return os << "i31ref";
- case HeapType::data:
- return os << "dataref";
+ case HeapType::struct_:
+ return os << "structref";
case HeapType::array:
return os << "arrayref";
case HeapType::string:
@@ -1851,8 +1849,8 @@ std::ostream& TypePrinter::print(HeapType type) {
return os << "eq";
case HeapType::i31:
return os << "i31";
- case HeapType::data:
- return os << "data";
+ case HeapType::struct_:
+ return os << "struct";
case HeapType::array:
return os << "array";
case HeapType::string:
diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp
index c2d06ae90..66bba8862 100644
--- a/src/wasm/wat-parser.cpp
+++ b/src/wasm/wat-parser.cpp
@@ -491,7 +491,7 @@ struct NullTypeParserCtx {
HeapTypeT makeExtern() { return Ok{}; }
HeapTypeT makeEq() { return Ok{}; }
HeapTypeT makeI31() { return Ok{}; }
- HeapTypeT makeData() { return Ok{}; }
+ HeapTypeT makeStructType() { return Ok{}; }
HeapTypeT makeArrayType() { return Ok{}; }
TypeT makeI32() { return Ok{}; }
@@ -575,7 +575,7 @@ template<typename Ctx> struct TypeParserCtx {
HeapTypeT makeExtern() { return HeapType::ext; }
HeapTypeT makeEq() { return HeapType::eq; }
HeapTypeT makeI31() { return HeapType::i31; }
- HeapTypeT makeData() { return HeapType::data; }
+ HeapTypeT makeStructType() { return HeapType::struct_; }
HeapTypeT makeArrayType() { return HeapType::array; }
TypeT makeI32() { return Type::i32; }
@@ -2449,8 +2449,8 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
if (ctx.in.takeKeyword("i31"sv)) {
return ctx.makeI31();
}
- if (ctx.in.takeKeyword("data"sv)) {
- return ctx.makeData();
+ if (ctx.in.takeKeyword("struct"sv)) {
+ return ctx.makeStructType();
}
if (ctx.in.takeKeyword("array"sv)) {
return ctx.makeArrayType();
@@ -2465,7 +2465,7 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
// | 'anyref' => anyref
// | 'eqref' => eqref
// | 'i31ref' => i31ref
-// | 'dataref' => dataref
+// | 'structref' => structref
// | 'arrayref' => arrayref
// | '(' ref null? t:heaptype ')' => ref null? t
template<typename Ctx> MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx) {
@@ -2484,8 +2484,8 @@ template<typename Ctx> MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx) {
if (ctx.in.takeKeyword("i31ref"sv)) {
return ctx.makeRefType(ctx.makeI31(), Nullable);
}
- if (ctx.in.takeKeyword("dataref"sv)) {
- return ctx.makeRefType(ctx.makeData(), Nullable);
+ if (ctx.in.takeKeyword("structref"sv)) {
+ return ctx.makeRefType(ctx.makeStructType(), Nullable);
}
if (ctx.in.takeKeyword("arrayref"sv)) {
return ctx.in.err("arrayref not yet supported");