New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: method values cause receiver to escape to the heap #27557
Comments
We probably can treat the method expression the same way as closures, which will probably solve this. |
This seems fixed with the latest master (
|
@agnivade Thanks for checking. The To explain the diagnostics, This issue is about how OCALLPART is analyzed: go/src/cmd/compile/internal/gc/escape.go Lines 519 to 526 in 744fcfe
Currently we always flow the receiver argument (i.e., For example, we need to make sure
|
Change https://golang.org/cl/197137 mentions this issue: |
One additional caveat I realized looking at this again is that scc.go needs to be updated to recognize OCALLPART. |
This commit just adds a regress test for a few of the important corner cases that I identified in #27557, which turn out to not be tested anywhere. While here, annotate a few of the existing test cases where we could improve escape analysis. Updates #27557. Change-Id: Ie57792a538f7899bb17915485fabc86100f469a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/197137 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Change https://golang.org/cl/228263 mentions this issue: |
What did you do?
In this minimal code example, functions
f1
andf2
both take an argumentt
and call itsfoo
method.t1
calls the method directly;t2
uses a method value.See this golang-nuts thread for background.
What did you expect to see?
The value
t
allocated on the stack in both functions.What did you see instead?
In function
f2
,t
escapes to the heap.I understand that method values involve making a copy of the receiver (a pointer in this case). But if the compiler can figure out that
t
doesn't escape fromf1
, why can't it do the same forf2
?Does this issue reproduce with the latest release (go1.11)?
Yes.
System details
The text was updated successfully, but these errors were encountered: