-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: var _ = f prevents f from being dead-code eliminated #60464
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
Erm, no, no, no! This would, for instance, break the Ginkgo TDD framework, and in consequence Kubernetes. Probably lots of other projects too. Or am I misunderstanding the OP?
|
@thediveo I think what you're pointing to is an example of a function call whose return value is being assigned to the blank identifier. That shouldn't and wouldn't change behavior. The original issue is about a variable (involving no function calls) being assigned to the blank identifier, where no side-effects are possible. |
Specifically, Describe has side effects, so it can’t be eliminated. I think a function with no side effects would be safe to eliminate. |
CC @golang/compiler |
Does this also affect the |
This seems related to the same problems around deadcoding of unused global map variables, e.g. issues #2559 + #36021. The problem is that when you write
at the global scope, the compiler turns this into a fragment of the form
within the package "init" function. Since "init" is live if anything in the package is live, the variable itself is live, as well as anything referenced in the expression being assigned. Interestingly, if you do something like this:
The final assembly for "main" looks like:
e.g. the compiler has been able to optimize away the reference to I think the difference seems to be that in the init version, the final store is done to a real static temp, whereas in the local version the assign is done to a "_" pseudo var. AST for the local-to-main version:
AST for the global scope version:
|
Context: https://go.dev/cl/498595
This statement prevents
Config.EncryptTicket
from being dead-code eliminated:Seems like the compiler (linker?) could notice that the reference is dead and eliminate it.
The text was updated successfully, but these errors were encountered: