v0.18.0

Latest Released

A release of CUE, published on cue.dev.

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.

cue
#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.

cue
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:

cue
@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.

cue
@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.

cue
#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).

cue
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.

Downloads

Every file this release published, with its SHA-256. Most people install CUE as Installing CUE describes, which also shows how to check a download.

Installers

PlatformFile and SHA-256
macOS, Apple silicon and Intelcue_v0.18.0_darwin_all.pkge3650a0ba305f3302351d275408ab30db96637eb4c545ca9795e7d760cacda49
Windows, x86-64cue_v0.18.0_windows_amd64.msic0d8eee86b74ec20e2761e2939851715b2e11045d95cc1fee58fa86834baacc0
Windows, Arm64cue_v0.18.0_windows_arm64.msi0c9bbf65af25be4849239407bc571d92ad13fc7e8f1ad7eefd7b24818ce78f1a

Archives

PlatformFile and SHA-256
macOS, Intelcue_v0.18.0_darwin_amd64.tar.gz1505834055850e645535267066e8383bb95d94c90dbc3d7973490f2506427b6b
macOS, Apple siliconcue_v0.18.0_darwin_arm64.tar.gzca98a77d1a98869078e2213d621ec70c6a84df4ef50f68fbc1a557e3219491fd
Linux, x86-64cue_v0.18.0_linux_amd64.tar.gz94559f109a79621476711905bc3099c45c29922a54904e4d526d7548f5a81c0d
Linux, Arm64cue_v0.18.0_linux_arm64.tar.gz0ad9238c89db5524677c1b46f34fe5e0e12c3876941aad6c3b3ac9f5633c01f7
Windows, x86-64cue_v0.18.0_windows_amd64.zip20474e5d77e500fad2e8a6295ce7418c2f2c1f3ea0d85322290c407466d70622
Windows, Arm64cue_v0.18.0_windows_arm64.zip9bd17491dc07147475b578122816a94d34702dc097dde5094c7e4a7c85e4eefb

SHA-256 checksums for all of these: cue_v0.18.0_checksums.txt

Install CUE