diff options
| author | Austin Clements <austin@google.com> | 2021-03-15 16:23:21 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2021-03-18 16:51:24 +0000 |
| commit | af4388aee195c4328a779ba8f8171ad1632feb7e (patch) | |
| tree | b3b6ad2a85303649ef7342f2278bfde88d46c7cd /src/cmd/internal/objabi | |
| parent | 6461d74bf203925c981c889034ac5f713dc9db0b (diff) | |
| download | go-af4388aee195c4328a779ba8f8171ad1632feb7e.tar.xz | |
cmd/internal/objabi: support boolean GOEXPERIMENTs
Currently, objabi exports GOEXPERIMENT flags as ints that are either 0
or 1. Since the dawn of time, there's been a comment saying that we
*could* support general integers here, but it's never happened and all
the "== 0" and "!= 0" and "== 1" are driving me crazy and are making
the code harder to read and maintain. Hence, this CL adds support for
boolean GOEXPERIMENT flags. We'll introduce some bool-typed flags in
the next CL.
Change-Id: I7813400db130a9b8f71a644fe7912808dbe645bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/302069
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/objabi')
| -rw-r--r-- | src/cmd/internal/objabi/util.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index 9308a6d2eb..8c96ceca35 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -157,17 +157,22 @@ func init() { var Framepointer_enabled = GOARCH == "amd64" || GOARCH == "arm64" func addexp(s string) { - // Could do general integer parsing here, but the runtime copy doesn't yet. - v := 1 + // Could do general integer parsing here, but the runtime.haveexperiment doesn't yet. + v, vb := 1, true name := s if len(name) > 2 && name[:2] == "no" { - v = 0 + v, vb = 0, false name = name[2:] } for i := 0; i < len(exper); i++ { if exper[i].name == name { - if exper[i].val != nil { - *exper[i].val = v + switch val := exper[i].val.(type) { + case *int: + *val = v + case *bool: + *val = vb + default: + panic("bad GOEXPERIMENT type for " + s) } return } @@ -189,7 +194,7 @@ var ( // variable recorded when the toolchain is built. var exper = []struct { name string - val *int + val interface{} // Must be *int or *bool }{ {"fieldtrack", &Fieldtrack_enabled}, {"preemptibleloops", &Preemptibleloops_enabled}, @@ -204,8 +209,15 @@ var defaultExpstring string func expList() string { buf := "" for i := range exper { - if *exper[i].val != 0 { - buf += "," + exper[i].name + switch val := exper[i].val.(type) { + case *int: + if *val != 0 { + buf += "," + exper[i].name + } + case *bool: + if *val { + buf += "," + exper[i].name + } } } if len(buf) == 0 { |
