From e29efea3007a8b5cdb92713bf394829586e2db6a Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Wed, 29 Jan 2025 15:54:25 -0500 Subject: [PATCH 1/3] wit: change the ABI alignment of list from 8 to 4 Fixes #288. --- wit/list.go | 2 +- wit/list_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 wit/list_test.go diff --git a/wit/list.go b/wit/list.go index b9cbdc74..f7e26832 100644 --- a/wit/list.go +++ b/wit/list.go @@ -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]. // diff --git a/wit/list_test.go b/wit/list_test.go new file mode 100644 index 00000000..9d3a2492 --- /dev/null +++ b/wit/list_test.go @@ -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 is %d, expected %d", got, want) + } +} From 9fbbfdc86433d4f215bf03ea9e9d4d35167c6bfb Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Wed, 29 Jan 2025 15:54:44 -0500 Subject: [PATCH 2/3] wit/bindgen: call v.Types() once --- wit/bindgen/generator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wit/bindgen/generator.go b/wit/bindgen/generator.go index 4ad188a9..6036eac3 100644 --- a/wit/bindgen/generator.go +++ b/wit/bindgen/generator.go @@ -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) From 3ce4471841edb06987fa08b7a935d308c35b67b4 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Wed, 29 Jan 2025 15:56:35 -0500 Subject: [PATCH 3/3] CHANGELOG: add note about #288 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99ed9194..e84346f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` as 4, rather than 8. ## [v0.5.0] — 2024-12-14