]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objabi: support boolean GOEXPERIMENTs
authorAustin Clements <austin@google.com>
Mon, 15 Mar 2021 20:23:21 +0000 (16:23 -0400)
committerAustin Clements <austin@google.com>
Thu, 18 Mar 2021 16:51:24 +0000 (16:51 +0000)
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>
src/cmd/internal/objabi/util.go

index 9308a6d2ebc99a75d834b7b925b66a771750a262..8c96ceca358c1193b2dacd939fcada3e5695252b 100644 (file)
@@ -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 {