]> Cypherpunks.ru repositories - gostls13.git/blob - doc/go1.21.html
doc/go1.21: fix link in debug/elf section
[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 <h3 id="darwin">Darwin</h3>
143
144 <p><!-- go.dev/issue/57125 -->
145   As <a href="go1.20#darwin">announced</a> in the Go 1.20 release notes,
146   Go 1.21 requires macOS 10.15 Catalina or later;
147   support for previous versions has been discontinued.
148 </p>
149
150 <h3 id="windows">Windows</h3>
151
152 <p><!-- go.dev/issue/57003, go.dev/issue/57004 -->
153   As <a href="go1.20#windows">announced</a> in the Go 1.20 release notes,
154   Go 1.21 requires at least Windows 10 or Windows Server 2016;
155   support for previous versions has been discontinued.
156 </p>
157
158 <!-- CL 470695 -->
159 <p>
160   <!-- cmd/dist: default to GOARM=7 on all non-arm systems -->
161 </p>
162
163 <h3 id="wasm">WebAssembly</h3>
164
165 <p><!-- https://go.dev/issue/38248, https://go.dev/issue/59149, CL 489255 -->
166   The new <code>go:wasmimport</code> directive can now be used in Go programs
167   to import functions from the WebAssembly host.
168 </p>
169
170 <!-- https://go.dev/issue/56100 -->
171 <p>
172   The Go scheduler now interacts much more efficiently with the
173   JavaScript event loop, especially in applications that block
174   frequently on asynchronous events.
175 </p>
176
177
178 <h3 id="wasip1">WebAssembly System Interface</h3>
179
180 <p><!-- https://go.dev/issue/58141 -->
181   Go 1.21 adds an experimental port to the <a href="https://wasi.dev/">
182   WebAssembly System Interface (WASI)</a>, Preview 1
183   (<code>GOOS=wasip1</code>, <code>GOARCH=wasm</code>).
184 </p>
185
186 <p>
187   As a result of the addition of the new <code>GOOS</code> value
188   "<code>wasip1</code>", Go files named <code>*_wasip1.go</code>
189   will now be <a href="/pkg/go/build/#hdr-Build_Constraints">ignored
190   by Go tools</a> except when that <code>GOOS</code> value is being
191   used.
192   If you have existing filenames matching that pattern, you will
193   need to rename them.
194 </p>
195
196 <h2 id="tools">Tools</h2>
197
198 <!-- https://go.dev/issue/15513 -->
199 <p>
200   <!-- support compiling all tests without running -->
201 </p>
202
203 <h3 id="go-command">Go command</h3>
204
205 <p><!-- https://go.dev/issue/58099, CL 474236 -->
206   The <code>-pgo</code> build flag now defaults to <code>-pgo=auto</code>,
207   and the restriction of specifying a single main package on the command
208   line is now removed. If a file named <code>default.pgo</code> is present
209   in the main package's directory, the <code>go</code> command will use
210   it to enable profile-guided optimization for building the corresponding
211   program.
212 </p>
213
214 <p><!-- https://go.dev/issue/37708, CL 463837 -->
215   The new <code>go</code> <code>test</code> option
216   <code>-fullpath</code> prints full path names in test log messages,
217   rather than just base names.
218 </p>
219
220 <!-- CL 466397 -->
221 <p>
222   <!-- cmd/go: make go test build multiple executables; The go test command now supports using the -c flag with multiple packages. -->
223 </p>
224
225 <h3 id="cgo">Cgo</h3>
226
227 <p><!-- CL 490819 -->
228   In files that <code>import "C"</code>, the Go toolchain now
229   correctly reports errors for attempts to declare Go methods on C types.
230 </p>
231
232 <h2 id="runtime-changes">Runtime</h2>
233
234 <p>
235   TODO: complete this section, or delete if not needed
236 </p>
237
238 <p><!-- https://go.dev/issue/7181 -->
239   When printing very deep stacks, the runtime now prints the first 50
240   (innermost) frames followed by the bottom 50 (outermost) frames,
241   rather than just printing the first 100 frames. This makes it easier
242   to see how deeply recursive stacks started, and is especially
243   valuable for debugging stack overflows.
244 </p>
245
246 <p><!-- https://go.dev/issue/59960 -->
247   On Linux platforms that support transparent huge pages, the Go runtime
248   now manages which parts of the heap may be backed by huge pages more
249   explicitly. This leads to better utilization of memory: small heaps
250   should see less memory used (up to 50% in pathological cases) while
251   large heaps should see fewer broken huge pages for dense parts of the
252   heap, improving CPU usage and latency by up to 1%.
253 </p>
254
255 <p><!-- https://go.dev/issue/57069, https://go.dev/issue/56966 -->
256   As a result of runtime-internal garbage collection tuning,
257   applications may see up to a 40% reduction in application tail latency
258   and a small decrease in memory use. Some applications may also observe
259   a small loss in throughput.
260
261   The memory use decrease should be proportional to the loss in
262   throughput, such that the previous release's throughput/memory
263   tradeoff may be recovered (with little change to latency) by
264   increasing <code>GOGC</code> and/or <code>GOMEMLIMIT</code> slightly.
265 </p>
266
267 <p><!-- https://go.dev/issue/51676 -->
268   Calls from C to Go on threads created in C require some setup to prepare for
269   Go execution. On Unix platforms, this setup is now preserved across multiple
270   calls from the same thread. This significantly reduces the overhead of
271   subsequent C to Go calls from ~1-3 microseconds per call to ~100-200
272   nanoseconds per call.
273 </p>
274
275 <h2 id="compiler">Compiler</h2>
276
277 <p>
278   Profile-guide optimization (PGO), added as a preview in Go 1.20, is now ready
279   for general use. PGO enables additional optimizations on code identified as
280   hot by profiles of production workloads. As mentioned in the
281   <a href="#go-command">Go command section</a>, PGO is enabled by default for
282   binaries that contain a <code>default.pgo</code> profile in the main
283   package directory. Performance improvements vary depending on application
284   behavior, with most programs from a representative set of Go programs seeing
285   between 2 and 7% improvement from enabling PGO. See the
286   <a href="/doc/pgo">PGO user guide</a> for detailed documentation.
287 </p>
288
289 <!-- https://go.dev/issue/59959 -->
290 <p>
291   PGO builds can now devirtualize some interface method calls, adding a
292   concrete call to the most common callee. This enables further optimization,
293   such as inlining the callee.
294 </p>
295
296 <p>
297   TODO: complete this section, or delete if not needed
298 </p>
299
300 <h2 id="assembler">Assembler</h2>
301
302 <!-- CL 476295 -->
303 <p>
304   The verifier that checks for incorrect uses of <code>R15</code> when dynamic linking on amd64 has been improved.
305 </p>
306
307 <h2 id="linker">Linker</h2>
308
309 <p><!-- https://go.dev/issue/57302, CL 461749 -->
310   On Windows AMD64, the linker (with help from the compiler) now emits
311   SEH unwinding data by default, which improves the integration
312   of Go applications with Windows debuggers and other tools.
313 </p>
314
315 <!-- CL 457455 -->
316 <p>
317   <!-- cmd/link: generate .xdata PE section -->
318 </p>
319 <!-- CL 463395, CL 461315 -->
320 <p>
321   In Go 1.21 the linker (with help from the compiler) is now capable of
322   deleting dead (unreferenced) global map variables, if the number of
323   entries in the variable initializer is sufficiently large, and if the
324   initializer expressions are side-effect free.
325 </p>
326 <p>
327   TODO: complete this section, or delete if not needed
328 </p>
329
330 <h2 id="library">Core library</h2>
331
332 <h3 id="slog">New log/slog package</h3>
333
334 <p><!-- https://go.dev/issue/59060, https://go.dev/issue/59141, https://go.dev/issue/59204, https://go.dev/issue/59280,
335         https://go.dev/issue/59282, https://go.dev/issue/59339, https://go.dev/issue/59345,
336         CL 477295, CL 484096, CL 486376, CL 486415, CL 487855 -->
337   The new <a href="/pkg/log/slog">log/slog</a> package provides structured logging with levels.
338   Structured logging emits key-value pairs
339   to enable fast, accurate processing of large amounts of log data.
340   The package supports integration with popular log analysis tools and services.
341 </p>
342
343 <h3 id="slogtest">New testing/slogtest package</h3>
344
345 <p><!-- CL 487895 -->
346   The new <a href="/pkg/testing/slogtest">testing/slogtest</a> package can help
347   to validate <a href="/pkg/log/slog#Handler">slog.Handler</a> implementations.
348 </p>
349
350 <h3 id="slices">New slices package</h3>
351
352 <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 -->
353   The new <a href="/pkg/slices">slices</a> package provides many common
354   operations on slices, using generic functions that work with slices
355   of any element type.
356 </p>
357
358 <h3 id="maps">New maps package</h3>
359
360 <p><!-- https://go.dev/issue/57436, CL 464343 -->
361   The new <a href="/pkg/maps/">maps</a> package provides several
362   common operations on maps, using generic functions that work with
363   maps of any key or element type.
364 </p>
365
366 <h3 id="minor_library_changes">Minor changes to the library</h3>
367
368 <p>
369   As always, there are various minor changes and updates to the library,
370   made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a>
371   in mind.
372   There are also various performance improvements, not enumerated here.
373 </p>
374
375 <p>
376   TODO: complete this section
377 </p>
378
379 <dl id="archive/tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt>
380   <dd>
381     <p><!-- https://go.dev/issue/54451, CL 491175 -->
382       The implementation of the
383       <a href="/pkg/io/fs/#FileInfo"><code>io/fs.FileInfo</code></a>
384       interface returned by
385       <a href="/pkg/archive/tar/#Header.FileInfo"><code>Header.FileInfo</code></a>
386       now implements a <code>String</code> method that calls
387       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
388     </p>
389   </dd>
390 </dl><!-- archive/tar -->
391
392 <dl id="archive/zip"><dt><a href="/pkg/archive/zip/">archive/zip</a></dt>
393   <dd>
394     <p><!-- https://go.dev/issue/54451, CL 491175 -->
395       The implementation of the
396       <a href="/pkg/io/fs/#FileInfo"><code>io/fs.FileInfo</code></a>
397       interface returned by
398       <a href="/pkg/archive/zip/#FileHeader.FileInfo"><code>FileHeader.FileInfo</code></a>
399       now implements a <code>String</code> method that calls
400       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
401     </p>
402
403     <p><!-- https://go.dev/issue/54451, CL 491175 -->
404       The implementation of the
405       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
406       interface returned by the
407       <a href="/pkg/io/fs/#ReadDirFile.ReadDir"><code>io/fs.ReadDirFile.ReadDir</code></a>
408       method of the
409       <a href="/pkg/io/fs/#File"><code>io/fs.File</code></a>
410       returned by
411       <a href="/pkg/archive/zip/#Reader.Open"><code>Reader.Open</code></a>
412       now implements a <code>String</code> method that calls
413       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
414     </p>
415   </dd>
416 </dl><!-- archive/zip -->
417
418 <dl id="bytes"><dt><a href="/pkg/bytes/">bytes</a></dt>
419   <dd>
420     <p><!-- https://go.dev/issue/53685, CL 474635 -->
421       The <a href="/pkg/bytes/#Buffer"><code>Buffer</code></a> type
422       has two new methods:
423       <a href="/pkg/bytes/#Buffer.Available"><code>Available</code></a>
424       and <a href="/pkg/bytes/#AvailableBuffer"><code>AvailableBuffer</code></a>.
425       These may be used along with the
426       <a href="/pkg/bytes/#Buffer.Write"><code>Write</code></a>
427       method to append directly to the <code>Buffer</code>.
428     </p>
429   </dd>
430 </dl><!-- bytes -->
431
432 <dl id="context"><dt><a href="/pkg/context/">context</a></dt>
433   <dd>
434     <p><!-- https://go.dev/issue/40221, CL 479918 -->
435       The new <a href="/pkg/context/#WithoutCancel"><code>WithoutCancel</code></a>
436       function returns a copy of a context that is not canceled when the original
437       context is canceled.
438     </p>
439     <p><!-- https://go.dev/issue/56661, CL 449318 -->
440       The new <a href="/pkg/context/#WithDeadlineCause"><code>WithDeadlineCause</code></a>
441       and <a href="/pkg/context/#WithTimeoutCause"><code>WithTimeoutCause</code></a>
442       functions provide a way to set a context cancellation cause when a deadline or
443       timer expires. The cause may be retrieved with the
444       <a href="/pkg/context/#Cause"><code>Cause</code></a> function.
445     </p>
446     <p><!-- https://go.dev/issue/57928, CL 482695 -->
447       The new <a href="/pkg/context/#AfterFunc"><code>AfterFunc</code></a>
448       function registers a function to run after a context has been cancelled.
449     </p>
450   </dd>
451 </dl>
452
453 <dl id="crypto/elliptic"><dt><a href="/pkg/crypto/elliptic/">crypto/elliptic</a></dt>
454   <dd>
455     <p><!-- CL 459977 -->
456       All of the <a href="/pkg/crypto/elliptic/#Curve"><code>Curve</code></a> methods have been deprecated, along with <a href="/pkg/crypto/elliptic/#GenerateKey"><code>GenerateKey</code></a>, <a href="/pkg/crypto/elliptic/#Marshal"><code>Marshal</code></a>, and <a href="/pkg/crypto/elliptic/#Unmarshal"><code>Unmarshal</code></a>. For ECDH operations, the new <a href="/pkg/crypto/ecdh/"><code>crypto/ecdh</code></a> package should be used instead.
457     </p>
458   </dd>
459 </dl><!-- crypto/elliptic -->
460
461 <dl id="crypto/rsa"><dt><a href="/pkg/crypto/rsa/">crypto/rsa</a></dt>
462   <dd>
463     <p><!-- https://go.dev/issue/56921, CL 459976 -->
464       The <a href="/pkg/crypto/rsa/#GenerateMultiPrimeKey"><code>GenerateMultiPrimeKey</code></a> function and the <a href="/pkg/crypto/rsa/#PrecomputedValues.CRTValues"><code>PrecomputedValues.CRTValues</code></a> field have been deprecated. <a href="/pkg/crypto/rsa/#PrecomputedValues.CRTValues"><code>PrecomputedValues.CRTValues</code></a> will still be populated when <a href="/pkg/crypto/rsa/#PrivateKey.Precompute"><code>PrivateKey.Precompute</code></a> is called, but the values will not be used during decryption operations.
465     </p>
466   </dd>
467 </dl><!-- crypto/rsa -->
468
469 <dl id="crypto/sha256"><dt><a href="/pkg/crypto/sha256/">crypto/sha256</a></dt>
470   <dd>
471     <p><!-- https://go.dev/issue/50543, CL 408795 -->
472       SHA-224 and SHA-256 operations now use native instructions when available when <code>GOOS=amd64</code>, providing a performance improvement on the order of 3-4x.
473     </p>
474   </dd>
475 </dl><!-- crypto/sha256 -->
476
477 <dl id="crypto/x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
478   <dd>
479     <p><!-- https://go.dev/issue/53573, CL 468875 -->
480       <a href="/pkg/crypto/x509/#RevocationList.RevokedCertificates"><code>RevocationList.RevokedCertificates</code></a> has been deprecated and replaced with the new <a href="/pkg/crypto/x509/#RevocationList.Entries"><code>RevocationList.Entries</code></a> field, which is a slice of <a href="/pkg/crypto/x509/#RevocationListEntry"><code>RevocationListEntry</code></a>. <a href="/pkg/crypto/x509/#RevocationListEntry"><code>RevocationListEntry</code></a> contains all of the fields in <a href="/pkg/crypto/x509/#pkix.RevokedCertificate"><code>pkix.RevokedCertificate</code></a>, as well as the revocation reason code.
481     </p>
482   </dd>
483 </dl><!-- crypto/x509 -->
484
485 <dl id="debug/elf"><dt><a href="/pkg/debug/elf/">debug/elf</a></dt>
486   <dd>
487     <p><!-- https://go.dev/issue/56892, CL 452617 -->
488       The new
489       <a href="/pkg/debug/elf/#File.DynValue"><code>File.DynValue</code></a>
490       method may be used to retrieve the numeric values listed with a
491       given dynamic tag.
492     </p>
493
494     <p><!-- https://go.dev/issue/56887, CL 452496 -->
495       The constant flags permitted in a <code>DT_FLAGS_1</code>
496       dynamic tag are now defined with type
497       <a href="/pkg/debug/elf/#DynFlag1"><code>DynFlag1</code></a>. These
498       tags have names starting with <code>DF_1</code>.
499     </p>
500
501     <p><!-- CL 473256 -->
502       The package now defines the constant
503       <a href="/pkg/debug/elf/#COMPRESS_ZSTD"><code>COMPRESS_ZSTD</code></a>.
504     </p>
505   </dd>
506 </dl><!-- debug/elf -->
507
508 <dl id="debug/pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt>
509   <dd>
510     <p><!-- CL 488475 -->
511       Attempts to read from a section containing uninitialized data
512       using
513       <a href="/pkg/debug/pe/#Section.Data"><code>Section.Data</code></a>
514       or the reader returned by <a href="/pkg/debug/pe/#Section.Open"><code>Section.Open</code></a>
515       now return an error.
516     </p>
517   </dd>
518 </dl><!-- debug/pe -->
519
520 <dl id="embed"><dt><a href="/pkg/embed/">embed</a></dt>
521   <dd>
522     <p><!-- https://go.dev/issue/57803, CL 483235 -->
523       The <a href="/pkg/io/fs/#File"><code>io/fs.File</code></a>
524       returned by
525       <a href="/pkg/embed/#FS.Open"><code>FS.Open</code></a> now
526       has a <code>ReadAt</code> method that
527       implements <a href="/pkg/io/#ReaderAt"><code>io.ReaderAt</code></a>.
528     </p>
529
530     <p><!-- https://go.dev/issue/54451, CL 491175 -->
531       Calling <code><a href="/pkg/embed/FS.Open">FS.Open</a>.<a href="/pkg/io/fs/#File.Stat">Stat</a></code>
532       will return a type that now implements a <code>String</code>
533       method that calls
534       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
535     </p>
536   </dd>
537 </dl><!-- embed -->
538
539 <dl id="errors"><dt><a href="/pkg/errors/">errors</a></dt>
540   <dd>
541     <p><!-- https://go.dev/issue/41198, CL 473935 -->
542       The new
543       <a href="/pkg/errors/#ErrUnsupported"><code>ErrUnsupported</code></a>
544       error provides a standardized way to indicate that a requested
545       operation may not be performed because it is unsupported.
546       For example, a call to
547       <a href="/pkg/os/#Link"><code>os.Link</code></a> when using a
548       file system that does not support hard links.
549     </p>
550   </dd>
551 </dl><!-- errors -->
552
553 <dl id="flag"><dt><a href="/pkg/flag/">flag</a></dt>
554   <dd>
555     <p><!-- https://go.dev/issue/53747, CL 476015 -->
556       The new <a href="/pkg/flag/#BoolFunc"><code>BoolFunc</code></a>
557       function and
558       <a href="/pkg/flag/#FlagSet.BoolFunc"><code>FlagSet.BoolFunc</code></a>
559       method define a flag that does not require an argument and calls
560       a function when the flag is used. This is similar to
561       <a href="/pkg/flag/#Func"><code>Func</code></a> but for a
562       boolean flag.
563     </p>
564
565     <p><!-- CL 480215 -->
566       A flag definition
567       (via <a href="/pkg/flag/#Bool"><code>Bool</code></a>,
568       <a href="/pkg/flag/#BoolVar"><code>BoolVar</code></a>,
569       <a href="/pkg/flag/#Int"><code>Int</code></a>,
570       <a href="/pkg/flag/#IntVar"><code>IntVar</code></a>, etc.)
571       will panic if <a href="/pkg/flag/#Set"><code>Set</code></a> has
572       already been called on a flag with the same name. This change is
573       intended to detect cases where <a href="#language">changes in
574       initialization order</a> cause flag operations to occur in a
575       different order than expected. In many cases the fix to this
576       problem is to introduce a explicit package dependence to
577       correctly order the definition before any
578       <a href="/pkg/flag/#Set"><code>Set</code></a> 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 <!-- https://go.dev/issue/56491 rolled back -->
675 <!-- CL 459435 reverted -->
676 <!-- CL 467515 reverted -->
677
678 <dl id="math/big"><dt><a href="/pkg/math/big/">math/big</a></dt>
679   <dd>
680     <p><!-- https://go.dev/issue/56984, CL 453115 -->
681       The new <a href="/pkg/math/big/#Int.Float64"><code>Int.Float64</code></a>
682       method returns the nearest floating-point value to a
683       multi-precision integer, along with an indication of any
684       rounding that occurred.
685     </p>
686   </dd>
687 </dl><!-- math/big -->
688
689 <dl id="net"><dt><a href="/pkg/net/">net</a></dt>
690   <dd>
691     <p>
692       <!-- https://go.dev/issue/59166, https://go.dev/issue/56539 -->
693       <!-- CL 471136, CL 471137, CL 471140 -->
694       On Linux, the <a href="/pkg/net/">net</a> package can now use
695       Multipath TCP when the kernel supports it. It is not used by
696       default. To use Multipath TCP when available on a client, call
697       the
698       <a href="/pkg/net/#Dialer.SetMultipathTCP"><code>Dialer.SetMultipathTCP</code></a>
699       method before calling the
700       <a href="/pkg/net/#Dialer.Dial"><code>Dialer.Dial</code></a> or
701       <a href="/pkg/net/#Dialer.DialContext"><code>Dialer.DialContext</code></a>
702       methods. To use Multipath TCP when available on a server, call
703       the
704       <a href="/pkg/net/#ListenConfig.SetMultipathTCP"><code>ListenConfig.SetMultipathTCP</code></a>
705       method before calling the
706       <a href="/pkg/net/#ListenConfig.Listen"><code>ListenConfig.Listen</code></a>
707       method. Specify the network as <code>"tcp"</code> or
708       <code>"tcp4"</code> or <code>"tcp6"</code> as usual. If
709       Multipath TCP is not supported by the kernel or the remote host,
710       the connection will silently fall back to TCP. To test whether a
711       particular connection is using Multipath TCP, use the
712       <a href="/pkg/net/#TCPConn.MultipathTCP"><code>TCPConn.MultipathTCP</code></a>
713       method.
714     </p>
715     <p>
716       In a future Go release we may enable Multipath TCP by default on
717       systems that support it.
718     </p>
719   </dd>
720 </dl><!-- net -->
721
722 <dl id="net/http"><dt><a href="/pkg/net/http/">net/http</a></dt>
723   <dd>
724     <p><!-- https://go.dev/issue/44855, CL 382117 -->
725       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.
726     </p>
727
728     <p><!-- CL 472636 -->
729       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
730     </p>
731
732     <p><!-- CL 494122 -->
733       The <a href="/pkg/net/http/">net/http</a> package now supports
734       <a href="/pkg/errors/#ErrUnsupported"><code>errors.ErrUnsupported</code></a>,
735       in that the expression
736       <code>errors.Is(http.ErrNotSupported, errors.ErrUnsupported)</code>
737       will return true.
738     </p>
739   </dd>
740 </dl><!-- net/http -->
741
742 <dl id="os"><dt><a href="/pkg/os/">os</a></dt>
743   <dd>
744     <p><!-- https://go.dev/issue/32558, CL 219638 -->
745       Programs may now pass an empty <code>time.Time</code> value to
746       the <a href="/pkg/os/#Chtimes"><code>Chtimes</code></a> function
747       to leave either the access time or the modification time unchanged.
748     </p>
749
750     <p><!-- CL 480135 -->
751       On Windows the
752       <a href="/pkg/os#File.Chdir"><code>File.Chdir</code></a> method
753       now changes the current directory to the file, rather than
754       always returning an error.
755     </p>
756
757     <p><!-- CL 477215 -->
758       On Windows calling
759       <a href="/pkg/os/#Truncate"><code>Truncate</code></a> on a
760       non-existent file used to create an empty file. It now returns
761       an error indicating that the file does not exist.
762     </p>
763
764     <p><!-- https://go.dev/issue/56899, CL 463219 -->
765       On Windows calling
766       <a href="/pkg/os/#TempDir"><code>TempDir</code></a> now uses
767       GetTempPath2W when available, instead of GetTempPathW. The
768       new behavior is a security hardening measure that prevents
769       temporary files created by processes running as SYSTEM to
770       be accessed by non-SYSTEM processes.
771     </p>
772
773     <p><!-- CL 493036 -->
774       On Windows the os package now supports working with files whose
775       names, stored as UTF-16, can't be represented as valid UTF-8.
776     </p>
777
778     <p><!-- https://go.dev/issue/54451, CL 491175 -->
779       The implementation of the
780       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
781       interface returned by the
782       <a href="/pkg/os/#ReadDir"><code>ReadDir</code></a> function and
783       the <a href="/pkg/os/#File.ReadDir"><code>File.ReadDir</code></a>
784       method now implements a <code>String</code> method that calls
785       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
786     </p>
787
788     <p><!-- https://go.dev/issue/53761, CL 416775, CL 498015-->
789     The implementation of the
790     <a href="/pkg/io/fs/#FS"><code>io/fs.FS</code></a> interface returned by
791     the <a href="/pkg/os/#DirFS"><code>DirFS</code></a> function now implements
792     the <a href="/pkg/io/fs/#ReadFileFS"><code>io/fs.ReadFileFS</code></a> and
793     the <a href="/pkg/io/fs/#ReadDirFS"><code>io/fs.ReadDirFS</code></a>
794     interfaces.
795     </p>
796   </dd>
797 </dl><!-- os -->
798
799 <dl id="path/filepath"><dt><a href="/pkg/path/filepath/">path/filepath</a></dt>
800   <dd>
801     <p>
802       The implementation of the
803       <a href="/pkg/io/fs/#DirEntry"><code>io/fs.DirEntry</code></a>
804       interface passed to the function argument of
805       <a href="/pkg/path/filepath/#WalkDir"><code>WalkDir</code></a>
806       now implements a <code>String</code> method that calls
807       <a href="/pkg/io/fs/#FormatDirEntry"><code>io/fs.FormatDirEntry</code></a>.
808     </p>
809   </dd>
810 </dl><!-- path/filepath -->
811
812 <!-- CL 459455 reverted -->
813
814 <dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt>
815   <dd>
816     <p><!-- CL 408826, CL 413474 -->
817       In Go 1.21, <a href="/pkg/reflect/#ValueOf"><code>ValueOf</code></a>
818       no longer forces its argument to be allocated on the heap, allowing
819       a <code>Value</code>'s content to be allocated on the stack. Most
820       operations on a <code>Value</code> also allow the underlying value
821       to be stack allocated.
822     </p>
823
824     <p><!-- https://go.dev/issue/55002 -->
825       The new <a href="/pkg/reflect/#Value"><code>Value</code></a>
826       method <a href="/pkg/reflect/#Value.Clear"><code>Value.Clear</code></a>
827       clears the contents of a map or zeros the contents of a slice.
828       This corresponds to the new <code>clear</code> built-in
829       <a href="#language">added to the language</a>.
830     </p>
831
832     <p><!-- https://go.dev/issue/56906, CL 452762 -->
833       The <a href="/pkg/reflect/#SliceHeader"><code>SliceHeader</code></a>
834       and <a href="/pkg/reflect/#StringHeader"><code>StringHeader</code></a>
835       types are now deprecated. In new code
836       prefer <a href="/pkg/unsafe/#Slice"><code>unsafe.Slice</code></a>,
837       <a href="/pkg/unsafe/#SliceData"><code>unsafe.SliceData</code></a>,
838       <a href="/pkg/unsafe/#String"><code>unsafe.String</code></a>,
839       or <a href="/pkg/unsafe/#StringData"><code>unsafe.StringData</code></a>.
840     </p>
841   </dd>
842 </dl><!-- reflect -->
843
844 <dl id="regexp"><dt><a href="/pkg/regexp/">regexp</a></dt>
845   <dd>
846     <p><!-- https://go.dev/issue/46159, CL 479401 -->
847       <a href="/pkg/regexp#Regexp"><code>Regexp</code></a> now defines
848       <a href="/pkg/regexp#Regexp.MarshalText"><code>MarshalText</code></a>
849       and <a href="/pkg/regexp#Regexp.UnmarshalText"><code>UnmarshalText</code></a>
850       methods. These implement
851       <a href="/pkg/encoding#TextMarshaler"><code>encoding.TextMarshaler</code></a>
852       and
853       <a href="/pkg/encoding#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>
854       and will be used by packages such as
855       <a href="/pkg/encoding/json">encoding/json</a>.
856     </p>
857   </dd>
858 </dl><!-- regexp -->
859
860 <dl id="runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
861   <dd>
862     <p><!-- https://go.dev/issue/38651 -->
863       TODO: <a href="https://go.dev/issue/38651">https://go.dev/issue/38651</a>: add &#39;created by goroutine number&#39; to stack traces
864     </p>
865
866     <p><!-- https://go.dev/issue/57441, CL 474915 -->
867       Crashing Go applications can now opt-in to Windows Error Reporting (WER) by setting the environment variable
868       <code>GOTRACEBACK=wer</code> or calling <a href="/pkg/runtime/debug/#SetTraceback"><code>debug.SetTraceback("wer")</code></a>
869       before the crash. Other than enabling WER, the runtime will behave as with <code>GOTRACEBACK=crash</code>.
870       On non-Windows systems, <code>GOTRACEBACK=wer</code> is ignored.
871     </p>
872
873     <p><!-- CL 447778 -->
874       <code>GODEBUG=cgocheck=2</code>, a thorough checker of cgo pointer passing rules,
875       is no longer available as a <a href="/pkg/runtime#hdr-Environment_Variables">debug option</a>.
876       Instead, it is available as an experiment using <code>GOEXPERIMENT=cgocheck2</code>.
877       In particular this means that this mode has to be selected at build time instead of startup time.
878     <p>
879       <code>GODEBUG=cgocheck=1</code> is still available (and is still the default).
880     </p>
881
882     <p><!-- https://go.dev/issue/46787 -->
883       A new type <code>Pinner</code> has been added to the runtime
884       package. <code>Pinner</code>s may be used to "pin" Go memory
885       such that it may be used more freely by non-Go code. For instance,
886       passing Go values that reference pinned Go memory to C code is
887       now allowed. Previously, passing any such nested reference was
888       disallowed by the
889       <a href="https://pkg.go.dev/cmd/cgo#hdr-Passing_pointers">cgo pointer passing rules.</a>
890
891       See <a href="/pkg/runtime#Pinner">the docs</a> for more details.
892     </p>
893   </dd>
894 </dl><!-- runtime -->
895
896 <dl id="runtime/trace"><dt><a href="/pkg/runtime/trace/">runtime/trace</a></dt>
897   <dd>
898     <p><!-- https://go.dev/issue/16638 -->
899       Collecting traces on amd64 and arm64 now incurs a substantially
900       smaller CPU cost: up to a 10x improvement over the previous release.
901     </p>
902
903     <p><!-- CL 494495 -->
904       Traces now contain explicit stop-the-world events for every reason
905       the Go runtime might stop-the-world, not just garbage collection.
906     </p>
907   </dd>
908 </dl><!-- runtime/trace -->
909
910 <dl id="runtime/metrics"><dt><a href="/pkg/runtime/metrics/">runtime/metrics</a></dt>
911   <dd>
912     <p><!-- https://go.dev/issue/56857 -->
913       A few previously-internal GC metrics, such as live heap size, are
914       now available.
915
916       <code>GOGC</code> and <code>GOMEMLIMIT</code> are also now
917       available as metrics.
918     </p>
919   </dd>
920 </dl><!-- runtime/metrics -->
921
922 <dl id="sync"><dt><a href="/pkg/sync/">sync</a></dt>
923   <dd>
924     <p><!-- https://go.dev/issue/56102, CL 451356 -->
925       The new <a href="/pkg/sync/#OnceFunc"><code>OnceFunc</code></a>,
926       <a href="/pkg/sync/#OnceValue"><code>OnceValue</code></a>, and
927       <a href="/pkg/sync/#OnceValues"><code>OnceValues</code></a>
928       functions capture a common use of <a href="/pkg/sync/#Once">Once</a> to
929       lazily initialize a value on first use.
930     </p>
931   </dd>
932 </dl>
933
934 <dl id="syscall"><dt><a href="/pkg/syscall/">syscall</a></dt>
935   <dd>
936     <p><!-- CL 480135 -->
937       On Windows the
938       <a href="/pkg/syscall#Fchdir"><code>Fchdir</code></a> function
939       now changes the current directory to its argument, rather than
940       always returning an error.
941     </p>
942
943     <p><!-- https://go.dev/issue/46259, CL 458335 -->
944       On FreeBSD
945       <a href="/pkg/syscall#SysProcAttr"><code>SysProcAttr</code></a>
946       has a new field <code>Jail</code> that may be used to put the
947       newly created process in a jailed environment.
948     </p>
949
950     <p><!-- CL 493036 -->
951       On Windows the syscall package now supports working with files whose
952       names, stored as UTF-16, can't be represented as valid UTF-8.
953       The <a href="/pkg/syscall#UTF16ToString"><code>UTF16ToString</code></a>
954       and <a href="/pkg/syscall#UTF16FromString"><code>UTF16FromString</code></a>
955       functions now convert between UTF-16 data and
956       <a href="https://simonsapin.github.io/wtf-8/">WTF-8</a> strings.
957       This is backward compatible as WTF-8 is a superset of the UTF-8
958       format that was used in earlier releases.
959     </p>
960
961     <p><!-- CL 476578, CL 476875, CL 476916 -->
962       Several error values match the new
963       <a href="/pkg/errors/#ErrUnsupported"><code>errors.ErrUnsupported</code></a>,
964       such that <code>errors.Is(err, errors.ErrUnsupported)</code>
965       returns true.
966       <ul>
967         <li><code>ENOSYS</code></li>
968         <li><code>ENOTSUP</code></li>
969         <li><code>EOPNOTSUPP</code></li>
970         <li><code>EPLAN9</code> (Plan 9 only)</li>
971         <li><code>ERROR_CALL_NOT_IMPLEMENTED</code> (Windows only)</li>
972         <li><code>ERROR_NOT_SUPPORTED</code> (Windows only)</li>
973         <li><code>EWINDOWS</code> (Windows only)</li>
974       </ul>
975     </p>
976   </dd>
977 </dl><!-- syscall -->
978
979 <dl id="testing"><dt><a href="/pkg/testing/">testing</a></dt>
980   <dd>
981     <p><!-- https://go.dev/issue/37708, CL 463837 -->
982       The new <code>-test.fullpath</code> option will print full path
983       names in test log messages, rather than just base names.
984     </p>
985
986     <p><!-- https://go.dev/issue/52600, CL 475496 -->
987       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>.
988     </p>
989   </dd>
990 </dl><!-- testing -->
991
992 <dl id="testing/fstest"><dt><a href="/pkg/testing/fstest/">testing/fstest</a></dt>
993   <dd>
994     <p><!-- https://go.dev/issue/54451, CL 491175 -->
995       Calling <code><a href="/pkg/testing/fstest/MapFS.Open">Open</a>.<a href="/pkg/io/fs/#File.Stat">Stat</a></code>
996       will return a type that now implements a <code>String</code>
997       method that calls
998       <a href="/pkg/io/fs/#FormatFileInfo"><code>io/fs.FormatFileInfo</code></a>.
999     </p>
1000   </dd>
1001 </dl><!-- testing/fstest -->
1002
1003 <dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt>
1004   <dd>
1005     <p><!-- CL 456837 -->
1006       The <a href="/pkg/unicode/"><code>unicode</code></a> package and
1007       associated support throughout the system has been upgraded to
1008       <a href="https://www.unicode.org/versions/Unicode15.0.0/">Unicode 15.0.0</a>.
1009     </p>
1010 </dl><!-- unicode -->
1011
1012 <!-- proposals for x repos that don't need to be mentioned here but
1013      are picked up by the relnote tool. -->
1014 <!-- https://go.dev/issue/54232 -->
1015 <!-- https://go.dev/issue/57906 -->
1016 <!-- https://go.dev/issue/58668 -->