-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: breaking change in 1.23rc2 with version constraints in GOPATH mode #68658
Comments
CC @griesemer |
I don't see what's wrong here: the file specifies the language version as go1.10 and If the issue exists in a larger code base, please provide a reproducer that accurately reflects the situation. Otherwise, please close this issue, thanks. |
@griesemer False.
I'm going to guess that the playground compiles in "module mode" not "GOPATH mode" and thus is not a valid way to reproduce the issue I described. |
@rittneje I see. If the compiler is invoked without a valid -lang version, or a -lang version before go1.21, than file local versions are ignored and the code is compiled assuming the latest language version, despite the I suspect a change in the way the go command invokes the compiler in GOPATH mode. |
Yes, we changed how the go command invokes the compiler: https://go.dev/cl/593156 changes the go command to always pass in a language version (which in gopath mode it sets to the toolchain version, so as new a version as possible). I think that the behavior of passing in the language version is the correct behavior. I also think that doing the downgrade is the correct behavior. But we can change the way the go command is invoked if it's decided that we don't want to do the downgrade in GOPATH mode (after all in the documentation of the buildconstraint downgrade it's mainly mentioned in the context of modules). |
@matloob I think it would be more helpful if there were a way for us to specify the language version to the compiler in GOPATH mode. For example, right now any GOPATH-mode application compiled under 1.22+ will use the new loop semantics, without any ability to opt out (since they cannot use module directive). |
Perhaps GCFLAGS can be used to set -lang in GOPATH mode. |
@rittneje This is the sort of thing the |
@matloob Yes, but that would mean that a GOPATH-mode repo has to add |
@matloob It seems that with Go 1.22, a GOPATH-mode application will use the 1.22 loop semantics, even though it wasn't supposed to as per #60915. However, now that ship has sailed, and GOPATH-mode applications may well be relying on the 1.22 loop semantics, meaning that restoring 1.21 semantics as originally proposed is itself a breaking change. |
Change https://go.dev/cl/602216 mentions this issue: |
CL 607955 is changing the behavior of "//go:build" file versions. Before, file versions did not apply if go version was set for the package, but after CL 6079055, the package's go version does not influence whether the file version is applied: max(fileVersion, go1.21) will always be applied. Once CL 607955 is released in a go 1.23 minor release, we can update the test to require go1.23 and test for the new behavior (though it would fail for users building with a version of go older than the minor release with the behavior update). For golang/go#68658 Change-Id: I99d39ce108274edf401d861e553ad923b508f936 Reviewed-on: https://go-review.googlesource.com/c/tools/+/608797 Reviewed-by: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
@gopherbot please backport this to 1.23. It's necessary to unbreak GOPATH mode with certain build tags |
Backport issue(s) opened: #69094 (for 1.23). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change the rules for how //go:build "file versions" are applied: instead of considering whether a file version is an upgrade or downgrade from the -lang version, always use max(fileVersion, go1.21). This prevents file versions from downgrading the version below go1.21. Before Go 1.21 the //go:build version did not have the meaning of setting the file's langage version. This fixes an issue that was appearing in GOPATH builds: Go 1.23.0 started providing -lang versions to the compiler in GOPATH mode (among other places) which it wasn't doing before, and it set -lang to the toolchain version (1.23). Because the -lang version was greater than go1.21, language version used to compile the file would be set to the //go:build file version. //go:build file versions below 1.21 could cause files that could previously build to stop building. For example, take a Go file with a //go:build line specifying go1.10. If that file used a 1.18 feature, that use would compile fine with a Go 1.22 toolchain. But it would produce an error when compiling with the 1.23.0 toolchain because it set the language version to 1.10 and disallowed the 1.18 feature. This breaks backwards compatibility: when the build tag was added, it did not have the meaning of restricting the language version. For #68658 Change-Id: I6cedda81a55bcccffaa3501eef9e2be6541b6ece Reviewed-on: https://go-review.googlesource.com/c/go/+/607955 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
Change https://go.dev/cl/608935 mentions this issue: |
…) if fileVersion present Change the rules for how //go:build "file versions" are applied: instead of considering whether a file version is an upgrade or downgrade from the -lang version, always use max(fileVersion, go1.21). This prevents file versions from downgrading the version below go1.21. Before Go 1.21 the //go:build version did not have the meaning of setting the file's langage version. This fixes an issue that was appearing in GOPATH builds: Go 1.23.0 started providing -lang versions to the compiler in GOPATH mode (among other places) which it wasn't doing before, and it set -lang to the toolchain version (1.23). Because the -lang version was greater than go1.21, language version used to compile the file would be set to the //go:build file version. //go:build file versions below 1.21 could cause files that could previously build to stop building. For example, take a Go file with a //go:build line specifying go1.10. If that file used a 1.18 feature, that use would compile fine with a Go 1.22 toolchain. But it would produce an error when compiling with the 1.23.0 toolchain because it set the language version to 1.10 and disallowed the 1.18 feature. This breaks backwards compatibility: when the build tag was added, it did not have the meaning of restricting the language version. For #68658 Fixes #69094 Change-Id: I6cedda81a55bcccffaa3501eef9e2be6541b6ece Reviewed-on: https://go-review.googlesource.com/c/go/+/607955 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> (cherry picked from commit aeac0b6) Reviewed-on: https://go-review.googlesource.com/c/go/+/608935
Change https://go.dev/cl/609415 mentions this issue: |
Change https://go.dev/cl/609416 mentions this issue: |
…03895 The tests disabled in this CL depend on being able to downgrade Go versions to versions earlier than Go 1.21. This behavior will change with CL 603895. Disable these tests for now and re-enable them with fixes in a later CL. For golang/go#68658 Change-Id: I13bdc03117989a128d90195ac90b2905102d293f Reviewed-on: https://go-review.googlesource.com/c/tools/+/604817 Commit-Queue: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tim King <[email protected]> Auto-Submit: Michael Matloob <[email protected]> (cherry picked from commit 7f262d6) Reviewed-on: https://go-review.googlesource.com/c/tools/+/609416 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> TryBot-Bypass: Robert Findley <[email protected]>
…compatible with CL 607955 CL 607955 is changing the behavior of "//go:build" file versions. Before, file versions did not apply if go version was set for the package, but after CL 6079055, the package's go version does not influence whether the file version is applied: max(fileVersion, go1.21) will always be applied. Once CL 607955 is released in a go 1.23 minor release, we can update the test to require go1.23 and test for the new behavior (though it would fail for users building with a version of go older than the minor release with the behavior update). For golang/go#68658 Change-Id: I99d39ce108274edf401d861e553ad923b508f936 Reviewed-on: https://go-review.googlesource.com/c/tools/+/608797 Reviewed-by: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit adb7301) Reviewed-on: https://go-review.googlesource.com/c/tools/+/609415 TryBot-Bypass: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Change https://go.dev/cl/609436 mentions this issue: |
Change https://go.dev/cl/615698 mentions this issue: |
For golang/go#68658 Change-Id: I6e05e21f924cda18e368543e59071b2c79c16ef2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/615698 Commit-Queue: Tim King <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Change https://go.dev/cl/615685 mentions this issue: |
@gopherbot please backport this to 1.22. It's necessary to have consistent file versions with build tags with later versions. |
@timothy-king You're running into friction issue #25574 – there was already a backport request in #68658 (comment). As a workaround, you can create the 1.22 backport issue manually. |
Change https://go.dev/cl/617495 mentions this issue: |
Enable units tests after 1.23. Tests were rewritten for the changes to the 1.21 file version event horizon. The test is not enabled for 1.22. A backport for golang/go#68658 may be required. For golang/go#68658 Change-Id: I15f46e3ff3de7c02592d5a357ae199116323c29f Reviewed-on: https://go-review.googlesource.com/c/tools/+/615685 Reviewed-by: Alan Donovan <[email protected]> Commit-Queue: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
The decision for the backport for 1.22 can be done on #69749. Closing this issue which is about 1.23 and 1.24. |
Go version
go version go1.23rc2 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
As a minimal reproduction, we have a repository in GOPATH-mode, organized like so:
main.go is defined as follows:
What did you see happen?
Compiling with 1.23rc2 fails:
What did you expect to see?
It should still work, like it does in 1.22.
(Please note the above is just a minimal reproduction. In reality, the offending
go:build
directive is in a vendored dependency.)The text was updated successfully, but these errors were encountered: