Home / Learn / 11 Packages and modules
Release v0.4.0Edition 0.2
11.8 Recap and reference
Page 9 of 9
11.8.1 For agents
A diagnostic about an import carries the place of the declaration as a related span, and its repair. For Private stays private:
json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U1004","severity":"error","domain":"names","message":"function `digits` is private to module `store.money`","primary":{"file":"src/store/app.una","start":{"line":4,"col":21},"end":{"line":4,"col":27}},"related":[{"file":"src/store/money.una","start":{"line":10,"col":1},"end":{"line":10,"col":7},"message":"declared here without `pub`"}],"repairs":[{"rank":1,"escape_cost":0,"widens":{"kind":"visibility","cost":"every module may then call it: check that it belongs to the module's interface"},"description":"declare `digits` with `pub`","edit":{"file":"src/store/money.una","start":{"line":10,"col":1},"end":{"line":10,"col":1},"replacement":"pub "}}],"explain":"una explain U1004"}],"fixable":0}The repair has escape_cost 0, but widens names the visibility it would open, so una fix skips it. It gives the reason widens authority for every repair that widens what code may reach, visibility included:
Terminal
$ una fix --dry-run .
skipped src/store/money.una:10:1 U1004 declare `digits` with `pub`: widens authorityThe compact rule: one module per file, named by its path; take each declaration you use with a named import; make a declaration pub only on purpose, with its whole header written; keep the imports free of cycles and sorted.
11.8.2 Recap
- One file is one module, and its header names its path under
src/:src/store/money.unaismodule store.money. - Declarations are private by default. Mark
pubonly what other modules need, with a doc comment and its whole header written. - Import each declaration you use by name. A sum kind brings its variants, and a record its constructor and fields.
- Keep the imports a graph with no cycle, and let
una fmtkeep them sorted. una.tomlhas a fixed set of tables and keys; an unknown one is U7002. A package imports only its own modules,std.hostandstd.testing.verification.lockpins the solver, so every machine gets the same result: copy it, do not edit it.- Keep each module's examples in the module;
una test .runs those of every module, after one check of the whole package.
11.8.3 Reference
- Construct and configuration pages: modules and imports,
kind,where,example, canonical form,una.toml,[package] name,[package] version,[package] edition,[run] entry,[run] grants,[labels] categories,[trusted] modules,[escape_budget] checked_per_module,verification.lock - Diagnostics: U1001, U1002, U1003, U1004, U1005, U1008, U1009, U3012, U5001, U5002, U5003, U7001, U7002, U7004
- Specification: diagnostics, the command line and project files, grammar, static semantics, functions and contracts, canonical form, verification
Next:12 Capabilities