Go (golang) 1.17, the next release of the open source, Google-developed programming language, is now in a beta release stage, with changes intended to simplify coding for safety.
The first beta was published on June 10, with the production release expected in August. Release notes cite three small enhancements to the language, intended to simplify writing code that conforms to
unsafe.Pointer’s safety rules. These enhancements include:
- An expression
Tmay now be converted to array pointer type
ais the result of such a conversion, then corresponding indices that are in range refer to the same underlying elements:
&a[i] == &s[i] for 0 <= i < N. The conversion panics
if len(s)is less than
unsafe.Add: unsafe.Add(ptr, len)adds
ptrand returns the updated pointer
unsafe.Pointer(uintptr(ptr) + uintptr(len)).
unsafe.Slice: For expression ptr of type
*T, unsafe.Slice(ptr, len)returns a slice of type
Twhose underlying array starts at
ptrand whose length and capacity are
For the compiler, Go 1.17 implements a new way of passing function arguments and results using registers rather than the stack. This is enabled for Linux, MacOS, and Windows on the 64-bit x86 architecture. Benchmarking has shown a resulting performance improvement of about 5% and a typical reduction in binary size of about 2%. This change does not affect the functionality of safe Go code but can affect code outside the compatibility guidelines with minimal impacts. Also with the compiler, functions containing closures can be inlined. One effect of this is that a function with a closure may produce a distinct closure function for each place that the function is inlined. This change could reveal bugs where Go functions are incorrectly compared by pointer value. Go functions by definition are not comparable.
In the area of module loading, if a module specifies
go 1.17 or higher in its
go.mod file, its transitive requirements now are loaded lazily, avoiding the need to download or read
go.mod files for otherwise irrelevant dependencies. Also in Go 1.17, there are new warnings for
Unwrap methods. The
cover tool, meanwhile, now uses an optimized parser from
golang.org.x.tools/cover, which can be noticeably faster when parsing large overage files. There are also minor changes to the library.
Binary and source distributions for the Go 1.17 beta can be downloaded from golang.org. Those who have Go already installed can access the beta by using the following go command:
$ go get golang.org/dl/go1.17beta1
$ go1.17beta1 download
Predecessor release Go 1.16 was made available in February, featuring library and runtime enhancements. The current stable releases include Go 1.16.5 and Go 1.15.13. A fuzzing capability for Go developers is planned for a future release of the language.
Copyright © 2021 IDG Communications, Inc.