From 4e58466b40b65cda399b4749105f0ce10f48f62b Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 8 Sep 2023 20:08:33 -0500 Subject: Make final types the default (#5918) Match the spec and parse the shorthand binary and text formats as final and emit final types without supertypes using the shorthands as well. This is a potentially-breaking change, since the text and binary shorthands can no longer be used to define types that have subtypes. Also make TypeBuilder entries final by default to better match the spec and update the internal APIs to use the "open" terminology rather than "final" terminology. Future changes will update the text format to use the standard "sub open" rather than the current "sub final" keywords. The exception is the new wat parser, which supporst "sub open" as of this change, since it didn't support final types at all previously. --- src/wasm/wat-parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/wasm/wat-parser.cpp') diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp index 3961cbb7f..bdd1af0d8 100644 --- a/src/wasm/wat-parser.cpp +++ b/src/wasm/wat-parser.cpp @@ -849,6 +849,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { void addFuncType(SignatureT) {} void addStructType(StructT) {} void addArrayType(ArrayT) {} + void setOpen() {} Result<> addSubtype(Index) { return Ok{}; } void finishSubtype(Name name, Index pos) { subtypeDefs.push_back({name, pos, Index(subtypeDefs.size())}); @@ -1078,6 +1079,8 @@ struct ParseTypeDefsCtx : TypeParserCtx { void addArrayType(ArrayT& type) { builder[index] = type; } + void setOpen() { builder[index].setOpen(); } + Result<> addSubtype(Index super) { if (super >= builder.size()) { return in.err("supertype index out of bounds"); @@ -3463,6 +3466,9 @@ template MaybeResult<> subtype(Ctx& ctx) { } if (ctx.in.takeSExprStart("sub"sv)) { + if (ctx.in.takeKeyword("open"sv)) { + ctx.setOpen(); + } if (auto super = maybeTypeidx(ctx)) { CHECK_ERR(super); CHECK_ERR(ctx.addSubtype(*super)); -- cgit v1.2.3