Home / Docs / Una for agents
Repairs
From spec/13 §3.
For U5001 and U5002 the compiler proposes, when applicable, in this order:
| Candidate | escape_cost |
|---|---|
| Strengthen a parameter or field type to a refined kind that implies the goal | 0 |
Add a requires clause equal to the missing hypothesis (only for non-pub functions or with a note that callers change) |
0 |
Add a guard (if or when arm) that handles the failing case |
0 |
Replace the value with checked(value, goal) else fail <Variant> |
1 |
By kind (ADR 0033): a refuted or unknown refinement or precondition proposes, in order, a stronger parameter type when the value is a parameter, a requires clause for a private function, a guard, and checked; a postcondition proposes a guard or a changed ensures clause; a division a guard; an exhaustive an else arm. These repairs have no mechanical edit (edit is null).
A refinement obligation of a function value flowing into a function type (spec/12 §3, ADR 0037) proposes only a stronger type at the position of a function type: for a parameter, of the expected function type ("strengthen parameter 1 of fn(Int) -> Int to a refined kind that implies x > 0"); for the result, of the value's function type ("strengthen the result of fn(Int) -> Int to a refined kind that implies result > 0"). No requires clause, guard or checked is proposed, since none of them reaches a value that exists only when the function is called. The result obligation of a lambda, whose result type is not written, proposes a guard in the lambda's body.
(ADR 0095.) Escapes rank last. A repair is an escape when it takes one of these routes: checked, where a runtime test replaces a static proof (spec/06 §6); escape_budget, which raises [escape_budget] checked_per_module; or trusted, which declares or lists a trusted module or declassifies through a policy (spec/07 §5, §6). An escape has escape_cost 1 and carries the escape key (§1); every other repair has escape_cost 0. A repair is one route: it never joins a fix that keeps the guarantee and an escape. Every escape comes after every repair that keeps the guarantee, so when one exists, rank 1 is never an escape. A message states the problem; the routes out of it, escapes included, are repairs. In particular:
| Code | Repairs that keep the guarantee | Escape, last |
|---|---|---|
| U7003 | state the fact in a refined type or a requires clause and remove the checked; handle the failing values with a guard and remove the checked |
raise checked_per_module |
| U2016 | in code, test with a function, not a predicate, with the predicate's body, when that body calls no other opaque predicate and the predicate belongs to the package | checked |
| U4003 | send only data, or interpolate only fields, at the accepted label, or send the value to an operation that accepts its label | declassify through a policy |
| U4004 | move the policy and its via function into a module that is already trusted, when one exists |
declare this module trusted in both places |
| U7005 | remove trusted from the header, or the entry from [trusted] modules; when the module declares a policy, the repair says that its policies are then U4004 |
complete the declaration in the other place |
(v0.3, ADR 0094 rule 7.) A labeled answer is named. A U4001, U4002 or U4003 whose reported label the answer of an operation explains, where the operation's binding gives it a label (spec/05 §3 rule 6), names that binding and operation. The message ends with "; this value carries the answer of @service_files.owner, labeled internal[Service]" (with "this argument", "this item", "this key" or "this priority" for the value it reports at, "this flow" at a parameter of a function type, where the answer would flow into the function value's parameter, or "the condition" when the flow is through the program counter), the call is a related location unless the diagnostic is already there, and the first repair names them with the routes that keep the guarantee: read the operation through a binding whose answers are within the label allowed, or send the value, or run the code, where the answer's label may go. When no repair of the diagnostic is an escape, it gains one, last: release the answer through a policy of a trusted module. The answer named is the first, in source order within the declaration, whose label is within the label reported and not within the label allowed; every answer a flow carries meets the first condition, so the answer that caused the flow is never left out, and a flow that no answer explains, such as one from a secret parameter beside an internal[Service] answer, names none. The choice is a heuristic over the declaration's source order, not data flow: a flow from another value whose label is at or above the answer's, such as a parameter labeled internal[Service] beside an internal[Service] answer, may name that answer although the answer does not reach the flow. It affects the wording only, never a code, a location or a verdict. Covered are the flows into declared types, operation arguments, branch joins and implicit results; failures, calls, policies and effectful parameters under the program counter, including a function value labeled above public and a parameter run under a labeled list; sinks; updates of editable bindings and of collections; dense shapes; stop when; and first_where over a labeled result. A flow through a timing label (spec/27 §5) and the [drive], run grants and limiter flows of spec/27 name none, since their label is a timing label, not an answer's. The codes and the locations do not change. (v0.4, S-46.) Whether acquire of std.limit failed is named the same way, as "whether @gate.acquire failed, labeled internal, the label Limited carries" (spec/27 §10 rule 4). No binding lowers that label, so the first repair names only the routes that keep the guarantee: under the condition, perform only operations that accept internal, or decide without branching on it; for a value, send it only where internal data may go. The escape, last, releases whether the call failed through a policy of a trusted module.
(ADR 0097.) Widenings rank after the repairs that keep authority. A repair widens when it adds operations to a uses clause or declares one (authority), makes a declaration pub (visibility), or grants a host capability's operations in [run] grants or with --grant (grant). A widening is fully checked, so it is not an escape and keeps escape_cost 0; it carries the widens key (§1), and output ranks it after every repair of equal escape_cost that keeps authority. una fix never applies a widening (§5, ADR 0084). A message states the problem, and the routes out of it are repairs:
| Code | Repairs that keep authority | Widening, after them |
|---|---|---|
| U3002 at an operation | use another binding in scope that permits the operation | add the operation to the uses clause |
| U3002 at a call | rebind with with @need = @other, when it applies |
add the operations to the uses clause |
| U3001, U3003, U3004 | none | declare the binding with uses |
| U1004 | none | declare the declaration pub |
| U3012, host capability | none | grant the operations in [run] grants |
| U3012, other capability | install a handler with with inside main |
none |
(v0.3, ADR 0093 rule 6.) Repairs never widen authority first. In edition 0.3 and later:
- U3020. When the boundary's ceiling allows every operation that the callee's requirement
@x: C[ops]declares, and the caller holds a binding@yofCthat permits them (a binding whose capability and operations are declared, not a handler), the first repair is the grantwith @x = @y[ops], narrowed to those operations, with@ythe binding named@xwhen it qualifies, otherwise the only binding that qualifies. When several bindings other than@xqualify, which one the boundary receives is a decision about trust: the first repair is advice that lists them, with no edit. The grant carries an edit only at a call that is the whole expression of its statement orlet, when the statement does not bind@xalready; when the statement has awith, the grant is added to it and resolves outside it, as the right-hand sides of awithdo, so the bindings that qualify are counted there, and a header binding that the statement'swithrebinds still counts as itself. It is advice at a function value and at a handler's installation, where@yis resolved below the installingwith, as the right-hand sides of awithare, so it is never a binding of thatwith. When no binding qualifies, the first repair is advice to grant one, or a handler whose ownuseslie within the ceiling. When the ceiling withholds an operation of the requirement, no grant is offered at any rank: the first repair is advice for a handler whose ownuseslie within the ceiling, and it names the operations the ceiling withholds. - U3021. The first repair is advice that narrows the grant to the ceiling: to what the callee declares,
with @x = @y[ops]or a handler, when that lies within the ceiling. When the callee declares more than the ceiling allows, the repair says that no grant keeps both. No repair raises a ceiling, and none editsuna.toml. - U3001 and U3002. First the routes that keep authority: another binding that permits the operation, or a rebinding of a binding the caller holds, written
with @need = @other[ops]when@otherpermits more than the callee needs, which is also the first repair of a U3001 at a call whose requirement another binding of the same capability permits. The rebinding carries an edit only when exactly one binding the caller holds qualifies, counted where the rebinding resolves: outside the statement's ownwith, if it has one, so a header binding thatwithrebinds still counts as itself; when several do, it is advice that lists them. Then the widening of a private header. The widening of apubheader, an entry point included (spec/04 §8), comes last, and its description says that it is an authority change of the public header.
Editions 0.1 and 0.2 keep their repairs. These repairs change no program's meaning.
Other diagnostics MAY include repairs (for example, a missing label with its mechanical edit). una check and the other commands never apply repairs. (v0.2, ADR 0084.) una fix applies mechanical ones on request (§5). A repair whose edit widens authority or visibility, by adding operations to a uses clause, declaring a uses clause or making a declaration pub, is marked so where it is built, and una fix never applies it.
(ADR 0096.) A syntax error (U0001, U0101) whose source has the shape of another language's form stays an error, since Una has one syntax (charter P4). Its first repair names Una's form, and carries an exact edit when rewriting is exact. Exact means four things: the edit changes only the declaration the error is reported in; once it is applied, the file has no syntax error in or before the edited range; the result is the stated reading in Una's form, token for token; and the edit is deterministic. The shapes and the condition of each edit are the table of ADR 0096 rule 3. Among them are an if … then … else wrapped across lines, = at the end of a function header, a name that starts with _, a when with its arms on one line, and a guard without else. A rename takes a name that is visible nowhere it would be written (ADR 0096 rule 3a).