From 63a042e3a94df7ba3a5c9dde03990a9813fdc366 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 8 Dec 2020 18:55:20 -0800 Subject: [GC] Add basic RTT support (#3432) This adds rtt.canon and rtt.sub together with RTT type support that is necessary for them. Together this lets us test roundtripping the instructions and types. Also fixes a missing traversal over globals in collectHeapTypes, which the example from the GC docs requires, as the RTTs are in globals there. This does not yet add full interpreter support and other things. It disables initial contents on GC in the fuzzer, to avoid the fuzzer breaking. Renames the binary ID for exnref, which is being removed from the spec, and which overlaps with the binary ID for rtt. --- src/wasm/wasm-validator.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index b2e208d53..c6e22899c 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2211,13 +2211,27 @@ void FunctionValidator::visitBrOnCast(BrOnCast* curr) { void FunctionValidator::visitRttCanon(RttCanon* curr) { shouldBeTrue( getModule()->features.hasGC(), curr, "rtt.canon requires gc to be enabled"); - WASM_UNREACHABLE("TODO (gc): rtt.canon"); + shouldBeTrue(curr->type.isRtt(), curr, "rtt.canon must have RTT type"); + auto rtt = curr->type.getRtt(); + shouldBeEqual(rtt.depth, Index(0), curr, "rtt.canon has a depth of 0"); } void FunctionValidator::visitRttSub(RttSub* curr) { shouldBeTrue( getModule()->features.hasGC(), curr, "rtt.sub requires gc to be enabled"); - WASM_UNREACHABLE("TODO (gc): rtt.sub"); + shouldBeTrue(curr->type.isRtt(), curr, "rtt.sub must have RTT type"); + if (curr->parent->type != Type::unreachable) { + shouldBeTrue( + curr->parent->type.isRtt(), curr, "rtt.sub parent must have RTT type"); + auto parentRtt = curr->parent->type.getRtt(); + auto rtt = curr->type.getRtt(); + if (rtt.hasDepth() && parentRtt.hasDepth()) { + shouldBeEqual(rtt.depth, + parentRtt.depth + 1, + curr, + "rtt.canon has a depth of 1 over the parent"); + } + } } void FunctionValidator::visitStructNew(StructNew* curr) { -- cgit v1.2.3