diff options
author | Alon Zakai <azakai@google.com> | 2021-09-02 09:17:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-02 09:17:37 -0700 |
commit | e84980dffb62d672c991960a701a3c7de8f8aa74 (patch) | |
tree | 8e130330f04c3cf10702bc24241061f33591b2f9 /src/ir/table-utils.cpp | |
parent | 4bf2d3bc3da17a28b65222d6e84f6126dcb9c553 (diff) | |
download | binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.gz binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.bz2 binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.zip |
Support specialized function types in element segments (#4109)
Before this, the element segments would be printed as having type
funcref, and then if their table had a specialized type, the element
type would not be a subtype of the table and validation would fail.
Diffstat (limited to 'src/ir/table-utils.cpp')
-rw-r--r-- | src/ir/table-utils.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir/table-utils.cpp b/src/ir/table-utils.cpp index 80ef885f9..79b90d249 100644 --- a/src/ir/table-utils.cpp +++ b/src/ir/table-utils.cpp @@ -64,6 +64,25 @@ std::set<Name> getFunctionsNeedingElemDeclare(Module& wasm) { return ret; } +bool usesExpressions(ElementSegment* curr, Module* module) { + // Binaryen IR always has ref.funcs for functions in tables for uniformity, + // so that by itself does not indicate if expressions should be used when + // emitting the table or not. But definitely anything that is not a ref.func + // implies we are post-MVP and must use expressions. + bool allElementsRefFunc = + std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) { + return entry->is<RefFunc>(); + }); + + // If the table has a specialized (non-MVP) type, then the segment must + // declare a type that is a subtype of that, so it must use the post-MVP form + // of using expressions. + bool hasTableOfSpecializedType = + curr->table.is() && module->getTable(curr->table)->type != Type::funcref; + + return !allElementsRefFunc || hasTableOfSpecializedType; +} + } // namespace TableUtils } // namespace wasm |