summaryrefslogtreecommitdiff
path: root/src/passes/GlobalRefining.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-01-03 10:20:08 -0800
committerGitHub <noreply@github.com>2023-01-03 10:20:08 -0800
commit4a8a4b87a1dfde2809f08432d34b9a7618cb4a4f (patch)
tree46b514d8d7d81f1703db179219cdd0b8c38d6042 /src/passes/GlobalRefining.cpp
parentcec66beba45668dbad74abd2396bb80d33595ff0 (diff)
downloadbinaryen-4a8a4b87a1dfde2809f08432d34b9a7618cb4a4f.tar.gz
binaryen-4a8a4b87a1dfde2809f08432d34b9a7618cb4a4f.tar.bz2
binaryen-4a8a4b87a1dfde2809f08432d34b9a7618cb4a4f.zip
[Wasm GC] Do not refine types of exported globals in closed world (#5380)
Doing so can cause us to switch from a private type to a public type and error. Also refactor export-utils to make this easy.
Diffstat (limited to 'src/passes/GlobalRefining.cpp')
-rw-r--r--src/passes/GlobalRefining.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/passes/GlobalRefining.cpp b/src/passes/GlobalRefining.cpp
index 67a186f92..129f34283 100644
--- a/src/passes/GlobalRefining.cpp
+++ b/src/passes/GlobalRefining.cpp
@@ -18,6 +18,7 @@
// Apply more specific subtypes to global variables where possible.
//
+#include "ir/export-utils.h"
#include "ir/find_all.h"
#include "ir/lubs.h"
#include "ir/module-utils.h"
@@ -63,10 +64,20 @@ struct GlobalRefining : public Pass {
}
}
+ // In closed world we cannot change the types of exports, as we might change
+ // from a public type to a private that would cause a validation error.
+ // TODO We could refine to a type that is still public, however.
+ std::unordered_set<Name> unoptimizable;
+ if (getPassOptions().closedWorld) {
+ for (auto* global : ExportUtils::getExportedGlobals(*module)) {
+ unoptimizable.insert(global->name);
+ }
+ }
+
bool optimized = false;
for (auto& global : module->globals) {
- if (global->imported()) {
+ if (global->imported() || unoptimizable.count(global->name)) {
continue;
}