-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: Unused interface methods don't get gc'd #42421
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
Comments
Thanks. Interesting example. I think the unused method is linked in because it is referenced from the itab. If you change foo.go to do
then UnusedInterfaceMethod disappears. I agree this is awkward, and we probably could fix the itab case. But it's too late for 1.16. Will try in 1.17. Thanks. |
I'm surprised there is any case in which an exported method is eliminated from a compiled binary. Reflection can reach it without ever naming it: https://play.golang.org/p/zCIdBYzv8zo. I think that's the reason the |
@zephyrtronium unused method elimination is disabled if use of reflection is detected. the approach to dead code elimination is described here. |
Change https://golang.org/cl/268479 mentions this issue: |
@cherrymui how are we doing? will this still make 1.17? this is pretty important for size-conscious projects like ours. |
Yes, it will make into 1.17. I have CLs above already. I need to rebase and get them in. Thanks. |
@cherrymui i see it's been approved, any reason it's not merged yet? |
Follow up to #38685 that seems to have solved a simple case but does not eliminate an unused interface method across packages
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
source:
What did you expect to see?
foobar/bar.(*Bar).UnusedInterfaceMethod
should not make it into the final binary.in fact, neither should
foobar/bar.(*Bar).UsedInterfaceMethod
because pointer variant is not used.in other words, all that should be left from
bar.Bar
should bebar.Bar.UsedInterfaceMethod
.interesting, that
foobar/bar.Bar.UnusedInterfaceMethod
does get eliminated but not thebar.*Bar
variant.why is it even generated in the first place?
What did you see instead?
The text was updated successfully, but these errors were encountered: