1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:07:09 -07:00
go/test/codegen/issue60324.go
Matthew Dempsky 7f1467ff4d cmd/compile: incorporate inlined function names into closure naming
In Go 1.17, cmd/compile gained the ability to inline calls to
functions that contain function literals (aka "closures"). This was
implemented by duplicating the function literal body and emitting a
second LSym, because in general it might be optimized better than the
original function literal.

However, the second LSym was named simply as any other function
literal appearing literally in the enclosing function would be named.
E.g., if f has a closure "f.funcX", and f is inlined into g, we would
create "g.funcY" (N.B., X and Y need not be the same.). Users then
have no idea this function originally came from f.

With this CL, the inlined call stack is incorporated into the clone
LSym's name: instead of "g.funcY", it's named "g.f.funcY".

In the future, it seems desirable to arrange for the clone's name to
appear exactly as the original name, so stack traces remain the same
as when -l or -d=inlfuncswithclosures are used. But it's unclear
whether the linker supports that today, or whether any downstream
tooling would be confused by this.

Updates #60324.

Change-Id: Ifad0ccef7e959e72005beeecdfffd872f63982f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/497137
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2023-05-22 22:47:15 +00:00

37 lines
805 B
Go

// asmcheck
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package codegen
func main() {
// amd64:"LEAQ\tcommand-line-arguments\\.main\\.f\\.g\\.h\\.func3"
f(1)()
// amd64:"LEAQ\tcommand-line-arguments\\.main\\.g\\.h\\.func2"
g(2)()
// amd64:"LEAQ\tcommand-line-arguments\\.main\\.h\\.func1"
h(3)()
// amd64:"LEAQ\tcommand-line-arguments\\.main\\.f\\.g\\.h\\.func4"
f(4)()
}
func f(x int) func() {
// amd64:"LEAQ\tcommand-line-arguments\\.f\\.g\\.h\\.func1"
return g(x)
}
func g(x int) func() {
// amd64:"LEAQ\tcommand-line-arguments\\.g\\.h\\.func1"
return h(x)
}
func h(x int) func() {
// amd64:"LEAQ\tcommand-line-arguments\\.h\\.func1"
return func() { recover() }
}