Release notes
What each release of CUE says about itself, newest first, to read across versions. Every commit a release contains, and its files, are on its own page.
v0.18
v0.18.0
Changes which may break some users are marked below with a warning.
Language
As a reminder, the try experiment and the shortcircuit experiment introduced in v0.17.0 are both still ongoing. Please give them a try and report any issues or feedback!
Strict embedding and the ... operator
Warning
The explicitopen experiment, ongoing since v0.15.0, is now stable: from language version v0.18.0 on, embedding is strict and needs no opt-in. A struct which embeds a closed value is now closed to that value’s fields, where before the embedding constrained only itself and left its sibling fields alone, and a comprehension’s conjunct closes its struct just like any other conjunct. The new postfix ... operator opens an embedded value again, so #A... embeds #A without closing the struct around it.
#A: {a: int}
x: {
#A // x is now closed to #A's fields
b: 1 // error: field not allowed
}
y: {
#A... // spread leaves y open
b: 1
}
Migrate a module with cue mod upgrade, described below, or by running cue fix --exp=explicitopen while it is still at an older language version and only then raising language.version in cue.mod/module.cue: a file at v0.18.0 or later has no way back, as an @experiment attribute can only enable an experiment. See the how-to guide and the proposal for the full design.
Postfix aliases and self
Warning
The aliasv2 experiment, also ongoing since v0.15.0, is now stable: from language version v0.18.0 on, the postfix alias syntax and the predeclared self identifier need no opt-in, and the old prefix syntax is no longer accepted.
x~(X): {a: 1, b: X.a} // was x: X={a: 1, b: X.a}
[string]~(K,_): {name: K} // was [K=string]: {name: K}
// A value alias becomes a let binding on self.
y: {
let Y = self
c: 2
d: Y.c // was y: Y={c: 2, d: Y.c}
}
As above, cue mod upgrade or cue fix --exp=aliasv2 rewrites the prefix form; cue fix --exp=explicitopen,aliasv2 applies both migrations in one pass. See the how-to guide and the proposal.
The new functions experiment
The new functions experiment adds function literals, function types, and calls to the language. A function literal declares its parameters, may constrain its result with ->, and defines its body after the final :; a call supplies arguments by position or by label. Functions are values: they unify with themselves and with function types, they capture the scope they are declared in, and they may be applied partially.
You can try this experiment on a module at language version v0.18.0 via the @experiment(functions) file attribute:
@experiment(functions)
add: func(a: int, b: int) -> int: a + b
scale: func(x: int) -> int: x * 2
out: add(1, scale(3)) // 7
A literal without a body denotes a function type, which constrains a function value in the same way a schema constrains a struct: an implementation unified with a function type must accept every argument the type admits, and callbacks are checked where they are passed. Function types match parameters by label, combining optional, required, and regular parameters as for struct fields. Recursion via closures, such as with a fixed-point combinator, is detected as a structural cycle (#4495). See the proposal discussion and its revision on function contracts for the full design.
The new openlists experiment
The new openlists experiment makes lists open by default, just like structs. A list literal without a trailing ellipsis is no longer fixed to its length outside of definitions, so unifying [3] with [_, 4] yields [3, 4] rather than an incompatible list lengths error. Lists close where structs close: within a definition, or when passed to close, which now accepts lists as well as structs.
The experiment also introduces closed literals: #[1, 2] means what [1, 2] means without the experiment, and #{a: 1} closes a struct at its own level as close does. As #[ now starts a closed list, an index on a definition named # is written (#)[i].
You can try this experiment on a module at language version v0.18.0 via the @experiment(openlists) file attribute. cue fix --exp=openlists rewrites existing files so they keep their meaning, writing list literals as closed literals and wrapping slices and builtin results in close. See the proposal for the full design.
Exact arithmetic
Warning
Integer addition, subtraction, and multiplication are now exact at any size, as the spec requires, rather than rounding to 34 digits. This also fixes strconv.FormatInt and uuid.FromInt failing on large integers (#3787, #4263), as well as SI multipliers on long literals, math.Floor, math.Ceil, and math.MultipleOf, which all rounded numbers beyond 34 digits.
Dividing two integers now yields an int when the quotient is exact, as the spec has always prescribed: 4 / 2 is the integer 2, so x: float & 10 / 5 is now a conflict. A quotient also keeps the decimal places its operands imply, so 6.00 / 3 is 2.00, and an exported float always carries a digit after its decimal point.
The list.Sum, list.Product, list.Avg, list.Range, list.Min, list.Max, math.Abs, math.Copysign, and math.Dim functions now follow the arithmetic operators, keeping the kinds of their arguments: list.Sum([1.5, 2.5]) is now the float 4.0 rather than the integer 4, so a field declared int no longer accepts it.
Other changes
A CUE file which belongs to no module can now declare the language version it is written for with a @version attribute, placed ahead of any other file attribute and the package clause, so that a reproducer or a standalone file written for an older version runs as written without creating a module for it. The attribute is an error in a file of a module which declares a language version, as the module file decides the version of its files.
@version(v0.17.0)
package p
File attributes such as @experiment(...) and @extern(embed) are now honored between the package clause and the import declarations, where the spec allows them, rather than being silently ignored or rejected (#2371).
Warning
Pattern constraints may no longer be marked as optional or required: [string]?: int and [string]!: int are now rejected by the parser, matching the spec grammar. A pattern constraint is optional by construction, so the markers had no effect; simply remove them (#3716).
The comparison bounds == and != now work with boolean values, so constraints like !=true behave as documented in the spec (#4388). Multi-line strings now accept a backslash-escaped newline (#2317), and for k, k in x is rejected as a redeclaration (#4012).
Evaluator
Closedness
Warning
Selecting through a regular field which holds a definition now keeps the definition’s closedness, just like selecting from the definition itself. Such selections inside a for comprehension’s body are now closed as well, as they already were inside an if.
#D: s: {a: 1}
d: #D
x: #D.s & {extra: 1} // error: field not allowed
y: d.s & {extra: 1} // now also an error
This most often shows up when a comprehension iterates over a definition and the values it yields are then extended with further fields, for example by a pattern constraint. If those values are meant as data to build on, declare them as a regular or hidden field instead of a definition, or leave the struct open with ....
Closedness also follows what a reference denotes rather than where it is evaluated. A reference which reaches into a definition from outside now closes the value it selects even when it is evaluated inside that definition, such as outside.s below, which was previously accepted. Conversely, a definition which refers to a regular struct no longer rejects a field which a sibling reference in that struct supplies (#4501).
outside: #Out
let Out = {s: {a: 1}, u: outside.s & {b: 2}} // error: field not allowed
#Out: Out
#P: {a?: int}
x: {q: {}, s: #P & q & {a: 3}}
#L: {v: x} // no longer rejects a
As the spec requires, an ellipsis in an embedding, as in s: {{#B, ...}, h: {i: 1}}, now opens only the struct it is part of, and no longer the structs declared beside the embedding, so that a field added to one of them, such as s: h: extra: 1, is rejected as field not allowed. Give such a struct its own ellipsis, as in h: {i: 1, ...}, or declare the field in it. Fields opened by the spread operator are also closed again in more cases, as the spec requires (#4525, #4528).
Performance
A reference unified with a definition or with a disjunction of definitions, as in deps: [...#Node] with #Node: #Task | #Group, is now shared with the value it refers to rather than evaluated again under every path, so that a dependency graph typed this way is evaluated once per node rather than exponentially in its depth, regardless of the order in which the fields are declared (#4512, #4513).
Configurations with many nested disjunctions, such as schemas imported from JSON Schema, evaluate up to 9% faster and allocate up to 16% less memory. A recursive disjunction wrapped in a struct no longer drops disjuncts and grows exponentially in cost (#4475), and exporting a struct holding many unifications of empty or single-field structs no longer takes memory exponential in their number.
Other changes
The order in which fields and comprehensions are written no longer matters: a configuration which only evaluated when a comprehension came after the fields it reads now evaluates in any order (#4098).
== and != now compare integers and floats numerically wherever they appear, so {a: 1.0} == {a: 1} and [1.0] == [1] are true, matching how 1.0 == 1 already behaved at the top level (#4120). cue.Value.Equals and list.Contains change in the same way.
The != and =~ bounds and the builtin validators of a field in an inline struct or a let which is read through a reference, such as by an interpolation, are now checked, where they were silently dropped. This surfaces conflicts which earlier releases accepted (#4510).
Errors are reported more completely and accurately. A missing required field now points at the data which omits the field, so that cue vet with many data files says which one is at fault (#2520), and an error inside an interpolation, as in "\(x.foo & {})", no longer evaluates to an empty string (#2201). Many other errors now carry the positions of the values involved, report all failing elements or disjuncts rather than only the first, or are no longer hidden behind a sibling error (#2507, #2615, #3986, #4115, #4462, #4477).
Fix several regressions introduced in v0.17.0: a vertex not initialized panic involving pattern-constrained maps (#4521), a disjunction’s default not applied when a comprehension guard reads it early (#4520), and spurious field not allowed errors with definitions embedded in lists or at a package root (#4522, #4523).
A number of hangs, panics, and spurious errors such as structural cycles have also been fixed, many involving disjunctions, comprehensions, or let bindings (#4176, #4399, #4428, #4440, #4447, #4448, #4449, #4453, #4474, #4478, #4479, #4487, #4490).
cmd/cue
The new formatter is enabled by default
Warning
The formatv2 experiment, announced in v0.17.0, is now enabled by default: cue fmt and the cue/format Go API are backed by a rewritten formatter. The new implementation resolves long-standing issues with the old one, in particular around the alignment of fields and trailing comments and the layout of multi-line expressions, so expect some reformatting when running cue fmt over existing files. It keeps the source’s line breaks between consecutive import declarations, as gofmt does (#1545), and between function parameters and call arguments (#4497).
The old formatter remains available via CUE_EXPERIMENT=formatv2=0 for v0.18; v0.17 also accepts the formatv2 experiment name, so the setting can be shared by teams using both versions. Please report any misformatting via the issue tracker, as we intend to remove the old formatter once the new one is stable.
Other changes
The new --language-version flag of the commands which read CUE outside a module, among them cue eval, cue export, cue vet, cue fmt, cue fix, cue import, and cue get go, selects the language version for files which belong to no module, including standard input. It is only a fallback: the files of a module which declares a language version keep that version, and a file’s own @version attribute takes precedence. CUE generated by cue import, cue get go, and cue get crd targets the chosen version.
cue fix without package arguments now fixes every file of the module, from any directory inside it. Its rewrites leave fewer structs wrapped in __closeAll or __reclose (#4534), and the explicitopen rewrite no longer closes values which the original left open.
CUE packages can now be combined with individual schema and data files in a single invocation, such as cue vet ./schemapkg extra-schema.json data.yaml, and the --package flag now treats individual CUE files the same way as packages (#3341, #3671, #3914).
cue vet now checks every data file, and every document of a stream, against the schema and reports all of their errors, rather than stopping at the first one which fails to unify (#2511), and honors all -d/--schema flags rather than only the last one (#3726). cue eval likewise carries on past a failing data file.
cue vet, cue export, and cue eval -c now report incomplete values, such as missing required fields, alongside any other errors, rather than leaving them out whenever another field had a conflict (#1319, #3358, #4140). cue eval --ignore --concrete now shows non-concrete values and reference cycles as errors, as documented (#2342).
-e expressions now apply only to the selected expressions, avoiding spurious errors from unrelated parts of the input (#3371), and are parsed and compiled at the language version of the module they are evaluated against, so they may use the features which are stable there, such as self to select a field whose name is not an identifier (#358, #4297).
Warning
The -n/--name flag is now only accepted by cue import, the only command where it had any effect (#3048), and the -s/--simplify flag is now only accepted by cue eval, cue fix, cue fmt, and cue trim. A --path value with a trailing component which is not a label, such as foo:bar:baz, is now rejected rather than silently ignored (#3368).
cue cmd now unifies data files named on the command line with the loaded package, as the other commands do (#4473), and its memory use no longer grows with the number of tasks which return a result: the peak memory of a command running 40 such tasks drops from about 500MB to about 125MB (#4509). Tool tasks now surface evaluation errors in their fields rather than treating them as unset, and tool/exec and tool/http gain a number of fixes, such as a timeout field for http.Do (#4467).
The cue binary is 7% smaller thanks to dropping most of the protobuf runtime from its dependencies.
Modules
The new cue mod upgrade command moves a module to a new language version, rewriting every CUE file of the module for that version, including those under cue.mod, before recording the version in cue.mod/module.cue. Files are rewritten without loading them, so a package whose import cannot be resolved is converted all the same, and a file which cannot be converted stops the upgrade before anything is written unless --force is given.
Each module’s files are now parsed at the language version that module declares, rather than at the main module’s version, so a module which has moved to v0.18.0 can still depend on packages written for an older version of CUE.
Module zips now order files before directories, as documented, which changes the digests of newly published modules. Publishing a version again with the same files reuses the archive already in the registry, so retrying a release job keeps working against registries with immutable tags (#3340).
cue mod get can now move a dependency off a version which no longer exists in the registry (#3965), a module version is downloaded at most once per process (#3413), and fetching modules through a registry proxy which compresses its responses or omits Content-Length now works. Registry errors now name the registry host and the module involved without repeating them, and report HTTP failures such as rate limits as such (#2952, #3611, #3696).
@embed now works in files named directly on the command line within a module, and in packages loaded from dependency modules (#4439), and a file using @embed without @extern(embed) now reports the missing declaration rather than silently ignoring it (#4010).
Wildcard package patterns such as ./.../name now match the package path in full rather than any of its suffixes (#3212), package directory arguments with a trailing slash or a relative form now behave consistently (#3707), and imports using a redundant package qualifier, such as foo.com/bar:bar, now resolve correctly in all cases (#4446).
LSP server
The language server now understands the function literals of the functions experiment: go-to-definition, find references, rename, completion, and hover work inside function literals and on labeled arguments, which resolve to the parameter they bind.
Standard library imports now resolve, so strings, list, and the rest offer completion and hover like any other package. Hovering over a field now shows its value with all conjuncts unified, and doc comments follow the semantic ownership rules of the language, such as attaching to the innermost field of a shorthand like a: b: c (#2672).
Fix a regression introduced in v0.17.0 where finding definitions and references failed through an import of a package from a transitive module dependency (#4553). The language server is also more robust, fixing a number of crashes and stale results, including with symbolic links and unusual files in a package directory (#4491).
As always, the language server is under active development: please report any bugs or missing features you encounter via the Issue tracker or via the #lsp channels on Discord or Slack. See our Getting Started wiki page for instructions on how to set it up with your editor.
Encodings
Experimental INI support
INI files can now be both imported and exported, such as via cue import config.ini or cue export --out ini (#2689). As INI has no specification, the default generic flavor only accepts the syntax which all flavors share, so that no data is lost; the flavor file tag selects the syntax of a particular tool, as in ini+flavor=git: for a git config file, with git, python, systemd, and windows supported. The encoding is experimental, so both the flavors and the CUE they decode to may still change.
OpenAPI documents
The new openapiv2 experiment teaches cue import and cue export to handle complete OpenAPI documents — including paths, servers, and security — rather than only their component schemas. Enable it via CUE_EXPERIMENT=openapiv2; the underlying Go APIs are encoding/openapi.ExtractV2 and encoding/openapi.GenerateV2.
cue get go
cue get go now follows encoding/json for embedded structs, promoting their fields without requiring an inline tag option (#1026), and emits them as a spread embedding, #Embedded..., in modules at language version v0.18.0 or later. It supports the encoding/json additions of Go 1.27, such as the embed option, and the new jsonv2 codec follows encoding/json/v2 instead (#4471).
The new --omit flag takes selectors such as pkg.Name, replacing the deprecated --exclude flag. Its pkg.Name.Method form translates a type as if it lacked an encoding method like MarshalJSON, so that a schema can be generated for types which only implement such methods to validate their input (#2466).
JSON Schema
The JSON Schema encoder can now generate JSON Schema draft-07 and the OpenAPI 3.0 dialect in addition to draft 2020-12, and its output is improved in many ways, such as exact numeric bounds and format keywords for sized number types (#2529, #4438).
The JSON Schema decoder now supports unevaluatedProperties where the evaluated properties are known statically, such as via allOf and $ref, and unifies allOf subschemas so their fields and documentation appear in the result.
YAML
The new --out yaml+indentSequences=false encoding tag emits the zero-indent list style favored by Kubernetes and others (#4177). A @yaml tag can now be given to a list element or an embedded value via a declaration attribute, as in {"x", @yaml(,tag="!Env")}.
The YAML encoder now quotes strings which YAML 1.1 decoders would read as values of other types, such as 0x_ or =. The YAML decoder once again decodes YAML 1.1 octals with a sign, such as -0123, and floats with a leading zero, such as 01289.5, fixing a regression introduced in v0.17.0, and decodes integers beyond 64 bits as integers. Merge keys referencing an alias count towards the limit on alias expansion, and no longer panic or overflow the stack on an alias to a sequence or to the mapping being merged into.
Other changes
New output encoding tags --out cue+compact and --out json+compact emit compact single-line output, and cue import now prefers hash-delimited strings like #"..."# when they avoid escaping (#124).
The TOML decoder now takes linear time, where large inputs took quadratic time (#4580).
Standard library
Warning
uuid.ToInt now decodes the 128-bit value of its UUID, as documented, rather than converting the bytes of its string form, so its results change. Any form accepted by uuid.Parse yields the same value, which round-trips through uuid.FromInt.
list.Sort, list.SortStable, and list.IsSorted no longer panic on a comparator whose less field comes from a comprehension, an embedding, or a unification (#3063).
math.Pow now returns 1 for a zero exponent with any base, including zero, as documented (#4506).
Go API
The new cue.Unify function unifies many values at once, more efficiently than a chain of Value.Unify calls.
cue/ast’s new Clone function copies a syntax tree, including its comments and its resolved references, so a tree can be rewritten without disturbing the original. Its new DocComments and ResolveComments functions report the doc comments that semantically document a node, resolving the field-shorthand convention.
cue/format exposes the knobs of the new formatter: its new Indent, IndentWidth and LineWidth options control the indentation string, its visual width, and the target line width, and its new Compact option renders a value on a single line. UseSpaces and TabIndent are deprecated in favor of Indent and IndentWidth; go fix migrates uses of UseSpaces.
cue/load.Config.LanguageVersion sets the fallback language version for input which belongs to no module, as the --language-version flag does, and the new cue/build.Instance.TargetLanguageVersion reports the version which cue.Value.Syntax targets for an instance. The new encoding/jsonschema.CRDConfig.TargetLanguageVersion field lets encoding/jsonschema.ExtractCRDs generate schemas for modules declaring an older language version.
The experimental encoding/jsonschema.GenerateMany function generates several schemas at once with a shared pool of definitions, as used by the new OpenAPI generator.
The Go code generated from cue.proto is now shipped as the encoding/protobuf/cueproto package, so proto definitions using CUE options can be compiled without extra setup (#581). The compatibility shim at encoding/protobuf/cue is deprecated and will be removed in v0.19.
Programs embedding CUE could be far larger than necessary, as the text/template builtin and cue/stats looked up methods by name, which stops the Go linker from discarding unused exported methods anywhere in the binary; one reported binary was 66MiB rather than 25MiB (#4514). cue/stats no longer does so, and building with the cuenotemplate build tag leaves the text/template package out of the standard library so that the linker discards unused methods again, at the cost of CUE code importing text/template failing.
cue.IsIncomplete now reports an error combining several others as incomplete only when all of them are, so that a permanent error is never mistaken for an incomplete one, and lists of errors from cue/errors now implement Unwrap.
A number of APIs, such as exporting values and cue/ast/astutil.Sanitize, no longer modify the values or syntax trees given to them, which also fixes data races when using them concurrently, as well as in cue.Iterator.Next and cue.Value.LookupPath.
cue.Value.Decode once again prefers a tagged field over an untagged one at the same depth, fixing a regression introduced in v0.9.0, and converting a Go struct to CUE now names its fields as encoding/json does (#2261). cue.Context.Encode now honors the omitzero JSON struct tag (#4429) and encodes a nil pointer of any type as null rather than panicking.
A number of panics and other bugs in cue.Value methods such as Allows, Subsume, and Unify have been fixed (#4387, #4496, #4545, #4549).
Inlining imports, via cue def --inline-imports or cue.InlineImports, now handles let declarations and values which have been unified or merged with data files, rather than emitting unresolved references (#2252, #2495, #3484).
cue/parser no longer takes quadratic or worse time on some pathological inputs, such as deeply nested parentheses, calls, or function signatures.
tools/flow now supports tasks in a value below the root of its instance (#2185), and fixes a data race (#2184), leaked goroutines (#2663), and the handling of tasks returning ErrAbort.
v0.17
v0.17.1
Evaluator
Fix several regressions introduced in v0.17.0: a panic when evaluating some disjunctions (#4419), and spurious invalid interpolation (#4420), field not allowed (#4423), and structural cycle (#4430) errors involving comprehensions or self references.
Fix two regressions introduced in v0.17.0 where evaluation could hang (#4421, #4422), as well as two long-standing hangs on self-referencing configurations (#2766, #4231).
cmd/cue
Fix a panic in cue exp gengotypes, a regression introduced in v0.17.0, when a definition references a definition from another package via embedding (#4436).
Module replacements are now subject to minimum-version selection like any other dependency. cue mod tidy now normalizes a fully-pinned replacement to its major version and records the target as a regular dependency.
v0.17.0
Changes which may break some users are marked below with: ⚠️
Language
The active try experiment renames the new fallback keyword, used with for comprehensions, to otherwise. fallback continues to be accepted for now, but is rewritten to the new form.
The active aliasv2 experiment now allows ~(X) as an alternative to ~X for the single postfix alias form. ~X is also rewritten as ~(X) for the sake of consistency and clarity.
Language versions v0.17.0 and later allow omitting commas in multi-line lists. Just like a newline after a struct field implies a comma, a newline after a list element now implies a comma as well.
Language versions v0.17.0 and later allow a newline or a comma before the closing bracket of an index expression, matching how lists and func arguments allow omitting trailing commas.
The language spec is tweaked to make $ a valid identifier, which was already allowed by the parser and evaluator.
⚠️ Support for the infix div, mod, quo, and rem operators has been removed. Since late 2020, these infix forms have been undocumented and rewritten by cue fix to the new function calls.
The new shortcircuit experiment
This release introduces the shortcircuit experiment, which changes the && and || operators to not evaluate the right operand if the left operand alone determines the result.
This matches the behavior already documented in the CUE spec and is consistent with most mainstream languages, but for the sake of a smooth transition for end users, we are rolling out this change via an experiment.
You can try this experiment via the @experiment(shortcircuit) file attribute. To mimic the old behavior with the experiment, you can use a hidden field:
_y: Y
if X && _y {}
Evaluator
Comprehensions
The comprehension algorithm now waits to run a comprehension’s body until the fields it reads have a concrete value, rather than trying to produce its fields up front. This resolves a number of long-standing bugs, most notably the last known regressions from evalv2, where a comprehension that should have resolved instead failed as an incomplete value or a cycle.
This design also greatly simplifies upcoming evaluator work, such as introducing new builtins to replace comparing values to bottom, as well as the design of evalv4.
Other changes
The evaluator no longer deduplicates errors just by position, which was causing some useful errors from disjunctions or standard library calls to be dropped incorrectly.
Several long-standing cycle-detection bugs have been fixed, such as self-referential uses of matchN and matchIf, self-feeding disjunctions, and comprehensions that read a let binding which refers back to the comprehension’s own fields.
Fixed a bug where the same package imported via different qualified import paths (e.g. foo.com/bar@v0 or foo.com/bar:baz) did not share the same hidden field namespace.
Resolving an unversioned import from a dependency module now respects that module’s own default major version, instead of always using the main module’s default.
Fix a number of issues where cue def could produce invalid CUE output, such as due to name conflicts.
Fix an evaluator regression where embedded disjunctions across packages may not correctly apply closedness.
Fix an evaluator bug where cue.Context.BuildExpr of close({}) did not actually result in a closed struct.
Fix a bug where some calls to standard library functions or validators did not include the “error in call to pkg.Func” error context, or included it twice.
A few changes to the evaluator should reduce allocated objects by up to 16%, reducing GC overhead and memory usage.
To ease the transition into the new formatter we plan to release with v0.18, CUE_EXPERIMENT=formatv2=0 is now allowed as a no-op.
A number of other bugs, panics, and hangs have been resolved as well.
cmd/cue
Module replaces
CUE now supports substituting a module dependency with a local directory or a different remote module during development - for example while testing a fix to a dependency before it is published, or to replace a dependency with a fork including improvements.
This configuration lives in cue.mod/local-module.cue, which is excluded when publishing to registries. cue mod edit and cue mod tidy gain support for maintaining this file.
We have also published a how-to guide on replacing a dependency with a local module.
Read the full design doc in the proposal, or read the cue.mod/local-module.cue reference docs.
Other changes
The new global -C or --chdir flag runs cue from the given working directory.
Command input parsing is improved so that CUE packages can come after data files, such as cue vet -c data.yaml ./schema.
cue import --with-context now ensures that data represents the original raw input data, and not its interpretation like JSON Schema.
cue import --path now skips over null values in an input stream, such as empty documents in a YAML file.
Fix a bug where the flag cue export --path was ignored when the inputs were pure CUE.
The new cue exp gengotypes --outfile flag controls the output file path when generating a single package.
cue vet -d/--schema now supports hidden fields, and correctly reports an error when the command inputs are CUE only.
cue fix and cue trim no longer change file modification times when no changes are necessary.
A $CUE_CACHE_DIR directory is no longer required when loading CUE without external dependencies.
The “filetypes” lookup tables now use a more compact encoding, saving about 150KiB in binary size for cmd/cue as well as Go API users.
LSP server
Add an initial version of organize-imports, which sorts the existing imports and removes unneeded imports. It is not yet capable of suggesting missing imports.
Wait for a short period of inactivity before sending diagnostics to the editor. This “debounce” means that a user typing incomplete CUE syntax will not be distracted with syntax errors as much.
The aliasv2 experiment is now fully supported.
The rename function is fixed to distinguish between field names and aliases.
Improve field name analysis in general so that fields with multiple aliases (e.g. v=[k=string]: _) are properly supported.
Improve attribute handling for file-level embedded attributes, and to attach attributes within expressions to the correct struct.
Treat conjunctions (&) and disjunctions (|) the same way for goto-definition. With the cursor on a path, it returns all results that the path MAY resolve to. With the cursor on a field declaration name, it returns all results that the path constructed from the field’s name, and its field’s name (and so on) MAY resolve to.
Special-case close function calls so that paths can resolve through fields within the argument to close.
Encodings
⚠️ The experimental JSON Schema encoder now emits most definitions without the leading # character, shortening names and ensuring compatibility with the wider JSON Schema ecosystem. This required deprecating encoding/jsonschema.GenerateConfig.NameFunc in favor of NamesFunc.
The JSON Schema encoder is improved to support list.UniqueItems and standalone validators, to use maxItems and minItems instead of maxLength and minLength for lists with prefix elements, and to generate description keywords for doc comments.
Several closedness bugs in the JSON Schema encoder have been fixed, ensuring that the generated JSON Schema behaves the same way as the original CUE definition.
The JSON Schema decoder is improved to better handle the prefixItems keyword.
The ProtoBuf decoder now resolves relative references following the usual scoping rules, instead of always resolving them against the top-level scope.
Standard library
Add time.ToUnix and time.ToUnixNano, which convert an RFC3339Nano time value into seconds or nanoseconds since the Unix epoch, complementing the existing Unix builtin.
strconv.FormatFloat now accepts a string format parameter, like FormatFloat(3.14, "e", 4, 64).
list.MatchN now shows what expected value it’s matching against when it fails.
The net IP APIs now consistently return an error on invalid input types.
Go API
Using cue.Values concurrently is now fully supported, which required deprecating cue.Value.Context. If you encounter any races or bugs, please report them via the issue tracker.
cue/load now supports loading from an io/fs.FS, as outlined in proposal #4285. Loading file embeds through Config.Overlay and Config.FS is supported now as well.
cue/ast/astutil deprecates Sanitize in favor of the new SanitizeFiles API, given that Sanitize on a single file cannot know if another file in the same package shadows builtin names like self.
Add Path.Compare and Selector.Compare, providing allocation-free total ordering suitable for slices.SortFunc.
Clarify that cue/format indents with a tab width of 4 by default.
A new fuzzer has been introduced in the cue package, checking that the parser doesn’t crash and that its results are consistent with the rest of the Go APIs like cue/literal. So far, it has already resulted in seventeen bug fixes.
The cue.Interpreter option API has been deprecated in favor of cue.WithInjection, which is a better name going forward.
⚠️ cue/ast.File.Imports, deprecated in mid 2025 in favor of cue/ast.File.ImportSpecs, is now removed.
⚠️ The long-deprecated and hidden cue.Instance methods Lookup, LookupDef, LookupField, and Fill are now removed.
⚠️ The modconfig.Registry interface is changed to report default major versions, which is required for resolving unversioned imports against each dependency module’s own defaults. Clients that implement or wrap the interface will need to update. The new interface is future-proofed for upcoming modules changes.
v0.16
v0.16.1
Language
The fallback keyword in the aliasv2 experiment is replaced by otherwise, which is clearer. cue fmt or cue fix can be used to rewrite existing code.
Evaluator
Fix a regression where the compiler could add comments to the input AST value, which could lead to increased memory usage.
Fix a bug where exporting certain schemas could result in “cannot have both alias and field in same scope” errors.
cmd/cue
Fix a panic which could occur when using non-label expressions in the --path flag.
Teach cue login to give helpful errors when used with OCI registries which don’t support the OAuth2 device flow.
Go API
Fix a regression where cue.Context.Encode could panic on custom marshaler types with pointer receivers.
v0.16.0
Changes which may break some users are marked below with: ⚠️
Language
As a reminder, we have two ongoing language experiments since v0.15; a replacement for struct embedding and a rework of aliases. Please give these a try and report any issues or feedback!
⚠️ The cmdreferencepkg global experiment is now stable, meaning that CUE_EXPERIMENT=cmdreferencepkg is always enabled.
#"""# is now accepted as a string literal quoting a double quote, ".
Multiline string literals now require a trailing newline, matching the language spec.
The new try experiment
This release introduces the try experiment, which adds a try clause in comprehensions as well as the use of ? in field selectors. This addition to the language is intended to provide a more concise syntax for handling optional fields without the risk of unintentionally swallowing errors.
This experiment also introduces the else clause for if and try comprehensions, and the fallback clause for for comprehensions, which trigger when a comprehension produces zero values.
You can try this experiment by following our how-to guides on the try clause and the else clause. For more information, see the proposal on GitHub and the spec change patch.
Evaluator
Performance
Further improve the use of caching in the typochecker algorithm; this provides speed-ups of up to 80% on some large projects.
Very large structs (tested with 20,000 fields) are up to 80% faster now, as we were repeating some work unnecessarily.
A great deal of effort has gone into reducing the allocations and memory usage across a number of projects. For some of these, memory usage is down by as much as 60%.
These improvements were possible thanks to our Unity service, letting us analyze CUE’s performance and test for regressions on third party projects. Contact @mvdan on Discord, Slack, or via the Unity page to ensure that your project is included or you are running into slowness.
A number of changes were made to improve support for using cue.Values concurrently; see Issue #2733 for more details and ongoing progress.
Other changes
Fix a regression introduced in v0.13 where the or built-in with literal arguments could stop behaving like a disjunction.
A number of panics and other bugs in the evaluator which were reported since v0.15.0 have been fixed; thank you to all who reported these.
cmd/cue
Add support for $DOCKER_AUTH_CONFIG to directly provide the contents of $DOCKER_CONFIG/config.json to authenticate with module registries, matching Docker’s current behavior.
The --outfile flag now works when given non-regular files such as named pipes or sockets.
⚠️ cue mod publish no longer ignores sub-directories containing a go.mod file.
⚠️ Using cue inside the cue.mod directory now fails consistently with a clear error message to not place CUE code there. Previously, some commands worked while others failed with confusing errors.
⚠️ The global --verbose and --trace flags have been moved to the cue get go and cue trim commands respectively, as they were the only ones actually using those flags, and this could be confusing to users.
Fix a bug where loading ./...:pkgname could lead to loading directories without CUE files as instances, which could cause poor performance for CUE packages with multiple parent directories.
cue exp writefs gains an encoding optional field for regular files, to specify an encoding rather than infer it from the filename extension.
LSP server
Initial LSP support for editing embedded JSON and YAML files. This feature provides completions and hover-docs when editing JSON or YAML files which are embedded into CUE via the @embed attribute. A teaser video is available on YouTube.
Code Actions: two code actions are now provided, Add surrounding struct braces and Remove surrounding struct braces, which convert between
a: b: c
and
a: {
b: c
}
with the cursor on b.
A complete overhaul of how the LSP server suggests code completions. This solves the previous naïve implementation which would only make suggestions after a field name or path had been started. Now completions are available from within whitespace.
Embedded paths with mutual dependencies: embedded paths with multiple components (e.g. a.b.c) can in some cases only be fully resolved after the resolution of other embedded paths. The LSP server can now correctly handle these dependencies.
The LSP server now implements LSP Document Symbols functionality. This is often used by editors to provide light-weight breadcrumb navigation within a file.
Some preliminary diagnostics are now sent from the LSP server back to the editor. Initially this mainly indicates syntax errors in CUE files, but this can be extended in the future.
Many bug fixes, including better behaviour for files and directories with spaces; improvements for value aliases (foo: L=x); LSP rename now provides placeholder text; improved jump-to-definition behaviour for package-level fields; fixed issues around imports; path resolution; formatting of standalone CUE files; and others.
See our Getting Started wiki page for instructions on how to set it up with your editor.
Please report any bugs or missing features you encounter via the Issue tracker or via the #lsp channels on Discord or Slack.
Encodings
Add support for encoding YAML tags like key: !Custom value by using CUE attributes like key: "value" @yaml(,tag="!Custom").
cue get go now detects which Go packages use Kubernetes type semantics via // +k8s:openapi-gen=true and obeys the field annotations // +optional and // +nullable.
cue get go gains a --codec flag to configure the use and priority of Go struct field tags like json or yaml.
Fix a bug where cue get go could skip over fields whose type implements one of the supported marshaling interfaces.
Fix a few bugs where cue get go could result in invalid or failing CUE code.
JSON Schema’s Config.OpenOnlyWhenExplicit option is now exposed for the CLI via the filetype tag jsonschema+openOnlyWhenExplicit.
JSON Schema now properly encodes hash references for better compatibility with other tools.
Standard library
The strconv package adds ParseNumber, like ParseInt or ParseFloat but allowing other CUE number strings such as 1Ki.
The net package adds InCIDR to test whether an IP is contained by a CIDR string.
The net package adds ParseCIDR to extract useful information from a CIDR string.
The net package adds CompareIP to compare two IP addresses, which can be useful for computing with IP ranges.
The net/http package adds Serve as an experimental API to listen on a port and serve HTTP requests.
The tool/file package adds Symlink to create symbolic links.
Go API
cue.Value.Decode now supports the new cue.Unmarshaler interface, allowing Go types to implement their own CUE value decoding logic via an UnmarshalCUE(cue.Value) error method.
The new cue.IsIncomplete function reports whether the given value is a CUE incomplete error.
cue/ast gains the NewPredeclared and Ident.IsPredeclared to mark and detect identifiers referencing predeclared names like error or int rather than fields which may shadow those names in the current scope.
⚠️ cue.Value.Decode now uses cue.IsIncomplete to not treat incomplete errors as fatal, allowing the decoding to continue.
Fix a bug where cue.Value.Decode could behave incorrectly when decoding a CUE null or incomplete value.
⚠️ cue/token.Compare now sorts absolute paths before relative ones, to ensure consistent behavior between Unix-like systems and Windows.
⚠️ The long-deprecated cue/ast.Node.Comments and cue/ast.Node.AddComment interface methods are now removed; use cue/ast.Comments and cue/ast.AddComment respectively.
⚠️ The long-deprecated and unused cue/parser.FromVersion and cue/parser.DeprecationError APIs are now removed.
⚠️ The long-deprecated and hidden cue.Instance.Eval method is now removed.
v0.15
v0.15.4
Evaluator
Fix a panic which could occur when using the error built-in with cyclic references.
Fix a panic which could occur when loading @experiment(aliasv2) syntax with an invalid alias name.
cmd/cue
Relax the cue login --token validation to allow future Central Registry token types.
Encodings
Fix a bug in the TOML decoder where nested arrays were causing incorrect “duplicate key” errors.
v0.15.3
Evaluator
Fix a panic which could occur when using Expr after LookupPath on a cue.Value.
cmd/cue
Fix a panic which could occur when using cue cmd tasks referencing definitions.
Fix a panic which could occur when cue get go encountered a Go enum type with zero named values.
Encodings
Fix a bug in the TOML decoder where nested arrays were not being correctly mapped to CUE values.
v0.15.1
Evaluator
Fix an evalv3 regression first introduced in v0.11.0 where the and built-in function started evaluating its arguments too eagerly, causing failures in cue def.
Fix an evalv3 regression where closedness info could be lost when using a comprehension.
Fix a bug where the evaluator would panic on alias cycles with dynamic fields rather than giving a good error.
LSP
Formatting standalone CUE files - either without a package name, or outside of a CUE module - now works correctly.
Fix a bug where trying to use “find references” on a CUE module with nested modules would cause a hang.
Fix a bug where resolving path roots did not work correctly in the presence of struct embeddings.
cmd/cue
Fix a regression in v0.15.0 where cue get go no longer skipped generating CUE files without any declarations.
Go API
Fix a bug in the subsume package where a struct with a pattern constraint did not subsume a closed struct with a matching field.
Rename the bootstrap build tag used in the internal/filetypes package to cuebootstrap to avoid conflicts with build tags in other Go modules.
v0.15.0
Changes which may break some users are marked below with: ⚠️
Note that this release no longer includes a checksums.txt asset; GitHub now provide digests natively.
LSP
This release includes the initial version of cue lsp - with support for “go to definition”, “find references”, rename, code completion, hover documentation, and code formatting.
See our Getting Started wiki page for instructions on how to set it up with your editor.
Please report any bugs or missing features you encounter via the Issue tracker or via the #lsp channels on Discord or Slack.
Language
explicitopen experiment for #A...
The explicitopen per-file experiment enables the posfix ... operator to explicitly open closed structs, allowing additional fields to be added. This change simplifies CUE’s semantics, reduces user confusion, and enables clearer expression of type extensibility patterns.
You can try this experiment by following our how-to guide. For more information, see the proposal on GitHub and the spec change patch.
aliasv2 experiment
The aliasv2 per-file experiment implements the new “postfix aliases” syntax, and introduces a “self” predeclared identifier referring to the innermost surrounding struct or list.
You can try this experiment by following our how-to guide. For more information, see the proposal on GitHub and the spec change patch.
Other experiments
⚠️ With its proposal accepted, the keepvalidators global experiment is now stable, meaning that CUE_EXPERIMENT=keepvalidators is always enabled.
With its proposal accepted, the structcmp per-file experiment is now stable with language.version at v0.15.0 or later, meaning that the @experiment(structcmp) attribute is unnecessary as it’s always enabled.
Evaluator
⚠️ Removing evalv2
The old evalv2 evaluator, which previously could be re-enabled via CUE_EXPERIMENT=evalv3=0, is now deleted. The new evalv3 evaluator has been on by default since v0.13.0, and at this point our entire test suite including Unity is working.
Removing the old evaluator reduces significant load on development, as we were able to clear out 4000 lines of code, and simplify the internal types and code structure. This is a necessary step to unblock ongoing feature and performance work in the evaluator.
As a bonus, because the old and new evaluators shared many core evaluator types, removing the fields only used by the old evaluator yields modest memory usage improvements of around 4-6%.
Performance
Evaluating concrete CUE values no longer involves dependency analysis; this should result in modest speed improvements when marshaling to YAML, via either cue export -e expr -o yaml or yaml.Marshal.
Dependency analysis now avoids computing references more than once, which resolves an expontential performance issue for some configurations using chains of CUE references.
Add caching to a part of the typochecker algorithm; this has been measured to provide performance improvements of up to 30% on a few large projects.
cue/parser now reuses more memory, which results in parsing performance improvements of up to 30% and memory savings of up to 50%, especially when loading large CUE data files.
Other changes
File embedding via the @embed attribute has gained an allowEmptyGlob option, to allow glob patterns to match zero files without causing an error.
The evaluator now shows all user errors created with the error builtin when they can be related to a disjunction failure. Previously, the evaluator would try to only show user errors directly part of a disjunction error, but that caused too many omissions.
Some error positions which were lost in the transition from evalv2 to evalv3 have been reintroduced.
Fix a bug where required fields in a definition might not be enforced when unifying with an inline struct in an expression, such as (#RequiresFoo & {bar: "baz"}).bar.
Fix a regression introduced in v0.12.0 where incomplete errors were not being handled consistently if they directly involved the top-level value.
A number of panics and error regressions in the evaluator which were reported since v0.14 have been fixed; thank you to all who reported these.
cmd/cue
A new cue help experiments command is introduced to document all available per-file and global experiments.
The cue fix --exp flag is introduced to rewrite files or packages to use new and experimental semantics with @experiment attributes.
cue mod mirror now copies OCI referrers between registries, which ensures that artifacts like signatures and attestations which reference modules being mirrored are copied as well.
cue mod resolve gains a --deps flag that lists all dependencies of the current module and which registries they resolve to.
cue get go gains an --outfile flag to generate exactly one CUE file for a single Go package, which can be useful when integrating cue get go into build systems like Bazel.
Fix a regression introduced in v0.9.0 where loading a qualified pattern like ./...:pkgname no longer filtered files based on the package name given.
cue get go now stops on any Go package loading error. Trying to continue in the presence of syntax or type-checking errors could lead to generating incorrect CUE.
Encodings
Initial support for encoding CUE schemas as JSON Schema is added. This includes a new encoding/jsonschema.Generate Go API, as well as CLI support via cue def --out jsonschema. This is currently very experimental, and many features are missing. For now, it can only generate a single version of JSON Schema, draft/2020-12.
The YAML library in the archived Go module gopkg.in/yaml.v3 has been replaced by go.yaml.in/yaml/v3, an active fork now maintained by the YAML organization.
cue exp gengotypes is improved to handle more edge cases with CUE package imports which could result in broken Go code.
The Protobuf decoder has been tweaked to not require files such as google/protobuf/timestamp.proto to exist on disk, given that they are mapped to CUE standard library APIs directly.
The Protobuf decoder has also been tweaked to support fully qualified references such as my.pkg.name.MessageName.
A bug is fixed in the TOML decoder where sub-table keys could incorrectly lead to duplicate key errors.
Standard library
The net package has gained new AddIP and AddIPCIDR functions to add numerical offsets to IP addresses or CIDR networks.
The Atoi, ParseInt, and ParseUint functions in the strconv package now work on integers with unlimited precision, like the rest of the CUE evaluator, rather than just a maximum of 64 bits.
Go API
The new cue.Value.IsClosed and cue.Value.IsClosedRecursively methods report whether a value has been closed at the top level or recursively, which is useful information when writing schema encodings.
The new cue.Patterns and cue.Selector.Pattern APIs allow introspecting pattern constraints in CUE struct values.
The new encoding/yaml.Decoder API allows decoding a stream of YAML documents, given that existing APIs did not support streams of multiple YAML documents.
encoding/json gains JSON Pointer APIs, which are already useful in packages like encoding/jsonschema.
cue/ast introduces PostfixExpr to support upcoming additions to the language syntax.
cue/ast introduces StringLabelNeedsQuoting to determine whether a string label needs to be quoted when used in CUE syntax.
cue/ast introduces NewStringLabel to create an ast.Label as either an unquoted identifier or a quoted string, depending on whether the string label needs quoting.
tools/fix has gained new APIs to fix configs to use an active experiment, as well as fixing configs to a newer language version.
cue introduces a Path.Append convenience method.
⚠️ cue/build.Instance.Match is removed, given that it was never set to any value at any point since it was added.
cue/token is adjusted so that node positions within a file never result in an offset which is outside the bounds of the file. This could easily lead to subtle bugs or panics when using node position offsets.
⚠️ The cue/token.Pos.Before method is now rewritten to match cue/token.Pos.Compare, given that it always returned “false” for positions from different files. The method is now deprecated as well.
cue/errors is adjusted so that Positions only collects printable positions, to prevent printing empty positions in the CLI.
cue/ast deprecates the File.Imports field in favor of the File.ImportSpecs iterator method. The iterator method File.ImportDecls is also introduced for completeness.
⚠️ The long-deprecated cue.ResolveReferences option API is now removed.
cue/parser.DeprecationError.Version is deprecated, as tracking CUE language versions via integers has not been used since v0.4.3, and the mechanism was never properly documented.
v0.14
v0.14.2
v0.14.1
v0.14.0
This release brings significant performance improvements, three language changes, and initial support for Kubernetes CRDs.
Changes which may break some users are marked below with: ⚠️
Evaluator
Performance
A particularly slow part of the new closedness algorithm has been rewritten for speed, resulting in improvements of up to 10x in wall times for some projects.
Significant progress has been made to the new evaluator’s memory usage; a few large projects experiencing high memory usage on v0.13 now see reductions of up to 80%.
Various other optimizations and performance bug fixes have been made to the new evaluator, yielding speed-ups of 5-20% on a variety of CUE projects.
error builtin
A new error builtin is added to the language, which allows users to create custom error values with a specified message.
Don’t simplify validators into concrete values
A new CUE_EXPERIMENT=keepvalidators experiment is introduced, already on by default, which prevents validators from being simplified into concrete values.
X == Y and == X
Firstly, there were several bug fixes related to ==. Most notably, [int] == [int] incorrectly resolved to true. It now correctly resolves to an error.
All other changes are enabled using the @experiment(structcmp) file-level attribute.
Enabling this experiment allows all CUE values to be compared for equality. This includes comparing structs.
The same experiment also allows a unary == to enforce that a value is a specific concrete value.
Other changes
⚠️ The file embedding experiment can no longer be disabled via CUE_EXPERIMENT=embed=0, having been introduced in CUE v0.10.0.
File embedding is now enabled when using the cue/cuecontext or cue/load APIs; earlier versions could not expose it via the Go API due to an import cycle.
⚠️ The topological field sorting experiment can no longer be disabled via CUE_EXPERIMENT=toposort=0, having been introduced in CUE v0.11.0.
⚠️ CUE_EXPERIMENT=cmdreferencepkg, introduced in v0.13.0 to require referencing tool packages to declare cue cmd tasks, is now on by default.
The new closedness algorithm has been adjusted to fix a number of “field not allowed” bugs, particularly in the form of regressions compared to the old evaluator.
A particularly slow part of the new closedness algorithm has been optimized, resulting in improvements of up to 10x in wall times for some projects.
cmd/cue
⚠️ cue def --strict jsonschema:, deprecated in favor of cue def jsonschema+strict: in v0.11.0, is no longer supported.
Two bugs have been fixed in the new cue trim algorithm where disjunctions could incorrectly select defaults or be treated as ambiguous.
Encodings
cue get crd introduces support for extracting Kubernetes Custom Resource Definitions (CRDs) as CUE definitions; see cue help get crd.
The new encoding/jsonschema.ExtractCRDs Go API exposes the extractor used by cue get crd.
The JSON Schema decoder has gained support for dependencies, bringing the pass rate for the official JSON Schema test suite up from 79% to 81%.
Go API
cue/load now provides module information via the new Instance.ModuleFile field.
⚠️ In order to support the above change, the mod/modfile.File.Format method has been moved to the function mod/modfile.Format: an API-breaking change but necessary to avoid a cyclic package dependency.
cue/parser gains a new Config API, which allows other packages like cue/load to properly apply the right parser options such as the CUE language version.
⚠️ In order to support the above change, the cue/parser.Config.ParseFile and cue/build.ParseFile signatures have now changed (incompatibly) to add a parser.Config argument, enabling the CUE language version to be passed through.
Fix an issue where cue.Value.Decode did not work with *math/big.Float types.
v0.13
v0.13.2
Evaluator
Fix a regression causing odd number of disjuncts to misbehave in some cases.
v0.13.1
Evaluator
The evaluator’s core packages no longer depend on the golang.org/x/mod module, which was only used to format version strings.
Fix a regression causing “cyclic field to reference” in some cases.
Fix a regression causing closedness rules to not apply in some cases.
Disable a minor optimization which was also causing closedness rules to not apply in some cases.
cmd/cue
Fix a build error triggered by changes in the upcoming Go 1.25 version, allowing v0.13 to be used further into the future.
cue mod mirror --dry-run now works as documented; it had been left unimplemented by accident.
v0.13.0
This release finally enables the new evaluator by default – the culmination of over a year’s worth of work!
It also packs in lots of new features, such as support for absolute module packages, dozens of JSON Schema improvements, and a new experimental XML encoding.
Changes which may break some users are marked below with: ⚠️
Evaluator
The new evaluator first introduced in v0.9.0 via CUE_EXPERIMENT=evalv3 is now enabled by default! There are no remaining substantial regressions in our test suite, and the Unity corpus is almost entirely working now. Given that the new evaluator fixes dozens of bugs for many users, and is already significantly faster for the majority of CUE users, we believe it is time to turn it on by default.
We will continue to track any remaining issues for the new evaluator via the evalv3 label. If you encounter any regressions, please file a bug report. You can also revert to the old evaluator to temporarily work around bugs via CUE_EXPERIMENT=evalv3=0. See this FAQ page for more information.
We aim to resolve many of these remaining bugs in an upcoming v0.13.1 bugfix release.
An entirely new algorithm for cue trim and tools/trim has been implemented for evalv3, which resolves all known bugs when trimming CUE.
Closedness in evalv3 has been revisited to match the semantics of evalv2 much more closely, while at the same time reducing its overhead for larger configurations. This fixes most “field not allowed” regressions and improves the performance of some configurations by up to 5x. As a result, CUE_DEBUG=openinline is now removed as it is unnecessary.
Performance work for the new evaluator is ongoing; a number of changes in this release led to performance improvements of between 5% and 80% for a variety of projects. For more details, see Marcel’s performance update last month.
⚠️ The new topological sort algorithm for field ordering has been tweaked to avoid becoming too slow in some cases. This may result in some ordering changes, but we expect them to be relatively small. See the change for more details.
The parser now correctly allows keywords as required field labels, such as if!: _, fixing a discrepancy with the spec.
Filenames beginning with a dot can now be embedded as long as the glob pattern uses an explicit dot, such as @embed(glob="dir/.data_*.json").
⚠️ @embed(glob="pattern...") directives whose file globbing results in zero files now result in an error, to avoid situations where a glob pattern silently stops working as intended.
cmd/cue
Initial support for absolute packages is introduced, which allow specifying a remote package at a particular version such as cue export foo.com/data@v1.2.3 or cue vet foo.com/schema@v1.2.3 -d '#schema' data.yaml without requiring a CUE module file locally.
The cue help filetypes logic, written itself in CUE, no longer requires using the evaluator to parse CLI arguments or load CUE packages. This results in significant speed-ups when using the CLI with many inputs.
The new cue refactor imports command rewrites import paths, making it easy to migrate between module locations and major versions.
The new cue mod mirror command copies modules from one registry to another.
cue mod tidy now preserves the top-level custom field as intended.
Hidden files, and files with build tags, should now be correctly filtered when loading a single CUE package.
cue get go should no longer attempt to import types from the Go standard library as CUE, which caused errors.
cue get go no longer fails on Go strings containing certain character escape sequences or non-UTF8 bytes.
cue get go now interprets Go fields with the new json:",omitzero" struct tag as CUE optional fields.
cue cmd now fails if no tasks were actually defined, to avoid situations where a user is misled into thinking a task was defined when it was not.
Encodings
The XML “Koala” encoding proposed in February is now available via an experimental implementation. Try it out via the CLI like cue export xml+koala: data.xml, or via its Go API.
The encoding/jsonschema package gains better support for Kubernetes schemas (CRDs and the core API) although these improvements are as yet only available via the Go API.
⚠️ The JSON Schema decoder now imports schema descriptions as CUE doc comments, which required a change to encoding/jsonschema.Config.DefineSchema.
Empty YAML files are now decoded as *null | _ rather than null, allowing them to be unified with struct schemas as if they were an empty struct.
cue exp gengotypes now allows control over how to generate optional CUE fields via e.g. @(,optional=nullable), where the default now is not to use pointers.
⚠️ cue exp gengotypes tweaks how it parses @(,type=) options to support composite types such as slices and maps. Note that this means package paths with slashes must be quoted now.
Builtins
⚠️ The uuid.ToString function is removed, given that it never did anything useful and could mislead users into thinking it did.
tool/http gained a followRedirects option to let the user disable HTTP redirection.
Go API
⚠️ CUE_EXPERIMENT=decodeint64 can no longer be disabled as we consider the experiment finished, having been introduced in CUE v0.11.0.
⚠️ The long-deprecated cue.Runtime methods Parse, FromExpr, CompileFile, and CompileExpr are now removed.
cuecontext.EvalDefault still pointed to the old evaluator; it now correctly points to the new evaluator, and follows the CUE_EXPERIMENT=evalv3 flag just like cmd/cue and the rest of the Go API.
Mirroring cuecontext.EvalExperiment, the new cuecontext.EvalStable constant is added to track the latest stable version of the evaluator.
module.SplitPathVersion and module.ParseImportPath have been deprecated in favor of cue/ast.SplitPackageVersion and cue/ast.ParseImportPath package to consolidate the API.
The new mod/modfile.File.ModuleForImportPath function allows resolving a module and default major version for a package without consulting a registry.
The new mod/modregistry.Client.Mirror method implements the logic behind the new cue mod mirror command.
The new mod/module.Version.Compare method is added in favor of module.Sort, which is now deprecated.
v0.12
v0.12.1
v0.12.0
This release fixes dozens of bugs in the new evaluator, enables the embed and toposort experiments by default, further improves JSON Schema support, and introduces cue exp gengotypes.
Changes which may break some users are marked below with: ⚠️
Evaluator
CL 1205861 enables the Embedding proposal via CUE_EXPERIMENT=embed by default, given that the proposal was accepted in late December.
Since v0.11.0, an experimental “topological sorting” of struct fields has been available via CUE_EXPERIMENT=toposort; this release enables the experiment by default. Topological sorting produces a more principled ordering of fields as produced by cue export and cue eval. The intent is to ensure the old and new evaluators order struct fields in the same way, in order to build confidence and ease the transition to the new evaluator.
We encourage all CUE users to update to this release and switch to topological sorting for their CUE outputs. An issue for gathering feedback is available, should you run into any issues.
A great deal of work has happened in the new evaluator, which can be used via CUE_EXPERIMENT=evalv3. Marcel also recently posted another update on performance progress. Below is a selection of particularly relevant changes in the new evaluator.
CLs 1204490, 1204669, and 1205368 resolve a number of significant performance issues spotted in the new evaluator.
CLs 1206123, 1206178, 1206284, 1206321, 1206385, and 1207910 fix a number of disjunction issues leading to incorrect behavior in the new evaluator.
CLs 1206327, 1206383, and 1206384 fix a number of cycle issues leading to incorrect errors in the new evaluator.
CLs 1206823, 1207237, 1207314, 1204365, 1205361, 1205363, and 1207714 fix a number of closedness issues which resulted in missing or incorrect errors in the new evaluator.
CL 1207912 fixes a regression which could cause “not properly initialized” errors in the new evaluator.
CLs 1206926, 1207169, 1207263, 1207545, and 1207715 fix panics which were recently discovered.
CL 1205862 sorts conjuncts in binary expressions to reduce ordering differences between evaluator versions.
CL 1207908 ensures that conversions of Go values to CUE respect struct field order, for the sake of topological sorting.
CL 1207907 ensures that converting Go arrays to CUE uses list.Repeat rather than the now-removed list arithmetic syntax.
CL 1204491 introduces CUE_DEBUG=openinline, enabled by default, which emulates the old evaluator’s incorrect closedness behavior in some edge cases. This should help the transition towards the new evaluator, and allow us to fix the behavior of these edge cases in future CUE releases.
CL 1204608 introduces CUE_DEBUG=sortfields which sorts all struct fields lexicographically. This replaces CUE_DEBUG_SORT_ARCS=1, which did not work with the new evaluator.
Go API
⚠️ CL 1205569 enables CUE_EXPERIMENT=decodeint64 by default, causing cue.Value.Decode to choose int64 rather than int as the default Go type for CUE integer values.
CL 1206368 adds a cue/token.Pos.Compare method to allow comparing two positions, for example to sort via slices.SortFunc.
CL 1207007 adds encoding/jsonschema.Config.AllowNonExistentRoot to prevent an error when no value is found at the Config.Root path.
Builtins
CL 1204378 teaches list.UniqueItems to handle incomplete values correctly, fixing a bug in JSON Schema.
CL 1204425 fixes list.MatchN so that it matches final values, like the matchN evaluator built-in, fixing a bug in JSON Schema.
⚠️ CL 1204920 removes the long-deprecated cue.Value.IsClosed method.
⚠️ CL 1205530 removes the long-deprecated cue.Instance.Doc method.
⚠️ CL 1205529 removes the long-deprecated cue/load.Config.BuildTags field.
cmd/cue
CL 1207142 adds the new command cue mod rename to aid in changing the module path of the current module.
⚠️ CL 1206950 fixes an issue where incomplete errors were not being reported by cue eval and cue vet.
CL 1204111 fixes some edge cases where CUE comments were lost or duplicated, particularly with cue def.
CL 1204874 re-enables command suggestions when a user makes a typo like cue exprot.
CL 1206784 fixes an issue where arguments and flags in cue cmd could not be interspersed, unlike other subcommands.
Encodings
The new experimental command cue exp gengotypes allows generating Go type definitions derived from exported CUE schemas. This can be a nice alternative to cue get go for projects developing both CUE and Go, if one wishes to maintain the source of truth for shared schemas in CUE. cue exp gengotypes is generally more reliable than cue get go, given that Go’s type system is not as powerful.
JSON Schema spec compatibility is improved further by fixing a number of bugs and adding missing features. Notably, it now supports arbitrary references to internal structure in $ref. JSON Schema’s spec test suite has gone from a “pass” rate of 75% to 79% thanks to these efforts.
⚠️ CL 1207146 tweaks JSON Schema to not generate defaults, given that they are annotations rather than constraints, and generating CUE defaults causes various issues.
v0.11
v0.11.2
This release includes fixes for bugs which were uncovered and resolved in the last few weeks.
Evaluator
CL 1206279 fixes a regression in the old evaluator which could lead to “conflicting value” errors.
cmd/cue
CL 1207330 fixes a regression where cue get go stopped copying some CUE files from Go package directories.
CL 1207402 fixes a regression where cue def --inline-imports could result in invalid CUE which failed to evaluate.
v0.11.1
This release includes fixes for bugs which were uncovered and resolved in the last few weeks.
Modules
CL 1205761 fixes a crash which could occur when using cue mod get on a module with existing dependencies.
CL 1204614 fixes a regression where loading a CUE package whose directory name ends with .cue was no longer working.
v0.11.0
This release includes the new matchN and matchIf validators, many fixes to evalv3 including a new cycle algorithm, a new experimental toposort field ordering, and many improvements to JSON Schema support.
Changes which may break some users are marked below with: ⚠️
Evaluator
A number of crashes, regressions, and other bugs have been fixed in the new evaluator, which can be enabled by CUE_EXPERIMENT=evalv3. For more details, see our latest performance update. Thanks to all who have tested the new evaluator and reported bugs!
CL 1201897 lands a new cycle algorithm in CUE_EXPERIMENT=evalv3, which is much simpler than the old algorithm and is needed to unlock further bug fixes and performance improvements.
CL 1198922 adds a new matchN built-in validator, necessary implement a host of validators such as the JSON Schema equivalents of not, oneOf, and anyOf. See the new how-to guide for it.
CL 1200942 adds a new matchIf builtin, similar to matchN, which makes it significantly easier to implement the if, then, and else keywords in JSON Schema.
CL 1202685 tweaks cuecontext.New to follow CUE_EVALUATOR=evalv3 when the cuecontext.EvaluatorVersion option is not used.
CLs 1202903, 1203264, 1203267, and 1203528 fix a number of bugs where CUE_EXPERIMENT=embed was not working as described in the proposed design.
CL 1199898 relaxes the evaluator to allow referencing required fields via selectors, rather than failing like we do with optional fields. This should help with the transition of CUE schemas from regular to required fields, such as those decoded from JSON Schema.
⚠️ CL 1200221 removes support for arithmetic operators on lists, and CL 1200221 teaches cue fix to rewrite most of them. We have added a doc page with more details and examples.
CL 1202746 teaches CUE_STATS_FILE to start reporting the evaluator version being used, which is useful information when looking at performance stats.
Field ordering
A new experiment is introduced via CUE_EXPERIMENT=toposort which enables a more principled ordering of CUE fields as produced by cue export and cue eval. The intention is to ensure the old and new evaluators order fields of structs in the same way, in order to build confidence and ease the transition to the new evaluator. There are still a few wrinkles to work out, and the question of iteration order in comprehensions over structs remains to be tackled. An issue for gathering feedback is available.
Modules
⚠️ CL 1199541 wraps up the CUE modules experiment by dropping support for CUE_EXPERIMENT=modules=0, now that the new mode has been the default since CUE v0.9.0, and we are not aware of any remaining regressions.
CL 1201522 fixes a bug where imports did not work properly when using cue/load.Config.Package = "*".
Go API
⚠️ CL 1203193 adds a new experiment via CUE_EXPERIMENT=decodeint64 which causes cue.Value.Decode to default to int64 rather than int when decoding CUE integer values. This ensures consistent behavior with 32-bit architectures.
⚠️ CL 1203192 tweaks the signature of cue.Index so that it accepts int64 as well as int for consistency with 32-bit architectures.
CL 1202744 tweaks cuecontext.EvalVersion so that the zero value is not a valid evaluator version, as that could lead to unintentional behavior.
⚠️ CL 1202244 tweaks the cue.Value API to consider open lists as concrete, aligning with the spec.
⚠️ CLs 1201768, 1201933, 1201934, 1201936, and 120193 remove pieces of the encoding/openapi Go API which have been deprecated for some time and already have reasonable alternatives available.
⚠️ CL 1201962 removes fields from cue/build.Instance and cue/load.Config which have been deprecated and unused for some time.
⚠️ CL 1201963 removes APIs from encoding/json and encoding/yaml which have been deprecated for some time and already have reasonable alternatives available.
⚠️ CLs 1202285 and 1202286 remove the cue.Value.Subsumes and cue.Value.Split methods, which have been deprecated and hidden for years.
CL 1200507 deprecates astutil.Cursor.Import, which is now superseded by astutil.Sanitize.
Encodings
A significant amount of work has gone into improving JSON Schema support, fixing many bugs and producing better CUE output, as well as leveraging the new matchN and matchIf builtins. While this work is still in progress, we already expect an overall improvement compared to v0.10.0. This work will also form the basis for CUE modules for well-known services that will be published to the Central Registry.
The TOML support first released in v0.10.0 is further polished by decoding CUE nodes with positions as well as adding support for TOML dates and times.
⚠️ CL 1199541 wraps up the new YAML decoder experiment by dropping support for CUE_EXPERIMENT=yamlv3decoder=0, allowing the 8400 lines of code in internal/third_party/yaml to be removed.
CL 1200901 improves filetype tags, as described by cue help inputs, so that unknown tag=value pairs cause failures, and invalid pair combinations aren’t silently ignored.
CLs 1200899 and 1200924 split JSON Schema’s strictness option into StrictFeatures and StrictKeywords which allows erroring when unimplemented features are used, but not when unknown keywords are used. --strict is also superseded by jsonschema+strict:.
CL 1201111 teaches default filetype tags to be applied in the default auto interpretation mode as well.
CL 1201113 adds the StrictFeatures and StrictKeywords options to OpenAPI, mirroring the options added to JSON Schema.
CL 1201910 allows configuring how encoding/jsonschema maps URLs to values within a package.
CL 1201935 refactors encoding/openapi so that it can directly use the existing CUE value encoder for JSON, rather than a parallel encoder of CUE syntax trees to JSON which had to be maintained separately.
CLs 1201807, 1201808, 1201824, and 1201826 improve the performance of encoding CUE values to JSON, resulting in as much as a 10x improvement in wall time and memory usage for deeply nested CUE values.
Builtins
CL 1201474 adds a new encoding/toml package with Marshal and Unmarshal APIs, following the addition of TOML support in v0.10.0.
CL 1202104 adds the net.URL and net.AbsURL validators, needed by JSON Schema.
⚠️ CL 1201115 removes strconv.ParseComplex, which never worked in any past CUE release and does not seem like an useful API to have in its current form.
CL 1194425 tweaks the yaml.Validate and json.Validate functions to allow non-concrete CUE values as schema parameters.
CL 1199602 adds a list.MatchN function, surfacing the matchN built-in validator for use in the JSON Schema decoder.
⚠️ CL 1199881 tweaks uuid.Valid so that it is consistent with uuid.Parse in terms of what UUID formats are accepted.
cmd/cue
⚠️ CL 1203289 moves cuepls to cue lsp, enabling users to install one binary rather than two, and avoiding potential version discrepancies.
⚠️ CL 1199634 drops support for the deprecated short form of cue cmd; users of cue foo should now call cue cmd foo.
CL 1204223 adds a cue login --token flag to log into a CUE registry with a token which was generated via the web interface or API, for use in automated environments like CI.
CL 1200351 fixes a bug in cue fix where it would not operate on directories with multiple packages.
CL 1200498 fixes a bug in cue fix where added imports would end up with mangled names.
CL 1200554 teaches cue fix to work on standard input and output, like other sub-commands.
CL 1201709 fixes a minor regression introduced in CUE v0.9.0 where cue help cmd mycmd ./mypkg stopped showing a valid command’s help text.
v0.10
v0.10.1
This release includes fixes for two bugs which were uncovered and resolved in the last few weeks.
cmd/cue
CL 1202646 fixes a panic for users of the cmd/cue/cmd Go API.
CL 1202738 fixes a bug when using @if attributes in files specified directly as command line arguments.
v0.10.0
This release includes experimental support for the embed proposal, many fixes for the new evaluator and modules, as well as many other fixes and enhancements.
Evaluator
CLs 1195897, 1196094, 1198356, 1198736, and 1198860 fix crashes with CUE_EXPERIMENT=evalv3 as reported by users.
CLs 1199272, 1199273, and 1199340 fix spurious “field not allowed” error regressions in the new evaluator.
CL 1198566 fixes a performance regression introduced in CUE v0.6 where cue cmd and tools/flow became many times slower on some inputs.
CL 1198350 ensures that all interpreter errors, such as those from @embed attributes, include position information.
Embed proposal
With CUE_EXPERIMENT=embed, CUE now supports the embedding of non-CUE files within a CUE package. See the embed proposal and its design document for details, as well as the new how-to guide for the feature.
Modules
The cue help documentation for modules and inputs has been expanded, and a number of error messages when using or publishing modules are now more helpful.
A new concept guide on CUE language versions documents the language.version field in cue.mod/module.cue files.
CL 1198249 adds support for an @ignore file attribute to unconditionally ignore a file when loading packages or calculating dependencies.
CL 1198003 teaches the CUE loader to support symbolic links when loading from local directories, matching the behavior before CUE_EXPERIMENT=modules was introduced.
CL 1198143 tweaks cue mod init without an argument to create a module with the module path cue.example rather than an empty path that made the module file invalid.
CL 1197530 fixes the behavior of build tags, and also adds support for parentheses in build tag expressions.
CL 1197531 implements better caching when evaluating dependencies, which should speed up evaluation of modules that use multi-directory packages.
Go API
CL 1196721 disallows importing or loading packages with an underscore qualifier like foo.com/bar:_, as it was never intended behavior. Users should use the new embed proposal instead.
CL 1198555 adds a cue/load.Config.SkipImports option to avoid loading instances from import statements. This particularly helps cue fmt, where the loading caused unwanted slowness and unnecessary errors.
CL 1196820 adds a cue.LanguageVersion function to obtain the current version of the language spec that the Go module implements.
CL 1197160 implements considered support for build tags in modules. Build tags are considered false when outside the main module.
CL 1198686 fixes cue/load so that it no longer produces extra invalid packages when Config.Package was set to * and nested packages were loaded.
CL 1198351 fixes a bug in astutil.Sanitize where unused imports were not being fully removed from ast.File, causing errors in cue trim where all uses of an import were removed.
CL 1198494 speeds up the Path method on wrapped errors, which causes noticeable speed-ups in some edge cases.
CL 1198157 fixes cue/parser to accept keywords as valid selectors, aligning with the language specification.
Encodings
Initial support for TOML is included in this release, including support in cmd/cue and an experimental Go package. See the issue tracker for remaining work in this space.
CLs 1199309, 1199139, 1199306, 1199214, 1199398, 1199308, and 1199309 resolve a number of issues when decoding JSON Schema files.
CLs 1196332, 1199094, and 1199103 fix the JSON decoder to provide correct position information when decoding JSONL files or encountering a syntax error.
CL 1198874 fixes the loading of JSON files to reject multiple newline-delimited values, as those ar only allowed in NDJSON or JSONL files.
CL 1198876 teaches the YAML decoder to decode empty documents as null, aligning with the YAML spec and fixing panics when loading empty YAML files.
CL 1196291 tweaks the YAML decoder so that comments following a field are attached to the entire field.
CL 1196436 tweaks the textproto decoder to correctly handle required and optional fields.
CLs 1195628 and 1199054 ensure that cue/format prints the correct white space before and after comments.
CL 1195884 teaches cue/format to preserve comments associated with ... ellipsis expressions.
CL 538624 fixes a bug where cue/format would start a CUE file with white space if it began with a clause.
CL 1196134 fixes a bug in cue/format where a comment at the start of a CUE file would sometimes be indented.
CL 1196135 fixes a bug in cue/format where index or selector expressions could cause extra tab indentation.
Builtins
CL 1196212 adds a list.Reverse function to reverse the elements of a list.
CL 1197452 tweaks tool/exec.Run so that its errors are unambiguous when any command arguments contain white space.
CL 1198636 tweaks path.Match and tool/file.Glob to reject ** wildcard patterns as unsupported, to avoid confusion and allow future changes to their behavior. Note that this change may break uses of ** patterns, which behaved like *.
cmd/cue
CL 1196822 adds a --language-version flag for cue mod init and cue mod edit to set the language.version value.
CL 1197185 teaches cue mod resolve to work on the current module when no arguments are given.
CL 1196370 teaches cue mod registry to gracefully shut down when interrupted.
v0.9
v0.9.2
v0.9.1
This release includes a few fixes, mainly relating to CUE_EXPERIMENT=modules being enabled by default in v0.9.0.
Modules
CLs 1196176 and 1196180 allow using and developing a module whose cue.mod/module.cue lacks a major version suffix like @v0, as adding one may break older CUE versions without CUE_EXPERIMENT=modules.
CL 1196156 adds a cue/load.Config.AcceptLegacyModules option to allow loading CUE modules without a language.version field, given that the field was only introduced in v0.8.0.
CL 1196178 fixes a regression where loading a package with the cue/load.Config.Package option set was no longer working as expected.
As a reminder, we are maintaining an FAQ page which should help modules users with the upgrade to v0.9.
Builtins
CL 1195888 fixes the path.Match API so that it can actually take the three parameters it expects.
v0.9.0
This release includes major changes to Modules and the Evaluator, as well as many other fixes and improvements. A special thanks to Noam Dolovich for numerous contributions to this release!
Modules
Following the Modules proposal v3 being accepted, the modules experiment is now enabled by default in this release. It should no longer be necessary to set CUE_EXPERIMENT=modules, and CUE_EXPERIMENT=modules=0 can be used to disable the experiment. We are not aware of any significant regressions, so please file a bug if you find one.
We have published an FAQ page which should help modules users with the upgrade to v0.9. We will add to this page over the coming weeks to ease the transition into the “new” modules mode.
This release also includes experimental support for the CUE Central Registry at https://registry.cue.works. We have added a cue login command to log into the Central Registry via a GitHub account, and other commands know how to use these credentials when talking to the registry.
To get started with the Central Registry, we have published a tutorial on working with modules and the central registry as well. We will share more details about the Central Registry and support for other login mechanisms in the future. For now, we are looking to get early feedback.
The CUE schema for cue.mod/module.cue is now dictated by the declared language.version value, which is now mandatory. This allows us to change or tighten the schema with future CUE versions without breaking existing users. Use the new cue mod fix command to add the field.
cue mod publish now requires source to publish a module, as described in Proposal 3017. The cue mod init --source flag is added to create a new module with this field.
cue mod publish now includes VCS metadata in published module versions, as described in Proposal 3057.
The cue mod fix command is added, which allows fixing up old cue.mod/module.cue files; see cue help mod fix.
The cue mod edit command is added, which allows some automatic editing of cue.mod/module.cue from the command line; see cue help mod edit.
CL 1193289 teaches $CUE_REGISTRY about a special none registry, causing any matching modules to refuse to fetch or resolve.
CL 1195546 teaches cue mod publish to include a LICENSE file from the VCS repository root if the CUE module subdirectory has none.
CL 1194090 adds the --dryrun, --json, and --out flags to cue mod publish to inspect what would be published as part of a module version.
CL 1194106 adds the cue mod resolve command to show how a module path resolves to a registry in the form of an OCI reference.
CL 1185280 adds cue help modules as a high-level overview of CUE modules.
CL 1194669 restricts the parsing of cue.mod/module.cue files to data-only mode, forbidding any references or comprehensions which may break cue mod commands or cause other issues.
As a reminder, the ongoing and planned work can be seen in the Modules Roadmap.
Evaluator
The new evaluator can now be enabled in the command line via CUE_EXPERIMENT=evalv3, and in the Go API via cuecontext.EvaluatorVersion(cuecontext.EvalV3). The new evaluator already includes a new disjunction algorithm as well as initial structure sharing support; note that structure sharing can be disabled with CUE_DEBUG=sharing=false.
The work is not yet complete, and some known bugs remain, but over 95% of the existing tests are passing and the performance already looks promising. Work on this new evaluator will continue during the next release cycle. We will only turn on the new evaluator by default once we are reasonably confident that there are no significant regressions.
CL 1185458 ensures we detect permanent errors for undefined fields earlier, necessary for the permanent errors fix in tools/flow below.
Subscribe to the Performance umbrella issue for updates, and see the Evaluator Roadmap project for the planned work ahead.
Encodings
The Encodings project was kicked off at a recent CUE Community Update call. As part of this, we now have an #encodings channel on Slack and Discord, as well as an Encodings Roadmap project on GitHub where the ongoing and planned work can be seen.
In this release, the new YAML decoder is available in experimental form and enabled by default, given that all of our tests are already passing. You can disable it via CUE_EXPERIMENT=yamlv3decoder=0. The old YAML decoder will be removed in a future release once we’re reasonably confident that no significant regressions are present.
CLs 1193257, 1193394, 1193576, and 1193577 greatly speed up internal/filetypes, used when loading files from disk in cue/load or when encoding/decoding files in cmd/cue.
CL 1193678 teaches cue/load to cache loading files from directories, which avoids repeated work when loading parent directories to form instances.
The changes above, plus cue.Value.IsNull below, should result in a significant speed-up for cmd/cue as well as cue/load when loading many CUE packages or directories. For example, on the main CUE repository, cue fmt ./... went from ~14s to ~0.1s, and cue vet ./... went from ~5s to ~2s.
CL 1193639 teaches internal/filetypes to only load its embedded CUE on first use, allowing any Go programs to skip the ~6ms load time until the first call to a cue/load API, if any.
CL 1195047 fixes the decoding of YAML 1.1 octal numbers so that they no longer result in invalid CUE literals.
cmd/cue
CL 1189314 adds a cue fmt --check flag to list badly formatted files rather than modifying them directly.
CL 1193778 adds a cue fmt --diff flag which displays diffs instead of updating files.
CL 1193962 adds a cue fmt --files flag to interpret the arguments as file paths to walk and recursively format rather than package patterns.
CL 1192180 speeds up cue fmt by ensuring that it only processes each CUE file once, rather than formatting files from parent directories as well.
CL 1185356 tweaks cue/load so that cue fmt is able to format CUE files given directly as arguments even when they belong to different packages.
CL 1193702 ensures that cue get go always generates CUE code from Go time.Duration types and values in a way that is fully compatible with Go’s encoding/json library.
CL 1193386 fixes cue fmt --simplify to no longer break complex labels by unquoting string literals within them.
CL 1193934 improves cue fmt so that it does not write to files on disk which are already well formatted.
CL 1194247 tweaks cue help so that it correctly fails when given unknown help topics or commands.
CL 1185473 deprecates the short-form cue somecmd in favor of cue cmd somecmd, as the former caused a number of bugs and slowness when working out which subcommand to execute.
Go API
CL 1193405 adds a cue.Value.IsNull method to mirror cue.Value.Null without constructing error values, making cue.Value.Decode faster in many scenarios, including its use in cue/load via internal/filetypes.
CL 1191227 adds a cue/token.File.Lines getter method, much like go/token.File.Lines was added in Go 1.21.
CL 1193030 ensures that cue/load.Instances always returns instances in a deterministic order, in particular when multiple instances share the same directory.
CL 1194421 fixes a memory leak where using load.Instances to load CUE modules would increase the size of a global cue.Context until the process was terminated.
CL 1187452 teaches tools/flow to fail when a task encounters a permanent error, which were being ignored before.
CL 1191226 teaches cue/literal.ParseNum to support both positive and negative signs for consistency.
CL 1194410 fixes cue/load so that it errors on empty string arguments once again.
CL 1193515 fixes an edge case where cue/format would vertically align fields at different struct levels.
CL 1193585 fixes a bug where cue/format would print trailing commas for list elements after any inline comments, causing broken syntax.
CL 1193759 teaches cue/format to collapse empty lists and structs to a single line for consistent formatting.
CL 1185361 deprecates cue/load.Config.StdRoot, which has not worked as advertised for some time.
CL 1185684 removes the last remaining bits of API which supported quoted identifiers, which had already been deprecated and largely unsupported for years.
Builtins
CL 1193242 teaches encoding/yaml.Unmarshal to reject trailing input, just like encoding/json.Unmarshal already did.
CL 1184631 fixes using math.MultipleOf as a validator function.
CL 1193690 fixes math.MultipleOf as it had an incorrect implementation which could easily return bad results.
CL 1194165 fixes invalid builtin calls so that they correctly result in a “bottom” error.
CL 1194515 fixes structs.MinFields and structs.MaxFields to ignore optional fields, matching the documented behavior.
v0.8
v0.8.2
This release includes a single fix for cue get go: CL 1193892 fixes a regression introduced in cue get go in v0.8.1 which caused transitive package dependencies to no longer be generated.
v0.8.1
This release includes a number of fixes detailed below:
CL 1186144 fixes a number of evaluator panics which could be triggered by calling the cue.Value.Expr method, which also happened when using the OpenAPI encoder.
CL 1173100 fixes cue get go panics which might occur when any Go packages are vendored or use imported alias declarations.
CL 1185281 fixes a regression introduced in v0.8.0 which led to some incorrect failures in tools/flow and cue cmd.
v0.8.0
This release includes experimental support for CUE Modules (more details below), as well as a number of improvements and fixes.
More CLs and refactors have also landed for the core evaluator’s performance work. These aren’t enabled yet as the work isn’t complete; subscribe to the performance umbrella issue to read regular updates.
As a reminder: users can register their projects with Unity, our regression and performance testing setup. Unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. It continues to catch multiple issues with each release. Adding your project to Unity not only guarantees that we will not break your tests (if we do, we will work with you to fix your CUE code), but it also helps to improve the quality of each CUE release. Follow this link to learn more about Unity, install it, or get in touch with any questions.
Modules
This release includes experimental support for CUE modules in cmd/cue, as outlined in the updated Modules and package management proposal v3.
Alongside this release, we have published a tutorial on the new website which shows how to publish and fetch modules with a custom module registry.
We have also published the first version of the Modules reference documentation, the canonical documentation page describing how CUE modules work in detail.
Note that support for CUE modules is still experimental and subject to change, and needs to be explicitly enabled via CUE_EXPERIMENT=modules. See cue help environment for more information on the environment variables used below.
CUE maps modules to registries via $CUE_REGISTRY, which supports a simple string configuration format as well as a more detailed CUE configuration format which can be read from disk. See cue help registryconfig for more details.
The new cue mod tidy command rewrites cue.mod/module.cue in its canonical format, adds any missing module dependency requirements, and removes unused ones.
The new cue mod publish command publishes the current module to a module registry.
The new cue mod get command can add a new module dependency, update an existing one, or downgrade an existing one as long as it does not cause any conflict.
When running commands like cue export with CUE_EXPERIMENT=modules, dependencies are automatically fetched from module registries following $CUE_REGISTRY and cached on disk inside $CUE_CACHE_DIR.
CUE Language Server Protocol Implementation
This release includes the first early version of an experimental Language Server Protocol (LSP) implementation for CUE. Whilst it remains experimental, the cmd/cuepls binary is separate from cmd/cue. However at a later date it will most likely to become a subcommand of cmd/cue like cue lsp serve.
We are working on updating the VSCode plugin to use cmd/cuepls, as well as supporting an initial version of a plugin for Neovim. For JetBrains users, we are working with the author of the CUE plugin to understand how best to integrate cmd/cuepls with JetBrains.
We will share announcements once the editor integrations are ready for use, and once more LSP features beyond formatting files are available. Subscribe to the LSP announce discussion, or join us in #cuepls on CUE Slack.
Go API
Note that this version of CUE requires Go 1.21 or later, following our policy to support the latest two stable Go releases just like upstream.
The cue/load package supports the CUE Modules experiment out of the box with the environment variable CUE_EXPERIMENT=modules. Alternatively, a custom registry and authorizer can be configured with the Config.Registry field via the modconfig.NewRegistry API.
cue/load also has a new Config.Env struct field to provide the environment variables used to load CUE modules from registries. It defaults to using os.Environ.
We have also added new Go examples to the cue/load package, including an example demonstrating the use of a CUE modules registry.
CL 1173271 drops support for legacy pkg directories, which have been deprecated since the transition to a cue.mod directory in 2019.
CL 1174069 replaces a few more uses of the deprecated cue.Instance type with cue.InstanceOrValue.
CL 1175779 deprecates the FileOffset and File.Base APIs in cue/token, which were inherited from go/token but never had any effect.
Language
There are no changes to the language in this version.
Spec
CL 1173197 makes the use of the term “builtin function” consistent across the document.
Core Evaluator
CL 1173262 fixes a regression introduced by v0.7.0’s upgrade to github.com/cockroachdb/apd/v3 where some arithmetic operations would result in an extra 0 digit.
Encoders
CL 1173689 fixes the YAML encoder so that strings looking like hexadecimal numbers are properly quoted.
Builtins
CL 1173735 replaces the uses of Go’s net package with net/netip when dealing with IP addresses, which makes them immutable, comparable, and take less memory.
CL 1173926 adds an IPv6 API to net to check that a value is a valid IPv6 address, mirroring IPv4 and taking advantage of the switch to the Go net/netip package.
CL 1174339 fixes tool/exec so that it correctly applies env defaults in CUE values.
CL 1174623 fixes tool/exec so that it accepts env list values as documented.
cmd/cue
CL 1176194 adds a language.version field to cue.mod/module.cue to track what CUE language version a module was written for. This will become necessary to make future language changes as smooth as possible for CUE users. For example, running cue mod init or cue mod tidy with the v0.8.0 release should add language: version: "v0.8.0" when the field isn’t present.
CL 1173892 adds a cue help environment section to document the environment variables used by the CLI, such as CUE_EXPERIMENT and CUE_REGISTRY.
CL 1176665 fixes cue cmd so that legacy commands always get the corresponding CUE schema unified.
CL 1177330 fixes a bug where some evaluation errors in tools/flow and cue cmd were omitted, causing unintended results.
CL 1177546 tweaks cmd/cue so that it obeys the --package flag when the output format is CUE.
v0.7
v0.7.1
This release is a re-build of CUE v0.7.0 with Go 1.22.0 to prevent cue get go panics; see https://github.com/cue-lang/cue/issues/2802.
v0.7.0
This release comprises a number of bug fixes and small improvements, as well as more ground work for Modules, WebAssembly, and the core evaluator’s performance refactors.
Note that v0.7 was originally planned to center around the core evaluator’s performance improvements. Since those refactors are not ready, and we have other fixes and improvements we want to release, we have slightly altered the release plan accordingly. We will share more details on our next community call.
As a reminder: users can register their projects with Unity, our regression and performance testing setup. Unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. Unity continues to catch multiple issues with each release. Adding your project to Unity not only guarantees that we will not break your tests (if we do, we will work with you to fix your CUE code), but it also helps to improve the quality of each CUE release. Follow this link to learn more about Unity, install it, or get in touch with any questions.
Thank you to @SteVwonder, @bozaro, @cedricgc, @howardjohn, @mpvl, @mvdan, @myitcv, @nickfiggins, @rogpeppe, @rudifa, and @uhthomas for contributing to this release!
And a special thanks to all who joined the recent contributor office hours calls on our community calendar, as well as our #contributing channel on Slack! Thanks to their involvement, more issues can be investigated and fixed each release.
Go API
Note that this version of CUE requires Go 1.20 or later, per our policy to support the latest two stable Go releases just like upstream.
CL 1172105 fixes a regression introduced in v0.6.0 where calling Iterator.Selector.Index while iterating over a list would incorrectly panic.
CL 1167597 fixes cue/load so it now errors on package import cycles, following the spec.
CL 1167647 adjusts cue.Value.Decode to decode empty CUE lists into a Go interface{} as a non-nil empty slice.
CL 547369 teaches cue.Value.Decode how to decode values which aren’t entirely concrete into a Go type by using cue.Value as part of the destination type.
Language
There are no changes to the language in this version.
Spec
CL 1171216 fixes two errors in a dynamic fields example.
Core Evaluator
CL 1172014 disallows the direct use of unary operators with basic types, since they would result in confusing bounds which seemed incorrect.
CL 1172013 fixes a closedness bug where close did not properly apply when used inside definitions.
CL 1172874 fixes a panic in cue export introduced by v0.6.0.
Encoders
CL 1172314 teaches encoding/protobuf to follow the field_behavior annotation marking a field as either optional or required when decoding.
Builtins
CL 1172991 adds a mustSucceed boolean parameter to tool/exec.Run, which can be set to false to allow a command to fail and set its own field success to false.
CL 557322 fixes the values of math’s Log2E and Log10E constants, which were being incorrectly truncated.
cmd/cue
CLs 1170966 and 1171302 fix a number of issues in cue fmt (and by extension the cue/format package), resulting in better and more consistent formatting of CUE files.
CLs 1171292, 1171015, 1170115, and 1171971 implement a variety of improvements and bug fixes for cue get go.
CL 1172017 fixes a number of issues with the line and column positions reported by our YAML decoder, which could result in weird CUE formatting when using cue import or misleading positions being shown to the user.
CL 1169709 increases the robustness of cue export -o, which in some situations could ignore file errors or incorrectly replace an existing file without the -f flag.
CL 1173072 fixes a panic when using cue import --list with empty YAML input.
CL 1168436 updates the cue export documentation to add the missing cue and binary supported export formats.
Modules
A number of changes are included to support an experimental implementation of the proposed modules and package management support. These aren’t enabled by default, and will be announced soon.
v0.6
v0.6.0
The main focus of this release is the introduction of required fields, as well as fixing a number of issues and regressions introduced in the v0.5.0 release.
As a reminder: users can register their projects with unity, our regression and performance testing setup. unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. unity continues to catch multiple issues with each release. Adding your project to unity not only guarantees that we will not break your tests (if we do, we will work with you to fix your CUE code), but it also helps to improve the quality of each CUE release. Follow this link to learn more about Unity, install it, or get in touch with any questions.
Thank you to @4ad, @Abirdcfly, @alexandear, @chee-zaram, @eraserhd, @ghostwheel42, @joanlopez, @jpluscplusm, @kcburge, @mpvl, @mvdan, @myitcv, @rogpeppe, @toshi0607, and @zeithaste for contributing to this release!
API
CL 543335 adds arch to set of injectable system variables understood by cue/load. The text at cue help injection explains how this in more detail.
CL 552142 adds support for zero values in cue.Value.Float64, which has the effect of fixing the error when attempting to use strconv.FormatFloat with a zero value.
CL 548783 fixes a long-standing bug to make HTML escaping in JSON an opt-in. This means that cue export now respects the --escape flag when set, and encoding/json only escapes HTML when HTMLEscape is used.
Language
Required fields
The main focus of the v0.6.0 release is the introduction of required fields.
CUE already supports the “optional field constraint”, denoted foo?: value.
Required fields add a “required field constraint”, denoted foo!: value, which is like foo?: value, but requires a regular field be provided for foo (a field foo: without !: or ?:).
We refer to optional field constraints and required field constraints collectively as “field constraints”.
As a general rule, all data and data templating should be defined with regular fields, whereas schemas would be defined in terms of field constraints. Of course, CUE being CUE, mixing these two fields is allowed: this rule is not a restriction but suggested as a matter of style and proper usage.
Here are some examples of how exclamation marks can be used to express things that were previously not possible.
#Def: {
kind!: "def"
intList!: [...int]
}Using required fields can also result in better error messages. Consider this schema:
#Person: {
name: string
age?: int
}Note that this is non-idiomatic, because our new guidelines suggest schemas should only be defined in terms of field constraints, but we will use this for illustration purposes.
Now consider this usage of #Person:
jack: #Person & {age: 3}In data mode, the error message here is currently jack.name: incomplete value string, which does not provide much actionable information to the user to help them fix the problem.
Now consider how #Person looks with required fields, idiomatically only using field constraints:
#Person: {
name!: string
age?: int
}
jack: #Person & {age: 3}Now the error message reads:
jack.name: field is required but not presentwhich more closely reflects the underlying problem..
This error could be resolved by adding jack: name: "Jack".
For more details and background on the change, please see the original required fields proposal.
Other changes
Whilst it should not be a breaking change from a CUE perspective, we have upgraded to use github.com/cockroachdb/apd/v3. We have also increased apd.Context precision from 24 to 34.
CL 551207 adds support for making dynamic fields optional or required. For example, the following is now possible:
x: "y"
(x): "foo"
(x)?: "foo"
(x)!: "foo"and yields:
x: "y"
y: "foo"CL 546886 removes support for old-style :: definitions. This also includes deprecation support. In a similar vein, CL 547011 removes the last vestiges of <foo>: T. This was once the notation for pattern constraints.
Spec
Various bug fixes, with special thanks to @nicuveo for raising many of these.
Builtins
The following four functions have been added to the net package:
PathEscapePathUnescapeQueryEscapeQueryUnescape
Thanks to @eraserhd for this change.
CL 549087 reimplements pkg/list.Sort. The resulting reduction in the number of allocations and other work gives rise to a ~80% reduction in running time against CUE benchmarks.
cmd/cue
CL 547212 improves the documentation for the -l flag passed to cue import. This addresses a frequent point of confusion in questions to GitHub Discussions and on Slack.
CL 550616 fixes cue get go to respect the --exclude flag for constants. This makes it possible to (for example) exclude all unexported identifiers from a cue get go run.
CL 555576 fixed an important bug where cmd/cue vet was not properly consuming all input data.
CL 556526 fixed a bug where CUE files beginning with an underscore were not being loaded when explicitly given as filename arguments.
WebAssembly (Wasm)
We have added preliminary support for Wasm. Users can compile code from any language and toolchain that supports Wasm into plugins that are dynamically loaded by CUE. Users can then call and use functions from these Wasm modules, just like they can use standard library functions.
See the documentation at cuelang.org/go/cue/interpreter/wasm to learn more about Wasm and its current limitations.
Changelog
v0.5
v0.5.0
This release focuses on changes to the implementation of comprehensions, the algorithm for detecting cycles in CUE, and the reimplementation of let comprehensions as fields.
Also included are a number of bug fixes and changes to help the KubeVela project upgrade off CUE v0.2.2 to the latest release. v0.5.0 is the first release since v0.4.3 back in April 2022. It has been a long time in the making, and is comprised of 277 commits.
It is worth noting that we do not plan nor wish for such long gaps between releases. For more details on upcoming releases and steps we are taking to increase release cadence as well as our confidence in each release, please see this discussion.
As a reminder: users can register their projects with unity, our regression and performance testing setup. unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. unity continues to catch multiple issues with each release. Adding your project to unity not only guarantees that we will not break your tests (if we do, we will work with you to fix your CUE code), but it also helps to improve the quality of each CUE release. We are currently in the process of releasing Unity as a GitHub App on the public Marketplace. Sign up to receive updates; we will be in touch as soon as the GitHub App is ready.
Thank you to @djosephsen, @joaopapereira, @mpvl, @mvdan, @myitcv, @qequ, @rogpeppe, @rytswd, @satotake, @spachava753, and @tmm1 for contributing to this release!
Project-level changes
Various CI-related changes have been made to simplify and streamline the GerritHub-based CI setup across the various CUE repositories. A common base package is vendored into each repository and used as a template for GitHub workflows and other configuration. For those interested in studying the setup, please see the files beneath internal/ci.
This release drops support for go1.16.x , go1.17.x and go1.18.x, is tested against go1.19.x and go1.20.x, and is built using go1.20.2.
Our dependency on github.com/rogpeppe/go-internal is upgraded to v1.9.0 and various testscript-related improvements have been made to CUE’s tests.
GoReleaser has been upgrade to v1.16.2 as part of the release workflow. In a related change, CL 546920 moves us to a CUE-based source configuration for GoReleaser. This allows us to define the concept of ’latest’, state which indicates whether we should perform the homebrew release and the Docker manifest latest steps. This fixes a long-standing bug whereby homebrew taps and Docker images were created for the latest release, regardless of whether that was a pre-release, or indeed a patch version of a non-current minor version.
As of CL 547507, CUE build artefacts published on GitHub are entirely reproducible, thanks to Go’s support for reproducible, verifiable and verified builds.
Encoders
When cue import-ing YAML, the -R recursive flag now only recursively interprets text as YAML if it contains a newline CL 536902.
API
Various APIs have been transitioned to drop use of the deprecated cue.Runtime type, as well as migrating away from cue.Instance via cue.InstanceOrValue. Some use of these deprecated types remains: #1035, #1735, #1806. These will be tidied up in later releases as the API surface matures towards v1.0.0.
The cue package now supports InlineImports for Value.Syntax CL 541561. This leverages new support within the internal exporter to creating self-contained CUE. This change also deprecates Value.ResolveReferences().
Package cue adds Selector.Type to make it easier to pull out selector-specific information from a selector (for example, it makes it possible and cheap to retrieve the unquoted string label from a regular field selector) CL 542738.
Package cue adds Value.BuildInstance(). If a cue.Value exactly represents a package, BuildInstance() returns the build instance corresponding to the value CL 542769.
cue/stats is introduced as a new package for getting CUE operation statistics. The functionality is hoisted from internal/core/adt, but the package should for all practical purposes be seen as a new implementation. The stats have been aggregated as experimental functionality to the tools/flow package.
CL 546763 disallowed deprecated language features in the Go API. These features had long been deprecated in cmd/cue. This means that API operations will now fail on deprecated features whereas before they were handled in compatibility mode. The parser.FromVersion feature can be used to reenable these deprecated features.
Language
This release does not introduce any language changes. CL 537264 made some minor adjustments to the language specification to improve readability.
CL 541457 removes support for re-writing of old-style let declarations. This had already been deprecated for a long time and this change was made to enable support for aliases of embeddings.
Core evaluator
Per-field comprehensions
One of the major changes introduced in this release is how comprehensions are handled. CL 529524 move the evaluator to a model of per-field comprehensions.
Comprehensions are expanded for, if, and let clauses that yield zero or more structs to be embedded in the enclosing list or struct.
CUE does not allow cyclic dependencies between comprehensions if they result in an ambiguous set of fields. It does allow cascading insertions as in:
a?: int
b?: int
if a != _|_ {
b: 2
}
if b != _|_ {
c: 3
d: 4
}The way this works is that for fields with a fixed prefix path in a comprehension value, the comprehension is assigned to these respective fields.
More concretely, the above example is rewritten to:
a?: int
b: if a != _|_ { 2 }
c: if b != _|_ { 3 }
d: if b != _|_ { 4 }where the fields with if clause are only inserted if their condition resolves to true. Note that this is not valid CUE; it may be in the future.
With this rewrite, dependencies in comprehension expressions are handled analogously to other expressions.
Note that a single comprehension may be distributed across multiple fields. The evaluator will ensure, however, that a comprehension is only evaluated once.
Analogous to reference cycles, as of CL 544129 we allow comprehensions to use the struct in which they are defined as source, as long as they do not introduce new fields, which would alter the source on which they iterate.
Reimplementation of cycle detection
The new algorithm is inspired by the cycle detection used by Tomabechi’s 1 and Van Lohuizen’s 2 graph unification algorithms.
Unlike with traditional graph unification, however, CUE uses references, which, unlike node equivalence, are unidirectional. This means that the technique to track equivalence through dereference, as common in graph unification algorithms like Tomabechi’s, does not work unaltered.
The unidirectional nature of references imply that each reference equates an exact copy of the value it points to. This renders the original approach of node-pointer equivalence useless.
The new algorithm, a variant of Tomabechi’s and Van Lohuizen’s algorithm, looks at references equality on conjuncts, instead of node equality. This simplifies the accounting and allows for far simpler and precise accounting when using references instead of the traditional node equivalence.
More background info on cycles
We have to define when a cycle is detected. CUE implementations MUST report an error upon a structural cycle, and SHOULD report cycles at the shortest possible paths at which they occur, but MAY report these at deeper paths. For instance, the following CUE has a structural cycle:
f: g: fThe shortest path at which the cycle can be reported is f.g, but as all failed configurations are logically equal, it is fine for implementations to report them at f.g.g, for instance.
It is not, however, correct to assume that a reference to a parent is always a cycle. Consider this case:
a: [string]: b: aEven though reference a refers to a parent node, the cycle needs to be fed by a concrete field in struct a to persist, meaning it cannot result in a cycle as defined in the spec as it is defined here. Note however, that a specialization of this configuration can result in a cycle. Consider
a: [string]: b: a
a: c: _Here reference a is guaranteed to result in a structural cycle, as field c will match the pattern constraint unconditionally.
In other words, it is not possible to exclude tracking references across pattern constraints from cycle checking.
It is tempting to try to find a complete set of these edge cases with the aim to statically determine cases in which this occurs. But as Carpenter 3 demonstrates, it is possible for cycles to be created as a result of unifying two graphs that are themselves acyclic. The following example is a translation of Carpenters example to CUE:
y: {
f: h: g
g: _
}
x: {
f: _
g: f
}Even though the above contains no cycles, the result of x & y is cyclic:
f: h: g
g: fThis means that, in practice, cycle detection has at least partially a dynamic component to it.
The language specification contains a higher-level and more complete overview of structural cycles.
Reimplementation of let comprehensions
CL 543362 made a change to internal/core to reimplement let comprehensions as fields. This makes it easier to track context as let comprehensions then follow the same paradigm as fields. It also allows debug information to be shown as to where lets are added in the tree. This change was accompanied by number of others that refined the approach.
Self-contained export
internal/core/export now implements an algorithm for generating self-contained CUE on export, an option that can further be refined by asking the exporter to inline imports. These internal changes manifest in changes to cue def and cuelang.org/go/cue that are described elsewhere.
Other changes
CL 545897 started tracking stats within the core CUE tests. This book keeping helps to spot likely regressions in performance early by collocating the stats with the CUE that is being evaluated.
Builtins
In the strconv package, strconv.FormatInt and strconv.FormatUint now support arbitary-precision format; see CL 538512.
CL 545898 improved the error messages for pkg builtins, by including the path in error in many cases, and passing a wrapped message for encoding/yaml.
CL 546237 allows incomplete list.MinItems constraints. Before it either returned false or true, ignoring that making a configuration more specific might still satisfy MinItems later on. CL 546238 made a similar change for struct.MinFields.
Tooling layer
Standard input is now parsed correctly in cue cmd-declared command tasks; see CL 541898.
cmd/cue
Version control system (VCS) information is included in cue version as of CL 540297. The Go version used to build cmd/cue is included as of CL 549302.
cue def now supports an --inline-imports flag which resolves imports to print a self-contained version of the command input. For example, given the txtar input:
-- cue.mod/module.cue --
module: "example.com/a"
-- in.cue --
package a
import "example.com/a/pkg"
import "list"
v: pkg.v
-- pkg/pkg.cue --
package pkg
v: { x: 3, y: x }The running cue def --inline-imports in.cue will give:
package a
import "list"
v: {
x: 3
y: x
}CL 546243 fixed a long-standing bug whereby the --ignore errors flag was not observed by cue eval.
v0.4
v0.4.3
This release includes various bug fixes, including fixing some crashes. It also fixes a memory leak that would cause long-running servers to OOM (see #1418). It also now supports Go 1.18.
It also fixes various builtin extensions.
This release also makes a lot of preparations for the upcoming comprehension rework, which will allow us to do all kinds improvements and performance enhancements.
As a reminder: users can register their projects with unity, our regression and performance testing setup. unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. unity continues to catch multiple issues with each release. Adding your project to unity not only guarantees that we will not break your tests (if we do, we will work with you to fix your CUE code), but it also helps to improve the quality of each CUE release. We are in the process of adding support for adding private projects to unity.
Thank you to @benmoss, @cuichenli, @danbison, @emcfarlane, @eonpatapon, @jared-gs, @jdreaver, @jlongtine, @mattmoor, @mvdan, @oncilla, @roidelapluie, @slewiskelly, @xinau, and @yannk for contributing to this release!
Language changes
This release removes all remaining support for quoted identifiers. Although this hasn’t been supported for a while, there were still parts of the code that handled them, resulting in cryptic error messages.
Core evaluator
This release sees an overall improvement in error location reporting. These changes are quite substantial but largely, aside from a few resulting bug fixes, do not alter behavior.
Builtins
net
Add CIDR range verification function.
regexp
Add ReplaceAll and ReplaceAllLiteral
time
Fixes a hermeticity issues where a local time zone may be selected. Added FormatString to ultimately replace Format, where Format will first have to be deprecated.
Add FormatString, FormatDuration and Split
tool/file
Add MkdirTemp, RemoveAll
tool/http
Add Support for TLS settings.
Docker images
docker pull docker.io/cuelang/cue:0.4.3
v0.4.2
This patch release largely focuses on bug fixes, but also includes some additions to the cmd/cue cmd tooling layer and builtins. Some of the bug fixes were identified as part of preparing for an upcoming CUE talk at FOSDEM.
Thank you to @brandonbloom, @eonpatapon, @obowersa and @seh for contributing to this release!
Core evaluator
A number of bug fixes relating to edge cases of CUE evaluation. Notably, 1374dc99007937166e204302792df34c46138df0 fixes some subtle bugs where fields can be missed if patterns are inserted too late.
0aaf4c69be6394bcb20c0a659382f48b9cffec33 disallows _ as a field label, fixing a bug where the following CUE was previously accepted as valid:
_: 5
This now results in:
cannot use _ as label:
./x.cue:1:1
Tooling layer (cmd/cue cmd)
@eonpatapon added Mkdir, MkdirAll to pkg/tool/file. https://github.com/cue-lang/cue/issues/1502 was raised as a follow-up, a wider review of how the pkg/… API needs to change pre v1.
Spec
@seh contributed to the “Declarations and scope” section, clarifying that top-level let identifiers are scoped to the containing file block.
cmd/cue
@slewiskelly highlighted a regression introduced as far back as aaf6e846d8450663dd4fd265021a969d02a2bf4e where cmd/cue is used to validate data using a schema. In this regression, CUE inadvertently marks the failures as “fatal”, instead of “incomplete” (that is, could be satisfied by making a value more concrete). 04812bfb515de3300ac21ca181542f8ea02c9ea1 disables schema checking for now whilst we consider a more precise solution.
Builtins
Both pkg/encoding/yaml and pkg/encoding/json now support UnmarshalStream.
Docker images
docker pull docker.io/cuelang/cue:0.4.2
v0.4.1
After an extended break following CUE’s migration to cue-lang/cue and multiple pre-releases, the v0.4.1 release mainly focuses on bug fixes. We also renew our pledge to in future release smaller changes more frequently on our way to language stability.
Thank you to @chai2010, @yujunz, @caarlos0, @hrvolapeter, @slewiskelly, @antong, @mvdan, @ameowlia and @palmamartin for contributing to this release!
Project-level changes
- Create
amd64andarm64release assets forlinux,windowsanddarwin, with accompanyingamd64andarm64Docker images and manifests:v0.4.1-beta.6 - Remove
go1.15from build matrix:v0.4.1-beta.6 - Improve contribution project contribution guide:
v0.4.1-beta.6
Encoders
- Upgrade
gopkg.in/yaml.v3; may result in some formatting changes for Yaml output:v0.4.1-beta.6
cmd/cue
- Support working directory in
tool/exec.Run:v0.4.1-beta.6 - Numerous bug fixes relating to
cue evalexporting ofletexpressions (#1116):v0.4.1-beta.6 - Fix for
cue defbug where multiple list conjuncts resulted in an output containing a{}conjunct:v0.4.1-beta.6
API
cue.ResolveReferencesfixed to work for the KubeVela project:v0.4.1-beta.6- @ameowlia fixed an issue with a test example for
cue.Context:v0.4.1-beta.6 - Allow concurrent use of
cue.Context:v0.4.1-rc.1
Evaluator
- Fix a number of issues related to the use of aliases in lists by introducing a new scope with list values:
v0.4.1-beta.6 - Fix for issues related to defaults and string and number lists (#1025, #1404):
v0.4.1-beta.6 - Fix for a bug where comprehensions inside a definition resulted in an error (#1404):
v0.4.1-beta.6 - Important fix for bug related to the handling of default values that result in error (#1304 and #1257):
v0.4.1-beta.6 - Various unexpected panics have been fixed, including a panic in the case of circular
letdeclarations (#1042):v0.4.1-beta.6 - Fix matching of
"_"label:v0.4.1-rc.2
Language
This release makes no changes to the language.
- The CUE spec now correctly defines
$as an identifier (#1264):v0.4.1-beta.6
Docker images
docker pull docker.io/cuelang/cue:0.4.1
v0.4.0
In line with our aim to release smaller changes more frequently on our way to language stability, the v0.4.0 release comes just under two months after v0.3.0. It includes one language addition, a fairly significant reshaping of the API and tooling improvements, as well as the usual host of bug fixes, and performance and error message enhancements.
This release includes a more comprehensive implementation of protobuf, supporting textproto and JSON protobuf mappings, and paves the way for binary protobuf support. See the v0.4.0-alpha.1 release notes for more details.
This release also sets the direction for the CUE API, and brings the overall API much closer to where we would like it to go in the run up to v1.0.0. It also prepares the API for the query extension. See the v0.4.0-alpha.2 release notes for more details.
The v0.4.0 minor release follows the pre-v1.0.0 release policy described in the v0.3.0 release notes: it contains backwards incompatible changes discussed below.
As a reminder: users can register their projects with unity. unity is used to ensure that a project’s CUE evaluations do not unexpectedly stop working, or regress in terms of performance. We are in the process of adding support for API-based tests, as well as private instances.
Language additions
- Value aliases:
v0.4.0-beta.1
Tooling
- Tag variables to inject contextual system values:
v0.4.0-beta.1 - Binary file type:
v0.4.0-beta.1
API additions
Context.NewList:v0.4.0-beta.1Value.FillPath:v0.4.0-beta.1Context.Encode:v0.4.0-beta.1- The
cue.Pathmodel:v0.4.0-alpha.2 - Phasing out
Instance:v0.4.0-alpha.2 Contextto replaceRuntime:v0.4.0-alpha.2Value.Allows:v0.4.0-alpha.2
CUE package additions
crypto/hmac:v0.4.0-beta.1uuid:v0.4.0-beta.1
Performance and error handling
- Error message tuning:
v0.4.0-alpha.2 - Fix for pathological performance hit when using
FillorUnify:v0.4.0-alpha.2
Backwards incompatible changes
- Dropped support for old-style aliases:
v0.4.0-beta.1 - Dropped support for old-style comprehensions:
v0.4.0-beta.1 - Removed
ast.TemplateLabeltype from API:v0.4.0-beta.1 Value.Expr:v0.4.0-beta.1Value.Decode:v0.4.0-beta.1Value.Formatimplementation:v0.4.0-alpha.2cue/encoding:v0.4.0-alpha.2@protobuftag:v0.4.0-alpha.1- JSON mappings:
v0.4.0-alpha.1 - Enum mappings:
v0.4.0-alpha.1
v0.3
v0.3.2
Not a big release, just a couple of API bug fixes.
v0.3.1
This release contains several bug fixes, API additions, some API deprecations, and a language addition. One of the bug fixes may lead to unexpected behavior (see below).
Backwards Incompatible Bug Fix
One common use case of cmd/cue involves combining CUE and non-CUE files. Consider the following example:
// check.cue
package check
map: {for n in nodes {"\(n.name)": n}}# data.yaml
nodes:
- name: bar
parent: foo
- name: baz
parent: fooWith v0.3.0 and earlier, cue eval would happily combine these two files:
$ cue eval data.yaml check.cue
map: {
bar: {
name: "bar"
parent: "foo"
}
baz: {
name: "baz"
parent: "foo"
}
}
nodes: [{
name: "bar"
parent: "foo"
}, {
name: "baz"
parent: "foo"
}]But cue vet would complain:
$ cue vet data.yaml check.cue
map: reference "nodes" not found:
./check.cue:3:16cue vet is actually correct here. Identifier resolution should only happen across files that belong to the same package: non-CUE files are equivalent to a CUE file without a package clause or an anonymous package clause (package _), hence cue eval should really fail in this instance.
v0.3.1 makes cue eval and other commands consistent with cue vet. This was deemed a sufficiently breaking change to warrant its own release.
The fix in this case is to define nodes in the scope of package check:
// check.cue
package check
nodes: _
map: {for n in nodes {"\(n.name)": n}}at which point cue eval succeeds as before.
An upcoming change will also ensure this condition of identifier resolution is satisfied for all non-package CUE file arguments.
API changes
The cue.Selector model has been extended to allow querying optional fields and arbitrary elements.
Deprecations
The following methods of Value have now been deprecated:
FieldByName
Elem
Template
Really, you should only need LookupPath for your lookup needs. For the most part, these old methods have been reimplemented using the new API.
Also, updated the doc that one really, really should not use Merge.
If you are a user of the API we strongly recommend running staticcheck: it will raise errors where you are using deprecated parts of the API.
Language Additions
CUE now allows parenthesized expressions as labels. This is not (yet) published in the spec, but part of the query proposal. So "\(x)": foo, where x is a string, may now be written as (x): foo.
v0.3.0
After a long road, we have now an official v0.3.0 release. Aside from implementing some important changes to the language (see release notes), it prepares CUE for exciting new features such as the query and policy extensions and other language extensions as well as much better performance.
The focus will now be to get to language stability and a v1.0.0 release.
With this release will also come a different approach to versioning leading up to the v1.0.0 release. The goal is to get to the stability guarantee for the language first, then the API and tooling. Up to v1.0.0, version increments will have the following meanings:
- minor (
_.x._)- backwards incompatible changes
- bug fixes with notable backwards incompatible changes
- large new features
- patch (
_._.x)- bug and spec conformance fixes
- new features
We plan to get the few small remaining backwards incompatible languages chances out as soon as possible. To make the transition as simple as possible, we aim to put possible impactful bug fixes in small releases, so that users get a chance to get used to them. And, of course, we plan to make any necessary transitions as smooth as possible using cue fix aids when possible.
Note that to smooth out any transition, users can register their repos at https://github.com/cue-sh/unity. This is used to ensure that their CUE evaluations will not unexpectedly stop working.
API
encoding/protobuf/jsonpb
Protobuf defines its own, somewhat peculiar, mapping to JSON. This package provides a way to interpret JSON for such mappings, given a CUE schema. This is a first step towards broader Protobuf value support.
cue.Selector
Several new features have been added to Selector, including the possibility to query whether a selector is a regular string field and the ability to create a Selector form an ast.Label.
Value.Attributes
Value has been extended with a more extensive API to retrieve attributes.
Value.Subsume
Now allows raw (CUE-native) subsumption, instead of just the “Schema” or “Data” interpretations.
Value.FillPath
For completeness, note that beta.8 already introduced FillPath.
v0.2
v0.2.2
This is the last release before commencing the move to the new evaluator.
Backwards incompatible changes
yaml.Validate
This now uses Unification again. This brings it in line with the json package.
This change was done to facilitate moving to the new evaluator. This seems no longer necessary. Either way, using subsumption for validation seems wrong. It is better if the desired validation can be specified in the language itself.
Language feature support override
This is the last version that supports :: under the hood and the last release that will allow moving from :: to new-style definitions using cue fix. The cue tool now supports the CUE_SYNTAX_OVERRIDE environment variable to specify the features to allow at a specific version. So even though this feature disallows :: by default, it can be allowed again by setting this environment variable to v0.1.0, for instance.
This will not re-enable features that have been permanently removed.
OpenAPI fixes
OpenAPI is not always compatible with JSON Schema. For instance, it may use an older version. CUE used the new interpretation of exclusive ranges, whereas OpenAPI v3.0.0 and before required the old interpretation. Both interpretations are now supported and are switched based on the selected version (an API feature).
cue completion
This release exposes the Cobra command completion feature. This is currently only tested for bash and is known to not work, for instance, for Fish.
cue get go
This will now generate unexported constants using the _# prefix.
API
Fill
Now allows a cue.Value to be set anywhere in a Go value.
Builtins
list.SliceRunes
Allow slicing of strings per rune.
Embedding in NewStruct
Added ast.Embed helper to specify embeddings in ast.NewStruct.
Testing
Most txtar-based tests now support the CUE_UPDATE environment variable for updating tests. This allows running
CUE_UPDATE=1 go test ./...to update all these tests at once. It is not possible to use the --update flag for a bulk update, because not all tests implement it, causing such tests to fail.
v0.2.1
Disabling of previously deprecated language features
The new evaluator will no longer support some of the legacy syntax. Also, it will adopt JSON Schema semantics for bulk optional fields (to be called pattern constraints) and will have more flexible semantics for ellipsis to allow encoding “additionalConstraints” more easily.
To allow for a smooth transition, this release disables the older deprecated semantics and syntax to remind people to run cue fix to upgrade their configurations, as cue fix won’t work for these deprecated features once the new evaluator comes around.
API changes
To facilitate moving the API as well, LookupDef now automatically adds a # prefix if a field cannot be found and is not a valid definition in the new syntax. This is an unambiguous addition.
JSON Schema and OpenAPI fixes
Exclusive minimum and maximum legacy support
The current OpenAPI implementation used the current JSON Schema semantics for representing exclusive minima and maxima. OpenAPI v3.0.0, however, mandates the use of the deprecated encoding. The OpenAPI generator now generates such constraints using the legacy syntax. The OpenAPI generation API now has a Version field that allows enabling the new behavior if set to 3.1.0.
As for now, the JSON schema reader will accept the legacy encoding unconditionally in addition to accepting the standard encoding.
$ref changes
OpenAPI defines that a$ref replaces all other fields in a schema. The JSON Schema RFC seems to allow at least some fields to be alongside $ref and there are some side comment notes that seem to imply that this is explicitly allowed. In order to avoid any confusion, however, $ref is now wrapped in an allOf if it may otherwise cause a conflict.
JSON Schema model fixing for mixed type fields
The original JSON Schema made the erroneous assumption that a constraint for a certain type implies that the value must be of this type. This is not the case. So
type: [string, integer]
minimum: 3
maxLengh: 4will now be encoded as
strings.MaxRunes(4) | (int & >=3)
cue get go
The cue get go tool now also converts Go constraints encoding the field tags. This bring is in line with the API converters.
The tool now also has a --local flag to allow generating files in the Go package directory, rather than the corresponding cue.mod/gen subdirectory. This is not set to the default as to not break existing behavior.
v0.2.0
This release makes several minor and bigger language changes. The changes are a result of analyzing CUE’s interoperability with other languages and what is needed for this. It is expected that these are the last major changes and that this fixes the look and feel of the language. In addition to the usual cue fmt-based rewrites, we now also provide a cue fix command to aid in the transition. Also, the old formats are still supported for now. Minor language changes and additions to the language are still planned on the path to stability.
The new language changes allow for a simpler JSON Schema mapping. This, in turn, allows for a more straightforward combination of schema and data on the command line.
New syntax for definitions
Before, definitions were indicated with a double colon ::. They lived in the same namespace as regular fields. This property complicated defining automated conversions of some other data formats to CUE. For instance, JSON Schema keeps separate sections for schema and definitions. As there is no enforced convention, as in Go, for naming the two kinds differently, one could not map these to the same struct. This forced schemas to be moved to another location, which turned out to be cumbersome and unnatural.
Another issue with the old syntax is that one could not determine from a reference a.b whether b would refer to a definition or regular field. Not a big problem per se, but it lacked clarity.
As of v0.2.0, definitions are denoted with special identifier starting with a #. As this was not a legal identifier before, such identifiers can safely be used exclusively for definitions. Effectively, definitions now have their own namespace. Other than that, definitions work as before. They still close a struct, they are not output during export, and you simply use their identifier to refer to them.
Before:
A :: b: int
b: c :: string
D: A
E: b.cAfter
#A: b: int
b: #c: string
D: #A
E: b.#cThe #c notation is just an identifier: no special syntax is needed to handle them. As before, "#foo" still denotes a regular field with a name starting with #.
Using an initial # to distinguish between definitions and regular fields was inspired by Go’s use of initial casing to distinguish between exported and non-exported identifiers. Indeed because CUE is a JSON superset and interop focused, there is little control over casing. As we explain later in the Hidden Fields section, we also resurrect _ as a means of excluding fields and definitions from output.
The new notation may take a bit of getting used to, but the increased readability and the flexibility from the separate namespaces are big wins. So far the feedback has been overwhelmingly positive.
The Go, Protobuf, JSON Schema, and OpenAPI mappings, as well as the tutorials, have been ported to use #-style definitions. Please beware that if one has other templates based on this they need to be rewritten as well.
Limitations
The new definition syntax is more restricted than the old syntax. In general, it is no longer allowed to have dynamic definition names. For instance, the syntax disallows using interpolations for creating names. Also bulk optional fields only apply to regular fields. We think this actually benefits static analysis and is overall a good change. If need be, though, the old semantics can be simulated by containing a struct within a definition used as a map. In case this proves to be too limiting, we have a possible language change up our sleeves that would allow dynamic definitions again.
Old style definitions will keep being supported up to the next minor release. Use cue fix to rewrite current files (see below).
API changes
The current API assumed definitions and fields lived in the same namespace. The current API is therefore inherently broken. The Struct.FieldByName has been deliberately broken to force users to disambiguate. To evaluate a reference, it is recommended to use Dereference instead of passing the result of Reference to Lookup.
There are some good ideas to make the API considerably simpler and more powerful. This is contemplated to be built on top of the new adt package, which is developed as part of the evaluator rewrite, which is planned for the next minor release.
cue fix
To aid in the conversion to #-style definitions, the cue fix command is introduced. This command does a module-wide update of packages by default, but allows specifying individual files and packages.
This is no longer piggybacked on cue fmt. Unlike previous rewrites, the definition rewrite requires evaluation. In addition, not all current definitions are legal in the new syntax. The converter will not remap those. Also, unfortunately, due to API limitations, the converter can also not handle all legal cases. We hope that such cases will be rare, though.
Cases that cannot be handled are clearly marked with locations that may reference the definition included. Definitions with issues have are marked with a deliberately obscure @tmpNoExportNewDef attribute, indicating they need manual fixing
There is also a possibility there will be undetected breakage. This may happen if a selection is made in a disjunction where the field may be either a definition or regular field. The fact that this is even possible indicates that the old model was probably too flexible and possibly more bug prone. With new-style definitions such shenanigans are no longer possible.
Unfortunately, cue fix currently does not handle updating multiple packages within the same directory at once unless manually specified. We intend to allow this at some point.
Tool semantics changes
Previously, the cue tool handled schemas and data differently. In practice, the distinction is not all that clear, making this distinction somewhat “forced”. The cue tool now treats data and schemas as the same thing and always unifies them without distinction by default. This greatly simplifies its use and makes it a very powerful tool for operating directly on non-CUE schema.
There are two exceptions to the new “always unify all files” rules: 1) with cue vet multiple data files are still individually verified against a single schema. 2) the -d option still separates schema from data files. One could argue that the latter isn’t really necessary anymore, as we will see next.
JSON Schema mapping
The following command
cue export schema.json data.yamlconverts the schema.json (which has a proper value for $schema to detect the format) to a schema and data.yaml to data, and unifies the results. This will naturally fail if the contents of data doesn’t correspond to the schema. There is no special logic needed to detect these cases, other than knowing when to interpret a data file as JSON Schema.
Note that #-style definitions were key to make this possible. Without them, there would be no obvious way to map JSON Schema to the root of a config as merging fields and schema to the same namespace could result in conflicts.
OpenAPI merging
Another example of the new capabilities is that one can now merge schema as one would merge data. For instance, the following command merges two OpenAPI files and then outputs it again as OpenAPI:
cue def openapi: file1.json file2.json --out openapiThe user won’t even see the intermediate CUE.
Hidden fields
This release also officially resurrects hidden fields (identifiers written as, for example, _foo). They were removed from the spec as with the introduction of definitions they were believed to be an incongruent feature. They fit, however, quite nicely with the new-style definitions. They were still in use and proved to be more useful than expected. As they were never really removed from the implementation nothing changes. However, their comeback is now official.
For clarity, both hidden fields and definitions are not shown in exported output. They serve different functions, though.
A definition defines a new composite type, the most general specification of something. They are at the other end of the spectrum to concrete instances. As definitions are supposed to fully define a schema, CUE can use them to catch typos in field names by detecting fields that are not supposed to be there.
A hidden field can be any value and is not subjected to such scrutiny. They are used to define fields that are not converted to output without making them a definition.
Although this is not yet enforced, hidden fields are local to a package. To make the matrix complete identifiers starting with _# denote hidden definitions, or definitions local to a package. These can be used today, although this restriction is also not yet enforced.
Streamlined syntax for list comprehension
List comprehensions are now written as
[ for x in src { x + 1 } ]This brings them in line with field comprehensions, where the value also comes after the comprehension clauses. Overall, this greatly increases readability.
This also harmonized the syntax. It simplifies both spec and implementation, and prepares for some of the constructs mentioned in the query proposal.
The one thing that may require some getting used to is the curly braces alluding to the value being a struct. If the curly braces contain a single scalar value, however, it is promoted to be the result of an iteration. CUE users may already be familiar with this construct at the top-level scope, where “embedded scalars” are the final result of evaluation. This construct was originally invented to allow omitting curly braces, while still being a superset of JSON (JSonnet uses the same trick). It turns out, however, that this trick can be quite useful when generalized to apply to any struct, not just the top-level one. We continue to investigate this possibility. Consider this the first application.
Using cue fmt will automatically update old list comprehensions to use the new format.
Added limitations on bulk optional fields
Previously, it was allowed to have a bulk optional field alongside regular fields within a struct
a: {
[string]: T
foo: S
}Many people expected T to only apply to fields other than foo, but not foo itself. This is, in fact, how JSON Schema’s patternProperties and additionalProperties work. With hindsight, this approach turns out to have many benefits.
The plan is to transition to these new semantics. We will first disallow bulk optional fields alongside other fields altogether. This can easily be worked around by singling out such fields by wrapping them in curly braces:
a: {
{ [string]: T }
foo: S
}Bulk optional fields of this style
a: [string]: intare effectively already singled out and can remain unchanged.
The resulting embedding means the same thing in CUE. After the original semantics of mixing these fields has been banned for some time, we can introduce the original syntax, but now with “fallback” semantics analogous to JSON Schema.
For this release cue fmt simply rewrites bulk optional fields to be singled out. Forcing the rewrite is planned for a next release, followed by dropping support, waiting and then changing the semantics.
API: astutil.Sanitize
A noteworthy addition to the API is astutil.Sanitize. This function aids automated rewrites of CUE ASTs. Adding fields to arbitrary CUE ASTs may inadvertently shadow references. Inserting references to imports may cause similar issues. Not handling these cases correctly was a common source of bugs. Sanitize shares code with the actual resolver and can therefore be expected to be more accurate than any parallel implementation.
The Sanitizer automatically detects and resolves shadowed fields and fixes the AST in place accordingly. It uses the following trick: like in Go, the CUE resolver uses an extra field in ast.Ident (a reference) to mark what an identifier points to. The Sanitizer runs resolution on an AST which already may have such fields filled out from previous resolutions. If the result is not consistent, it will modify the AST to make it so.
Users can manually set such resolutions as well. For instance, setting the resolution to an ast.ImportSpec will cause the spec to be inserted automatically or the node to resolve to a preexisting equivalent one.
More functionality can be added in the future. The key is that all converters can share the same logic. It has already been used to fix import inserting in JSON Schema and to fix import disambiguation in the protobuf converter.
CI improvements
CUE uses GitHub Actions for its CI. The configuration for that was YAML. The lack of validation causes some breakages here and there when these needed to be adjusted. The configuration is now written in CUE! We’ll let you know how it goes.
We also now have a TryBot for the Gerrit repo, which should also prevent breakages in the future.
Deprecations
Space-separated labels are now no longer supported and will give a compiler error complaining about a missing :.
Legacy (“back-style”) field comprehensions are now also no longer supported.
Some APIs have deliberately been broken to force handling the distinction between identifiers and strings.
v0.1
v0.1.2
This release contains several fixes and enhancements related to CUE conversions.
It fixes several issues with the related to JSON Schema conversion, including an incorrect implementation of the JSON Schema spec. Most notably, one may not infer from a constraint for a certain type that a value must be of that type. This means that if a schema, for instance, defines a properties section, but does not specify the type to an object, the resulting CUE value will be a disjunction from this object and all non-object top-level types. This is not a bug.
Another change is that the cue tool now may silently ignore imprecise conversions, as long as the produced result does not give false negatives. The --strict option will emit the original errors.
v0.1.1
The release fixes a critical regression that affected cmd eval as well as various other minor regressions and documentation and formatting issues.
Support for space-separated labels and old-style field comprehensions is now disabled by default. The intention is to remove these entirely soon.
This release now also allows OpenAPI inputs to be expressed in CUE itself, instead of just JSON or YAML.
v0.1.0
This release introduces various improvements to the cue command, including a streamlined CLI interface and improved interoperability between different file formats.
Many of the command-line flags were previously rather arbitrarily implemented for some commands and not others. This release fixes most of that. This release also makes it possible to convert between different formats, such as YAML, JSON, JSON Schema (input only), OpenAPI, and Protbuf (input only).
This release also starts a new versioning strategy. CUE exists of several fairly independent parts. Each next milestone focusses on a one of these parts. This round it was the cue command-line tool. Next round will be the evaluator. Each next minor version will correspond to one such milestone. This is not to say that upgrades and bug fixes cannot happen to other parts within a cycle—they can—but it helps focus.
The new strategy will also make it easier to do intermittent releases. We will use the minor releases to signify big additions and backwards-incompatible changes. Patch releases may include backwards-incompatible changes that include bug fixes or disabling previously deprecated features. We intent to follow this trategy until providing a general backwards-compatibility guarantee for v1.0.0. As usual, we intend to provide a smooth migration path for each incompatible language change.
As of this release, a Docker image is generated as part of the release process.
Define file types
A frequently asked feature was to be able to interpret files as anything. CUE now allows qualifiers to “cast” a file to any supported format. For instance,
$ cue eval json: foo.datainterprets foo.data as JSON and then prints it as CUE. This also shows that the input for eval no longer needs to be CUE but can be any format that is convertible to CUE.
This means that CUE can now also be used between non-CUE formats. For instance,
$ cue export foo.json -o foo.yamlwill convert JSON to YAML.
Packages can now be qualified by package name (for instance ./foo:bar), not just directory.
Run cue help inputs and cue help filetypes for more information.
Streamlined flags
The import command already had a set of flags that maps JSON and YAML files to a prescribed location within a CUE configuration. These flags are now also available for many other commands so that JSON and YAML files, as well as other formats, can be processed by the cue command without first having to convert them to CUE.
For instance,
$ cue eval -l 'strings.ToLower(kind)' -l name foo.yamlputs any document in foo.yaml at a path based on its kind and name fields.
Also the output flags (file and format), among others, have been harmonized across commands. This sometimes led to backwards-incompatible changes.
Run cue help flags for more information.
CUE as a data format
The qualifier mechanism can also be used to restrict what language constructions can be used in .cue files. Most notably,
$ cue eval data: foo.cuespecifies that the file foo.cue may only contain data fields, but no references, definitions, builtin invocations, or any other CUE construct other than simple data. In other words, this allows CUE to be used as an alternative JSON or YAML format.
In the future we may add a file extension to indicate this CUE dialect.
New cue def command
The cue eval command was configured to generate cue that seemed pleasing to read to humans, but it would generate something that is neither useful as data nor as a schema. cue export could already be used to generate data, but there was nothing to conveniently generate a schema.
cue def is also the command of choice converting schema-based formats to CUE.
Value injection
Many users have requested a convenient way to defining environment-specific variants of configurations and ways to inject values based on environemt variables and command line flags.
We have added support for environment variables at various points in the tooling layer. Due to their non-hermetic nature, though, environment variables are not an appropriate mechanism for CUE configurations in general.
An important criterion for allowing such injection was retaining the ability to analyze configurations and make intent of how to use a configuration explicit. Simultaneously, we did not want to impose on the structure of a configuration.
Our solution is to use attributes to explicitly mark injection points. A field that with a “tag” attribute of the following form:
environment: "prod" | "staging" @tag(env)can be set to "prod" on the command line using -t env=prod. The tag attribute may also explicitly define some shorthands. For instance, by specifying
environment: "prod" | "staging" @tag(env,short=prod|staging)the same can be accomplished using -t prod.
This mechanism makes it very clear to both the user and the cue tooling which non-concrete values may be set by the user and which should be resolved by values within a configuration.
In the future we may consider to also allow whole-file injection analogous to Go build tags.
This release does not include support for command-line flags in the tooling layer. This is still being considered for a future release.
Run cue help injection for more information.
OpenAPI support
The cue tool now has basic support for converting OpenAPI definitions to CUE. This is a first stab, does not yet support external references, and is not as feature rich as the CUE-to-OpenAPI Go API that is used by Istio to generate its OpenAPI. But it should be a good start.
OpenAPI definitions can be imported using cue import or just used on the fly using cue eval or cue def. OpenAPI can be defined in JSON or YAML. For instance:
$ cue def openapi: foo.yamlwill interpret the foo.yaml file as OpenAPI and generate corresponding CUE.
It is also possible to convert CUE to OpenAPI. OpenAPI can be represented in JSON, YAML, or even CUE. For instance,
$ cue def ./pkg -out openapi+yamlwrites the evaluated CUE as OpenAPI in YAML format to stdout.
JSON Schema support
The cue tool has very basic support for mapping JSON Schema to CUE. This is still experimental and the converse (mapping CUE to JSON Schema) is not yet supported. The typical conventions followed in OpenAPI make it easy to find a mapping from OpenAPI to CUE. The same does not hold for JSON Schema. This is partly complicated by fields and definitions sharing the same namespace in CUE. Also, the top-level schema of JSON Schema is unnamed, making it hard to find an appropriate destination.
There is a proposal for CUE to have definitions and fields live in a separate namespace. This will make such a mapping considerably easier. For now, consider the mapping experimental.
As with OpenAPI, external references and anchors are not yet supported.
Auto detection of file types
The cue tool now interprets files with a .json, .yaml and .yml extension as either data, OpenAPI, or JSON Schema based on markers in the data. For JSON Schema this is a $schema field that refers to a schema on json-schema.org. OpenAPI is selected if a file contains a top-level openapi field with major version 3, an info.title, and an info.version field.
The use of qualifiers disables auto detection. So auto detection for a JSON file, for instance, can be disabled using a json: or data: qualifier.
cue import modes
The cue import tool now has import modes that specify which kinds of files to import. The default is the old default: JSON and YAML files, but with auto detection enabled.
Run cue help import for more details.
Protobuf support
The new cue import proto command can import Protobuf definitions.
A successful run imports all transitive dependencies of a .proto file into a CUE module: .proto files located within the module are converted to a CUE package at that location. The package name is derived from the go_package option, if present. Imported .proto files that can be found in a given include directory are put in the corresponding path in the cue.mod/gen directory.
The existing Protobuf API has been modified to generate CUE types hierarchically (instead of mapping all files to the top level) to make them closely correspond to the Protobuf definitions.
Protobuf definitions can be annotated with CUE-specific options to specify additional constraints for fields.
Command and Task changes
The task section in commands is now optional. A task can be included anywhere in a command. So commands with a single task can now be written as
import "tool/cli"
command: echo: cli.Print & {
text: "Hello world!"
}The cue tool will look for tasks anywhere nested within the run command where each task is considered a leaf node in this nesting.
Tasks can also be defined at the top of the file. These will only be run if they are referenced by a task defined in an executed command
Sometimes task must run after another task, even though it does not depend on any of its outputs. The $after field can be used in that case to explicitly mark a dependency.
See https://pkg.go.dev/cuelang.org/go@v0.1.0/pkg/tool?tab=doc for more information.
Vet changes
In addition to the flag restructuring, it is now possible to check a data file against a CUE package.
A backwards-incompatible change is that one now needs to use the -d flag, instead of the -e flag, to select a schema against which to compare. The -e flag was used by other commands to mean something different and this was cleaned up for consistency sake.
Trim safeguard
The cue trim command now checks that the resulting rewrite results in the same output when exported. This prevents a bug in the trim algorithm from inadventently compromising a configuration.
Run the command with the -i flag to bypass this check.
API additions
Go API:
cue/ast: Many new AST construction helperscue/literal: Added CUE number parsing utilitiescue: AddedLookupDef,Dereference,IsClosedand various other methods.cue:Fillnow acceptsValue.
CUE API various additions to
pkg/encoding/yamlpkg/filepkg/listpkg/mathpkg/regexppkg/tool/execpkg/tool/os
Language Changes
- Added attribute declarations (
@foo(bar)can be used as a declaration.)
Backwards-incompatible changes
Changes in flags:
- The
--attributesflag has been renamed to--show-attributesto be consistent with the--show-hiddenand--show-optionalflags. - The
-eflag forcue vethas been renamed to-d. The-eflag was already used for other commands and means something similar, but different. This allows-eand-dto be simulatenously supported. - The
-oflag now always defines an output file and the-outflag now always defines an output format. - Block comment support was already deprecated for a while, but support has now been removed from the language.
API changes:
cue:Instance.Namewas changed toInstance.PkgName.cue:Iteratoris now returned as a pointer.cue:Syntaxnow includes a package clause if a package is defined.encoding/protobuf:- proper encoding of
oneOf, which previously required at least one of the one-of fields to be specified. - generated CUE types are now declared as definitions.
- generated CUE types are now organized hierarchically, mapping one-to-one to the hierarchy defined in the
.protofiles. It previously adopted the Go convention, mapping all types to the top-level.
- proper encoding of
Bug fixes and performance enhancements
There were several bug fixes. Some of them might break your configuration. For instance, a regression was introduced that allowed required imports to be omitted in *_tool.cue files.
v0.0
v0.0.15
This release focusses on bug fixes and stability improvements.
There is one language change, and that is to allow the $ character in identifiers. The main reasons for this is that it is a commonly used character in identifiers in JSON. The single $ is currently reserved.
v0.0.14
This release is characterized by a major syntax change. We don’t take such changes lightly. The new syntax makes the language more regular (and simpler to parse), prepares it for some key features, and, we believe, makes it easier to understand. This is also a major step towards stabilizing the grammar of the language to the extent we can start guaranteeing backwards compatibility.
The old syntax is still supported. The cue fmt will rewrite your files from the old syntax to the new one.
Colons instead of spaces as separators for shorthands
CUE allows single-field structs to be written without curly braces if they are declared at another field. In the old syntax
a: {
b: {
c: 4
}
}could be written as
a b c: 4In the new syntax, this is written as
a: b: c: 4Aside from enabling some new features and simplifying the parser, this syntax also allows the shorthand to be used for both definitions and regular fields. For instance,
a: b:: c: intprevious had to be written as
a: {
b:: { c: int }
}Bulk optional fields
The new syntax now allows optional fields to be specified in bulk:
// Define a map from string key to numbers
numMap: [string]: number
// Apply constraint T to all fields with a name ending in "Test"
[=~"Test$"]: TUsing [string]: number is very similar to using a “bind label” previously. More on that later.
The old syntax for optional fields
foo?: baris now just syntactic sugar for
["foo"]: barLabel filters are the equivalent of patternProperties in JSON schema.
Note that using colons as separators, which often have a connotation of defining something, interacts well with this language construct. For instance, a map of maps of ints is written as:
[string]: [string]: intMore aliasing
Shadowing of fields is a common issue in CUE (or similar languages, for that matter). CUE already supported various mechanisms to deal with this. For instance, in this example an alias is used to reach the outer a:
A=a
a: c: a: A.b
b: 4Other tricks up CUE sleeves were quoted identifiers and allowing to make field non-referable using double quotes. Together these tricks proved both cumbersome and inadequate. The existing techniques also proved to be hard to handle for code generators and rewriters.
CUE now extends the aliasing model to field and label aliases. A field alias,
X=foo: barbinds X to bar just as foo does. This allows the above to be written as
X=a: c: a: X.b
b: 4This is not a great win, bit in many cases it will be. Moreover, it allows defining references to fields that can otherwise not be referenced, such as
X="foo-bar": baz
Y="\(x)Test": yCUE now also allows label aliases, which are placed inside the square brackets:
[X=string]: { name: X }These are only visible within the field’s value. This replaces the “bind” labels, such as <Name>: { name: Name }. These are essentially the same, but explained differently and with a different syntax. The old syntax makes CUE hard to parse and is less flexible and will be phased out.
Packaging
Another change is the way the cue tool manages packaging. The cue.mod file and pkg directory are replaced with a cue.mod directory marking the root of a CUE module and with contents managed by the cue tool, analogously to how the git tool manages the .git directory.
See https://cuelang.org/docs/concepts/packages for more details.
Deprecations
Fields names starting with double underscore __
This was defined in the language specification, but previously not enforced. It now is. Field aliases make it easier to work around this restriction.
<X> syntax
Bind labels, or templates, are being replaced by the new optional field construct.
cue fmt will rewrite the old format to the new one.
Back-quoted identifiers
Back-quoted identifiers (i.e. foo-bar) were introduced to improve reachability of fields in case of shadowing. But they only solve half the problem. Field proved to be a more general solution, making back-quoted identifiers a redundant part of the language. As they are not trivial, they will be removed. As for now, the cue tool will rewrite programs using back-quoted identifiers using aliases.
v0.0.13
This release introduces two changes that may break existing configurations. One is really a bug fix relative to the spec. These changes were not included in v0.0.12 to allow some of the bug fixes of the latter release to be available before introducing these changes.
Top-level “emit” structs are embedded
Previously, a top-level embedded struct had different semantics from embedded structs within structs itself. For instance, this configuration
{
a: 3
}
b: 3would previously yield { a: 3 }, but will now yield { a: 3, b: 3 }.
This semantics was a leftover from before CUE supported embedding.
But keeping this around was just too confusing.
Other values, like lists or strings retain their original semantics. However, for consistency sake, these may only be accompanied by definitions.
So previously this was allowed
"Hello \(who)!"
who: "World"but must now be
"Hello \(who)!"
who :: "World"Failing Definitions are an error
Previously a definition was, unlike a normal field, not an error. This was not according to the spec and this has now been rectified. To allow a definition to fail, make it optional (using a `?).
v0.0.12
This release contains a host of bug fixes and improved conformance to the spec. The most notable change, however, is the relaxing of the closed struct constructs.
Relaxed closed structs
With the previous release, each struct literal in a definition was treated strictly as closed. This turned out to be both tedious and counter-intuitive. This led to a spec change and corresponding different implementation where a definition is only closed once it is referenced. This means that merging literal structs defined within a definition works exactly like unification of regular structs up to the point they are referenced.
Features
There are several builtins added, including in the list and regexp packages.
The latter added builtins to extract fields from strings into a struct using named groups.
v0.0.11
v0.0.10
Language touch ups
New-style Comprehensions
This release is characterized by the redesign of field comprehensions, now struct comprehensions. The old format is still supported, but cue fmt will rewrite it to the new format.
The new format looks like:
for k, v in a {
"\(k)": v
}instead of
"\(k)": v for k, v in aThis may seem like a gratuitous change, but it has many advantages:
- generated structs are syntactically and semantically like embeddings
- large comprehensions are clearer
- a single iteration can add multiple fields
- makes scoping clearer
Removal of block quotes
Because a comprehension may start with if, we can use if false { ... } to disable a large block. This, and various other considerations have led to the decision to remove block quotes from the language.
Block quotes are still supported, but they are no longer generated and cue fmt will translate them.
Quoted identifiers
CUE now allows identifiers to be quoted with back ticks:
`foo-bar`: 2
baz: `foo-bar`This allows fields with odd names to still be referenced using identifiers. More importantly, the allowed space of identifiers should ideally be limited. For instance, it is a good idea to require them to be in Unicode normal form NFC. Allowing arbitrary strings as identifiers seemed like a bad idea. CUE will soon disallow this. For now, cue fmt rewrites strings used labels is they are referenced by some nodes.
Quotes also have another benefit. A disadvantage of the new style comprehensions is that it is harder and less clear to allow the keywords of comprehensions as field names. Consider for instance:
for x in src: 2CUE will now only allow one such keyword as a field name, but requires quoting otherwise. A future cue fmt may rewrite this as:
`for` x `in` src: 2Backwards incompatible changes
The language changes introduced do not break anything, as the old formats are still supported. However, at some point they won’t be. So be sure to run cue fmt at some point.
- The
ast.LabelNamehas been changed to have proper semantics in light of the upcoming changes. The signature has been change to reflect the changes properly and to assure code is properly investigated in light of these changes. - Comprehensions now iterate only over non-optional regular fields, as would perhaps be expected.
- Top-level emit values are printed in eval output
- Top-level struct embeddings are merged in the API
v0.0.9
Bug fixes and builtins
The central theme of this release is bug fixes, most notably in the cue command line utility.
It also adds and improves on some of the builtins in the pkg directory.
Backwards incompatible changes
The crypto hash builtins now return a value of type bytes, instead of a list of bytes.