Skip to content

Commit 7b7bf7a

Browse files
committed
wit/bindgen: use custom GC shape for tuples
Monotypic tuples may not be dense, as they can include a bool, or a struct with a bool.
1 parent 5c4ace4 commit 7b7bf7a

4 files changed

Lines changed: 84 additions & 7 deletions

File tree

testdata/issues/issue352.wit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package issues:issue352;
2+
3+
world w {
4+
import i;
5+
}
6+
7+
interface i {
8+
type a = result<tuple<bool, bool, bool>, s16>;
9+
}

testdata/issues/issue352.wit.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "w",
5+
"imports": {
6+
"interface-0": {
7+
"interface": {
8+
"id": 0
9+
}
10+
}
11+
},
12+
"exports": {},
13+
"package": 0
14+
}
15+
],
16+
"interfaces": [
17+
{
18+
"name": "i",
19+
"types": {
20+
"a": 1
21+
},
22+
"functions": {},
23+
"package": 0
24+
}
25+
],
26+
"types": [
27+
{
28+
"name": null,
29+
"kind": {
30+
"tuple": {
31+
"types": [
32+
"bool",
33+
"bool",
34+
"bool"
35+
]
36+
}
37+
},
38+
"owner": null
39+
},
40+
{
41+
"name": "a",
42+
"kind": {
43+
"result": {
44+
"ok": 0,
45+
"err": "s16"
46+
}
47+
},
48+
"owner": {
49+
"interface": 0
50+
}
51+
}
52+
],
53+
"packages": [
54+
{
55+
"name": "issues:issue352",
56+
"interfaces": {
57+
"i": 0
58+
},
59+
"worlds": {
60+
"w": 0
61+
}
62+
}
63+
]
64+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package issues:issue352;
2+
3+
interface i {
4+
type a = result<tuple<bool, bool, bool>, s16>;
5+
}
6+
7+
world w {
8+
import i;
9+
}

wit/bindgen/generator.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,20 +1032,15 @@ func (g *generator) typeDefShape(file *gen.File, dir wit.Direction, t *wit.TypeD
10321032
case wit.Type:
10331033
return g.typeShape(file, dir, kind)
10341034
case *wit.Variant:
1035-
if kind.Enum() != nil {
1036-
// Variants that can be represented as an enum do not need a custom shape.
1035+
if len(kind.Types()) == 0 {
1036+
// Variants without associated types do not need a custom shape.
10371037
return g.typeRep(file, dir, t)
10381038
}
10391039
case *wit.Result:
10401040
if len(kind.Types()) == 0 {
10411041
// Results without associated types do not need a custom shape.
10421042
return g.typeRep(file, dir, t)
10431043
}
1044-
case *wit.Tuple:
1045-
if kind.Type() != nil {
1046-
// Monotypic tuples have a packed memory layout.
1047-
return g.typeRep(file, dir, t)
1048-
}
10491044
case *wit.Enum, *wit.Flags, *wit.List,
10501045
*wit.Resource, *wit.Own, *wit.Borrow, *wit.Stream, *wit.Future:
10511046
// Certain types do not need custom type shapes:

0 commit comments

Comments
 (0)