Skip to content
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

doc: mention language downgrading via //go:build #61894

Closed
dominikh opened this issue Aug 9, 2023 · 5 comments
Closed

doc: mention language downgrading via //go:build #61894

dominikh opened this issue Aug 9, 2023 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dominikh
Copy link
Member

dominikh commented Aug 9, 2023

Reading https://go.dev/doc/toolchain, only upgrading the language version on a per-file basis is shown, not downgrading.

It does say that

The language version can be changed on a per-file basis by using a build constraint

but that's a bit implicit, considering this is a major change from how module versions and build constraints used to interact.

https://pkg.go.dev/cmd/go#hdr-Build_constraints doesn't mention the semantics of version build constraints, either.

@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Aug 9, 2023
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 9, 2023
@mknyszek mknyszek added this to the Backlog milestone Aug 9, 2023
@mknyszek
Copy link
Contributor

mknyszek commented Aug 9, 2023

CC @rsc

@oliverpool
Copy link

oliverpool commented Nov 22, 2023

I got bitten by this in #64308 where implementing a polyfill for a previous version of the compiler would not work:

//go:build !go1.21

package main

// min is a pseudo-polyfill for go1.21 min function
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

Currently the doc states:

For example, a module containing code that uses the Go 1.21 language version should have a go.mod file with a go line such as go 1.21 or go 1.21.3. If a specific source file should be compiled only when using a newer Go toolchain, adding //go:build go1.22 to that source file both ensures that only Go 1.22 and newer toolchains will compile the file and also changes the language version in that file to Go 1.22.

It would be helpful to add something like:

For a module to use builtin functions introduced in a later version of Go, use a proxy function with two files implementing it. One with the //go:build go1.22 build constraint which directly calls the builtin, the other with //go:build !go1.22, with a polyfill of the (not-yet available) builtin.

@oliverpool
Copy link

oliverpool commented Nov 22, 2023

the language version declared by the go directive of the go.mod is not used to satisfy build constraints (which are checked against the currently running Go toolchain).

Edit: I just realized that this is only relevant for builtins (since stdlib or syntax changes require 2 mutually excluding Go files)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595475 mentions this issue: cmd/go/internal/help: add documentation for language version downgrading

gopherbot pushed a commit that referenced this issue Jun 27, 2024
This change adds documentation for language version downgrading using
build constraints.

Fixes #68161
For #61894

Change-Id: I283a51afd7020c9fd1f5469a6a93fd814ba32f7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/595475
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Mchnan pushed a commit to Mchnan/go-sylixos that referenced this issue Jul 9, 2024
This change adds documentation for language version downgrading using
build constraints.

Fixes golang#68161
For golang#61894

Change-Id: I283a51afd7020c9fd1f5469a6a93fd814ba32f7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/595475
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@matloob matloob modified the milestones: Go1.23, Go1.24 Jul 30, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/602936 mentions this issue: _content/doc: be more specific about build constraint downgrades

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 6, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Go Compiler / Runtime Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

8 participants