summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp9
-rw-r--r--src/ir/module-splitting.cpp3
-rw-r--r--src/ir/table-utils.h4
-rw-r--r--src/tools/fuzzing.h15
-rw-r--r--src/wasm-builder.h6
-rw-r--r--src/wasm/wasm-binary.cpp3
-rw-r--r--src/wasm/wasm-s-parser.cpp4
-rw-r--r--src/wasm/wasm-validator.cpp2
8 files changed, 20 insertions, 26 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 907dbbb8b..49817974a 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -1283,9 +1283,10 @@ BinaryenExpressionRef BinaryenRefAs(BinaryenModuleRef module,
BinaryenExpressionRef
BinaryenRefFunc(BinaryenModuleRef module, const char* func, BinaryenType type) {
+ // TODO: consider changing the C API to receive a heap type
Type type_(type);
return static_cast<Expression*>(
- Builder(*(Module*)module).makeRefFunc(func, type_));
+ Builder(*(Module*)module).makeRefFunc(func, type_.getHeapType()));
}
BinaryenExpressionRef BinaryenRefEq(BinaryenModuleRef module,
@@ -3485,9 +3486,8 @@ BinaryenAddActiveElementSegment(BinaryenModuleRef module,
if (func == nullptr) {
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
- Type type(HeapType(func->sig), Nullable);
segment->data.push_back(
- Builder(*(Module*)module).makeRefFunc(funcNames[i], type));
+ Builder(*(Module*)module).makeRefFunc(funcNames[i], func->sig));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
@@ -3503,9 +3503,8 @@ BinaryenAddPassiveElementSegment(BinaryenModuleRef module,
if (func == nullptr) {
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
- Type type(HeapType(func->sig), Nullable);
segment->data.push_back(
- Builder(*(Module*)module).makeRefFunc(funcNames[i], type));
+ Builder(*(Module*)module).makeRefFunc(funcNames[i], func->sig));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp
index 0634171ce..68496045f 100644
--- a/src/ir/module-splitting.cpp
+++ b/src/ir/module-splitting.cpp
@@ -105,8 +105,7 @@ template<class F> void forEachElement(Module& module, F f) {
static RefFunc* makeRefFunc(Module& wasm, Function* func) {
// FIXME: make the type NonNullable when we support it!
- return Builder(wasm).makeRefFunc(func->name,
- Type(HeapType(func->sig), Nullable));
+ return Builder(wasm).makeRefFunc(func->name, func->sig);
}
struct TableSlotManager {
diff --git a/src/ir/table-utils.h b/src/ir/table-utils.h
index d3151bd2c..d2f90626a 100644
--- a/src/ir/table-utils.h
+++ b/src/ir/table-utils.h
@@ -87,9 +87,7 @@ inline Index append(Table& table, Name name, Module& wasm) {
auto* func = wasm.getFunctionOrNull(name);
assert(func != nullptr && "Cannot append non-existing function to a table.");
- // FIXME: make the type NonNullable when we support it!
- auto type = Type(HeapType(func->sig), Nullable);
- segment->data.push_back(Builder(wasm).makeRefFunc(name, type));
+ segment->data.push_back(Builder(wasm).makeRefFunc(name, func->sig));
table.initial = table.initial + 1;
return tableIndex;
}
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 37c027088..b3b21f8ca 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -738,7 +738,7 @@ private:
}
// add some to an elem segment
while (oneIn(3) && !finishedInput) {
- auto type = Type(HeapType(func->sig), Nullable);
+ auto type = Type(HeapType(func->sig), NonNullable);
std::vector<ElementSegment*> compatibleSegments;
ModuleUtils::iterActiveElementSegments(
wasm, [&](ElementSegment* segment) {
@@ -747,8 +747,7 @@ private:
}
});
auto& randomElem = compatibleSegments[upTo(compatibleSegments.size())];
- // FIXME: make the type NonNullable when we support it!
- randomElem->data.push_back(builder.makeRefFunc(func->name, type));
+ randomElem->data.push_back(builder.makeRefFunc(func->name, func->sig));
}
numAddedFunctions++;
return func;
@@ -1523,10 +1522,9 @@ private:
for (const auto& type : target->sig.params) {
args.push_back(make(type));
}
- auto targetType = Type(HeapType(target->sig), NonNullable);
// TODO: half the time make a completely random item with that type.
return builder.makeCallRef(
- builder.makeRefFunc(target->name, targetType), args, type, isReturn);
+ builder.makeRefFunc(target->name, target->sig), args, type, isReturn);
}
Expression* makeLocalGet(Type type) {
@@ -2115,8 +2113,7 @@ private:
if (!wasm.functions.empty() && !oneIn(wasm.functions.size())) {
target = pick(wasm.functions).get();
}
- auto type = Type(HeapType(target->sig), Nullable);
- return builder.makeRefFunc(target->name, type);
+ return builder.makeRefFunc(target->name, target->sig);
}
if (type == Type::i31ref) {
return builder.makeI31New(makeConst(Type::i32));
@@ -2138,7 +2135,7 @@ private:
// TODO: randomize the order
for (auto& func : wasm.functions) {
if (type == Type(HeapType(func->sig), NonNullable)) {
- return builder.makeRefFunc(func->name, type);
+ return builder.makeRefFunc(func->name, func->sig);
}
}
// We failed to find a function, so create a null reference if we can.
@@ -2160,7 +2157,7 @@ private:
sig,
{},
builder.makeUnreachable()));
- return builder.makeRefFunc(func->name, type);
+ return builder.makeRefFunc(func->name, heapType);
}
if (type.isRtt()) {
return builder.makeRtt(type);
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index d1e06b5be..46ec734cc 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -618,10 +618,10 @@ public:
ret->finalize();
return ret;
}
- RefFunc* makeRefFunc(Name func, Type type) {
+ RefFunc* makeRefFunc(Name func, HeapType heapType) {
auto* ret = wasm.allocator.alloc<RefFunc>();
ret->func = func;
- ret->finalize(type);
+ ret->finalize(Type(heapType, NonNullable));
return ret;
}
RefEq* makeRefEq(Expression* left, Expression* right) {
@@ -870,7 +870,7 @@ public:
return makeRefNull(type);
}
if (type.isFunction()) {
- return makeRefFunc(value.getFunc(), type);
+ return makeRefFunc(value.getFunc(), type.getHeapType());
}
if (type.isRtt()) {
return makeRtt(value.type);
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 3ff98187f..ed18cc0e4 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2856,8 +2856,7 @@ void WasmBinaryBuilder::readElementSegments() {
Index index = getU32LEB();
auto sig = getSignatureByFunctionIndex(index);
// Use a placeholder name for now
- auto* refFunc = Builder(wasm).makeRefFunc(
- Name::fromInt(index), Type(HeapType(sig), Nullable));
+ auto* refFunc = Builder(wasm).makeRefFunc(Name::fromInt(index), sig);
functionRefs[index].push_back(refFunc);
segmentData.push_back(refFunc);
}
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 8d1583059..a5f5f88f2 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -3354,8 +3354,8 @@ ElementSegment* SExpressionWasmBuilder::parseElemFinish(
} else {
for (; i < s.size(); i++) {
auto func = getFunctionName(*s[i]);
- segment->data.push_back(Builder(wasm).makeRefFunc(
- func, Type(HeapType(functionSignatures[func]), Nullable)));
+ segment->data.push_back(
+ Builder(wasm).makeRefFunc(func, functionSignatures[func]));
}
}
return wasm.addElementSegment(std::move(segment));
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 8464a3aa9..2ac4e3187 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2001,6 +2001,8 @@ void FunctionValidator::visitRefFunc(RefFunc* curr) {
shouldBeTrue(curr->type.isFunction(),
curr,
"ref.func must have a function reference type");
+ shouldBeTrue(
+ !curr->type.isNullable(), curr, "ref.func must have non-nullable type");
// TODO: verify it also has a typed function references type, and the right
// one,
// curr->type.getHeapType().getSignature()