Home / Learn

Release v0.4.0

19 Editions

Page 1 of 11

A language that grows has to add keywords and tighten rules, and a program written last year must still mean what it meant. Una does this with editions: each package names the edition of the language it is written in, and every release of una keeps each stable edition, whose rules are final, exactly as it was. This chapter shows what an edition is, what editions 0.2 and 0.3 add, and how to move a package from one edition to the next, letting the checker and una fix find what has to change.

What you'll build

A shelf-label printer for a store, on edition 0.3. It reads a stock export, the list of stock lines that another system of the store writes out, prints a label for every line with stock, and has a dry run that counts the labels without printing any. The dry run is not a convention: the checker proves that no label is printed when dry_run is true. main makes a dry run, then a real one:

Output
dry run: 2 labels
[LAMP-01 | 4 on hand]
[SHELF-03 | 12 on hand]
printed 2 labels

You will learn to:

  • name a package's edition in una.toml, and know what stays fixed for that edition;
  • recognize what edition 0.2 adds, and the diagnostics a construct of a later edition gives;
  • use edition 0.3, a preview, and its stricter rules;
  • move a package to a later edition with una check and una fix;
  • move a package to edition 0.4, a preview, whose manifest is ita.una, with una migrate;
  • lock a function's authority in una.toml, so that a change to it shows up in review.

Download this chapter's packages: each step is a package under steps/, and the chapter's program is day-to-day/; run una check . and una run . in one.

Why it works this way

Languages that grow without editions face a choice. Either a new keyword, a word the language keeps for itself, breaks every program that used the word as a name, or the language never adds one. A rule that becomes stricter, such as one that rejects code that can never run, breaks programs that passed yesterday, and the team that maintains them finds out on the day a compiler is upgraded.

Una separates the two things a release changes:

  1. The compiler improves for every edition. A new release fixes bugs, adds explanations and makes the tools better, for every package.
  2. The language changes only in a new edition. New keywords, new constructs and stricter rules come with an edition, and a package gets them only when its manifest names that edition.
  3. Editions are cumulative. Edition 0.3 has every construct and rule of 0.2, and 0.2 has every construct of 0.1. Moving a package forward never removes a construct. It can reject code that a stricter rule no longer allows or a name that became a keyword, and a few prelude functions and reports change too (section 19.2). Edition 0.3 also accepts some code that 0.2 rejects (section 19.3).

So upgrading una never changes what a stable edition accepts or rejects, except to fix a soundness or security error: a bug that let the checker accept a program it should have rejected. Moving a package to a new edition is a separate step, a change to one line of una.toml, which you make when you are ready and review like any other change.

Key idea

A package's edition is a line of its manifest: una.toml, or ita.una from edition 0.4. Upgrading una keeps the meaning of every stable edition, and a later edition adds constructs and, with few exceptions, tightens rules.

View the Markdown

Next:19.1 An edition is part of the package