-
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
cmd/vet: warn when iterating over an array #18626
Comments
I'm also thinking about this. This is definitely not a correctness issue,
but it did have major performance implications (when the array is large
enough)
The reason I support this check being in cmd/vet is that this kind of
issues is far from trivial and we current lack any facilities to catch
excess stack usage (even if we have have stack usage tests, the developer
still need to remember to use it, and determining the correct threshold is
also very difficult and the correct threshold could change from release to
release due to compiler improvements.)
Of course, determine the correct warning threshold would be the hard part
of this issue. I think anything more than a few kB is suspicious.
|
|
It is correct to do so, and can even be the right thing to do in many cases. It's therefore not something that vet can complain about. (See the src/cmd/vet/README for details.) Perhaps golint is a better choice. Feel free to suggest that. |
@robpike, I've been thinking about a possible use case for this,
but couldn't think of any except when you also want to modify
the array in the loop body. Is that what you have in mind?
Any other use cases? If we do make a golint pass, we might
need to exclude this case.
|
It's not obvious to me that this is a style issue. Even if it were, However, I can see why this doesn't quite fit |
I don't think it's a fit for any of my tools, either, for essentially the same reason as for why it shouldn't go into vet. |
See #18625 for an interesting bug where large stack growth was caused by this. To avoid false positives, maybe vet should only warn if the array size exceeds some number of bytes?
\cc @robpike @dominikh @minux
The text was updated successfully, but these errors were encountered: