github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/buildcfg/exp.go (about) 1 // Copyright 2021 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package buildcfg 6 7 import ( 8 "github.com/shogo82148/std/internal/goexperiment" 9 ) 10 11 // ExperimentFlags represents a set of GOEXPERIMENT flags relative to a baseline 12 // (platform-default) experiment configuration. 13 type ExperimentFlags struct { 14 goexperiment.Flags 15 baseline goexperiment.Flags 16 } 17 18 // Experiment contains the toolchain experiments enabled for the 19 // current build. 20 // 21 // (This is not necessarily the set of experiments the compiler itself 22 // was built with.) 23 // 24 // experimentBaseline specifies the experiment flags that are enabled by 25 // default in the current toolchain. This is, in effect, the "control" 26 // configuration and any variation from this is an experiment. 27 var Experiment ExperimentFlags = func() ExperimentFlags { 28 flags, err := ParseGOEXPERIMENT(GOOS, GOARCH, envOr("GOEXPERIMENT", defaultGOEXPERIMENT)) 29 if err != nil { 30 Error = err 31 return ExperimentFlags{} 32 } 33 return *flags 34 }() 35 36 // DefaultGOEXPERIMENT is the embedded default GOEXPERIMENT string. 37 // It is not guaranteed to be canonical. 38 const DefaultGOEXPERIMENT = defaultGOEXPERIMENT 39 40 // FramePointerEnabled enables the use of platform conventions for 41 // saving frame pointers. 42 // 43 // This used to be an experiment, but now it's always enabled on 44 // platforms that support it. 45 // 46 // Note: must agree with runtime.framepointer_enabled. 47 var FramePointerEnabled = GOARCH == "amd64" || GOARCH == "arm64" 48 49 // ParseGOEXPERIMENT parses a (GOOS, GOARCH, GOEXPERIMENT) 50 // configuration tuple and returns the enabled and baseline experiment 51 // flag sets. 52 // 53 // TODO(mdempsky): Move to internal/goexperiment. 54 func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) 55 56 // String returns the canonical GOEXPERIMENT string to enable this experiment 57 // configuration. (Experiments in the same state as in the baseline are elided.) 58 func (exp *ExperimentFlags) String() string 59 60 // Enabled returns a list of enabled experiments, as 61 // lower-cased experiment names. 62 func (exp *ExperimentFlags) Enabled() []string 63 64 // All returns a list of all experiment settings. 65 // Disabled experiments appear in the list prefixed by "no". 66 func (exp *ExperimentFlags) All() []string