Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ struct ParseImplicitTypeDefsCtx : TypeParserCtx<ParseImplicitTypeDefsCtx> {
types(types), implicitTypes(implicitTypes) {
for (auto type : types) {
if (type.isSignature() && type.getRecGroup().size() == 1 &&
!type.isShared()) {
!type.getDeclaredSuperType() && !type.isOpen() && !type.isShared()) {
sigTypes.insert({type.getSignature(), type});
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ using namespace std::string_view_literals;

// Types
template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::RefTypeT> reftype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::RefTypeT> maybeRefType(Ctx&);
template<typename Ctx> Result<typename Ctx::RefTypeT> reftype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::TypeT> tupletype(Ctx&);
template<typename Ctx> Result<typename Ctx::TypeT> valtype(Ctx&);
template<typename Ctx>
Expand Down Expand Up @@ -419,7 +420,7 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
// | 'structref' => structref
// | 'arrayref' => arrayref
// | '(' ref null? t:heaptype ')' => ref null? t
template<typename Ctx> MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx) {
template<typename Ctx> MaybeResult<typename Ctx::TypeT> maybeReftype(Ctx& ctx) {
if (ctx.in.takeKeyword("funcref"sv)) {
return ctx.makeRefType(ctx.makeFuncType(), Nullable);
}
Expand Down Expand Up @@ -482,6 +483,14 @@ template<typename Ctx> MaybeResult<typename Ctx::TypeT> reftype(Ctx& ctx) {
return ctx.makeRefType(*type, nullability);
}

template<typename Ctx> Result<typename Ctx::TypeT> reftype(Ctx& ctx) {
if (auto t = maybeReftype(ctx)) {
CHECK_ERR(t);
return *t;
}
return ctx.in.err("expected reftype");
}

// tupletype ::= '(' 'tuple' valtype* ')'
template<typename Ctx> MaybeResult<typename Ctx::TypeT> tupletype(Ctx& ctx) {
if (!ctx.in.takeSExprStart("tuple"sv)) {
Expand Down Expand Up @@ -520,7 +529,7 @@ template<typename Ctx> Result<typename Ctx::TypeT> singlevaltype(Ctx& ctx) {
return ctx.makeF64();
} else if (ctx.in.takeKeyword("v128"sv)) {
return ctx.makeV128();
} else if (auto type = reftype(ctx)) {
} else if (auto type = maybeReftype(ctx)) {
CHECK_ERR(type);
return *type;
} else {
Expand Down Expand Up @@ -788,10 +797,6 @@ Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx& ctx, Type indexType) {
CHECK_ERR(limits);
auto type = reftype(ctx);
CHECK_ERR(type);

if (!type) {
return ctx.in.err("expected reftype");
}
return ctx.makeTableType(indexType, *limits, *type);
}

Expand Down Expand Up @@ -2999,7 +3004,7 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
}

// Reftype if we have inline elements.
auto type = reftype(ctx);
auto type = maybeReftype(ctx);
CHECK_ERR(type);

std::optional<typename Ctx::TableTypeT> ttype;
Expand Down Expand Up @@ -3246,7 +3251,8 @@ MaybeResult<typename Ctx::ExprT> maybeElemexpr(Ctx& ctx) {
// | funcidx* (iff the tableuse is omitted)
template<typename Ctx>
Result<typename Ctx::ElemListT> elemlist(Ctx& ctx, bool legacy) {
if (auto type = reftype(ctx)) {
if (auto type = maybeReftype(ctx)) {
CHECK_ERR(type);
auto res = ctx.makeElemList(*type);
while (auto elem = maybeElemexpr(ctx)) {
CHECK_ERR(elem);
Expand Down
Loading