Skip to content

Commit 5d297dc

Browse files
authored
Update the text syntax for tuple types (#6246)
Instead of e.g. `(i32 i32)`, use `(tuple i32 i32)`. Having a keyword to introduce the s-expression is more consistent with the rest of the language.
1 parent d23a63f commit 5d297dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+241
-238
lines changed

src/shared-constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern Name PRINT;
6262
extern Name EXIT;
6363
extern Name SHARED;
6464
extern Name TAG;
65+
extern Name TUPLE;
6566

6667
} // namespace wasm
6768

src/wasm/wasm-s-parser.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,12 +1393,15 @@ Type SExpressionWasmBuilder::elementToType(Element& s) {
13931393
}
13941394
return Type(parseHeapType(*s[i]), nullable);
13951395
}
1396-
// It's a tuple.
1397-
std::vector<Type> types;
1398-
for (size_t i = 0; i < s.size(); ++i) {
1399-
types.push_back(elementToType(*list[i]));
1396+
if (elementStartsWith(s, TUPLE)) {
1397+
// It's a tuple.
1398+
std::vector<Type> types;
1399+
for (size_t i = 1; i < s.size(); ++i) {
1400+
types.push_back(elementToType(*list[i]));
1401+
}
1402+
return Type(types);
14001403
}
1401-
return Type(types);
1404+
throw SParseException(std::string("expected type, got list"), s);
14021405
}
14031406

