cueexperiment

package
v0.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanApplyFix added in v0.15.0

func CanApplyFix(experiment, version, target string) error

CanApplyFix validates whether an experiment fix can be applied to a file with the given version and existing experiments.

func GetActive added in v0.15.0

func GetActive(origVersion, targetVersion string) []string

GetActive returns all experiments that are active (can be enabled) for the given version, but not yet accepted.

func GetUpgradable added in v0.15.0

func GetUpgradable(origVersion, targetVersion string) []string

GetUpgradable returns all experiments that are stable (possibly in later versions), that can be upgraded from the current version (must be lower than stable) to the desired version.

func Init

func Init() error

Init initializes Flags. Note: this isn't named "init" because we don't always want it to be called (for example we don't want it to be called when running "cue help"), and also because we want the failure mode to be one of error not panic, which would be the only option if it was a top level init function.

func IsPreview added in v0.15.0

func IsPreview(experiment, version string) bool

IsPreview returns true if the experiment exists and can be used for the given version.

func IsStable added in v0.15.0

func IsStable(experiment, version string) bool

IsStable returns true if the experiment is stable (no longer experimental) for the given version.

func ShouldRemoveAttribute added in v0.15.0

func ShouldRemoveAttribute(experiment, version string) bool

ShouldRemoveAttribute returns true if the experiment attribute should be removed because the experiment is stable for the given version.

Types

type Config added in v0.14.0

type Config struct {

	// FormatV2 selects the Wadler-Lindig pretty-printer as the
	// implementation behind "cue fmt" and "cue/format".
	// It only exists from v0.18.0 onwards; v0.17 knows about it solely so that
	// CUE_EXPERIMENT=formatv2=0 is accepted across both versions. Enabling it
	// is rejected, as the implementation is not present.
	FormatV2 bool `experiment:"preview:v0.18.0"`

	// Modules enables support for the modules and package management proposal
	// as described in https://cuelang.org/discussion/2939.
	Modules bool `experiment:"preview:v0.8.0,default:v0.9.0,stable:v0.11.0"`

	// YAMLV3Decoder swaps the old internal/third_party/yaml decoder with the new
	// decoder implemented in internal/encoding/yaml on top of yaml.v3.
	YAMLV3Decoder bool `experiment:"preview:v0.9.0,default:v0.9.0,stable:v0.11.0"`

	// DecodeInt64 changes [cuelang.org/go/cue.Value.Decode] to choose
	// 'int64' rather than 'int' as the default type for CUE integer values
	// to ensure consistency with 32-bit platforms.
	DecodeInt64 bool `experiment:"preview:v0.11.0,default:v0.12.0,stable:v0.13.0"`

	// Embed enables support for embedded data files as described in
	// https://cuelang.org/discussion/3264.
	Embed bool `experiment:"preview:v0.10.0,default:v0.12.0,stable:v0.14.0"`

	// TopoSort enables topological sorting of struct fields.
	// Provide feedback via https://cuelang.org/issue/3558.
	TopoSort bool `experiment:"preview:v0.11.0,default:v0.12.0,stable:v0.14.0"`

	// EvalV3 enables the new CUE evaluator, addressing performance issues
	// and bringing better algorithms for disjunctions, closedness, and cycles.
	EvalV3 bool `experiment:"preview:v0.9.0,default:v0.13.0,stable:v0.15.0"`

	// KeepValidators prevents validators from simplifying into concrete values,
	// even if their concrete value could be derived, such as '>=1 & <=1' to '1'.
	// Proposal:     https://cuelang.org/discussion/3775.
	// Spec change:  https://cuelang.org/cl/1217013
	// Spec change:  https://cuelang.org/cl/1217014
	KeepValidators bool `experiment:"preview:v0.14.0,default:v0.14.0,stable:v0.15.0"`

	// CmdReferencePkg requires referencing an imported tool package to declare tasks.
	// Otherwise, declaring tasks via "$id" or "kind" string fields is allowed.
	CmdReferencePkg bool `experiment:"preview:v0.13.0,default:v0.14.0,stable:v0.16.0"`
}

Config holds the set of known CUE_EXPERIMENT flags.

Keep the fields sorted from oldest to newest based on when the experiment was added.

var Flags Config

Flags holds the set of global CUE_EXPERIMENT flags. It is initialized by Init.

type File added in v0.14.0

type File struct {

	// Testing is used to enable experiments for testing.
	//
	// TODO: we could later use it for enabling testing features, such as
	// testing-specific builtins.
	Testing bool `experiment:"preview:v0.13.0"`

	// Accepted_ is for testing purposes only. It should be removed when an
	// experiment is accepted and can be used to test this feature instead.
	Accepted_ bool `experiment:"preview:v0.13.0,stable:v0.15.0"`

	// StructCmp enables comparison of structs. This also defines the ==
	// operator to be defined on all values. For instance, comparing 1 and
	// "foo" will return false, whereas previously it would return an error.
	//
	// Proposal:      https://cuelang.org/issue/2583
	// Spec change:   https://cuelang.org/cl/1217013
	// Spec change:   https://cuelang.org/cl/1217014
	StructCmp bool `experiment:"preview:v0.14.0,stable:v0.15.0"`

	// ExplicitOpen enables the postfix ... operator to explicitly open
	// closed structs, allowing additional fields to be added.
	//
	// Proposal:      https://cuelang.org/issue/4032
	// Spec change:   https://cuelang.org/cl/1221642
	// Requires cue fix when upgrading
	ExplicitOpen bool `experiment:"preview:v0.15.0"`

	// AliasV2 enables the use of 'self' identifier to refer to the
	// enclosing struct and enables the postfix alias syntax (~X and ~(K,V)).
	// The file where this experiment is enabled disallows the use of old prefix
	// alias syntax (X=).
	//
	// Proposal:      https://cuelang.org/issue/4014
	// Spec change:   https://cuelang.org/cl/1222377
	// Requires cue fix when upgrading
	AliasV2 bool `experiment:"preview:v0.15.0"`

	// Try enables the try clause and optional reference markers (?).
	// The try clause allows conditional field inclusion based on whether
	// optional references resolve. The ? marker on references (a?, a.b?, a[i]?)
	// is only valid within a try context.
	//
	// Proposal:      https://cuelang.org/issue/4019
	// Spec change:   https://cuelang.org/cl/1231444
	Try bool `experiment:"preview:v0.16.0"`

	// ShortCircuit enables short-circuit evaluation for the logical operators
	// && and ||. When the result is fully determined by the left operand alone
	// (false && ... or true || ...), the right operand is not evaluated and any
	// error or incomplete value it carries is suppressed.
	//
	// This matches the behavior documented in the CUE spec ("The right operand
	// is evaluated conditionally") and is consistent with all mainstream
	// languages.
	ShortCircuit bool `experiment:"preview:v0.17.0"`
	// contains filtered or unexported fields
}

File defines the experiments that can be set per file. Users can activate experiments by setting them using a file-based attribute @experiment() in a CUE file. When an experiment is first introduced, it is disabled by default.

preview:     the version from when the experiment was introduced.
stable:      the version from when it is permanently set to true.
withdrawn:   results in an error if the user attempts to use the flag.

func NewFile added in v0.14.0

func NewFile(version string, experiments ...string) (*File, error)

NewFile parses the given comma-separated list of experiments for the given version and returns a PerFile struct with the experiments enabled. A empty version indicates the default version.

func (*File) LanguageVersion added in v0.14.0

func (f *File) LanguageVersion() string

LanguageVersion returns the language version of the file or "" if no language version is associated with it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL