Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit names for elements creating using Builder::make_ methods #6809

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4968,7 +4968,6 @@ BinaryenTableRef BinaryenAddTable(BinaryenModuleRef module,
BinaryenIndex maximum,
BinaryenType tableType) {
auto table = Builder::makeTable(name, Type(tableType), initial, maximum);
table->hasExplicitName = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it is no longer needed since Builder::makeTable now uses explicit name by default.

return ((Module*)module)->addTable(std::move(table));
}
void BinaryenRemoveTable(BinaryenModuleRef module, const char* table) {
Expand Down
7 changes: 3 additions & 4 deletions src/ir/module-splitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ void ModuleSplitter::setupTablePatching() {
auto placeholder = std::make_unique<Function>();
placeholder->module = config.placeholderNamespace;
placeholder->base = std::to_string(index);
placeholder->name = Names::getValidFunctionName(
auto name = Names::getValidFunctionName(
primary, std::string("placeholder_") + placeholder->base.toString());
placeholder->hasExplicitName = true;
placeholder->setExplicitName(name);
placeholder->type = secondaryFunc->type;
elem = placeholder->name;
primary.addFunction(std::move(placeholder));
Expand Down Expand Up @@ -804,8 +804,7 @@ void ModuleSplitter::shareImportableItems() {
Importable& secondaryItem,
const std::string& genericExportName,
ExternalKind kind) {
secondaryItem.name = primaryItem.name;
secondaryItem.hasExplicitName = primaryItem.hasExplicitName;
secondaryItem.setName(primaryItem.name, primaryItem.hasExplicitName);
secondaryItem.module = config.importNamespace;
auto exportIt = exports.find(std::make_pair(kind, primaryItem.name));
if (exportIt != exports.end()) {
Expand Down
1 change: 0 additions & 1 deletion src/passes/GenerateDynCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) {
}
auto f = builder.makeFunction(
name, std::move(namedParams), Signature(Type(params), sig.results), {});
f->hasExplicitName = true;
Expression* fptr = builder.makeLocalGet(0, table->indexType);
std::vector<Expression*> args;
Index i = 0;
Expand Down
9 changes: 3 additions & 6 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ struct LegalizeJSInterface : public Pass {

Builder builder(*module);
auto* legal = new Function();
legal->name = legalName;
legal->hasExplicitName = true;
legal->setExplicitName(legalName);

auto* call = module->allocator.alloc<Call>();
call->target = func->name;
Expand Down Expand Up @@ -272,14 +271,12 @@ struct LegalizeJSInterface : public Pass {
Name makeLegalStubForCalledImport(Function* im, Module* module) {
Builder builder(*module);
auto legalIm = std::make_unique<Function>();
legalIm->name = Name(std::string("legalimport$") + im->name.toString());
legalIm->setExplicitName(Name(std::string("legalimport$") + im->name.toString()));
legalIm->module = im->module;
legalIm->base = im->base;
legalIm->hasExplicitName = true;
auto stub = std::make_unique<Function>();
stub->name = Name(std::string("legalfunc$") + im->name.toString());
stub->setExplicitName(Name(std::string("legalfunc$") + im->name.toString()));
stub->type = im->type;
stub->hasExplicitName = true;

auto* call = module->allocator.alloc<Call>();
call->target = legalIm->name;
Expand Down
1 change: 0 additions & 1 deletion src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ void TranslateToFuzzReader::setupTables() {
} else {
auto tablePtr = builder.makeTable(
Names::getValidTableName(wasm, "fuzzing_table"), funcref, 0, 0);
tablePtr->hasExplicitName = true;
table = wasm.addTable(std::move(tablePtr));
}
funcrefTableName = table->name;
Expand Down
2 changes: 0 additions & 2 deletions src/tools/wasm-split/instrumenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void Instrumenter::addGlobals(size_t numFuncs) {
Type::i32,
Builder(*wasm).makeConst(Literal::makeZero(Type::i32)),
Builder::Mutable);
global->hasExplicitName = true;
wasm->addGlobal(std::move(global));
};
addGlobal(counterGlobal);
Expand Down Expand Up @@ -204,7 +203,6 @@ void Instrumenter::addProfileExport(size_t numFuncs) {
auto name = Names::getValidFunctionName(*wasm, config.profileExport);
auto writeProfile =
Builder::makeFunction(name, Signature({ptrType, Type::i32}, Type::i32), {});
writeProfile->hasExplicitName = true;
writeProfile->setLocalName(0, "addr");
writeProfile->setLocalName(1, "size");

Expand Down
16 changes: 8 additions & 8 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Builder {
Expression* body = nullptr) {
assert(type.isSignature());
auto func = std::make_unique<Function>();
func->name = name;
func->setExplicitName(name);
func->type = type;
func->body = body;
func->vars.swap(vars);
Expand All @@ -63,7 +63,7 @@ class Builder {
Expression* body = nullptr) {
assert(type.isSignature());
auto func = std::make_unique<Function>();
func->name = name;
func->setExplicitName(name);
func->type = type;
func->body = body;
for (size_t i = 0; i < params.size(); ++i) {
Expand All @@ -89,7 +89,7 @@ class Builder {
Address max = Table::kMaxSize,
Type indexType = Type::i32) {
auto table = std::make_unique<Table>();
table->name = name;
table->setExplicitName(name);
table->type = type;
table->indexType = indexType;
table->initial = initial;
Expand All @@ -103,7 +103,7 @@ class Builder {
Expression* offset = nullptr,
Type type = Type(HeapType::func, Nullable)) {
auto seg = std::make_unique<ElementSegment>();
seg->name = name;
seg->setExplicitName(name);
seg->table = table;
seg->offset = offset;
seg->type = type;
Expand All @@ -116,7 +116,7 @@ class Builder {
bool shared = false,
Type indexType = Type::i32) {
auto memory = std::make_unique<Memory>();
memory->name = name;
memory->setExplicitName(name);
memory->initial = initial;
memory->max = max;
memory->shared = shared;
Expand All @@ -132,7 +132,7 @@ class Builder {
const char* init = "",
Address size = 0) {
auto seg = std::make_unique<DataSegment>();
seg->name = name;
seg->setExplicitName(name);
seg->memory = memory;
seg->isPassive = isPassive;
seg->offset = offset;
Expand All @@ -155,7 +155,7 @@ class Builder {
static std::unique_ptr<Global>
makeGlobal(Name name, Type type, Expression* init, Mutability mutable_) {
auto glob = std::make_unique<Global>();
glob->name = name;
glob->setExplicitName(name);
glob->type = type;
glob->init = init;
glob->mutable_ = mutable_ == Mutable;
Expand All @@ -164,7 +164,7 @@ class Builder {

static std::unique_ptr<Tag> makeTag(Name name, Signature sig) {
auto tag = std::make_unique<Tag>();
tag->name = name;
tag->setExplicitName(name);
tag->sig = sig;
return tag;
}
Expand Down
Loading