Go version
go1.23
Output of go env in your module/workspace:
What did you do?
Compile the following:
package main
import "archive/tar"
var src []tar.Header
var dst *tar.Header
func main() {
for i := range src {
dst = &src[i] // line 10
}
}
What did you see happen?
I see this compiled out:
...
0x0069 00105 (main.go:10) PCDATA $1, $0
0x0069 00105 (main.go:10) CALL runtime.panicIndex(SB)
0x006e 00110 (main.go:10) XCHGL AX, AX
...
What did you expect to see?
No such call to runtime.panicIndex. The slice is indexed from an iteration integer that is provably bounded by the length of src itself. The only possible way a panic occurs is if src is mutated during the iteration (or asynchronously in another goroutine, in which case there must be synchronization primitives).
Go version
go1.23
Output of
go envin your module/workspace:What did you do?
Compile the following:
What did you see happen?
I see this compiled out:
What did you expect to see?
No such call to
runtime.panicIndex. The slice is indexed from an iteration integer that is provably bounded by the length ofsrcitself. The only possible way a panic occurs is ifsrcis mutated during the iteration (or asynchronously in another goroutine, in which case there must be synchronization primitives).