Skip to content
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

Closed
earthboundkid opened this issue Oct 9, 2019 · 5 comments

Comments

@earthboundkid
Copy link
Contributor

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 that go 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.

@smasher164 smasher164 changed the title Feature request: Magic comment to have go vet check that variable is stack allocated cmd/vet: magic comment to check that variable is stack allocated Oct 9, 2019
@randall77
Copy link
Contributor

You can write a test using AllocsPerRun in the testing package, to ensure that some function doesn't allocate more than you expect. Is that insufficient somehow?

@earthboundkid
Copy link
Contributor Author

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.

@andybons andybons changed the title cmd/vet: magic comment to check that variable is stack allocated proposal: cmd/vet: magic comment to check that variable is stack allocated Oct 10, 2019
@gopherbot gopherbot added this to the Proposal milestone Oct 10, 2019
@rsc
Copy link
Contributor

rsc commented Dec 4, 2019

Go vet is about detecting common mistakes.
It is out of scope to start designing vet-specific annotations and/or type-checking,
and it is also out of scope to tie anything in vet to a single compiler.

@rsc
Copy link
Contributor

rsc commented Jan 15, 2020

Based on the discussion above, this seems like a likely decline.

@rsc
Copy link
Contributor

rsc commented Jan 22, 2020

No change in consensus, so declined.

@golang golang locked and limited conversation to collaborators Jan 21, 2021
@rsc rsc moved this to Declined in Proposals Aug 10, 2022
@rsc rsc added this to Proposals Aug 10, 2022
@rsc rsc removed this from Proposals Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants