Home / Docs / Configure a package

[escape_budget] checked_per_module

Release v0.4.0Edition 0.1 and laterU7002U7003

What it does

Una proves the facts a program relies on before it runs, such as a shelf number being between 0 and 9. When a fact cannot be proved, as with a number a customer types, checked tests it while the program runs instead, and fails when it does not hold. That gives up a proof, so it is an escape, and checked_per_module is the escape budget: how many times each module of the package may use checked. The default is 0, so a package that wants run-time tests says so here, and reviewers see it.

Learn more: When no proof can decide: checked and opaque predicates.

una.tomltoml
[package]
name = "shop"
version = "0.1.0"
edition = "0.2"

[escape_budget]
checked_per_module = 1
src/shop.unauna
module shop

pub kind Shelf = Int in 0..9

pub kind ShelfError = | NoSuchShelf

pub shelf(n: Int) -> Shelf
  fails ShelfError
=
  checked(n, it >= 0 and it <= 9) else fail NoSuchShelf

Forms

toml
[escape_budget]
checked_per_module = <an integer of at least 0>

The default is 0, and a single file has the default.

Examples

A use beyond the budget is rejected, here with the default of 0:

una.tomltoml
[package]
name = "shop"
version = "0.1.0"
edition = "0.2"
src/shop.unauna
-- fails with U7003
module shop

pub kind Shelf = Int in 0..9

pub kind ShelfError = | NoSuchShelf

pub shelf(n: Int) -> Shelf
  fails ShelfError
=
  checked(n, it >= 0 and it <= 9) else fail NoSuchShelf

Edge cases

At least 0:

una.tomltoml
[package]
name = "shop"
version = "0.1.0"
edition = "0.2"

[escape_budget]
checked_per_module = -1
src/shop.unauna
-- fails with U7002
module shop

pub price(cents: Int) -> Int = cents

Further rules:

Diagnostics

Edition

The escape budget is the same in editions 0.1 and 0.2. From edition 0.4 it is written in the escapes section of ita.una, as checked per module <n> (see ita.una).

Normative source