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/compile: reject unknown //go: comments in runtime (or std) #18331
Comments
CL https://golang.org/cl/34561 mentions this issue. |
Doing it for all go code looks easier. Tricky part is limiting this to runtime. |
There is a flag that gets passed to the compiler when compiling the runtime, so it should be straightforward. On my phone, but look for a variable in cmd/compile/internal/gc called something like compiling_runtime. :) |
Limiting to just std is harder, but one option is to add a new compiler flag to validate //go: comments, and have cmd/go pass it iff the package is in std. |
That would also help with testing, I suspect. |
CL https://golang.org/cl/34562 mentions this issue. |
I've taken a stab at this with https://go-review.googlesource.com/34562 as my afternoon project. |
@Dhananjay92 I was using my phone to get notifications about issues. Now I see that our CLs are both up to solve the same issue. Sure, let's coordinate on yours. I'll tag @josharian and @mdempsky as reviewers on your CL. |
Note that we shouldn't apply this restriction to code outside
std, because there are other implementations out there that
might define their own //go: magic comments, and it's valid
for programs to contain those magic comments if the code
is intended for both gc and the other implementation.
|
Yes, we should limit this check somehow to our code. I am waiting for us to reach some decision on whether to take an extra flag enabling this check, or try to deduce that with the help of So what does everyone think, should we take an extra flag or limit to only when Also, if we care about these in our repository only, why not implement this in a static checker, like govet? |
We've also had to fix instances where go: comments were line-wrapped elsewhere into a paragraph, so they were no longer treated as pragmas: golang.org/cl/12271. Not sure if that's something we can/want to try addressing at the same time.
Or in the Go repo's commit hook? |
We discussed this a bit on https://golang.org/cl/34378. The problem with govet is that we basically never run it on the runtime because it's incredibly noisy (the runtime has to do all sorts of things govet doesn't like). There are already several other runtime-specific checks in the compiler. Though AFAIK there are no std-specific checks. |
Actually, I spent a fair amount of time in the 1.8 cycle writing a vet runner with whitelists specifically so that we could run vet on std and cmd (and in the process fixed a lot of bugs in vet and std/cmd). However, it never got a builder set up for it, and it regressed almost every day. Evidence of its value, I suppose. Around the beginning of the freeze I stopped trying to keep up. When there is a builder set up for it (in Brad's court, AFAIK), we can do one more big push to get everything cleaned up and make it green and include it in the trybots. And at that point, we could rely on vet or a vet-like check.
As I mentioned above, if we wanted to do something like this for std in the compiler, I'd suggest adding a compiler flag specifically to check this, and then arrange for cmd/go to send it into the compiler when compiling std. This is good for testing, and others who use magic go comments could also add it to their own gcflags. |
CL https://golang.org/cl/45010 mentions this issue. |
The compiler should fail if it finds an unknown //go: comment in the runtime, or possibly anywhere in std. We've had a few CLs fixing typos in these: https://golang.org/cl/34377 (crypto/aes), https://golang.org/cl/34378 (runtime).
/cc @randall77 @griesemer @minux
The text was updated successfully, but these errors were encountered: