lean2js

Lean2Js.HelperAgree

source

Imports 2

The helper table the model assumes, proved against the source that ships #

The model of the generated code assumes a table of runtime helpers, Js.helper. What that table says each helper answers is proved here against what the shipped source computes, so the hand-written JavaScript stops being taken on trust.

Four rows ask for something of their arguments, and helperArgsOk is where all four are written down. Three are the model being more careful than the helper — __i53div and __str re-check the Int53 range the type has already given, and __ddelete is stated on the dictionaries a Map can actually hold. The fourth, __eq, is a real divergence: see eqShape.

Conversion #

theorem

Lean2Js.HelperSem.ofJsList_eq

source
Used by
    theorem

    Lean2Js.HelperSem.ofJsFields_eq

    source
    Used by
      theorem

      Lean2Js.HelperSem.ofJs_arr

      source
      @[simp]
      Used by
        theorem

        Lean2Js.HelperSem.ofJs_obj

        source
        @[simp]
        Used by
          theorem

          Lean2Js.HelperSem.ofJs_dict

          source
          @[simp]
          Used by
            theorem

            Lean2Js.HelperSem.ofJs_fn

            source
            @[simp]
            Used by
              theorem

              Lean2Js.HelperSem.ofRes_fail

              source
              @[simp]
              Used by

                Entry lists #

                theorem

                Lean2Js.HelperSem.find?_ofJs

                source
                (es : List (String × Js.JsValue)) (k : String) :
                List.find? (fun (x : String × Val) => x.fst == k) (List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es) = Option.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) (List.find? (fun (x : String × Js.JsValue) => x.fst == k) es)
                Used by
                  theorem

                  Lean2Js.HelperSem.any_ofJs

                  source
                  (es : List (String × Js.JsValue)) (k : String) :
                  ((List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es).any fun (x : String × Val) => x.fst == k) = es.any fun (x : String × Js.JsValue) => x.fst == k
                  Used by
                    theorem

                    Lean2Js.HelperSem.any_eq_find?

                    source
                    (es : List (String × Js.JsValue)) (k : String) :
                    (es.any fun (x : String × Js.JsValue) => x.fst == k) = (List.find? (fun (x : String × Js.JsValue) => x.fst == k) es).isSome
                    Used by
                      theorem

                      Lean2Js.HelperSem.filter_ofJs

                      source
                      (es : List (String × Js.JsValue)) (k : String) :
                      List.filter (fun (x : String × Val) => x.fst != k) (List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es) = List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) (List.filter (fun (x : String × Js.JsValue) => x.fst != k) es)
                      Used by
                        theorem

                        Lean2Js.HelperSem.keys_ofJs

                        source
                        (es : List (String × Js.JsValue)) :
                        List.map (fun (x : String × Val) => x.fst) (List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es) = List.map (fun (x : String × Js.JsValue) => x.fst) es
                        Used by
                          theorem

                          Lean2Js.HelperSem.mapSet_ofJs

                          source
                          (es : List (String × Js.JsValue)) (k : String) (v : Js.JsValue) :
                          mapSet (List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es) k (ofJs v) = List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) (Js.Runtime.mapSet es k v)
                          Used by
                            theorem

                            Lean2Js.HelperSem.lookupV_ofJs

                            source
                            {es : List (String × Js.JsValue)} {k : String} {v : Js.JsValue} (h : Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == k) es) = some v) :
                            lookupV (List.map (fun (e : String × Js.JsValue) => (e.fst, ofJs e.snd)) es) k = ofJs v
                            Used by

                              Arithmetic #

                              >>> 0 reads a product's residue modulo 2^32, and truncating either factor to int32 first leaves that residue alone, so Math.imul is the multiplication the model does.

                              theorem

                              Lean2Js.HelperSem.u32_emod

                              source
                              Used by
                                theorem

                                Lean2Js.HelperSem.u32_congr

                                source
                                Used by
                                  theorem

                                  Lean2Js.HelperSem.toInt32_emod

                                  source
                                  Used by
                                    theorem

                                    Lean2Js.HelperSem.u32_imul

                                    source
                                    (a b : Int) :
                                    Used by
                                      theorem

                                      Lean2Js.HelperSem.tdiv_mem_i53

                                      source

                                      Truncated division never leaves the Int53 range the numerator was already in, which is why __i53div can return without the range check the model still writes.

                                      Used by

                                        Numbers #

                                        theorem

                                        Lean2Js.HelperSem.agree_i53

                                        source
                                        (ext : Ext) (a : Int) (f : Nat) :
                                        callDef ext (f + 8) "__i53" [ofJs (Js.JsValue.num a)] = ofRes (Js.Runtime.i53 a)
                                        Used by
                                          theorem

                                          Lean2Js.HelperSem.agree_i53div

                                          source
                                          (ext : Ext) (a b : Int) (f : Nat) (h : Js.Runtime.safeMin ≤ a) (h' : a ≤ Js.Runtime.safeMax) :
                                          Used by
                                            theorem

                                            Lean2Js.HelperSem.agree_i53mod

                                            source
                                            (ext : Ext) (a b : Int) (f : Nat) :
                                            Used by
                                              theorem

                                              Lean2Js.HelperSem.agree_u32mul

                                              source
                                              (ext : Ext) (a b : Int) (f : Nat) :
                                              Used by
                                                theorem

                                                Lean2Js.HelperSem.agree_u32div

                                                source
                                                (ext : Ext) (a b : Int) (f : Nat) :
                                                Used by
                                                  theorem

                                                  Lean2Js.HelperSem.agree_u32mod

                                                  source
                                                  (ext : Ext) (a b : Int) (f : Nat) :
                                                  Used by
                                                    theorem

                                                    Lean2Js.HelperSem.agree_bigdiv

                                                    source
                                                    (ext : Ext) (a b : Int) (f : Nat) :
                                                    Used by
                                                      theorem

                                                      Lean2Js.HelperSem.agree_bigmod

                                                      source
                                                      (ext : Ext) (a b : Int) (f : Nat) :
                                                      Used by
                                                        theorem

                                                        Lean2Js.HelperSem.agree_abs_num

                                                        source
                                                        (ext : Ext) (a : Int) (f : Nat) :
                                                        callDef ext (f + 5) "__abs" [ofJs (Js.JsValue.num a)] = ofRes (Except.ok (Js.JsValue.num (if a < 0 then -a else a)))
                                                        Used by
                                                          theorem

                                                          Lean2Js.HelperSem.agree_abs_big

                                                          source
                                                          (ext : Ext) (a : Int) (f : Nat) :
                                                          Used by
                                                            theorem

                                                            Lean2Js.HelperSem.agree_min_num

                                                            source
                                                            (ext : Ext) (a b : Int) (f : Nat) :
                                                            Used by
                                                              theorem

                                                              Lean2Js.HelperSem.agree_min_big

                                                              source
                                                              (ext : Ext) (a b : Int) (f : Nat) :
                                                              Used by
                                                                theorem

                                                                Lean2Js.HelperSem.agree_max_num

                                                                source
                                                                (ext : Ext) (a b : Int) (f : Nat) :
                                                                Used by
                                                                  theorem

                                                                  Lean2Js.HelperSem.agree_max_big

                                                                  source
                                                                  (ext : Ext) (a b : Int) (f : Nat) :
                                                                  Used by

                                                                    Arrays #

                                                                    theorem

                                                                    Lean2Js.HelperSem.agree_at

                                                                    source
                                                                    (ext : Ext) (xs : List Js.JsValue) (i : Int) (f : Nat) :
                                                                    Used by
                                                                      theorem

                                                                      Lean2Js.HelperSem.agree_aslice

                                                                      source
                                                                      (ext : Ext) (xs : List Js.JsValue) (lo hi : Int) (f : Nat) :
                                                                      Used by
                                                                        theorem

                                                                        Lean2Js.HelperSem.agree_aconcat

                                                                        source
                                                                        (ext : Ext) (a b : List Js.JsValue) (f : Nat) :
                                                                        Used by
                                                                          theorem

                                                                          Lean2Js.HelperSem.agree_areverse

                                                                          source
                                                                          (ext : Ext) (xs : List Js.JsValue) (f : Nat) :
                                                                          callDef ext (f + (xs.length + 9)) "__areverse" [ofJs (Js.JsValue.arr xs)] = ofRes (Except.ok (Js.JsValue.arr xs.reverse))
                                                                          Used by
                                                                            theorem

                                                                            Lean2Js.HelperSem.agree_range

                                                                            source
                                                                            (ext : Ext) (n : Int) (f : Nat) :
                                                                            Used by

                                                                              Dictionaries #

                                                                              theorem

                                                                              Lean2Js.HelperSem.agree_dhas

                                                                              source
                                                                              (ext : Ext) (es : List (String × Js.JsValue)) (k : String) (f : Nat) :
                                                                              Used by
                                                                                theorem

                                                                                Lean2Js.HelperSem.agree_dkeys

                                                                                source
                                                                                (ext : Ext) (es : List (String × Js.JsValue)) (f : Nat) :
                                                                                Used by
                                                                                  theorem

                                                                                  Lean2Js.HelperSem.agree_dvalues

                                                                                  source
                                                                                  (ext : Ext) (es : List (String × Js.JsValue)) (f : Nat) :
                                                                                  callDef ext (f + 5) "__dvalues" [ofJs (Js.JsValue.dict es)] = ofRes (Except.ok (Js.JsValue.arr (List.map (fun (x : String × Js.JsValue) => x.snd) es)))
                                                                                  Used by
                                                                                    theorem

                                                                                    Lean2Js.HelperSem.agree_dset

                                                                                    source
                                                                                    (ext : Ext) (es : List (String × Js.JsValue)) (k : String) (v : Js.JsValue) (f : Nat) :
                                                                                    Used by
                                                                                      theorem

                                                                                      Lean2Js.HelperSem.agree_ddelete

                                                                                      source
                                                                                      (ext : Ext) (es : List (String × Js.JsValue)) (k : String) (f : Nat) (h : Js.keysDistinct (List.map (fun (x : String × Js.JsValue) => x.fst) es) = true) :
                                                                                      callDef ext (f + (es.length + 12)) "__ddelete" [ofJs (Js.JsValue.dict es), ofJs (Js.JsValue.str k)] = ofRes (Except.ok (Js.JsValue.dict (List.filter (fun (x : String × Js.JsValue) => x.fst != k) es)))
                                                                                      Used by
                                                                                        theorem

                                                                                        Lean2Js.HelperSem.agree_dget

                                                                                        source
                                                                                        (ext : Ext) (es : List (String × Js.JsValue)) (k : String) (f : Nat) :
                                                                                        callDef ext (f + 10) "__dget" [ofJs (Js.JsValue.dict es), ofJs (Js.JsValue.str k)] = ofRes (Except.ok (match Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == k) es) with | some v => Js.JsValue.obj [("tag", Js.JsValue.str "some"), ("value", v)] | none => Js.JsValue.obj [("tag", Js.JsValue.str "none")]))
                                                                                        Used by

                                                                                          Strings #

                                                                                          theorem

                                                                                          Lean2Js.HelperSem.agree_strcmp

                                                                                          source
                                                                                          (ext : Ext) (x y : String) (f : Nat) :
                                                                                          Used by
                                                                                            theorem

                                                                                            Lean2Js.HelperSem.agree_str

                                                                                            source
                                                                                            (ext : Ext) (a : Int) (f : Nat) (hlo : Js.Runtime.safeMin ≤ a) (hhi : a ≤ Js.Runtime.safeMax) :
                                                                                            Used by
                                                                                              theorem

                                                                                              Lean2Js.HelperSem.agree_toInt

                                                                                              source
                                                                                              (ext : Ext) (x : String) (f : Nat) :
                                                                                              Used by
                                                                                                theorem

                                                                                                Lean2Js.HelperSem.agree_strlen

                                                                                                source
                                                                                                (ext : Ext) (x : String) (f : Nat) :
                                                                                                Used by
                                                                                                  theorem

                                                                                                  Lean2Js.HelperSem.agree_trim

                                                                                                  source
                                                                                                  (ext : Ext) (x : String) (f : Nat) :
                                                                                                  Used by
                                                                                                    theorem

                                                                                                    Lean2Js.HelperSem.agree_upper

                                                                                                    source
                                                                                                    (ext : Ext) (x : String) (f : Nat) :
                                                                                                    Used by
                                                                                                      theorem

                                                                                                      Lean2Js.HelperSem.agree_lower

                                                                                                      source
                                                                                                      (ext : Ext) (x : String) (f : Nat) :
                                                                                                      Used by
                                                                                                        theorem

                                                                                                        Lean2Js.HelperSem.agree_startsWith

                                                                                                        source
                                                                                                        (ext : Ext) (x t : String) (f : Nat) :
                                                                                                        Used by
                                                                                                          theorem

                                                                                                          Lean2Js.HelperSem.agree_endsWith

                                                                                                          source
                                                                                                          Used by
                                                                                                            theorem

                                                                                                            Lean2Js.HelperSem.agree_includes

                                                                                                            source
                                                                                                            Used by
                                                                                                              theorem

                                                                                                              Lean2Js.HelperSem.agree_split

                                                                                                              source
                                                                                                              (ext : Ext) (x sep : String) (f : Nat) :
                                                                                                              Used by
                                                                                                                theorem

                                                                                                                Lean2Js.HelperSem.agree_indexOf

                                                                                                                source
                                                                                                                (ext : Ext) (x t : String) (f : Nat) :
                                                                                                                Used by
                                                                                                                  theorem

                                                                                                                  Lean2Js.HelperSem.agree_join

                                                                                                                  source
                                                                                                                  (ext : Ext) (ss : List String) (sep : String) (f : Nat) :
                                                                                                                  Used by
                                                                                                                    theorem

                                                                                                                    Lean2Js.HelperSem.agree_repeat

                                                                                                                    source
                                                                                                                    (ext : Ext) (x : String) (n : Int) (f : Nat) :
                                                                                                                    Used by
                                                                                                                      theorem

                                                                                                                      Lean2Js.HelperSem.agree_substring

                                                                                                                      source
                                                                                                                      (ext : Ext) (x : String) (lo hi : Int) (f : Nat) :
                                                                                                                      Used by

                                                                                                                        Structural equality #

                                                                                                                        __eq walks an object's fields by name and the model's beq walks them in order, so the two part company on a permutation; and a Map cannot hold one key twice while the model's association list can. eqShape is exactly the pair of shapes on which they do agree. A function value is not one of the divergences: a value of a function type is a reference to a top-level function, and both compare those by name.

                                                                                                                        def

                                                                                                                        Lean2Js.HelperSem.eqShape

                                                                                                                        source
                                                                                                                        @[irreducible]
                                                                                                                        Equations
                                                                                                                        Instances For
                                                                                                                          Used by
                                                                                                                            def

                                                                                                                            Lean2Js.HelperSem.eqShapeList

                                                                                                                            source
                                                                                                                            @[irreducible]
                                                                                                                            Equations
                                                                                                                            Instances For
                                                                                                                              Used by
                                                                                                                                def

                                                                                                                                Lean2Js.HelperSem.eqShapeFields

                                                                                                                                source
                                                                                                                                @[irreducible]
                                                                                                                                Equations
                                                                                                                                Instances For
                                                                                                                                  Used by
                                                                                                                                    theorem

                                                                                                                                    Lean2Js.HelperSem.lookupV_cons_ne

                                                                                                                                    source
                                                                                                                                    {k k' : String} {v : Val} {es : List (String × Val)} (h : k' ≠ k) :
                                                                                                                                    lookupV ((k, v) :: es) k' = lookupV es k'
                                                                                                                                    Used by
                                                                                                                                      theorem

                                                                                                                                      Lean2Js.HelperSem.lookupV_cons_self

                                                                                                                                      source
                                                                                                                                      {k : String} {v : Val} {es : List (String × Val)} :
                                                                                                                                      lookupV ((k, v) :: es) k = v
                                                                                                                                      Used by
                                                                                                                                        theorem

                                                                                                                                        Lean2Js.HelperSem.eqObj_cons

                                                                                                                                        source
                                                                                                                                        {k : String} {v w : Val} {es fs : List (String × Val)} (ks : List String) :
                                                                                                                                        (∀ (k' : String), k' ∈ ks → k' ≠ k) → eqObj ((k, v) :: es) ((k, w) :: fs) ks = eqObj es fs ks
                                                                                                                                        Used by
                                                                                                                                          theorem

                                                                                                                                          Lean2Js.HelperSem.eqKeys_cons

                                                                                                                                          source
                                                                                                                                          {k : String} {v w : Val} {es fs : List (String × Val)} (ks ls : List String) :
                                                                                                                                          (∀ (k' : String), k' ∈ ks → k' ≠ k) → eqKeys ((k, v) :: es) ((k, w) :: fs) ks ls = eqKeys es fs ks ls
                                                                                                                                          Used by
                                                                                                                                            theorem

                                                                                                                                            Lean2Js.HelperSem.ne_of_contains_false

                                                                                                                                            source
                                                                                                                                            {ks : List String} {k : String} (h : ks.contains k = false) (k' : String) :
                                                                                                                                            k' ∈ ks → k' ≠ k
                                                                                                                                            Used by
                                                                                                                                              theorem

                                                                                                                                              Lean2Js.HelperSem.beqList_length

                                                                                                                                              source
                                                                                                                                              Used by
                                                                                                                                                theorem

                                                                                                                                                Lean2Js.HelperSem.beqFields_length

                                                                                                                                                source
                                                                                                                                                Used by
                                                                                                                                                  theorem

                                                                                                                                                  Lean2Js.HelperSem.keys_length

                                                                                                                                                  source
                                                                                                                                                  (es : List (String × Js.JsValue)) :
                                                                                                                                                  (List.map (fun (x : String × Js.JsValue) => x.fst) es).length = es.length
                                                                                                                                                  Used by
                                                                                                                                                    theorem

                                                                                                                                                    Lean2Js.HelperSem.eq_beq

                                                                                                                                                    source
                                                                                                                                                    (x y : Js.JsValue) (h : eqShape x y = true) :
                                                                                                                                                    eqVal (ofJs x) (ofJs y) = x.beq y
                                                                                                                                                    Used by
                                                                                                                                                      theorem

                                                                                                                                                      Lean2Js.HelperSem.agree_eq

                                                                                                                                                      source
                                                                                                                                                      (ext : Ext) (x y : Js.JsValue) (f : Nat) (h : eqShape x y = true) :
                                                                                                                                                      callDef ext (f + eqFuel (ofJs x) (ofJs y)) "__eq" [ofJs x, ofJs y] = ofRes (Except.ok (Js.JsValue.bool (x.beq y)))
                                                                                                                                                      Used by

                                                                                                                                                        The table #

                                                                                                                                                        def

                                                                                                                                                        Lean2Js.HelperSem.helperArgsOk

                                                                                                                                                        source
                                                                                                                                                        (name : String) (args : List Js.JsValue) :

                                                                                                                                                        What a call has to satisfy for the shipped source to answer what the model's table says. Three rows are the model being the more careful of the two — two re-check an Int53 range the type has already given, and one is stated on dictionaries a Map can actually hold — and one is a real divergence.

                                                                                                                                                        Equations
                                                                                                                                                        Instances For
                                                                                                                                                          Used by
                                                                                                                                                            theorem

                                                                                                                                                            Lean2Js.HelperSem.helper_agrees

                                                                                                                                                            source
                                                                                                                                                            (ext : Ext) (name : String) (args : List Js.JsValue) (r : Js.JsResult) (hok : helperArgsOk name args) (h : Js.helper name args = some r) :
                                                                                                                                                            Helper.Calls ext name (List.map ofJs args) (ofRes r)

                                                                                                                                                            Every row of Js.helper is answered by the JavaScript the compiler writes out, so what the helpers behind the table are left trusted for is what helperArgsOk still asks of a call.

                                                                                                                                                            The table is not the whole of what the model assumes about hand-written JavaScript. JsSem.eval carries __ck, __out and the seven traversal helpers as rules of its own rather than as rows, and those are answered by HelperProof.calls_ck_checkTy, calls_out_outTy, calls_map, calls_filter, calls_find, calls_all, calls_any, calls_reduce and calls_sortBy. calls_out_outTy is the one of those that asks something of its argument: __out walks a value the declared type accepts, which is what the entry hands it and what decl_correct says the body produced. __sortBy asks something of its arguments the way four of the rows do: the keys of one call are all numbers or all strings, which is what the key type the compiler insists on gives.

                                                                                                                                                            Used by