Slide 1

Slide 1 text

Go1.25 リリースパーティ ~ nil pointer bug ~ 09/30/2025 sivchari newmo Inc The Go gopher was designed by Renée French.

Slide 2

Slide 2 text

自己紹介

Slide 3

Slide 3 text

● sivchari ○ X/GitHub @sivchari ● newmo ● Kubernetes maintainer ○ Cluster API ○ Kube API Linter ● Go Conference メインオーガナイザー

Slide 4

Slide 4 text

Go1.25からのCompiler

Slide 5

Slide 5 text

{ Go1.25のCompiler ● nil pointer bug ● DWARF5 support ● Faster slices

Slide 6

Slide 6 text

{ Go1.25のCompiler ● nil pointer bug ● DWARF5 support ● Faster slices

Slide 7

Slide 7 text

nil pointer bug

Slide 8

Slide 8 text

nil pointer bug m := map[string]*struct { field int }{} v, ok := m[“key”] valid := v.field >= 0 // 1 if !ok { println(“mark”) return } println(valid) // 2 Go N <= 1.24 panic or not?

Slide 9

Slide 9 text

nil pointer bug m := map[string]*struct { field int }{} v, ok := m[“key”] valid := v.field >= 0 // 1 if !ok { println(“mark”) return } println(valid) // 2 Go N <= 1.24 panic or not?

Slide 10

Slide 10 text

nil pointer bug m := map[string]*struct { field int }{} v, ok := m[“key”] valid := v.field >= 0 // 1 if !ok { println(“mark”) return } println(valid) // 2 Go N >= 1.24 panic or not?

Slide 11

Slide 11 text

nil pointer bug m := map[string]*struct { field int }{} v, ok := m[“key”] valid := v.field >= 0 // 1 if !ok { println(“mark”) return } println(valid) // 2 Go N >= 1.24 panic or not?

Slide 12

Slide 12 text

CompilerとMemory Model

Slide 13

Slide 13 text

CompilerとMemory Model ● Issue #72860 ○ Go1.21で行ったコンパイラ最適化が問題 ○ Compilerが遅延評価していた ○ compiler/ssa/internal/tighten.go

Slide 14

Slide 14 text

CompilerとMemory Model ● GoのMemory Modelに違反する Requirement 1: The memory operations in each goroutine must correspond to a correct sequential execution of that goroutine, given the values read from and written to memory. That execution must be consistent with the sequenced before relation, defined as the partial order requirements set out by the Go language specification for Go's control flow constructs as well as the order of evaluation for expressions.

Slide 15

Slide 15 text

CompilerとMemory Model ● Memory Modelとの不一致 ○ 最適化がされても実行順序は維持されている 必要がある(Sequenced before)

Slide 16

Slide 16 text

CompilerとMemory Model m := map[string]*struct { field int }{} v, ok := m[“key”] valid := v.field >= 0 // 1 if !ok { println(“mark”) return } println(valid) // 2 valid is sequenced before `if !ok`

Slide 17

Slide 17 text

CompilerとMemory Model m := map[string]*struct { field int }{} v, ok := m[“key”] if !ok { println(“mark”) return } valid := v.field >= 0 // 1 println(valid) // 2 valid is sequenced before `if !ok`

Slide 18

Slide 18 text

CompilerとMemory Model if opcodeTable[v.Op].nilCheck { // Nil checks need to stay in their block. See issue 72860. continue } CL 657715

Slide 19

Slide 19 text

CompilerとMemory Model b4: ← b2 LoweredNilCheck v44 v40 GOSSAFUNC=main GOTOOLCHAIN=go1.24.0 go build main.go

Slide 20

Slide 20 text

CompilerとMemory Model b2: LoweredNilCheck v44 v40 GOSSAFUNC=main GOTOOLCHAIN=go1.25.0 go build main.go

Slide 21

Slide 21 text

まとめ

Slide 22

Slide 22 text

● Go1.25からコンパイラ最適化が修正された ● Goとしてのバグである ● リンター作成してみると面白いかも