Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
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
15 changes: 9 additions & 6 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4973,7 +4973,7 @@ static BinaryenFunctionRef addFunctionInternal(BinaryenModuleRef module,
BinaryenExpressionRef body) {
auto* ret = new Function;
ret->setExplicitName(name);
ret->type = type;
ret->type = Type(type, NonNullable, Exact);
for (BinaryenIndex i = 0; i < numVarTypes; i++) {
ret->vars.push_back(Type(varTypes[i]));
}
Expand Down Expand Up @@ -5097,7 +5097,8 @@ void BinaryenAddFunctionImport(BinaryenModuleRef module,
func->module = externalModuleName;
func->base = externalBaseName;
// TODO: Take a HeapType rather than params and results.
func->type = Signature(Type(params), Type(results));
func->type =
Type(Signature(Type(params), Type(results)), NonNullable, Exact);
((Module*)module)->addFunction(std::move(func));
} else {
// already exists so just set module and base
Expand Down Expand Up @@ -5285,7 +5286,8 @@ BinaryenAddActiveElementSegment(BinaryenModuleRef module,
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
segment->data.push_back(
Builder(*(Module*)module).makeRefFunc(funcNames[i], func->type));
Builder(*(Module*)module)
.makeRefFunc(funcNames[i], func->type.getHeapType()));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
Expand All @@ -5302,7 +5304,8 @@ BinaryenAddPassiveElementSegment(BinaryenModuleRef module,
Fatal() << "invalid function '" << funcNames[i] << "'.";
}
segment->data.push_back(
Builder(*(Module*)module).makeRefFunc(funcNames[i], func->type));
Builder(*(Module*)module)
.makeRefFunc(funcNames[i], func->type.getHeapType()));
}
return ((Module*)module)->addElementSegment(std::move(segment));
}
Expand Down Expand Up @@ -6017,10 +6020,10 @@ void BinaryenFunctionSetBody(BinaryenFunctionRef func,
((Function*)func)->body = (Expression*)body;
}
BinaryenHeapType BinaryenFunctionGetType(BinaryenFunctionRef func) {
return ((Function*)func)->type.getID();
return ((Function*)func)->type.getHeapType().getID();
}
void BinaryenFunctionSetType(BinaryenFunctionRef func, BinaryenHeapType type) {
((Function*)func)->type = HeapType(type);
((Function*)func)->type = Type(HeapType(type), NonNullable, Exact);
}
void BinaryenFunctionOptimize(BinaryenFunctionRef func,
BinaryenModuleRef module) {
Expand Down
20 changes: 12 additions & 8 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,10 @@ void ModuleSplitter::setupJSPI() {
primary.removeExport(LOAD_SECONDARY_MODULE);
} else {
// Add an imported function to load the secondary module.
auto import = Builder::makeFunction(ModuleSplitting::LOAD_SECONDARY_MODULE,
Signature(Type::none, Type::none),
{});
auto import = Builder::makeFunction(
ModuleSplitting::LOAD_SECONDARY_MODULE,
Type(Signature(Type::none, Type::none), NonNullable, Exact),
{});
import->module = ENV;
import->base = ModuleSplitting::LOAD_SECONDARY_MODULE;
primary.addFunction(std::move(import));
Expand Down Expand Up @@ -689,14 +690,15 @@ void ModuleSplitter::indirectCallsToSecondaryFunctions() {
Builder builder(*getModule());
Index secIndex = parent.funcToSecondaryIndex.at(curr->target);
auto* func = parent.secondaries.at(secIndex)->getFunction(curr->target);
auto tableSlot = parent.tableManager.getSlot(curr->target, func->type);
auto tableSlot =
parent.tableManager.getSlot(curr->target, func->type.getHeapType());

replaceCurrent(parent.maybeLoadSecondary(
builder,
builder.makeCallIndirect(tableSlot.tableName,
tableSlot.makeExpr(parent.primary),
curr->operands,
func->type,
func->type.getHeapType(),
curr->isReturn)));
}
};
Expand Down Expand Up @@ -786,7 +788,8 @@ void ModuleSplitter::setupTablePatching() {
primary, std::string("placeholder_") + placeholder->base.toString());
placeholder->hasExplicitName = true;
placeholder->type = secondaryFunc->type;
elem = Builder(primary).makeRefFunc(placeholder->name, placeholder->type);
elem = Builder(primary).makeRefFunc(placeholder->name,
placeholder->type.getHeapType());
primary.addFunction(std::move(placeholder));
});

