-
Notifications
You must be signed in to change notification settings - Fork 18k
sync/atomic: remove noCopy from Value #21504
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
/cc @josharian |
Change https://golang.org/cl/56671 mentions this issue: |
….Value Using atomic.Value causes vet errors in code copying PublicKey or PrivateKey structures. I don't think the errors are accurate, but it's easier to work around them than to change vet or change atomic.Value. See #21504. Change-Id: I3a3435c1fc664cc5166c81674f6f7c58dab35f21 Reviewed-on: https://go-review.googlesource.com/56671 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Adam Langley <agl@golang.org>
Change https://golang.org/cl/57941 mentions this issue: |
…atomic.Value Using atomic.Value causes vet errors in code copying PublicKey or PrivateKey structures. I don't think the errors are accurate, but it's easier to work around them than to change vet or change atomic.Value. See #21504. Change-Id: I3a3435c1fc664cc5166c81674f6f7c58dab35f21 Reviewed-on: https://go-review.googlesource.com/56671 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Adam Langley <agl@golang.org> Reviewed-on: https://go-review.googlesource.com/57941
A different solution might be to ignore the noCopy property on initialization in a pure literal expression. Before assigning the result of a literal to a specific value there are no concurrency issues to worry about. So the false positive is actually a vet bug related to literals and it might make sense to track and treat it as such after closing this issue. Note: Pure literal expression means constructed by either trivial assignments of other literals or constants or by calling pure functions (as in https://en.wikipedia.org/wiki/Pure_function). |
I wasn't able to reproduce the false positive in the report: package main
import (
"sync/atomic"
)
type Y struct {
v atomic.Value
}
type X struct {
Y Y
}
func main() {
var x X
// None of these trigger the vet nocopy check:
x = X{
Y: Y{},
}
x.Y = Y{}
// This does, though:
y := x.Y
} Also at https://play.golang.org/p/MfsefrZzGB. |
Maybe @rsc was just running into a vet bug of some kind. (Perhaps even one that has been fixed?) I'm thinking of #16227 or #13675. However, I agree that atomic.Value shouldn't have noCopy because its stated copying semantics are more complicated than "do not copy an atomic.Value". I guess this program should be okay(?) but vet warns about it: package main
import (
"fmt"
"sync/atomic"
)
func main() {
var v0 atomic.Value
v1 := v0 // assignment copies lock value to v1: sync/atomic.Value contains sync/atomic.noCopy
v0.Store(3)
v1.Store(4)
fmt.Println(v0.Load())
fmt.Println(v1.Load())
} |
Change https://golang.org/cl/80836 mentions this issue: |
The noCopy in sync/atomic.Value is causing false positives in my code.
The comment on Value says
But the vet check triggers all the time, not just after the first Store call. In particular it triggers when initializing a composite literal like
where Y has a sync.Value in it. In my particular code, in order to keep it vet-safe, I am going to have to use an unsafe.Pointer instead, which is terrible. I shouldn't be forced into unsafe code because of a bad annotation.
It's probably too late for Go 1.9, but we should take noCopy out for Go 1.10, especially if we manage to turn vet on by default.
The text was updated successfully, but these errors were encountered: