1
0
mirror of https://github.com/golang/go synced 2024-11-22 14:04:48 -07:00

[dev.regabi] cmd/compile: rewrite concurrentFlagOk to be clearer

The current implementation copies Debug, clears a bunch of flags
that are meant to be considered OK, and then checks the result
against the zero value. But more flags are cleared than remain:
it's easier to write and to understand to just check the ones that
need checking.

This phrasing also makes it safe to move more flags into the struct.

It turns out that some of the flags being checked should probably
not be checked, but this CL is meant to be a strict semantic no-op,
so left a TODO to clean up the function a bit more later.

Change-Id: I7afe6d7b32b5b889c40dd339568e8602e02df9bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/271666
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-11-15 11:40:25 -05:00
parent c754f25241
commit 7b144ed4f7

View File

@ -1418,24 +1418,18 @@ func IsAlias(sym *types.Sym) bool {
return sym.Def != nil && asNode(sym.Def).Sym != sym
}
// By default, assume any debug flags are incompatible with concurrent
// compilation. A few are safe and potentially in common use for
// normal compiles, though; return true for those.
// concurrentFlagOk reports whether the current compiler flags
// are compatible with concurrent compilation.
func concurrentFlagOk() bool {
// Report whether any debug flag that would prevent concurrent
// compilation is set, by zeroing out the allowed ones and then
// checking if the resulting struct is zero.
d := Debug
d.B = 0 // disable bounds checking
d.C = 0 // disable printing of columns in error messages
d.e = 0 // no limit on errors; errors all come from non-concurrent code
d.N = 0 // disable optimizations
d.l = 0 // disable inlining
d.w = 0 // all printing happens before compilation
d.W = 0 // all printing happens before compilation
d.S = 0 // printing disassembly happens at the end (but see concurrentBackendAllowed below)
return d == DebugFlags{}
// TODO(rsc): Many of these are fine. Remove them.
return Debug.P == 0 &&
Debug.E == 0 &&
Debug.K == 0 &&
Debug.L == 0 &&
Debug.h == 0 &&
Debug.j == 0 &&
Debug.m == 0 &&
Debug.r == 0
}
func concurrentBackendAllowed() bool {