go/src/internal/buildcfg/exp.go

206 lines
6.2 KiB
Go
Raw Normal View History

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buildcfg
import (
"fmt"
"reflect"
"strings"
"internal/goexperiment"
)
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
// ExperimentFlags represents a set of GOEXPERIMENT flags relative to a baseline
// (platform-default) experiment configuration.
type ExperimentFlags struct {
goexperiment.Flags
baseline goexperiment.Flags
}
// Experiment contains the toolchain experiments enabled for the
// current build.
//
// (This is not necessarily the set of experiments the compiler itself
// was built with.)
//
// Experiment.baseline specifies the experiment flags that are enabled by
// default in the current toolchain. This is, in effect, the "control"
// configuration and any variation from this is an experiment.
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
var Experiment ExperimentFlags = func() ExperimentFlags {
flags, err := ParseGOEXPERIMENT(GOOS, GOARCH, envOr("GOEXPERIMENT", defaultGOEXPERIMENT))
if err != nil {
Error = err
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
return ExperimentFlags{}
}
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
return *flags
}()
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
// DefaultGOEXPERIMENT is the embedded default GOEXPERIMENT string.
// It is not guaranteed to be canonical.
const DefaultGOEXPERIMENT = defaultGOEXPERIMENT
// FramePointerEnabled enables the use of platform conventions for
// saving frame pointers.
//
// This used to be an experiment, but now it's always enabled on
// platforms that support it.
//
// Note: must agree with runtime.framepointer_enabled.
var FramePointerEnabled = GOARCH == "amd64" || GOARCH == "arm64"
// ParseGOEXPERIMENT parses a (GOOS, GOARCH, GOEXPERIMENT)
// configuration tuple and returns the enabled and baseline experiment
// flag sets.
//
// TODO(mdempsky): Move to [internal/goexperiment].
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) {
// regabiSupported is set to true on platforms where register ABI is
// supported and enabled by default.
// regabiAlwaysOn is set to true on platforms where register ABI is
// always on.
var regabiSupported, regabiAlwaysOn bool
internal/buildcfg: enable register ABI for PPC64 This enables the new register ABI for all PPC64 targets by default including linux/ppc64, linux/ppc64le, and aix/ppc64. Improvements with the new register ABI on a power9: name old time/op (ns/op) new time/op (ns/op) delta BinaryTree17 3882070000 3274900000 -15.64% Fannkuch11 3787620000 3614740000 -4.56% FmtFprintfEmpty 58.705 51.1875 -12.81% FmtFprintfString 101.675 94.4725 -7.08% FmtFprintfInt 112.725 104.075 -7.67% FmtFprintfIntInt 166.475 158.05 -5.06% FmtFprintfPrefixedInt 183.7 178.975 -2.57% FmtFprintfFloat 246.55 258.8 +4.97% FmtManyArgs 648.325 665.875 +2.71% GobDecode 8004660 6802210 -15.02% GobEncode 7289780 5675710 -22.14% Gzip 326931000 323586000 -1.02% Gunzip 47544700 37808000 -20.48% HTTPClientServer 46927.2 42357.8 -9.74% JSONEncode 12098300 9621450 -20.47% JSONDecode 62305300 55410200 -11.07% Mandelbrot200 5841540 5934590 +1.59% GoParse 5594880 4003360 -28.45% RegexpMatchEasy0_32 96.185 89.6325 -6.81% RegexpMatchEasy0_1K 255.775 210.45 -17.72% RegexpMatchEasy1_32 102.95 93.8825 -8.81% RegexpMatchEasy1_1K 511.65 385.075 -24.74% RegexpMatchMedium_32 1414.75 1236.75 -12.58% RegexpMatchMedium_1K 42114.5 37022.5 -12.09% RegexpMatchHard_32 2110.5 1901.5 -9.90% RegexpMatchHard_1K 63559.5 59494 -6.40% Revcomp 532981000 480640000 -9.82% Template 81903600 65743300 -19.73% TimeParse 310.75 276.525 -11.01% TimeFormat 483.4 355.475 -26.46% Change-Id: Ib7c5dfe8ddc2f17050943912048f55667dabde39 Reviewed-on: https://go-review.googlesource.com/c/go/+/353969 Trust: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-10-04 12:13:41 -05:00
switch goarch {
case "amd64", "arm64", "loong64", "ppc64le", "ppc64", "riscv64":
regabiAlwaysOn = true
internal/buildcfg: enable register ABI for PPC64 This enables the new register ABI for all PPC64 targets by default including linux/ppc64, linux/ppc64le, and aix/ppc64. Improvements with the new register ABI on a power9: name old time/op (ns/op) new time/op (ns/op) delta BinaryTree17 3882070000 3274900000 -15.64% Fannkuch11 3787620000 3614740000 -4.56% FmtFprintfEmpty 58.705 51.1875 -12.81% FmtFprintfString 101.675 94.4725 -7.08% FmtFprintfInt 112.725 104.075 -7.67% FmtFprintfIntInt 166.475 158.05 -5.06% FmtFprintfPrefixedInt 183.7 178.975 -2.57% FmtFprintfFloat 246.55 258.8 +4.97% FmtManyArgs 648.325 665.875 +2.71% GobDecode 8004660 6802210 -15.02% GobEncode 7289780 5675710 -22.14% Gzip 326931000 323586000 -1.02% Gunzip 47544700 37808000 -20.48% HTTPClientServer 46927.2 42357.8 -9.74% JSONEncode 12098300 9621450 -20.47% JSONDecode 62305300 55410200 -11.07% Mandelbrot200 5841540 5934590 +1.59% GoParse 5594880 4003360 -28.45% RegexpMatchEasy0_32 96.185 89.6325 -6.81% RegexpMatchEasy0_1K 255.775 210.45 -17.72% RegexpMatchEasy1_32 102.95 93.8825 -8.81% RegexpMatchEasy1_1K 511.65 385.075 -24.74% RegexpMatchMedium_32 1414.75 1236.75 -12.58% RegexpMatchMedium_1K 42114.5 37022.5 -12.09% RegexpMatchHard_32 2110.5 1901.5 -9.90% RegexpMatchHard_1K 63559.5 59494 -6.40% Revcomp 532981000 480640000 -9.82% Template 81903600 65743300 -19.73% TimeParse 310.75 276.525 -11.01% TimeFormat 483.4 355.475 -26.46% Change-Id: Ib7c5dfe8ddc2f17050943912048f55667dabde39 Reviewed-on: https://go-review.googlesource.com/c/go/+/353969 Trust: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-10-04 12:13:41 -05:00
regabiSupported = true
}
// Older versions (anything before V16) of dsymutil don't handle
// the .debug_rnglists section in DWARF5. See
// https://github.com/golang/go/issues/26379#issuecomment-2677068742
// for more context. This disables all DWARF5 on mac, which is not
// ideal (would be better to disable just for cases where we know
// the build will use external linking). In the GOOS=aix case, the
// XCOFF format (as far as can be determined) doesn't seem to
// support the necessary section subtypes for DWARF-specific
// things like .debug_addr (needed for DWARF 5).
dwarf5Supported := (goos != "darwin" && goos != "ios" && goos != "aix")
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
baseline := goexperiment.Flags{
RegabiWrappers: regabiSupported,
RegabiArgs: regabiSupported,
Dwarf5: dwarf5Supported,
RandomizedHeapBase64: true,
RuntimeFree: true,
SizeSpecializedMalloc: true,
GreenTeaGC: true,
}
// Start with the statically enabled set of experiments.
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
flags := &ExperimentFlags{
Flags: baseline,
baseline: baseline,
}
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
// Pick up any changes to the baseline configuration from the
// GOEXPERIMENT environment. This can be set at make.bash time
// and overridden at build time.
if goexp != "" {
// Create a map of known experiment names.
names := make(map[string]func(bool))
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
rv := reflect.ValueOf(&flags.Flags).Elem()
rt := rv.Type()
for i := 0; i < rt.NumField(); i++ {
field := rv.Field(i)
names[strings.ToLower(rt.Field(i).Name)] = field.SetBool
}
// "regabi" is an alias for all working regabi
// subexperiments, and not an experiment itself. Doing
// this as an alias make both "regabi" and "noregabi"
// do the right thing.
names["regabi"] = func(v bool) {
flags.RegabiWrappers = v
flags.RegabiArgs = v
}
// Parse names.
all: replace strings.Split with strings.SplitSeq In Go 1.25+, strings.SplitSeq offers better performance. Here are the benchmark results comparing strings.Split and strings.SplitSeq in a for-loop, with the benchmark code located in src/strings/iter_test.go: goos: darwin goarch: amd64 pkg: cmd/go/internal/auth cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ParseGitAuth/standard-8 281.4n ± 1% 218.0n ± 11% -22.54% (p=0.000 n=10) ParseGitAuth/with_url-8 549.1n ± 1% 480.5n ± 13% -12.48% (p=0.002 n=10) ParseGitAuth/minimal-8 235.4n ± 1% 197.3n ± 7% -16.20% (p=0.000 n=10) ParseGitAuth/complex-8 797.6n ± 2% 805.2n ± 4% ~ (p=0.481 n=10) ParseGitAuth/empty-8 87.48n ± 3% 63.25n ± 6% -27.71% (p=0.000 n=10) ParseGitAuth/malformed-8 228.8n ± 1% 171.2n ± 3% -25.17% (p=0.000 n=10) geomean 288.9n 237.7n -17.72% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ParseGitAuth/standard-8 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/with_url-8 400.0 ± 0% 288.0 ± 0% -28.00% (p=0.000 n=10) ParseGitAuth/minimal-8 144.00 ± 0% 80.00 ± 0% -44.44% (p=0.000 n=10) ParseGitAuth/complex-8 528.0 ± 0% 400.0 ± 0% -24.24% (p=0.000 n=10) ParseGitAuth/empty-8 32.00 ± 0% 16.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 176.00 ± 0% 80.00 ± 0% -54.55% (p=0.000 n=10) geomean 179.0 102.1 -42.96% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ParseGitAuth/standard-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/with_url-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/minimal-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/complex-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/empty-8 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) geomean 3.086 2.040 -33.91% Updates #69315. Change-Id: Id0219edea45d9658d527b863162ebe917e7821d9 GitHub-Last-Rev: 392b315e122f2c9ef8703ca2dbce8f82ec198556 GitHub-Pull-Request: golang/go#75259 Reviewed-on: https://go-review.googlesource.com/c/go/+/701015 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2025-09-15 14:39:58 +00:00
for f := range strings.SplitSeq(goexp, ",") {
if f == "" {
continue
}
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
if f == "none" {
// GOEXPERIMENT=none disables all experiment flags.
// This is used by cmd/dist, which doesn't know how
// to build with any experiment flags.
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
flags.Flags = goexperiment.Flags{}
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
continue
}
val := true
if strings.HasPrefix(f, "no") {
f, val = f[2:], false
}
set, ok := names[f]
if !ok {
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
return nil, fmt.Errorf("unknown GOEXPERIMENT %s", f)
}
set(val)
}
}
if regabiAlwaysOn {
flags.RegabiWrappers = true
flags.RegabiArgs = true
}
cmd/compile, internal/buildcfg: enable regABI on loong64, and add loong64 in test func hasRegisterABI goos: linux goarch: loong64 pkg: test/bench/go1 cpu: Loongson-3A5000 @ 2500.00MHz │ bench.old │ bench.new │ │ sec/op │ sec/op vs base │ Template 116.4m ± 1% 101.3m ± 0% -12.94% (p=0.000 n=20) Gzip 417.2m ± 0% 419.4m ± 0% +0.53% (p=0.000 n=20) Gunzip 87.41m ± 0% 84.61m ± 0% -3.20% (p=0.000 n=20) FmtFprintfEmpty 97.87n ± 0% 81.05n ± 0% -17.19% (p=0.000 n=20) FmtFprintfString 151.1n ± 0% 140.9n ± 0% -6.75% (p=0.000 n=20) FmtFprintfInt 155.6n ± 0% 143.0n ± 0% -8.10% (p=0.000 n=20) FmtFprintfIntInt 236.9n ± 0% 225.1n ± 0% -5.00% (p=0.000 n=20) FmtFprintfPrefixedInt 316.8n ± 0% 331.9n ± 0% +4.77% (p=0.000 n=20) FmtFprintfFloat 401.5n ± 0% 380.0n ± 0% -5.35% (p=0.000 n=20) FmtManyArgs 925.3n ± 0% 910.1n ± 0% -1.64% (p=0.000 n=20) BinaryTree17 14.04 ± 1% 12.84 ± 0% -8.52% (p=0.000 n=20) RegexpMatchEasy0_32 133.1n ± 0% 121.3n ± 0% -8.87% (p=0.000 n=20) RegexpMatchEasy0_1K 1.363µ ± 0% 1.337µ ± 0% -1.91% (p=0.000 n=20) RegexpMatchEasy1_32 162.7n ± 0% 152.6n ± 0% -6.24% (p=0.000 n=20) RegexpMatchEasy1_1K 1.505µ ± 0% 1.740µ ± 0% +15.61% (p=0.000 n=20) RegexpMatchMedium_32 1.429µ ± 0% 1.299µ ± 0% -9.10% (p=0.000 n=20) RegexpMatchMedium_1K 41.76µ ± 0% 38.16µ ± 0% -8.61% (p=0.000 n=20) RegexpMatchHard_32 2.094µ ± 0% 2.157µ ± 0% +3.01% (p=0.000 n=20) RegexpMatchHard_1K 63.25µ ± 0% 64.72µ ± 0% +2.33% (p=0.000 n=20) JSONEncode 18.00m ± 1% 17.46m ± 1% -3.05% (p=0.000 n=20) JSONDecode 79.49m ± 0% 72.42m ± 0% -8.89% (p=0.000 n=20) Revcomp 1.147 ± 0% 1.255 ± 0% +9.39% (p=0.000 n=20) Fannkuch11 3.623 ± 0% 3.410 ± 0% -5.87% (p=0.000 n=20) Fannkuch11 3.623 ± 0% 3.410 ± 0% -5.87% (p=0.000 n=20) GobDecode 14.26m ± 0% 12.92m ± 0% -9.36% (p=0.000 n=20) GobEncode 16.86m ± 1% 14.96m ± 0% -11.28% (p=0.000 n=20) GoParse 8.721m ± 0% 8.125m ± 1% -6.84% (p=0.000 n=20) Mandelbrot200 7.203m ± 0% 7.171m ± 0% -0.44% (p=0.000 n=20) HTTPClientServer 83.96µ ± 0% 80.83µ ± 0% -3.72% (p=0.000 n=20) TimeParse 415.3n ± 0% 389.1n ± 0% -6.31% (p=0.000 n=20) TimeFormat 506.4n ± 0% 495.9n ± 0% -2.06% (p=0.000 n=20) geomean 102.6µ 98.04µ -4.40% │ bench.old │ bench.new │ │ B/s │ B/s vs base │ Template 15.90Mi ± 1% 18.26Mi ± 0% +14.88% (p=0.000 n=20) Gzip 44.36Mi ± 0% 44.12Mi ± 0% -0.53% (p=0.000 n=20) Gunzip 211.7Mi ± 0% 218.7Mi ± 0% +3.31% (p=0.000 n=20) RegexpMatchEasy0_32 229.3Mi ± 0% 251.6Mi ± 0% +9.72% (p=0.000 n=20) RegexpMatchEasy0_1K 716.4Mi ± 0% 730.3Mi ± 0% +1.94% (p=0.000 n=20) RegexpMatchEasy1_32 187.6Mi ± 0% 200.0Mi ± 0% +6.64% (p=0.000 n=20) RegexpMatchEasy1_1K 649.1Mi ± 0% 561.3Mi ± 0% -13.52% (p=0.000 n=20) RegexpMatchMedium_32 21.35Mi ± 0% 23.50Mi ± 0% +10.05% (p=0.000 n=20) RegexpMatchMedium_1K 23.38Mi ± 0% 25.59Mi ± 0% +9.42% (p=0.000 n=20) RegexpMatchHard_32 14.57Mi ± 0% 14.14Mi ± 0% -2.95% (p=0.000 n=20) RegexpMatchHard_1K 15.44Mi ± 0% 15.09Mi ± 0% -2.29% (p=0.000 n=20) JSONEncode 102.8Mi ± 1% 106.0Mi ± 1% +3.15% (p=0.000 n=20) JSONDecode 23.28Mi ± 0% 25.55Mi ± 0% +9.75% (p=0.000 n=20) Revcomp 211.3Mi ± 0% 193.1Mi ± 0% -8.58% (p=0.000 n=20) GobDecode 51.34Mi ± 0% 56.64Mi ± 0% +10.33% (p=0.000 n=20) GobEncode 43.42Mi ± 1% 48.93Mi ± 0% +12.71% (p=0.000 n=20) GoParse 6.337Mi ± 0% 6.800Mi ± 1% +7.30% (p=0.000 n=20) geomean 61.24Mi 63.63Mi +3.91% Update #40724 Co-authored-by: Xiaolin Zhao <zhaoxiaolin@loongson.cn> Change-Id: I5993460da8c5926c70cb6fbe551b8e4655dea9d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/521790 Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2023-08-16 10:39:38 +08:00
// regabi is only supported on amd64, arm64, loong64, riscv64, ppc64 and ppc64le.
internal/buildcfg: enable register ABI for PPC64 This enables the new register ABI for all PPC64 targets by default including linux/ppc64, linux/ppc64le, and aix/ppc64. Improvements with the new register ABI on a power9: name old time/op (ns/op) new time/op (ns/op) delta BinaryTree17 3882070000 3274900000 -15.64% Fannkuch11 3787620000 3614740000 -4.56% FmtFprintfEmpty 58.705 51.1875 -12.81% FmtFprintfString 101.675 94.4725 -7.08% FmtFprintfInt 112.725 104.075 -7.67% FmtFprintfIntInt 166.475 158.05 -5.06% FmtFprintfPrefixedInt 183.7 178.975 -2.57% FmtFprintfFloat 246.55 258.8 +4.97% FmtManyArgs 648.325 665.875 +2.71% GobDecode 8004660 6802210 -15.02% GobEncode 7289780 5675710 -22.14% Gzip 326931000 323586000 -1.02% Gunzip 47544700 37808000 -20.48% HTTPClientServer 46927.2 42357.8 -9.74% JSONEncode 12098300 9621450 -20.47% JSONDecode 62305300 55410200 -11.07% Mandelbrot200 5841540 5934590 +1.59% GoParse 5594880 4003360 -28.45% RegexpMatchEasy0_32 96.185 89.6325 -6.81% RegexpMatchEasy0_1K 255.775 210.45 -17.72% RegexpMatchEasy1_32 102.95 93.8825 -8.81% RegexpMatchEasy1_1K 511.65 385.075 -24.74% RegexpMatchMedium_32 1414.75 1236.75 -12.58% RegexpMatchMedium_1K 42114.5 37022.5 -12.09% RegexpMatchHard_32 2110.5 1901.5 -9.90% RegexpMatchHard_1K 63559.5 59494 -6.40% Revcomp 532981000 480640000 -9.82% Template 81903600 65743300 -19.73% TimeParse 310.75 276.525 -11.01% TimeFormat 483.4 355.475 -26.46% Change-Id: Ib7c5dfe8ddc2f17050943912048f55667dabde39 Reviewed-on: https://go-review.googlesource.com/c/go/+/353969 Trust: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2021-10-04 12:13:41 -05:00
if !regabiSupported {
buildcfg: disable regabiwrappers along with regabiargs This (1) "just makes sense" and (2) avoids a weird bug in some name-dependent calling conventions in wasm code generation, when the local pkg has a real name instead of "". The calling conventions are triggered for a "wrapper" function, and somehow an abiwrapper was taken to be a "wrapper" function, resulting in the use of an invalid register. But abiwrapping has no business being in js/wasm code generation, so just turn that off. Updates #51734. For posterity, that crash is: GOSSAFUNC=wasmTruncU GOMAXPROCS=1 \ GOOS=js GOARCH=wasm GOEXPERIMENT=regabi,regabiargs /Users/drchase/work/go-quick/bin/go build \ -gcflags=all=-d=abiwrap -o a.exe \ GOROOT/test/abi/bad_select_crash.go <autogenerated>:1: internal compiler error: panic: bad Get: invalid register goroutine 1 [running]: runtime/debug.Stack() runtime/debug/stack.go:24 +0x65 cmd/compile/internal/base.FatalfAt({0xc80?, 0x0?}, {0x195c85e, 0x9}, {0xc005ef72c8, 0x1, 0x1}) /Users/drchase/work/go-quick/src/cmd/compile/internal/base/print.go:227 +0x1d7 cmd/compile/internal/base.Fatalf(...) /Users/drchase/work/go-quick/src/cmd/compile/internal/base/print.go:196 cmd/compile/internal/gc.handlePanic() /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/main.go:48 +0x85 panic({0x18bf3c0, 0x1ad0430}) runtime/panic.go:854 +0x26d cmd/internal/obj/wasm.assemble(0xc0000f8200, 0xc001c74880, 0x0?) /Users/drchase/work/go-quick/src/cmd/internal/obj/wasm/wasmobj.go:920 +0x1958 cmd/internal/obj.Flushplist(0xc0000f8200, 0xc005ef79a8, 0xc0022264c0, {0x7ff7bfefdd17, 0x7}) /Users/drchase/work/go-quick/src/cmd/internal/obj/plist.go:151 +0x784 cmd/compile/internal/objw.(*Progs).Flush(...) /Users/drchase/work/go-quick/src/cmd/compile/internal/objw/prog.go:124 cmd/compile/internal/ssagen.Compile(0xc000707e00, 0xc001b4d620?) /Users/drchase/work/go-quick/src/cmd/compile/internal/ssagen/pgen.go:208 +0x495 cmd/compile/internal/gc.compileFunctions.func4.1(0xc005ef7a01?) /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/compile.go:153 +0x3a cmd/compile/internal/gc.compileFunctions.func2(0x0?) /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/compile.go:125 +0x1e cmd/compile/internal/gc.compileFunctions.func4({0xc004685000, 0x79f, 0xa00?}) /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/compile.go:152 +0x53 cmd/compile/internal/gc.compileFunctions() /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/compile.go:163 +0x162 cmd/compile/internal/gc.Main(0x198d3d8) /Users/drchase/work/go-quick/src/cmd/compile/internal/gc/main.go:297 +0x108a main.main() /Users/drchase/work/go-quick/src/cmd/compile/main.go:55 +0xdd Change-Id: I79f039e2494f78efba60e52ab1110d62656fb7ef Reviewed-on: https://go-review.googlesource.com/c/go/+/405899 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-12 17:25:04 -04:00
flags.RegabiWrappers = false
flags.RegabiArgs = false
}
// Check regabi dependencies.
if flags.RegabiArgs && !flags.RegabiWrappers {
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
return nil, fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers")
}
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
return flags, nil
}
// String returns the canonical GOEXPERIMENT string to enable this experiment
// configuration. (Experiments in the same state as in the baseline are elided.)
func (exp *ExperimentFlags) String() string {
return strings.Join(expList(&exp.Flags, &exp.baseline, false), ",")
}
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
// expList returns the list of lower-cased experiment names for
// experiments that differ from base. base may be nil to indicate no
// experiments. If all is true, then include all experiment flags,
// regardless of base.
func expList(exp, base *goexperiment.Flags, all bool) []string {
var list []string
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
rv := reflect.ValueOf(exp).Elem()
var rBase reflect.Value
if base != nil {
rBase = reflect.ValueOf(base).Elem()
}
rt := rv.Type()
for i := 0; i < rt.NumField(); i++ {
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
name := strings.ToLower(rt.Field(i).Name)
val := rv.Field(i).Bool()
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
baseVal := false
if base != nil {
baseVal = rBase.Field(i).Bool()
}
if all || val != baseVal {
cmd/internal/objabi: make GOEXPERIMENT be a diff from default experiments Right now the rules around handling default-on experiments are complicated and a bit inconsistent. Notably, objabi.GOEXPERIMENT is set to a comma-separated list of enabled experiments, but this may not be the string a user should set the GOEXPERIMENT environment variable to get that list of experiments: if an experiment is enabled by default but gets turned off by GOEXPERIMENT, then the string we report needs to include "no"+experiment to capture that default override. This complication also seeps into the version string we print for "go tool compile -V", etc. This logic is further complicated by the fact that it only wants to include an experiment string if the set of experiments varies from the default. This CL rethinks how we handle default-on experiments. Now that experiment state is all captured in a struct, we can simplify a lot of this logic. objabi.GOEXPERIMENT will be set based on the delta from the default set of experiments, which reflects what a user would actually need to pass on the command line. Likewise, we include this delta in the "-V" output, which simplifies this logic because if there's nothing to show in the version string, the delta will be empty. Change-Id: I7ed307329541fc2c9f90edd463fbaf8e0cc9e8ee Reviewed-on: https://go-review.googlesource.com/c/go/+/307819 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-04-06 16:11:17 -04:00
if val {
list = append(list, name)
} else {
list = append(list, "no"+name)
}
}
}
return list
}
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
// Enabled returns a list of enabled experiments, as
// lower-cased experiment names.
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
func (exp *ExperimentFlags) Enabled() []string {
return expList(&exp.Flags, nil, false)
}
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
// All returns a list of all experiment settings.
// Disabled experiments appear in the list prefixed by "no".
internal/buildcfg: extract logic specific to cmd/go cmd/go/internal/cfg duplicates many of the fields of internal/buildcfg, but initializes them from a Go environment file in addition to the usual process environment. internal/buildcfg doesn't (and shouldn't) know or care about that environment file, but prior to this CL it exposed hooks for cmd/go/internal/cfg to write data back to internal/buildcfg to incorporate information from the file. It also produced quirky GOEXPERIMENT strings when a non-trivial default was overridden, seemingly so that 'go env' would produce those same quirky strings in edge-cases where they are needed. This change reverses that information flow: internal/buildcfg now exports a structured type with methods — instead of top-level functions communicating through global state — so that cmd/go can utilize its marshaling and unmarshaling functionality without also needing to write results back into buildcfg package state. The quirks specific to 'go env' have been eliminated by distinguishing between the raw GOEXPERIMENT value set by the user (which is what we should report from 'go env') and the cleaned, canonical equivalent (which is what we should use in the build cache key). For #51461. Change-Id: I4ef5b7c58b1fb3468497649a6d2fb6c19aa06c70 Reviewed-on: https://go-review.googlesource.com/c/go/+/393574 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 16:25:47 -04:00
func (exp *ExperimentFlags) All() []string {
return expList(&exp.Flags, nil, true)
}