Expand Down Expand Up @@ -827,7 +830,8 @@ void ModuleSplitter::setupTablePatching() {
// primarySeg->data[i] is a placeholder, so use the secondary
// function.
auto* func = replacement->second;
auto* ref = Builder(secondary).makeRefFunc(func->name, func->type);
auto* ref = Builder(secondary).makeRefFunc(func->name,
func->type.getHeapType());
secondaryElems.push_back(ref);
++replacement;
} else if (auto* get = primarySeg->data[i]->dynCast<RefFunc>()) {
Expand Down Expand Up @@ -869,7 +873,7 @@ void ModuleSplitter::setupTablePatching() {
}
auto* func = curr->second;
currData.push_back(
Builder(secondary).makeRefFunc(func->name, func->type));
Builder(secondary).makeRefFunc(func->name, func->type.getHeapType()));
}
if (currData.size()) {
finishSegment();
Expand Down
4 changes: 2 additions & 2 deletions src/ir/module-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ std::vector<HeapType> getPublicHeapTypes(Module& wasm) {
// We can ignore call.without.effects, which is implemented as an import but
// functionally is a call within the module.
if (!Intrinsics(wasm).isCallWithoutEffects(func)) {
notePublic(func->type);
notePublic(func->type.getHeapType());
}
});
for (auto& ex : wasm.exports) {
switch (ex->kind) {
case ExternalKind::Function: {
auto* func = wasm.getFunction(*ex->getInternalName());
notePublic(func->type);
notePublic(func->type.getHeapType());
continue;
}
case ExternalKind::Table: {
Expand Down
18 changes: 10 additions & 8 deletions src/ir/possible-contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,13 @@ struct InfoCollector
// actually have a RefFunc.
auto* func = getModule()->getFunction(curr->func);
for (Index i = 0; i < func->getParams().size(); i++) {
info.links.push_back(
{SignatureParamLocation{func->type, i}, ParamLocation{func, i}});
info.links.push_back({SignatureParamLocation{func->type.getHeapType(), i},
ParamLocation{func, i}});
}
for (Index i = 0; i < func->getResults().size(); i++) {
info.links.push_back(
{ResultLocation{func, i}, SignatureResultLocation{func->type, i}});
{ResultLocation{func, i},
SignatureResultLocation{func->type.getHeapType(), i}});
}

if (!options.closedWorld) {
Expand Down Expand Up @@ -1759,9 +1760,9 @@ void TNHOracle::infer() {
continue;
}
while (1) {
typeFunctions[type].push_back(func.get());
if (auto super = type.getDeclaredSuperType()) {
type = *super;
typeFunctions[type.getHeapType()].push_back(func.get());
if (auto super = type.getHeapType().getDeclaredSuperType()) {
type = type.with(*super);
} else {
break;
}
Expand Down Expand Up @@ -1859,8 +1860,9 @@ void TNHOracle::infer() {
// as other opts will make this call direct later, after which a
// lot of other optimizations become possible anyhow.
auto target = possibleTargets[0]->name;
info.inferences[call->target] = PossibleContents::literal(
Literal::makeFunc(target, wasm.getFunction(target)->type));
info.inferences[call->target] =
PossibleContents::literal(Literal::makeFunc(
target, wasm.getFunction(target)->type.getHeapType()));
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ir/table-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ 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.");
segment->data.push_back(Builder(wasm).makeRefFunc(name, func->type));
segment->data.push_back(
Builder(wasm).makeRefFunc(name, func->type.getHeapType()));
table.initial++;
return tableIndex;
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>,
if (!type.type.isSignature()) {
return in.err(pos, "expected signature type");
}
f->type = type.type;
f->type = f->type.with(type.type);
// If we are provided with too many names (more than the function has), we
// will error on that later when we check the signature matches the type.
// For now, avoid asserting in setLocalName.
Expand Down Expand Up @@ -1601,7 +1601,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx>, AnnotationParserCtx {
elems.push_back(expr);
}
void appendFuncElem(std::vector<Expression*>& elems, Name func) {
auto type = wasm.getFunction(func)->type;
auto type = wasm.getFunction(func)->type.getHeapType();
elems.push_back(builder.makeRefFunc(func, type));
}

Expand Down
2 changes: 1 addition & 1 deletion src/passes/Directize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct FunctionDirectizer : public WalkerPass<PostWalker<FunctionDirectizer>> {
return CallUtils::Trap{};
}
auto* func = getModule()->getFunction(name);
if (!HeapType::isSubType(func->type, original->heapType)) {
if (!HeapType::isSubType(func->type.getHeapType(), original->heapType)) {
return CallUtils::Trap{};
}
return CallUtils::Known{name};
Expand Down
12 changes: 6 additions & 6 deletions 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);
ref->finalize(thunk->type.getHeapType());
}
}

Expand Down Expand Up @@ -209,11 +209,11 @@ struct FuncCastEmulation : public Pass {
for (Index i = 0; i < numParams; i++) {
thunkParams.push_back(Type::i64);
}
auto thunkFunc =
builder.makeFunction(thunk,
Signature(Type(thunkParams), Type::i64),
{}, // no vars
toABI(call, module));
auto thunkFunc = builder.makeFunction(
thunk,
Type(Signature(Type(thunkParams), Type::i64), NonNullable, Exact),
{}, // no vars
toABI(call, module));
thunkFunc->hasExplicitName = true;
return module->addFunction(std::move(thunkFunc));
}
Expand Down
10 changes: 7 additions & 3 deletions src/passes/GenerateDynCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct GenerateDynCalls : public WalkerPass<PostWalker<GenerateDynCalls>> {
std::vector<Name> tableSegmentData;
ElementUtils::iterElementSegmentFunctionNames(
it->get(), [&](Name name, Index) {
generateDynCallThunk(wasm->getFunction(name)->type);
generateDynCallThunk(wasm->getFunction(name)->type.getHeapType());
});
}
}
Expand All @@ -70,7 +70,7 @@ struct GenerateDynCalls : public WalkerPass<PostWalker<GenerateDynCalls>> {
// Generate dynCalls for invokes
if (func->imported() && func->module == ENV &&
func->base.startsWith("invoke_")) {
Signature sig = func->type.getSignature();
Signature sig = func->type.getHeapType().getSignature();
// The first parameter is a pointer to the original function that's called
// by the invoke, so skip it
std::vector<Type> newParams(sig.params.begin() + 1, sig.params.end());
Expand Down Expand Up @@ -155,7 +155,11 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) {
params.push_back(param);
}
auto f = builder.makeFunction(
name, std::move(namedParams), Signature(Type(params), sig.results), {});
name,
std::move(namedParams),
Type(Signature(Type(params), sig.results), NonNullable, Exact),
{},
nullptr);
f->hasExplicitName = true;
Expression* fptr = builder.makeLocalGet(0, table->addressType);
std::vector<Expression*> args;
Expand Down
26 changes: 14 additions & 12 deletions src/passes/JSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ struct JSPI : public Pass {
if (wasmSplit) {
// Make an import for the load secondary module function so a JSPI wrapper
// version will be created.
auto import =
Builder::makeFunction(ModuleSplitting::LOAD_SECONDARY_MODULE,
Signature(Type::none, Type::none),
{});
auto import = Builder::makeFunction(
ModuleSplitting::LOAD_SECONDARY_MODULE,
Type(Signature(Type::none, Type::none), NonNullable, Exact),
{});
import->module = ENV;
import->base = ModuleSplitting::LOAD_SECONDARY_MODULE;
module->addFunction(std::move(import));
Expand Down Expand Up @@ -152,7 +152,8 @@ struct JSPI : public Pass {
continue;
}
auto* replacementRef = builder.makeRefFunc(
iter->second, module->getFunction(iter->second)->type);
iter->second,
module->getFunction(iter->second)->type.getHeapType());
segment->data[i] = replacementRef;
}
}
Expand Down Expand Up @@ -213,12 +214,12 @@ struct JSPI : public Pass {
block->list.push_back(builder.makeConst(0));
}
block->finalize();
auto wrapperFunc =
Builder::makeFunction(wrapperName,
std::move(namedWrapperParams),
Signature(Type(wrapperParams), resultsType),
{},
block);
auto wrapperFunc = Builder::makeFunction(
wrapperName,
std::move(namedWrapperParams),
Type(Signature(Type(wrapperParams), resultsType), NonNullable, Exact),
{},
block);
return module->addFunction(std::move(wrapperFunc))->name;
}

Expand Down Expand Up @@ -276,7 +277,8 @@ struct JSPI : public Pass {
block->finalize();
call->type = im->getResults();
stub->body = block;
wrapperIm->type = Signature(Type(params), call->type);
wrapperIm->type =
Type(Signature(Type(params), call->type), NonNullable, Exact);

if (wasmSplit && im->name == ModuleSplitting::LOAD_SECONDARY_MODULE) {
// In non-debug builds the name of the JSPI wrapper function for loading
Expand Down
13 changes: 8 additions & 5 deletions 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);
curr->finalize(iter->second->type.getHeapType());
}
};

Expand Down Expand Up @@ -248,7 +248,8 @@ struct LegalizeJSInterface : public Pass {
}
Type resultsType =
func->getResults() == Type::i64 ? Type::i32 : func->getResults();
legal->type = Signature(Type(legalParams), resultsType);
legal->type =
Type(Signature(Type(legalParams), resultsType), NonNullable, Exact);
if (func->getResults() == Type::i64) {
auto index = Builder::addVar(legal, Name(), Type::i64);
auto* block = builder.makeBlock();
Expand Down Expand Up @@ -307,7 +308,8 @@ struct LegalizeJSInterface : public Pass {
call->type = im->getResults();
stub->body = call;
}
legalIm->type = Signature(Type(params), call->type);
legalIm->type =
Type(Signature(Type(params), call->type), NonNullable, Exact);

auto* stubPtr = stub.get();
if (!module->getFunctionOrNull(stub->name)) {
Expand All @@ -331,7 +333,8 @@ struct LegalizeJSInterface : public Pass {
return f;
}
// Failing that create a new function import.
auto import = Builder::makeFunction(name, Signature(params, results), {});
auto import = Builder::makeFunction(
name, Type(Signature(params, results), NonNullable, Exact), {});
import->module = ENV;
import->base = name;
auto* ret = import.get();
Expand Down Expand Up @@ -374,7 +377,7 @@ struct LegalizeAndPruneJSInterface : public LegalizeJSInterface {

// The params are allowed to be multivalue, but not the results. Otherwise
// look for SIMD etc.
auto sig = func->type.getSignature();
auto sig = func->getSig();
auto illegal = isIllegal(sig.results);
illegal =
illegal || std::any_of(sig.params.begin(),
Expand Down
8 changes: 4 additions & 4 deletions src/passes/MergeSimilarFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct ParamInfo {
return (*literals)[0].type;
} else if (auto callees = std::get_if<std::vector<Name>>(&values)) {
auto* callee = module->getFunction((*callees)[0]);
return Type(callee->type, NonNullable);
return Type(callee->type.getHeapType(), NonNullable);
} else {
WASM_UNREACHABLE("unexpected const value type");
}
Expand All @@ -132,7 +132,7 @@ struct ParamInfo {
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;
auto heapType = module->getFunction(fnName)->type.getHeapType();
return builder.makeRefFunc(fnName, heapType);
} else {
WASM_UNREACHABLE("unexpected const value type");
Expand Down Expand Up @@ -613,8 +613,8 @@ Function* EquivalentClass::createShared(Module* module,
Expression* body =
ExpressionManipulator::flexibleCopy(primaryFunction->body, *module, copier);
auto vars = primaryFunction->vars;
std::unique_ptr<Function> f =
builder.makeFunction(fnName, sig, std::move(vars), body);
std::unique_ptr<Function> f = builder.makeFunction(
fnName, Type(sig, NonNullable, Exact), std::move(vars), body);
return module->addFunction(std::move(f));
}

Expand Down
Loading
Loading