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/passes/Print.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 4fa38442c..616ce9759 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2735,12 +2735,9 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } } void visitElementSegment(ElementSegment* curr) { - bool allElementsRefFunc = - std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) { - return entry->is(); - }); + bool usesExpressions = TableUtils::usesExpressions(curr, currModule); auto printElemType = [&]() { - if (allElementsRefFunc) { + if (!usesExpressions) { o << "func"; } else { printType(o, curr->type, currModule); @@ -2758,7 +2755,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } if (curr->table.is()) { - if (!allElementsRefFunc || currModule->tables.size() > 1) { + if (usesExpressions || currModule->tables.size() > 1) { // tableuse o << " (table "; printName(curr->table, o); @@ -2768,7 +2765,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { o << ' '; visit(curr->offset); - if (!allElementsRefFunc || currModule->tables.size() > 1) { + if (usesExpressions || currModule->tables.size() > 1) { o << ' '; printElemType(); } @@ -2777,7 +2774,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor { printElemType(); } - if (allElementsRefFunc) { + if (!usesExpressions) { for (auto* entry : curr->data) { auto* refFunc = entry->cast(); o << ' '; -- cgit v1.2.3