From: Austin Clements Date: Mon, 15 Mar 2021 20:23:21 +0000 (-0400) Subject: cmd/internal/objabi: support boolean GOEXPERIMENTs X-Git-Tag: go1.17beta1~1062 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=af4388aee195c4328a779ba8f8171ad1632feb7e;p=gostls13.git 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 Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- 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 {