From 2d6a96c6e69b1b283942449ff23f059712e815e3 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sun, 7 Jun 2026 00:51:04 +0000 Subject: [PATCH] [wasm-split] Move some code (NFC) This just moves some code to make future diff tidier. This makes `walkSegments` a lambda function within `shareImportableItems` because it is only used within that function, and this adds the dispatch table and segments to the primary's used list within `getUsedNames` rather than outside. --- src/ir/module-splitting.cpp | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 088348f1c03..40d3a276b3d 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -638,25 +638,6 @@ void ModuleSplitter::thunkExportedSecondaryFunctions() { } } -// Helper to walk expressions in segments but NOT in globals. -template -static void walkSegments(Walker& walker, Module* module) { - walker.setModule(module); - for (auto& curr : module->elementSegments) { - if (curr->offset) { - walker.walk(curr->offset); - } - for (auto* item : curr->data) { - walker.walk(item); - } - } - for (auto& curr : module->dataSegments) { - if (curr->offset) { - walker.walk(curr->offset); - } - } -} - void ModuleSplitter::shareImportableItems() { struct UsedNames { @@ -666,6 +647,23 @@ void ModuleSplitter::shareImportableItems() { std::unordered_set tags; }; + auto walkSegments = [](auto& walker, Module* module) { + walker.setModule(module); + for (auto& curr : module->elementSegments) { + if (curr->offset) { + walker.walk(curr->offset); + } + for (auto* item : curr->data) { + walker.walk(item); + } + } + for (auto& curr : module->dataSegments) { + if (curr->offset) { + walker.walk(curr->offset); + } + } + }; + struct NameCollector : public PostWalker> { @@ -776,6 +774,17 @@ void ModuleSplitter::shareImportableItems() { } } + // We need to assume the dispatch table and its base global are used in the + // primary module, because we will create segments there later. + if (&module == &primary) { + if (tableManager.dispatchTable) { + used.tables.insert(tableManager.dispatchTable->name); + } + if (tableManager.dispatchBase.global) { + used.globals.insert(tableManager.dispatchBase.global); + } + } + // Compute the transitive closure of globals referenced in other globals' // initializers. Since globals can reference other globals, we must ensure // that if a global is used in a module, all its dependencies are also @@ -805,15 +814,6 @@ void ModuleSplitter::shareImportableItems() { secondaryUsed.push_back(getUsedNames(*secondaryPtr)); } - // We need to assume the dispatch table and its base global are used in the - // primary module, because we will create segments there later. - if (tableManager.dispatchTable) { - primaryUsed.tables.insert(tableManager.dispatchTable->name); - } - if (tableManager.dispatchBase.global) { - primaryUsed.globals.insert(tableManager.dispatchBase.global); - } - // If custom-descirptors is enabled, global initializers can trap. Trapping // globals should stay in the primary module to preserve the trapping behavior // upon instantiation.