DRAFT RELEASE NOTES — Introduction to Go 1.21

Go 1.21 is not yet released. These are work-in-progress release notes. Go 1.21 is expected to be released in August 2023.

Changes to the language

TODO: complete this section

Ports

WebAssembly System Interface

Go 1.21 adds an experimental port to the WebAssembly System Interface (WASI), Preview 1 (GOOS=wasip1, GOARCH=wasm).

As a result of the addition of the new GOOS value "wasip1", Go files named *_wasip1.go will now be ignored by Go tools except when that GOOS value is being used. If you have existing filenames matching that pattern, you will need to rename them.

Tools

Go command

<-- https://go.dev/issue/58099, CL 474236 --> The -pgo build flag now defaults to -pgo=auto, and the restriction of specifying a single main package on the command line is now removed. If a file named default.pgo is present in the main package's directory, the go command will use it to enable profile-guided optimization for building the corresponding program.

Runtime

TODO: complete this section, or delete if not needed

When printing very deep stacks, the runtime now prints the first 50 (innermost) frames followed by the bottom 50 (outermost) frames, rather than just printing the first 100 frames. This makes it easier to see how deeply recursive stacks started, and is especially valuable for debugging stack overflows.

Compiler

TODO: complete this section, or delete if not needed

Linker

TODO: complete this section, or delete if not needed

Core library

Minor changes to the library

As always, there are various minor changes and updates to the library, made with the Go 1 promise of compatibility in mind. There are also various performance improvements, not enumerated here.

TODO: complete this section

context

The new WithoutCancel function returns a copy of a context that is not canceled when the original context is canceled.

The new WithDeadlineCause and WithTimeoutCause functions provide a way to set a context cancellation cause when a deadline or timer expires. The cause may be retrieved with the Cause function.

The new AfterFunc function registers a function to run after a context has been cancelled.

reflect

In Go 1.21, ValueOf no longer forces its argument to be allocated on the heap, allowing a Value's content to be allocated on the stack. Most operations on a Value also allow the underlying value to be stack allocated.

sync

The new OnceFunc, OnceValue, and OnceValues functions capture a common use of Once to lazily initialize a value on first use.