this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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í <mvdan@mvdan.cc>
Change-Id: I3420fbbadde4e45e3e2c5b27a710a85fda66a12b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212505
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+34 -31
+10 -5
cue/cuecontext/cuecontext.go
··· 61 61 type EvalVersion = internal.EvaluatorVersion 62 62 63 63 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/ 65 68 EvalDefault EvalVersion = internal.DefaultVersion 66 69 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. 69 75 EvalExperiment EvalVersion = internal.DevVersion 70 76 71 77 // EvalV2 is the previous version of the evaluator. It was introduced in CUE ··· 74 80 75 81 // EvalV3 is the current version of the evaluator. It was introduced in 2024 76 82 // 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. 79 84 EvalV3 EvalVersion = internal.EvalV3 80 85 ) 81 86
+2 -9
cue/cuecontext/cuecontext_test.go
··· 93 93 // The experiment evaluator version setting does not affect the specific 94 94 // versions like Stable or V3, as they are fixed. 95 95 testFixedVersions := func() { 96 + test(New(EvaluatorVersion(EvalStable)), internal.EvalV3) 96 97 // We currently don't have an experimental version, so it's the current version. 97 98 test(New(EvaluatorVersion(EvalExperiment)), internal.EvalV3) 98 99 test(New(EvaluatorVersion(EvalV2)), internal.EvalV2) ··· 102 103 // The current and default evaluator version is EvalV3. 103 104 qt.Assert(t, qt.Equals(cueexperiment.Flags.EvalV3, true)) 104 105 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) 114 107 115 108 testFixedVersions() 116 109
+1 -7
internal/core/runtime/imports.go
··· 22 22 "cuelang.org/go/cue/errors" 23 23 "cuelang.org/go/internal" 24 24 "cuelang.org/go/internal/core/adt" 25 - "cuelang.org/go/internal/cueexperiment" 26 25 ) 27 26 28 27 type PackageFunc func(ctx adt.Runtime) (*adt.Vertex, errors.Error) ··· 59 58 // but future evaluator versions may not be compatible at that level. 60 59 // We should consider using one SharedRuntime per evaluator version, 61 60 // 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) 68 62 return r 69 63 }) 70 64
+12 -7
internal/core/runtime/runtime.go
··· 80 80 // SetVersion sets the version to use for the Runtime. This should only be set 81 81 // before first use. 82 82 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 + } 84 94 } 85 95 86 96 // SetTopologicalSort sets whether or not to use topological sorting ··· 114 124 115 125 r.loaded = map[*build.Instance]interface{}{} 116 126 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) 123 128 r.topoSort = cueexperiment.Flags.TopoSort 124 129 125 130 // By default we follow the environment's CUE_DEBUG settings,
+9 -3
internal/internal.go
··· 118 118 // EvalVersionUnset is the zero value, which signals that no evaluator version is provided. 119 119 EvalVersionUnset EvaluatorVersion = 0 120 120 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 + 121 127 // The values below are documented under [cuelang.org/go/cue/cuecontext.EvalVersion]. 122 128 // We should never change or delete the values below, as they describe all known past versions 123 129 // which is useful for understanding old debug output. ··· 125 131 EvalV2 EvaluatorVersion = 2 126 132 EvalV3 EvaluatorVersion = 3 127 133 128 - // The current default and experimental versions. 134 + // The current default, stable, and experimental versions. 129 135 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 132 138 ) 133 139 134 140 // ListEllipsis reports the list type and remaining elements of a list. If we