lean2js

Lean2Js.Dts

source

Imports 2

What the .d.ts says a value is, against the entry check the generated code runs #

What the .d.ts says a value of a declared type is, and how that compares with the entry check the generated code runs.

TsSat is the reading of the text Js.tsType and Js.declareType write: a discriminated union over the type's constructors, readonly T[] for an array, ReadonlyMap<string, V> for a dictionary, and number for both Int53 and UInt32. TypeScript erases to nothing at runtime, so this is a reading of a declaration and not a check that runs — that the reading is faithful to what TypeScript means by that text is where the .d.ts is still taken on trust.

Fields are read the way a property access reads them: Js.lookupField, the first entry carrying that name. Nothing here reads the order the keys arrive in, and nothing reads a key the type does not declare.

The two sets are the same, up to one point. checkTy_tsSat says the entry check is no more permissive than the .d.ts; tsSat_checkTy says it is no less, given inRange — the numbers the value carries lie in the Int53 and UInt32 ranges the check reads, which is what number cannot express. That is the whole of what the converse assumes about a value.

inductive

Lean2Js.Dts.TsSat

source
Instances For
    Used by
      inductive

      Lean2Js.Dts.TsSatFields

      source
      Instances For
        Used by
          theorem

          Lean2Js.Dts.TsSatFields.weaken

          source
          [Core.Discriminators] {p : Core.Program} {fs : List Core.Field} {jfs : List (String × Js.JsValue)} (e : String × Js.JsValue) :
          (∀ (f : Core.Field), f ∈ fs → e.fst ≠ f.name) → TsSatFields p fs jfs → TsSatFields p fs (e :: jfs)
          Used by
            theorem

            Lean2Js.Dts.lookup_key

            source
            Used by
              inductive

              Lean2Js.Dts.TsSatOut

              source

              The reading of the text Js.tsTypeOut writes: what the .d.ts says about a value on its way back out. TsSat with the dictObjMap arm gone, because a dictionary that crosses as a plain object comes back as one, and delegating to TsSat at a declared type, where one printed interface answers for both directions.

              Instances For
                Used by
                  theorem

                  Lean2Js.Dts.TsSatOut.toTsSat

                  source
                  {p : Core.Program} {ty : Core.Ty} {jv : Js.JsValue} (h : TsSatOut p ty jv) :
                  TsSat p ty jv

                  What the returning side admits, the argument side admits as well, so a value a consumer got back from one call is one the next call's parameter type takes.

                  Used by
                    theorem

                    Lean2Js.Dts.hasTy_tsSat

                    source
                    [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (v : Value) (ty : Core.Ty) :
                    Value.hasTy p v ty = true → TsSat p ty (encodeAt p ty v)

                    What a declaration hands back fits the published .d.ts. The reading is encodeAt — the value read out through the type the declaration was declared to return — because that is what the entry returns: at a dictObj it walks a Map into a plain object, and the .d.ts admits both.

                    Used by
                      theorem

                      Lean2Js.Dts.tsSatList_encodeListAt

                      source
                      [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (xs : List Value) (elem : Core.Ty) :
                      Value.hasElemTy p xs elem = true → ∀ (y : Js.JsValue), y ∈ encodeListAt p xs elem → TsSat p elem y
                      Used by
                        theorem

                        Lean2Js.Dts.tsSatEntries_encodeEntriesAt

                        source
                        [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (es : List (String × Value)) (elem : Core.Ty) :
                        Value.hasEntryTys p es elem = true → ∀ (e : String × Js.JsValue), e ∈ encodeEntriesAt p es elem → TsSat p elem e.snd
                        Used by
                          theorem

                          Lean2Js.Dts.tsSatFields_encodeFieldsAt

                          source
                          [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (fdecls : List Core.Field) (fs : List (String × Value)) :
                          (List.map (fun (x : Core.Field) => x.name) fdecls).Nodup → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → TsSatFields p fdecls (encodeFieldsAt p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls))
                          Used by
                            theorem

                            Lean2Js.Dts.hasTy_tsSatOut

                            source
                            [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (v : Value) (ty : Core.Ty) :
                            Value.hasTy p v ty = true → TsSatOut p ty (encodeAt p ty v)

                            What a declaration hands back fits the narrower type the .d.ts prints for a return. The only place it says more than hasTy_tsSat is a dictObj, where the entry has already walked the Map out into a plain object and so the union the argument side prints is not needed.

                            Used by
                              theorem

                              Lean2Js.Dts.tsSatOutList_encodeListAt

                              source
                              [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (xs : List Value) (elem : Core.Ty) :
                              Value.hasElemTy p xs elem = true → ∀ (y : Js.JsValue), y ∈ encodeListAt p xs elem → TsSatOut p elem y
                              Used by
                                theorem

                                Lean2Js.Dts.tsSatOutEntries_encodeEntriesAt

                                source
                                [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (es : List (String × Value)) (elem : Core.Ty) :
                                Value.hasEntryTys p es elem = true → ∀ (e : String × Js.JsValue), e ∈ encodeEntriesAt p es elem → TsSatOut p elem e.snd
                                Used by
                                  theorem

                                  Lean2Js.Dts.checkTy_tsSat

                                  source
                                  (p : Core.Program) (jv : Js.JsValue) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                  Compile.tyDescIn p st b ty = Except.ok d → Decl.StackAgrees p st env → Js.checkTy env jv d = true → TsSat p ty jv

                                  What the entry check lets through, the .d.ts admits. tsSat_checkTy is the other direction, which needs the number range the .d.ts cannot carry.

                                  Used by
                                    theorem

                                    Lean2Js.Dts.checkFields_tsSat

                                    source
                                    (p : Core.Program) (jfs : List (String × Js.JsValue)) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) :
                                    Compile.tyDescFields p st b fdecls = Except.ok ds → Decl.StackAgrees p st env → Js.checkFields env jfs ds = true → TsSatFields p fdecls jfs
                                    Used by
                                      theorem

                                      Lean2Js.Dts.checkList_tsSat

                                      source
                                      (p : Core.Program) (jxs : List Js.JsValue) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                      Compile.tyDescIn p st b elem = Except.ok d → Decl.StackAgrees p st env → Js.checkList env jxs d = true → ∀ (x : Js.JsValue), x ∈ jxs → TsSat p elem x
                                      Used by
                                        theorem

                                        Lean2Js.Dts.checkEntries_tsSat

                                        source
                                        (p : Core.Program) (jes : List (String × Js.JsValue)) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                        Compile.tyDescIn p st b elem = Except.ok d → Decl.StackAgrees p st env → Js.checkEntries env jes d = true → ∀ (e : String × Js.JsValue), e ∈ jes → TsSat p elem e.snd
                                        Used by

                                          The one thing a TypeScript type cannot say #

                                          Js.checkTy reads an Int53 or UInt32 range off a number, and number carries no range. inRange is that reading on its own: Js.checkTy with every shape test passing, so the only way it comes out false is a number outside the range the descriptor names at that position. Nothing runs it — it is what tsSat_checkTy assumes, and holding it apart from TsSat is what keeps that assumption down to one.

                                          def

                                          Lean2Js.Dts.inRange

                                          source
                                          @[irreducible]
                                          Equations
                                          Instances For
                                            Used by
                                              def

                                              Lean2Js.Dts.inRangeFields

                                              source
                                              @[irreducible]
                                              (env : Js.TyEnv) (fields : List (String × Js.JsValue)) :
                                              Equations
                                              Instances For
                                                Used by
                                                  def

                                                  Lean2Js.Dts.inRangeList

                                                  source
                                                  @[irreducible]
                                                  Equations
                                                  Instances For
                                                    Used by
                                                      def

                                                      Lean2Js.Dts.inRangeEntries

                                                      source
                                                      @[irreducible]
                                                      Equations
                                                      Instances For
                                                        Used by
                                                          theorem

                                                          Lean2Js.Dts.inRange_int53

                                                          source
                                                          Used by
                                                            theorem

                                                            Lean2Js.Dts.inRange_uint32

                                                            source
                                                            Used by
                                                              theorem

                                                              Lean2Js.Dts.inRange_array

                                                              source
                                                              Used by
                                                                theorem

                                                                Lean2Js.Dts.inRange_dict

                                                                source
                                                                Used by
                                                                  theorem

                                                                  Lean2Js.Dts.inRange_dictObj_dict

                                                                  source
                                                                  Used by
                                                                    theorem

                                                                    Lean2Js.Dts.inRange_dictObj_obj

                                                                    source
                                                                    Used by
                                                                      theorem

                                                                      Lean2Js.Dts.inRange_some

                                                                      source
                                                                      [Core.Discriminators] {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {d : Js.TyDesc} (h : Js.lookupField fields "tag" = some (Js.JsValue.str "some")) :
                                                                      inRange env (Js.JsValue.obj fields) d.option = inRangeFields env fields [("value", d)]
                                                                      Used by
                                                                        theorem

                                                                        Lean2Js.Dts.inRange_ok

                                                                        source
                                                                        [Core.Discriminators] {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {dok derr : Js.TyDesc} (h : Js.lookupField fields "tag" = some (Js.JsValue.str "ok")) :
                                                                        inRange env (Js.JsValue.obj fields) (dok.result derr) = inRangeFields env fields [("value", dok)]
                                                                        Used by
                                                                          theorem

                                                                          Lean2Js.Dts.inRange_error

                                                                          source
                                                                          [Core.Discriminators] {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {dok derr : Js.TyDesc} (h : Js.lookupField fields "tag" = some (Js.JsValue.str "error")) :
                                                                          inRange env (Js.JsValue.obj fields) (dok.result derr) = inRangeFields env fields [("error", derr)]
                                                                          Used by
                                                                            theorem

                                                                            Lean2Js.Dts.inRange_ctors

                                                                            source
                                                                            [Core.Discriminators] {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {key ctor : String} {alts : List (String × List (String × Js.TyDesc))} {alt : String × List (String × Js.TyDesc)} (htag : Js.lookupField fields key = some (Js.JsValue.str ctor)) (hf : List.find? (fun (x : String × List (String × Js.TyDesc)) => x.fst == ctor) alts = some alt) :
                                                                            inRange env (Js.JsValue.obj fields) (Js.TyDesc.ctors key alts) = inRangeFields env fields alt.snd
                                                                            Used by
                                                                              theorem

                                                                              Lean2Js.Dts.inRangeList_cons

                                                                              source
                                                                              [Core.Discriminators] {env : Js.TyEnv} (x : Js.JsValue) (xs : List Js.JsValue) (d : Js.TyDesc) :
                                                                              inRangeList env (x :: xs) d = (inRange env x d && inRangeList env xs d)
                                                                              Used by
                                                                                theorem

                                                                                Lean2Js.Dts.inRangeEntries_cons

                                                                                source
                                                                                [Core.Discriminators] {env : Js.TyEnv} (k : String) (v : Js.JsValue) (es : List (String × Js.JsValue)) (d : Js.TyDesc) :
                                                                                inRangeEntries env ((k, v) :: es) d = (inRange env v d && inRangeEntries env es d)
                                                                                Used by
                                                                                  theorem

                                                                                  Lean2Js.Dts.inRangeFields_found

                                                                                  source
                                                                                  [Core.Discriminators] {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {n : String} {t : Js.TyDesc} {ts : List (String × Js.TyDesc)} {v : Js.JsValue} (h : Js.lookupField fields n = some v) :
                                                                                  inRangeFields env fields ((n, t) :: ts) = (inRange env v t && inRangeFields env fields ts)
                                                                                  Used by

                                                                                    Everything the .d.ts admits, the entry check accepts #

                                                                                    The direction a caller feels. TsSat reads fields by name, so the order they arrive in is not read; Js.checkFields reads only the names the descriptor carries, so a key the type does not declare is not read either. What is left is inRange.

                                                                                    theorem

                                                                                    Lean2Js.Dts.tsSat_option_shape

                                                                                    source
                                                                                    Used by
                                                                                      theorem

                                                                                      Lean2Js.Dts.tsSat_result_shape

                                                                                      source
                                                                                      Used by
                                                                                        theorem

                                                                                        Lean2Js.Dts.tsSat_named_shape

                                                                                        source
                                                                                        Used by
                                                                                          theorem

                                                                                          Lean2Js.Dts.tsSat_array_shape

                                                                                          source
                                                                                          Used by
                                                                                            theorem

                                                                                            Lean2Js.Dts.tsSat_dict_shape

                                                                                            source
                                                                                            Used by
                                                                                              theorem

                                                                                              Lean2Js.Dts.find?_of_mem_nodup

                                                                                              source
                                                                                              [Core.Discriminators] {cs : List Core.CtorDef} {c : Core.CtorDef} :
                                                                                              c ∈ cs → (List.map (fun (x : Core.CtorDef) => x.name) cs).Nodup → List.find? (fun (x : Core.CtorDef) => x.name == c.name) cs = some c

                                                                                              A constructor of a validated type is the one its own name finds.

                                                                                              Used by
                                                                                                theorem

                                                                                                Lean2Js.Dts.tsSat_checkTy

                                                                                                source
                                                                                                [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (jv : Js.JsValue) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                                                                                Compile.tyDescIn p st b ty = Except.ok d → Decl.StackAgrees p st env → TsSat p ty jv → inRange env jv d = true → Js.checkTy env jv d = true

                                                                                                Everything the published .d.ts admits, the entry check accepts. The only thing assumed about the value is inRange: the order its keys arrive in is not read, and neither are keys the type does not declare.

                                                                                                Used by
                                                                                                  theorem

                                                                                                  Lean2Js.Dts.tsSatFields_checkFields

                                                                                                  source
                                                                                                  [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (jfs : List (String × Js.JsValue)) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) :
                                                                                                  Compile.tyDescFields p st b fdecls = Except.ok ds → Decl.StackAgrees p st env → TsSatFields p fdecls jfs → inRangeFields env jfs ds = true → Js.checkFields env jfs ds = true
                                                                                                  Used by
                                                                                                    theorem

                                                                                                    Lean2Js.Dts.tsSatList_checkList

                                                                                                    source
                                                                                                    [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (jxs : List Js.JsValue) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                                                                                    Compile.tyDescIn p st b elem = Except.ok d → Decl.StackAgrees p st env → (∀ (x : Js.JsValue), x ∈ jxs → TsSat p elem x) → inRangeList env jxs d = true → Js.checkList env jxs d = true
                                                                                                    Used by
                                                                                                      theorem

                                                                                                      Lean2Js.Dts.tsSatEntries_checkEntries

                                                                                                      source
                                                                                                      [Core.Discriminators] (p : Core.Program) (hn : Decl.TypesNamesOk p) (jes : List (String × Js.JsValue)) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                                                                                      Compile.tyDescIn p st b elem = Except.ok d → Decl.StackAgrees p st env → (∀ (e : String × Js.JsValue), e ∈ jes → TsSat p elem e.snd) → inRangeEntries env jes d = true → Js.checkEntries env jes d = true
                                                                                                      Used by