Source File
exp.go
Belonging Package
internal/buildcfg
// 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 buildcfgimport ()// ExperimentFlags represents a set of GOEXPERIMENT flags relative to a baseline// (platform-default) experiment configuration.type ExperimentFlags struct {goexperiment.Flagsbaseline 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.var Experiment ExperimentFlags = func() ExperimentFlags {, := ParseGOEXPERIMENT(GOOS, GOARCH, envOr("GOEXPERIMENT", defaultGOEXPERIMENT))if != nil {Error =return ExperimentFlags{}}return *}()// 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].func (, , 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 , boolswitch {case "amd64", "arm64", "loong64", "ppc64le", "ppc64", "riscv64":= true= 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).:= ( != "darwin" && != "ios" && != "aix"):= goexperiment.Flags{RegabiWrappers: ,RegabiArgs: ,AliasTypeParams: true,SwissMap: true,SyncHashTrieMap: true,Dwarf5: ,}// Start with the statically enabled set of experiments.:= &ExperimentFlags{Flags: ,baseline: ,}// 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 != "" {// Create a map of known experiment names.:= make(map[string]func(bool)):= reflect.ValueOf(&.Flags).Elem():= .Type()for := 0; < .NumField(); ++ {:= .Field()[strings.ToLower(.Field().Name)] = .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.["regabi"] = func( bool) {.RegabiWrappers =.RegabiArgs =}// Parse names.for , := range strings.Split(, ",") {if == "" {continue}if == "none" {// GOEXPERIMENT=none disables all experiment flags.// This is used by cmd/dist, which doesn't know how// to build with any experiment flags..Flags = goexperiment.Flags{}continue}:= trueif strings.HasPrefix(, "no") {, = [2:], false}, := []if ! {return nil, fmt.Errorf("unknown GOEXPERIMENT %s", )}()}}if {.RegabiWrappers = true.RegabiArgs = true}// regabi is only supported on amd64, arm64, loong64, riscv64, ppc64 and ppc64le.if ! {.RegabiWrappers = false.RegabiArgs = false}// Check regabi dependencies.if .RegabiArgs && !.RegabiWrappers {return nil, fmt.Errorf("GOEXPERIMENT regabiargs requires regabiwrappers")}return , nil}// String returns the canonical GOEXPERIMENT string to enable this experiment// configuration. (Experiments in the same state as in the baseline are elided.)func ( *ExperimentFlags) () string {return strings.Join(expList(&.Flags, &.baseline, false), ",")}// 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 (, *goexperiment.Flags, bool) []string {var []string:= reflect.ValueOf().Elem()var reflect.Valueif != nil {= reflect.ValueOf().Elem()}:= .Type()for := 0; < .NumField(); ++ {:= strings.ToLower(.Field().Name):= .Field().Bool():= falseif != nil {= .Field().Bool()}if || != {if {= append(, )} else {= append(, "no"+)}}}return}// Enabled returns a list of enabled experiments, as// lower-cased experiment names.func ( *ExperimentFlags) () []string {return expList(&.Flags, nil, false)}// All returns a list of all experiment settings.// Disabled experiments appear in the list prefixed by "no".func ( *ExperimentFlags) () []string {return expList(&.Flags, nil, true)}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)