The Go Blog

Go 1.9 is released

Francesc Campoy
24 August 2017

Today the Go team is happy to announce the release of Go 1.9. You can get it from the download page. There are many changes to the language, standard library, runtime, and tooling. This post covers the most significant visible ones. Most of the engineering effort put into this release went to improvements of the runtime and tooling, which makes for a less exciting announcement, but nonetheless a great release.

The most important change to the language is the introduction of type aliases: a feature created to support gradual code repair. A type alias declaration has the form:

type T1 = T2

This declaration introduces an alias name T1 for the type T2, in the same way that byte has always been an alias for uint8. The type alias design document and an article on refactoring cover this addition in more detail.

The new math/bits package provides bit counting and manipulation functions for unsigned integers, implemented by special CPU instructions when possible. For example, on x86-64 systems, bits.TrailingZeros(x) uses the BSF instruction.

The sync package has added a new Map type, safe for concurrent access. You can read more about it from its documentation and learn more about why it was created from this GopherCon 2017 lightning talk (slides). It is not a general replacement for Go’s map type; please see the documentation to learn when it should be used.

The testing package also has an addition. The new Helper method, added to both testing.T and testing.B, marks the calling function as a test helper function. When the testing package prints file and line information, it shows the location of the call to a helper function instead of a line in the helper function itself.

For example, consider this test:

package p

import "testing"

func failure(t *testing.T) {
    t.Helper() // This call silences this function in error reports.
    t.Fatal("failure")
}

func Test(t *testing.T) {
    failure(t)
}

Because failure identifies itself as a test helper, the error message printed during Test will indicate line 11, where failure is called, instead of line 7, where failure calls t.Fatal.

The time package now transparently tracks monotonic time in each Time value, making computing durations between two Time values a safe operation in the presence of wall clock adjustments. For example, this code now computes the right elapsed time even across a leap second clock reset:

start := time.Now()
f()
elapsed := time.Since(start)

See the package docs and design document for details.

Finally, as part of the efforts to make the Go compiler faster, Go 1.9 compiles functions in a package concurrently.

Go 1.9 includes many more additions, improvements, and fixes. Find the complete set of changes, and more information about the improvements listed above, in the Go 1.9 release notes.

To celebrate the release, Go User Groups around the world are holding release parties.

Next article: Community Outreach Working Group
Previous article: Contribution Workshop
Blog Index