From 97f37aa13ce3ed318dc18980f03c41e7536624a5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 27 May 2021 12:53:05 -0700 Subject: [Wasm GC] Add experimental array.copy (#3911) Spec for it is here: https://docs.google.com/document/d/1DklC3qVuOdLHSXB5UXghM_syCh-4cMinQ50ICiXnK3Q/edit# Also reorder some things in wasm.h that were not in the canonical order (that has no effect, but it is confusing to read). --- src/wasm/wasm-validator.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index d82542668..10b60e0a7 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -385,6 +385,7 @@ public: void visitArrayGet(ArrayGet* curr); void visitArraySet(ArraySet* curr); void visitArrayLen(ArrayLen* curr); + void visitArrayCopy(ArrayCopy* curr); void visitFunction(Function* curr); // helpers @@ -2457,6 +2458,31 @@ void FunctionValidator::visitArrayLen(ArrayLen* curr) { curr->type, Type(Type::i32), curr, "array.len result must be an i32"); } +void FunctionValidator::visitArrayCopy(ArrayCopy* curr) { + shouldBeTrue(getModule()->features.hasGC(), + curr, + "array.copy requires gc to be enabled"); + shouldBeEqualOrFirstIsUnreachable(curr->srcIndex->type, + Type(Type::i32), + curr, + "array.copy src index must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->destIndex->type, + Type(Type::i32), + curr, + "array.copy dest index must be an i32"); + if (curr->type == Type::unreachable) { + return; + } + const auto& srcElement = curr->srcRef->type.getHeapType().getArray().element; + const auto& destElement = + curr->destRef->type.getHeapType().getArray().element; + shouldBeSubType(srcElement.type, + destElement.type, + curr, + "array.copy must have the proper types"); + shouldBeTrue(destElement.mutable_, curr, "array.copy type must be mutable"); +} + void FunctionValidator::visitFunction(Function* curr) { if (curr->sig.results.isTuple()) { shouldBeTrue(getModule()->features.hasMultivalue(), -- cgit v1.2.3