lean2js

Lean2Js.Value

source

Imports 2

The values eval returns, and the traps that line the semantics up with JS #

The values eval returns, and the traps that have to be taken to line the semantics up with JS.

Where Lean and JS split on the answer, both sides fail rather than one being bent toward the other. Division by zero is the archetype: Lean's / 0 = 0 and JS's Infinity are both "right", so trapping is the only way to make them agree.

def

Lean2Js.int53Max

source
:

JS's Number.MAX_SAFE_INTEGER.

Equations
Instances For
    Used by
      def

      Lean2Js.int53Min

      source
      :

      JS's Number.MIN_SAFE_INTEGER.

      Equations
      Instances For
        Used by
          inductive

          Lean2Js.Value

          source

          A value with a constructor becomes a tagged object on the JS side too. Option is not specialised to T | null because the moment one is nested, none and some none stop being distinguishable.

          Instances For
            Used by
              instance

              Lean2Js.instReprValue

              source
              @[instance_reducible]
              Equations
              Used by
                partial def

                Lean2Js.instReprValue.repr

                source
                :
                Used by
                  instance

                  Lean2Js.instInhabitedValue

                  source
                  @[instance_reducible]
                  Equations
                  Used by
                    def

                    Lean2Js.lookupFieldV

                    source
                    (fields : List (String × Value)) (k : String) :

                    A constructor value's field by name. Everything that walks a value asks for a key rather than for a position, because the field order a value carries is the declaration's and not the caller's.

                    Equations
                    Instances For
                      Used by
                        theorem

                        Lean2Js.sizeOf_lookupFieldV

                        source
                        (fields : List (String × Value)) (k : String) {v : Value} (h : lookupFieldV fields k = some v) :
                        sizeOf v < sizeOf fields
                        Used by
                          inductive

                          Lean2Js.Err

                          source
                          • divByZero : Err
                          • int53Overflow : Err
                          • outOfFuel : Err
                          • indexOutOfBounds : Err
                          • noMatchingAlternative : Err
                          • typeError : Err
                          • unknownVar : Err
                          • unknownFn : Err
                          • arity : Err
                          Instances For
                            Used by
                              instance

                              Lean2Js.instReprErr

                              source
                              @[instance_reducible]
                              Equations
                              Used by
                                def

                                Lean2Js.instReprErr.repr

                                source
                                :
                                Equations
                                Instances For
                                  Used by
                                    def

                                    Lean2Js.instBEqErr.beq

                                    source
                                    :
                                    Err → Err → Bool
                                    Equations
                                    Instances For
                                      Used by
                                        instance

                                        Lean2Js.instBEqErr

                                        source
                                        @[instance_reducible]
                                        Equations
                                        Used by
                                          instance

                                          Lean2Js.instInhabitedErr

                                          source
                                          @[instance_reducible]
                                          Equations
                                          Used by
                                            def

                                            Lean2Js.Err.code

                                            source
                                            :
                                            Equations
                                            Instances For
                                              Used by
                                                def

                                                Lean2Js.Value.beq

                                                source
                                                @[irreducible]
                                                :
                                                Value → Value → Bool

                                                Structural equality. JS's === compares references, so the generated code calls a helper following the same rules.

                                                Equations
                                                Instances For
                                                  Used by
                                                    def

                                                    Lean2Js.Value.beqFields

                                                    source
                                                    @[irreducible]
                                                    Equations
                                                    Instances For
                                                      Used by
                                                        def

                                                        Lean2Js.Value.beqList

                                                        source
                                                        @[irreducible]
                                                        Equations
                                                        Instances For
                                                          Used by
                                                            instance

                                                            Lean2Js.instBEqValue

                                                            source
                                                            @[instance_reducible]
                                                            Equations
                                                            Used by
                                                              theorem

                                                              Lean2Js.Value.beq_def

                                                              source
                                                              (a b : Value) :
                                                              (a == b) = a.beq b

                                                              Where a proof about matching a pattern literal starts: matchPat compares with ==, and what reduces on a literal is Value.beq.

                                                              Used by

                                                                Value.beq is structural equality, and the two halves of saying so are what lets a claim about == on an author's own type be settled by comparing encodings.

                                                                theorem

                                                                Lean2Js.Value.beq_refl

                                                                source
                                                                (v : Value) :
                                                                v.beq v = true
                                                                Used by
                                                                  theorem

                                                                  Lean2Js.Value.beqFields_refl

                                                                  source
                                                                  (fs : List (String × Value)) :
                                                                  Used by
                                                                    theorem

                                                                    Lean2Js.Value.beqList_refl

                                                                    source
                                                                    (xs : List Value) :
                                                                    beqList xs xs = true
                                                                    Used by
                                                                      theorem

                                                                      Lean2Js.Value.eq_of_beq

                                                                      source
                                                                      {a b : Value} :
                                                                      a.beq b = true → a = b
                                                                      Used by
                                                                        theorem

                                                                        Lean2Js.Value.eq_of_beqFields

                                                                        source
                                                                        {as bs : List (String × Value)} :
                                                                        beqFields as bs = true → as = bs
                                                                        Used by
                                                                          theorem

                                                                          Lean2Js.Value.eq_of_beqList

                                                                          source
                                                                          {as bs : List Value} :
                                                                          beqList as bs = true → as = bs
                                                                          Used by
                                                                            def

                                                                            Lean2Js.keysDistinct

                                                                            source

                                                                            A JS Map cannot hold one key twice, so a dictionary that does has no value on the other side of the boundary and is rejected there.

                                                                            Equations
                                                                            Instances For
                                                                              Used by
                                                                                def

                                                                                Lean2Js.entrySet

                                                                                source
                                                                                (acc : List (String × Value)) (k : String) (v : Value) :

                                                                                What a Map filled from these entries holds, said on the side of the model's values. It mirrors Js.Runtime.mapSetAll across encodeValue, which is what the entry check needs when a dictionary reached it as a plain object: the object's entries are set into a Map one at a time, and this is the list that Map is left holding.

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

                                                                                    Lean2Js.entrySetAll

                                                                                    source
                                                                                    Equations
                                                                                    Instances For
                                                                                      Used by
                                                                                        def

                                                                                        Lean2Js.Value.hasTy

                                                                                        source
                                                                                        @[irreducible]

                                                                                        Checks that a value matches its declared type. This is what pins the public API boundary down by type.

                                                                                        Equations
                                                                                        Instances For
                                                                                          Used by
                                                                                            def

                                                                                            Lean2Js.Value.hasFieldTys

                                                                                            source
                                                                                            @[irreducible]
                                                                                            Equations
                                                                                            Instances For
                                                                                              Used by
                                                                                                def

                                                                                                Lean2Js.Value.hasElemTy

                                                                                                source
                                                                                                @[irreducible]
                                                                                                Equations
                                                                                                Instances For
                                                                                                  Used by
                                                                                                    def

                                                                                                    Lean2Js.Value.hasEntryTys

                                                                                                    source
                                                                                                    @[irreducible]
                                                                                                    Equations
                                                                                                    Instances For
                                                                                                      Used by

                                                                                                        Reading the entry check #

                                                                                                        The check a public function runs on its arguments is stated over Value.hasTy, which is defined by well-founded recursion and so does not reduce on its own. One lemma per shape lets a proof about a declaration discharge the check without unfolding the type machinery by hand.

                                                                                                        theorem

                                                                                                        Lean2Js.hasTy_bool

                                                                                                        source
                                                                                                        Used by
                                                                                                          theorem

                                                                                                          Lean2Js.hasTy_uint32

                                                                                                          source
                                                                                                          Used by
                                                                                                            theorem

                                                                                                            Lean2Js.hasTy_str

                                                                                                            source
                                                                                                            Used by
                                                                                                              theorem

                                                                                                              Lean2Js.hasTy_bigint

                                                                                                              source
                                                                                                              Used by
                                                                                                                theorem

                                                                                                                Lean2Js.hasTy_int53

                                                                                                                source
                                                                                                                Used by
                                                                                                                  theorem

                                                                                                                  Lean2Js.hasTy_named

                                                                                                                  source
                                                                                                                  (p : Core.Program) (ctor : String) (fields : List (String × Value)) (n : String) (args : List Core.Ty) (t : Core.TypeDef) (c : Core.CtorDef) (ht : p.findType? n = some t) (hc : t.findAt? args ctor = some c) :
                                                                                                                  Value.hasTy p (Value.obj ctor fields) (Core.Ty.named n args) = Value.hasFieldTys p fields (List.map (fun (f : Core.Field) => (f.name, f.ty)) c.fields)
                                                                                                                  Used by
                                                                                                                    theorem

                                                                                                                    Lean2Js.hasTy_none

                                                                                                                    source
                                                                                                                    (p : Core.Program) (elem : Core.Ty) :
                                                                                                                    Used by
                                                                                                                      theorem

                                                                                                                      Lean2Js.hasTy_some

                                                                                                                      source
                                                                                                                      (p : Core.Program) (fields : List (String × Value)) (elem : Core.Ty) :
                                                                                                                      Value.hasTy p (Value.obj "some" fields) elem.option = Value.hasFieldTys p fields [("value", elem)]
                                                                                                                      Used by
                                                                                                                        theorem

                                                                                                                        Lean2Js.hasTy_ok

                                                                                                                        source
                                                                                                                        (p : Core.Program) (fields : List (String × Value)) (ok err : Core.Ty) :
                                                                                                                        Value.hasTy p (Value.obj "ok" fields) (ok.result err) = Value.hasFieldTys p fields [("value", ok)]
                                                                                                                        Used by
                                                                                                                          theorem

                                                                                                                          Lean2Js.hasTy_error

                                                                                                                          source
                                                                                                                          (p : Core.Program) (fields : List (String × Value)) (ok err : Core.Ty) :
                                                                                                                          Value.hasTy p (Value.obj "error" fields) (ok.result err) = Value.hasFieldTys p fields [("error", err)]
                                                                                                                          Used by
                                                                                                                            theorem

                                                                                                                            Lean2Js.hasTy_array

                                                                                                                            source
                                                                                                                            (p : Core.Program) (xs : List Value) (elem : Core.Ty) :
                                                                                                                            Used by
                                                                                                                              theorem

                                                                                                                              Lean2Js.hasTy_dict

                                                                                                                              source
                                                                                                                              (p : Core.Program) (entries : List (String × Value)) (elem : Core.Ty) :
                                                                                                                              Value.hasTy p (Value.dict entries) elem.dict = (keysDistinct (List.map (fun (x : String × Value) => x.fst) entries) && Value.hasEntryTys p entries elem)
                                                                                                                              Used by
                                                                                                                                theorem

                                                                                                                                Lean2Js.hasTy_dictObj

                                                                                                                                source
                                                                                                                                (p : Core.Program) (entries : List (String × Value)) (elem : Core.Ty) :
                                                                                                                                Value.hasTy p (Value.dict entries) elem.dictObj = (keysDistinct (List.map (fun (x : String × Value) => x.fst) entries) && Value.hasEntryTys p entries elem)

                                                                                                                                A dictionary declared to cross as a plain object is the same value as one that crosses as a Map: the constructor moves the boundary's shape, not the model's.

                                                                                                                                Used by
                                                                                                                                  theorem

                                                                                                                                  Lean2Js.hasTy_dictObj_eq_dict

                                                                                                                                  source
                                                                                                                                  (p : Core.Program) (v : Value) (elem : Core.Ty) :

                                                                                                                                  The two spellings of a dictionary ask a value for exactly the same thing. This is what lets one operation read a receiver at either of them: what the constructor decides is the shape the boundary writes, and inside the module there is one predicate, not two.

                                                                                                                                  Used by
                                                                                                                                    theorem

                                                                                                                                    Lean2Js.hasTy_fn

                                                                                                                                    source
                                                                                                                                    (p : Core.Program) (name : String) (params : List Core.Ty) (ret : Core.Ty) :
                                                                                                                                    Value.hasTy p (Value.fn name) (Core.Ty.fn params ret) = match p.find? name with | some d => List.map (fun (x : Core.Param) => x.ty) d.params == params && d.ret == ret | none => false
                                                                                                                                    Used by
                                                                                                                                      theorem

                                                                                                                                      Lean2Js.hasFieldTys_nil

                                                                                                                                      source
                                                                                                                                      Used by
                                                                                                                                        theorem

                                                                                                                                        Lean2Js.hasFieldTys_cons

                                                                                                                                        source
                                                                                                                                        (p : Core.Program) (key : String) (value : Value) (rest : List (String × Value)) (name : String) (ty : Core.Ty) (tys : List (String × Core.Ty)) :
                                                                                                                                        Value.hasFieldTys p ((key, value) :: rest) ((name, ty) :: tys) = (key == name && Value.hasTy p value ty && Value.hasFieldTys p rest tys)
                                                                                                                                        Used by
                                                                                                                                          theorem

                                                                                                                                          Lean2Js.hasElemTy_nil

                                                                                                                                          source
                                                                                                                                          (p : Core.Program) (elem : Core.Ty) :
                                                                                                                                          Used by
                                                                                                                                            theorem

                                                                                                                                            Lean2Js.hasElemTy_cons

                                                                                                                                            source
                                                                                                                                            (p : Core.Program) (x : Value) (rest : List Value) (elem : Core.Ty) :
                                                                                                                                            Value.hasElemTy p (x :: rest) elem = (Value.hasTy p x elem && Value.hasElemTy p rest elem)
                                                                                                                                            Used by
                                                                                                                                              theorem

                                                                                                                                              Lean2Js.hasEntryTys_nil

                                                                                                                                              source
                                                                                                                                              Used by
                                                                                                                                                theorem

                                                                                                                                                Lean2Js.hasEntryTys_cons

                                                                                                                                                source
                                                                                                                                                (p : Core.Program) (key : String) (v : Value) (rest : List (String × Value)) (elem : Core.Ty) :
                                                                                                                                                Value.hasEntryTys p ((key, v) :: rest) elem = (Value.hasTy p v elem && Value.hasEntryTys p rest elem)
                                                                                                                                                Used by