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

TODO: complete this section, or delete if not needed

Tools

Go command

TODO: complete this section, or delete if not needed

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.