Home / Docs / Una for agents

Repairs

Release v0.4.0

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:

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).