Skip to content

Commit b141e31

Browse files
authored
[Custom Descriptors] Update text format (#8056)
Make the `descriptor` and `describes` clauses self-contained siblings of the following composite type in the text format. The corresponding proposal change is WebAssembly/custom-descriptors#46.
1 parent 7a39522 commit b141e31

34 files changed

+931
-941
lines changed

src/parser/parsers.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,34 +3091,30 @@ template<typename Ctx> Result<> comptype(Ctx& ctx) {
30913091
return ctx.in.err("expected type description");
30923092
}
30933093

3094-
// describedcomptype ::= '(' 'descriptor' typeidx ct:comptype ')'
3095-
// | ct:comptype
3094+
// describedcomptype ::= '(' 'descriptor' typeidx ')' comptype
3095+
// | comptype
30963096
template<typename Ctx> Result<> describedcomptype(Ctx& ctx) {
30973097
if (ctx.in.takeSExprStart("descriptor"sv)) {
3098-
auto x = typeidx(ctx);
3099-
CHECK_ERR(x);
3100-
ctx.setDescriptor(*x);
3101-
CHECK_ERR(comptype(ctx));
3098+
auto d = typeidx(ctx);
3099+
CHECK_ERR(d);
31023100
if (!ctx.in.takeRParen()) {
3103-
return ctx.in.err("expected end of described type");
3101+
return ctx.in.err("expected end of descriptor");
31043102
}
3105-
return Ok{};
3103+
ctx.setDescriptor(*d);
31063104
}
31073105
return comptype(ctx);
31083106
}
31093107

3110-
// describingcomptype ::= '(' 'describes' typeidx ct:describedcomptype ')'
3111-
// | ct: describedcomptype
3108+
// describingcomptype ::= '(' 'describes' typeidx ')' describedcomptype
3109+
// | describedcomptype
31123110
template<typename Ctx> Result<> describingcomptype(Ctx& ctx) {
31133111
if (ctx.in.takeSExprStart("describes"sv)) {
3114-
auto x = typeidx(ctx);
3115-
CHECK_ERR(x);
3116-
ctx.setDescribes(*x);
3117-
CHECK_ERR(describedcomptype(ctx));
3112+
auto d = typeidx(ctx);
3113+
CHECK_ERR(d);
31183114
if (!ctx.in.takeRParen()) {
3119-
return ctx.in.err("expected end of describing type");
3115+
return ctx.in.err("expected end of describes");
31203116
}
3121-
return Ok{};
3117+
ctx.setDescribes(*d);
31223118
}
31233119
return describedcomptype(ctx);
31243120
}

src/wasm/wasm-type.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,12 +1823,12 @@ std::ostream& TypePrinter::print(HeapType type) {
18231823
if (auto desc = type.getDescribedType()) {
18241824
os << "(describes ";
18251825
printHeapTypeName(*desc);
1826-
os << ' ';
1826+
os << ") ";
18271827
}
18281828
if (auto desc = type.getDescriptorType()) {
18291829
os << "(descriptor ";
18301830
printHeapTypeName(*desc);
1831-
os << ' ';
1831+
os << ") ";
18321832
}
18331833
switch (type.getKind()) {
18341834
case HeapTypeKind::Func:
@@ -1846,12 +1846,6 @@ std::ostream& TypePrinter::print(HeapType type) {
18461846
case HeapTypeKind::Basic:
18471847
WASM_UNREACHABLE("unexpected kind");
18481848
}
1849-
if (type.getDescriptorType()) {
1850-
os << ')';
1851-
}
1852-
if (type.getDescribedType()) {
1853-
os << ')';
1854-
}
18551849
if (type.isShared()) {
18561850
os << ')';
18571851
}

test/lit/basic/custom-descriptors.wast

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@
1212
(module
1313
(rec
1414
;; CHECK-TEXT: (rec
15-
;; CHECK-TEXT-NEXT: (type $described (descriptor $middle (struct)))
15+
;; CHECK-TEXT-NEXT: (type $described (descriptor $middle) (struct))
1616
;; CHECK-BIN: (rec
17-
;; CHECK-BIN-NEXT: (type $described (descriptor $middle (struct)))
18-
(type $described (descriptor $middle (struct)))
19-
;; CHECK-TEXT: (type $middle (describes $described (descriptor $describing (struct))))
20-
;; CHECK-BIN: (type $middle (describes $described (descriptor $describing (struct))))
21-
(type $middle (describes $described (descriptor $describing (struct))))
22-
;; CHECK-TEXT: (type $describing (describes $middle (struct)))
23-
;; CHECK-BIN: (type $describing (describes $middle (struct)))
24-
(type $describing (describes $middle (struct)))
17+
;; CHECK-BIN-NEXT: (type $described (descriptor $middle) (struct))
18+
(type $described (descriptor $middle) (struct))
19+
;; CHECK-TEXT: (type $middle (describes $described) (descriptor $describing) (struct))
20+
;; CHECK-BIN: (type $middle (describes $described) (descriptor $describing) (struct))
21+
(type $middle (describes $described) (descriptor $describing) (struct))
22+
;; CHECK-TEXT: (type $describing (describes $middle) (struct))
23+
;; CHECK-BIN: (type $describing (describes $middle) (struct))
24+
(type $describing (describes $middle) (struct))
2525
)
2626

2727
(rec
2828
;; CHECK-TEXT: (type $3 (func (param anyref) (result anyref)))
2929

3030
;; CHECK-TEXT: (rec
31-
;; CHECK-TEXT-NEXT: (type $pair (descriptor $pair.desc (struct (field i32) (field i64))))
31+
;; CHECK-TEXT-NEXT: (type $pair (descriptor $pair.desc) (struct (field i32) (field i64)))
3232
;; CHECK-BIN: (type $3 (func (param anyref) (result anyref)))
3333

3434
;; CHECK-BIN: (rec
35-
;; CHECK-BIN-NEXT: (type $pair (descriptor $pair.desc (struct (field i32) (field i64))))
36-
(type $pair (descriptor $pair.desc (struct (field i32 i64))))
37-
;; CHECK-TEXT: (type $pair.desc (describes $pair (struct)))
38-
;; CHECK-BIN: (type $pair.desc (describes $pair (struct)))
39-
(type $pair.desc (describes $pair (struct)))
35+
;; CHECK-BIN-NEXT: (type $pair (descriptor $pair.desc) (struct (field i32) (field i64)))
36+
(type $pair (descriptor $pair.desc) (struct (field i32 i64)))
37+
;; CHECK-TEXT: (type $pair.desc (describes $pair) (struct))
38+
;; CHECK-BIN: (type $pair.desc (describes $pair) (struct))
39+
(type $pair.desc (describes $pair) (struct))
4040
)
4141

4242
(rec
@@ -58,7 +58,7 @@
5858
;; CHECK-TEXT: (type $13 (func (result (ref (exact $pair)))))
5959

6060
;; CHECK-TEXT: (rec
61-
;; CHECK-TEXT-NEXT: (type $shared-described (shared (descriptor $shared-describing (struct))))
61+
;; CHECK-TEXT-NEXT: (type $shared-described (shared (descriptor $shared-describing) (struct)))
6262
;; CHECK-BIN: (type $6 (func))
6363

6464
;; CHECK-BIN: (type $7 (func (param anyref (ref null $describing))))
@@ -76,11 +76,11 @@
7676
;; CHECK-BIN: (type $13 (func (result (ref (exact $pair)))))
7777

7878
;; CHECK-BIN: (rec
79-
;; CHECK-BIN-NEXT: (type $shared-described (shared (descriptor $shared-describing (struct))))
80-
(type $shared-described (shared (descriptor $shared-describing (struct))))
81-
;; CHECK-TEXT: (type $shared-describing (shared (describes $shared-described (struct))))
82-
;; CHECK-BIN: (type $shared-describing (shared (describes $shared-described (struct))))
83-
(type $shared-describing (shared (describes $shared-described (struct))))
79+
;; CHECK-BIN-NEXT: (type $shared-described (shared (descriptor $shared-describing) (struct)))
80+
(type $shared-described (shared (descriptor $shared-describing) (struct)))
81+
;; CHECK-TEXT: (type $shared-describing (shared (describes $shared-described) (struct)))
82+
;; CHECK-BIN: (type $shared-describing (shared (describes $shared-described) (struct)))
83+
(type $shared-describing (shared (describes $shared-described) (struct)))
8484
)
8585

8686

@@ -685,18 +685,18 @@
685685

686686
)
687687
;; CHECK-BIN-NODEBUG: (rec
688-
;; CHECK-BIN-NODEBUG-NEXT: (type $0 (descriptor $1 (struct)))
688+
;; CHECK-BIN-NODEBUG-NEXT: (type $0 (descriptor $1) (struct))
689689

690-
;; CHECK-BIN-NODEBUG: (type $1 (describes $0 (descriptor $2 (struct))))
690+
;; CHECK-BIN-NODEBUG: (type $1 (describes $0) (descriptor $2) (struct))
691691

692-
;; CHECK-BIN-NODEBUG: (type $2 (describes $1 (struct)))
692+
;; CHECK-BIN-NODEBUG: (type $2 (describes $1) (struct))
693693

694694
;; CHECK-BIN-NODEBUG: (type $3 (func (param anyref) (result anyref)))
695695

696696
;; CHECK-BIN-NODEBUG: (rec
697-
;; CHECK-BIN-NODEBUG-NEXT: (type $4 (descriptor $5 (struct (field i32) (field i64))))
697+
;; CHECK-BIN-NODEBUG-NEXT: (type $4 (descriptor $5) (struct (field i32) (field i64)))
698698

699-
;; CHECK-BIN-NODEBUG: (type $5 (describes $4 (struct)))
699+
;; CHECK-BIN-NODEBUG: (type $5 (describes $4) (struct))
700700

701701
;; CHECK-BIN-NODEBUG: (type $6 (func))
702702

@@ -715,9 +715,9 @@
715715
;; CHECK-BIN-NODEBUG: (type $13 (func (result (ref (exact $4)))))
716716

717717
;; CHECK-BIN-NODEBUG: (rec
718-
;; CHECK-BIN-NODEBUG-NEXT: (type $14 (shared (descriptor $15 (struct))))
718+
;; CHECK-BIN-NODEBUG-NEXT: (type $14 (shared (descriptor $15) (struct)))
719719

720-
;; CHECK-BIN-NODEBUG: (type $15 (shared (describes $14 (struct))))
720+
;; CHECK-BIN-NODEBUG: (type $15 (shared (describes $14) (struct)))
721721

722722
;; CHECK-BIN-NODEBUG: (type $16 (func (param (ref null $0) (ref null (exact $1)))))
723723

test/lit/ctor-eval/gc-desc.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
(module
55
(rec
66
;; CHECK: (rec
7-
;; CHECK-NEXT: (type $struct (sub (descriptor $desc (struct))))
8-
(type $struct (sub (descriptor $desc (struct))))
9-
;; CHECK: (type $desc (describes $struct (struct)))
10-
(type $desc (describes $struct (struct)))
7+
;; CHECK-NEXT: (type $struct (sub (descriptor $desc) (struct)))
8+
(type $struct (sub (descriptor $desc) (struct)))
9+
;; CHECK: (type $desc (describes $struct) (struct))
10+
(type $desc (describes $struct) (struct))
1111
)
1212
;; CHECK: (type $2 (func))
1313

test/lit/fuzz-types.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
;; CHECK-NEXT: (type $4 (sub (array (ref null $9))))
1111
;; CHECK-NEXT: (type $5 (sub final $0 (shared (array i8))))
1212
;; CHECK-NEXT: (type $6 (sub $2 (shared (func (param i64 (ref null (shared eq)) i64) (result (ref $8))))))
13-
;; CHECK-NEXT: (type $7 (sub (shared (descriptor $9 (struct (field (ref null $7)) (field (mut i64)) (field (mut i8)) (field i32) (field (mut i32)))))))
13+
;; CHECK-NEXT: (type $7 (sub (shared (descriptor $9) (struct (field (ref null $7)) (field (mut i64)) (field (mut i8)) (field i32) (field (mut i32))))))
1414
;; CHECK-NEXT: (type $8 (sub $2 (shared (func (param i64 (ref null $0) i64) (result (ref $8))))))
15-
;; CHECK-NEXT: (type $9 (shared (describes $7 (descriptor $12 (struct (field i32) (field (mut (ref $8))) (field f64))))))
15+
;; CHECK-NEXT: (type $9 (shared (describes $7) (descriptor $12) (struct (field i32) (field (mut (ref $8))) (field f64))))
1616
;; CHECK-NEXT: (type $10 (sub (array (mut externref))))
1717
;; CHECK-NEXT: (type $11 (sub $4 (array (ref $9))))
18-
;; CHECK-NEXT: (type $12 (sub (shared (describes $9 (struct (field (mut f64)) (field (mut i32)) (field (mut f64)))))))
18+
;; CHECK-NEXT: (type $12 (sub (shared (describes $9) (struct (field (mut f64)) (field (mut i32)) (field (mut f64))))))
1919
;; CHECK-NEXT: )
2020
;; CHECK-NEXT: (rec
2121
;; CHECK-NEXT: (type $13 (sub (struct (field (mut i16)) (field i64) (field (mut (ref (shared func)))))))
@@ -42,12 +42,12 @@
4242
;; CHECK-NEXT: (type $4 (sub (array (ref null $9))))
4343
;; CHECK-NEXT: (type $5 (sub final $0 (shared (array i8))))
4444
;; CHECK-NEXT: (type $6 (sub $2 (shared (func (param i64 (ref null (shared eq)) i64) (result (ref $8))))))
45-
;; CHECK-NEXT: (type $7 (sub (shared (descriptor $9 (struct (field (ref null $7)) (field (mut i64)) (field (mut i8)) (field i32) (field (mut i32)))))))
45+
;; CHECK-NEXT: (type $7 (sub (shared (descriptor $9) (struct (field (ref null $7)) (field (mut i64)) (field (mut i8)) (field i32) (field (mut i32))))))
4646
;; CHECK-NEXT: (type $8 (sub $2 (shared (func (param i64 (ref null $0) i64) (result (ref $8))))))
47-
;; CHECK-NEXT: (type $9 (shared (describes $7 (descriptor $12 (struct (field i32) (field (mut (ref $8))) (field f64))))))
47+
;; CHECK-NEXT: (type $9 (shared (describes $7) (descriptor $12) (struct (field i32) (field (mut (ref $8))) (field f64))))
4848
;; CHECK-NEXT: (type $10 (sub (array (mut externref))))
4949
;; CHECK-NEXT: (type $11 (sub $4 (array (ref $9))))
50-
;; CHECK-NEXT: (type $12 (sub (shared (describes $9 (struct (field (mut f64)) (field (mut i32)) (field (mut f64)))))))
50+
;; CHECK-NEXT: (type $12 (sub (shared (describes $9) (struct (field (mut f64)) (field (mut i32)) (field (mut f64))))))
5151
;; CHECK-NEXT: )
5252
;; CHECK-NEXT: (rec
5353
;; CHECK-NEXT: (type $13 (sub (struct (field (mut i16)) (field i64) (field (mut (ref (shared func)))))))

0 commit comments

Comments
 (0)