From 7f1467ff4ddd882acb318c0ffe24fd3702ce75cc Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 22 May 2023 13:25:15 -0700 Subject: 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 TryBot-Result: Gopher Robot Run-TryBot: Matthew Dempsky --- test/codegen/issue60324.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/codegen/issue60324.go (limited to 'test/codegen') diff --git a/test/codegen/issue60324.go b/test/codegen/issue60324.go new file mode 100644 index 0000000000..d106e7ecf8 --- /dev/null +++ b/test/codegen/issue60324.go @@ -0,0 +1,36 @@ +// 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() } +} -- cgit v1.3-5-g9baa