Skip to content

Commit 5db1e99

Browse files
committed
doc/go1.21: document forward and backward compatibility
Also handle go test -c TODO. For #15513. For #56986. For #57001. Change-Id: I571ae25d8d8fcd44cb38ac16cdd2a1180016eb94 Reviewed-on: https://go-review.googlesource.com/c/go/+/500956 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 1b9c721 commit 5db1e99

File tree

1 file changed

+84
-10
lines changed

1 file changed

+84
-10
lines changed

doc/go1.21.html

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ <h2 id="introduction">DRAFT RELEASE NOTES — Introduction to Go 1.21</h2>
2323
</strong>
2424
</p>
2525

26+
<p>
27+
The latest Go release, version 1.21, arrives six months after <a href="/doc/go1.20">Go 1.20</a>.
28+
Most of its changes are in the implementation of the toolchain, runtime, and libraries.
29+
As always, the release maintains the Go 1 <a href="/doc/go1compat">promise of compatibility</a>;
30+
in fact, Go 1.21 <a href="#godebug">improves upon that promise</a>.
31+
We expect almost all Go programs to continue to compile and run as before.
32+
</p>
33+
34+
<p>
35+
Go 1.21 introduces a small change to the numbering of releases.
36+
In the past, we used Go 1.<i>N</i> to refer to both the overall Go language version and release family
37+
as well as the first release in that family.
38+
Starting in Go 1.21, the first release is now Go 1.<i>N</i>.0.
39+
Today we are releasing both the Go 1.21 language and its initial implementation, the Go 1.21.0 release.
40+
These notes refer to “Go 1.21”; tools like <code>go</code> <code>version</code> will report “<code>go1.21.0</code>
41+
(until you upgrade to Go 1.21.1).
42+
See “<a href="/doc/toolchain#versions">Go versions</a>” in the “Go Toolchains” documentation for details
43+
about the new version numbering.
44+
</p>
45+
2646
<h2 id="language">Changes to the language</h2>
2747

2848
<p>
@@ -123,13 +143,9 @@ <h2 id="language">Changes to the language</h2>
123143
Together, all these changes make type inference more powerful and inference failures less surprising.
124144
</p>
125145

126-
<p><!-- https://go.dev/issue/56986 -->
127-
TODO: <a href="https://go.dev/issue/56986">https://go.dev/issue/56986</a>: extended backwards compatibility for Go
128-
</p>
129-
130146
<!-- https://go.dev/issue/57969 -->
131147
<p>
132-
<!-- add GOEXPERIMENT=loopvar -->
148+
<!-- TODO(rsc): add GOEXPERIMENT=loopvar -->
133149
</p>
134150

135151

@@ -138,10 +154,55 @@ <h2 id="language">Changes to the language</h2>
138154
</p>
139155

140156
<h2 id="tools">Tools</h2>
157+
<p>
158+
Go 1.21 adds improved support for backwards compatibility and forwards compatibility
159+
in the Go toolchain.
160+
</p>
161+
162+
<p><!-- https://go.dev/issue/56986 -->
163+
To improve backwards compatibility, Go 1.21 formalizes
164+
Go's use of the GODEBUG environment variable to control
165+
the default behavior for changes that are non-breaking according to the
166+
<a href="/doc/go1compat">compatibility policy</a>
167+
but nonetheless may cause existing programs to break.
168+
(For example, programs that depend on buggy behavior may break
169+
when a bug is fixed, but bug fixes are not considered breaking changes.)
170+
When Go must make this kind of behavior change,
171+
it now chooses between the old and new behavior based on the
172+
<code>go</code> line in the workspace's <code>go.work</code> file
173+
or else the main module's <code>go.mod</code> file.
174+
Upgrading to a new Go toolchain but leaving the <code>go</code> line
175+
set to its original (older) Go version preserves the behavior of the older
176+
toolchain.
177+
With this compatibility support, the latest Go toolchain should always
178+
be the best, most secure, implementation of an older version of Go.
179+
See “<a href="/doc/godebug">Go, Backwards Compatibility, and GODEBUG</a>” for details.
180+
</p>
181+
182+
<p><!-- https://go.dev/issue/57001 -->
183+
To improve forwards compatibility, Go 1.21 now reads the <code>go</code> line
184+
in a <code>go.work</code> or <code>go.mod</code> file as a strict
185+
minimum requirement: <code>go</code> <code>1.21.0</code> means
186+
that the workspace or module cannot be used with Go 1.20 or with Go 1.21rc1.
187+
This allows projects that depend on fixes made in later versions of Go
188+
to ensure that they are not used with earlier versions.
189+
It also gives better error reporting for projects that make use of new Go features:
190+
when the problem is that a newer Go version is needed,
191+
that problem is reported clearly, instead of attempting to build the code
192+
and instead printing errors about unresolved imports or syntax errors.
193+
</p>
141194

142-
<!-- https://go.dev/issue/15513 -->
143195
<p>
144-
<!-- support compiling all tests without running -->
196+
To make these new stricter version requirements easier to manage,
197+
the <code>go</code> command can now invoke not just the toolchain
198+
bundled in its own release but also other Go toolchain versions found in the PATH
199+
or downloaded on demand.
200+
If a <code>go.mod</code> or <code>go.work</code> <code>go</code> line
201+
declares a minimum requirement on a newer version of Go, the <code>go</code>
202+
command will find and run that version automatically.
203+
The new <code>toolchain</code> directive sets a suggested minimum toolchain to use,
204+
which may be newer than the strict <code>go</code> minimum.
205+
See “<a href="/doc/toolchain">Go Toolchains</a>” for details.
145206
</p>
146207

147208
<h3 id="go-command">Go command</h3>
@@ -155,15 +216,28 @@ <h3 id="go-command">Go command</h3>
155216
program.
156217
</p>
157218

219+
<p>
220+
The <code>-C</code> <code>dir</code> flag must now be the first
221+
flag on the command-line when used.
222+
</p>
223+
158224
<p><!-- https://go.dev/issue/37708, CL 463837 -->
159225
The new <code>go</code> <code>test</code> option
160226
<code>-fullpath</code> prints full path names in test log messages,
161227
rather than just base names.
162228
</p>
163229

164-
<!-- CL 466397 -->
165-
<p>
166-
<!-- cmd/go: make go test build multiple executables; The go test command now supports using the -c flag with multiple packages. -->
230+
<p><!-- https://go.dev/issue/15513, CL 466397 -->
231+
The <code>go</code> <code>test</code> <code>-c</code> flag now
232+
supports writing test binaries for multiple packages, each to
233+
<code>pkg.test</code> where <code>pkg</code> is the package name.
234+
It is an error if more than one test package being compiled has a given package name.]
235+
</p>
236+
237+
<p><!-- https://go.dev/issue/15513, CL 466397 -->
238+
The <code>go</code> <code>test</code> <code>-o</code> flag now
239+
accepts a directory argument, in which case test binaries are written to that
240+
directory instead of the current directory.
167241
</p>
168242

169243
<h3 id="cgo">Cgo</h3>

0 commit comments

Comments
 (0)