]> Cypherpunks repositories - gostls13.git/commit
cmd/go: define a build tag for any GOEXPERIMENT which is enabled.
authorDan Scales <danscales@google.com>
Wed, 11 Mar 2020 19:08:03 +0000 (12:08 -0700)
committerDan Scales <danscales@google.com>
Mon, 23 Mar 2020 19:24:26 +0000 (19:24 +0000)
commit5113f5776620dfd0221bb876b9889c73d585371c
tree05d51bce9ea4d6ef4b8848228eec58a0d4650c9e
parent6aded2524cb77eeab907e64512c5f7c54b530756
cmd/go: define a build tag for any GOEXPERIMENT which is enabled.

For each experiment that has been enabled in the toolchain, define a build tag
with the same name (but prefixed by "goexperiment.") which can be used for
compiling alternative files for the experiment. This allows changes for the
experiment, like extra struct fields in the runtime, without affecting the base
non-experiment code at all.

I use this capability in my CL for static lock ranking
(https://go-review.googlesource.com/c/go/+/207619), so that static lock ranking
can be fully enabled as a GOEXPERIMENT, but there is no overhead in the runtime
when the experiment is not enabled.

I added a test in cmd/go/testdata/scripts to make sure the build tags are being
defined properly. In order to implement the test, I needed to provide environment
variable GOEXPSTRING to the test scripts (with its value set from
objabi.Expstring(), so that it can determine the experiments baked into the
toolchain.

I filed https://github.com/golang/go/issues/37937 to make a builder with
GOEXPERIMENT set to 'staticlockranking'. This builder will ensure another variant
of GOEXPERIMENT is being tested regularly for this change, as well as checking
static lock ranking in the runtime.

Change-Id: Ieb4b86107238febd105558c1e639d30cfe57ab5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/222925
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/work/init.go
src/cmd/go/script_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/build_tag_goexperiment.txt [new file with mode: 0644]