Skip to content

Commit ad0442b

Browse files
committed
cue/cuecontext: fix EvalDefault to follow the default, add EvalStable
When we flipped evalv3 on by default in https://cuelang.org/cl/1211974 we flipped the default for the experiment flag, but we forgot about cuecontext.EvalDefault, which remained at evalv2. We could tweak Evaldefault to instead be fixed at evalv3, but that isn't quite right either; if a user creates an evaluator context via cuecontext.New() the selected version follows the CUE_EXPERIMENT=evalv3 flag, which is the default behavior implemented in cmd/cue as well. It would then follow that using cuecontext.New(cuecontext.EvaluatorVersion(cuecontext.EvalDefault)) would result in the same behavior, but it does not if EvalDefault is fixed at either EvalV2 or EvalV3 as a constant. Make EvalDefault select a default version as described above, and add EvalStable as an alias for the latest stable version of the evaluator, which is what EvalDefault used to implement. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I3420fbbadde4e45e3e2c5b27a710a85fda66a12b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212505 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 1ec46e7 commit ad0442b

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

cue/cuecontext/cuecontext.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,17 @@ func Interpreter(i ExternInterpreter) Option {
6161
type EvalVersion = internal.EvaluatorVersion
6262

6363
const (
64-
// EvalDefault is the latest stable version of the evaluator.
64+
// EvalDefault is the default version of the evaluator, which is selected based on
65+
// the CUE_EXPERIMENT environment variable described in [cue help environment].
66+
//
67+
// [cue help environment]: https://cuelang.org/docs/reference/command/cue-help-environment/
6568
EvalDefault EvalVersion = internal.DefaultVersion
6669

67-
// EvalExperiment refers to the latest unstable version of the evaluator.
68-
// Note that this version may change without notice.
70+
// EvalDefault is the latest stable version of the evaluator, currently [EvalV3].
71+
EvalStable EvalVersion = internal.StableVersion
72+
73+
// EvalExperiment refers to the latest in-development version of the evaluator,
74+
// currently [EvalV3]. Note that this version may change without notice.
6975
EvalExperiment EvalVersion = internal.DevVersion
7076

7177
// EvalV2 is the previous version of the evaluator. It was introduced in CUE
@@ -74,8 +80,7 @@ const (
7480

7581
// EvalV3 is the current version of the evaluator. It was introduced in 2024
7682
// and brought a new disjunction algorithm, a new closedness algorithm, a
77-
// new core scheduler, and adds performance enhancements like structure
78-
// sharing.
83+
// new core scheduler, and adds performance enhancements like structure sharing.
7984
EvalV3 EvalVersion = internal.EvalV3
8085
)
8186

cue/cuecontext/cuecontext_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestEvalVersion(t *testing.T) {
9393
// The experiment evaluator version setting does not affect the specific
9494
// versions like Stable or V3, as they are fixed.
9595
testFixedVersions := func() {
96+
test(New(EvaluatorVersion(EvalStable)), internal.EvalV3)
9697
// We currently don't have an experimental version, so it's the current version.
9798
test(New(EvaluatorVersion(EvalExperiment)), internal.EvalV3)
9899
test(New(EvaluatorVersion(EvalV2)), internal.EvalV2)
@@ -102,15 +103,7 @@ func TestEvalVersion(t *testing.T) {
102103
// The current and default evaluator version is EvalV3.
103104
qt.Assert(t, qt.Equals(cueexperiment.Flags.EvalV3, true))
104105
test(New(), internal.EvalV3)
105-
// TODO(mvdan): explicitly selecting the default should result in evalv3 here,
106-
// just like implicitly selecting the default by not using the EvaluatorVersion flag.
107-
// It currently does not, because internally, we treat "unset" vs "default"
108-
// as different version selection scenarios.
109-
//
110-
// Or, if we want an evaluator version to describe "latest stable", opposing
111-
// EvalExperiment to describe "latest experimental", we should rename it to EvalStable
112-
// and keep its current behavior.
113-
test(New(EvaluatorVersion(EvalDefault)), internal.EvalV2)
106+
test(New(EvaluatorVersion(EvalDefault)), internal.EvalV3)
114107

115108
testFixedVersions()
116109

internal/core/runtime/imports.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"cuelang.org/go/cue/errors"
2323
"cuelang.org/go/internal"
2424
"cuelang.org/go/internal/core/adt"
25-
"cuelang.org/go/internal/cueexperiment"
2625
)
2726

2827
type PackageFunc func(ctx adt.Runtime) (*adt.Vertex, errors.Error)
@@ -59,12 +58,7 @@ var SharedRuntime = sync.OnceValue(func() *Runtime {
5958
// but future evaluator versions may not be compatible at that level.
6059
// We should consider using one SharedRuntime per evaluator version,
6160
// or getting rid of SharedRuntime altogether.
62-
cueexperiment.Init()
63-
if cueexperiment.Flags.EvalV3 {
64-
r.version = internal.EvalV3
65-
} else {
66-
r.version = internal.EvalV2
67-
}
61+
r.SetVersion(internal.DefaultVersion)
6862
return r
6963
})
7064

internal/core/runtime/runtime.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ func NewWithSettings(v internal.EvaluatorVersion, flags cuedebug.Config) *Runtim
8080
// SetVersion sets the version to use for the Runtime. This should only be set
8181
// before first use.
8282
func (r *Runtime) SetVersion(v internal.EvaluatorVersion) {
83-
r.version = v
83+
switch v {
84+
case internal.EvalV2, internal.EvalV3:
85+
r.version = v
86+
case internal.EvalVersionUnset, internal.DefaultVersion:
87+
cueexperiment.Init()
88+
if cueexperiment.Flags.EvalV3 {
89+
r.version = internal.EvalV3
90+
} else {
91+
r.version = internal.EvalV2
92+
}
93+
}
8494
}
8595

8696
// SetTopologicalSort sets whether or not to use topological sorting
@@ -114,12 +124,7 @@ func (r *Runtime) Init() {
114124

115125
r.loaded = map[*build.Instance]interface{}{}
116126

117-
cueexperiment.Init()
118-
if cueexperiment.Flags.EvalV3 {
119-
r.version = internal.EvalV3
120-
} else {
121-
r.version = internal.EvalV2
122-
}
127+
r.SetVersion(internal.DefaultVersion)
123128
r.topoSort = cueexperiment.Flags.TopoSort
124129

125130
// By default we follow the environment's CUE_DEBUG settings,

internal/internal.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,23 @@ const (
118118
// EvalVersionUnset is the zero value, which signals that no evaluator version is provided.
119119
EvalVersionUnset EvaluatorVersion = 0
120120

121+
// DefaultVersion is a special value as it selects a version depending on the current
122+
// value of CUE_EXPERIMENT. It exists separately to [EvalVersionUnset], even though both
123+
// implement the same version selection logic, so that we can distinguish between
124+
// a user explicitly asking for the default version versus an entirely unset version.
125+
DefaultVersion EvaluatorVersion = -1 // TODO(mvdan): rename to EvalDefault for consistency with cuecontext
126+
121127
// The values below are documented under [cuelang.org/go/cue/cuecontext.EvalVersion].
122128
// We should never change or delete the values below, as they describe all known past versions
123129
// which is useful for understanding old debug output.
124130

125131
EvalV2 EvaluatorVersion = 2
126132
EvalV3 EvaluatorVersion = 3
127133

128-
// The current default and experimental versions.
134+
// The current default, stable, and experimental versions.
129135

130-
DefaultVersion = EvalV2 // TODO(mvdan): rename to EvalDefault for consistency with cuecontext
131-
DevVersion = EvalV3 // TODO(mvdan): rename to EvalExperiment for consistency with cuecontext
136+
StableVersion = EvalV3 // TODO(mvdan): rename to EvalStable for consistency with cuecontext
137+
DevVersion = EvalV3 // TODO(mvdan): rename to EvalExperiment for consistency with cuecontext
132138
)
133139

134140
// ListEllipsis reports the list type and remaining elements of a list. If we

0 commit comments

Comments
 (0)