-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: cmd/vet: magic comment to check that variable is stack allocated #34798
Comments
You can write a test using |
That’s a good question. I see this mostly as a convenience feature to make it more simple. This would also be per variable rather than per function. |
Go vet is about detecting common mistakes. |
Based on the discussion above, this seems like a likely decline. |
No change in consensus, so declined. |
Go doesn't directly allow for heap vs. stack allocation, but this is critical to ensuring high performance. You can check that variables are properly stack allocated by asking Go to report what escapes to the heap with
-gcflags "-m"
but this is a manual process. I propose adding a magic comment thatgo vet
will use to check whether the variable ought to be stack allocated.The comment should have no actual effect on escape analysis. It will merely create a visible error if something is not allocated as intended.
The text was updated successfully, but these errors were encountered: