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

Open
carlmjohnson opened this issue Oct 9, 2019 · 2 comments

Comments

@carlmjohnson
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

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
@gopherbot gopherbot added the Proposal label Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.