The argument-swapping front end #
A swappable operation (Swap) has two arguments of one sort and a semi-inverse that solves the
first; in the flow signature, add. A program that adds a + b where b is to be consumed is
not typed as written; swapArgs rewrites it to add(b, a).
The choice is made by forward inference. Every line contributes its forward form, its solved
form if it has a semi-inverse, and, for a swappable o(a, b), the swapped solved form
b ← (c, a). Starting from the weights and the returned variables, an equation fires when its
reads are known and its results unknown, until nothing fires (fwdKnown). The pass swaps
exactly the lines whose swapped form fired. The swap preserves the meaning for a model where
the swappable operations commute (FrontSem), and if any swap of the program is typed, the
one chosen here is (FrontComplete).
The swappable operations of a signature: two arguments of one sort, and a semi-inverse that solves the first.
Instances
How many leading arguments the semi-inverse of l solves, if there is one.
Equations
- RoleFlow.kOf l = Option.map (fun (x : RoleFlow.SemiInv Sg.Op l.as l.bs) => x.k) (Sg.inv l.op)
Instances For
The solved form of the line l, numbered i, at scope n.
Equations
Instances For
The swapped solved form: a swappable o(a, b) solved for b.
Equations
Instances For
The equations of the line l: forward, solved, and swapped solved.
Equations
- RoleFlow.lineEqns i n l = { binds := l.ys n, reads := l.args, line := i, swap := false } :: RoleFlow.solvedEqns i n l ++ RoleFlow.swappedEqns i n l
Instances For
The equations of the lines at scope n, numbered from i.
Equations
- RoleFlow.eqns x✝¹ x✝ [] = []
- RoleFlow.eqns x✝¹ x✝ (l :: ls) = RoleFlow.lineEqns x✝¹ x✝ l ++ RoleFlow.eqns (x✝¹ + 1) (x✝ + l.bs.length) ls
Instances For
Swap the arguments of l if it is swappable and s holds.
Equations
Instances For
Swap the lines whose number (from i) satisfies sw.
Equations
- RoleFlow.swapLines sw x✝ [] = []
- RoleFlow.swapLines sw x✝ (l :: ls) = RoleFlow.swapIf (sw x✝) l :: RoleFlow.swapLines sw (x✝ + 1) ls
Instances For
The lines whose swapped form fired.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The front end: swap the arguments of the lines whose swapped solved form fired.
Equations
- RoleFlow.swapArgs P = { wts := P.wts, ins := P.ins, outs := P.outs, lines := RoleFlow.swapLines (RoleFlow.swapSet P).contains 0 P.lines, ret := P.ret }