]> Cypherpunks.ru repositories - gostls13.git/blob - doc/go1.21.html
0f13f04b6ff7f17c6a8b0672201bba8fbcb9f666
[gostls13.git] / doc / go1.21.html
1 <!--{
2         "Title": "Go 1.21 Release Notes",
3         "Path":  "/doc/go1.21"
4 }-->
5
6 <!--
7 NOTE: In this document and others in this directory, the convention is to
8 set fixed-width phrases with non-fixed-width spaces, as in
9 <code>hello</code> <code>world</code>.
10 Do not send CLs removing the interior tags from such phrases.
11 -->
12
13 <style>
14   main ul li { margin: 0.5em 0; }
15 </style>
16
17 <h2 id="introduction">DRAFT RELEASE NOTES — Introduction to Go 1.21</h2>
18
19 <p>
20   <strong>
21     Go 1.21 is not yet released. These are work-in-progress
22     release notes. Go 1.21 is expected to be released in August 2023.
23   </strong>
24 </p>
25
26 <h2 id="language">Changes to the language</h2>
27
28 <p>
29   Go 1.21 adds three new built-ins to the language.
30
31   <ul>
32     <li><!-- https://go.dev/issue/59488 -->
33       The new functions <code>min</code> and <code>max</code> compute the
34       smallest (or largest, for <code>max</code>) value of a fixed number
35       of given arguments.
36       See the language spec for
37       <a href="https://tip.golang.org/ref/spec#Min_and_max">details</a>.
38     </li>
39     <li><!-- https://go.dev/issue/56351 -->
40       The new function <code>clear</code> deletes all elements from a
41       map or zeroes all elements of a slice.
42       See the language spec for
43       <a href="https://tip.golang.org/ref/spec#Clear">details</a>.
44     </li>
45   </ul>
46 </p>
47
48 <p><!-- https://go.dev/issue/57411 -->
49   Package initialization order is now specified more precisely. The
50   new algorithm is:
51   <ul>
52     <li>
53       Sort all packages by import path.
54     </li>
55     <li>Repeat until the list of packages is empty:
56       <ul>
57         <li>
58           Find the first package in the list for which all imports are
59           already initialized.
60         </li>
61         <li>
62           Initialize that package and remove it from the list.
63         </li>
64       </ul>
65     </li>
66   </ul>
67   This may change the behavior of some programs that rely on a
68   specific initialization ordering that was not expressed by explicit
69   imports. The behavior of such programs was not well defined by the
70   spec in past releases. The new rule provides an unambiguous definition.
71 </p>
72
73 <p>
74   Multiple improvements that increase the power and precision of type inference have been made.
75 </p>
76 <ul>
77   <li><!-- https://go.dev/issue/59338 -->
78     A (possibly partially instantiated generic) function may now be called with arguments that are
79     themselves (possibly partially instantiated) generic functions.
80     The compiler will attempt to infer the missing type arguments of the callee (as before) and,
81     for each argument that is a generic function that is not fully instantiated,
82     its missing type arguments (new).
83     Typical use cases are calls to generic functions operating on containers
84     (such as <a href="/pkg/slices#IndexFunc">slices.IndexFunc</a>) where a function argument
85     may also be generic, and where the type argument of the called function and its arguments
86     are inferred from the container type.
87     More generally, a generic function may now be used without explicit instantiation when
88     it is assigned to a variable or returned as a result value if the type arguments can
89     be inferred from the assignment.
90   </li>
91   <li><!-- https://go.dev/issue/60353, https://go.dev/issue/57192, https://go.dev/issue/52397, https://go.dev/issue/41176 -->
92     Type inference now also considers methods when a value is assigned to an interface:
93     type arguments for type parameters used in method signatures may be inferred from
94     the corresponding parameter types of matching methods.
95   </li>
96   <li><!-- https://go.dev/issue/51593 https://go.dev/issue/39661 -->
97     Similarly, since a type argument must implement all the methods of its corresponding constraint,
98     the methods of the type argument and constraint are matched which may lead to the inference of
99     additional type arguments.
100   </li>
101   <li><!-- https://go.dev/issue/58671 -->
102     If multiple untyped constant arguments of different kinds (such as an untyped int and
103     an untyped floating-point constant) are passed to parameters with the same (not otherwise
104     specified) type parameter type, instead of an error, now type inference determines the
105     type using the same approach as an operator with untyped constant operands.
106     This change brings the types inferred from untyped constant arguments in line with the
107     types of constant expressions.
108   </li>
109   <li><!-- https://go.dev/issue/59750 -->
110     Type inference is now precise when matching corresponding types in assignments:
111     component types (such as the the elements of slices, or the parameter types in function signatures)
112     must be identical (given suitable type arguments) to match, otherwise inference fails.
113     This change produces more accurate error messages:
114     where in the past type inference may have succeeded incorrectly and lead to an invalid assignment,
115     the compiler now reports an inference error if two types can't possibly match.
116   </li>
117 </ul>
118
119 <p><!-- https://go.dev/issue/58650 -->
120   More generally, the description of
121   <a href="https://tip.golang.org/ref/spec#Type_inference">type inference</a>
122   in the language spec has been clarified.
123   Together, all these changes make type inference more powerful and inference failures less surprising.
124 </p>
125
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
130 <!-- https://go.dev/issue/57969 -->
131 <p>
132   <!-- add GOEXPERIMENT=loopvar -->
133 </p>
134
135
136 <p>
137   TODO: complete this section
138 </p>
139
140 <h2 id="ports">Ports</h2>
141
142 <!-- CL 470695 -->
143 <p>
144   <!-- cmd/dist: default to GOARM=7 on all non-arm systems -->
145 </p>
146
147 <!-- https://go.dev/issue/38248 -->
148 <p>
149   <!-- replace CallImport with go:wasmimport directive -->
150 </p>
151
152 <h3 id="wasm">WebAssembly</h3>
153
154 <!-- https://go.dev/issue/59149 -->
155 <p>
156   <!-- allow the use of go:wasmimport globally -->
157 </p>
158
159 <!-- CL 489255 -->
160 <p>
161   <!-- cmd/compile: remove go:wasmimport restriction -->
162 </p>
163
164 <!-- https://go.dev/issue/56100 -->
165 <p>
166   The Go scheduler now interacts much more efficiently with the
167   JavaScript event loop, especially in applications that block
168   frequently on asynchronous events.
169 </p>
170
171
172 <h3 id="wasip1">WebAssembly System Interface</h3>
173
174 <p><!-- https://go.dev/issue/58141 -->
175   Go 1.21 adds an experimental port to the <a href="https://wasi.dev/">
176   WebAssembly System Interface (WASI)</a>, Preview 1
177   (<code>GOOS=wasip1</code>, <code>GOARCH=wasm</code>).
178 </p>
179
180 <p>
181   As a result of the addition of the new <code>GOOS</code> value
182   "<code>wasip1</code>", Go files named <code>*_wasip1.go</code>
183   will now be <a href="/pkg/go/build/#hdr-Build_Constraints">ignored
184   by Go tools</a> except when that <code>GOOS</code> value is being
185   used.
186   If you have existing filenames matching that pattern, you will
187   need to rename them.
188 </p>
189
190 <h2 id="tools">Tools</h2>
191
192 <!-- https://go.dev/issue/15513 -->
193 <p>
194   <!-- support compiling all tests without running -->
195 </p>
196
197 <h3 id="go-command">Go command</h3>
198
199 <p><!-- https://go.dev/issue/58099, CL 474236 -->
200   The <code>-pgo</code> build flag now defaults to <code>-pgo=auto</code>,
201   and the restriction of specifying a single main package on the command
202   line is now removed. If a file named <code>default.pgo</code> is present
203   in the main package's directory, the <code>go</code> command will use
204   it to enable profile-guided optimization for building the corresponding
205   program.
206 </p>
207
208 <p><!-- https://go.dev/issue/37708, CL 463837 -->
209   The new <code>go</code> <code>test</code> option
210   <code>-fullpath</code> prints full path names in test log messages,
211   rather than just base names.
212 </p>
213
214 <!-- CL 466397 -->
215 <p>
216   <!-- cmd/go: make go test build multiple executables; The go test command now supports using the -c flag with multiple packages. -->
217 </p>
218
219 <h2 id="runtime-changes">Runtime</h2>
220
221 <p>
222   TODO: complete this section, or delete if not needed
223 </p>
224
225 <p><!-- https://go.dev/issue/7181 -->
226   When printing very deep stacks, the runtime now prints the first 50
227   (innermost) frames followed by the bottom 50 (outermost) frames,
228   rather than just printing the first 100 frames. This makes it easier
229   to see how deeply recursive stacks started, and is especially
230   valuable for debugging stack overflows.
231 </p>
232
233 <p><!-- https://go.dev/issue/59960 -->
234   On Linux platforms that support transparent huge pages, the Go runtime
235   now manages which parts of the heap may be backed by huge pages more
236   explicitly. This leads to better utilization of memory: small heaps
237   should see less memory used (up to 50% in pathological cases) while
238   large heaps should see fewer broken huge pages for dense parts of the
239   heap, improving CPU usage and latency by up to 1%.
240 </p>
241
242 <p><!-- https://go.dev/issue/57069, https://go.dev/issue/56966 -->
243   As a result of runtime-internal garbage collection tuning,
244   applications may see up to a 40% reduction in application tail latency
245   and a small decrease in memory use. Some applications may also observe
246   a small loss in throughput.
247
248   The memory use decrease should be proportional to the loss in
249   throughput, such that the previous release's throughput/memory
250   tradeoff may be recovered (with little change to latency) by
251   increasing <code>GOGC</code> and/or <code>GOMEMLIMIT</code> slightly.
252 </p>
253
254 <p><!-- https://go.dev/issue/51676 -->
255   Calls from C to Go on threads created in C require some setup to prepare for
256   Go execution. On Unix platforms, this setup is now preserved across multiple
257   calls from the same thread. This significantly reduces the overhead of
258   subsequent C to Go calls from ~1-3 microseconds per call to ~100-200
259   nanoseconds per call.
260 </p>
261
262 <h2 id="compiler">Compiler</h2>
263
264 <!-- CL 490819 -->
265 <p>
266   <!-- cmd/cgo: reject attempts to declare methods on C types -->
267 </p>
268
269 <!-- CL 461315 -->
270 <p>
271   <!-- cmd/compile: enable deadcode of unreferenced large global maps -->
272 </p>
273
274 <p>
275   TODO: complete this section, or delete if not needed
276 </p>
277
278 <h2 id="assembler">Assembler</h2>
279
280 <!-- CL 476295 -->
281 <p>
282   The verifier that checks for incorrect uses of <code>R15</code> when dynamic linking on amd64 has been improved.
283 </p>
284
285 <h2 id="linker">Linker</h2>
286
287 <p><!-- https://go.dev/issue/57302, CL 461749 -->
288   On Windows AMD64, the linker (with help from the compiler) now emits
289   SEH unwinding data by default, which improves the integration
290   of Go applications with Windows debuggers and other tools.
291 </p>
292
293 <!-- CL 457455 -->
294 <p>
295   <!-- cmd/link: generate .xdata PE section -->
296 </p>
297 <!-- CL 463395 -->
298 <p>
299   In Go 1.21 the linker (with help from the compiler) is now capable of
300   deleting dead (unreferenced) global map variables, if the number of
301   entries in the variable initializer is sufficiently large, and if the
302   initializer expressions are side-effect free.
303 </p>
304 <p>
305   TODO: complete this section, or delete if not needed
306 </p>
307
308 <h2 id="library">Core library</h2>
309
310 <h3 id="slog">New log/slog package</h3>
311
312 <p><!-- https://go.dev/issue/59060, https://go.dev/issue/59141, https://go.dev/issue/59204, https://go.dev/issue/59280,
313         https://go.dev/issue/59282, https://go.dev/issue/59339, https://go.dev/issue/59345,
314         CL 477295, CL 484096, CL 486376, CL 486415, CL 487855 -->
315   The new <a href="/pkg/log/slog">log/slog</a> package provides structured logging with levels.
316   Structured logging emits key-value pairs
317   to enable fast, accurate processing of large amounts of log data.
318   The package supports integration with popular log analysis tools and services.
319 </p>
320
321 <h3 id="slogtest">New testing/slogtest package</h3>
322
323 <p><!-- CL 487895 -->
324   The new <a href="/pkg/testing/slogtest">testing/slogtest</a> package can help
325   to validate <a href="/pkg/log/slog#Handler">slog.Handler<a/> implementations.
326 </p>
327
328 <h3 id="slices">New slices package</h3>
329
330 <p><!-- https://go.dev/issue/45955, https://go.dev/issue/54768, https://go.dev/issue/57348, https://go.dev/issue/57433, CL 467417, CL 483175 -->
331   The new <a href="/pkg/slices">slices</a> package provides many common
332   operations on slices, using generic functions that work with slices
333   of any element type.
334 </p>
335
336 <h3 id="maps">New maps package</h3>
337
338 <p><!-- https://go.dev/issue/57436, CL 464343 -->
339   The new <a href="/pkg/maps/">maps</a> package provides several
340   common operations on maps, using generic functions that work with
341   maps of any key or element type.
342 </p>
343
344 <h3 id="minor_library_changes">Minor changes to the library</h3>
345
346 <p>
347   As always, there are various minor changes and updates to the library,
348   made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a>
349   in mind.
350   There are also various performance improvements, not enumerated here.
351 </p>
352
353 <p>
354   TODO: complete this section
355 </p>
356
357 <dl id="archive/tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt>
358   <dd>
359     <p><!-- https://go.dev/issue/54451, CL 491175 -->
360       The implementation of the
361       <a href="/pkg/io/fs/#FileInfo"><code>io/fs.FileInfo</code></a>
362       interface returned by
363       <a href="/pkg/archive/tar/#Header.FileInfo"><code>Header.FileInfo</code></a>
364       now implements a <code>String</code> method that calls
365       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
366     </p>
367   </dd>
368 </dl><!-- archive/tar -->
369
370 <dl id="archive/zip"><dt><a href="/pkg/archive/zip/">archive/zip</a></dt>
371   <dd>
372     <p><!-- https://go.dev/issue/54451, CL 491175 -->
373       The implementation of the
374       <a href="/pkg/io/fs/#FileInfo"><code>io/fs.FileInfo</code></a>
375       interface returned by
376       <a href="/pkg/archive/zip/#FileHeader.FileInfo"><code>FileHeader.FileInfo</code></a>
377       now implements a <code>String</code> method that calls
378       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
379     </p>
380
381     <p><!-- https://go.dev/issue/54451, CL 491175 -->
382       The implementation of the
383       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
384       interface returned by the
385       <a href="/pkg/io/fs/#ReadDirFile.ReadDir"><code>io/fs.ReadDirFile.ReadDir</code></a>
386       method of the
387       <a href="/pkg/io/fs/#File"><code>io/fs.File</code></a>
388       returned by
389       <a href="/pkg/archive/zip/#Reader.Open"><code>Reader.Open</code></a>
390       now implements a <code>String</code> method that calls
391       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
392     </p>
393   </dd>
394 </dl><!-- archive/zip -->
395
396 <dl id="bytes"><dt><a href="/pkg/bytes/">bytes</a></dt>
397   <dd>
398     <p><!-- https://go.dev/issue/53685, CL 474635 -->
399       The <a href="/pkg/bytes/#Buffer"><code>Buffer</code></a> type
400       has two new methods:
401       <a href="/pkg/bytes/#Buffer.Available"><code>Available</code></a>
402       and <a href="/pkg/bytes/#AvailableBuffer"><code>AvailableBuffer</code></a>.
403       These may be used along with the
404       <a href="/pkg/bytes/#Buffer.Write"><code>Write</code></a>
405       method to append directly to the <code>Buffer</code>.
406     </p>
407   </dd>
408 </dl><!-- bytes -->
409
410 <dl id="context"><dt><a href="/pkg/context/">context</a></dt>
411   <dd>
412     <p><!-- https://go.dev/issue/40221, CL 479918 -->
413       The new <a href="/pkg/context/#WithoutCancel"><code>WithoutCancel</code></a>
414       function returns a copy of a context that is not canceled when the original
415       context is canceled.
416     </p>
417     <p><!-- https://go.dev/issue/56661, CL 449318 -->
418       The new <a href="/pkg/context/#WithDeadlineCause"><code>WithDeadlineCause</code></a>
419       and <a href="/pkg/context/#WithTimeoutCause"><code>WithTimeoutCause</code></a>
420       functions provide a way to set a context cancellation cause when a deadline or
421       timer expires. The cause may be retrieved with the
422       <a href="/pkg/context/#Cause"><code>Cause</code></a> function.
423     </p>
424     <p><!-- https://go.dev/issue/57928, CL 482695 -->
425       The new <a href="/pkg/context/#AfterFunc"><code>AfterFunc</code></a>
426       function registers a function to run after a context has been cancelled.
427     </p>
428   </dd>
429 </dl>
430
431 <dl id="crypto/elliptic"><dt><a href="/pkg/crypto/elliptic/">crypto/elliptic</a></dt>
432   <dd>
433     <p><!-- CL 459977 -->
434       TODO: <a href="https://go.dev/cl/459977">https://go.dev/cl/459977</a>: crypto/elliptic: deprecate unsafe APIs; modified api/next/34648.txt, api/next/52221.txt
435     </p>
436   </dd>
437 </dl><!-- crypto/elliptic -->
438
439 <dl id="crypto/rsa"><dt><a href="/pkg/crypto/rsa/">crypto/rsa</a></dt>
440   <dd>
441     <p><!-- https://go.dev/issue/56921 -->
442       TODO: <a href="https://go.dev/issue/56921">https://go.dev/issue/56921</a>: deprecate GenerateMultiPrimeKey and PrecomputedValues.CRTValues
443     </p>
444
445     <p><!-- CL 459976 -->
446       TODO: <a href="https://go.dev/cl/459976">https://go.dev/cl/459976</a>: crypto/rsa: deprecate multiprime RSA support; modified api/next/56921.txt
447     </p>
448   </dd>
449 </dl><!-- crypto/rsa -->
450
451 <dl id="crypto/sha1"><dt><a href="/pkg/crypto/sha1/">crypto/sha1</a></dt>
452   <dd>
453     <p><!-- CL 483815 -->
454       TODO: <a href="https://go.dev/cl/483815">https://go.dev/cl/483815</a>: crypto/sha1: add WriteString and WriteByte method
455     </p>
456   </dd>
457 </dl><!-- crypto/sha1 -->
458
459 <dl id="crypto/sha256"><dt><a href="/pkg/crypto/sha256/">crypto/sha256</a></dt>
460   <dd>
461     <p><!-- https://go.dev/issue/50543 -->
462       TODO: <a href="https://go.dev/issue/50543">https://go.dev/issue/50543</a>: add native SHA256 instruction implementation for AMD64
463     </p>
464
465     <p><!-- CL 408795 -->
466       TODO: <a href="https://go.dev/cl/408795">https://go.dev/cl/408795</a>: crypto/sha256: add sha-ni implementation; crypto/sha256 uses Intel SHA extensions on new enough x86 processors, making it 3-4X faster.
467     </p>
468
469     <p><!-- CL 481478 -->
470       TODO: <a href="https://go.dev/cl/481478">https://go.dev/cl/481478</a>: crypto/sha256: add WriteString and WriteByte method
471     </p>
472   </dd>
473 </dl><!-- crypto/sha256 -->
474
475 <dl id="crypto/sha512"><dt><a href="/pkg/crypto/sha512/">crypto/sha512</a></dt>
476   <dd>
477     <p><!-- CL 483816 -->
478       TODO: <a href="https://go.dev/cl/483816">https://go.dev/cl/483816</a>: crypto/sha512: add WriteString and WriteByte method
479     </p>
480   </dd>
481 </dl><!-- crypto/sha512 -->
482
483 <dl id="crypto/x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
484   <dd>
485     <p><!-- https://go.dev/issue/53573 -->
486       TODO: <a href="https://go.dev/issue/53573">https://go.dev/issue/53573</a>: surface ReasonCode inside x509.RevocationList entries
487     </p>
488
489     <p><!-- CL 468875 -->
490       TODO: <a href="https://go.dev/cl/468875">https://go.dev/cl/468875</a>: crypto/x509: surface ReasonCode in RevocationList API; modified api/next/53573.txt
491     </p>
492   </dd>
493 </dl><!-- crypto/x509 -->
494
495 <dl id="debug/elf"><dt><a href="/pkg/debug/elf/">debug/elf</a></dt>
496   <dd>
497     <p><!-- https://go.dev/issue/56892, CL 452617 -->
498       The new
499       <a href="https:/pkg/debug/elf/#File.DynValue"><code>File.DynValue</code></a>
500       method may be used to retrieve the numeric values listed with a
501       given dynamic tag.
502     </p>
503
504     <p><!-- https://go.dev/issue/56887, CL 452496 -->
505       The constant flags permitted in a <code>DT_FLAGS_1</code>
506       dynamic tag are now defined with type
507       <a href="/pkg/debug/elf/#DynFlag1"><code>DynFlag1</code></a>. These
508       tags have names starting with <code>DF_1</code>.
509     </p>
510
511     <p><!-- CL 473256 -->
512       The package now defines the constant
513       <a href="/pkg/debug/elf/#COMPRESS_ZSTD"><code>COMPRESS_ZSTD</code></a>.
514     </p>
515   </dd>
516 </dl><!-- debug/elf -->
517
518 <dl id="debug/pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt>
519   <dd>
520     <p><!-- CL 488475 -->
521       Attempts to read from a section containing uninitialized data
522       using
523       <a href="/pkg/debug/pe/#Section.Data"><code>Section.Data</code></a>
524       or the reader returned by <a href="/pkg/debug/pe/#Section.Open"><code>Section.Open</code></a>
525       now return an error.
526     </p>
527   </dd>
528 </dl><!-- debug/pe -->
529
530 <dl id="embed"><dt><a href="/pkg/embed/">embed</a></dt>
531   <dd>
532     <p><!-- https://go.dev/issue/57803, CL 483235 -->
533       The <a href="/pkg/io/fs/#File"><code>io/fs.File</code></a>
534       returned by
535       <a href="/pkg/embed/#FS.Open"><code>FS.Open</code></a> now
536       has a <code>ReadAt</code> method that
537       implements <a href="/pkg/io/#ReaderAt"><code>io.ReaderAt</code></a>.
538     </p>
539
540     <p><!-- https://go.dev/issue/54451, CL 491175 -->
541       Calling <code><a href="/pkg/embed/FS.Open">FS.Open</a>.<a href="/pkg/io/fs/#File.Stat">Stat</a></code>
542       will return a type that now implements a <code>String</code>
543       method that calls
544       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
545     </p>
546   </dd>
547 </dl><!-- embed -->
548
549 <dl id="errors"><dt><a href="/pkg/errors/">errors</a></dt>
550   <dd>
551     <p><!-- https://go.dev/issue/41198, CL 473935 -->
552       The new
553       <a href="/pkg/errors/#ErrUnsupported"><code>ErrUnsupported</code></a>
554       error provides a standardized way to indicate that a requested
555       operation may not be performed because it is unsupported.
556       For example, a call to
557       <a href="/pkg/os/#Link"><code>os.Link</code></a> when using a
558       file system that does not support hard links.
559     </p>
560   </dd>
561 </dl><!-- errors -->
562
563 <dl id="flag"><dt><a href="/pkg/flag/">flag</a></dt>
564   <dd>
565     <p><!-- https://go.dev/issue/53747, CL 476015 -->
566       The new <a href="/pkg/flag/#BoolFunc"><code>BoolFunc</code></a>
567       function and
568       <a href="/pkg/flag/#FlagSet.BoolFunc"><code>FlagSet.BoolFunc</code></a>
569       method define a flag that does not require an argument and calls
570       a function when the flag is used. This is similar to
571       <a href="/pkg/flag/#Func"><code>Func</code></a> but for a
572       boolean flag.
573     </p>
574
575     <p><!-- CL 480215 -->
576       A flag definition (via <code>Bool</code>, <code>BoolVar</code>, <code>Int</code>, <code>IntVar</code>, etc.) will panic if <code>Set</code> has already been called on a flag with the same name.
577       <p>
578       This change is intended to detect cases where <a href="#language">changes in initialization order</a> cause flag operations to occur in a different order than expected. In many cases the fix to this problem is to introduce a explicit package dependence to correctly order the definition before any <code>Set</code> operations.
579     </p>
580   </dd>
581 </dl><!-- flag -->
582
583 <dl id="go/ast"><dt><a href="/pkg/go/ast/">go/ast</a></dt>
584   <dd>
585     <p><!-- https://go.dev/issue/28089, CL 487935 -->
586       The new <a href="/pkg/go/ast/#IsGenerated"><code>IsGenerated</code></a> predicate
587       reports whether a file syntax tree contains the
588       <a href="https://go.dev/s/generatedcode">special comment</a>
589       that conventionally indicates that the file was generated by a tool.
590     </p>
591   </dd>
592
593   <dd>
594     <p><!-- https://go.dev/issue/59033, CL 476276 -->
595       The new
596       <a href="/pkg/go/ast/#File.GoVersion"><code>File.GoVersion</code></a>
597       field records the minimum Go version required by
598       any <code>//go:build</code> or <code>// +build</code>
599       directives.
600     </p>
601   </dd>
602 </dl><!-- go/ast -->
603
604 <dl id="go/build"><dt><a href="/pkg/go/build/">go/build</a></dt>
605   <dd>
606     <p><!-- https://go.dev/issue/56986, CL 453603 -->
607       The package now parses build directives (comments that start
608       with <code>//go:</code>) in file headers (before
609       the <code>package</code> declaration). These directives are
610       available in the new
611       <a href="/pkg/go/build/Package"><code>Package</code></a> fields
612       <a href="/pkg/go/build/Package.Directives"><code>Directives</code></a>,
613       <a href="/pkg/go/build/Package.TestDirectives"><code>TestDirectives</code></a>,
614       and
615       <a href="/pkg/go/build/Package.XTestDirectives"><code>XTestDirectives</code></a>.
616     </p>
617   </dd>
618 </dl><!-- go/build -->
619
620 <dl id="go/build/constraint"><dt><a href="/pkg/go/build/constraint/">go/build/constraint</a></dt>
621   <dd>
622     <p><!-- https://go.dev/issue/59033, CL 476275 -->
623       The new
624       <a href="/pkg/go/build/constraint/#GoVersion"><code>GoVersion</code></a>
625       function returns the minimum Go version implied by a build
626       expression.
627     </p>
628   </dd>
629 </dl><!-- go/build/constraint -->
630
631 <dl id="go/token"><dt><a href="/pkg/go/token/">go/token</a></dt>
632   <dd>
633     <p><!-- https://go.dev/issue/57708, CL 464515 -->
634       The new <a href="/pkg/go/token/#File.Lines"><code>File.Lines</code></a> method
635       returns the file's line-number table in the same form as accepted by
636       <code>File.SetLines</code>.
637     </p>
638   </dd>
639 </dl><!-- go/token -->
640
641 <dl id="hash/maphash"><dt><a href="/pkg/hash/maphash/">hash/maphash</a></dt>
642   <dd>
643     <p><!-- https://go.dev/issue/47342, CL 468795 -->
644       The <code>hash/maphash</code> package now has a pure Go implementation, selectable with the <code>purego</code> build tag.
645     </p>
646   </dd>
647 </dl><!-- hash/maphash -->
648
649 <dl id="io/fs"><dt><a href="/pkg/io/fs/">io/fs</a></dt>
650   <dd>
651     <p><!-- https://go.dev/issue/54451, CL 489555 -->
652       The new
653       <a href="/pkg/io/fs/#FormatFileInfo"><code>FormatFileInfo</code></a>
654       function returns a formatted version of a
655       <a href="/pkg/io/fs/#FileInfo"><code>FileInfo</code></a>.
656       The new
657       <a href="/pkg/io/fs/#FormatDirEntry"><code>FormatDirEntry</code></a>
658       function returns a formatted version of a
659       <a href="/pkg/io/fs/#FileInfo"><code>DirEntry</code></a>.
660       The implementation of
661       <a href="/pkg/io/fs/#DirEntry"><code>DirEntry</code></a>
662       returned by
663       <a href="/pkg/io/fs/#ReadDir"><code>ReadDir</code></a> now
664       implements a <code>String</code> method that calls
665       <a href="/pkg/io/fs/#FormatDirEntry"><code>FormatDirEntry</code></a>,
666       and the same is true for
667       the <a href="/pkg/io/fs/#DirEntry"><code>DirEntry</code></a>
668       value passed to
669       <a href="/pkg/io/fs/#WalkDirFunc"><code>WalkDirFunc</code></a>.
670     </p>
671   </dd>
672 </dl><!-- io/fs -->
673
674 <dl id="math"><dt><a href="/pkg/math/">math</a></dt>
675   <dd>
676     <p><!-- https://go.dev/issue/56491 -->
677       TODO: <a href="https://go.dev/issue/56491">https://go.dev/issue/56491</a>: add Compare and Compare32
678     </p>
679
680     <p><!-- CL 459435 -->
681       TODO: <a href="https://go.dev/cl/459435">https://go.dev/cl/459435</a>: math: add Compare and Compare32; modified api/next/56491.txt
682     </p>
683
684     <p><!-- CL 467515 -->
685       TODO: <a href="https://go.dev/cl/467515">https://go.dev/cl/467515</a>: math: add Compare and Compare32; modified api/next/56491.txt
686     </p>
687   </dd>
688 </dl><!-- math -->
689
690 <dl id="math/big"><dt><a href="/pkg/math/big/">math/big</a></dt>
691   <dd>
692     <p><!-- https://go.dev/issue/56984, CL 453115 -->
693       The new <a href="/pkg/math/big/#Int.ToFloat64"><code>Int.ToFloat64</code></a>
694       method returns the nearest floating-point value to a
695       multi-precision integer, along with an indication of any
696       rounding that occurred.
697     </p>
698   </dd>
699 </dl><!-- math/big -->
700
701 <dl id="net"><dt><a href="/pkg/net/">net</a></dt>
702   <dd>
703     <p>
704       <!-- https://go.dev/issue/59166, https://go.dev/issue/56539 -->
705       <!-- CL 471136, CL 471137, CL 471140 -->
706       On Linux, the <a href="/pkg/net/">net</a> package can now use
707       Multipath TCP when the kernel supports it. It is not used by
708       default. To use Multipath TCP when available on a client, call
709       the
710       <a href="/pkg/net/#Dialer.SetMultipathTCP"><code>Dialer.SetMultipathTCP</code></a>
711       method before calling the
712       <a href="/pkg/net/#Dialer.Dial"><code>Dialer.Dial</code></a> or
713       <a href="/pkg/net/#Dialer.DialContext"><code>Dialer.DialContext</code></a>
714       methods. To use Multipath TCP when available on a server, call
715       the
716       <a href="/pkg/net/#ListenConfig.SetMultipathTCP"><code>ListenConfig.SetMultipathTCP</code></a>
717       method before calling the
718       <a href="/pkg/net/#ListenConfig.Listen"><code>ListenConfig.Listen</code></a>
719       method. Specify the network as <code>"tcp"</code> or
720       <code>"tcp4"</code> or <code>"tcp6"</code> as usual. If
721       Multipath TCP is not supported by the kernel or the remote host,
722       the connection will silently fall back to TCP. To test whether a
723       particular connection is using Multipath TCP, use the
724       <a href="/pkg/net/#TCPConn.MultipathTCP"><code>TCPConn.MultipathTCP</code></a>
725       method.
726     </p>
727     <p>
728       In a future Go release we may enable Multipath TCP by default on
729       systems that support it.
730     </p>
731   </dd>
732 </dl><!-- net -->
733
734 <dl id="net/http"><dt><a href="/pkg/net/http/">net/http</a></dt>
735   <dd>
736     <p><!-- https://go.dev/issue/44855, CL 382117 -->
737       The new <a href="/pkg/net/http/#ErrSchemeMismatch"><code>ErrSchemeMismatch</code></a> error is returned by <a href="/pkg/net/http/#Client"><code>Client</code></a> and <a href="/pkg/net/http/#Transport"><code>Transport</code></a> when the server responds to an HTTPS request with an HTTP response.
738     </p>
739
740     <p><!-- CL 472636 -->
741       TODO: <a href="https://go.dev/cl/472636">https://go.dev/cl/472636</a>: net/http: support full-duplex HTTP/1 responses; modified api/next/57786.txt
742     </p>
743
744     <p><!-- CL 494122 -->
745       The <a href="/pkg/net/http/">net/http</a> package now supports
746       <a href="/pkg/errors/#ErrUnsupported"><code>errors.ErrUnsupported</code></a>,
747       in that the expression
748       <code>errors.Is(http.ErrNotSupported, errors.ErrUnsupported)</code>
749       will return true.
750     </p>
751   </dd>
752 </dl><!-- net/http -->
753
754 <dl id="os"><dt><a href="/pkg/os/">os</a></dt>
755   <dd>
756     <p><!-- https://go.dev/issue/32558, CL 219638 -->
757       Programs may now pass an empty <code>time.Time</code> value to
758       the <a href="/pkg/os/#Chtimes"><code>Chtimes</code></a> function
759       to leave either the access time or the modification time unchanged.
760     </p>
761
762     <p><!-- CL 480135 -->
763       On Windows the
764       <a href="/pkg/os#File.Chdir"><code>File.Chdir</code></a> method
765       now changes the current directory to the file, rather than
766       always returning an error.
767     </p>
768
769     <p><!-- CL 477215 -->
770       On Windows calling
771       <a href="/pkg/os/#Truncate"><code>Truncate</code></a> on a
772       non-existent file used to create an empty file. It now returns
773       an error indicating that the file does not exist.
774     </p>
775
776     <p><!-- CL 493036 -->
777       On Windows the os package now supports working with files whose
778       names, stored as UTF-16, can't be represented as valid UTF-8.
779     </p>
780
781     <p><!-- https://go.dev/issue/54451, CL 491175 -->
782       The implementation of the
783       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
784       interface returned by the
785       <a href="/pkg/os/#ReadDir"><code>ReadDir</code></a> function and
786       the <a href="/pkg/os/#File.ReadDir"><code>File.ReadDir</code>
787       method now implements a <code>String</code> method that calls
788       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
789     </p>
790   </dd>
791 </dl><!-- os -->
792
793 <dl id="path/filepath"><dt><a href="/pkg/path/filepath/">path/filepath</a></dt>
794   <dd>
795     <p>
796       The implementation of the
797       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
798       interface passed to the function argument of
799       <a href="/pkg/path/filepath/#WalkDir"><code>WalkDir</code></a>
800       now implements a <code>String</code> method that calls
801       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
802     </p>
803   </dd>
804 </dl><!-- path/filepath -->
805
806 <!-- CL 459455 reverted -->
807
808 <dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt>
809   <dd>
810     <p><!-- CL 408826, CL 413474 -->
811       In Go 1.21, <a href="/pkg/reflect/#ValueOf"><code>ValueOf</code></a>
812       no longer forces its argument to be allocated on the heap, allowing
813       a <code>Value</code>'s content to be allocated on the stack. Most
814       operations on a <code>Value</code> also allow the underlying value
815       to be stack allocated.
816     </p>
817
818     <p><!-- https://go.dev/issue/55002 -->
819       The new <a href="/pkg/reflect/#Value"><code>Value</code></a>
820       method <a href="/pkg/reflect/#Value.Clear"><code>Value.Clear</code></a>
821       clears the contents of a map or zeros the contents of a slice.
822       This corresponds to the new <code>clear</code> built-in
823       <a href="#language">added to the language</a>.
824     </p>
825
826     <p><!-- https://go.dev/issue/56906, CL 452762 -->
827       The <a href="/pkg/reflect/#SliceHeader"><code>SliceHeader</code></a>
828       and <a href="/pkg/reflect/#StringHeader"><code>StringHeader</code></a>
829       types are now deprecated. In new code
830       prefer <a href="/pkg/unsafe/#Slice"><code>unsafe.Slice</code></a>,
831       <a href="/pkg/unsafe/#SliceData"><code>unsafe.SliceData</code></a>,
832       <a href="/pkg/unsafe/#String"><code>unsafe.String</code></a>,
833       or <a href="/pkg/unsafe/#StringData"><code>unsafe.StringData</code></a>.
834     </p>
835   </dd>
836 </dl><!-- reflect -->
837
838 <dl id="regexp"><dt><a href="/pkg/regexp/">regexp</a></dt>
839   <dd>
840     <p><!-- https://go.dev/issue/46159, CL 479401 -->
841       <a href="/pkg/regexp#Regexp"><code>Regexp</code></a> now defines
842       <a href="/pkg/regexp#Regexp.MarshalText"><code>MarshalText</code></a>
843       and <a href="/pkg/regexp#Regexp.UnmarshalText"><code>UnmarshalText</code></a>
844       methods. These implement
845       <a href="/pkg/encoding#TextMarshaler"><code>encoding.TextMarshaler</code></a>
846       and
847       <a href="/pkg/encoding#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>
848       and will be used by packages such as
849       <a href="/pkg/encoding/json">encoding/json</a>.
850     </p>
851   </dd>
852 </dl><!-- regexp -->
853
854 <dl id="runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
855   <dd>
856     <p><!-- https://go.dev/issue/38651 -->
857       TODO: <a href="https://go.dev/issue/38651">https://go.dev/issue/38651</a>: add &#39;created by goroutine number&#39; to stack traces
858     </p>
859
860     <p><!-- https://go.dev/issue/57441, CL 474915 -->
861       Crashing Go applications can now opt-in to Windows Error Reporting (WER) by setting the environment variable
862       <code>GOTRACEBACK=wer</code> or calling <a href="/pkg/runtime/debug/#SetTraceback"><code>debug.SetTraceback("wer")</code></a>
863       before the crash. Other than enabling WER, the runtime will behave as with <code>GOTRACEBACK=crash</code>.
864       On non-Windows systems, <code>GOTRACEBACK=wer</code> is ignored.
865     </p>
866
867     <p><!-- CL 447778 -->
868       <code>GODEBUG=cgocheck=2</code>, a thorough checker of cgo pointer passing rules,
869       is no longer available as a <a href="/pkg/runtime#hdr-Environment_Variables">debug option</a>.
870       Instead, it is available as an experiment using <code>GOEXPERIMENT=cgocheck2</code>.
871       In particular this means that this mode has to be selected at build time instead of startup time.
872     <p>
873       <code>GODEBUG=cgocheck=1</code> is still available (and is still the default).
874     </p>
875
876     <p><!-- https://go.dev/issue/46787 -->
877       A new type <code>Pinner</code> has been added to the runtime
878       package. <code>Pinner</code>s may be used to "pin" Go memory
879       such that it may be used more freely by non-Go code. For instance,
880       passing Go values that reference pinned Go memory to C code is
881       now allowed. Previously, passing any such nested reference was
882       disallowed by the
883       <a href="https://pkg.go.dev/cmd/cgo#hdr-Passing_pointers">cgo pointer passing rules.</a>
884
885       See <a href="/pkg/runtime#Pinner">the docs</a> for more details.
886     </p>
887   </dd>
888 </dl><!-- runtime -->
889
890 <dl id="runtime/trace"><dt><a href="/pkg/runtime/trace/">runtime/trace</a></dt>
891   <dd>
892     <p><!-- https://go.dev/issue/16638 -->
893       Collecting traces on amd64 and arm64 now incurs a substantially
894       smaller CPU cost: up to a 10x improvement over the previous release.
895     </p>
896
897     <p><!-- CL 494495 -->
898       Traces now contain explicit stop-the-world events for every reason
899       the Go runtime might stop-the-world, not just garbage collection.
900     </p>
901   </dd>
902 </dl><!-- runtime/trace -->
903
904 <dl id="runtime/metrics"><dt><a href="/pkg/runtime/metrics/">runtime/metrics</a></dt>
905   <dd>
906     <p><!-- https://go.dev/issue/56857 -->
907       A few previously-internal GC metrics, such as live heap size, are
908       now available.
909
910       <code>GOGC</code> and <code>GOMEMLIMIT</code> are also now
911       available as metrics.
912     </p>
913   </dd>
914 </dl><!-- runtime/metrics -->
915
916 <dl id="sync"><dt><a href="/pkg/sync/">sync</a></dt>
917   <dd>
918     <p><!-- https://go.dev/issue/56102, CL 451356 -->
919       The new <a href="/pkg/sync/#OnceFunc"><code>OnceFunc</code></a>,
920       <a href="/pkg/sync/#OnceValue"><code>OnceValue</code></a>, and
921       <a href="/pkg/sync/#OnceValues"><code>OnceValues</code></a>
922       functions capture a common use of <a href="/pkg/sync/#Once">Once</a> to
923       lazily initialize a value on first use.
924     </p>
925   </dd>
926 </dl>
927
928 <dl id="syscall"><dt><a href="/pkg/syscall/">syscall</a></dt>
929   <dd>
930     <p><!-- CL 480135 -->
931       On Windows the
932       <a href="/pkg/syscall#Fchdir"><code>Fchdir</code></a> function
933       now changes the current directory to its argument, rather than
934       always returning an error.
935     </p>
936
937     <p><!-- https://go.dev/issue/46259, CL 458335 -->
938       On FreeBSD
939       <a href="/pkg/syscall#SysProcAttr"><code>SysProcAttr</code></a>
940       has a new field <code>Jail</code> that may be used to put the
941       newly created process in a jailed environment.
942     </p>
943
944     <p><!-- CL 493036 -->
945       On Windows the syscall package now supports working with files whose
946       names, stored as UTF-16, can't be represented as valid UTF-8.
947       The <a href="/pkg/syscall#UTF16ToString"><code>UTF16ToString</code></a>
948       and <a href="/pkg/syscall#UTF16FromString"><code>UTF16FromString</code></a>
949       functions now convert between UTF-16 data and
950       <a href="https://simonsapin.github.io/wtf-8/">WTF-8</a> strings.
951       This is backward compatible as WTF-8 is a superset of the UTF-8
952       format that was used in earlier releases.
953     </p>
954
955     <p><!-- CL 476578, CL 476875, CL 476916 -->
956       Several error values match the new
957       <a href="/pkg/errors/#ErrUnsupported"><code>errors.ErrUnsupported</code></a>,
958       such that <code>errors.Is(err, errors.ErrUnsupported)</code>
959       returns true.
960       <ul>
961         <li><code>ENOSYS</code></li>
962         <li><code>ENOTSUP</code></li>
963         <li><code>EOPNOTSUPP</code></li>
964         <li><code>EPLAN9</code> (Plan 9 only)</li>
965         <li><code>ERROR_CALL_NOT_IMPLEMENTED</code> (Windows only)</li>
966         <li><code>ERROR_NOT_SUPPORTED</code> (Windows only)</li>
967         <li><code>EWINDOWS</code> (Windows only)</li>
968       </ul>
969     </p>
970   </dd>
971 </dl><!-- syscall -->
972
973 <dl id="testing"><dt><a href="/pkg/testing/">testing</a></dt>
974   <dd>
975     <p><!-- https://go.dev/issue/37708, CL 463837 -->
976       The new <code>-test.fullpath</code> option will print full path
977       names in test log messages, rather than just base names.
978     </p>
979
980     <p><!-- https://go.dev/issue/52600, CL 475496 -->
981       The new <a href="/pkg/testing/#Testing"><code>Testing</code></a> function reports whether the program is a test created by <code>go</code> <code>test</code>.
982     </p>
983   </dd>
984 </dl><!-- testing -->
985
986 <dl id="testing/fstest"><dt><a href="/pkg/testing/fstest/">testing/fstest</a></dt>
987   <dd>
988     <p><!-- https://go.dev/issue/54451, CL 491175 -->
989       Calling <code><a href="/pkg/testing/fstest/MapFS.Open">Open</a>.<a href="/pkg/io/fs/#File.Stat">Stat</a></code>
990       will return a type that now implements a <code>String</code>
991       method that calls
992       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
993     </p>
994   </dd>
995 </dl><!-- testing/fstest -->
996
997 <dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt>
998   <dd>
999     <p><!-- CL 456837 -->
1000       The <a href="/pkg/unicode/"><code>unicode</code></a> package and
1001       associated support throughout the system has been upgraded to
1002       <a href="https://www.unicode.org/versions/Unicode15.0.0/">Unicode 15.0.0</a>.
1003     </p>
1004 </dl><!-- unicode -->
1005
1006 <!-- proposals for x repos that don't need to be mentioned here but
1007      are picked up by the relnote tool. -->
1008 <!-- https://go.dev/issue/54232 -->
1009 <!-- https://go.dev/issue/57906 -->
1010 <!-- https://go.dev/issue/58668 -->