Skip to content
Merged
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
11 changes: 5 additions & 6 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,10 +1614,11 @@ BinaryenExpressionRef BinaryenRefFunc(BinaryenModuleRef module,
// is non-imported if not. TODO: If we want to allow creating imports later,
// we would need an API addition or change.
auto* wasm = (Module*)module;
if (wasm->getFunctionOrNull(func)) {
if ([[maybe_unused]] auto* f = wasm->getFunctionOrNull(func)) {
assert(f->type.getHeapType() == HeapType(type));
// Use the HeapType constructor, which will do a lookup on the module.
return static_cast<Expression*>(
Builder(*(Module*)module).makeRefFunc(func, HeapType(type)));
Builder(*(Module*)module).makeRefFunc(func));
} else {
// Assume non-imported, and provide the full type for that.
Type full = Type(HeapType(type), NonNullable, Exact);
Expand Down Expand Up @@ -5299,8 +5300,7 @@ BinaryenAddActiveElementSegment(BinaryenModuleRef module,
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
segment->data.push_back(
Builder(*(Module*)module)
.makeRefFunc(funcNames[i], func->type.getHeapType()));
Builder(*(Module*)module).makeRefFunc(funcNames[i]));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
Expand All @@ -5317,8 +5317,7 @@ BinaryenAddPassiveElementSegment(BinaryenModuleRef module,
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
segment->data.push_back(
Builder(*(Module*)module)
.makeRefFunc(funcNames[i], func->type.getHeapType()));
Builder(*(Module*)module).makeRefFunc(funcNames[i]));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
Expand Down
4 changes: 1 addition & 3 deletions src/ir/ReFinalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ void ReFinalize::visitMemorySize(MemorySize* curr) { curr->finalize(); }
void ReFinalize::visitMemoryGrow(MemoryGrow* curr) { curr->finalize(); }
void ReFinalize::visitRefNull(RefNull* curr) { curr->finalize(); }
void ReFinalize::visitRefIsNull(RefIsNull* curr) { curr->finalize(); }
void ReFinalize::visitRefFunc(RefFunc* curr) {
curr->finalize(curr->type.getHeapType(), *getModule());
}
void ReFinalize::visitRefFunc(RefFunc* curr) { curr->finalize(*getModule()); }
void ReFinalize::visitRefEq(RefEq* curr) { curr->finalize(); }
void ReFinalize::visitTableGet(TableGet* curr) { curr->finalize(); }
void ReFinalize::visitTableSet(TableSet* curr) { curr->finalize(); }
Expand Down
3 changes: 1 addition & 2 deletions src/ir/possible-contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ class PossibleContents {
wasm.getGlobal(info.name)->type);
} else {
assert(info.kind == ExternalKind::Function);
return builder.makeRefFunc(
info.name, wasm.getFunction(info.name)->type.getHeapType());
return builder.makeRefFunc(info.name);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/ir/table-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ inline Index append(Table& table, Name name, Module& wasm) {
wasm.dylinkSection->tableSize++;
}

auto* func = wasm.getFunctionOrNull(name);
assert(func != nullptr && "Cannot append non-existing function to a table.");
segment->data.push_back(
Builder(wasm).makeRefFunc(name, func->type.getHeapType()));
assert(wasm.getFunctionOrNull(name) != nullptr &&
"Cannot append non-existing function to a table.");
segment->data.push_back(Builder(wasm).makeRefFunc(name));
table.initial++;
return tableIndex;
}
Expand Down
2 changes: 1 addition & 1 deletion src/passes/FuncCastEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct FuncCastEmulation : public Pass {
}
auto* thunk = iter->second;
ref->func = thunk->name;
ref->finalize(thunk->type.getHeapType(), *module);
ref->finalize(*module);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/passes/JSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ struct JSPI : public Pass {
if (iter == wrappedExports.end()) {
continue;
}
auto* replacementRef = builder.makeRefFunc(
iter->second,
module->getFunction(iter->second)->type.getHeapType());
auto* replacementRef = builder.makeRefFunc(iter->second);
segment->data[i] = replacementRef;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct LegalizeJSInterface : public Pass {
}

curr->func = iter->second->name;
curr->finalize(iter->second->type.getHeapType(), *getModule());
curr->finalize(*getModule());
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/passes/MergeSimilarFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ struct ParamInfo {
if (const auto literals = std::get_if<Literals>(&values)) {
return builder.makeConst((*literals)[index]);
} else if (auto callees = std::get_if<std::vector<Name>>(&values)) {
auto fnName = (*callees)[index];
auto heapType = module->getFunction(fnName)->type.getHeapType();
return builder.makeRefFunc(fnName, heapType);
return builder.makeRefFunc((*callees)[index]);
} else {
WASM_UNREACHABLE("unexpected const value type");
}
Expand Down
12 changes: 4 additions & 8 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,8 +1694,7 @@ Function* TranslateToFuzzReader::addFunction() {
}
});
auto& randomElem = compatibleSegments[upTo(compatibleSegments.size())];
randomElem->data.push_back(
builder.makeRefFunc(func->name, func->type.getHeapType()));
randomElem->data.push_back(builder.makeRefFunc(func->name));
}
numAddedFunctions++;
return func;
Expand Down Expand Up @@ -2988,10 +2987,7 @@ Expression* TranslateToFuzzReader::makeCallRef(Type type) {
}
// TODO: half the time make a completely random item with that type.
return builder.makeCallRef(
builder.makeRefFunc(target->name, target->type.getHeapType()),
args,
type,
isReturn);
builder.makeRefFunc(target->name), args, type, isReturn);
}

Expression* TranslateToFuzzReader::makeLocalGet(Type type) {
Expand Down Expand Up @@ -3627,7 +3623,7 @@ Expression* TranslateToFuzzReader::makeRefFuncConst(Type type) {
do {
auto& func = wasm.functions[i];
if (Type::isSubType(func->type, type)) {
return builder.makeRefFunc(func->name, func->type.getHeapType());
return builder.makeRefFunc(func->name);
}
i = (i + 1) % wasm.functions.size();
} while (i != start);
Expand Down Expand Up @@ -3666,7 +3662,7 @@ Expression* TranslateToFuzzReader::makeRefFuncConst(Type type) {
Type(heapType, NonNullable, Exact),
{},
body));
return builder.makeRefFunc(func->name, heapType);
return builder.makeRefFunc(func->name);
}

Expression* TranslateToFuzzReader::makeConst(Type type) {
Expand Down
5 changes: 1 addition & 4 deletions src/tools/wasm-merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ void updateTypes(Module& wasm) {
}
}

void visitRefFunc(RefFunc* curr) {
curr->finalize(getModule()->getFunction(curr->func)->type.getHeapType(),
*getModule());
}
void visitRefFunc(RefFunc* curr) { curr->finalize(*getModule()); }

void visitFunction(Function* curr) {
ReFinalize().walkFunctionInModule(curr, getModule());
Expand Down
6 changes: 3 additions & 3 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,10 @@ class Builder {
ret->type = type;
return ret;
}
RefFunc* makeRefFunc(Name func, HeapType heapType) {
RefFunc* makeRefFunc(Name func) {
auto* ret = wasm.allocator.alloc<RefFunc>();
ret->func = func;
ret->finalize(heapType, wasm);
ret->finalize(wasm);
return ret;
}
RefEq* makeRefEq(Expression* left, Expression* right) {
Expand Down Expand Up @@ -1368,7 +1368,7 @@ class Builder {
return makeRefNull(type.getHeapType());
}
if (type.isFunction()) {
return makeRefFunc(value.getFunc(), type.getHeapType());
return makeRefFunc(value.getFunc());
}
if (type.isRef() && type.getHeapType().isMaybeShared(HeapType::i31)) {
return makeRefI31(makeConst(value.geti31()),
Expand Down
2 changes: 1 addition & 1 deletion src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ class RefFunc : public SpecificExpression<Expression::RefFuncId> {
Name func;

void finalize();
void finalize(HeapType heapType, Module& wasm);
void finalize(Module& wasm);
};

class RefEq : public SpecificExpression<Expression::RefEqId> {
Expand Down
3 changes: 1 addition & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4962,8 +4962,7 @@ void WasmBinaryReader::readElementSegments() {
} else {
for (Index j = 0; j < size; j++) {
Index index = getU32LEB();
auto sig = getTypeByFunctionIndex(index);
auto* refFunc = Builder(wasm).makeRefFunc(getFunctionName(index), sig);
auto* refFunc = Builder(wasm).makeRefFunc(getFunctionName(index));
segmentData.push_back(refFunc);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ Result<> IRBuilder::makeRefIsNull() {
}

Result<> IRBuilder::makeRefFunc(Name func) {
push(builder.makeRefFunc(func, wasm.getFunction(func)->type.getHeapType()));
push(builder.makeRefFunc(func));
return Ok{};
}

Expand Down
6 changes: 1 addition & 5 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,7 @@ void RefFunc::finalize() {
assert(type.isSignature());
}

void RefFunc::finalize(HeapType heapType, Module& wasm) {
type = Type(heapType,
NonNullable,
wasm.getFunction(func)->imported() ? Inexact : Exact);
}
void RefFunc::finalize(Module& wasm) { type = wasm.getFunction(func)->type; }

void RefEq::finalize() {
if (left->type == Type::unreachable || right->type == Type::unreachable) {
Expand Down
Loading