summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/fuzzing.h6
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm-type.h13
-rw-r--r--src/wasm/wasm-binary.cpp24
-rw-r--r--src/wasm/wasm-s-parser.cpp11
-rw-r--r--src/wasm/wasm-type.cpp8
-rw-r--r--src/wasm/wasm.cpp8
7 files changed, 42 insertions, 29 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 621555ab1..7d9131767 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -1478,7 +1478,7 @@ private:
for (const auto& type : target->sig.params) {
args.push_back(make(type));
}
- auto targetType = Type(HeapType(target->sig), /* nullable = */ true);
+ auto targetType = Type(HeapType(target->sig), Nullable);
// TODO: half the time make a completely random item with that type.
return builder.makeCallRef(
builder.makeRefFunc(target->name, targetType), args, type, isReturn);
@@ -2066,7 +2066,7 @@ private:
if (!wasm.functions.empty() && !oneIn(wasm.functions.size())) {
target = pick(wasm.functions).get();
}
- auto type = Type(HeapType(target->sig), /* nullable = */ true);
+ auto type = Type(HeapType(target->sig), Nullable);
return builder.makeRefFunc(target->name, type);
}
if (type == Type::i31ref) {
@@ -2079,7 +2079,7 @@ private:
for (auto& func : wasm.functions) {
// FIXME: RefFunc type should be non-nullable, but we emit nullable
// types for now.
- if (type == Type(HeapType(func->sig), /* nullable = */ true)) {
+ if (type == Type(HeapType(func->sig), Nullable)) {
return builder.makeRefFunc(func->name, type);
}
}
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 1d250aa2b..382bfbd4f 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1276,6 +1276,7 @@ public:
Type getType(int initial);
HeapType getHeapType();
+ Mutability getMutability();
Field getField();
Type getConcreteType();
Name getInlineString();
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 0df515f79..0df3bfeed 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -44,6 +44,9 @@ struct Struct;
struct Array;
struct Rtt;
+enum Nullability { NonNullable, Nullable };
+enum Mutability { Immutable, Mutable };
+
// The type used for interning IDs in the public interfaces of Type and
// HeapType.
using TypeID = uint64_t;
@@ -93,7 +96,7 @@ public:
// Construct from a heap type description. Also covers construction from
// Signature, Struct or Array via implicit conversion to HeapType.
- Type(HeapType, bool nullable);
+ Type(HeapType, Nullability nullable);
// Construct from rtt description
Type(Rtt);
@@ -384,12 +387,12 @@ struct Field {
i8,
i16,
} packedType; // applicable iff type=i32
- bool mutable_;
+ Mutability mutable_;
Name name;
- Field(Type type, bool mutable_, Name name = Name())
+ Field(Type type, Mutability mutable_, Name name = Name())
: type(type), packedType(not_packed), mutable_(mutable_), name(name) {}
- Field(PackedType packedType, bool mutable_, Name name = Name())
+ Field(PackedType packedType, Mutability mutable_, Name name = Name())
: type(Type::i32), packedType(packedType), mutable_(mutable_), name(name) {}
constexpr bool isPacked() const {
@@ -483,7 +486,7 @@ struct TypeBuilder {
// TypeBuilder's HeapTypes. Temporary Ref and Rtt types are backed by the
// HeapType at index `i`.
Type getTempTupleType(const Tuple&);
- Type getTempRefType(size_t i, bool nullable);
+ Type getTempRefType(size_t i, Nullability nullable);
Type getTempRttType(size_t i, uint32_t depth);
// Canonicalizes and returns all of the heap types. May only be called once
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 796ba4b4e..66715686e 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1411,10 +1411,10 @@ Type WasmBinaryBuilder::getType(int initial) {
case BinaryConsts::EncodedType::eqref:
return Type::eqref;
case BinaryConsts::EncodedType::nullable:
- return Type(getHeapType(), /* nullable = */ true);
+ return Type(getHeapType(), Nullable);
case BinaryConsts::EncodedType::nonnullable:
// FIXME: for now, force all inputs to be nullable
- return Type(getHeapType(), /* nullable = */ true);
+ return Type(getHeapType(), Nullable);
case BinaryConsts::EncodedType::i31ref:
return Type::i31ref;
case BinaryConsts::EncodedType::rtt_n: {
@@ -1461,21 +1461,32 @@ HeapType WasmBinaryBuilder::getHeapType() {
WASM_UNREACHABLE("unexpected type");
}
+Mutability WasmBinaryBuilder::getMutability() {
+ switch (getU32LEB()) {
+ case 0:
+ return Immutable;
+ case 1:
+ return Mutable;
+ default:
+ throw ParseException("Expected 0 or 1 for mutability");
+ }
+}
+
Field WasmBinaryBuilder::getField() {
// The value may be a general wasm type, or one of the types only possible in
// a field.
auto initial = getS32LEB();
if (initial == BinaryConsts::EncodedType::i8) {
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(Field::i8, mutable_);
}
if (initial == BinaryConsts::EncodedType::i16) {
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(Field::i16, mutable_);
}
// It's a regular wasm value.
auto type = getType(initial);
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(type, mutable_);
}
@@ -5433,8 +5444,7 @@ void WasmBinaryBuilder::visitRefFunc(RefFunc* curr) {
// To support typed function refs, we give the reference not just a general
// funcref, but a specific subtype with the actual signature.
// FIXME: for now, emit a nullable type here
- curr->finalize(Type(HeapType(getSignatureByFunctionIndex(index)),
- /* nullable = */ true));
+ curr->finalize(Type(HeapType(getSignatureByFunctionIndex(index)), Nullable));
}
void WasmBinaryBuilder::visitRefEq(RefEq* curr) {
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 85bc2aba9..c1c227d21 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -932,10 +932,10 @@ Type SExpressionWasmBuilder::elementToType(Element& s) {
std::string("invalid reference type qualifier"), s.line, s.col);
}
// FIXME: for now, force all inputs to be nullable
- bool nullable = true;
+ Nullability nullable = Nullable;
size_t i = 1;
if (size == 3) {
- nullable = true;
+ nullable = Nullable;
i++;
}
return Type(parseHeapType(*s[i]), nullable);
@@ -1925,8 +1925,7 @@ Expression* SExpressionWasmBuilder::makeRefFunc(Element& s) {
ret->func = func;
// To support typed function refs, we give the reference not just a general
// funcref, but a specific subtype with the actual signature.
- ret->finalize(
- Type(HeapType(functionSignatures[func]), /* nullable = */ true));
+ ret->finalize(Type(HeapType(functionSignatures[func]), Nullable));
return ret;
}
@@ -2826,7 +2825,7 @@ HeapType SExpressionWasmBuilder::parseHeapType(Element& s) {
}
// It's a struct or an array.
auto parseField = [&](Element* t) {
- bool mutable_ = false;
+ Mutability mutable_ = Immutable;
// t is a list, containing either
// TYPE
// or
@@ -2842,7 +2841,7 @@ HeapType SExpressionWasmBuilder::parseHeapType(Element& s) {
}
// The element may also be (mut (..)).
if (elementStartsWith(t, MUT)) {
- mutable_ = true;
+ mutable_ = Mutable;
t = (*t)[1];
}
if (t->isStr()) {
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index ddad9c0ed..95d351ba2 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -39,7 +39,7 @@ struct TypeInfo {
} kind;
struct Ref {
HeapType heapType;
- bool nullable;
+ Nullability nullable;
};
union {
Tuple tuple;
@@ -49,7 +49,7 @@ struct TypeInfo {
TypeInfo(const Tuple& tuple) : kind(TupleKind), tuple(tuple) {}
TypeInfo(Tuple&& tuple) : kind(TupleKind), tuple(std::move(tuple)) {}
- TypeInfo(HeapType heapType, bool nullable)
+ TypeInfo(HeapType heapType, Nullability nullable)
: kind(RefKind), ref{heapType, nullable} {}
TypeInfo(Rtt rtt) : kind(RttKind), rtt(rtt) {}
TypeInfo(const TypeInfo& other);
@@ -351,7 +351,7 @@ Type::Type(Tuple&& tuple) {
new (this) Type(globalTypeStore.canonicalize(std::move(tuple)));
}
-Type::Type(HeapType heapType, bool nullable) {
+Type::Type(HeapType heapType, Nullability nullable) {
new (this) Type(globalTypeStore.canonicalize(TypeInfo(heapType, nullable)));
}
@@ -1053,7 +1053,7 @@ Type TypeBuilder::getTempTupleType(const Tuple& tuple) {
return impl->typeStore.canonicalize(tuple);
}
-Type TypeBuilder::getTempRefType(size_t i, bool nullable) {
+Type TypeBuilder::getTempRefType(size_t i, Nullability nullable) {
assert(i < impl->entries.size() && "Index out of bounds");
return impl->typeStore.canonicalize(
TypeInfo(impl->entries[i].get(), nullable));
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 8e6550c27..851e6a804 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -978,7 +978,7 @@ void MemoryGrow::finalize() {
}
}
-void RefNull::finalize(HeapType heapType) { type = Type(heapType, true); }
+void RefNull::finalize(HeapType heapType) { type = Type(heapType, Nullable); }
void RefNull::finalize(Type type_) {
type = type_;
@@ -1098,7 +1098,7 @@ void RefCast::finalize() {
type = Type::unreachable;
} else {
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
}
@@ -1125,7 +1125,7 @@ void StructNew::finalize() {
return;
}
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
void StructGet::finalize() {
@@ -1151,7 +1151,7 @@ void ArrayNew::finalize() {
return;
}
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
void ArrayGet::finalize() {