DRAFT RELEASE NOTES — Introduction to Go 1.19

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

Changes to the language

TODO: complete this section

TODO: https://go.dev/issue/52038: adjust scope of type parameters declared by method receivers

Ports

TODO: complete this section, or delete if not needed

Go 1.19 supports the Loongson 64-bit architecture LoongArch on Linux (GOOS=linux, GOARCH=loong64).

Tools

TODO: complete this section, or delete if not needed

: TODO: https://go.dev/issue/47528 warn when errors.As target has type *error

Doc Comments

TODO: complete this section.

Go command

TODO: complete this section.

The -trimpath flag, if set, is now included in the build settings stamped into Go binaries by go build, and can be examined using go version -m or debug.ReadBuildInfo.

go generate now sets the GOROOT environment variable explicitly in the generator's environment, so that generators can locate the correct GOROOT even if built with -trimpath.

go test and go generate now place GOROOT/bin at the beginning of the PATH used for the subprocess, so tests and generators that execute the go command will resolve it to same GOROOT.

go env now quotes entries that contain spaces in the CGO_CFLAGS, CGO_CPPFLAGS, CGO_CXXFLAGS, CGO_FFLAGS, CGO_LDFLAGS, and GOGCCFLAGS variables it reports.

New unix build constraint

The build constraint unix is now recognized in //go:build lines. The constraint is satisfied if the target operating system, also known as GOOS, is a Unix or Unix-like system. For the 1.19 release it is satisfied if GOOS is one of aix, android, darwin, dragonfly, freebsd, hurd, illumos, ios, linux, netbsd, openbsd, or solaris. In future releases the unix constraint may match additional newly supported operating systems.

Runtime

The runtime now includes support for a soft memory limit. This memory limit includes the Go heap and all other memory managed by the runtime, and excludes external memory sources such as mappings of the binary itself, memory managed in other languages, and memory held by the operating system on behalf of the Go program. This limit may be managed via runtime/debug.SetMemoryLimit or the equivalent GOMEMLIMIT environment variable. The limit works in conjunction with runtime/debug.SetGCPercent / GOGC, and will be respected even if GOGC=off, allowing Go programs to always make maximal use of their memory limit, improving resource efficiency in some cases. See the GC guide for a detailed guide explaining the soft memory limit in more detail, as well as a variety of common use-cases and scenarios. Please note that small memory limits, on the order of tens of megabytes or less, are less likely to be respected due to external latency factors, such as OS scheduling. See issue 52433 for more details. Larger memory limits, on the order of hundreds of megabytes or more, are stable and production-ready.

In order to limit the effects of GC thrashing when the program's live heap size approaches the soft memory limit, the Go runtime also attempts to limit total GC CPU utilization to 50%, excluding idle time, choosing to use more memory over preventing application progress. In practice, we expect this limit to only play a role in exceptional cases, and the new runtime metric /gc/limiter/last-enabled:gc-cycle reports when this last occurred.

The runtime now schedules many fewer GC worker goroutines on idle operating system threads when the application is idle enough to force a periodic GC cycle.

The runtime will now allocate initial goroutine stacks based on the historic average stack usage of goroutines. This avoids some of the early stack growth and copying needed in the average case in exchange for at most 2x wasted space on below-average goroutines.

On Unix operating systems, Go programs that import package os now automatically increase the open file limit (RLIMIT_NOFILE) to the maximum allowed value. Programs that need a lower limit (for compatibility with select, for example) can set the limit back as needed, or lower the hard limit prior to starting the Go program.

Unrecoverable fatal errors (such as concurrent map writes, or unlock of unlocked mutexes) now print a simpler traceback excluding runtime metadata (equivalent to a fatal panic) unless GOTRACEBACK=system or crash. Runtime-internal fatal error tracebacks always include full metadata regardless of the value of GOTRACEBACK

Support for debugger-injected function calls has been added on ARM64, enabling users to call functions from their binary in an interactive debugging session when using a debugger that is updated to make use of this functionality.

TODO: https://go.dev/issue/44853: enable address sanitizer in Go

Compiler

The compiler now uses a jump table to implement large integer and string switch statements. Performance improvements for the switch statement vary but can be on the order of 20% faster. (GOARCH=amd64 and GOARCH=arm64 only)

TODO: https://go.dev/cl/402374: enable regabi on riscv64 by default

The Go compiler now requires the -p=importpath flag to build a linkable object file. This is already supplied by the go command and by Bazel. Any other build systems that invoke the Go compiler directly will need to make sure they pass this flag as well.

Linker

On ELF platforms, the linker now emits compressed DWARF sections in the standard gABI format (SHF_COMPRESSED), instead of the legacy .zdebug format.

Core library

TODO: complete this section

New atomic types

The sync/atomic package defines new atomic types Bool, Int32, Int64, Uint32, Uint64, Uintptr, and Pointer. These types hide the underlying values so that all accesses are forced to use the atomic APIs. Pointer also avoids the need to convert to unsafe.Pointer at call sites. Int64 and Uint64 automatically receive 64-bit alignment on ARM, 386, and 32-bit MIPS required for 64-bit atomics on these systems.

Doc comment parsing

TODO: https://go.dev/cl/384265: go/doc: use go/doc/comment; modified api/next/51082.txt TODO: https://go.dev/cl/397276: go/doc/comment: add data structures; modified api/next/51082.txt TODO: https://go.dev/cl/397278: go/doc/comment: add paragraph parsing and test framework; modified api/next/51082.txt TODO: https://go.dev/cl/397279: go/doc/comment: add Printer and basic comment printing; modified api/next/51082.txt TODO: https://go.dev/cl/397281: go/doc/comment: parse and print doc links; modified api/next/51082.txt TODO: https://go.dev/cl/397284: go/doc/comment: parse and print headings; modified api/next/51082.txt

PATH lookups

TODO: https://go.dev/issue/43724: return error when PATH lookup would use current directory

TODO: https://go.dev/issue/43947: on Windows use NeedCurrentDirectoryForExePathW for LookPath behavior

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.

TODO: complete this section

archive/zip

TODO: https://go.dev/cl/387976: permit zip files to have prefixes

crypto/rand

Read no longer buffers random data obtained from the operating system between calls.

On Plan 9, Read has been reimplemented, replacing the ANSI X9.31 algorithm with fast key erasure.

crypto/tls

The tls10default GODEBUG option has been removed. It is still possible to enable TLS 1.0 client-side by setting Config.MinVersion.

The TLS server and client now reject duplicate extensions in TLS handshakes, as required by RFC 5246, Section 7.4.1.4 and RFC 8446, Section 4.2.

crypto/x509

CreateCertificate no longer supports creating certificates with SignatureAlgorithm set to MD5WithRSA.

CreateCertificate no longer accepts negative serial numbers.

ParseCertificate and ParseCertificateRequest now reject certificates and CSRs which contain duplicate extensions.

The new CertPool.Clone and CertPool.Equal methods allow cloning a CertPool and checking the equality of two CertPools respectively.

The new function ParseRevocationList provides a faster, safer to use CRL parser which returns a RevocationList. To support this addition, RevocationList adds new fields RawIssuer, Signature, AuthorityKeyId, and Extensions. The new method RevocationList.CheckSignatureFrom checks that the signature on a CRL is a valid signature from a Certificate. With the new CRL functionality, the existing functions ParseCRL and ParseDERCRL are deprecated. Additionally the method Certificate.CheckCRLSignature is deprecated.

When building paths, Certificate.Verify now considers certificates to be equal when the subjects, public keys, and SANs are all equal. Before, it required byte-for-byte equality.

TODO: https://go.dev/issue/46057: add CertPool.Equal

TODO: https://go.dev/issue/50674: add ParseRevocationList, deprecate ParseCRL & ParseDERCRL

TODO: https://go.dev/cl/390834: crypto/x509: add new CRL parser, deprecate old one; modified api/next/50674.txt

TODO: https://go.dev/cl/400175: crypto/x509: add CertPool.Clone; modified api/next/35044.txt TODO: https://go.dev/issue/35044: add CertPool.Clone

