Skip to content

Commit f0957de

Browse files
authored
Merge pull request #290 from bytecodealliance/ydnar/issue288
wit: fix ABI alignment of list<T> to 4
2 parents c53528d + 3ce4471 commit f0957de

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

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

2020
- [#281](https://github.com/bytecodealliance/go-modules/issues/281): errors from internal `wasm-tools` calls are no longer silently ignored. This required fixing a number of related issues, including synthetic world packages for Component Model metadata generation, WIT generation, and WIT keyword escaping in WIT package or interface names.
2121
- [#284](https://github.com/bytecodealliance/go-modules/issues/284): do not use `bool` for `variant` or `result` GC shapes. TinyGo returns `result` and `variant` values with `bool` as 0 or 1, which breaks the memory representation of tagged unions (variants).
22+
- [#288](https://github.com/bytecodealliance/go-modules/issues/288): correctly report the `wasm32` ABI alignment of `list<T>` as 4, rather than 8.
2223

2324
## [v0.5.0] — 2024-12-14
2425

wit/bindgen/generator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,12 @@ func (g *generator) variantRep(file *gen.File, dir wit.Direction, t *wit.TypeDef
880880
}
881881

882882
disc := wit.Discriminant(len(v.Cases))
883-
shape := variantShape(v.Types())
884-
align := variantAlign(v.Types())
883+
types := v.Types()
884+
shape := variantShape(types)
885+
align := variantAlign(types)
885886

886887
var typeShape string
887-
if len(v.Types()) == 1 {
888+
if len(types) == 1 {
888889
typeShape = g.typeRep(file, dir, shape)
889890
} else {
890891
typeShape = g.typeShape(file, dir, shape)

wit/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (*List) Size() uintptr { return 8 } // [2]int32
1717
// Align returns the [ABI byte alignment] a [List].
1818
//
1919
// [ABI byte alignment]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#alignment
20-
func (*List) Align() uintptr { return 8 } // [2]int32
20+
func (*List) Align() uintptr { return 4 }
2121

2222
// Flat returns the [flattened] ABI representation of [List].
2323
//

wit/list_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package wit
2+
3+
import "testing"
4+
5+
// https://github.com/bytecodealliance/go-modules/issues/288
6+
func TestListAlign(t *testing.T) {
7+
var l List
8+
got, want := l.Align(), uintptr(4)
9+
if got != want {
10+
t.Errorf("ABI alignment for list<T> is %d, expected %d", got, want)
11+
}
12+
}

0 commit comments

Comments
 (0)