Documentation

LeanPool.OrderMaintenance.Impl.Lang

M6: the core language #

A small language for the core's code, with two semantics:

Sim.lean proves once that the two agree, with the machine cost computed from the source. Each Level F function is then written in this language, and an agreement lemma shows that evalF computes what the Level F function computes.

All values are Nat. A record field is read as a number: Bool fields as 0/1 (with dead for alive, so that every default record reads 0), St as 0–3. A write that the encoding cannot represent (a Bool field set to 5, an index past the capacity) is a bug of the source program: evalF returns .bug, and the agreement lemmas show that it never happens.

Encodings of small types #

Encode a Boolean by zero or one.

Equations
Instances For
    theorem OrderMaintenance.Model.St.toN_ofN {v : Nat} (h : v ≤ 3) :
    (ofN v).toN = v

    Fields #

    Element fields accessible to the typed implementation language.

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

        Group fields accessible to the typed implementation language.

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

            Chunk fields accessible to the typed implementation language.

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

                Top-tree node fields accessible to the typed implementation language.

                • height : NF
                • livePar : NF
                • weight : NF
                • first : NF
                • last : NF
                • draining : NF
                • t1 : NF
                • t2 : NF
                • overflow : NF
                • dead : NF
                Instances For
                  @[instance_reducible]
                  Equations
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Plain arrays of numbers, extended on write (Array.setX).

                    • pqHead : AF
                    • pqNext : AF
                    • pqPrev : AF
                    • pqWhere : AF
                    • nbNext : AF
                    • nbPrev : AF
                    • lpar : AF
                    Instances For
                      @[instance_reducible]
                      Equations
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Scalars of the core.

                        • count : SF
                        • head : SF
                        • tail : SF
                        • firstGroup : SF
                        • firstChunk : SF
                        • notReady : SF
                        • fallbacks : SF
                        • pqHi : SF
                        • pqLo : SF
                        Instances For
                          @[instance_reducible]
                          Equations
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Record counts (read only; push extends them).

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

                                Parameters (read only).

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

                                    A numeric field selector across records, plain arrays and core scalars.

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

                                          Write a natural-number encoding into a element field.

                                          Equations
                                          Instances For

                                            Check that a numeric value is a valid encoding for this element field.

                                            Equations
                                            Instances For

                                              Write a natural-number encoding into a group field.

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

                                                Check that a numeric value is a valid encoding for this group field.

                                                Equations
                                                Instances For

                                                  Write a natural-number encoding into a chunk field.

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

                                                    Check that a numeric value is a valid encoding for this chunk field.

                                                    Equations
                                                    Instances For

                                                      Write a natural-number encoding into a top-tree node field.

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

                                                        Check that a numeric value is a valid encoding for this top-tree node field.

                                                        Equations
                                                        Instances For

                                                          Replace a plain numeric array in a core.

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

                                                            Write a natural-number encoding into a core scalar.

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

                                                              Check the Boolean range of the encoded readiness scalar.

                                                              Equations
                                                              Instances For

                                                                Append a default record to a selected record table.

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

                                                                  Lists, paths and the optional records #

                                                                  The lists of the core: per node (children, table, in-tables, sides), per chunk (cin), and the free-group stack. Each is seen as a list of pairs (view); the stack is stored reversed, so that its head is the last element.

                                                                  • children : LK
                                                                  • table : LK
                                                                  • inTab : LK
                                                                  • side : LK
                                                                  • cin : LK
                                                                  • freeG : LK
                                                                  Instances For
                                                                    @[instance_reducible]
                                                                    Equations
                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      Replace a selected core list from its pair-list representation.

                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For
                                                                        def OrderMaintenance.Impl.LK.stride (κlcap : LK → Nat) :
                                                                        LK → Nat

                                                                        The distance between consecutive records' lists in the machine array. The free-group stack has a single record, so its stride is 0 and the compiled code does not depend on its capacity.

                                                                        Equations
                                                                        Instances For

                                                                          The path row of chunk c. While the chunk list is being built, the row of the chunk being prepared holds prep.path (so that committing it costs nothing).

                                                                          Equations
                                                                          Instances For

                                                                            The optional records, read field by field (0 when absent).

                                                                            • prepOn : OF
                                                                            • prepChunk : OF
                                                                            • prepH : OF
                                                                            • prepBelow : OF
                                                                            • prepTag : OF
                                                                            • jobOn : OF
                                                                            • jobX : OF
                                                                            • jobY : OF
                                                                            • jobZ : OF
                                                                            • jobT : OF
                                                                            • jobA : OF
                                                                            • jobB : OF
                                                                            • jobC : OF
                                                                            • jobD : OF
                                                                            Instances For
                                                                              @[instance_reducible]
                                                                              Equations
                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For

                                                                                Read a numeric field of the optional preparation or reservation-job state.

                                                                                Equations
                                                                                Instances For

                                                                                  The capacities of the machine arrays: records of each table, plain arrays, lists (records and elements per record), and the width of a path row.

                                                                                  • tbl : Tbl → Nat

                                                                                    Allocated capacity of each record table.

                                                                                  • arr : AF → Nat

                                                                                    Allocated capacity of each plain numeric array.

                                                                                  • lrec : LK → Nat

                                                                                    Number of record rows available for each list kind.

                                                                                  • lcap : LK → Nat

                                                                                    Maximum length of a row for each list kind.

                                                                                  • pw : Nat

                                                                                    Allocated width of one ancestor-path row.

                                                                                  Instances For

                                                                                    Write field f of record i; none if the encoding cannot represent the result.

                                                                                    Equations
                                                                                    Instances For

                                                                                      Replace list k of record i by l; none if not representable.

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

                                                                                        The path row of c reads 0 everywhere.

                                                                                        Equations
                                                                                        Instances For

                                                                                          c is not the chunk being prepared.

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

                                                                                            Syntax #

                                                                                            Typed expressions reading core records, list rows, parameters and locals.

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

                                                                                                Typed core statements with explicit failures, bounded loops and procedure calls.

                                                                                                • skip : Stm
                                                                                                • assign (x : Machine.Reg) (e : Exp) : Stm
                                                                                                • wr (f : Fld) (i e : Exp) : Stm
                                                                                                • push (t : Tbl) (x : Machine.Reg) : Stm

                                                                                                  Append a default record to table t; its index goes to x.

                                                                                                • seq (s t : Stm) : Stm
                                                                                                • ite (c : Exp) (s t : Stm) : Stm
                                                                                                • loop (x : Machine.Reg) (n : Exp) (b : Stm) : Stm
                                                                                                • call (name : String) (params : List Machine.Reg) (body : Stm) (rets : List Machine.Reg) (args : List Exp) (dsts : List Machine.Reg) : Stm
                                                                                                • fail : Stm

                                                                                                  A failed guard.

                                                                                                • bug : Stm

                                                                                                  A state the source program never reaches (an assertion of Level F).

                                                                                                • catch (s h : Stm) : Stm
                                                                                                • lwr (k : LK) (snd : Bool) (i j e : Exp) : Stm

                                                                                                  Set component snd of element j of list k of record i.

                                                                                                • lgrow (k : LK) (i a b : Exp) : Stm

                                                                                                  Append the element (a, b) to list k of record i.

                                                                                                • lshrink (k : LK) (i : Exp) : Stm

                                                                                                  Drop the last element of list k of record i.

                                                                                                • lclear (k : LK) (i : Exp) : Stm
                                                                                                • pwr (c j e : Exp) : Stm

                                                                                                  Set level j of the path of chunk c.

                                                                                                • rowReset (c : Exp) : Stm

                                                                                                  Give the fresh chunk c the path [NIL, …, NIL] (its row already reads 0).

                                                                                                • prepInit (c b : Exp) : Stm

                                                                                                  Start building the chain above chunk c (with below = b).

                                                                                                • prepSet (h b t : Exp) : Stm
                                                                                                • prepPath (j e : Exp) : Stm

                                                                                                  Set level j of the path being built.

                                                                                                • prepCommit : Stm

                                                                                                  The chain is built: its path becomes the chunk's path.

                                                                                                • jobSet (x y z t a b c d : Exp) : Stm
                                                                                                • jobClear : Stm
                                                                                                • pcSet (t a b c d : Exp) : Stm
                                                                                                Instances For
                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For

                                                                                                    Semantics on Level F #

                                                                                                    @[reducible, inline]

                                                                                                    Natural-number values assigned to local register names.

                                                                                                    Equations
                                                                                                    Instances For

                                                                                                      Evaluate a list of arguments, failing when any argument is invalid.

                                                                                                      Equations
                                                                                                      Instances For

                                                                                                        Sum the static machine evaluation costs of a list of expressions.

                                                                                                        Equations
                                                                                                        Instances For

                                                                                                          An outcome with the number of machine steps taken.

                                                                                                          Instances For

                                                                                                            Continue a normal typed outcome, accumulating cost and propagating abnormal outcomes.

                                                                                                            Equations
                                                                                                            Instances For

                                                                                                              The steps of push: read the count, write it back plus one.

                                                                                                              Equations
                                                                                                              Instances For

                                                                                                                Execute a bounded typed loop with its index local and accumulated instruction cost.

                                                                                                                Equations
                                                                                                                Instances For

                                                                                                                  Execute typed core statements with exact charged RAM cost and explicit abnormal outcomes.

                                                                                                                  Equations
                                                                                                                  Instances For