Skip to content

Conversation

@ydnar
Copy link
Contributor

@ydnar ydnar commented Oct 5, 2024

Updates to current version of the wasm types proposal at golang/go#66984.

Changes include:

  • Removal of int and uint as allowed types.
  • Restriction of int8, uint8, int16, and uint16 to struct fields, arrays, or pointer values.
  • Requires struct types in wasm params with 1 or more fields to include structs.HostLayout. It enforces this for Go 1.23 or later.
    • TODO: revise this to minimum Go 1.24?

@ydnar ydnar requested review from aykevl and dgryski October 5, 2024 22:13
@ydnar ydnar self-assigned this Oct 5, 2024
@ydnar ydnar changed the base branch from release to dev October 5, 2024 22:14
@ydnar ydnar changed the title compiler: update to latest version of wasm types proposal compiler: conform to latest iteration of wasm types proposal Oct 5, 2024
@ydnar
Copy link
Contributor Author

ydnar commented Oct 7, 2024

@dgryski @aykevl would you prefer I split this into two parts, one that upgrades the wasm-tools-go dependency and regenerates the bindings, and a separate one with the wasm types changes to package compiler?

@deadprogram
Copy link
Member

would you prefer I split this into two parts, one that upgrades the wasm-tools-go dependency and regenerates the bindings, and a separate one with the wasm types changes to package compiler?

I personally would prefer that. 😸

@ydnar
Copy link
Contributor Author

ydnar commented Oct 17, 2024

would you prefer I split this into two parts, one that upgrades the wasm-tools-go dependency and regenerates the bindings, and a separate one with the wasm types changes to package compiler?

I personally would prefer that. 😸

Here you go: #4529

@deadprogram
Copy link
Member

@deadprogram
Copy link
Member

@ydnar note the CI failure...

@ydnar
Copy link
Contributor Author

ydnar commented Oct 17, 2024

What's the minimum version of Go supported by TinyGo?

Looks like this field was added in 1.21: https://pkg.go.dev/go/types#Package.GoVersion

@deadprogram
Copy link
Member

"Officially" should be same as Go itself. But we have been able to keep backwards compat quite a few versions of both Go and LLVM, as shown by the CircleCI tests.

@ydnar
Copy link
Contributor Author

ydnar commented Oct 17, 2024

"Officially" should be same as Go itself. But we have been able to keep backwards compat quite a few versions of both Go and LLVM, as shown by the CircleCI tests.

How does this project define compatibility?

  1. TinyGo can be built with version N of Go?
  2. or TinyGo can be used with version N of Go?

Asking because what % of users build TinyGo from source, and what % of those users are using older versions of Go? Versus what % of end-users of TinyGo who use a binary distribution use older versions of Go?

@aykevl
Copy link
Member

aykevl commented Oct 18, 2024

Usually we keep compatibility as long as it isn't too much of an issue to support. We tend to drop older versions when it's getting annoying to support these older versions. It's always surprising how many people rely on older Go versions but still expect to use a newer TinyGo version.

Also, to be clear: because it makes CI easier "can be built" and "can be used with" is usually the same version. The lower bound is currently LLVM 15 and Go 1.19:

tinygo/.circleci/config.yml

Lines 121 to 123 in ef4f46f

# This tests our lowest supported versions of Go and LLVM, to make sure at
# least the smoke tests still pass.
- test-llvm15-go119

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though please see #4520 because it will conflict.

Comment on lines 469 to 470
if !goenv.WantGoVersion(c.pkg.GoVersion(), 1, 23) {
hasHostLayout = true // package structs does not exist before go1.23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess one way to work around this is to put this in a separate file with build tags. Together with #4501, the compiler won't try to compile projects with a Go version that's newer than the one TinyGo was compiled with (which means that when TinyGo was compiled with Go before 1.23, it will refuse to even compile code that requires Go 1.23+).

It's a bit ugly, but will keep compatibility for a bit longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aykevl thanks! I rebased and my branch now uses Parse. I included the tests for Parse in my PR as well.

@aykevl
Copy link
Member

aykevl commented Oct 18, 2024

I guess we could drop support for Go 1.19 and Go 1.20. That would leave Go 1.21-1.23 supported. I find it difficult to guess how many people would have an issue with this (note that Go 1.19 is the Go version in Debian 12).

ydnar added a commit to ydnar/tinygo that referenced this pull request Oct 18, 2024
@ydnar
Copy link
Contributor Author

ydnar commented Oct 18, 2024

@aykevl I updated this quite a bit. Can you take a look?

@ydnar ydnar requested a review from aykevl October 18, 2024 18:43
@ydnar
Copy link
Contributor Author

ydnar commented Oct 18, 2024

I can split this into two PRs, one for the package goenv changes (Parse and Compare), and a second for the wasm types.

@deadprogram
Copy link
Member

I can split this into two PRs, one for the package goenv changes (Parse and Compare), and a second for the wasm types.

Sorry to be a pain, but I am fairly certain that will make it a lot easier to review. Thank you!

ydnar added a commit to ydnar/tinygo that referenced this pull request Oct 19, 2024
ydnar added a commit to ydnar/tinygo that referenced this pull request Oct 19, 2024
@ydnar
Copy link
Contributor Author

ydnar commented Oct 19, 2024

I can split this into two PRs, one for the package goenv changes (Parse and Compare), and a second for the wasm types.

Sorry to be a pain, but I am fairly certain that will make it a lot easier to review. Thank you!

Done! See #4536.

@deadprogram
Copy link
Member

@ydnar I think this PR can be rebased now, if you please.

ydnar added 4 commits October 21, 2024 07:37
golang/go#66984

- Remove int and uint as allowed types in params, results, pointers, or struct fields
- Only allow small integers in pointers, arrays, or struct fields
golang/go#66984

TODO: regenerate WASI syscall packages for GC shape types including structs.HostLayout

compiler: require go1.23 for structs.HostLayout

compiler: use an interface to check if GoVersion() exists

This permits TinyGo to compile with Go 1.21.

compiler: use goenv.Compare instead of WantGoVersion
compiler/testdata: improve tests for structs.HostLayout
@ydnar
Copy link
Contributor Author

ydnar commented Oct 21, 2024

@deadprogram done!

Copy link
Member

@deadprogram deadprogram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing and my current code still compiles and runs without issue.

LGTM!

Comment on lines +476 to +478
if gv, ok := any(c.pkg).(interface{ GoVersion() string }); ok {
if goenv.Compare(gv.GoVersion(), "go1.23") >= 0 {
hasHostLayout = false // package structs added in go1.23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution, I hadn't thought of that! Much cleaner than using build tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! It's great when the only difference is a new method.

@aykevl
Copy link
Member

aykevl commented Oct 22, 2024

Was this PR also meant to be squashed?

@deadprogram
Copy link
Member

Now merging, thank you @ydnar for working on this and to @aykevl for helping review.

@deadprogram deadprogram merged commit 24c11d4 into tinygo-org:dev Oct 22, 2024
17 checks passed
@ydnar ydnar deleted the ydnar/wasm-types branch October 22, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants