hp
toc

Crashing GC in 57 bytes

2024-05-27, post № 287

programming, #lang:go, #internal-compiler-error

Terser than GCC’s C++ (cf. 235), Go’s standard implementation can be forced to doubt itself in a mere 57 bytes:

$ go version
go version go1.22.1 linux/amd64
$ printf 'package main;func main(){panic(0);x:=0;l:for{goto l};_=x}' >/tmp/ice.go
$ wc -c /tmp/ice.go
57 /tmp/ice.go
$ go run /tmp/ice.go
# command-line-arguments
CLOSURE [/tmp/ice.go:1:56:var x int]
<unknown line number>: internal compiler error: assertion failed

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

Without having analyzed the compiler, black-box behavioural poking revealed that truly fickly a panic has to be followed with a variable declaration whose use entwines a label; else all one gets is an immediately-panicking or non-terminating executable:

package main

func main() {
	panic(0)

	x := 0

l:
	for {
		goto l
	}

	_ = x
}

At first, it irritates you, since⸺although you expect a plethora of compilation and test failures whilst developing⸺the error looks off. At closer inspection, a joyful rush grips you as you might be the first human being engaging in this specific dialogue with your compiler. So you stop everything else and golf away to extract an erroring nub. Whole swaths of code you rip out without a care for your program you once developed. The tiniest of changes⸺even ones which go in between equivalent source formulations⸺make the compiler snap out of its delusions, rendering it able to produce an executable. But you persevere, wanting the compiler to fail again and again at compiling a program without any use.

Cf. Go issue #67661

Jonathan Frech's blog; built 2024/11/02 16:03:59 CET