From e84980dffb62d672c991960a701a3c7de8f8aa74 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 2 Sep 2021 09:17:37 -0700 Subject: 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. --- src/wasm/wasm-binary.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/wasm/wasm-binary.cpp') diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ab229f111..ee3c1a6fa 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -584,11 +584,8 @@ void WasmBinaryWriter::writeElementSegments() { Index tableIdx = 0; bool isPassive = segment->table.isNull(); - // if all items are ref.func, we can use the shorter form. - bool usesExpressions = - std::any_of(segment->data.begin(), - segment->data.end(), - [](Expression* curr) { return !curr->is(); }); + // If the segment is MVP, we can use the shorter form. + bool usesExpressions = TableUtils::usesExpressions(segment.get(), wasm); bool hasTableIndex = false; if (!isPassive) { @@ -620,7 +617,7 @@ void WasmBinaryWriter::writeElementSegments() { // elemType writeType(segment->type); } else { - // elemKind funcref + // MVP elemKind of funcref o << U32LEB(0); } } @@ -2864,12 +2861,12 @@ void WasmBinaryBuilder::readElementSegments() { if (usesExpressions) { segment->type = getType(); if (!segment->type.isFunction()) { - throwError("Invalid type for an element segment"); + throwError("Invalid type for a usesExpressions element segment"); } } else { auto elemKind = getU32LEB(); if (elemKind != 0x0) { - throwError("Only funcref elem kinds are valid."); + throwError("Invalid kind (!= funcref(0)) since !usesExpressions."); } } } -- cgit v1.2.3