The first RC of Go 1.20 has been released, and the official version is planned to be launched in February next year.

Download address: https://go.dev/dl/#go1.20rc1

It’s worth noting that Go 1.20 was the last version to support running on macOS 10.13 High Sierra or 10.14 Mojave. Go 1.21 will require macOS 10.15 Catalina or later.

Additionally, Go 1.20 adds support for FreeBSD on RISC-V (GOOS=freebsd, GOARCH=riscv64) for experimental support.

Go 1.20 currently contains 4 changes in syntax.

  • Conversion from slice (slice) to array

Go 1.7 added the function of converting from slice (slice) to array pointer, and Go 1.20 has extended this function – it can be directly converted from slice to array.

For example, given a slicex,[4]byte(x)can be written as*(*[4]byte)(x).


s := make([]byte, 2, 4)

a0 := [0]byte(s)
a1 := [1]byte(s[1:])     // a1[0] == s[1]
a2 := [2]byte(s)         // a2[0] == s[0]
a4 := [4]byte(s)         // panics: len([4]byte) > len(s)

s0 := (*[0]byte)(s)      // s0 != nil
s1 := (*[1]byte)(s[1:])  // &s1[0] == &s[1]
s2 := (*[2]byte)(s)      // &s2[0] == &s[0]
s4 := (*[4]byte)(s)      // panics: len([4]byte) > len(s)

var t []string
t0 := [0]string
t1 := (*[0]string)
t2 := (*[1]string)

u := make([]byte, 0)
u0 := (*[0]byte)(u)      // u0 != nil
  • standard libraryunsafeThe package defines 3 new functions:SliceData,StringandStringData

In Go 1.17,unsafeThe package adds the Slice function:

  • unsafe.Slice : for *T Type of ptr expression,unsafe.Slice(ptr, len) return a []T A slice of type whose underlying array is derived from ptr Initially, its length and capacity are len

Together with the 3 functions newly defined by Go 1.20, these 4 functions provide complete functions for constructing and deconstructing slices and string values.

See https://tip.golang.org/ref/spec/#Package_unsafe for details.

Comparable types such as ordinary interfaces can now satisfycomparableConstraints, even if the type arguments are not strictly comparable types.

The Go language specification has been updated. The value of a structure variable is only compared with one field at a time, and the order of field comparison is consistent with the order in which the fields are defined in the structure. Once the value comparison of a certain field is inconsistent, the comparison will stop immediately.

This change has no impact on the code.

Finally, since Go 1.20 is still in the development stage, the current public Release Notes are also in draft status.

#RC1 #released #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *