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-s-parser.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 21104d0fe..63b6e34bd 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -50,7 +50,7 @@ int unhex(char c) { namespace wasm { static Name STRUCT("struct"), FIELD("field"), ARRAY("array"), I8("i8"), - I16("i16"); + I16("i16"), RTT("rtt"); static Address getAddress(const Element* s) { return atoll(s->c_str()); } @@ -940,6 +940,18 @@ Type SExpressionWasmBuilder::elementToType(Element& s) { } return Type(parseHeapType(*s[i]), nullable); } + if (elementStartsWith(s, RTT)) { + // It's an RTT, something like (rtt N $typename) or just (rtt $typename) + // if there is no depth. + if (s[1]->dollared()) { + auto heapType = parseHeapType(*s[1]); + return Type(Rtt(heapType)); + } else { + auto depth = atoi(s[1]->str().c_str()); + auto heapType = parseHeapType(*s[2]); + return Type(Rtt(depth, heapType)); + } + } // It's a tuple. std::vector types; for (size_t i = 0; i < s.size(); ++i) { @@ -2102,17 +2114,13 @@ Expression* SExpressionWasmBuilder::makeBrOnCast(Element& s) { } Expression* SExpressionWasmBuilder::makeRttCanon(Element& s) { - auto ret = allocator.alloc(); - WASM_UNREACHABLE("TODO (gc): rtt.canon"); - ret->finalize(); - return ret; + return Builder(wasm).makeRttCanon(parseHeapType(*s[1])); } Expression* SExpressionWasmBuilder::makeRttSub(Element& s) { - auto ret = allocator.alloc(); - WASM_UNREACHABLE("TODO (gc): rtt.sub"); - ret->finalize(); - return ret; + auto heapType = parseHeapType(*s[1]); + auto parent = parseExpression(*s[2]); + return Builder(wasm).makeRttSub(heapType, parent); } Expression* SExpressionWasmBuilder::makeStructNew(Element& s, bool default_) { -- cgit v1.2.3