Skip to content

Commit

Permalink
Merge pull request #290 from bytecodealliance/ydnar/issue288
Browse files Browse the repository at this point in the history
wit: fix ABI alignment of list<T> to 4
  • Loading branch information
ydnar authored Jan 29, 2025
2 parents c53528d + 3ce4471 commit f0957de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

- [#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.
- [#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).
- [#288](https://github.com/bytecodealliance/go-modules/issues/288): correctly report the `wasm32` ABI alignment of `list<T>` as 4, rather than 8.

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

Expand Down
7 changes: 4 additions & 3 deletions wit/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,12 @@ func (g *generator) variantRep(file *gen.File, dir wit.Direction, t *wit.TypeDef
}

disc := wit.Discriminant(len(v.Cases))
shape := variantShape(v.Types())
align := variantAlign(v.Types())
types := v.Types()
shape := variantShape(types)
align := variantAlign(types)

var typeShape string
if len(v.Types()) == 1 {
if len(types) == 1 {
typeShape = g.typeRep(file, dir, shape)
} else {
typeShape = g.typeShape(file, dir, shape)
Expand Down
2 changes: 1 addition & 1 deletion wit/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (*List) Size() uintptr { return 8 } // [2]int32
// Align returns the [ABI byte alignment] a [List].
//
// [ABI byte alignment]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#alignment
func (*List) Align() uintptr { return 8 } // [2]int32
func (*List) Align() uintptr { return 4 }

// Flat returns the [flattened] ABI representation of [List].
//
Expand Down
12 changes: 12 additions & 0 deletions wit/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package wit

import "testing"

// https://github.com/bytecodealliance/go-modules/issues/288
func TestListAlign(t *testing.T) {
var l List
got, want := l.Align(), uintptr(4)
if got != want {
t.Errorf("ABI alignment for list<T> is %d, expected %d", got, want)
}
}

0 comments on commit f0957de

Please sign in to comment.