crypto/x509/pkix

The types CertificateList and TBSCertificateList have been deprecated. The new crypto/x509 CRL functionality should be used instead.

debug

TODO: https://go.dev/cl/396735: debug: define ELF relocation for loong64; modified api/next/46229.txt

debug/pe

TODO: https://go.dev/issue/51868: add APIs to support reading COMDAT info for sections

TODO: https://go.dev/cl/394534: debug/pe: add APIs for reading section def aux info; modified api/next/51868.txt

encoding/binary

TODO: https://go.dev/cl/386017: add AppendByteOrder

TODO: https://go.dev/issue/51644: add AppendUvarint and AppendVarint

encoding/csv

TODO: https://go.dev/cl/405675: add Reader.InputOffset method

encoding/xml

TODO: https://go.dev/issue/45628: add Decoder.InputPos TODO: https://go.dev/cl/311270: encoding/xml: expose decoder line and column; modified api/next/45628.txt

flag

TODO: https://go.dev/cl/313329: add TextVar function

fmt

TODO: https://go.dev/cl/406177: add Append, Appendln, Appendf

go/parser

TODO: https://go.dev/cl/403696: parser to accept ~x as unary expression

go/types

The new methods Func.Origin and Var.Origin return the corresponding Object of the generic type for synthetic Func and Var objects created during type instantiation.

It is no longer possible to produce an infinite number of distinct-but-identical Named type instantiations via recursive calls to Named.Underlying or Named.Method.

hash/maphash

TODO: https://go.dev/cl/392494: hash/maphash: add Bytes and String; modified api/next/42710.txt TODO: https://go.dev/issue/42710: add Bytes and String

html/template

TODO: https://go.dev/issue/46121: make FuncMap an alias for text/template.FuncMap TODO: https://go.dev/cl/389156: html/template: make FuncMap a type alias of text/template.FuncMap; modified api/except.txt, api/next/46121.txt

image/draw

Draw with the Src operator preserves non-premultiplied-alpha colors when destination and source images are both *image.NRGBA (or both *image.NRGBA64). This reverts a behavior change accidentally introduced by a Go 1.18 library optimization, to match the behavior in Go 1.17 and earlier.

io

TODO: https://go.dev/cl/400236: NopCloser forward WriterTo implementations if the reader supports it

TODO: https://go.dev/issue/50842: implement WriterTo on result of MultiReader

mime

On Windows only, the mime package now ignores a registry entry recording that the extension .js should have MIME type text/plain. This is a common unintentional misconfiguration on Windows systems. The effect is that .js will have the default MIME type text/javascript; charset=utf-8. Applications that expect text/plain on Windows must now explicitly call AddExtensionType.

net

The pure Go resolver will now use EDNS(0) to include a suggested maximum reply packet length, permitting reply packets to contain up to 1232 bytes (the previous maximum was 512). In the unlikely event that this causes problems with a local DNS resolver, setting the environment variable GODEBUG=netdns=cgo to use the cgo-based resolver should work. Please report any such problems on the issue tracker.

When a net package function or method returns an "I/O timeout" error, the error will now satisfy errors.Is(err, context.DeadlineExceeded). When a net package function returns an "operation was canceled" error, the error will now satisfy errors.Is(err, context.Canceled). These changes are intended to make it easier for code to test for cases in which a context cancellation or timeout causes a net package function or method to return an error, while preserving backward compatibility for error messages.

Resolver.PreferGo is now implemented on Windows and Plan 9. It previously only worked on Unix platforms. Combined with Dialer.Resolver and Resolver.Dial, it's now possible to write portable programs and be in control of all DNS name lookups when dialing.

The net package now has initial support for the netgo build tag on Windows. When used, the package uses the Go DNS client (as used by Resolver.PreferGo) instead of asking Windows for DNS results. The upstream DNS server it discovers from Windows may not yet be correct with complex system network configurations, however.

net/http

ResponseWriter.WriteHeader now supports sending user-defined 1xx informational headers.

