summaryrefslogtreecommitdiff
path: root/src/parser/parsers.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-06-12 12:30:28 -0700
committerGitHub <noreply@github.com>2024-06-12 12:30:28 -0700
commit0e1187664ebf93bd268ba7d77813441a4874d998 (patch)
tree5a71076f179d4edfd3cdb811676ccd5c420e582b /src/parser/parsers.h
parentac21c8cc9204e09fab070d2fd915e7ab583a5dac (diff)
downloadbinaryen-0e1187664ebf93bd268ba7d77813441a4874d998.tar.gz
binaryen-0e1187664ebf93bd268ba7d77813441a4874d998.tar.bz2
binaryen-0e1187664ebf93bd268ba7d77813441a4874d998.zip
[threads] Parse, build, and print shared composite types (#6654)
Parse the text format for shared composite types as described in the shared-everything thread proposal. Update the parser to use 'comptype' instead of 'strtype' to match the final GC spec and add the new syntactic class 'sharecomptype'. Update the type canonicalization logic to take sharedness into account to avoid merging shared and unshared types. Make the same change in the TypeMerging pass. Ensure that shared and unshared types cannot be in a subtype relationship with each other. Follow-up PRs will add shared abstract heap types, binary parsing and emitting for shared types, and fuzzer support for shared types.
Diffstat (limited to 'src/parser/parsers.h')
-rw-r--r--src/parser/parsers.h36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index c4eaf5fc6..a3fe5e5eb 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -331,7 +331,8 @@ template<typename Ctx>
Result<typename Ctx::TypeUseT> typeuse(Ctx&, bool allowNames = true);
MaybeResult<ImportNames> inlineImport(Lexer&);
Result<std::vector<Name>> inlineExports(Lexer&);
-template<typename Ctx> Result<> strtype(Ctx&);
+template<typename Ctx> Result<> comptype(Ctx&);
+template<typename Ctx> Result<> sharecomptype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::ModuleNameT> subtype(Ctx&);
template<typename Ctx> MaybeResult<> deftype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::LocalsT> locals(Ctx&);
@@ -2709,11 +2710,11 @@ inline Result<std::vector<Name>> inlineExports(Lexer& in) {
return exports;
}
-// strtype ::= ft:functype => ft
-// | ct:conttype => ct
-// | st:structtype => st
-// | at:arraytype => at
-template<typename Ctx> Result<> strtype(Ctx& ctx) {
+// comptype ::= ft:functype => ft
+// | ct:conttype => ct
+// | st:structtype => st
+// | at:arraytype => at
+template<typename Ctx> Result<> comptype(Ctx& ctx) {
if (auto type = functype(ctx)) {
CHECK_ERR(type);
ctx.addFuncType(*type);
@@ -2737,8 +2738,23 @@ template<typename Ctx> Result<> strtype(Ctx& ctx) {
return ctx.in.err("expected type description");
}
-// subtype ::= '(' 'type' id? '(' 'sub' typeidx? strtype ')' ')'
-// | '(' 'type' id? strtype ')'
+// sharecomptype ::= '(' 'shared' t:comptype ')' => shared t
+// | t:comptype => unshared t
+template<typename Ctx> Result<> sharecomptype(Ctx& ctx) {
+ if (ctx.in.takeSExprStart("shared"sv)) {
+ ctx.setShared();
+ CHECK_ERR(comptype(ctx));
+ if (!ctx.in.takeRParen()) {
+ return ctx.in.err("expected end of shared comptype");
+ }
+ } else {
+ CHECK_ERR(comptype(ctx));
+ }
+ return Ok{};
+}
+
+// subtype ::= '(' 'type' id? '(' 'sub' typeidx? sharecomptype ')' ')'
+// | '(' 'type' id? sharecomptype ')'
template<typename Ctx> MaybeResult<> subtype(Ctx& ctx) {
auto pos = ctx.in.getPos();
@@ -2760,13 +2776,13 @@ template<typename Ctx> MaybeResult<> subtype(Ctx& ctx) {
CHECK_ERR(ctx.addSubtype(*super));
}
- CHECK_ERR(strtype(ctx));
+ CHECK_ERR(sharecomptype(ctx));
if (!ctx.in.takeRParen()) {
return ctx.in.err("expected end of subtype definition");
}
} else {
- CHECK_ERR(strtype(ctx));
+ CHECK_ERR(sharecomptype(ctx));
}
if (!ctx.in.takeRParen()) {