mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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>
20 lines
726 B
Go
20 lines
726 B
Go
// errorcheckwithauto -0 -m -d=inlfuncswithclosures=1
|
|
|
|
// Copyright 2022 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 foo
|
|
|
|
func r(z int) int {
|
|
foo := func(x int) int { // ERROR "can inline r.func1" "func literal does not escape"
|
|
return x + z
|
|
}
|
|
bar := func(x int) int { // ERROR "func literal does not escape" "can inline r.func2"
|
|
return x + func(y int) int { // ERROR "can inline r.func2.1" "can inline r.r.func2.func3"
|
|
return 2*y + x*z
|
|
}(x) // ERROR "inlining call to r.func2.1"
|
|
}
|
|
return foo(42) + bar(42) // ERROR "inlining call to r.func1" "inlining call to r.func2" "inlining call to r.r.func2.func3"
|
|
}
|