-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: copylocks false positives #16227
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
Comments
I agree that false positives are a bane, and lean towards rolling back the new checks until we can reduce their frequency. |
The case with The case with *t = *types.NewStruct(p.fieldList(parent)) This case remains bogus even if the right hand side value contains newly created zero lock. |
The
This always copies the zero value, which is always OK. You may not like the style, but it's not wrong. And your fix changes a struct field from |
I think the |
Note that of the three warnings from
The other two are new on tip. |
@josharian , the old lock may be still in use. Probably other cases are possible. cc'ing @dvyukov , who may know more about such cases. |
@valyala there will always be stuff that vet doesn't catch. But false positives are worse than false negatives: They cause annoyance, they can cause people to write worse code to silence the tool, and worst of all, they can cause people to stop using the tool altogether. Unless the false positive rate is extremely low for a check, it's better for the check not to go in. I'd suggest that allowing assignment where the RHS is a struct literal in which all lock fields are zero is going to be a net win, taking into account both false positives and false negatives and their relative weight. |
@josharian cmd/vet does already allow an assignment where the RHS is a struct literal. The warning in go/internal/gcimporter is a different case: an assignment where the RHS is an indirection of a function call. |
|
There is another easy way to fix the warning without losing the efficiency - see the CL. |
@valyala I agree that that works, but I also agree with @josharian 's point: false positives from a tool like vet must be as low as possible. |
I see. I've been in the compiler too long--in my brain, that was getting inlined. If this is common enough, we could have vet do a bit of (semantic) inlining. But that's definitely way out of scope for 1.7. |
I changed cmd/vet to avoid these cases in https://golang.org/cl/24711 . Now we need to decide which approach to take. |
CL https://golang.org/cl/24711 mentions this issue. |
CL https://golang.org/cl/24693 mentions this issue. |
CL https://golang.org/cl/24694 mentions this issue. |
Don't issue a copylock warning about a result type; the function may return a composite literal with a zero value, which is OK. Don't issue a copylock warning about a function call on the RHS, or an indirection of a function call; the function may return a composite literal with a zero value, which is OK. Updates #16227. Change-Id: I94f0e066bbfbca5d4f8ba96106210083e36694a2 Reviewed-on: https://go-review.googlesource.com/24711 Reviewed-by: Josh Bleecher Snyder <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]>
Moving any remaining work to 1.8. It's actually not clear to me what work remains, but I will leave that for @josharian . |
I think we can call this closed. We'll open a new issue if new false positives arise. |
Examples from the standard library that I believe were introduced between Go 1.6 and Go 1.7.
cancelCtx
is a struct type containing a sync.Mutex. But all of these are just fine--in newCancelCtx (line 236), the sync.Mutex is (implicitly) being set to its zero value, which is fine. And since it is the zero value, and these are used as initializations of new values (lines 230, 375), they are also ok.Types.NewStruct
constructs a new struct and omits (implicitly zeros) the lock fields.I think we should consider rolling back the new checks for 1.7 and restoring them in 1.8 without these false positives. At least in the case of struct initialization, ignoring fields being initialized to the zero value will help. I'm not sure how to detect copying of values that are known to contain zero-valued locks. Marking Go 1.7; Rob can adjust milestone from there.
cc @valyala @robpike
The text was updated successfully, but these errors were encountered: