lean2js

Lean2Js.Decl

source

Correctness at the boundary a caller crosses: one public function #

Turns the fragment's expression-level correctness into a claim about one public function. The bridge is built at the boundary a caller actually crosses: the entry check the generated code runs on its arguments, the environment that check hands the body, and the fuel the model spends getting there.

The entry check #

Value.hasTy is what evalCall requires of an argument; Js.checkTy is what the generated function runs on the encoded one. They are separate definitions over separate value types, so nothing but a proof holds them together.

theorem

Lean2Js.Decl.errNeOk

source
{ε α : Type} {e : ε} {d : α} (h : Except.error e = Except.ok d) :
Used by

    The environment a descriptor is read under #

    tyDescIn walks under a stack of the declared types it is inside; the entry check walks under an environment of what those types bound. StackAgrees is the two lined up: the k-th binder of the environment is what expanding the k-th name on the stack produces, from that point outwards.

    def

    Lean2Js.Decl.envFor

    source
    (d : Js.TyDesc) (env : Js.TyEnv) :

    What a descriptor adds to the environment when the walk enters it: a binder if it is one, nothing otherwise.

    Equations
    Instances For
      Used by
        def

        Lean2Js.Decl.StackAgrees

        source
        (p : Core.Program) (st : Compile.Stack) (env : Js.TyEnv) :
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Used by
            theorem

            Lean2Js.Decl.StackAgrees.nil

            source
            Used by
              theorem

              Lean2Js.Decl.StackAgrees.drop

              source
              {p : Core.Program} {st : Compile.Stack} {env : Js.TyEnv} (h : StackAgrees p st env) (j : Nat) :
              Used by
                theorem

                Lean2Js.Decl.StackAgrees.cons

                source
                {p : Core.Program} {st : Compile.Stack} {env : Js.TyEnv} {n : String} {args : List Core.Ty} {key : String} {alts : Js.TyAlts} {b : Nat} (h : StackAgrees p st env) (hd : Compile.tyDescIn p st b (Core.Ty.named n args) = Except.ok (Js.TyDesc.mu key alts)) :
                StackAgrees p ((n, args) :: st) ((key, alts) :: env)
                Used by
                  theorem

                  Lean2Js.Decl.tyDesc_bool_inv

                  source
                  Used by
                    theorem

                    Lean2Js.Decl.tyDesc_int53_inv

                    source
                    Used by
                      theorem

                      Lean2Js.Decl.tyDesc_uint32_inv

                      source
                      Used by
                        theorem

                        Lean2Js.Decl.tyDesc_string_inv

                        source
                        Used by
                          theorem

                          Lean2Js.Decl.tyDesc_bigint_inv

                          source
                          Used by
                            theorem

                            Lean2Js.Decl.tyDesc_var_inv

                            source
                            {st : Compile.Stack} {p : Core.Program} {b : Nat} {n : String} {d : Js.TyDesc} (h : Compile.tyDescIn p st b (Core.Ty.var n) = Except.ok d) :
                            Used by
                              theorem

                              Lean2Js.Decl.tyDesc_fn_inv

                              source
                              {st : Compile.Stack} {p : Core.Program} {b : Nat} {ps : List Core.Ty} {r : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b (Core.Ty.fn ps r) = Except.ok d) :
                              Used by
                                theorem

                                Lean2Js.Decl.tyDesc_option_inv

                                source
                                {st : Compile.Stack} {p : Core.Program} {b : Nat} {t : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b t.option = Except.ok d) :
                                Used by
                                  theorem

                                  Lean2Js.Decl.tyDesc_array_inv

                                  source
                                  {st : Compile.Stack} {p : Core.Program} {b : Nat} {t : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b t.array = Except.ok d) :
                                  Used by
                                    theorem

                                    Lean2Js.Decl.tyDesc_dictObj_inv

                                    source
                                    Used by
                                      theorem

                                      Lean2Js.Decl.tyDesc_dict_inv

                                      source
                                      {st : Compile.Stack} {p : Core.Program} {b : Nat} {t : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b t.dict = Except.ok d) :
                                      Used by
                                        theorem

                                        Lean2Js.Decl.tyDesc_result_inv

                                        source
                                        {st : Compile.Stack} {p : Core.Program} {b : Nat} {ok err : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b (ok.result err) = Except.ok d) :
                                        ∃ (dok : Js.TyDesc), ∃ (derr : Js.TyDesc), Compile.tyDescIn p st b ok = Except.ok dok ∧ Compile.tyDescIn p st b err = Except.ok derr ∧ d = dok.result derr
                                        Used by
                                          theorem

                                          Lean2Js.Decl.tyDesc_named_inv

                                          source

                                          A declared type expands one of three ways: to a ref where the name has come round again at the same arguments, to a mu where the type can reach itself, and to a ctors where it cannot. The last two differ only in what the walk is left standing under, which is what envFor says.

                                          Used by
                                            theorem

                                            Lean2Js.Decl.checkTy_envFor

                                            source
                                            {env : Js.TyEnv} {jv : Js.JsValue} {key : String} {alts : Js.TyAlts} {d : Js.TyDesc} (h : d = Js.TyDesc.ctors key alts ∨ d = Js.TyDesc.mu key alts) :
                                            Js.checkTy env jv d = Js.checkTy (envFor d env) jv (Js.TyDesc.ctors key alts)

                                            A ctors and the mu that binds it are checked the same way, under environments that differ by that binder.

                                            Used by
                                              theorem

                                              Lean2Js.Decl.normTy_envFor

                                              source
                                              {env : Js.TyEnv} {jv : Js.JsValue} {key : String} {alts : Js.TyAlts} {d : Js.TyDesc} (h : d = Js.TyDesc.ctors key alts ∨ d = Js.TyDesc.mu key alts) :
                                              Js.normTy env jv d = Js.normTy (envFor d env) jv (Js.TyDesc.ctors key alts)
                                              Used by

                                                Reading the shape check #

                                                Js.checkTy is well-founded too, so it needs the same one-lemma-per-shape treatment Value.hasTy got.

                                                theorem

                                                Lean2Js.Decl.checkTy_bool

                                                source
                                                Used by
                                                  theorem

                                                  Lean2Js.Decl.checkTy_int53

                                                  source
                                                  Used by
                                                    theorem

                                                    Lean2Js.Decl.checkTy_uint32

                                                    source
                                                    Used by
                                                      theorem

                                                      Lean2Js.Decl.checkTy_string

                                                      source
                                                      Used by
                                                        theorem

                                                        Lean2Js.Decl.checkTy_bigint

                                                        source
                                                        Used by
                                                          theorem

                                                          Lean2Js.Decl.checkTy_array

                                                          source
                                                          {env : Js.TyEnv} (xs : List Js.JsValue) (d : Js.TyDesc) :
                                                          Used by
                                                            theorem

                                                            Lean2Js.Decl.checkTy_dict

                                                            source
                                                            Used by
                                                              theorem

                                                              Lean2Js.Decl.checkTy_dictObj_dict

                                                              source
                                                              Used by
                                                                theorem

                                                                Lean2Js.Decl.checkTy_dictObj_obj

                                                                source
                                                                {env : Js.TyEnv} (fields : List (String × Js.JsValue)) (d : Js.TyDesc) :
                                                                Js.checkTy env (Js.JsValue.obj fields) d.dictObj = Js.checkEntries env fields d
                                                                Used by
                                                                  theorem

                                                                  Lean2Js.Decl.checkTy_none

                                                                  source
                                                                  {env : Js.TyEnv} (fields : List (String × Js.JsValue)) (d : Js.TyDesc) (h : Js.lookupField fields "tag" = some (Js.JsValue.str "none")) :
                                                                  Used by
                                                                    theorem

                                                                    Lean2Js.Decl.checkTy_some

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

                                                                      Lean2Js.Decl.checkTy_ok

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

                                                                        Lean2Js.Decl.checkTy_error

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

                                                                          Lean2Js.Decl.checkTy_ctors

                                                                          source
                                                                          {env : Js.TyEnv} (key ctor : String) (fields : List (String × Js.JsValue)) (alts : List (String × List (String × Js.TyDesc))) (flds : 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 (ctor, flds)) :
                                                                          Js.checkTy env (Js.JsValue.obj fields) (Js.TyDesc.ctors key alts) = Js.checkFields env fields flds
                                                                          Used by
                                                                            theorem

                                                                            Lean2Js.Decl.checkList_nil

                                                                            source
                                                                            {env : Js.TyEnv} (d : Js.TyDesc) :
                                                                            Used by
                                                                              theorem

                                                                              Lean2Js.Decl.checkList_cons

                                                                              source
                                                                              {env : Js.TyEnv} (x : Js.JsValue) (rest : List Js.JsValue) (d : Js.TyDesc) :
                                                                              Js.checkList env (x :: rest) d = (Js.checkTy env x d && Js.checkList env rest d)
                                                                              Used by
                                                                                theorem

                                                                                Lean2Js.Decl.checkEntries_nil

                                                                                source
                                                                                {env : Js.TyEnv} (d : Js.TyDesc) :
                                                                                Used by
                                                                                  theorem

                                                                                  Lean2Js.Decl.checkEntries_cons

                                                                                  source
                                                                                  {env : Js.TyEnv} (key : String) (v : Js.JsValue) (rest : List (String × Js.JsValue)) (d : Js.TyDesc) :
                                                                                  Js.checkEntries env ((key, v) :: rest) d = (Js.checkTy env v d && Js.checkEntries env rest d)
                                                                                  Used by

                                                                                    Finding a constructor's descriptor #

                                                                                    Value.hasTy looks the constructor up in the declaration; the generated check looks it up in the descriptor list the compiler built from that same declaration.

                                                                                    theorem

                                                                                    Lean2Js.Decl.tyDescAlts_find

                                                                                    source
                                                                                    (p : Core.Program) (st : Compile.Stack) (b : Nat) (cs : List Core.CtorDef) (alts : List (String × List (String × Js.TyDesc))) (ctor : String) (c : Core.CtorDef) :
                                                                                    Compile.tyDescAlts p st b cs = Except.ok alts → List.find? (fun (x : Core.CtorDef) => x.name == ctor) cs = some c → ∃ (ds : List (String × Js.TyDesc)), List.find? (fun (x : String × List (String × Js.TyDesc)) => x.fst == ctor) alts = some (c.name, ds) ∧ Compile.tyDescFields p st b c.fields = Except.ok ds
                                                                                    Used by

                                                                                      The entry check agrees #

                                                                                      If a value satisfies the type its declaration promised, its encoding passes the shape check the generated function runs at the boundary. This is the positive direction only: a value that fails Value.hasTy is left to the run-time agreement check.

                                                                                      def

                                                                                      Lean2Js.Decl.TypesNamesOk

                                                                                      source

                                                                                      A declared type names its constructors apart from each other, every constructor names its fields apart from each other and from the key the type is told apart by, and that key is the one the constructor's name is carried under — the descriptor reads the type's, the encoding reads the name's, and the entry check is where the two meet. Compile.validateType checks all four, and compileProgram runs it over every declared type.

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

                                                                                          Lean2Js.Decl.hasFieldTys_singleton_inv

                                                                                          source
                                                                                          Used by
                                                                                            theorem

                                                                                            Lean2Js.Decl.named_unfolds

                                                                                            source
                                                                                            {p : Core.Program} {st : Compile.Stack} {env : Js.TyEnv} {b : Nat} {n : String} {args : List Core.Ty} {d : Js.TyDesc} (hd : Compile.tyDescIn p st b (Core.Ty.named n args) = Except.ok d) (hsa : StackAgrees p st env) :

                                                                                            However a declared type's descriptor was reached — written out, bound as a mu, or named by a ref back to a binder — what the walk does next is read the constructors of one ctors node, under the environment that node stands in. This is that node, and what it is read under.

                                                                                            What the node's field names have to be is carried as an implication rather than as a hypothesis: the .d.ts direction needs the node and not the names.

                                                                                            Used by
                                                                                              theorem

                                                                                              Lean2Js.Decl.checkTy_encodeValue

                                                                                              source
                                                                                              [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (v : Value) :
                                                                                              Compile.tyDescIn p st b ty = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasTy p v ty = true → Js.checkTy env (encodeValue v) d = true
                                                                                              Used by
                                                                                                theorem

                                                                                                Lean2Js.Decl.checkFields_encodeFields

                                                                                                source
                                                                                                [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) (fs : List (String × Value)) :
                                                                                                Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → Js.checkFields env (encodeFields fs) ds = true
                                                                                                Used by
                                                                                                  theorem

                                                                                                  Lean2Js.Decl.checkList_encodeList

                                                                                                  source
                                                                                                  [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (xs : List Value) :
                                                                                                  Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasElemTy p xs elem = true → Js.checkList env (encodeList xs) d = true
                                                                                                  Used by
                                                                                                    theorem

                                                                                                    Lean2Js.Decl.checkEntries_encodeFields

                                                                                                    source
                                                                                                    [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (es : List (String × Value)) :
                                                                                                    Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasEntryTys p es elem = true → Js.checkEntries env (encodeFields es) d = true
                                                                                                    Used by

                                                                                                      Normalisation leaves the canonical shape alone #

                                                                                                      encodeValue already writes tag first, the declared fields in declared order, and nothing else, so the entry check's normalisation has nothing to rebuild on what the reference semantics produced.

                                                                                                      theorem

                                                                                                      Lean2Js.Decl.normTy_encodeValue

                                                                                                      source
                                                                                                      [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (v : Value) :
                                                                                                      Compile.tyDescIn p st b ty = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasTy p v ty = true → Js.normTy env (encodeValue v) d = encodeValue v
                                                                                                      Used by
                                                                                                        theorem

                                                                                                        Lean2Js.Decl.normFields_encodeFields

                                                                                                        source
                                                                                                        [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) (fs : List (String × Value)) :
                                                                                                        Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → Js.normFields env (encodeFields fs) ds = encodeFields fs
                                                                                                        Used by
                                                                                                          theorem

                                                                                                          Lean2Js.Decl.normList_encodeList

                                                                                                          source
                                                                                                          [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (xs : List Value) :
                                                                                                          Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasElemTy p xs elem = true → Js.normList env (encodeList xs) d = encodeList xs
                                                                                                          Used by
                                                                                                            theorem

                                                                                                            Lean2Js.Decl.normEntries_encodeFields

                                                                                                            source
                                                                                                            [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (es : List (String × Value)) :
                                                                                                            Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasEntryTys p es elem = true → Js.normEntries env (encodeFields es) d = encodeFields es
                                                                                                            Used by

                                                                                                              The walk out reads the same value through its declared type #

                                                                                                              outTy parts from normTy at one node and encodeAt parts from encodeValue at the same one, so the two meet: what a declaration's entry hands back is the value the reference semantics produced, read through the type the declaration was declared to return.

                                                                                                              encodeValue v on the left is what the body built, which is what decl_correct says, and the walk is what the entry runs over it. Where the return type reaches no dictObj, Js.outTy_eq_normTy makes this normTy_encodeValue again and the entry emits no walk at all.

                                                                                                              theorem

                                                                                                              Lean2Js.Decl.outTy_encodeValue

                                                                                                              source
                                                                                                              [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (v : Value) :
                                                                                                              Compile.tyDescIn p st b ty = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasTy p v ty = true → Js.outTy env (encodeValue v) d = encodeAt p ty v
                                                                                                              Used by
                                                                                                                theorem

                                                                                                                Lean2Js.Decl.outFields_encodeFieldsAt

                                                                                                                source
                                                                                                                [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) (fs : List (String × Value)) :
                                                                                                                Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → Js.outFields env (encodeFields fs) ds = encodeFieldsAt p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls)
                                                                                                                Used by
                                                                                                                  theorem

                                                                                                                  Lean2Js.Decl.outList_encodeListAt

                                                                                                                  source
                                                                                                                  [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (xs : List Value) :
                                                                                                                  Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasElemTy p xs elem = true → Js.outList env (encodeList xs) d = encodeListAt p xs elem
                                                                                                                  Used by
                                                                                                                    theorem

                                                                                                                    Lean2Js.Decl.outEntries_encodeEntriesAt

                                                                                                                    source
                                                                                                                    [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (es : List (String × Value)) :
                                                                                                                    Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasEntryTys p es elem = true → Js.outEntries env (encodeFields es) d = encodeEntriesAt p es elem
                                                                                                                    Used by

                                                                                                                      The entry check refuses #

                                                                                                                      The other direction. What matters at the boundary is not that a bad Value fails the check — it is that everything the check accepts is the encoding of a value the reference semantics accepts too, which is what turns a refusal on one side into a refusal on the other.

                                                                                                                      The claim is stated about JS values rather than about Values because encodeValue is not injective: an Int53 and a UInt32 holding the same number both encode to .num, so nothing on the generated side could tell them apart. Over Values the direction is false; over what actually crosses the boundary it holds.

                                                                                                                      theorem

                                                                                                                      Lean2Js.Decl.checkTy_bool_inv

                                                                                                                      source
                                                                                                                      Used by
                                                                                                                        theorem

                                                                                                                        Lean2Js.Decl.checkTy_int53_inv

                                                                                                                        source
                                                                                                                        Used by
                                                                                                                          theorem

                                                                                                                          Lean2Js.Decl.checkTy_uint32_inv

                                                                                                                          source
                                                                                                                          Used by
                                                                                                                            theorem

                                                                                                                            Lean2Js.Decl.checkTy_string_inv

                                                                                                                            source
                                                                                                                            Used by
                                                                                                                              theorem

                                                                                                                              Lean2Js.Decl.checkTy_bigint_inv

                                                                                                                              source
                                                                                                                              Used by
                                                                                                                                theorem

                                                                                                                                Lean2Js.Decl.checkTy_array_inv

                                                                                                                                source
                                                                                                                                {env : Js.TyEnv} {jv : Js.JsValue} {d : Js.TyDesc} (h : Js.checkTy env jv d.array = true) :
                                                                                                                                Used by
                                                                                                                                  theorem

                                                                                                                                  Lean2Js.Decl.checkTy_dict_inv

                                                                                                                                  source
                                                                                                                                  Used by
                                                                                                                                    theorem

                                                                                                                                    Lean2Js.Decl.checkTy_dictObj_inv

                                                                                                                                    source

                                                                                                                                    A dictionary declared to cross as a plain object is met as either shape: the object a consumer writes, or the Map another declaration of the same package handed back.

                                                                                                                                    Used by
                                                                                                                                      theorem

                                                                                                                                      Lean2Js.Decl.checkTy_option_shape

                                                                                                                                      source
                                                                                                                                      {env : Js.TyEnv} {jv : Js.JsValue} {d : Js.TyDesc} (h : Js.checkTy env jv d.option = true) :
                                                                                                                                      Used by
                                                                                                                                        theorem

                                                                                                                                        Lean2Js.Decl.checkTy_result_shape

                                                                                                                                        source
                                                                                                                                        {env : Js.TyEnv} {jv : Js.JsValue} {dok derr : Js.TyDesc} (h : Js.checkTy env jv (dok.result derr) = true) :
                                                                                                                                        Used by
                                                                                                                                          theorem

                                                                                                                                          Lean2Js.Decl.checkTy_ctors_shape

                                                                                                                                          source
                                                                                                                                          {env : Js.TyEnv} {jv : Js.JsValue} {key : String} {alts : List (String × List (String × Js.TyDesc))} (h : Js.checkTy env jv (Js.TyDesc.ctors key alts) = true) :
                                                                                                                                          Used by
                                                                                                                                            theorem

                                                                                                                                            Lean2Js.Decl.checkTy_option_fields

                                                                                                                                            source
                                                                                                                                            {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {d : Js.TyDesc} (h : Js.checkTy env (Js.JsValue.obj fields) d.option = true) :
                                                                                                                                            Js.lookupField fields "tag" = some (Js.JsValue.str "none") ∨ Js.lookupField fields "tag" = some (Js.JsValue.str "some") ∧ Js.checkFields env fields [("value", d)] = true
                                                                                                                                            Used by
                                                                                                                                              theorem

                                                                                                                                              Lean2Js.Decl.checkTy_result_fields

                                                                                                                                              source
                                                                                                                                              {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {dok derr : Js.TyDesc} (h : Js.checkTy env (Js.JsValue.obj fields) (dok.result derr) = true) :
                                                                                                                                              Js.lookupField fields "tag" = some (Js.JsValue.str "ok") ∧ Js.checkFields env fields [("value", dok)] = true ∨ Js.lookupField fields "tag" = some (Js.JsValue.str "error") ∧ Js.checkFields env fields [("error", derr)] = true
                                                                                                                                              Used by
                                                                                                                                                theorem

                                                                                                                                                Lean2Js.Decl.checkTy_ctors_fields

                                                                                                                                                source
                                                                                                                                                {env : Js.TyEnv} {fields : List (String × Js.JsValue)} {key : String} {alts : List (String × List (String × Js.TyDesc))} (h : Js.checkTy env (Js.JsValue.obj fields) (Js.TyDesc.ctors key alts) = true) :
                                                                                                                                                ∃ (ctor : String), ∃ (ds : List (String × Js.TyDesc)), Js.lookupField fields key = some (Js.JsValue.str ctor) ∧ List.find? (fun (x : String × List (String × Js.TyDesc)) => x.fst == ctor) alts = some (ctor, ds) ∧ Js.checkFields env fields ds = true
                                                                                                                                                Used by
                                                                                                                                                  theorem

                                                                                                                                                  Lean2Js.Decl.checkFields_singleton_inv

                                                                                                                                                  source
                                                                                                                                                  {env : Js.TyEnv} {jfs : List (String × Js.JsValue)} {name : String} {d : Js.TyDesc} (h : Js.checkFields env jfs [(name, d)] = true) :
                                                                                                                                                  Used by
                                                                                                                                                    theorem

                                                                                                                                                    Lean2Js.Decl.dictKeysDistinct_obj

                                                                                                                                                    source
                                                                                                                                                    Used by
                                                                                                                                                      theorem

                                                                                                                                                      Lean2Js.Decl.dictKeysDistinct_arr

                                                                                                                                                      source
                                                                                                                                                      Used by
                                                                                                                                                        theorem

                                                                                                                                                        Lean2Js.Decl.dictKeysDistinct_dict

                                                                                                                                                        source
                                                                                                                                                        Used by
                                                                                                                                                          theorem

                                                                                                                                                          Lean2Js.Decl.dictKeysDistinctFields_cons

                                                                                                                                                          source
                                                                                                                                                          Used by
                                                                                                                                                            theorem

                                                                                                                                                            Lean2Js.Decl.dictKeysDistinctList_cons

                                                                                                                                                            source
                                                                                                                                                            Used by
                                                                                                                                                              theorem

                                                                                                                                                              Lean2Js.Decl.dictKeysDistinct_lookupField

                                                                                                                                                              source
                                                                                                                                                              Used by
                                                                                                                                                                theorem

                                                                                                                                                                Lean2Js.Decl.keysDistinct_of_js

                                                                                                                                                                source
                                                                                                                                                                Used by
                                                                                                                                                                  theorem

                                                                                                                                                                  Lean2Js.Decl.entrySetAll_nodup

                                                                                                                                                                  source
                                                                                                                                                                  (es acc : List (String × Value)) :
                                                                                                                                                                  (List.map (fun (x : String × Value) => x.fst) acc).Nodup → (List.map (fun (x : String × Value) => x.fst) (entrySetAll acc es)).Nodup
                                                                                                                                                                  Used by
                                                                                                                                                                    theorem

                                                                                                                                                                    Lean2Js.Decl.entrySetAll_mem

                                                                                                                                                                    source
                                                                                                                                                                    (es acc : List (String × Value)) (e : String × Value) :
                                                                                                                                                                    e ∈ entrySetAll acc es → e ∈ acc ∨ e ∈ es
                                                                                                                                                                    Used by
                                                                                                                                                                      theorem

                                                                                                                                                                      Lean2Js.Decl.encodeFields_entrySet

                                                                                                                                                                      source
                                                                                                                                                                      Used by
                                                                                                                                                                        theorem

                                                                                                                                                                        Lean2Js.Decl.encodeFields_entrySetAll

                                                                                                                                                                        source
                                                                                                                                                                        Used by
                                                                                                                                                                          theorem

                                                                                                                                                                          Lean2Js.Decl.encodeFields_keys

                                                                                                                                                                          source
                                                                                                                                                                          [Core.Discriminators] (es : List (String × Value)) :
                                                                                                                                                                          List.map (fun (x : String × Js.JsValue) => x.fst) (encodeFields es) = List.map (fun (x : String × Value) => x.fst) es
                                                                                                                                                                          Used by
                                                                                                                                                                            theorem

                                                                                                                                                                            Lean2Js.Decl.keysDistinct_to_js

                                                                                                                                                                            source
                                                                                                                                                                            Used by
                                                                                                                                                                              theorem

                                                                                                                                                                              Lean2Js.Decl.mapSetAll_encodeFields

                                                                                                                                                                              source

                                                                                                                                                                              A dictionary read out of an object and back into a Map is the dictionary it was: the keys a value carries are distinct, so nothing collapses on the way.

                                                                                                                                                                              Used by

                                                                                                                                                                                The entry check reads back what the walk out wrote #

                                                                                                                                                                                A call through a function value goes to the entry, which hands its result back through the declared type. What the caller is holding is then encodeAt, not encodeValue, so the check it runs on the way back in has to accept it and rebuild the Map the module works in. These are checkTy_encodeValue and normTy_encodeValue with encodeAt on the left, and they part from them at the one node the two encodings part at.

                                                                                                                                                                                theorem

                                                                                                                                                                                Lean2Js.Decl.checkTy_encodeAt

                                                                                                                                                                                source
                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (v : Value) :
                                                                                                                                                                                Compile.tyDescIn p st b ty = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasTy p v ty = true → Js.checkTy env (encodeAt p ty v) d = true
                                                                                                                                                                                Used by
                                                                                                                                                                                  theorem

                                                                                                                                                                                  Lean2Js.Decl.checkFields_encodeFieldsAt

                                                                                                                                                                                  source
                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) (fs : List (String × Value)) :
                                                                                                                                                                                  Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → Js.checkFields env (encodeFieldsAt p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls)) ds = true
                                                                                                                                                                                  Used by
                                                                                                                                                                                    theorem

                                                                                                                                                                                    Lean2Js.Decl.checkList_encodeListAt

                                                                                                                                                                                    source
                                                                                                                                                                                    [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (xs : List Value) :
                                                                                                                                                                                    Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasElemTy p xs elem = true → Js.checkList env (encodeListAt p xs elem) d = true
                                                                                                                                                                                    Used by
                                                                                                                                                                                      theorem

                                                                                                                                                                                      Lean2Js.Decl.checkEntries_encodeEntriesAt

                                                                                                                                                                                      source
                                                                                                                                                                                      [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (es : List (String × Value)) :
                                                                                                                                                                                      Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasEntryTys p es elem = true → Js.checkEntries env (encodeEntriesAt p es elem) d = true
                                                                                                                                                                                      Used by

                                                                                                                                                                                        Normalisation leaves the canonical shape alone #

                                                                                                                                                                                        encodeValue already writes tag first, the declared fields in declared order, and nothing else, so the entry check's normalisation has nothing to rebuild on what the reference semantics produced.

                                                                                                                                                                                        theorem

                                                                                                                                                                                        Lean2Js.Decl.normTy_encodeAt

                                                                                                                                                                                        source
                                                                                                                                                                                        [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (ty : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (v : Value) :
                                                                                                                                                                                        Compile.tyDescIn p st b ty = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasTy p v ty = true → Js.normTy env (encodeAt p ty v) d = encodeValue v
                                                                                                                                                                                        Used by
                                                                                                                                                                                          theorem

                                                                                                                                                                                          Lean2Js.Decl.normFields_encodeFieldsAt

                                                                                                                                                                                          source
                                                                                                                                                                                          [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) (fs : List (String × Value)) :
                                                                                                                                                                                          Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true → Js.normFields env (encodeFieldsAt p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls)) ds = encodeFields fs
                                                                                                                                                                                          Used by
                                                                                                                                                                                            theorem

                                                                                                                                                                                            Lean2Js.Decl.normList_encodeListAt

                                                                                                                                                                                            source
                                                                                                                                                                                            [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (xs : List Value) :
                                                                                                                                                                                            Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasElemTy p xs elem = true → Js.normList env (encodeListAt p xs elem) d = encodeList xs
                                                                                                                                                                                            Used by
                                                                                                                                                                                              theorem

                                                                                                                                                                                              Lean2Js.Decl.normEntries_encodeEntriesAt

                                                                                                                                                                                              source
                                                                                                                                                                                              [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) (es : List (String × Value)) :
                                                                                                                                                                                              Compile.tyDescIn p st b elem = Except.ok d → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Value.hasEntryTys p es elem = true → Js.normEntries env (encodeEntriesAt p es elem) d = encodeFields es
                                                                                                                                                                                              Used by
                                                                                                                                                                                                theorem

                                                                                                                                                                                                Lean2Js.Decl.tyDescAlts_find_inv

                                                                                                                                                                                                source
                                                                                                                                                                                                (p : Core.Program) (st : Compile.Stack) (b : Nat) (cs : List Core.CtorDef) (alts : List (String × List (String × Js.TyDesc))) (ctor : String) (ds : List (String × Js.TyDesc)) :
                                                                                                                                                                                                Compile.tyDescAlts p st b cs = Except.ok alts → List.find? (fun (x : String × List (String × Js.TyDesc)) => x.fst == ctor) alts = some (ctor, ds) → ∃ (c : Core.CtorDef), List.find? (fun (x : Core.CtorDef) => x.name == ctor) cs = some c ∧ Compile.tyDescFields p st b c.fields = Except.ok ds

                                                                                                                                                                                                The mirror of tyDescAlts_find: a constructor the generated check found in the descriptor list is one the declaration has.

                                                                                                                                                                                                Used by
                                                                                                                                                                                                  theorem

                                                                                                                                                                                                  Lean2Js.Decl.checkTy_sound

                                                                                                                                                                                                  source
                                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) (hn : 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 → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Js.checkTy env jv d = true → Js.dictKeysDistinct jv = true → ∃ (v : Value), Js.normTy env jv d = encodeValue v ∧ Value.hasTy p v ty = true

                                                                                                                                                                                                  Everything the generated entry check lets through normalises to the encoding of a value of the declared type. The recursion is on the JS value, not on the type: unfolding a .named substitutes its arguments into the field types, which can grow.

                                                                                                                                                                                                  Used by
                                                                                                                                                                                                    theorem

                                                                                                                                                                                                    Lean2Js.Decl.checkFields_sound

                                                                                                                                                                                                    source
                                                                                                                                                                                                    [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (jfs : List (String × Js.JsValue)) (fdecls : List Core.Field) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (ds : List (String × Js.TyDesc)) (key : String) :
                                                                                                                                                                                                    Compile.tyDescFields p st b fdecls = Except.ok ds → StackAgrees p st env → Js.envOk env = true → Js.namesOk key ds = true → Js.fieldsOk (List.length env) ds = true → Js.checkFields env jfs ds = true → Js.dictKeysDistinctFields jfs = true → ∃ (fs : List (String × Value)), Js.normFields env jfs ds = encodeFields fs ∧ Value.hasFieldTys p fs (List.map (fun (f : Core.Field) => (f.name, f.ty)) fdecls) = true
                                                                                                                                                                                                    Used by
                                                                                                                                                                                                      theorem

                                                                                                                                                                                                      Lean2Js.Decl.checkList_sound

                                                                                                                                                                                                      source
                                                                                                                                                                                                      [Core.Discriminators] (p : Core.Program) (hn : 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 → StackAgrees p st env → Js.envOk env = true → Js.descOk (List.length env) d = true → Js.checkList env jxs d = true → Js.dictKeysDistinctList jxs = true → ∃ (vs : List Value), Js.normList env jxs d = encodeList vs ∧ Value.hasElemTy p vs elem = true
                                                                                                                                                                                                      Used by
                                                                                                                                                                                                        theorem

                                                                                                                                                                                                        Lean2Js.Decl.checkEntries_sound

                                                                                                                                                                                                        source
                                                                                                                                                                                                        [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) (jes : List (String × Js.JsValue)) (elem : Core.Ty) (st : Compile.Stack) (env : Js.TyEnv) (b : Nat) (d : Js.TyDesc) :
                                                                                                                                                                                                        Used by

                                                                                                                                                                                                          The entry environment #

                                                                                                                                                                                                          A public function's body runs under two layers: the checked parameters the entry left on top, and the raw __p0, __p1, … the check read them from. Value.hasTy knows nothing about either, so the two have to be lined up by hand. The reserved prefix is what keeps the layers apart.

                                                                                                                                                                                                          theorem

                                                                                                                                                                                                          Lean2Js.Decl.repr_inj

                                                                                                                                                                                                          source
                                                                                                                                                                                                          [Core.Discriminators] {a b : Nat} (h : a.repr = b.repr) :
                                                                                                                                                                                                          a = b
                                                                                                                                                                                                          Used by
                                                                                                                                                                                                            theorem

                                                                                                                                                                                                            Lean2Js.Decl.rawParam_reserved

                                                                                                                                                                                                            source
                                                                                                                                                                                                            Used by
                                                                                                                                                                                                              theorem

                                                                                                                                                                                                              Lean2Js.Decl.rawParam_inj

                                                                                                                                                                                                              source
                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                Lean2Js.Decl.validateIdent_unreserved

                                                                                                                                                                                                                source
                                                                                                                                                                                                                [Core.Discriminators] {kind name : String} (h : validateIdent kind name = Except.ok ()) :
                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                  Lean2Js.Decl.ne_rawParam

                                                                                                                                                                                                                  source
                                                                                                                                                                                                                  [Core.Discriminators] {name : String} {i : Nat} (h : isReserved name = false) :
                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                    def

                                                                                                                                                                                                                    Lean2Js.Decl.RawBound

                                                                                                                                                                                                                    source
                                                                                                                                                                                                                    (jenv : Js.JsEnv) :

                                                                                                                                                                                                                    Which raw name each argument is reachable under. Stated as a lookup rather than as a shape so that the checked parameters the entry keeps stacking on top do not disturb it.

                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                        Lean2Js.Decl.RawBound.cons_unreserved

                                                                                                                                                                                                                        source
                                                                                                                                                                                                                        [Core.Discriminators] {jenv : Js.JsEnv} {name : String} {v : Js.JsValue} {i : Nat} (hname : isReserved name = false) {as : List Js.JsValue} :
                                                                                                                                                                                                                        RawBound jenv i as → RawBound ((name, v) :: jenv) i as
                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                          Lean2Js.Decl.RawBound.cons_raw

                                                                                                                                                                                                                          source
                                                                                                                                                                                                                          [Core.Discriminators] {jenv : Js.JsEnv} {v : Js.JsValue} {i j : Nat} {as : List Js.JsValue} :
                                                                                                                                                                                                                          i < j → RawBound jenv j as → RawBound ((Compile.rawParam i, v) :: jenv) j as
                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                            Lean2Js.Decl.rawBound_bindAll

                                                                                                                                                                                                                            source
                                                                                                                                                                                                                            [Core.Discriminators] (params : List Core.Param) (jargs : List Js.JsValue) (i : Nat) :
                                                                                                                                                                                                                            params.length = jargs.length → RawBound (Js.bindAll (Compile.rawParams i params) jargs) i jargs
                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                              def

                                                                                                                                                                                                                              Lean2Js.Decl.Unreserved

                                                                                                                                                                                                                              source
                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                  def

                                                                                                                                                                                                                                  Lean2Js.Decl.DistinctNames

                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                      def

                                                                                                                                                                                                                                      Lean2Js.Decl.NoFnParams

                                                                                                                                                                                                                                      source

                                                                                                                                                                                                                                      No parameter is function-typed, which is what Decl.isPublic decides. The entry emits no check for one, so it is the line the refusing direction stops at.

                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                          def

                                                                                                                                                                                                                                          Lean2Js.Decl.checkedBindings

                                                                                                                                                                                                                                          source

                                                                                                                                                                                                                                          What the entry check leaves on top of the environment, newest first: the last parameter is checked last, so it ends up in front.

                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                              Lean2Js.Decl.eval_ident

                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                              [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (name : String) (v : Js.JsValue) (h : Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) jenv) = some v) :
                                                                                                                                                                                                                                              Js.eval m (f + 1) jenv (Js.Expr.ident name) = Except.ok v
                                                                                                                                                                                                                                              Used by

                                                                                                                                                                                                                                                The descriptors the entry check reads #

                                                                                                                                                                                                                                                The entry check reads a constructor's fields by name; encodeValue writes them in declared order. A proof about the entry has to know the two are the same reading, which is Js.descOk, and for a descriptor the compiler rendered it comes from the program having been validated.

                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                Lean2Js.Decl.namesOk_of_nodup

                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                [Core.Discriminators] {key : String} {flds : List (String × Js.TyDesc)} :
                                                                                                                                                                                                                                                (∀ (n : String), n ∈ List.map (fun (x : String × Js.TyDesc) => x.fst) flds → n ≠ key) → (List.map (fun (x : String × Js.TyDesc) => x.fst) flds).Nodup → Js.namesOk key flds = true
                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                  Lean2Js.Decl.descOk_tyDesc

                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                  {st : Compile.Stack} [Core.Discriminators] {p : Core.Program} (hnames : TypesNamesOk p) (b : Nat) (ty : Core.Ty) (d : Js.TyDesc) :
                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                    Lean2Js.Decl.descNoDictObj_tyDesc

                                                                                                                                                                                                                                                    source

                                                                                                                                                                                                                                                    Where the program declares no dictionary that crosses as a plain object and a type reaches none, the descriptor the entry is compiled against reaches none either. This is what carries the author's reading — "nothing here uses Dict.Obj" — over to the reading the compiler consults when it decides whether an entry needs a walk out at all.

                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                      Lean2Js.Decl.retWalk_id_of_descNoDictObj

                                                                                                                                                                                                                                                      source

                                                                                                                                                                                                                                                      An entry whose return descriptor reaches no dictObj emits no walk out, so Compile.retWalk is the identity and the function written out is the one it was before a dictionary could cross the boundary as a plain object. The descriptor is that declaration's own return type expanded, so this is per declaration: one declaration of a program may hand a dictionary across as an object while its neighbour emits no walk at all.

                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                        Lean2Js.Decl.retWalk_id_of_retNoDictObj

                                                                                                                                                                                                                                                        source

                                                                                                                                                                                                                                                        The same, read off the return type as written, which takes the whole program: Ty.noDictObj stops at a declared type's name, and such a type may carry a Dict.Obj field, so the expansion reaches one where the return type does not. That is what hp rules out, and retWalk_id_of_descNoDictObj is the reading that asks for neither.

                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                          Lean2Js.Decl.retWalk_id_of_noDictObj

                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                          [Core.Discriminators] {p : Core.Program} (hp : p.noDictObj = true) {d : Core.Decl} (hd : d ∈ p.decls) {desc : Js.TyDesc} (hdesc : Compile.tyDesc p (Compile.tyDescBudget p d.ret) d.ret = Except.ok desc) (e : Js.Expr) :

                                                                                                                                                                                                                                                          No entry of a program that declares no dictObj anywhere emits a walk out, which is every declaration of it at once.

                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                            Lean2Js.Decl.encodeAt_eq_encodeValue_of_desc

                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                            [Core.Discriminators] [Core.Discriminators] (p : Core.Program) (hn : TypesNamesOk p) {ty : Core.Ty} {b : Nat} {d : Js.TyDesc} {v : Value} (hd : Compile.tyDesc p b ty = Except.ok d) (hnd : Js.descNoDictObj d = true) (hv : Value.hasTy p v ty = true) :

                                                                                                                                                                                                                                                            Where the descriptor the entry read reaches no dictionary crossing as a plain object, reading a value out through its declared type is reading it without one, so the entry emits no walk and hands back what the body built. This is what keeps every claim a package makes today where it is.

                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                              Lean2Js.Decl.eval_check

                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                              [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (d : Js.TyDesc) (x : Js.Expr) (v : Js.JsValue) (hx : Js.eval m f jenv x = Except.ok v) (hc : Js.checkTy [] v d = true) :
                                                                                                                                                                                                                                                              Js.eval m (f + 1) jenv (Js.Expr.check d x) = Except.ok (Js.normTy [] v d)
                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                Lean2Js.Decl.eval_check_fail

                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (d : Js.TyDesc) (x : Js.Expr) (v : Js.JsValue) (hx : Js.eval m f jenv x = Except.ok v) (hc : Js.checkTy [] v d = false) :
                                                                                                                                                                                                                                                                Js.eval m (f + 1) jenv (Js.Expr.check d x) = Except.error "typeError"
                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                  Lean2Js.Decl.eval_out

                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                  [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (d : Js.TyDesc) (x : Js.Expr) (v : Js.JsValue) (hx : Js.eval m f jenv x = Except.ok v) :
                                                                                                                                                                                                                                                                  Js.eval m (f + 1) jenv (Js.Expr.out d x) = Except.ok (Js.outTy [] v d)

                                                                                                                                                                                                                                                                  The walk out runs no check: what the body handed back already has the declared type.

                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                    Lean2Js.Decl.eval_out_err

                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                    [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (d : Js.TyDesc) (x : Js.Expr) (code : String) (hx : Js.eval m f jenv x = Except.error code) :
                                                                                                                                                                                                                                                                    Js.eval m (f + 1) jenv (Js.Expr.out d x) = Except.error code

                                                                                                                                                                                                                                                                    And where the body threw, the walk never runs.

                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                      Lean2Js.Decl.evalStmts_const

                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                      [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (name : String) (val : Js.Expr) (v : Js.JsValue) (rest : List Js.Stmt) (h : Js.eval m f jenv val = Except.ok v) :
                                                                                                                                                                                                                                                                      Js.evalStmts m f jenv (Js.Stmt.const name val :: rest) = Js.evalStmts m f ((name, v) :: jenv) rest
                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                        Lean2Js.Decl.evalStmts_const_fail

                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                        [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (name : String) (val : Js.Expr) (e : String) (rest : List Js.Stmt) (h : Js.eval m f jenv val = Except.error e) :
                                                                                                                                                                                                                                                                        Js.evalStmts m f jenv (Js.Stmt.const name val :: rest) = Except.error e
                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                          inductive

                                                                                                                                                                                                                                                                          Lean2Js.Decl.ArgsDecode

                                                                                                                                                                                                                                                                          source

                                                                                                                                                                                                                                                                          What the entry check hands the body: each JS argument, put in the canonical shape its declared type names, is the encoding of the corresponding Value. Key order and keys the type does not name are what the normalisation absorbs, which is why this is weaker than jargs = args.map encodeValue.

                                                                                                                                                                                                                                                                          A function-typed parameter is the one the entry hands through unchecked, so the only argument it decodes is the encoding itself. Decl.isPublic rules that case out at the boundary; it is reachable only from a call inside the program.

                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                              Lean2Js.Decl.ArgsDecode.length

                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                              [Core.Discriminators] {p : Core.Program} {params : List Core.Param} {jargs : List Js.JsValue} {args : List Value} :
                                                                                                                                                                                                                                                                              ArgsDecode p params jargs args → params.length = args.length
                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                Lean2Js.Decl.ArgsDecode.length_jargs

                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                [Core.Discriminators] {p : Core.Program} {params : List Core.Param} {jargs : List Js.JsValue} {args : List Value} :
                                                                                                                                                                                                                                                                                ArgsDecode p params jargs args → params.length = jargs.length
                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                  Lean2Js.Decl.tyDesc_isFn

                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                  {st : Compile.Stack} [Core.Discriminators] {p : Core.Program} {b : Nat} {ty : Core.Ty} {d : Js.TyDesc} (h : Compile.tyDescIn p st b ty = Except.ok d) :

                                                                                                                                                                                                                                                                                  A type the entry check has a descriptor for is not a function type: that is the one case tyDesc refuses, and it is what tells the two ArgsDecode constructors apart.

                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                    Lean2Js.Decl.evalStmts_paramChecks

                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                    [Core.Discriminators] (m : Js.Module) (p : Core.Program) (g : Nat) {params : List Core.Param} {jargs : List Js.JsValue} {args : List Value} (hdec : ArgsDecode p params jargs args) (i : Nat) (checks rest : List Js.Stmt) (jenv : Js.JsEnv) :
                                                                                                                                                                                                                                                                                    Compile.paramChecks p i params = Except.ok checks → Unreserved params → RawBound jenv i jargs → Js.evalStmts m (g + 2) jenv (checks ++ rest) = Js.evalStmts m (g + 2) (checkedBindings params args ++ jenv) rest
                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                      Lean2Js.Decl.argsDecode_encodeValue

                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                      [Core.Discriminators] (p : Core.Program) (hnames : TypesNamesOk p) (params : List Core.Param) (args : List Value) (i : Nat) (checks : List Js.Stmt) :
                                                                                                                                                                                                                                                                                      Compile.paramChecks p i params = Except.ok checks → ParamsTyped p params args → ArgsDecode p params (List.map encodeValue args) args

                                                                                                                                                                                                                                                                                      The canonical spelling is one of the spellings the entry accepts: an argument already in the shape its declared type names passes the check, and the normalisation leaves it where it is. This is what carries the general statement back to the call a declaration makes from inside the program.

                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                        Lean2Js.Decl.evalStmts_paramChecks_sound

                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                        [Core.Discriminators] (m : Js.Module) (p : Core.Program) (hnames : TypesNamesOk p) (g : Nat) (params : List Core.Param) (jargs : List Js.JsValue) (i : Nat) (checks rest : List Js.Stmt) (jenv : Js.JsEnv) :
                                                                                                                                                                                                                                                                                        Compile.paramChecks p i params = Except.ok checks → NoFnParams params → Unreserved params → params.length = jargs.length → RawBound jenv i jargs → Js.dictKeysDistinctList jargs = true → Js.evalStmts m (g + 2) jenv (checks ++ rest) = Except.error "typeError" ∨ ∃ (args : List Value), ArgsDecode p params jargs args ∧ ParamsTyped p params args

                                                                                                                                                                                                                                                                                        Walking the same entry, the other way. At each parameter the check either throws or hands back a Value the argument is the encoding of, so reaching the body at all means every argument decoded.

                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                          Lean2Js.Decl.envCovers_bindParams

                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                          [Core.Discriminators] (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                          params.length = args.length → Correct.EnvCovers (bindParams params args) (List.map (fun (param : Core.Param) => (param.name, param.ty)) params)
                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                            Lean2Js.Decl.checkedBindings_find_none

                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                            [Core.Discriminators] (ps : List Core.Param) (as : List Value) (nm : String) :
                                                                                                                                                                                                                                                                                            (List.map (fun (x : Core.Param) => x.name) ps).contains nm = false → List.find? (fun (x : String × Js.JsValue) => x.fst == nm) (checkedBindings ps as) = none
                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                              Lean2Js.Decl.jsEnvBinds_checkedBindings

                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                              [Core.Discriminators] (params : List Core.Param) (args : List Value) (jenv : Js.JsEnv) :
                                                                                                                                                                                                                                                                                              params.length = args.length → DistinctNames params → ∀ (name : String) (v : Value), (bindParams params args).lookup? name = some v → Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) (checkedBindings params args ++ jenv)) = some (encodeValue v)

                                                                                                                                                                                                                                                                                              The entry check stacks the parameters newest-first, the opposite of bindParams. Distinct parameter names are what make the two agree anyway: only one binding can answer a lookup.

                                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                Lean2Js.Decl.bindParams_scrutFree

                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.bindParams_unreserved

                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                                  Unreserved params → ∀ (name : String) (v : Value), (bindParams params args).lookup? name = some v → isReserved name = false

                                                                                                                                                                                                                                                                                                  Every name the entry binds is a parameter name, and those went through validateIdent.

                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.checkedBindings_fresh

                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (jenv : Js.JsEnv) (hraw : ∀ (name : String) (jv : Js.JsValue), Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) jenv) = some jv → isReserved name = true) (params : List Core.Param) (args : List Value) (name : String) (jv : Js.JsValue) :
                                                                                                                                                                                                                                                                                                    isReserved name = false → Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) (checkedBindings params args ++ jenv)) = some jv → ∃ (v : Value), (bindParams params args).lookup? name = some v

                                                                                                                                                                                                                                                                                                    Beyond the parameters the entry binds, the generated environment holds only the raw arguments, whose names carry the reserved prefix. So an unreserved name the generated code can read is one the reference environment binds too — which is what a call needs, since it reads its callee out of the environment.

                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.bindAll_rawParams_reserved

                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                      [Core.Discriminators] (params : List Core.Param) (jargs : List Js.JsValue) (i : Nat) (name : String) (jv : Js.JsValue) :
                                                                                                                                                                                                                                                                                                      Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) (Js.bindAll (Compile.rawParams i params) jargs)) = some jv → isReserved name = true

                                                                                                                                                                                                                                                                                                      The raw arguments the generated function is handed are bound to reserved names only.

                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.rawParam_notBody

                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.bindAll_rawParams_notBody

                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (params : List Core.Param) (jargs : List Js.JsValue) (i : Nat) (name : String) (jv : Js.JsValue) :
                                                                                                                                                                                                                                                                                                          Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) (Js.bindAll (Compile.rawParams i params) jargs)) = some jv → isBodyName name = false

                                                                                                                                                                                                                                                                                                          The raw arguments are bound outside the body prefix as well as inside the reserved one, which is what keeps a call the compiler redirected to a body from being shadowed by one of them.

                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.checkedBindings_notBody

                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (params : List Core.Param) (args : List Value) (name : String) (jv : Js.JsValue) :
                                                                                                                                                                                                                                                                                                            Unreserved params → Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) (checkedBindings params args)) = some jv → isBodyName name = false

                                                                                                                                                                                                                                                                                                            Nothing the entry check binds carries the body prefix: every name it binds is a parameter name, and those went through validateIdent.

                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.jsEnvAgrees_checkedBindings

                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                              [Core.Discriminators] (params : List Core.Param) (args : List Value) (jenv : Js.JsEnv) (hlen : params.length = args.length) (hdist : DistinctNames params) (hres : Unreserved params) (hraw : ∀ (name : String) (jv : Js.JsValue), Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) jenv) = some jv → isReserved name = true) (hrawb : ∀ (name : String) (jv : Js.JsValue), Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) jenv) = some jv → isBodyName name = false) :
                                                                                                                                                                                                                                                                                                              Correct.JsEnvAgrees (bindParams params args) (checkedBindings params args ++ jenv)
                                                                                                                                                                                                                                                                                                              Used by

                                                                                                                                                                                                                                                                                                                The arguments the entry hands the body #

                                                                                                                                                                                                                                                                                                                The entry check binds every parameter under its declared name and then calls the body with those names. Walking that call needs one lookup per parameter, which is what ParamBound lines up.

                                                                                                                                                                                                                                                                                                                def

                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.ParamBound

                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.name_of_lookup_bindParams

                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (ps : List Core.Param) (as : List Value) (name : String) (v : Value) :
                                                                                                                                                                                                                                                                                                                    (bindParams ps as).lookup? name = some v → name ∈ List.map (fun (x : Core.Param) => x.name) ps
                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.paramBound_of_binds

                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                      [Core.Discriminators] (params : List Core.Param) (args : List Value) (jenv : Js.JsEnv) :
                                                                                                                                                                                                                                                                                                                      params.length = args.length → DistinctNames params → (∀ (name : String) (v : Value), (bindParams params args).lookup? name = some v → Option.map (fun (x : String × Js.JsValue) => x.snd) (List.find? (fun (x : String × Js.JsValue) => x.fst == name) jenv) = some (encodeValue v)) → ParamBound jenv params args
                                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.evalList_paramIdents

                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                        [Core.Discriminators] (m : Js.Module) (g : Nat) (jenv : Js.JsEnv) (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                                                        ParamBound jenv params args → Js.evalList m (g + 1) jenv (Compile.paramIdents params) = Except.ok (List.map encodeValue args)
                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.bindAll_paramNames

                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                                                          params.length = args.length → Js.bindAll (List.map (fun (x : Core.Param) => x.name) params) (List.map encodeValue args) = Correct.encodeEnv (bindParams params args)

                                                                                                                                                                                                                                                                                                                          The body function runs its declaration under exactly the environment the reference semantics does. bindAll binds the parameters in declared order, which is the order bindParams binds them in, so the generated environment is the encoding of the reference one and nothing more.

                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.jsEnvAgrees_bindParams

                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (params : List Core.Param) (args : List Value) (hlen : params.length = args.length) (hres : Unreserved params) :
                                                                                                                                                                                                                                                                                                                            Correct.JsEnvAgrees (bindParams params args) (Js.bindAll (List.map (fun (x : Core.Param) => x.name) params) (List.map encodeValue args))
                                                                                                                                                                                                                                                                                                                            Used by

                                                                                                                                                                                                                                                                                                                              The body as statements #

                                                                                                                                                                                                                                                                                                                              compileBody opens the lets lined up at the head of a function into const statements instead of nesting arrows, so the fragment's expression-level result has to be walked back along that list.

                                                                                                                                                                                                                                                                                                                              def

                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.EventuallyStmts

                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                              (m : Js.Module) (jenv : Js.JsEnv) (stmts : List Js.Stmt) (v : Js.JsValue) :
                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.evalStmts_ret

                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (m : Js.Module) (f : Nat) (jenv : Js.JsEnv) (je : Js.Expr) (rest : List Js.Stmt) :
                                                                                                                                                                                                                                                                                                                                  Js.evalStmts m f jenv (Js.Stmt.ret je :: rest) = Js.eval m f jenv je
                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.compileBody_finish

                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (m : Js.Module) (p : Core.Program) (hsig : Correct.SignatureOk p) (hprog : ProgramTyped p) (f : Nat) (iha : Correct.AgreesAt p m f) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {acc stmts : List Js.Stmt} {ty : Core.Ty} {v : Value} (hc : Compile.compileFinish p ctx e acc = Except.ok (stmts, ty)) (henv : EnvTyped p env ctx) (hjenv : Correct.JsEnvAgrees env jenv) (he : evalExpr p f env e = Except.ok v) :
                                                                                                                                                                                                                                                                                                                                    ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner ∧ EventuallyStmts m jenv inner (encodeValue v)
                                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.compileBody_correct

                                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                                      [Core.Discriminators] (m : Js.Module) (p : Core.Program) (hsig : Correct.SignatureOk p) (hprog : ProgramTyped p) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {acc stmts : List Js.Stmt} {ty : Core.Ty} {v : Value} {f' : Nat} :
                                                                                                                                                                                                                                                                                                                                      f' ≤ f → Compile.compileBody p ctx e acc = Except.ok (stmts, ty) → EnvTyped p env ctx → Correct.JsEnvAgrees env jenv → evalExpr p f' env e = Except.ok v → ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner ∧ EventuallyStmts m jenv inner (encodeValue v)
                                                                                                                                                                                                                                                                                                                                      Used by

                                                                                                                                                                                                                                                                                                                                        The body throws #

                                                                                                                                                                                                                                                                                                                                        The mirror of the three above. What travels is the thrown code, so a let whose value throws does not need its body compiled to anything in particular — only to exist, which is what compileBody_shape says.

                                                                                                                                                                                                                                                                                                                                        def

                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.EventuallyStmtsErr

                                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                                        (m : Js.Module) (jenv : Js.JsEnv) (stmts : List Js.Stmt) (code : String) :
                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.compileFinish_shape

                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {e : Core.Expr} {acc stmts : List Js.Stmt} {ty : Core.Ty} (hc : Compile.compileFinish p ctx e acc = Except.ok (stmts, ty)) :
                                                                                                                                                                                                                                                                                                                                            ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner
                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.compileFinish_type

                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                              [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {e : Core.Expr} {acc stmts : List Js.Stmt} {ty : Core.Ty} (hc : Compile.compileFinish p ctx e acc = Except.ok (stmts, ty)) :

                                                                                                                                                                                                                                                                                                                                              The type compileFinish returns is the one compileExpr gave the expression it wrapped.

                                                                                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.compileBody_type

                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (e : Core.Expr) (ctx : Compile.Ctx) (acc stmts : List Js.Stmt) (ty : Core.Ty) :

                                                                                                                                                                                                                                                                                                                                                The type compileBody gives an expression is the one compileExpr gives it. The leading lets it opens into statements are the ones compileExpr would have put in an arrow, and both check the same things in the same order. Only the let is worth reading; every other shape goes straight to compileFinish, which is compileExpr with the value wrapped in a return.

                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.compileBody_shape

                                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {acc stmts : List Js.Stmt} {ty : Core.Ty} :
                                                                                                                                                                                                                                                                                                                                                  Compile.compileBody p ctx e acc = Except.ok (stmts, ty) → ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner
                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.compileBody_finish_traps

                                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (m : Js.Module) (p : Core.Program) (hsig : Correct.SignatureOk p) (hprog : ProgramTyped p) (f : Nat) (iha : Correct.AgreesAt p m f) (iht : Correct.TrapsAt p m f) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {acc stmts : List Js.Stmt} {ty : Core.Ty} {err : Err} (hc : Compile.compileFinish p ctx e acc = Except.ok (stmts, ty)) (henv : EnvTyped p env ctx) (hcov : Correct.EnvCovers env ctx) (hjenv : Correct.JsEnvAgrees env jenv) (he : evalExpr p f env e = Except.error err) (hne : Correct.Mirrorable err) :
                                                                                                                                                                                                                                                                                                                                                    ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner ∧ EventuallyStmtsErr m jenv inner err.code
                                                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.compileBody_traps

                                                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                                                      [Core.Discriminators] (m : Js.Module) (p : Core.Program) (hsig : Correct.SignatureOk p) (hprog : ProgramTyped p) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (iht : ∀ (g : Nat), g ≤ f → Correct.TrapsAt p m g) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {acc stmts : List Js.Stmt} {ty : Core.Ty} {err : Err} {f' : Nat} :
                                                                                                                                                                                                                                                                                                                                                      f' ≤ f → Compile.compileBody p ctx e acc = Except.ok (stmts, ty) → EnvTyped p env ctx → Correct.EnvCovers env ctx → Correct.JsEnvAgrees env jenv → evalExpr p f' env e = Except.error err → Correct.Mirrorable err → ∃ (inner : List Js.Stmt), stmts = acc.reverse ++ inner ∧ EventuallyStmtsErr m jenv inner err.code
                                                                                                                                                                                                                                                                                                                                                      Used by

                                                                                                                                                                                                                                                                                                                                                        One public function #

                                                                                                                                                                                                                                                                                                                                                        The pieces meet here. compileProgram compiles a declaration against the whole program and callFunction runs the result; evalCall checks the arguments against the declaration and runs the body. What is left is to read both apart and line them up.

                                                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.rawParams_length

                                                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                                                        [Core.Discriminators] (params : List Core.Param) (i : Nat) :
                                                                                                                                                                                                                                                                                                                                                        (Compile.rawParams i params).length = params.length
                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.unreserved_of_validated

                                                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (params : List Core.Param) :
                                                                                                                                                                                                                                                                                                                                                          (params.forM fun (param : Core.Param) => validateIdent "parameter" param.name) = Except.ok () → Unreserved params
                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.distinctNames_of_validated

                                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (params : List Core.Param) :
                                                                                                                                                                                                                                                                                                                                                            validateDistinct "parameter" (List.map (fun (x : Core.Param) => x.name) params) = Except.ok () → DistinctNames params
                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.paramsTyped_of_all

                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                              [Core.Discriminators] (p : Core.Program) (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                                                                                              params.length = args.length → ((params.zip args).all fun (x : Core.Param × Value) => match x with | (param, v) => Value.hasTy p v param.ty) = true → ParamsTyped p params args
                                                                                                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.all_of_paramsTyped

                                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                                                                                                                                                                                ParamsTyped p params args → ((params.zip args).all fun (x : Core.Param × Value) => match x with | (param, v) => Value.hasTy p v param.ty) = true
                                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.evalCall_body

                                                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] {p : Core.Program} {fn : String} {args : List Value} {d : Core.Decl} (hd : p.find? fn = some d) (hlen : d.params.length = args.length) (htyped : ParamsTyped p d.params args) :
                                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.evalCall_inv

                                                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] {p : Core.Program} {fn : String} {args : List Value} {v : Value} {d : Core.Decl} (hd : p.find? fn = some d) (h : evalCall p fn args = Except.ok v) :
                                                                                                                                                                                                                                                                                                                                                                    Used by

                                                                                                                                                                                                                                                                                                                                                                      The type declarations the arm chain reads #

                                                                                                                                                                                                                                                                                                                                                                      Correct.SignatureOk is what the match case of the fragment assumes about the program's types. compileProgram checks it before it compiles anything, so a module the compiler produced carries it.

                                                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.forM_ok

                                                                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                                                                      [Core.Discriminators] {α : Type} {f : α → Except String Unit} (l : List α) :
                                                                                                                                                                                                                                                                                                                                                                      l.forM f = Except.ok () → ∀ (a : α), a ∈ l → f a = Except.ok ()
                                                                                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.nodup_of_validateDistinct

                                                                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                                                                        [Core.Discriminators] {kind : String} {names : List String} {u : Unit} :
                                                                                                                                                                                                                                                                                                                                                                        validateDistinct kind names = Except.ok u → names.Nodup
                                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.keyFor_of_keyDeclared

                                                                                                                                                                                                                                                                                                                                                                          source

                                                                                                                                                                                                                                                                                                                                                                          The key a constructor's name is carried under is the one its type declares, which is what Compile.keyDeclared refuses a program for not saying.

                                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.validateType_ctors

                                                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.validateType_ctorNames

                                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.ctorsAt_names

                                                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] {t : Core.TypeDef} {args : List Core.Ty} {c : Core.CtorDef} (hc : c ∈ t.ctorsAt args) :
                                                                                                                                                                                                                                                                                                                                                                                ∃ (c0 : Core.CtorDef), c0 ∈ t.ctors ∧ c.name = c0.name ∧ List.map (fun (x : Core.Field) => x.name) c.fields = List.map (fun (x : Core.Field) => x.name) c0.fields
                                                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.typesNamesOk_of_compileProgram

                                                                                                                                                                                                                                                                                                                                                                                  source

                                                                                                                                                                                                                                                                                                                                                                                  The same reading of a validated program, in the form Compile.tyDesc walks: findType? and the constructors it expands, rather than Compile.signature.

                                                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.signatureOk_of_compileProgram

                                                                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.compileDecl_shape

                                                                                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.compileDecls_find

                                                                                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                                                                                        [Core.Discriminators] (p : Core.Program) (i : Nat) (decls : List Core.Decl) (funcs : List Js.Func) (fn : String) (d : Core.Decl) :
                                                                                                                                                                                                                                                                                                                                                                                        Compile.compileDecls p i decls = Except.ok funcs → (∀ (d' : Core.Decl), d' ∈ decls → isReserved d'.name = false) → List.find? (fun (x : Core.Decl) => x.name == fn) decls = some d → ∃ (fs : Js.Func × Js.Func), Compile.compileDecl p d = Except.ok fs ∧ List.find? (fun (x : Js.Func) => x.name == fn) funcs = some fs.fst ∧ List.find? (fun (x : Js.Func) => x.name == bodyName fn) funcs = some fs.snd

                                                                                                                                                                                                                                                                                                                                                                                        The two functions a declaration compiles to, found under the two names it takes. Both lookups are one theorem because the walk that skips a declaration's entry has to skip its body in the same step.

                                                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.compileDecls_mem

                                                                                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (p : Core.Program) (i : Nat) (decls : List Core.Decl) (funcs : List Js.Func) (d : Core.Decl) :
                                                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.programTyped_of_compileProgram

                                                                                                                                                                                                                                                                                                                                                                                            source

                                                                                                                                                                                                                                                                                                                                                                                            Every declaration of a program the compiler accepted compiles, under the context its parameters give, at the type it is declared to return. This is what a proof that reaches a call needs about the callee.

                                                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.compileProgram_find

                                                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                                                              Used by

                                                                                                                                                                                                                                                                                                                                                                                                The two levels, one induction #

                                                                                                                                                                                                                                                                                                                                                                                                A call runs the callee's body at one less fuel than the call itself, and the callee is a declaration, so the expression-level statement and the declaration-level one have to be proved together. Both are stated at one amount of fuel and the induction below hands each the other at the fuel it needs.

                                                                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.argsDecode_of_compileProgram

                                                                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] {p : Core.Program} {m : Js.Module} {fn : String} {d : Core.Decl} {args : List Value} (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (htyped : ParamsTyped p d.params args) :

                                                                                                                                                                                                                                                                                                                                                                                                Every declaration a compiled program has accepts the canonical spelling of its arguments: the one encodeValue writes. This is the hypothesis a caller who has not reordered anything discharges.

                                                                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.decl_agrees_body

                                                                                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (fn : String) (d : Core.Decl) (args : List Value) (v : Value) (hd : p.find? fn = some d) (hlen : d.params.length = args.length) (htyped : ParamsTyped p d.params args) (hbody : evalExpr p f (bindParams d.params args) d.body = Except.ok v) :
                                                                                                                                                                                                                                                                                                                                                                                                  ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' (bodyName fn) (List.map encodeValue args) = Except.ok (encodeValue v)

                                                                                                                                                                                                                                                                                                                                                                                                  The body function at one fuel, from the expression-level statement at every fuel up to it. This is where the compiled expression actually runs: the arguments arrive already encoded, under their declared names, and nothing is checked on the way in.

                                                                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.decl_traps_body

                                                                                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (iht : ∀ (g : Nat), g ≤ f → Correct.TrapsAt p m g) (fn : String) (d : Core.Decl) (args : List Value) (err : Err) (hd : p.find? fn = some d) (hlen : d.params.length = args.length) (htyped : ParamsTyped p d.params args) (hbody : evalExpr p f (bindParams d.params args) d.body = Except.error err) (hne : Correct.Mirrorable err) :
                                                                                                                                                                                                                                                                                                                                                                                                    ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' (bodyName fn) (List.map encodeValue args) = Except.error err.code

                                                                                                                                                                                                                                                                                                                                                                                                    The same on the other side.

                                                                                                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.hasTy_ret_of_body

                                                                                                                                                                                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                                                                                                                                                                                      [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (fn : String) (d : Core.Decl) (args : List Value) (v : Value) (hd : p.find? fn = some d) (htyped : ParamsTyped p d.params args) (hbody : evalExpr p f (bindParams d.params args) d.body = Except.ok v) :

                                                                                                                                                                                                                                                                                                                                                                                                      The value a declaration's body returns has the type the declaration was declared at. The entry reads its result back out through that type, so this is what the walk out is given.

                                                                                                                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.decl_agrees_jargs

                                                                                                                                                                                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                                                                                                                                                                                        [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) (v : Value) (hd : p.find? fn = some d) (htyped : ParamsTyped p d.params args) (hdec : ArgsDecode p d.params jargs args) (hbody : evalExpr p f (bindParams d.params args) d.body = Except.ok v) :
                                                                                                                                                                                                                                                                                                                                                                                                        ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.ok (encodeAt p d.ret v)

                                                                                                                                                                                                                                                                                                                                                                                                        The declaration-level statement at one fuel, at every spelling of the arguments the entry check accepts. The entry checks its arguments, binds them under their declared names, hands them to the body and reads the result back out through the declared return type, so this is decl_agrees_body with the check the body did not run in front of it and the walk out behind it.

                                                                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.decl_traps_jargs

                                                                                                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (iht : ∀ (g : Nat), g ≤ f → Correct.TrapsAt p m g) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) (err : Err) (hd : p.find? fn = some d) (htyped : ParamsTyped p d.params args) (hdec : ArgsDecode p d.params jargs args) (hbody : evalExpr p f (bindParams d.params args) d.body = Except.error err) (hne : Correct.Mirrorable err) :
                                                                                                                                                                                                                                                                                                                                                                                                          ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.error err.code

                                                                                                                                                                                                                                                                                                                                                                                                          The same on the other side.

                                                                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.decl_agrees_at

                                                                                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) :

                                                                                                                                                                                                                                                                                                                                                                                                            What the mutual induction needs for a call through a function value, which goes to the entry.

                                                                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.decl_body_agrees_at

                                                                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                                                                              [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) :

                                                                                                                                                                                                                                                                                                                                                                                                              And for a call whose callee the compiler read off the program, which goes to the body.

                                                                                                                                                                                                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.decl_traps_at

                                                                                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (iht : ∀ (g : Nat), g ≤ f → Correct.TrapsAt p m g) :

                                                                                                                                                                                                                                                                                                                                                                                                                The same on the other side.

                                                                                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.decl_body_traps_at

                                                                                                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) (f : Nat) (iha : ∀ (g : Nat), g ≤ f → Correct.AgreesAt p m g) (iht : ∀ (g : Nat), g ≤ f → Correct.TrapsAt p m g) :

                                                                                                                                                                                                                                                                                                                                                                                                                  And the body on the other side.

                                                                                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.find?_of_mem_nodup

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

                                                                                                                                                                                                                                                                                                                                                                                                                    Distinct names make membership and lookup the same thing.

                                                                                                                                                                                                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.moduleHasDecls_of_compileProgram

                                                                                                                                                                                                                                                                                                                                                                                                                      source

                                                                                                                                                                                                                                                                                                                                                                                                                      Every declaration of a compiled program has a function of its own name in the module.

                                                                                                                                                                                                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                                                                                                                                                                                                        Lean2Js.Decl.levels

                                                                                                                                                                                                                                                                                                                                                                                                                        source

                                                                                                                                                                                                                                                                                                                                                                                                                        The two directions at every fuel up to a bound. The step lemmas take the level below, and the declaration-level statements at that level come from the expression-level ones, so one induction settles both. The bound is what a body of nested lets needs: each let the entry opens costs one fuel.

                                                                                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.fragment_correct_in

                                                                                                                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {je : Js.Expr} {ty : Core.Ty} {f : Nat} {v : Value} :
                                                                                                                                                                                                                                                                                                                                                                                                                          EnvTyped p env ctx → Correct.JsEnvAgrees env jenv → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.ok v → Correct.Eventually m jenv je (encodeValue v)

                                                                                                                                                                                                                                                                                                                                                                                                                          If the reference semantics returns a value, the generated code returns the same value.

                                                                                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.fragment_correct

                                                                                                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {je : Js.Expr} {ty : Core.Ty} {f : Nat} {v : Value} :
                                                                                                                                                                                                                                                                                                                                                                                                                            EnvTyped p env ctx → (∀ (name : String) (w : Value), env.lookup? name = some w → isReserved name = false) → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.ok v → Correct.Eventually m (Correct.encodeEnv env) je (encodeValue v)

                                                                                                                                                                                                                                                                                                                                                                                                                            The shape the manifest quotes: the generated environment is exactly the encoded one.

                                                                                                                                                                                                                                                                                                                                                                                                                            The environment must bind no reserved name. Two things need it: match gives its scrutinee one, and a call reads its callee out of the environment, so a binding the generated code cannot have would send the two sides to different declarations. Every name a program can bind went through validateIdent, which rejects the prefix, so an environment a compiled declaration builds satisfies it.

                                                                                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.fragment_traps_in

                                                                                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                                                                                              [Core.Discriminators] (p : Core.Program) (m : Js.Module) (hm : Compile.compileProgram p = Except.ok m) {e : Core.Expr} (hfrag : Correct.InFragment e) {ctx : Compile.Ctx} {env : Env} {jenv : Js.JsEnv} {je : Js.Expr} {ty : Core.Ty} {f : Nat} {err : Err} :
                                                                                                                                                                                                                                                                                                                                                                                                                              EnvTyped p env ctx → Correct.EnvCovers env ctx → Correct.JsEnvAgrees env jenv → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.error err → Correct.Mirrorable err → Correct.EventuallyErr m jenv je err.code

                                                                                                                                                                                                                                                                                                                                                                                                                              If the reference semantics refuses, the generated code refuses with the same thrown code, for the failures Correct.Mirrorable names.

                                                                                                                                                                                                                                                                                                                                                                                                                              Used by

                                                                                                                                                                                                                                                                                                                                                                                                                                One public function #

                                                                                                                                                                                                                                                                                                                                                                                                                                What a caller of an exported function gets: for any JS arguments the entry check accepts, if the reference semantics returns a value then the generated module's function returns the same value, at every large enough amount of the model's fuel. The run-time agreement check's "the vectors we tried agreed" replaced by "any arguments at all", for every declaration the program has.

                                                                                                                                                                                                                                                                                                                                                                                                                                ArgsDecode is the spelling the claim is at, and it is the whole set the entry admits: key order and keys the declared type does not name are absorbed by the normalisation, so {currency, amount} and {amount, currency} are both covered, and decl_refuses says everything else throws.

                                                                                                                                                                                                                                                                                                                                                                                                                                The value is read through the type the declaration was declared to return, which is encodeValue v wherever that type reaches no dictionary crossing as a plain object — encodeAt_eq_encodeValue_of_desc and Agree.encodeAt_eq_encodeValue are the two readings of that, and every claim a package makes today is stated through one of them.

                                                                                                                                                                                                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                Lean2Js.Decl.decl_correct

                                                                                                                                                                                                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (m : Js.Module) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) (v : Value) (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (hdec : ArgsDecode p d.params jargs args) (he : evalCall p fn args = Except.ok v) :
                                                                                                                                                                                                                                                                                                                                                                                                                                ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.ok (encodeAt p d.ret v)
                                                                                                                                                                                                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                  Lean2Js.Decl.decl_traps

                                                                                                                                                                                                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                                                                                                                                                                                                  [Core.Discriminators] (p : Core.Program) (m : Js.Module) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) (err : Err) (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (htyped : ParamsTyped p d.params args) (hdec : ArgsDecode p d.params jargs args) (he : evalCall p fn args = Except.error err) (hne : Correct.Mirrorable err) :
                                                                                                                                                                                                                                                                                                                                                                                                                                  ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.error err.code

                                                                                                                                                                                                                                                                                                                                                                                                                                  The companion to decl_correct on the other side of the reference semantics. For arguments the entry accepts, if eval throws then the generated module's function throws the same code.

                                                                                                                                                                                                                                                                                                                                                                                                                                  The failures this carries are the ones Correct.Mirrorable names: every one but outOfFuel, which is the reference side's alone.

                                                                                                                                                                                                                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                    Lean2Js.Decl.decl_traps_at_cost

                                                                                                                                                                                                                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                                                                                                                                                                                                                    [Core.Discriminators] (p : Core.Program) (m : Js.Module) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) (err : Err) (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (hpub : d.paramsCheckable = true) (hok : Cost.progOk p = true) (hfuel : Cost.cost p ≤ defaultFuel) (htyped : ParamsTyped p d.params args) (hdec : ArgsDecode p d.params jargs args) (he : evalCall p fn args = Except.error err) :
                                                                                                                                                                                                                                                                                                                                                                                                                                    ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.error err.code

                                                                                                                                                                                                                                                                                                                                                                                                                                    The same claim with no fuel disclaimer. Cost.progOk and the fuel bound are decided from the program alone, once, by the emitter -- so what could not be discharged from the result is now discharged from the input, and outOfFuel is simply not among the answers eval can give.

                                                                                                                                                                                                                                                                                                                                                                                                                                    Used by

                                                                                                                                                                                                                                                                                                                                                                                                                                      The entry refuses #

                                                                                                                                                                                                                                                                                                                                                                                                                                      The mirror of decl_correct. The entry check never looks at the body, so this direction does not ask for InFragment. What it does ask for is paramsCheckable — a function-typed parameter is handed straight through, because JS offers no way to check a function's signature at run time. Every exported declaration satisfies it, and so does an internal one whose parameters have a shape: what the entry refuses does not depend on whether the entry is exported.

                                                                                                                                                                                                                                                                                                                                                                                                                                      def

                                                                                                                                                                                                                                                                                                                                                                                                                                      Lean2Js.Decl.EvalAccepts

                                                                                                                                                                                                                                                                                                                                                                                                                                      source

                                                                                                                                                                                                                                                                                                                                                                                                                                      The arguments the reference semantics lets into the body: a decoding of the JS arguments whose length and types are the ones the declaration asked for.

                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                          Lean2Js.Decl.noFnParams_of_checkable

                                                                                                                                                                                                                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                                                                                                                                                                                                                          [Core.Discriminators] (params : List Core.Param) :
                                                                                                                                                                                                                                                                                                                                                                                                                                          (params.all fun (param : Core.Param) => !param.ty.isFn) = true → NoFnParams params
                                                                                                                                                                                                                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                            Lean2Js.Decl.decl_refuses

                                                                                                                                                                                                                                                                                                                                                                                                                                            source
                                                                                                                                                                                                                                                                                                                                                                                                                                            [Core.Discriminators] (p : Core.Program) (m : Js.Module) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (hpub : d.paramsCheckable = true) (hk : Js.dictKeysDistinctList jargs = true) (hno : ¬EvalAccepts p d jargs) (g : Nat) :
                                                                                                                                                                                                                                                                                                                                                                                                                                            2 ≤ g → Js.callFunctionAt m g fn jargs = Except.error "typeError"

                                                                                                                                                                                                                                                                                                                                                                                                                                            What a caller of an exported function cannot get past. If no decoding of the JS arguments is one the reference semantics would accept — the wrong number of them, or one whose shape breaks the declared type — the generated module's function throws instead of running the body.

                                                                                                                                                                                                                                                                                                                                                                                                                                            dictKeysDistinctList is the assumption the model needs and the runtime supplies: the check is handed a Map, which cannot hold one key twice, where this model holds a dictionary as an association list.

                                                                                                                                                                                                                                                                                                                                                                                                                                            The fuel is not existential the way decl_correct's is. The check is one call of checkTy, a Bool function whose recursion the model does not pay for, so two is enough however deep the type.

                                                                                                                                                                                                                                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                                                                                                                                                                                                                                              Lean2Js.Decl.decl_refuses_call

                                                                                                                                                                                                                                                                                                                                                                                                                                              source
                                                                                                                                                                                                                                                                                                                                                                                                                                              [Core.Discriminators] (p : Core.Program) (m : Js.Module) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (hm : Compile.compileProgram p = Except.ok m) (hd : p.find? fn = some d) (hpub : d.paramsCheckable = true) (hk : Js.dictKeysDistinctList jargs = true) (hno : ¬EvalAccepts p d jargs) :
                                                                                                                                                                                                                                                                                                                                                                                                                                              Js.callFunction m fn jargs = Except.error "typeError"

                                                                                                                                                                                                                                                                                                                                                                                                                                              The same at the fuel the shipped artifact runs at.

                                                                                                                                                                                                                                                                                                                                                                                                                                              Used by