Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: escape analysis of interface calls to unexported method names #16001
Consider this Go source:
At the f.f(&i) call site in H, we can't be sure exactly what method will be called. However, since it's an unexported method name, it must be implemented by a method in the same package. Consequently, if we know that all candidate methods in the package are non-escaping (such as A.f and B.f are), we can still be sure that f.f(&i) is a non-escaping call.
Note that we still have to consider A.f even though A itself doesn't implement Fer, because a downstream package could do something like:
There are probably refinements that could avoid this though.
I happened to notice this because of package net's "exchange" function, which calls the unexported TCPConn.dnsRoundTrip or UDPConn.dnsRoundTrip methods. I haven't investigated how common this situation is though.