@@ -30,8 +30,6 @@ using namespace std::string_view_literals;
30
30
template <typename Ctx>
31
31
Result<typename Ctx::HeapTypeT> absheaptype (Ctx&, Shareability);
32
32
template <typename Ctx> Result<typename Ctx::HeapTypeT> heaptype (Ctx&);
33
- template <typename Ctx>
34
- MaybeResult<typename Ctx::TypeT> maybeReftypeAbbrev (Ctx&);
35
33
template <typename Ctx> MaybeResult<typename Ctx::RefTypeT> maybeReftype (Ctx&);
36
34
template <typename Ctx> Result<typename Ctx::RefTypeT> reftype (Ctx&);
37
35
template <typename Ctx> MaybeResult<typename Ctx::TypeT> tupletype (Ctx&);
@@ -436,6 +434,7 @@ Result<typename Ctx::HeapTypeT> absheaptype(Ctx& ctx, Shareability share) {
436
434
}
437
435
438
436
// heaptype ::= x:typeidx => types[x]
437
+ // | '(' 'exact' x:typeidx ')' => exact types[x]
439
438
// | t:absheaptype => unshared t
440
439
// | '(' 'shared' t:absheaptype ')' => shared t
441
440
template <typename Ctx> Result<typename Ctx::HeapTypeT> heaptype (Ctx& ctx) {
@@ -444,6 +443,15 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
444
443
return *t;
445
444
}
446
445
446
+ if (ctx.in .takeSExprStart (" exact" sv)) {
447
+ auto t = typeidx (ctx);
448
+ CHECK_ERR (t);
449
+ if (!ctx.in .takeRParen ()) {
450
+ return ctx.in .err (" expected end of exact heap type" );
451
+ }
452
+ return ctx.makeExact (*t);
453
+ }
454
+
447
455
auto share = ctx.in .takeSExprStart (" shared" sv) ? Shared : Unshared;
448
456
auto t = absheaptype (ctx, share);
449
457
CHECK_ERR (t);
@@ -460,85 +468,68 @@ template<typename Ctx> Result<typename Ctx::HeapTypeT> heaptype(Ctx& ctx) {
460
468
// | 'i31ref' => i31ref
461
469
// | 'structref' => structref
462
470
// | 'arrayref' => arrayref
463
- // | ...
464
- template <typename Ctx>
465
- MaybeResult<typename Ctx::TypeT> maybeReftypeAbbrev (Ctx& ctx) {
471
+ // | '(' ref null? t:heaptype ')' => ref null? t
472
+ template <typename Ctx> MaybeResult<typename Ctx::TypeT> maybeReftype (Ctx& ctx) {
466
473
if (ctx.in .takeKeyword (" funcref" sv)) {
467
- return ctx.makeRefType (ctx.makeFuncType (Unshared), Nullable, Inexact );
474
+ return ctx.makeRefType (ctx.makeFuncType (Unshared), Nullable);
468
475
}
469
476
if (ctx.in .takeKeyword (" externref" sv)) {
470
- return ctx.makeRefType (ctx.makeExternType (Unshared), Nullable, Inexact );
477
+ return ctx.makeRefType (ctx.makeExternType (Unshared), Nullable);
471
478
}
472
479
if (ctx.in .takeKeyword (" anyref" sv)) {
473
- return ctx.makeRefType (ctx.makeAnyType (Unshared), Nullable, Inexact );
480
+ return ctx.makeRefType (ctx.makeAnyType (Unshared), Nullable);
474
481
}
475
482
if (ctx.in .takeKeyword (" eqref" sv)) {
476
- return ctx.makeRefType (ctx.makeEqType (Unshared), Nullable, Inexact );
483
+ return ctx.makeRefType (ctx.makeEqType (Unshared), Nullable);
477
484
}
478
485
if (ctx.in .takeKeyword (" i31ref" sv)) {
479
- return ctx.makeRefType (ctx.makeI31Type (Unshared), Nullable, Inexact );
486
+ return ctx.makeRefType (ctx.makeI31Type (Unshared), Nullable);
480
487
}
481
488
if (ctx.in .takeKeyword (" structref" sv)) {
482
- return ctx.makeRefType (ctx.makeStructType (Unshared), Nullable, Inexact );
489
+ return ctx.makeRefType (ctx.makeStructType (Unshared), Nullable);
483
490
}
484
491
if (ctx.in .takeKeyword (" arrayref" sv)) {
485
- return ctx.makeRefType (ctx.makeArrayType (Unshared), Nullable, Inexact );
492
+ return ctx.makeRefType (ctx.makeArrayType (Unshared), Nullable);
486
493
}
487
494
if (ctx.in .takeKeyword (" exnref" sv)) {
488
- return ctx.makeRefType (ctx.makeExnType (Unshared), Nullable, Inexact );
495
+ return ctx.makeRefType (ctx.makeExnType (Unshared), Nullable);
489
496
}
490
497
if (ctx.in .takeKeyword (" stringref" sv)) {
491
- return ctx.makeRefType (ctx.makeStringType (Unshared), Nullable, Inexact );
498
+ return ctx.makeRefType (ctx.makeStringType (Unshared), Nullable);
492
499
}
493
500
if (ctx.in .takeKeyword (" contref" sv)) {
494
- return ctx.makeRefType (ctx.makeContType (Unshared), Nullable, Inexact );
501
+ return ctx.makeRefType (ctx.makeContType (Unshared), Nullable);
495
502
}
496
503
if (ctx.in .takeKeyword (" nullref" sv)) {
497
- return ctx.makeRefType (ctx.makeNoneType (Unshared), Nullable, Inexact );
504
+ return ctx.makeRefType (ctx.makeNoneType (Unshared), Nullable);
498
505
}
499
506
if (ctx.in .takeKeyword (" nullexternref" sv)) {
500
- return ctx.makeRefType (ctx.makeNoextType (Unshared), Nullable, Inexact );
507
+ return ctx.makeRefType (ctx.makeNoextType (Unshared), Nullable);
501
508
}
502
509
if (ctx.in .takeKeyword (" nullfuncref" sv)) {
503
- return ctx.makeRefType (ctx.makeNofuncType (Unshared), Nullable, Inexact );
510
+ return ctx.makeRefType (ctx.makeNofuncType (Unshared), Nullable);
504
511
}
505
512
if (ctx.in .takeKeyword (" nullexnref" sv)) {
506
- return ctx.makeRefType (ctx.makeNoexnType (Unshared), Nullable, Inexact );
513
+ return ctx.makeRefType (ctx.makeNoexnType (Unshared), Nullable);
507
514
}
508
515
if (ctx.in .takeKeyword (" nullcontref" sv)) {
509
- return ctx.makeRefType (ctx.makeNocontType (Unshared), Nullable, Inexact );
516
+ return ctx.makeRefType (ctx.makeNocontType (Unshared), Nullable);
510
517
}
511
- return {};
512
- }
513
518
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);
519
+ if (!ctx.in .takeSExprStart (" ref" sv)) {
520
+ return {};
528
521
}
529
522
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);
523
+ auto nullability = ctx.in .takeKeyword (" null" sv) ? Nullable : NonNullable;
524
+
525
+ auto type = heaptype (ctx);
526
+ CHECK_ERR (type);
527
+
528
+ if (!ctx.in .takeRParen ()) {
529
+ return ctx.in .err (" expected end of reftype" );
539
530
}
540
531
541
- return maybeReftypeAbbrev ( ctx);
532
+ return ctx. makeRefType (*type, nullability );
542
533
}
543
534
544
535
template <typename Ctx> Result<typename Ctx::TypeT> reftype (Ctx& ctx) {
0 commit comments