package main
import (
"reflect"
"runtime"
)
func f(n int) int {
return n % 2
}
func g(n int) int {
return f(n)
}
func name(fn any) (res string) {
return runtime.FuncForPC(uintptr(reflect.ValueOf(fn).Pointer())).Name()
}
func main() {
println(name(f))
println(name(g))
}
Prints
where it should print
This happens because the first instruction of g is an instruction inlined from f.
This came up recently because the scheduler change https://go-review.googlesource.com/c/go/+/270940 subtly changes the ordering, and line numbering, of assembly instructions at the start of functions.
Prints
where it should print
This happens because the first instruction of
gis an instruction inlined fromf.This came up recently because the scheduler change https://go-review.googlesource.com/c/go/+/270940 subtly changes the ordering, and line numbering, of assembly instructions at the start of functions.