mirror of
https://github.com/golang/go
synced 2024-11-26 06:27:58 -07:00
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>
This commit is contained in:
parent
6461d74bf2
commit
af4388aee1
@ -157,17 +157,22 @@ func init() {
|
|||||||
var Framepointer_enabled = GOARCH == "amd64" || GOARCH == "arm64"
|
var Framepointer_enabled = GOARCH == "amd64" || GOARCH == "arm64"
|
||||||
|
|
||||||
func addexp(s string) {
|
func addexp(s string) {
|
||||||
// Could do general integer parsing here, but the runtime copy doesn't yet.
|
// Could do general integer parsing here, but the runtime.haveexperiment doesn't yet.
|
||||||
v := 1
|
v, vb := 1, true
|
||||||
name := s
|
name := s
|
||||||
if len(name) > 2 && name[:2] == "no" {
|
if len(name) > 2 && name[:2] == "no" {
|
||||||
v = 0
|
v, vb = 0, false
|
||||||
name = name[2:]
|
name = name[2:]
|
||||||
}
|
}
|
||||||
for i := 0; i < len(exper); i++ {
|
for i := 0; i < len(exper); i++ {
|
||||||
if exper[i].name == name {
|
if exper[i].name == name {
|
||||||
if exper[i].val != nil {
|
switch val := exper[i].val.(type) {
|
||||||
*exper[i].val = v
|
case *int:
|
||||||
|
*val = v
|
||||||
|
case *bool:
|
||||||
|
*val = vb
|
||||||
|
default:
|
||||||
|
panic("bad GOEXPERIMENT type for " + s)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -189,7 +194,7 @@ var (
|
|||||||
// variable recorded when the toolchain is built.
|
// variable recorded when the toolchain is built.
|
||||||
var exper = []struct {
|
var exper = []struct {
|
||||||
name string
|
name string
|
||||||
val *int
|
val interface{} // Must be *int or *bool
|
||||||
}{
|
}{
|
||||||
{"fieldtrack", &Fieldtrack_enabled},
|
{"fieldtrack", &Fieldtrack_enabled},
|
||||||
{"preemptibleloops", &Preemptibleloops_enabled},
|
{"preemptibleloops", &Preemptibleloops_enabled},
|
||||||
@ -204,8 +209,15 @@ var defaultExpstring string
|
|||||||
func expList() string {
|
func expList() string {
|
||||||
buf := ""
|
buf := ""
|
||||||
for i := range exper {
|
for i := range exper {
|
||||||
if *exper[i].val != 0 {
|
switch val := exper[i].val.(type) {
|
||||||
buf += "," + exper[i].name
|
case *int:
|
||||||
|
if *val != 0 {
|
||||||
|
buf += "," + exper[i].name
|
||||||
|
}
|
||||||
|
case *bool:
|
||||||
|
if *val {
|
||||||
|
buf += "," + exper[i].name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(buf) == 0 {
|
if len(buf) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user