Documentation

Strata.Transform.Passive.Program

Vocabulary of the WP and SSA phases (language-generic) #

The WP phase (WP/WP.lean) turns a loop-free program (structured, without loops or calls, with deterministic guards) into a guarded program, and the SSA phase (SSA/SSA.lean) turns a guarded program into an obligation program (init/assume/assert/cover commands combined by nondeterministic ites, as consumed by obligation extraction), generic over the expression language P (see WPOps, WPLang). This file holds what both phases, their composition and their correctness statements share:

Key definitions: RE, Item, nest, LogEntry, substObl, freshName, AvoidSet, freshIn, FreshSt, inputAvoid.

Names, renamings, expressions #

@[reducible, inline]

A renaming: source variable → current SSA name (first binding wins; unbound variables are their own current name).

Equations
Instances For
    def Imperative.WP.Ren.get {P : PureExpr} [BEq P.Ident] (ρ : Ren P) (x : P.Ident) :

    The current name of x under ρ.

    Equations
    Instances For
      def Imperative.WP.Ren.set {P : PureExpr} (ρ : Ren P) (x y : P.Ident) :
      Ren P

      Rename x to y, shadowing earlier bindings of x.

      Equations
      Instances For
        @[reducible, inline]

        Source-variable types.

        Equations
        Instances For
          def Imperative.WP.Tys.get? {P : PureExpr} [BEq P.Ident] (tys : Tys P) (x : P.Ident) :

          The type recorded for x, if any (first binding wins).

          Equations
          Instances For

            Free variables of a continuation (a stack of statement lists).

            Equations
            Instances For

              A branch is local when it consists only of assert/cover commands: skipping it on the continuation's path skips no evaluation, no assumption and no assignment, so it can become a side branch of its own.

              Equations
              Instances For

                Reachability conditions and the flat output #

                inductive Imperative.WP.RE (P : PureExpr) :

                A reachability condition: top (reached whenever the enclosing path is), a Boolean name, the negation ¬g of a guard name, or q ∧ ¬g for a Boolean name q and a guard name g. Literals and negations are kept inline.

                Instances For
                  @[instance_reducible]
                  Equations
                  def Imperative.WP.RE.ite {P : PureExpr} [HasBool P] [HasFvar P] [WPOps P] (r : RE P) (t e : P.Expr) :

                  ite(r, t, e) with the condition folded: t for top, ite(g, e, t) for ¬g, ite(q, ite(g, e, t), e) for q ∧ ¬g.

                  Equations
                  Instances For

                    The label of generated reachability assumptions.

                    Equations
                    Instances For

                      One element of the flat translation.

                      • plain {P : PureExpr} (s : BigStep.PStmt P) : Item P

                        A straight-line statement of the obligation program.

                      • obls {P : PureExpr} (reach : Option (RE P)) (cs : BigStep.PStmts P) : Item P

                        A side branch: the consecutive obligations cs under the reachability reach.

                      • branch {P : PureExpr} (t e : List (Item P)) : Item P

                        A real branch: the flat translations t and e of the two arms of an ite after which no obligation follows. It ends the main path.

                      Instances For

                        Does the item leave the main path (a side branch or a real branch)?

                        Equations
                        Instances For

                          Turn the flat translation into the obligation program.

                          Equations
                          Instances For

                            nest (it :: rest), given nr = nest rest: a straight-line statement is kept when a branching item follows; a side branch becomes the then branch of a nondeterministic ite whose else branch is nr, and is inline when no branching item follows; a real branch becomes a nondeterministic ite of its nested arms, or the one nested arm that is not empty, and ends the list.

                            Equations
                            Instances For

                              nest of an item list, with whether one of its items leaves the main path (Item.isBranching), in one pass over the list.

                              Equations
                              Instances For

                                nestCons it rest nr, given b, whether an item of rest leaves the main path.

                                Equations
                                Instances For

                                  nest computed in one pass over the list (nestB).

                                  Equations
                                  Instances For
                                    @[csimp]

                                    The compiled code of nest is nestFast, linear in the number of items where nest rescans the rest of the list at each item.

                                    The choice record #

                                    An entry of the record of the obligations the SSA phase emits.

                                    • obl {P : PureExpr} (label : String) (sub : List (P.Ident × P.Ident × Option P.Ty)) : LogEntry P

                                      An obligation with label label, emitted on the SSA names: sub maps each renamed free variable x of its loop-free condition to its current name y and the type annotation ty of the emitted variable, so the emitted condition is the loop-free one with each such x replaced by y : ty (substObl), and the loop-free condition is the emitted one with sub inverted.

                                    Instances For
                                      def Imperative.WP.substObl {P : PureExpr} [HasFvar P] [HasSubstFvar P] (sub : List (P.Ident × P.Ident × Option P.Ty)) (e : P.Expr) :

                                      The condition an obligation of the obligation program has, for the loop-free condition e and the substitution sub of its choice-record entry: each x with (x, y, ty) in sub replaced by the variable y annotated ty.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Fresh names #

                                        The name the pass introduces with base b and counter n: b@n.

                                        Equations
                                        Instances For

                                          The label of generated join assumptions.

                                          Equations
                                          Instances For
                                            def Imperative.WP.mkInit {P : PureExpr} (x : P.Ident) (ty : P.Ty) (e : ExprOrNondet P) :

                                            The statement init x : ty := e.

                                            Equations
                                            Instances For
                                              @[reducible, inline]

                                              A hash set of identifiers.

                                              Equations
                                              Instances For

                                                The hash set of the identifiers of a list.

                                                Equations
                                                Instances For

                                                  The names fresh names avoid, in two levels: the global names glob (built once per program and shared by its procedures) and the identifiers loc of one procedure.

                                                  Instances For

                                                    The avoided names, as a list.

                                                    Equations
                                                    Instances For

                                                      The first counter from n (within fuel tries) whose name with base b is not avoided.

                                                      Equations
                                                      Instances For

                                                        A fresh name with base b from counter n: freshName b k for the least k ≥ n whose name is not avoided, and the counter advanced past it.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          The base of a name: the name without one trailing @digits (the counter of a fresh name).

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            The initial state of the WP and SSA phases: fresh-name counter, avoided names, types of the free variables.

                                                            Instances For

                                                              The names a phase avoids for its input ss with free-variable types tys: the names of G (the names of the enclosing program), the identifiers of ss and the free variables.

                                                              Equations
                                                              Instances For