Skip to content

Commit 999af0b

Browse files
authored
Merge pull request #354 from bytecodealliance/ydnar/issue352
wit/bindgen: create custom shape types for tuples
2 parents 5c4ace4 + 8957c84 commit 999af0b

7 files changed

Lines changed: 92 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1212

1313
- [#306](https://github.com/bytecodealliance/go-modules/issues/306): do not emit incompatible version feature gates when serializing WIT. For example, if a world with version `0.1.0` *includes* a world from another package with a `@since(version = 0.2.0)` feature gate, then strip that feature gate when serializing to WIT if the version is greater than the world’s package version.
1414
- [#350](https://github.com/bytecodealliance/go-modules/issues/350): correctly align `record` size to the highest alignment of its fields, per [specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#element-size).
15-
15+
- [#352](https://github.com/bytecodealliance/go-modules/issues/352): do not use `tuple` types as data shape for `variant` or `result` types, as they may contain a `bool` or not be packed.
1616

1717
## [v0.6.2] — 2025-03-16
1818

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+
}

tests/generated/wasi/sockets/v0.2.0/network/abi.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/wasi/sockets/v0.2.0/network/network.wit.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)