From 85f6385a7bac8b6c35b1846a38205ee84749bf31 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 29 May 2026 01:48:22 +0000 Subject: [PATCH 1/2] [wasm-split] Move computeTransitiveGlobals into getUsedNames (NFC) This doesn't have to be a separate function outside `getUsedNames`. --- src/ir/module-splitting.cpp | 49 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 95abc3306da..c34460d0fc0 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -773,6 +773,27 @@ void ModuleSplitter::shareImportableItems() { break; } } + + // 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 marked + // as used. + UniqueNonrepeatingDeferredQueue worklist; + for (auto global : used.globals) { + worklist.push(global); + } + while (!worklist.empty()) { + Name name = worklist.pop(); + // At this point all globals are still in the primary module, so this + // exists + auto* global = primary.getGlobal(name); + if (!global->imported() && global->init) { + for (auto* get : FindAll(global->init).list) { + worklist.push(get->name); + used.globals.insert(get->name); + } + } + } return used; }; @@ -804,34 +825,6 @@ void ModuleSplitter::shareImportableItems() { } } - // 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 marked - // as used. - auto computeTransitiveGlobals = [&](UsedNames& used) { - UniqueNonrepeatingDeferredQueue worklist; - for (auto global : used.globals) { - worklist.push(global); - } - while (!worklist.empty()) { - Name name = worklist.pop(); - // At this point all globals are still in the primary module, so this - // exists - auto* global = primary.getGlobal(name); - if (!global->imported() && global->init) { - for (auto* get : FindAll(global->init).list) { - worklist.push(get->name); - used.globals.insert(get->name); - } - } - } - }; - - computeTransitiveGlobals(primaryUsed); - for (auto& used : secondaryUsed) { - computeTransitiveGlobals(used); - } - // Given a name and module item kind, returns the list of secondary modules // using that name auto getUsingSecondaries = [&](const Name& name, auto UsedNames::* field) { From b358dfd030e4882e05c2884853250c3e354426f0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 29 May 2026 04:55:54 +0000 Subject: [PATCH 2/2] clang-format --- src/ir/module-splitting.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index c34460d0fc0..619b00d92b6 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -776,8 +776,8 @@ void ModuleSplitter::shareImportableItems() { // 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 marked - // as used. + // that if a global is used in a module, all its dependencies are also + // marked as used. UniqueNonrepeatingDeferredQueue worklist; for (auto global : used.globals) { worklist.push(global);