Fundamentals 4 min read

Go 1.20 Release Candidate Highlights: New Slice‑to‑Array Conversion, Unsafe Package Functions, and Comparable Types

Go 1.20 RC1 introduces experimental RISC‑V/FreeBSD support, expands slice‑to‑array conversion, adds three new unsafe package functions, updates comparable type constraints, and changes struct value comparison order, while being the final version compatible with macOS 10.13/10.14, with download details provided.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Go 1.20 Release Candidate Highlights: New Slice‑to‑Array Conversion, Unsafe Package Functions, and Comparable Types

Go 1.20 RC1 has been released, with the final version scheduled for February next year.

It is the last Go release that runs on macOS 10.13 High Sierra or 10.14 Mojave; Go 1.21 will require macOS 10.15 Catalina or later.

The release adds experimental support for RISC‑V on FreeBSD (GOOS=freebsd, GOARCH=riscv64).

Four syntax changes are introduced:

Slice‑to‑array conversion : Go 1.20 extends the slice‑to‑array‑pointer conversion added in Go 1.7, allowing direct conversion from a slice to an array.

New unsafe package functions : the unsafe package now defines SliceData , String , and StringData in addition to the existing unsafe.Slice , providing full construction and deconstruction of slices and strings.

Comparable type constraint : ordinary interfaces can satisfy the comparable constraint even when the type argument is not strictly comparable.

Struct value comparison order : when comparing struct values, fields are compared sequentially in declaration order, stopping at the first mismatch; this change does not affect existing code.

Example code for slice‑to‑array conversion and unsafe functions:

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(t)       // ok for nil slice t
t1 := (*[0]string)(t)    // t1 == nil
t2 := (*[1]string)(t)    // panics: len([1]string) > len(t)

u := make([]byte, 0)
u0 := (*[0]byte)(u)      // u0 != nil

For more details, see the Go language specification at https://tip.golang.org/ref/spec/#Package_unsafe.

Goprogramming languagesliceUnsafeRISC-VComparableGo1.20
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.