From ed92a8d5e493c839687c2f2d56cdc5123e6e3a47 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 11 May 2021 12:29:46 -0700 Subject: ExtractFunction: Do not always remove the memory and table (#3877) Instead, run RemoveUnusedModuleElements, which does that sort of thing. That is, this pass just "extracts" the function by turning all others into imports, and then they should almost all be removable via RemoveUnusedModuleElements, depending on whether they are used in the table or not, whether the extracted function calls them, etc. Without this, we would error if a function was in the table, and so this fixes #3876 --- src/passes/RemoveUnusedModuleElements.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/passes/RemoveUnusedModuleElements.cpp') diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index b5cf2635a..59d9a2a9b 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -229,6 +229,10 @@ struct RemoveUnusedModuleElements : public Pass { analyzer.reachable.count( ModuleElement(ModuleElementKind::Table, curr->name)) == 0; }); + // TODO: After removing elements, we may be able to remove more things, and + // should continue to work. (For example, after removing a reference + // to a function from an element segment, we may be able to remove + // that function, etc.) // Handle the memory if (!exportsMemory && !analyzer.usesMemory) { -- cgit v1.2.3