The io.ReadCloser returned by MaxBytesReader will now return the defined error type MaxBytesError when its read limit is exceeded.

The HTTP client will handle a 3xx response without a Location header by returning it to the caller, rather than treating it as an error.

net/url

The new JoinPath function and URL.JoinPath method create a new URL by joining a list of path elements.

The URL type now distinguishes between URLs with no authority and URLs with an empty authority. For example, http:///path has an empty authority (host), while http:/path has none.

The new URL field OmitHost is set to true when a URL has an empty authority.

os

TODO: https://go.dev/cl/392415: raise open file rlimit at startup

os/exec

An exec.Cmd with a non-empty Dir and a nil Env now implicitly sets the PWD environment variable for the subprocess to match Dir.

The new method (*exec.Cmd).Environ reports the environment that would be used to run the command, including the aforementioned PWD variable.

reflect

The method Value.Bytes now accepts addressable arrays in addition to slices.

The methods Value.Len and Value.Cap now successfully operate on a pointer to an array and return the length of that array, to match what the builtin len and cap functions do.

regexp

TODO: https://go.dev/issue/51684: add ErrNestingDepth error TODO: https://go.dev/cl/401076: regexp: change ErrInvalidDepth message to match proposal; modified api/next/51684.txt, api/next/regexpdepth.txt

regexp/syntax

TODO: https://go.dev/cl/384617: regexp/syntax: add and use ErrInvalidDepth; modified api/next/regexpdepth.txt TODO: https://go.dev/cl/401854: regexp/syntax: rename ErrInvalidDepth to ErrNestingDepth; modified api/next/51684.txt

runtime

The GOROOT function now returns the empty string (instead of "go") when the binary was built with the -trimpath flag set and the GOROOT variable is not set in the process environment.

runtime/debug

TODO: https://go.dev/cl/397018: runtime/debug: export SetMemoryLimit; modified api/next/48409.txt

runtime/metrics

The new /sched/gomaxprocs:threads metric reports the current runtime.GOMAXPROCS value.

The new /cgo/go-to-c-calls:calls metric reports the total number of calls made from Go to C. This metric is identical to the runtime.NumCgoCall function.

The new /gc/limiter/last-enabled:gc-cycle metric reports the last GC cycle when the GC CPU limiter was enabled. See the runtime notes for details about the GC CPU limiter.

runtime/pprof

Stop-the-world pause times have been significantly reduced when collecting goroutine profiles, reducing the overall latency impact to the application.

MaxRSS is now reported in heap profiles for all Unix operating systems (it was previously only reported for GOOS=android, darwin, ios, and linux).

runtime/race

The race detector has been upgraded to use thread sanitizer version v3 on all supported platforms except windows/amd64 and openbsd/amd64, which remain on v2. Compared to v2, it is now typically 1.5x to 2x faster, uses half as much memory, and it supports an unlimited number of goroutines.

The race detector is now supported on GOARCH=s390x.

Race detector support for openbsd/amd64 has been removed from thread sanitizer upstream, so it is unlikely to ever be updated from v2.

runtime/trace

When tracing and the CPU profiler are enabled simultaneously, the execution trace includes CPU profile samples as instantaneous events.

sort

The sorting algorithm has been rewritten to use pattern-defeating quicksort, which is faster for several common scenarios.

TODO: https://go.dev/issue/50340: add Find TODO: https://go.dev/cl/396514: sort: add Find function; modified api/next/50340.txt

strconv

Quote and related functions now quote the rune 007F as \x7f, not \u007f.

syscall

On PowerPC (GOARCH=ppc64, ppc64le), Syscall, Syscall6, RawSyscall, and RawSyscall6 now always return 0 for return value r2 instead of an undefined value.

On AIX and Solaris, Getrusage is now defined.

time

TODO: https://go.dev/cl/393515: add Duration.Abs TODO: https://go.dev/issue/51414: add Duration.Abs

TODO: https://go.dev/issue/50062: add Time.ZoneBounds TODO: https://go.dev/cl/405374: time: add Time.ZoneBounds; modified api/next/50062.txt