@@ -30,8 +30,6 @@ using namespace std::string_view_literals;
3030template <typename Ctx>
3131Result<typename Ctx::HeapTypeT> absheaptype (Ctx&, Shareability);
3232template <typename Ctx> Result<typename Ctx::HeapTypeT> heaptype (Ctx&);
33- template <typename Ctx>
34- MaybeResult<typename Ctx::TypeT> maybeReftypeAbbrev (Ctx&);
3533template <typename Ctx> MaybeResult<typename Ctx::RefTypeT> maybeReftype (Ctx&);
3634template <typename Ctx> Result<typename Ctx::RefTypeT> reftype (Ctx&);
3735template <typename Ctx> MaybeResult<typename Ctx::TypeT> tupletype (Ctx&);
@@ -460,85 +458,68 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
460458// | 'i31ref' => i31ref
461459// | 'structref' => structref
462460// | 'arrayref' => arrayref
463- // | ...
464- template <typename Ctx>
465- MaybeResult<typename Ctx::TypeT> maybeReftypeAbbrev (Ctx& ctx) {
461+ // | '(' ref null? t:heaptype ')' => ref null? t
462+ template <typename Ctx> MaybeResult<typename Ctx::TypeT> maybeReftype (Ctx& ctx) {
466463 if (ctx.in .takeKeyword (" funcref" sv)) {
467- return ctx.makeRefType (ctx.makeFuncType (Unshared), Nullable, Inexact );
464+ return ctx.makeRefType (ctx.makeFuncType (Unshared), Nullable);
468465 }
469466 if (ctx.in .takeKeyword (" externref" sv)) {
470- return ctx.makeRefType (ctx.makeExternType (Unshared), Nullable, Inexact );
467+ return ctx.makeRefType (ctx.makeExternType (Unshared), Nullable);
471468 }
472469 if (ctx.in .takeKeyword (" anyref" sv)) {
473- return ctx.makeRefType (ctx.makeAnyType (Unshared), Nullable, Inexact );
470+ return ctx.makeRefType (ctx.makeAnyType (Unshared), Nullable);
474471 }
475472 if (ctx.in .takeKeyword (" eqref" sv)) {
476- return ctx.makeRefType (ctx.makeEqType (Unshared), Nullable, Inexact );
473+ return ctx.makeRefType (ctx.makeEqType (Unshared), Nullable);
477474 }
478475 if (ctx.in .takeKeyword (" i31ref" sv)) {
479- return ctx.makeRefType (ctx.makeI31Type (Unshared), Nullable, Inexact );
476+ return ctx.makeRefType (ctx.makeI31Type (Unshared), Nullable);
480477 }
481478 if (ctx.in .takeKeyword (" structref" sv)) {
482- return ctx.makeRefType (ctx.makeStructType (Unshared), Nullable, Inexact );
479+ return ctx.makeRefType (ctx.makeStructType (Unshared), Nullable);
483480 }
484481 if (ctx.in .takeKeyword (" arrayref" sv)) {
485- return ctx.makeRefType (ctx.makeArrayType (Unshared), Nullable, Inexact );
482+ return ctx.makeRefType (ctx.makeArrayType (Unshared), Nullable);
486483 }
487484 if (ctx.in .takeKeyword (" exnref" sv)) {
488- return ctx.makeRefType (ctx.makeExnType (Unshared), Nullable, Inexact );
485+ return ctx.makeRefType (ctx.makeExnType (Unshared), Nullable);
489486 }
490487 if (ctx.in .takeKeyword (" stringref" sv)) {
491- return ctx.makeRefType (ctx.makeStringType (Unshared), Nullable, Inexact );
488+ return ctx.makeRefType (ctx.makeStringType (Unshared), Nullable);
492489 }
493490 if (ctx.in .takeKeyword (" contref" sv)) {
494- return ctx.makeRefType (ctx.makeContType (Unshared), Nullable, Inexact );
491+ return ctx.makeRefType (ctx.makeContType (Unshared), Nullable);
495492 }
496493 if (ctx.in .takeKeyword (" nullref" sv)) {
497- return ctx.makeRefType (ctx.makeNoneType (Unshared), Nullable, Inexact );
494+ return ctx.makeRefType (ctx.makeNoneType (Unshared), Nullable);
498495 }
499496 if (ctx.in .takeKeyword (" nullexternref" sv)) {
500- return ctx.makeRefType (ctx.makeNoextType (Unshared), Nullable, Inexact );
497+ return ctx.makeRefType (ctx.makeNoextType (Unshared), Nullable);
501498 }
502499 if (ctx.in .takeKeyword (" nullfuncref" sv)) {
503- return ctx.makeRefType (ctx.makeNofuncType (Unshared), Nullable, Inexact );
500+ return ctx.makeRefType (ctx.makeNofuncType (Unshared), Nullable);
504501 }
505502 if (ctx.in .takeKeyword (" nullexnref" sv)) {
506- return ctx.makeRefType (ctx.makeNoexnType (Unshared), Nullable, Inexact );
503+ return ctx.makeRefType (ctx.makeNoexnType (Unshared), Nullable);
507504 }
508505 if (ctx.in .takeKeyword (" nullcontref" sv)) {
509- return ctx.makeRefType (ctx.makeNocontType (Unshared), Nullable, Inexact );
506+ return ctx.makeRefType (ctx.makeNocontType (Unshared), Nullable);
510507 }
511- return {};
512- }
513508
514- // reftype ::= ...
515- // | '(' 'exact' (ref null ht):shorthand ')' => ref null exact ht
516- // | '(' ref null? exact? ht:heaptype ')' => ref null? t
517- template <typename Ctx> MaybeResult<typename Ctx::TypeT> maybeReftype (Ctx& ctx) {
518- if (ctx.in .takeSExprStart (" exact" sv)) {
519- auto rt = maybeReftypeAbbrev (ctx);
520- CHECK_ERR (rt);
521- if (!rt) {
522- return ctx.in .err (" expected reftype shorthand" );
523- }
524- if (!ctx.in .takeRParen ()) {
525- return ctx.in .err (" expected end of reftype" );
526- }
527- return ctx.makeRefType (ctx.getHeapTypeFromRefType (*rt), Nullable, Exact);
509+ if (!ctx.in .takeSExprStart (" ref" sv)) {
510+ return {};
528511 }
529512
530- if (ctx.in .takeSExprStart (" ref" sv)) {
531- auto nullability = ctx.in .takeKeyword (" null" sv) ? Nullable : NonNullable;
532- auto exactness = ctx.in .takeKeyword (" exact" sv) ? Exact : Inexact;
533- auto type = heaptype (ctx);
534- CHECK_ERR (type);
535- if (!ctx.in .takeRParen ()) {
536- return ctx.in .err (" expected end of reftype" );
537- }
538- return ctx.makeRefType (*type, nullability, exactness);
513+ auto nullability = ctx.in .takeKeyword (" null" sv) ? Nullable : NonNullable;
514+
515+ auto type = heaptype (ctx);
516+ CHECK_ERR (type);
517+
518+ if (!ctx.in .takeRParen ()) {
519+ return ctx.in .err (" expected end of reftype" );
539520 }
540521
541- return maybeReftypeAbbrev ( ctx);
522+ return ctx. makeRefType (*type, nullability );
542523}
543524
544525template <typename Ctx> Result<typename Ctx::TypeT> reftype (Ctx& ctx) {
0 commit comments