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
carlmjohnson opened this issue Oct 9, 2019 · 5 comments
Closed

Comments

@carlmjohnson
Copy link
Contributor

@carlmjohnson carlmjohnson commented Oct 9, 2019

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

@randall77 randall77 commented Oct 9, 2019

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?

@carlmjohnson
Copy link
Contributor Author

@carlmjohnson carlmjohnson commented Oct 9, 2019

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 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 rsc added this to Incoming in Proposals Dec 4, 2019
@rsc
Copy link
Contributor

@rsc rsc commented Jan 15, 2020

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

@rsc rsc moved this from Incoming to Likely Decline in Proposals Jan 15, 2020
@rsc
Copy link
Contributor

@rsc rsc commented Jan 22, 2020

No change in consensus, so declined.

@rsc rsc moved this from Likely Decline to Declined in Proposals Jan 22, 2020
@golang golang locked and limited conversation to collaborators Jan 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Proposals
Declined
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants