github cue-lang/cue v0.6.0-alpha.1

latest releases: v0.11.0-alpha.1, v0.11.0-0.dev, v0.10.0...
pre-release17 months ago

The main focus of this release is the introduction of required fields.

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 @4ad, @Abirdcfly, @alexandear, @joanlopez, @jpluscplusm, @kcburge, @mpvl, @mvdan, @myitcv, @rogpeppe, 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 present

which 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

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.

Builtins

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.

Changelog

  • internal/ci: use go1.20.3 for releases by @myitcv in 9db1b95
  • internal/tdtest: use field name in default error message by @mpvl in 401cab2
  • internal/core/adt: fix Definition closedness bug in API by @mpvl in c3c8eb7
  • update txtpbfmt to drop indirect dependency on glog by @mvdan in 410eea1
  • internal/core/adt: fix NotEqualOp for lists with differing lengths by @mvdan in 6e185bb
  • cmd/cue: remove skipped test scripts for fixing old definitions by @mvdan in 9505e90
  • all: make HTML escaping in JSON an opt-in by @mvdan in 48207fb
  • all: add tests to cover HTML escaping via encoding/json by @mvdan in 1aefd09
  • cue/build: remove context.Context field by @rogpeppe in 1932295
  • cue/ast: fix IsValidIdent for _0 by @rogpeppe in 9422314
  • internal/diff: remove unused code by @rogpeppe in 9e22283
  • cmd/cue/cmd: remove unused code by @rogpeppe in aa8c66f
  • internal/core/adt: fix let closedness issue with API use by @mpvl in 731ddd9
  • internal/core/export: avoid introducing shadowing by @mpvl in 1c9a3b2
  • internal/tdtest: new table-driven test package by @mpvl in 102150d
  • cue: more support for required fields for selectors by @mpvl in 0e16084
  • internal/core: fail on missing required only when concrete by @mpvl in f85172a
  • cue: fail on required field in various cases by @mpvl in e7d7c6a
  • internal/core/adt: add wrapper for inline Vertex by @mpvl in 071c4ab
  • internal/core/export: always export required fields by @mpvl in d5dd9ec
  • cue: remove field type by @mpvl in d05d9c1
  • cmd/cue: avoid loading the current package in cue help by @mvdan in 143b102
  • all: remove duplicate words in comments by @Abirdcfly in d8c71fa
  • internal/ci: fix cache eviction by @myitcv in 53d3bc7
  • internal/ci: address review feedback from CL 551352 by @myitcv in 06397b5
  • cue: add support for zero values in Value.Float64 by @kcburge in 8d31dad
  • cue/load/tags: add arch to set of injectable system variables by @jpluscplusm in 752b8e4
  • internal/ci: allow trybot workflows to be workflow_dispatch-ed by @myitcv in 09221a3
  • internal/core/adt: required fields checked for closedness by @mpvl in 42580d5
  • doc/ref/spec.md: fix uint16 and uint32 values range by @joanlopez in c67fe60
  • all: correct typos and duplicate words in comments by @alexandear in 2e28b01
  • cue/errors: remove redundant Sort call in list.sanitize by @zeithaste in f106acf
  • internal/ci: refactor CI workflows by @myitcv in d71a76c
  • internal/ci: remove hard-codings in base package by @myitcv in f881884
  • internal/core/adt: change addList signature by @mpvl in 0c840f6
  • internal/core/adt: introduce ArcNotPresent by @mpvl in e3a7fcf
  • internal/core/adt: use value array for Disjunction by @mpvl in 166ac88
  • internal/core/adt: specialize injectComprehension by @mpvl in fa4f2d3
  • internal/core/adt: hoist comprehension loop body by @mpvl in e0f5681
  • internal/ci: move evict_caches to base by @myitcv in cef63a3
  • internal/ci: remove mention of matrix and runner from base by @myitcv in 3ed9f92
  • internal/ci: remove trybot from push branches by @myitcv in 5cd427a
  • internal/ci: refactor base caching pattern by @myitcv in 92b28c4
  • internal/ci: drop pullThroughProxy step by @myitcv in 79aceb7
  • cue/errors: better vetting of error formats by @rogpeppe in c630554
  • internal/ci: improve push_tip_to_trybot defaults by @myitcv in be0601b
  • internal/ci/github: rename repo -> _repo by @myitcv in 646e965
  • internal/ci: import repo package once in github package by @myitcv in 7aec30c
  • internal/ci: drop parameter from trybotDispatchWorkflow by @myitcv in 6318def
  • cue/load: minimal module fetching implementation by @rogpeppe in cb9d6ed
  • bump golang.org/x and go-internal deps by @mvdan in 3f51337
  • internal/ci: bump GoReleaser to v1.16.2 ahead of v0.5.0 release by @myitcv in 5ec06d9
  • internal/ci: rename core -> repo by @myitcv in 6d6ffb4
  • start using Go 1.20, drop Go 1.18 by @mvdan in d1a6da8
  • internal/ci: switch to actions/setup-go@v4 by @mvdan in d9c354b
  • internal/ci: always force push to trybot repo by @myitcv in ed2a9c7
  • cue/load: avoid using ioutil.ReadDir to list directories by @mvdan in d077202
  • pkg/tool: small fixes to CUE docs by @mvdan in 3d08fb2
  • internal/ci: use unity and cuelang.org config from core by @myitcv in 4cbb563
  • internal/ci: DRY up core based on new base defaults by @myitcv in 1195b3d
  • internal/ci: establish better defaults in base by @myitcv in af02a2c
  • internal/ci: move away from using defs in github by @myitcv in 7a7ca81
  • internal/ci: move away from using definitions in base by @myitcv in d7a1740
  • internal/ci: use core directly instead of _base alias by @myitcv in f446b87
  • internal/ci: move away from using defs as params in base by @myitcv in 305dc1d
  • internal/ci: collapse gerrithub package into base by @myitcv in 9729270
  • internal/ci: tweak gerrithub package "params" ahead of move to base by @myitcv in 1980621
  • internal/ci: split base into separate files by @myitcv in 3a52c19
  • internal/ci: rename base parameter field name by @myitcv in cdd5730
  • internal/ci: move pushTipToTryBot workflow to gerrithub package by @myitcv in 0290e04
  • internal/ci: rename gerrithub #dispatchWorkflow by @myitcv in 0cfd8c5
  • internal/ci: remove hard-codings in gerrithub package by @myitcv in f5277b9
  • internal/ci: move configuration from workflows.cue to core by @myitcv in 1bb7e10
  • internal/ci: remove workflow files pre generate by @myitcv in b418955
  • Revert "internal/ci: move pushTipToTryBot workflow to gerrithub package" by @myitcv in 87db1a5
  • Revert "internal/ci: rename base parameter field name" by @myitcv in 2461c51
  • Revert "internal/ci: move configuration from workflows.cue to core" by @myitcv in 26ff449
  • Revert "internal/ci: rename gerrithub #dispatchWorkflow" by @myitcv in 38156f2
  • Revert "internal/ci: remove workflow files pre generate" by @myitcv in 0d89b9b
  • Revert "internal/ci: split base into separate files" by @myitcv in ee7509f
  • internal/ci: split base into separate files by @myitcv in d638a35
  • internal/ci: remove workflow files pre generate by @myitcv in f723eb7
  • internal/ci: rename gerrithub #dispatchWorkflow by @myitcv in d276f58
  • internal/ci: move configuration from workflows.cue to core by @myitcv in 5a0922e
  • internal/ci: rename base parameter field name by @myitcv in 584f3f0
  • internal/ci: move pushTipToTryBot workflow to gerrithub package by @myitcv in e440409
  • internal/ci: hoist dispatch keys to base by @myitcv in e3ed297
  • internal/ci: move workflows.cue defs to better places by @myitcv in 0250807
  • internal/ci: hoist cache steps to base package by @myitcv in 019f6dd
  • internal/ci: improve base package docs by @myitcv in 57066d4
  • internal/ci: make our checkout step configurable by @myitcv in ee093e2
  • internal/ci: specify githubRepositoryPath directly by @myitcv in 9c075ca
  • internal/ci: move core._#URLPath to base by @myitcv in dd965ad
  • internal/ci: move core.#codeReview to base by @myitcv in 8b14836
  • internal/ci: move core package away from definitions by @myitcv in 5475370
  • internal/ci: improve core package docs by @myitcv in e1a8bee
  • internal/ci: refactor the way we declare workflows by @myitcv in 09b06ff
  • internal/core/adt: hoist value validation by @mpvl in eea60b9
  • internal/core/adt: hoist comprehension code by @mpvl in 47f0025
  • internal/core/adt: reorganize nodeContext fields by @mpvl in f807ee8
  • internal/core/adt: unexport more methods by @mpvl in ce65141
  • internal/core/adt: unexport VertexStatus by @mpvl in 185eed7
  • internal/core/adt: remove state arg from Err, SetValue, and UpdateValue by @mpvl in 97904e3
  • internal/core/adt: unexport Unify by @mpvl in 7851142
  • internal/core/adt: clone arcMap by @mpvl in dbf7bb8
  • internal/ci: remove the cachePost steps by @myitcv in 6843415
  • internal/ci: bump default of cue version to v0.5.0-beta.5 by @myitcv in 3121a27
  • internal/ci: update base early git checks from alpha.cuelang.org by @myitcv in 4509e7f
  • internal/core/adt: allow required dynamic fields by @mpvl in c3138e3
  • internal/ci: skip test cache on protected branches by @myitcv in 21f494d
  • internal/core/adt: implement required fields. by @mpvl in 0b681f5
  • cue/ast: prepare for required fields by @mpvl in 1da0fd9
  • internal/core/adt: merge OptionalField and Field types by @mpvl in 1822d52
  • internal/ci: bump pinned version of Go for releases by @mvdan in e5cd9ac
  • internal/ci: use a group of cue commands for go:generate by @mvdan in d16b575
  • cmd/cue: remove fallback version code for Go 1.17 by @mvdan in e806bba
  • internal/ci: rerun trybot workflows post eviction by @myitcv in a632d16
  • internal/ci: tidy up use of curl for GitHub API calls by @myitcv in f4d0802
  • internal/ci: do not evict caches on push to ci/test by @myitcv in 254f0f1
  • internal/ci: evict workflow caches on a daily basis by @myitcv in ee81e77
  • internal/ci: bump to use ubuntu-22.04 as our linux machine by @myitcv in 4686700
  • internal/ci: use actions/cache/restore for non-protected branch by @myitcv in 38ee1c2
  • cue/load: don't read parent directories in tests by @mvdan in 9e014c3
  • internal/ci: reset git directory timestamps faster by @mvdan in c7fd893
  • internal/ci: fix up modified times for all directories by @mvdan in e31b8f7
  • internal/ci: run long tests on linux when testing CLs by @mvdan in daa4022
  • cmd/cue: remove go install long tests by @mvdan in fa1f369
  • internal/ci: restore git modified times after cloning by @mvdan in 829bd64
  • doc/tutorial/kubernetes: fix build breakage by @mpvl in b05585b
  • internal/core/adt: use ? in debug output by @mpvl in 5fe040a
  • internal/core/adt: optional field rewrite by @mpvl in 19bfdb9
  • internal/ci/gerrithub: update comment to be clearer by @mvdan in 4fed730
  • internal/core/adt: finalize earlier for arcs by @mpvl in c80a690
  • internal/core/adt: pass member type to insertField by @mpvl in 27b096c
  • internal/core/adt: remove duplicate statement by @mpvl in 383ff3e
  • internal/core/adt: export arcType and friends by @mpvl in 4f32fb4
  • internal/core/adt: revert fix for 2209 by @mpvl in c8e580e
  • cue/ast, cue/parser: parse function types by @4ad in 8f0fe77
  • cmd/cue: add CUE_DEBUG_PARSER_TRACE environment variable by @4ad in 34a27bb
  • internal/core/adt: fix possible infinte loop for API usage by @mpvl in 782cae0
  • internal/core/adt: fix regression in comparing to bottom by @mpvl in 9954cc2
  • internal/core/adt: remove unnecessary check by @mpvl in 1a0a81b
  • internal/core/adt: detect closed lists as fatal errors by @mpvl in 06fbefe
  • internal/core/adt: sharpen condition for scalar setting by @mpvl in 9b1f222
  • cmd/cue: respect --exclude for constants by @rogpeppe in b44e16d
  • cmd/cue: add test case for --exclude by @rogpeppe in 2fa4ee6
  • cue/context: support internal interpreters by @mpvl in 7617de2
  • internal/cuetxtar: configurable load.Config by @rogpeppe in 7485f58
  • cue/load/internal/...: copy pkgs from Go source by @rogpeppe in 5723470
  • cue/load: refactor loader by @rogpeppe in c28d75a
  • cue/load: move code before refactoring by @rogpeppe in 87b91c9
  • internal/ci: use simpler "go get" to pull a version through the proxy by @mvdan in eff0108
  • cue/stats: use int64 for stats counters by @mvdan in 7073554
  • cmd/cue: remove use of stderr directive by @mpvl in 7d89acd
  • doc/ref/spec.md: add required fields by @mpvl in 9a7c8fb
  • pkg/list: simply template for Ascending by @mpvl in 9dbb373
  • cue/testdata/benchmarks: add benchmark for sort by @mpvl in 9f538a6
  • cue/load: add initial module.cue schema by @rogpeppe in b2087b9
  • internal/ci: only run release workflow on main repo by @myitcv in ce37b63
  • cue/load: use cue package to interpret module.cue file by @rogpeppe in 1b6fb4e
  • cue/load: minor tweaks by @rogpeppe in d78f1a2
  • .github: clarify what we mean by "latest release" by @mvdan in 03e8f29
  • internal/ci: do not release "zero" releases in release workflow by @myitcv in 02e19c8
  • internal/ci: fix goreleaser in non-snapshot mode again by @mvdan in ae0d7ca
  • cmd/cue: include Go in the version command by @mvdan in 879f902
  • internal/ci: fix and test the release workflow on branches by @mvdan in 266bb32
  • cmd/cue: mention doc location for -l flag by @rogpeppe in 56caeaf
  • internal/core/adt: fix 2235 by @mpvl in 3c8f0ad
  • pkg/list: reimplement sort by @mpvl in 2e70ac7
  • cue/scanner: remove block comment scanning by @mpvl in 5d0a6f2
  • internal/core/adt: add tests for 2235 by @mpvl in 125e40b
  • cue/parser: remove last vestiges of : T by @mpvl in fd170da
  • all: remove support for :: by @mpvl in a6055ea
  • internal/encoding/{json|yaml}: disallow non-regular fields by @mpvl in 76e0be4
  • cmd/cue: add tests for issue 1926 by @mpvl in 9b573be

Don't miss a new cue release

NewReleases is sending notifications on new releases.