v0.4.0-beta.1

cue-lang/cue Pre-release Released

A release of CUE OSS · its page on GitHub

This release fixes some bugs, improves some errors and adds API. This version also drops support for some old constructs that have not been supported in the CUE tool for some time now. The main reason to start being more “aggressive” about this is to avoid surprises as we’re inching towards a full backwards compatibility guarantee. Note that “aggressive” is probably a strong word, these constructs have not been supported for over a year.

Language additions

Value aliases

CUE now allows value aliases, as suggested in various proposals and remarks. This allows, for instance, users to rewrite:

foo: {
    a: b + c
    b: int
    c: int
}
bar: foo & {b: 1, c: 2}

as

foo: X={
    a: X.b + X.c
}
bar: foo & {b: 1, c: 2}

In this case the benefit may be small, but there are various cases where not having this ability results in significant inconvenience. Also the query proposal, the UX design around the usage of the proposed must builtin, as well as various other patterns, rely on this ability.

Note the subtle but important difference between this and using field aliases. Using a field alias here, say X=foo: a: X.b + X.c would be equivalent to foo: a: foo.b + foo.c. As a result, in bar: foo, X.b would still be bound to the original location and not resolve to any b specified in bar.

Which one to use depends on the application. As a general rule, field aliases should be used when defining “types”, whereas value aliases should be used when defining “values”. An example of where one wants to use field aliases:

List="my-list-type": {
    value: _
    next:  List
}

Here, using a value alias would result in a list where every value must be the same. This is probably the most subtle aspect of CUE. The guideline of using values aliases when defining values, and field aliases when defining types, however, should give users a good steer on the matter.

Tooling

Tag variables to inject contextual system values

The injection mechanism now allows injecting specific variables, such as current time, username, or hostname, or a random number, into fields marked with a @tag attribute. For instance:

import "path"

_os: string @tag(os,var=os)

path.Base(dir, _os)

allows for an OS-specific Base operation. Except for cue cmd, the var will only be injected when the -T is explicitly specified on the command line.

This approach 1) allows packages to remain hermetic, 2) allows using such functionality without having to resort to cue cmd, and 3) avoids introducing another injection point.

See cue help injection for more details.

Binary file type

The cue tool now supports binary files. These are very much like the supported “text” files, but translate the file contents to a CUE binary literal, rather than a text literal.

There are no default file extensions to recognize a binary file. The binary: file qualifier can be used to read a file as binary. See cue help filetypes for more info.

To make loading binary files in bulk more useful when importing, the import command now supports the --ext flag, allowing certain file types to be interpreted as a certain format. This also works for other types. See cue help import for more info.

--force/-f

This flag is now allowed for any command that outputs files.

API additions

Context.NewList

Uses can now construct a new list cue.Value with Context.NewList. This is defined on Context to allow the creation of empty lists, which still need to be associated with a Context.

Value.FillPath

FillPath now accepts list indices. The Go-to-CUE are now documented in more detail.

Fillpath now also accepts the selectors AnyString and AnyIndex, which allows setting pattern constraints. For instance, v.FillPath(cue.MakePath(cue.Str("a"), cue.AnyString, x), adds a: [string]: x to v.

It also allows setting optional fields. For instance, v.FillPath(cue.MakePath(cue.Str("b").Optional()), 1) will add b?: 1 to v, using the usual rules for unifying such fields.

Context.Encode

The documentation of this method has been significantly improved. This also fixes some bugs that were uncovered in the process.

These are now also two additional options: InferBuiltins and ImportPath. These were exposed to support the cue command in using the new API, but thus also allows other tool writers to use the same kind of functionality.

CUE package additions

crypto/hmac

The new package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.

uuid

The new package uuid defines functionality for creating UUIDs as defined in RFC 4122.

Currently only Version 5 (SHA1) and Version 3 (MD5) are supported. The new tag variable injection mechanism that was introduced in this release, however, also opens up the possibility to include other versions, if needed.

Backwards incompatible changes

Dropped support for old-style aliases

Aliases of the style X = 4 (now let X = 4) have been deprecated since v0.1.4. However, by setting the version or in API use, these aliases would still work. Support for them has been fully removed. Down the line, this syntax can be reused as value aliases as well, relaxing the places where value aliases can be used.

For the time being, cue fix can still be used to rewrite old-style aliases to their let equivalent. There was a bug that missed the detection of some forms of the deprecated alias type. This has now been fixed.

Dropped support for old-style comprehensions

Support for the old-style comprehensions (e.g. [ x+1 for x in foo]) has now been fully removed. Use an older version of CUE to rewrite such old-style comprehensions using cue fmt or cue fix.

Removed ast.TemplateLabel type from API

This has not been parsed, supported, or used for ages. The type has now been removed from the API.

Value.Expr

Value.Expr now translates the or and and builtins as if they were native | or & constructs. This fixes a bug in encoding/openapi and is likely to prevent many issues. If one was relying on detecting the use of these builtins, however, this now will no longer work.

Value.Decode

This method was reimplemented to not use Value.MarshalJSON. This fixes many bugs, but may cause issues if users were relying on old behavior. The new implementation still strictly adheres to the JSON encoding spec when this makes sense, but deviates in some important aspects. For instance, numbers like 1 are now integers in CUE, rather than float. Also binary values are now handled correctly.

Bug fixes

  • hidden references used on the command line now resolve to hidden fields in the package under evaluation
  • equality of null value

All changes

46 changesby area

ci6

  • cidebug tip trigger failures5b14995
  • cifix broken tip and new version triggers24ce27e
  • cifix tip and new version curl and env problemsa8369ae
  • cifix tip triggers with proper quotingc143a3a
  • cimore debugging of tip triggers746e02e
  • citrigger unity and cuelang.org builds/equivalent on tip/new versions6c6b4e7

cmd5

  • cmd/cue/cmddo not silently ignore unknown filetypes97cac92
  • cmd/cue/cmdfix resolution of hidden values across tools89abc18
  • cmd/cue/cmdmove tag flags handling to central location4f7caea
  • cmd/cue/cmdsupport binary file typeb9e7d90
  • cmd/cuesupport --force for all commands that allow output flagsb449c0f

cue23

  • cue/astfully remove support for old-style comprehensionsaa70399
  • cue/astremove support for TemplateLabelb73ab0b
  • cue/loadprovide reason for exclusion of files1f1c3f6
  • cue/loadremove unused code975ba50
  • cue/loadsupport injection of system variablesbcdf277
  • cue/parserallow pattern constraints unconditionallyc2a68a9
  • cue/parserbetter error messages for use of deprecated constructs3e10918
  • cue/testdata, doc, pkgfix some it's/its typos3ef90b3
  • cueValue.Expr: process or and and builtins semantically.f60c88a
  • cueadd InferBuiltins EncodeOptiond9af603
  • cueadd NewListb49cbbd
  • cuealign import with top-level package for -e1f618f0
  • cueallow setting list elements in FillPath66efc67
  • cuebetter document Context.Encode and friends67c6b6f
  • cuehoist attribute-related functionality to separate file9d044f0
  • cuemore path cleanuped5cdf0
  • cuemove Decode to separate file3347302
  • cueprepare API implementation for structure sharingc365513
  • cueproperly decode "any" labels0457356
  • cuereimplement Decode to not use MarshalJSON819cf95
  • cueremove use of isDef5481b41
  • cuesupport optional fields for FillPath2e1ac0f
  • cueundeprecate Iterator.Labelac7e992

internal4

  • internal/core/adtfix null values equality1ad66ab
  • internal/core/adtuse Closed for checking recursive closedness3cdf845
  • internal/core/compledrop support for old-style aliases5cd76bb
  • internal/coresupport field value aliases8823e2a

pkg4

  • pkg/crypto/hmacadd crypto/hmac support6d67b48
  • pkg/crypto/hmacfix package documentation2118921
  • pkg/timefix documentation bug in Unixa7d3987
  • pkg/uuidimplementation of hermetic UUID functionsfd05bf4

Other4

  • doc/ref/spec.mdintroduction of value aliases3316905
  • doc/ref/spec.mdremove "dead code"a31dd01
  • docsadd link to Code of Conduct to CONTRIBUTING guide2198ac3
  • githubadd bug report template link to repro advicef5213be

Downloads

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

Archives

PlatformFile and SHA-256
macOS, Intelcue_v0.4.0-beta.1_darwin_amd64.tar.gz3949038e2eab93ab066874ede21910d64f46ac89520a7a873a6e871d94769947
Linux, x86-64cue_v0.4.0-beta.1_linux_amd64.tar.gz187bddf61b87f14c735e2404a5f3fa08dba949457e17104bf248b1d1a7e267dd
Linux, Arm64cue_v0.4.0-beta.1_linux_arm64.tar.gz676ee508fe1908fd84b59959d3150f3b5b0248d73a7fda95d768a2f7ab1c4062
Windows, x86-64cue_v0.4.0-beta.1_windows_amd64.zip5f443bde940beeb34798822797e32f2ba2c2e283e97be9fdc34083017efe6e4b

SHA-256 checksums for all of these: checksums.txt

Install CUE