diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/literal-utils.h | 2 | ||||
-rw-r--r-- | src/ir/type-updating.cpp | 8 | ||||
-rw-r--r-- | src/passes/Inlining.cpp | 2 | ||||
-rw-r--r-- | src/passes/RedundantSetElimination.cpp | 2 | ||||
-rw-r--r-- | src/wasm-type.h | 8 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 10 |
8 files changed, 26 insertions, 10 deletions
diff --git a/src/ir/literal-utils.h b/src/ir/literal-utils.h index 498085796..ce7da69cd 100644 --- a/src/ir/literal-utils.h +++ b/src/ir/literal-utils.h @@ -32,7 +32,7 @@ inline Expression* makeFromInt32(int32_t x, Type type, Module& wasm) { } inline bool canMakeZero(Type type) { - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { return false; } if (type.isTuple()) { diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp index 2dc60d2df..d91c5f385 100644 --- a/src/ir/type-updating.cpp +++ b/src/ir/type-updating.cpp @@ -34,7 +34,7 @@ void handleNonDefaultableLocals(Function* func, Module& wasm) { } bool hasNonNullable = false; for (auto type : func->vars) { - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { hasNonNullable = true; break; } @@ -52,7 +52,7 @@ void handleNonDefaultableLocals(Function* func, Module& wasm) { continue; } auto type = func->getLocalType(get->index); - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { // The get should now return a nullable value, and a ref.as_non_null // fixes that up. get->type = Type(type.getHeapType(), Nullable); @@ -74,7 +74,7 @@ void handleNonDefaultableLocals(Function* func, Module& wasm) { continue; } auto type = func->getLocalType(set->index); - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { set->type = Type(type.getHeapType(), Nullable); *setp = builder.makeRefAs(RefAsNonNull, set); } @@ -83,7 +83,7 @@ void handleNonDefaultableLocals(Function* func, Module& wasm) { // Rewrite the types of the function's vars (which we can do now, after we // are done using them to know which local.gets etc to fix). for (auto& type : func->vars) { - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { type = Type(type.getHeapType(), Nullable); } } diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 7c51e78cb..f4baf706d 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -293,7 +293,7 @@ doInlining(Module* module, Function* into, const InliningAction& action) { // zero-init value for (Index i = 0; i < from->vars.size(); i++) { auto type = from->vars[i]; - if (type.isRef() && !type.isNullable()) { + if (type.isNonNullable()) { // Non-nullable locals do not need to be zeroed out. They have no zero // value, and by definition should not be used before being written to, so // any value we set here would not be observed anyhow. diff --git a/src/passes/RedundantSetElimination.cpp b/src/passes/RedundantSetElimination.cpp index ccf6e6ac2..f42119a92 100644 --- a/src/passes/RedundantSetElimination.cpp +++ b/src/passes/RedundantSetElimination.cpp @@ -190,7 +190,7 @@ struct RedundantSetElimination std::cout << "new param value for " << i << '\n'; #endif start[i] = getUniqueValue(); - } else if (type.isRef() && !type.isNullable()) { + } else if (type.isNonNullable()) { #ifdef RSE_DEBUG std::cout << "new unique value for non-nullable " << i << '\n'; #endif diff --git a/src/wasm-type.h b/src/wasm-type.h index 12b4f3df7..ff1019e55 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -146,7 +146,15 @@ public: bool isRef() const; bool isFunction() const; bool isData() const; + // Checks whether a type is a reference and is nullable. This returns false + // for a value that is not a reference, that is, for which nullability is + // irrelevant. bool isNullable() const; + // Checks whether a type is a reference and is non-nullable. This returns + // false for a value that is not a reference, that is, for which nullability + // is irrelevant. (For that reason, this is only the negation of isNullable() + // on references, but both return false on non-references.) + bool isNonNullable() const; bool isRtt() const; bool isStruct() const; bool isArray() const; diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 4ff354e56..151ea83e5 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -34,7 +34,7 @@ Literal::Literal(Type type) : type(type) { // i31ref is special in that it is non-nullable, so we construct with zero i32 = 0; } else { - assert(type != Type::unreachable && (!type.isRef() || type.isNullable())); + assert(type != Type::unreachable && !type.isNonNullable()); if (isData()) { new (&gcData) std::shared_ptr<GCData>(); } else if (type.isRtt()) { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 43ab509a8..f58c4f783 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2572,7 +2572,7 @@ void WasmBinaryBuilder::pushExpression(Expression* curr) { std::vector<Type> finalTypes; if (!wasm.features.hasGCNNLocals()) { for (auto t : type) { - if (t.isRef() && !t.isNullable()) { + if (t.isNonNullable()) { t = Type(t.getHeapType(), Nullable); } finalTypes.push_back(t); diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index eb1bd14b1..d4f38cc2c 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -845,6 +845,14 @@ bool Type::isNullable() const { } } +bool Type::isNonNullable() const { + if (isRef()) { + return !isNullable(); + } else { + return false; + } +} + bool Type::isRtt() const { if (isBasic()) { return false; @@ -869,7 +877,7 @@ bool Type::isDefaultable() const { } return true; } - return isConcrete() && (!isRef() || isNullable()) && !isRtt(); + return isConcrete() && !isNonNullable() && !isRtt(); } Nullability Type::getNullability() const { |