Go 1.17, the latest release of the open source, Google-developed programming language, is now available as a production release, with changes intended to simplify coding for safety.
Go 1.17 was published on August 16. Release notes cite three small enhancements to the language, including two intended to simplify writing code that conforms to
unsafe.Pointer’s safety rules. The three 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. 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 code pointer function for each place that the function is inlined.
Pruned module graphs are introduced in this release. Module graphs of modules that specify Go 1.17 or higher in their go.mod file will include only the immediate dependencies of other Go 1.17 modules, not their full transitive dependencies.
Go 1.17 can be downloaded from golang.org. The previous 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. Go 1.17 went into a beta release stage on June 10.
Copyright © 2021 IDG Communications, Inc.