14041407
Type SExpressionWasmBuilder::stringToLaneType(const char* str) {

src/wasm/wasm-type.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,11 +1952,9 @@ std::ostream& TypePrinter::print(HeapType type) {
19521952
}
19531953

19541954
std::ostream& TypePrinter::print(const Tuple& tuple) {
1955-
os << '(';
1956-
auto sep = "";
1955+
os << "(tuple";
19571956
for (Type type : tuple) {
1958-
os << sep;
1959-
sep = " ";
1957+
os << ' ';
19601958
print(type);
19611959
}
19621960
return os << ')';

src/wasm/wasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Name PRINT("print");
9999
Name EXIT("exit");
100100
Name SHARED("shared");
101101
Name TAG("tag");
102+
Name TUPLE("tuple");
102103

103104
// Expressions
104105

test/example/typeinfo.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ i31ref
4040
(ref null $array.0)
4141

4242
;; Tuple
43-
()
43+
(tuple)
4444
none
45-
(i32 f64)
46-
(i32 f64)
45+
(tuple i32 f64)
46+
(tuple i32 f64)
4747

4848
;; Signature of references (param/result)
4949
(func (param (ref null $struct.0)) (result (ref $array.0)))
@@ -77,8 +77,8 @@ none
7777
(ref null $array.0)
7878

7979
;; Tuple of references
80-
((ref $func.0) (ref null $func.0) (ref $struct.0) (ref null $struct.0) (ref $array.0) (ref null $array.0))
81-
((ref $func.0) (ref null $func.0) (ref $struct.0) (ref null $struct.0) (ref $array.0) (ref null $array.0))
80+
(tuple (ref $func.0) (ref null $func.0) (ref $struct.0) (ref null $struct.0) (ref $array.0) (ref null $array.0))
81+
(tuple (ref $func.0) (ref null $func.0) (ref $struct.0) (ref null $struct.0) (ref $array.0) (ref null $array.0))
8282

8383
;; Recursive (not really)
8484
(func (param (ref $func.0)))

test/gtest/cfg.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ TEST_F(CFGTest, LinearReachingDefinitions) {
270270
auto moduleText = R"wasm(
271271
(module
272272
(func $bar
273-
(local $a (i32))
274-
(local $b (i32))
275-
(local $c (i32))
273+
(local $a i32)
274+
(local $b i32)
275+
(local $c i32)
276276
(local.set $a
277277
(i32.const 1)
278278
)
@@ -335,8 +335,8 @@ TEST_F(CFGTest, ReachingDefinitionsIf) {
335335
auto moduleText = R"wasm(
336336
(module
337337
(func $bar
338-
(local $a (i32))
339-
(local $b (i32))
338+
(local $a i32)
339+
(local $b i32)
340340
(local.set $a
341341
(i32.const 1)
342342
)
@@ -406,7 +406,7 @@ TEST_F(CFGTest, ReachingDefinitionsIf) {
406406
TEST_F(CFGTest, ReachingDefinitionsLoop) {
407407
auto moduleText = R"wasm(
408408
(module
409-
(func $bar (param $a (i32)) (param $b (i32))
409+
(func $bar (param $a i32) (param $b i32)
410410
(loop $loop
411411
(drop
412412
(local.get $a)

test/lit/basic/exception-handling-old.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
)
106106

107107
;; CHECK-TEXT: (func $try-catch-multivalue-tag (type $0)
108-
;; CHECK-TEXT-NEXT: (local $x (i32 i64))
108+
;; CHECK-TEXT-NEXT: (local $x (tuple i32 i64))
109109
;; CHECK-TEXT-NEXT: (try $try
110110
;; CHECK-TEXT-NEXT: (do
111111
;; CHECK-TEXT-NEXT: (throw $e-i32-i64
@@ -128,7 +128,7 @@
128128
;; CHECK-BIN: (func $try-catch-multivalue-tag (type $0)
129129
;; CHECK-BIN-NEXT: (local $x i32)
130130
;; CHECK-BIN-NEXT: (local $1 i64)
131-
;; CHECK-BIN-NEXT: (local $2 (i32 i64))
131+
;; CHECK-BIN-NEXT: (local $2 (tuple i32 i64))
132132
;; CHECK-BIN-NEXT: (local $3 i32)
133133
;; CHECK-BIN-NEXT: (try $label$3
134134
;; CHECK-BIN-NEXT: (do
@@ -162,7 +162,7 @@
162162
;; CHECK-BIN-NEXT: )
163163
;; CHECK-BIN-NEXT: )
164164
;; CHECK-BIN-NEXT: )
165-
(func $try-catch-multivalue-tag (local $x (i32 i64))
165+
(func $try-catch-multivalue-tag (local $x (tuple i32 i64))
166166
(try
167167
(do
168168
(throw $e-i32-i64 (i32.const 0) (i64.const 0))
@@ -1376,7 +1376,7 @@
13761376
;; CHECK-BIN-NODEBUG: (func $3 (type $0)
13771377
;; CHECK-BIN-NODEBUG-NEXT: (local $0 i32)
13781378
;; CHECK-BIN-NODEBUG-NEXT: (local $1 i64)
1379-
;; CHECK-BIN-NODEBUG-NEXT: (local $2 (i32 i64))
1379+
;; CHECK-BIN-NODEBUG-NEXT: (local $2 (tuple i32 i64))
13801380
;; CHECK-BIN-NODEBUG-NEXT: (local $3 i32)
13811381
;; CHECK-BIN-NODEBUG-NEXT: (try $label$3
13821382
;; CHECK-BIN-NODEBUG-NEXT: (do

test/lit/basic/exception-handling.wast

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@
237237
;; CHECK-TEXT-NEXT: )
238238
;; CHECK-TEXT-NEXT: )
239239
;; CHECK-BIN: (func $try-table-multivalue-tag (type $0)
240-
;; CHECK-BIN-NEXT: (local $0 (i32 i64))
240+
;; CHECK-BIN-NEXT: (local $0 (tuple i32 i64))
241241
;; CHECK-BIN-NEXT: (local $1 i32)
242-
;; CHECK-BIN-NEXT: (local $2 (i32 i64 exnref))
242+
;; CHECK-BIN-NEXT: (local $2 (tuple i32 i64 exnref))
243243
;; CHECK-BIN-NEXT: (local $3 i64)
244244
;; CHECK-BIN-NEXT: (local $4 i32)
245245
;; CHECK-BIN-NEXT: (block $label$1
@@ -419,7 +419,7 @@
419419
;; CHECK-TEXT-NEXT: )
420420
;; CHECK-TEXT-NEXT: )
421421
;; CHECK-BIN: (func $try-table-all-catch-clauses-i32-tag (type $0)
422-
;; CHECK-BIN-NEXT: (local $0 (i32 exnref))
422+
;; CHECK-BIN-NEXT: (local $0 (tuple i32 exnref))
423423
;; CHECK-BIN-NEXT: (local $1 i32)
424424
;; CHECK-BIN-NEXT: (block $label$1
425425
;; CHECK-BIN-NEXT: (drop
@@ -517,10 +517,10 @@
517517
;; CHECK-TEXT-NEXT: )
518518
;; CHECK-TEXT-NEXT: )
519519
;; CHECK-BIN: (func $try-table-all-catch-clauses-multivalue-tag (type $0)
520-
;; CHECK-BIN-NEXT: (local $0 (i32 i64 exnref))
520+
;; CHECK-BIN-NEXT: (local $0 (tuple i32 i64 exnref))
521521
;; CHECK-BIN-NEXT: (local $1 i64)
522522
;; CHECK-BIN-NEXT: (local $2 i32)
523-
;; CHECK-BIN-NEXT: (local $3 (i32 i64))
523+
;; CHECK-BIN-NEXT: (local $3 (tuple i32 i64))
524524
;; CHECK-BIN-NEXT: (local $4 i32)
525525
;; CHECK-BIN-NEXT: (block $label$1
526526
;; CHECK-BIN-NEXT: (local.set $3
@@ -810,9 +810,9 @@
810810
;; CHECK-BIN-NODEBUG-NEXT: )
811811

812812
;; CHECK-BIN-NODEBUG: (func $5 (type $0)
813-
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (i32 i64))
813+
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (tuple i32 i64))
814814
;; CHECK-BIN-NODEBUG-NEXT: (local $1 i32)
815-
;; CHECK-BIN-NODEBUG-NEXT: (local $2 (i32 i64 exnref))
815+
;; CHECK-BIN-NODEBUG-NEXT: (local $2 (tuple i32 i64 exnref))
816816
;; CHECK-BIN-NODEBUG-NEXT: (local $3 i64)
817817
;; CHECK-BIN-NODEBUG-NEXT: (local $4 i32)
818818
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1
@@ -899,7 +899,7 @@
899899
;; CHECK-BIN-NODEBUG-NEXT: )
900900

901901
;; CHECK-BIN-NODEBUG: (func $7 (type $0)
902-
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (i32 exnref))
902+
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (tuple i32 exnref))
903903
;; CHECK-BIN-NODEBUG-NEXT: (local $1 i32)
904904
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1
905905
;; CHECK-BIN-NODEBUG-NEXT: (drop
@@ -942,10 +942,10 @@
942942
;; CHECK-BIN-NODEBUG-NEXT: )
943943

944944
;; CHECK-BIN-NODEBUG: (func $8 (type $0)
945-
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (i32 i64 exnref))
945+
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (tuple i32 i64 exnref))
946946
;; CHECK-BIN-NODEBUG-NEXT: (local $1 i64)
947947
;; CHECK-BIN-NODEBUG-NEXT: (local $2 i32)
948-
;; CHECK-BIN-NODEBUG-NEXT: (local $3 (i32 i64))
948+
;; CHECK-BIN-NODEBUG-NEXT: (local $3 (tuple i32 i64))
949949
;; CHECK-BIN-NODEBUG-NEXT: (local $4 i32)
950950
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1
951951
;; CHECK-BIN-NODEBUG-NEXT: (local.set $3

test/lit/basic/typed_continuations_resume.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
;; CHECK-TEXT-NEXT: )
6262
;; CHECK-TEXT-NEXT: )
6363
;; CHECK-BIN: (func $go (type $3) (param $x (ref $ct)) (result i32)
64-
;; CHECK-BIN-NEXT: (local $1 (i32 (ref $ct)))
64+
;; CHECK-BIN-NEXT: (local $1 (tuple i32 (ref $ct)))
6565
;; CHECK-BIN-NEXT: (local $2 i32)
6666
;; CHECK-BIN-NEXT: (local.set $1
6767
;; CHECK-BIN-NEXT: (block $label$1 (type $2) (result i32 (ref $ct))
@@ -135,7 +135,7 @@
135135
;; CHECK-BIN-NODEBUG: (tag $tag$0 (param i32) (result i32))
136136

137137
;; CHECK-BIN-NODEBUG: (func $0 (type $3) (param $0 (ref $1)) (result i32)
138-
;; CHECK-BIN-NODEBUG-NEXT: (local $1 (i32 (ref $1)))
138+
;; CHECK-BIN-NODEBUG-NEXT: (local $1 (tuple i32 (ref $1)))
139139
;; CHECK-BIN-NODEBUG-NEXT: (local $2 i32)
140140
;; CHECK-BIN-NODEBUG-NEXT: (local.set $1
141141
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1 (type $2) (result i32 (ref $1))

test/lit/basic/types-function-references.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
)
175175

176176
;; CHECK-TEXT: (func $type-only-in-tuple-local (type $void)
177-
;; CHECK-TEXT-NEXT: (local $x (i32 (ref null $=>anyref) f64))
177+
;; CHECK-TEXT-NEXT: (local $x (tuple i32 (ref null $=>anyref) f64))
178178
;; CHECK-TEXT-NEXT: (nop)
179179
;; CHECK-TEXT-NEXT: )
180180
;; CHECK-BIN: (func $type-only-in-tuple-local (type $void)
@@ -184,7 +184,7 @@
184184
;; CHECK-BIN-NEXT: (nop)
185185
;; CHECK-BIN-NEXT: )
186186
(func $type-only-in-tuple-local
187-
(local $x (i32 (ref null $=>anyref) f64))
187+
(local $x (tuple i32 (ref null $=>anyref) f64))
188188
)
189189

190190
;; CHECK-TEXT: (func $type-only-in-tuple-block (type $void)
@@ -195,7 +195,7 @@
195195
;; CHECK-TEXT-NEXT: )
196196
;; CHECK-TEXT-NEXT: )
197197
;; CHECK-BIN: (func $type-only-in-tuple-block (type $void)
198-
;; CHECK-BIN-NEXT: (local $0 (i32 (ref null $mixed_results) f64))
198+
;; CHECK-BIN-NEXT: (local $0 (tuple i32 (ref null $mixed_results) f64))
199199
;; CHECK-BIN-NEXT: (local $1 (ref null $mixed_results))
200200
;; CHECK-BIN-NEXT: (local $2 i32)
201201
;; CHECK-BIN-NEXT: (local.set $0
@@ -433,7 +433,7 @@
433433
;; CHECK-BIN-NODEBUG-NEXT: )
434434

435435
;; CHECK-BIN-NODEBUG: (func $8 (type $1)
436-
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (i32 (ref null $0) f64))
436+
;; CHECK-BIN-NODEBUG-NEXT: (local $0 (tuple i32 (ref null $0) f64))
437437
;; CHECK-BIN-NODEBUG-NEXT: (local $1 (ref null $0))
438438
;; CHECK-BIN-NODEBUG-NEXT: (local $2 i32)
439439
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0

test/lit/blocktype.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
;; CHECK-NEXT: )
2626
;; CHECK-NEXT: )
2727
;; RTRIP: (func $f1 (type $f1) (result (ref $f1) (ref $f2))
28-
;; RTRIP-NEXT: (local $0 ((ref $f1) (ref $f2)))
29-
;; RTRIP-NEXT: (local $1 ((ref $f1) (ref $f2)))
28+
;; RTRIP-NEXT: (local $0 (tuple (ref $f1) (ref $f2)))
29+
;; RTRIP-NEXT: (local $1 (tuple (ref $f1) (ref $f2)))
3030
;; RTRIP-NEXT: (local.set $1
3131
;; RTRIP-NEXT: (loop $label$1 (type $f1) (result (ref $f1) (ref $f2))
3232
;; RTRIP-NEXT: (local.set $0
@@ -64,8 +64,8 @@
6464
;; CHECK-NEXT: )
6565
;; CHECK-NEXT: )
6666
;; RTRIP: (func $f2 (type $f2) (result (ref $f2) (ref $f1))
67-
;; RTRIP-NEXT: (local $0 ((ref $f2) (ref $f1)))
68-
;; RTRIP-NEXT: (local $1 ((ref $f2) (ref $f1)))
67+
;; RTRIP-NEXT: (local $0 (tuple (ref $f2) (ref $f1)))
68+
;; RTRIP-NEXT: (local $1 (tuple (ref $f2) (ref $f1)))
6969
;; RTRIP-NEXT: (local.set $1
7070
;; RTRIP-NEXT: (loop $label$1 (type $f2) (result (ref $f2) (ref $f1))
7171
;; RTRIP-NEXT: (local.set $0

test/lit/ctor-eval/multivalue-local.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
(func $multivalue-local (export "multivalue-local") (result i32)
1313
(local $0 i32)
14-
(local $1 (i32 i32))
14+
(local $1 (tuple i32 i32))
1515

1616
;; We can eval this line. But we will stop evalling at the line after it, the
1717
;; import call. As a result we'll only have a partial evalling of this

test/lit/multivalue-stack-ir.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
;; CHECK-NEXT: )
2727
;; CHECK-NEXT: )
2828
(func $test
29-
(local $pair (f32 i32))
29+
(local $pair (tuple f32 i32))
3030
(local $f32 f32)
3131
;; Normally this get-set pair would be eliminated by stack IR optimizations,
3232
;; but then the binary writer's tuple optimizations would leave the only the

0 commit comments

Comments
 (0)