gvisor
gvisor copied to clipboard
tools/checklocks: support field comments for guard specifications
This allows specifying guards in the format:
type foo struct {
mu sync.Mutex
bar int // +checklocks:mu
}
This syntax, while more limited, makes writing lock guards less verbose for structures where field documentation isn't attached to each field. For example, being able to write something like the following with field comments reduces the number of lines in the struct by >25% and is, in my opinion, easier to read.
type widget struct {
mu sync.Mutex // guards following
// The following counters track [...]
success int // +checklocks:mu
failure int // +checklocks:mu
retries int // +checklocks:mu
timeouts int // +checklocks:mu
}
We already support field comments for checklocks, for example: https://github.com/google/gvisor/blob/344f19745f01cb407c714d2a8c95f43022a49ebd/pkg/tcpip/stack/stack.go#L95-L96
Ah, ^ are considered field.Doc and not field comments. LGTM.
@ayushr2 Thanks!