Skip to content

Commit d4b7bdb

Browse files
authored
[wasm-split] Add an assert (NFC) (#7782)
While reading I thought that ```cpp assert(table == tableManager.activeTable->name); ``` in that `forEachElement` loop would be helpful, but adding it made clang-format intendentation change.. So the change was only the one assertion line. "Hide whitespace" will make it clear. This also removes a unused header.
1 parent 5c9dfac commit d4b7bdb

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/ir/module-splitting.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969

7070
#include "ir/module-splitting.h"
7171
#include "asmjs/shared-constants.h"
72-
#include "ir/element-utils.h"
7372
#include "ir/export-utils.h"
7473
#include "ir/manipulation.h"
7574
#include "ir/module-utils.h"
@@ -709,33 +708,36 @@ void ModuleSplitter::setupTablePatching() {
709708
// Replace table references to secondary functions with an imported
710709
// placeholder that encodes the table index in its name:
711710
// `importNamespace`.`index`.
712-
forEachElement(primary, [&](Name, Name, Index index, Expression*& elem) {
713-
auto* ref = elem->dynCast<RefFunc>();
714-
if (!ref) {
715-
return;
716-
}
717-
if (!secondaryFuncs.count(ref->func)) {
718-
return;
719-
}
720-
placeholderMap[index] = ref->func;
721-
auto* secondaryFunc = secondary.getFunction(ref->func);
722-
replacedElems[index] = secondaryFunc;
723-
if (!config.usePlaceholders) {
724-
// TODO: This can create active element segments with lots of nulls. We
725-
// should optimize them like we do data segments with zeros.
726-
elem = Builder(primary).makeRefNull(HeapType::nofunc);
727-
return;
728-
}
729-
auto placeholder = std::make_unique<Function>();
730-
placeholder->module = config.placeholderNamespace;
731-
placeholder->base = std::to_string(index);
732-
placeholder->name = Names::getValidFunctionName(
733-
primary, std::string("placeholder_") + placeholder->base.toString());
734-
placeholder->hasExplicitName = true;
735-
placeholder->type = secondaryFunc->type;
736-
elem = Builder(primary).makeRefFunc(placeholder->name, placeholder->type);
737-
primary.addFunction(std::move(placeholder));
738-
});
711+
forEachElement(
712+
primary, [&](Name table, Name, Index index, Expression*& elem) {
713+
auto* ref = elem->dynCast<RefFunc>();
714+
if (!ref) {
715+
return;
716+
}
717+
if (!secondaryFuncs.count(ref->func)) {
718+
return;
719+
}
720+
assert(table == tableManager.activeTable->name);
721+
722+
placeholderMap[index] = ref->func;
723+
auto* secondaryFunc = secondary.getFunction(ref->func);
724+
replacedElems[index] = secondaryFunc;
725+
if (!config.usePlaceholders) {
726+
// TODO: This can create active element segments with lots of nulls. We
727+
// should optimize them like we do data segments with zeros.
728+
elem = Builder(primary).makeRefNull(HeapType::nofunc);
729+
return;
730+
}
731+
auto placeholder = std::make_unique<Function>();
732+
placeholder->module = config.placeholderNamespace;
733+
placeholder->base = std::to_string(index);
734+
placeholder->name = Names::getValidFunctionName(
735+
primary, std::string("placeholder_") + placeholder->base.toString());
736+
placeholder->hasExplicitName = true;
737+
placeholder->type = secondaryFunc->type;
738+
elem = Builder(primary).makeRefFunc(placeholder->name, placeholder->type);
739+
primary.addFunction(std::move(placeholder));
740+
});
739741

740742
if (replacedElems.size() == 0) {
741743
// No placeholders to patch out of the table

0 commit comments

Comments
 (0)