summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-09-21 12:28:23 -0700
committerGitHub <noreply@github.com>2023-09-21 12:28:23 -0700
commitec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c (patch)
treed1c86dc6b1759f231f7d9f51c9a4493f74542859 /src/wasm
parenta35af4b1e9461b12fd7993b4fd249bd39d73945d (diff)
downloadbinaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.tar.gz
binaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.tar.bz2
binaryen-ec0f05cb98d6a4e30375a7a6a78966d25fdb5d9c.zip
Support i8/i16 mutable arrays as public types for string interop (#5814)
Probably any array of non-reference data can be allowed to be public and sent out of the module, as it is just data. For now, however, just special case the i8 and i16 array types which are useful already for string interop.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-type.cpp23
-rw-r--r--src/wasm/wasm-validator.cpp6
2 files changed, 28 insertions, 1 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index ba38231b6..4ce72582c 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -2580,6 +2580,29 @@ void TypeBuilder::dump() {
}
}
+std::unordered_set<HeapType> getIgnorablePublicTypes() {
+ auto array8 = Array(Field(Field::i8, Mutable));
+ auto array16 = Array(Field(Field::i16, Mutable));
+ TypeBuilder builder(4);
+ // We handle final and non-final here, but should remove one of them
+ // eventually TODO
+ builder[0] = array8;
+ builder[0].setOpen(false);
+ builder[1] = array16;
+ builder[1].setOpen(false);
+ builder[2] = array8;
+ builder[2].setOpen(true);
+ builder[3] = array16;
+ builder[3].setOpen(true);
+ auto result = builder.build();
+ assert(result);
+ std::unordered_set<HeapType> ret;
+ for (auto type : *result) {
+ ret.insert(type);
+ }
+ return ret;
+}
+
} // namespace wasm
namespace std {
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 2d00c4b67..3baaacb16 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -3726,8 +3726,12 @@ static void validateClosedWorldInterface(Module& module, ValidationInfo& info) {
}
}
+ // Ignorable public types are public, but we can ignore them for purposes of
+ // erroring here: It is always ok that they are public.
+ auto ignorable = getIgnorablePublicTypes();
+
for (auto type : ModuleUtils::getPublicHeapTypes(module)) {
- if (!publicFuncTypes.count(type)) {
+ if (!publicFuncTypes.count(type) && !ignorable.count(type)) {
auto name = type.toString();
if (auto it = module.typeNames.find(type); it != module.typeNames.end()) {
name = it->second.name.toString();