lean2js

Lean2Js.Sound

source

Type soundness: a value eval returns satisfies the type the compiler read #

Type soundness: if the compiler judged an expression to have type T and eval returns a value for it, that value satisfies T.

Compiler correctness needs this because the generated code branches on the type of its operands: a + b is __i53(a + b) for Int53 and string concatenation for String. Without a statement tying the type the compiler read out of its context to the value the environment actually holds, that case split cannot be closed.

What this covers #

TypeChecked names the expression forms the proof reaches. call is not among them: a call's type is the callee's declared return type, so covering it means covering every form any declaration's body can use, and the induction would have to carry the whole program's well-typedness. Outside TypeChecked, Agree.checkAgreement checks the shipped artifact at run time.

Which key a constructor is carried under does not reach a type: the statements below are about eval and the types the compiler read, and hold for whatever reading the program declares.

structure

Lean2Js.EnvTyped

source
(p : Core.Program) (env : Env) (ctx : Compile.Ctx) :

Every name the compiler's context has typed holds, if the environment binds it at all, a value of that type, and every name it binds is one the context has.

The second half is what a call and a function reference need. eval reads the callee out of the environment while the generated code was compiled against the context, so a name the context did not have would send the two sides to different declarations.

Instances For
    Used by
      inductive

      Lean2Js.TypeChecked

      source

      The expression forms type soundness reaches.

      Instances For
        Used by
          theorem

          Lean2Js.TypeChecked.all

          source

          Every shape of the subset type checks. The judgement covers the syntax, so the induction it drives reads as a case analysis on the expression.

          Used by
            theorem

            Lean2Js.TypeChecked.allList

            source
            Used by
              theorem

              Lean2Js.TypeChecked.allValues

              source
              [Core.Discriminators] (entries : List (String × Core.Expr)) (entry : String × Core.Expr) :
              entry ∈ entries → TypeChecked entry.snd
              Used by
                theorem

                Lean2Js.TypeChecked.allAlts

                source
                [Core.Discriminators] (alts : List Core.Alt) (alt : Core.Alt) :
                alt ∈ alts → TypeChecked alt.body
                Used by
                  theorem

                  Lean2Js.Ty.beq_refl

                  source
                  Used by
                    theorem

                    Lean2Js.Ty.beqList_refl

                    source
                    Used by
                      theorem

                      Lean2Js.tyList_beq_refl

                      source

                      Reflexivity for the plain list comparison the entry check and the signatures use, which goes through List's own BEq rather than Ty.beqList.

                      Used by
                        theorem

                        Lean2Js.Ty.eq_of_beq

                        source
                        [Core.Discriminators] {a b : Core.Ty} :
                        a.beq b = true → a = b
                        Used by
                          theorem

                          Lean2Js.Ty.eq_of_beqList

                          source
                          [Core.Discriminators] {as bs : List Core.Ty} :
                          Core.Ty.beqList as bs = true → as = bs
                          Used by
                            theorem

                            Lean2Js.Ty.eq_of_not_bne

                            source
                            [Core.Discriminators] {a b : Core.Ty} (h : ¬(a != b) = true) :
                            a = b
                            Used by
                              theorem

                              Lean2Js.hasTy_bool_inv

                              source
                              Used by
                                theorem

                                Lean2Js.hasTy_int53_inv

                                source
                                Used by
                                  theorem

                                  Lean2Js.hasTy_uint32_inv

                                  source
                                  Used by
                                    theorem

                                    Lean2Js.hasTy_string_inv

                                    source
                                    Used by
                                      theorem

                                      Lean2Js.hasTy_array_inv

                                      source
                                      [Core.Discriminators] {p : Core.Program} {v : Value} {elem : Core.Ty} (h : Value.hasTy p v elem.array = true) :
                                      Used by
                                        theorem

                                        Lean2Js.hasTy_bigint_inv

                                        source
                                        Used by
                                          theorem

                                          Lean2Js.hasTy_named_inv

                                          source
                                          [Core.Discriminators] {p : Core.Program} {v : Value} {n : String} {args : List Core.Ty} (h : Value.hasTy p v (Core.Ty.named n args) = true) :
                                          ∃ (ctor : String), ∃ (fields : List (String × Value)), v = Value.obj ctor fields
                                          Used by
                                            theorem

                                            Lean2Js.hasTy_option_inv

                                            source
                                            [Core.Discriminators] {p : Core.Program} {v : Value} {elem : Core.Ty} (h : Value.hasTy p v elem.option = true) :
                                            ∃ (ctor : String), ∃ (fields : List (String × Value)), v = Value.obj ctor fields
                                            Used by
                                              theorem

                                              Lean2Js.hasTy_result_inv

                                              source
                                              [Core.Discriminators] {p : Core.Program} {v : Value} {ok err : Core.Ty} (h : Value.hasTy p v (ok.result err) = true) :
                                              ∃ (ctor : String), ∃ (fields : List (String × Value)), v = Value.obj ctor fields
                                              Used by
                                                theorem

                                                Lean2Js.hasTy_dict_inv

                                                source
                                                [Core.Discriminators] {p : Core.Program} {v : Value} {elem : Core.Ty} (h : Value.hasTy p v elem.dict = true) :
                                                ∃ (entries : List (String × Value)), v = Value.dict entries
                                                Used by
                                                  theorem

                                                  Lean2Js.hasTy_dictObj_inv

                                                  source
                                                  [Core.Discriminators] {p : Core.Program} {v : Value} {elem : Core.Ty} (h : Value.hasTy p v elem.dictObj = true) :
                                                  ∃ (entries : List (String × Value)), v = Value.dict entries
                                                  Used by
                                                    theorem

                                                    Lean2Js.hasTy_of_dictValueTy

                                                    source
                                                    [Core.Discriminators] {p : Core.Program} {v : Value} {td value : Core.Ty} (h : Compile.dictValueTy td = some value) :
                                                    Value.hasTy p v td = Value.hasTy p v value.dict

                                                    A receiver a dictionary operation accepted holds exactly what the Map spelling asks for, whichever of the two the author declared. This is what lets the four cases below read either receiver through the .dict lemmas rather than through two copies of each.

                                                    Used by
                                                      theorem

                                                      Lean2Js.hasTy_fn_inv

                                                      source
                                                      [Core.Discriminators] {p : Core.Program} {v : Value} {params : List Core.Ty} {ret : Core.Ty} (h : Value.hasTy p v (Core.Ty.fn params ret) = true) :
                                                      ∃ (name : String), v = Value.fn name
                                                      Used by
                                                        theorem

                                                        Lean2Js.tyList_eq_of_beq

                                                        source
                                                        [Core.Discriminators] {as bs : List Core.Ty} :
                                                        (as == bs) = true → as = bs

                                                        Soundness of the plain list comparison, matching tyList_beq_refl.

                                                        Used by
                                                          theorem

                                                          Lean2Js.hasTy_fnValue_inv

                                                          source
                                                          [Core.Discriminators] {p : Core.Program} {name : String} {ty : Core.Ty} (h : Value.hasTy p (Value.fn name) ty = true) :
                                                          ∃ (params : List Core.Ty), ∃ (ret : Core.Ty), ty = Core.Ty.fn params ret

                                                          The converse direction: a function value satisfies no type but a function type. What a call needs, since eval reads the callee out of the environment.

                                                          Used by
                                                            theorem

                                                            Lean2Js.hasTy_var_inv

                                                            source
                                                            Used by
                                                              theorem

                                                              Lean2Js.hasTy_named_fields

                                                              source
                                                              [Core.Discriminators] {p : Core.Program} {ctor : String} {fields : List (String × Value)} {n : String} {args : List Core.Ty} (h : Value.hasTy p (Value.obj ctor fields) (Core.Ty.named n args) = true) :
                                                              Used by
                                                                theorem

                                                                Lean2Js.hasTy_option_fields

                                                                source
                                                                [Core.Discriminators] {p : Core.Program} {ctor : String} {fields : List (String × Value)} {elem : Core.Ty} (h : Value.hasTy p (Value.obj ctor fields) elem.option = true) :
                                                                ctor = "none" ∧ fields = [] ∨ ctor = "some" ∧ Value.hasFieldTys p fields [("value", elem)] = true
                                                                Used by
                                                                  theorem

                                                                  Lean2Js.hasTy_result_fields

                                                                  source
                                                                  [Core.Discriminators] {p : Core.Program} {ctor : String} {fields : List (String × Value)} {ok err : Core.Ty} (h : Value.hasTy p (Value.obj ctor fields) (ok.result err) = true) :
                                                                  ctor = "ok" ∧ Value.hasFieldTys p fields [("value", ok)] = true ∨ ctor = "error" ∧ Value.hasFieldTys p fields [("error", err)] = true
                                                                  Used by
                                                                    theorem

                                                                    Lean2Js.mkInt53_hasTy

                                                                    source
                                                                    Used by
                                                                      theorem

                                                                      Lean2Js.applyUn_not_hasTy

                                                                      source
                                                                      Used by
                                                                        theorem

                                                                        Lean2Js.applyUn_toString_hasTy

                                                                        source
                                                                        Used by
                                                                          theorem

                                                                          Lean2Js.applyUn_neg_int53

                                                                          source
                                                                          Used by
                                                                            theorem

                                                                            Lean2Js.applyUn_neg_bigint

                                                                            source
                                                                            Used by
                                                                              theorem

                                                                              Lean2Js.applyUn_abs_int53

                                                                              source
                                                                              Used by
                                                                                theorem

                                                                                Lean2Js.applyUn_abs_bigint

                                                                                source
                                                                                Used by
                                                                                  theorem

                                                                                  Lean2Js.int53_ty

                                                                                  source
                                                                                  Used by
                                                                                    theorem

                                                                                    Lean2Js.uint32_ty

                                                                                    source
                                                                                    Used by
                                                                                      theorem

                                                                                      Lean2Js.bigint_ty

                                                                                      source
                                                                                      Used by
                                                                                        theorem

                                                                                        Lean2Js.str_ty

                                                                                        source
                                                                                        Used by
                                                                                          theorem

                                                                                          Lean2Js.arr_ty

                                                                                          source
                                                                                          Used by
                                                                                            theorem

                                                                                            Lean2Js.hasElemTy_append

                                                                                            source
                                                                                            [Core.Discriminators] {p : Core.Program} {xs ys : List Value} {elem : Core.Ty} (hx : Value.hasElemTy p xs elem = true) (hy : Value.hasElemTy p ys elem = true) :
                                                                                            Value.hasElemTy p (xs ++ ys) elem = true
                                                                                            Used by
                                                                                              theorem

                                                                                              Lean2Js.hasElemTy_iff

                                                                                              source
                                                                                              [Core.Discriminators] (p : Core.Program) (xs : List Value) (elem : Core.Ty) :
                                                                                              Value.hasElemTy p xs elem = true ↔ ∀ (x : Value), x ∈ xs → Value.hasTy p x elem = true

                                                                                              Reading the check element by element, so that every list operation that only ever keeps elements it was given inherits it from a membership lemma about that operation.

                                                                                              Used by
                                                                                                theorem

                                                                                                Lean2Js.hasElemTy_of_subset

                                                                                                source
                                                                                                [Core.Discriminators] {p : Core.Program} {xs ys : List Value} {elem : Core.Ty} (h : Value.hasElemTy p xs elem = true) (hsub : ∀ (y : Value), y ∈ ys → y ∈ xs) :
                                                                                                Used by
                                                                                                  theorem

                                                                                                  Lean2Js.applyUn_range_int53

                                                                                                  source

                                                                                                  The count has to be the typed value rather than a bare Int: what keeps every element inside Int53 is that the count already is, and the elements are all below it.

                                                                                                  Used by
                                                                                                    theorem

                                                                                                    Lean2Js.hasElemTy_getElem?

                                                                                                    source
                                                                                                    [Core.Discriminators] {p : Core.Program} {xs : List Value} {elem : Core.Ty} {n : Nat} {v : Value} (h : Value.hasElemTy p xs elem = true) (hg : xs[n]? = some v) :
                                                                                                    Value.hasTy p v elem = true
                                                                                                    Used by
                                                                                                      theorem

                                                                                                      Lean2Js.hasElemTy_string_inv

                                                                                                      source
                                                                                                      Used by
                                                                                                        theorem

                                                                                                        Lean2Js.hasTy_string_array_inv

                                                                                                        source
                                                                                                        Used by
                                                                                                          theorem

                                                                                                          Lean2Js.hasElemTy_map_str

                                                                                                          source
                                                                                                          Used by
                                                                                                            theorem

                                                                                                            Lean2Js.sliceArr_hasTy

                                                                                                            source
                                                                                                            [Core.Discriminators] {p : Core.Program} {a lo hi v : Value} {elem : Core.Ty} (ha : Value.hasTy p a elem.array = true) (h : sliceArr a lo hi = Except.ok v) :
                                                                                                            Used by
                                                                                                              theorem

                                                                                                              Lean2Js.sortPairs_hasTy

                                                                                                              source
                                                                                                              [Core.Discriminators] {p : Core.Program} {xs keys vs : List Value} {elem : Core.Ty} (h : Value.hasTy p (Value.arr xs) elem.array = true) (hs : sortPairs (keys.zip xs) = Except.ok vs) :
                                                                                                              Used by
                                                                                                                theorem

                                                                                                                Lean2Js.reverse_hasTy

                                                                                                                source
                                                                                                                Used by
                                                                                                                  theorem

                                                                                                                  Lean2Js.applyArith_hasTy

                                                                                                                  source
                                                                                                                  [Core.Discriminators] {p : Core.Program} {op : Core.BinOp} {t : Core.Ty} {a b v : Value} (ha : Value.hasTy p a t = true) (h : applyArith op a b = Except.ok v) :
                                                                                                                  Used by
                                                                                                                    theorem

                                                                                                                    Lean2Js.applyMinMax_hasTy

                                                                                                                    source
                                                                                                                    [Core.Discriminators] {p : Core.Program} {op : Core.BinOp} {t : Core.Ty} {a b v : Value} (ha : Value.hasTy p a t = true) (hb : Value.hasTy p b t = true) (h : applyMinMax op a b = Except.ok v) :
                                                                                                                    Used by
                                                                                                                      theorem

                                                                                                                      Lean2Js.compareValues_hasTy

                                                                                                                      source
                                                                                                                      Used by
                                                                                                                        theorem

                                                                                                                        Lean2Js.applyBin_concat_hasTy

                                                                                                                        source
                                                                                                                        [Core.Discriminators] {p : Core.Program} {t : Core.Ty} {a b v : Value} (ha : Value.hasTy p a t = true) (hb : Value.hasTy p b t = true) (h : applyBin Core.BinOp.concat a b = Except.ok v) :
                                                                                                                        Used by
                                                                                                                          def

                                                                                                                          Lean2Js.binResultTy

                                                                                                                          source
                                                                                                                          (op : Core.BinOp) (t : Core.Ty) :

                                                                                                                          The type the compiler gives a binary operation whose operands both have type t.

                                                                                                                          Equations
                                                                                                                          Instances For
                                                                                                                            Used by
                                                                                                                              theorem

                                                                                                                              Lean2Js.applyBin_hasTy

                                                                                                                              source
                                                                                                                              [Core.Discriminators] {p : Core.Program} {op : Core.BinOp} {t : Core.Ty} {a b v : Value} (ha : Value.hasTy p a t = true) (hb : Value.hasTy p b t = true) (h : applyBin op a b = Except.ok v) :
                                                                                                                              Used by
                                                                                                                                theorem

                                                                                                                                Lean2Js.applyStrUn_hasTy

                                                                                                                                source
                                                                                                                                Used by
                                                                                                                                  theorem

                                                                                                                                  Lean2Js.applyStrBin_hasTy

                                                                                                                                  source
                                                                                                                                  Used by
                                                                                                                                    theorem

                                                                                                                                    Lean2Js.sliceStr_hasTy

                                                                                                                                    source
                                                                                                                                    Used by
                                                                                                                                      theorem

                                                                                                                                      Lean2Js.asBool_hasTy

                                                                                                                                      source
                                                                                                                                      Used by
                                                                                                                                        theorem

                                                                                                                                        Lean2Js.EnvTyped.cons

                                                                                                                                        source
                                                                                                                                        [Core.Discriminators] {p : Core.Program} {env : Env} {ctx : Compile.Ctx} {name : String} {ty : Core.Ty} {v : Value} (henv : EnvTyped p env ctx) (hv : Value.hasTy p v ty = true) :
                                                                                                                                        EnvTyped p ((name, v) :: env) ((name, ty) :: ctx)
                                                                                                                                        Used by
                                                                                                                                          theorem

                                                                                                                                          Lean2Js.EnvTyped.fnScoped

                                                                                                                                          source
                                                                                                                                          [Core.Discriminators] {p : Core.Program} {env : Env} {ctx : Compile.Ctx} (h : EnvTyped p env ctx) (name g : String) (hv : env.lookup? name = some (Value.fn g)) :
                                                                                                                                          ∃ (params : List Core.Ty), ∃ (ret : Core.Ty), Option.map (fun (x : String × Core.Ty) => x.snd) (List.find? (fun (x : String × Core.Ty) => x.fst == name) ctx) = some (Core.Ty.fn params ret)

                                                                                                                                          A function value in the environment is one the context typed as a function: it is bound, so the context has a type for it, and only a function type is satisfied by a function value.

                                                                                                                                          Used by
                                                                                                                                            theorem

                                                                                                                                            Lean2Js.litValue_hasTy

                                                                                                                                            source
                                                                                                                                            Used by
                                                                                                                                              theorem

                                                                                                                                              Lean2Js.keysDistinct_iff

                                                                                                                                              source
                                                                                                                                              Used by
                                                                                                                                                theorem

                                                                                                                                                Lean2Js.keysDistinct_of_validateDistinct

                                                                                                                                                source
                                                                                                                                                Used by
                                                                                                                                                  theorem

                                                                                                                                                  Lean2Js.keysDistinct_of_sublist

                                                                                                                                                  source
                                                                                                                                                  [Core.Discriminators] {ks ls : List String} (h : keysDistinct ls = true) (hs : ks.Sublist ls) :
                                                                                                                                                  Used by
                                                                                                                                                    theorem

                                                                                                                                                    Lean2Js.hasEntryTys_iff

                                                                                                                                                    source
                                                                                                                                                    [Core.Discriminators] (p : Core.Program) (entries : List (String × Value)) (elem : Core.Ty) :
                                                                                                                                                    Value.hasEntryTys p entries elem = true ↔ ∀ (e : String × Value), e ∈ entries → Value.hasTy p e.snd elem = true
                                                                                                                                                    Used by
                                                                                                                                                      theorem

                                                                                                                                                      Lean2Js.hasTy_dict_filter

                                                                                                                                                      source
                                                                                                                                                      [Core.Discriminators] {p : Core.Program} {entries : List (String × Value)} {elem : Core.Ty} {q : String × Value → Bool} (h : Value.hasTy p (Value.dict entries) elem.dict = true) :
                                                                                                                                                      Used by
                                                                                                                                                        theorem

                                                                                                                                                        Lean2Js.hasTy_dict_with

                                                                                                                                                        source
                                                                                                                                                        [Core.Discriminators] {p : Core.Program} {entries : List (String × Value)} {elem : Core.Ty} {k : String} {v : Value} (h : Value.hasTy p (Value.dict entries) elem.dict = true) (hv : Value.hasTy p v elem = true) :
                                                                                                                                                        Value.hasTy p (Value.dict (dictWith entries k v)) elem.dict = true

                                                                                                                                                        Writing a key already present leaves the key list alone, and writing a new one appends a key the list did not have. Either way a Map still holds every key once.

                                                                                                                                                        Used by
                                                                                                                                                          theorem

                                                                                                                                                          Lean2Js.dictLookup_hasTy

                                                                                                                                                          source
                                                                                                                                                          [Core.Discriminators] {p : Core.Program} {entries : List (String × Value)} {elem : Core.Ty} {k : String} (h : Value.hasEntryTys p entries elem = true) :
                                                                                                                                                          Value.hasTy p (dictLookup entries k) elem.option = true
                                                                                                                                                          Used by
                                                                                                                                                            theorem

                                                                                                                                                            Lean2Js.hasElemTy_dict_keys

                                                                                                                                                            source
                                                                                                                                                            Used by
                                                                                                                                                              theorem

                                                                                                                                                              Lean2Js.hasElemTy_dict_values

                                                                                                                                                              source
                                                                                                                                                              [Core.Discriminators] {p : Core.Program} {entries : List (String × Value)} {elem : Core.Ty} (h : Value.hasEntryTys p entries elem = true) :
                                                                                                                                                              Value.hasElemTy p (List.map (fun (x : String × Value) => x.snd) entries) elem = true
                                                                                                                                                              Used by
                                                                                                                                                                theorem

                                                                                                                                                                Lean2Js.findAt?_eq

                                                                                                                                                                source
                                                                                                                                                                [Core.Discriminators] (t : Core.TypeDef) (args : List Core.Ty) (ctor : String) :
                                                                                                                                                                t.findAt? args ctor = Option.map (fun (c : Core.CtorDef) => { name := c.name, fields := List.map (fun (f : Core.Field) => { name := f.name, ty := Core.Ty.subst (t.params.zip args) f.ty }) c.fields }) (t.find? ctor)

                                                                                                                                                                The constructors a use of the type at args sees are the declared ones with their field types substituted, so a lookup by name lands on the same constructor either way.

                                                                                                                                                                Used by
                                                                                                                                                                  theorem

                                                                                                                                                                  Lean2Js.hasFieldTys_find

                                                                                                                                                                  source
                                                                                                                                                                  [Core.Discriminators] {p : Core.Program} (fields : List (String × Value)) (tys : List (String × Core.Ty)) (k : String) (v : Value) (t : Core.Ty) :
                                                                                                                                                                  Value.hasFieldTys p fields tys = true → Option.map (fun (x : String × Value) => x.snd) (List.find? (fun (x : String × Value) => x.fst == k) fields) = some v → Option.map (fun (x : String × Core.Ty) => x.snd) (List.find? (fun (x : String × Core.Ty) => x.fst == k) tys) = some t → Value.hasTy p v t = true
                                                                                                                                                                  Used by
                                                                                                                                                                    theorem

                                                                                                                                                                    Lean2Js.ty_of_foldKindOf_self

                                                                                                                                                                    source

                                                                                                                                                                    A field the fold walks into is the type coming round, at the arguments the fold names. foldKindOf is read by the evaluator and by the emitter alike, so what it answers is what both walk.

                                                                                                                                                                    Used by
                                                                                                                                                                      theorem

                                                                                                                                                                      Lean2Js.ty_of_foldKindOf_list

                                                                                                                                                                      source
                                                                                                                                                                      Used by
                                                                                                                                                                        theorem

                                                                                                                                                                        Lean2Js.hasTy_of_lookupFieldV

                                                                                                                                                                        source
                                                                                                                                                                        [Core.Discriminators] {p : Core.Program} (fields : List (String × Value)) (fs : List Core.Field) :
                                                                                                                                                                        Value.hasFieldTys p fields (List.map (fun (f : Core.Field) => (f.name, f.ty)) fs) = true → (List.map (fun (x : Core.Field) => x.name) fs).Nodup → ∀ (fd : Core.Field), fd ∈ fs → ∀ (v : Value), lookupFieldV fields fd.name = some v → Value.hasTy p v fd.ty = true

                                                                                                                                                                        Reading a field out of a value by name gives the type the declaration puts at that name. hasFieldTys lines the value's fields up with the declared ones in order, and the names being apart is what makes the lookup land on the same one.

                                                                                                                                                                        Used by
                                                                                                                                                                          theorem

                                                                                                                                                                          Lean2Js.hasFieldTys_find_some

                                                                                                                                                                          source
                                                                                                                                                                          [Core.Discriminators] {p : Core.Program} (fields : List (String × Value)) (tys : List (String × Core.Ty)) (k : String) (t : Core.Ty) :
                                                                                                                                                                          Value.hasFieldTys p fields tys = true → Option.map (fun (x : String × Core.Ty) => x.snd) (List.find? (fun (x : String × Core.Ty) => x.fst == k) tys) = some t → ∃ (v : Value), Option.map (fun (x : String × Value) => x.snd) (List.find? (fun (x : String × Value) => x.fst == k) fields) = some v ∧ Value.hasTy p v t = true
                                                                                                                                                                          Used by
                                                                                                                                                                            theorem

                                                                                                                                                                            Lean2Js.find?_field_ty

                                                                                                                                                                            source
                                                                                                                                                                            [Core.Discriminators] {fields : List Core.Field} {field : String} {f : Core.Field} (h : List.find? (fun (x : Core.Field) => x.name == field) fields = some f) :
                                                                                                                                                                            Option.map (fun (x : String × Core.Ty) => x.snd) (List.find? (fun (x : String × Core.Ty) => x.fst == field) (List.map (fun (g : Core.Field) => (g.name, g.ty)) fields)) = some f.ty
                                                                                                                                                                            Used by
                                                                                                                                                                              theorem

                                                                                                                                                                              Lean2Js.scrutName_reserved

                                                                                                                                                                              source
                                                                                                                                                                              Used by
                                                                                                                                                                                theorem

                                                                                                                                                                                Lean2Js.ne_scrutName_of_unreserved

                                                                                                                                                                                source
                                                                                                                                                                                Used by
                                                                                                                                                                                  theorem

                                                                                                                                                                                  Lean2Js.ne_scrutName_of_validateIdent

                                                                                                                                                                                  source
                                                                                                                                                                                  [Core.Discriminators] {kind name : String} {u : Unit} (h : validateIdent kind name = Except.ok u) :

                                                                                                                                                                                  No name the compiler lets through can be the one match gives its scrutinee: validateIdent rejects the __ prefix, and scrutName starts with it.

                                                                                                                                                                                  Used by

                                                                                                                                                                                    Reading a traversal off the compiler #

                                                                                                                                                                                    Not private, unlike the inversions above: the correctness proof reads the same three parts out of a traversal — the array, the body under the binder, and the shape the compiler emitted.

                                                                                                                                                                                    theorem

                                                                                                                                                                                    Lean2Js.compileExpr_mapE_inv

                                                                                                                                                                                    source
                                                                                                                                                                                    [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {arr body : Core.Expr} {binder : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (arr.mapE binder body) = Except.ok (je, ty)) :
                                                                                                                                                                                    ∃ (jarr : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), ∃ (tbody : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ((binder, elem) :: ctx) body = Except.ok (jbody, tbody) ∧ ty = tbody.array ∧ je = jarr.mapJs binder jbody ∧ isReserved binder = false
                                                                                                                                                                                    Used by
                                                                                                                                                                                      theorem

                                                                                                                                                                                      Lean2Js.compileExpr_sortByKeyE_inv

                                                                                                                                                                                      source
                                                                                                                                                                                      [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {arr body : Core.Expr} {binder : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (arr.sortByKeyE binder body) = Except.ok (je, ty)) :
                                                                                                                                                                                      ∃ (jarr : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), ∃ (tbody : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ((binder, elem) :: ctx) body = Except.ok (jbody, tbody) ∧ (tbody = Core.Ty.int53 ∨ tbody = Core.Ty.string) ∧ ty = elem.array ∧ je = jarr.sortByJs binder jbody ∧ isReserved binder = false
                                                                                                                                                                                      Used by
                                                                                                                                                                                        theorem

                                                                                                                                                                                        Lean2Js.compileExpr_filterE_inv

                                                                                                                                                                                        source
                                                                                                                                                                                        [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {arr body : Core.Expr} {binder : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (arr.filterE binder body) = Except.ok (je, ty)) :
                                                                                                                                                                                        ∃ (jarr : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ((binder, elem) :: ctx) body = Except.ok (jbody, Core.Ty.bool) ∧ ty = elem.array ∧ je = jarr.filterJs binder jbody ∧ isReserved binder = false
                                                                                                                                                                                        Used by
                                                                                                                                                                                          theorem

                                                                                                                                                                                          Lean2Js.compileExpr_findE_inv

                                                                                                                                                                                          source
                                                                                                                                                                                          [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {arr body : Core.Expr} {binder : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (arr.findE binder body) = Except.ok (je, ty)) :
                                                                                                                                                                                          ∃ (jarr : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ((binder, elem) :: ctx) body = Except.ok (jbody, Core.Ty.bool) ∧ ty = elem.option ∧ je = jarr.findJs binder jbody ∧ isReserved binder = false
                                                                                                                                                                                          Used by
                                                                                                                                                                                            theorem

                                                                                                                                                                                            Lean2Js.compileExpr_quantE_inv

                                                                                                                                                                                            source
                                                                                                                                                                                            [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {op : Core.QuantOp} {arr body : Core.Expr} {binder : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (Core.Expr.quantE op arr binder body) = Except.ok (je, ty)) :
                                                                                                                                                                                            ∃ (jarr : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ((binder, elem) :: ctx) body = Except.ok (jbody, Core.Ty.bool) ∧ ty = Core.Ty.bool ∧ je = Js.Expr.quantJs op jarr binder jbody ∧ isReserved binder = false
                                                                                                                                                                                            Used by
                                                                                                                                                                                              theorem

                                                                                                                                                                                              Lean2Js.compileExpr_reduceE_inv

                                                                                                                                                                                              source
                                                                                                                                                                                              [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {arr init body : Core.Expr} {accName elemName : String} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (arr.reduceE init accName elemName body) = Except.ok (je, ty)) :
                                                                                                                                                                                              ∃ (jarr : Js.Expr), ∃ (jinit : Js.Expr), ∃ (jbody : Js.Expr), ∃ (elem : Core.Ty), Compile.compileExpr p ctx arr = Except.ok (jarr, elem.array) ∧ Compile.compileExpr p ctx init = Except.ok (jinit, ty) ∧ Compile.compileExpr p ((elemName, elem) :: (accName, ty) :: ctx) body = Except.ok (jbody, ty) ∧ je = jarr.reduceJs jinit accName elemName jbody ∧ isReserved accName = false ∧ isReserved elemName = false
                                                                                                                                                                                              Used by
                                                                                                                                                                                                theorem

                                                                                                                                                                                                Lean2Js.zipAll_of_map

                                                                                                                                                                                                source
                                                                                                                                                                                                [Core.Discriminators] {js : List (Js.Expr × Core.Ty)} (params : List Core.Param) :
                                                                                                                                                                                                (((List.map (fun (x : Core.Param) => x.ty) params).zip js).all fun (x : Core.Ty × Js.Expr × Core.Ty) => x.fst == x.snd.snd) = true → ((params.zip js).all fun (x : Core.Param × Js.Expr × Core.Ty) => x.fst.ty == x.snd.snd) = true

                                                                                                                                                                                                A call checks its arguments against the types of the callee's parameters. The names come from the same parameter list, so the check the compiler wrote over types alone reads as one over parameters.

                                                                                                                                                                                                Used by
                                                                                                                                                                                                  def

                                                                                                                                                                                                  Lean2Js.ParamsTyped

                                                                                                                                                                                                  source

                                                                                                                                                                                                  Every argument has the type its parameter declared.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                    Used by
                                                                                                                                                                                                      theorem

                                                                                                                                                                                                      Lean2Js.envTyped_bindParams

                                                                                                                                                                                                      source
                                                                                                                                                                                                      [Core.Discriminators] (p : Core.Program) (params : List Core.Param) (args : List Value) :
                                                                                                                                                                                                      ParamsTyped p params args → EnvTyped p (bindParams params args) (List.map (fun (param : Core.Param) => (param.name, param.ty)) params)

                                                                                                                                                                                                      The compiler's context and the reference environment are built from the same parameter list in the same order, so the name each lookup lands on is the same one.

                                                                                                                                                                                                      Used by
                                                                                                                                                                                                        theorem

                                                                                                                                                                                                        Lean2Js.paramsTyped_of_args

                                                                                                                                                                                                        source
                                                                                                                                                                                                        [Core.Discriminators] {p : Core.Program} {f : Nat} {ctx : Compile.Ctx} {env : Env} (ih : ∀ (e : Core.Expr) (je : Js.Expr) (ty : Core.Ty) (v : Value), TypeChecked e → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.ok v → Value.hasTy p v ty = true) (args : List Core.Expr) (js : List (Js.Expr × Core.Ty)) (vs : List Value) (params : List Core.Param) :
                                                                                                                                                                                                        (∀ (e : Core.Expr), e ∈ args → TypeChecked e) → Compile.compileArgs p ctx args = Except.ok js → evalArgs p f env args = Except.ok vs → ((params.zip js).all fun (x : Core.Param × Js.Expr × Core.Ty) => x.fst.ty == x.snd.snd) = true → params.length = js.length → ParamsTyped p params vs

                                                                                                                                                                                                        The arguments of a call, carrying the induction hypothesis of typeSound along them: the environment the callee's body runs in is typed by the context that body was compiled against.

                                                                                                                                                                                                        Used by

                                                                                                                                                                                                          Reading a match off the compiler #

                                                                                                                                                                                                          An arm is compiled against the context its pattern binds, and eval runs it in the environment the same pattern bound, so type soundness for match is the statement that those two line up.

                                                                                                                                                                                                          def

                                                                                                                                                                                                          Lean2Js.BindsAgree

                                                                                                                                                                                                          source

                                                                                                                                                                                                          What a pattern bound, against what the arm was compiled against: the same names in the same order, each value satisfying the type the compiler read.

                                                                                                                                                                                                          Equations
                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                            Used by
                                                                                                                                                                                                              def

                                                                                                                                                                                                              Lean2Js.ValuesTyped

                                                                                                                                                                                                              source
                                                                                                                                                                                                              Equations
                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                  Lean2Js.BindsAgree.append

                                                                                                                                                                                                                  source
                                                                                                                                                                                                                  [Core.Discriminators] {p : Core.Program} {b1 : Env} {c1 : Compile.Ctx} {b2 : Env} {c2 : Compile.Ctx} :
                                                                                                                                                                                                                  BindsAgree p b1 c1 → BindsAgree p b2 c2 → BindsAgree p (b1 ++ b2) (c1 ++ c2)
                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                    Lean2Js.EnvTyped.append

                                                                                                                                                                                                                    source
                                                                                                                                                                                                                    [Core.Discriminators] {p : Core.Program} {env : Env} {ctx : Compile.Ctx} (henv : EnvTyped p env ctx) {benv : Env} {bctx : Compile.Ctx} :
                                                                                                                                                                                                                    BindsAgree p benv bctx → EnvTyped p (benv ++ env) (bctx ++ ctx)
                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                      Lean2Js.valuesTyped_of_hasFieldTys

                                                                                                                                                                                                                      source
                                                                                                                                                                                                                      [Core.Discriminators] {p : Core.Program} {fields : List (String × Value)} {ftys : List (String × Core.Ty)} :
                                                                                                                                                                                                                      Value.hasFieldTys p fields ftys = true → ValuesTyped p (List.map (fun (x : String × Value) => x.snd) fields) (List.map (fun (x : String × Core.Ty) => x.snd) ftys)
                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                        Lean2Js.hasFieldTys_of_signature

                                                                                                                                                                                                                        source
                                                                                                                                                                                                                        [Core.Discriminators] {p : Core.Program} {ty : Core.Ty} {heads : List (Compile.Head × List (String × Core.Ty))} {ctor : String} {fields : List (String × Value)} {ftys : List (String × Core.Ty)} (hsig : Compile.signature p.types ty = some heads) (hfind : Option.map (fun (x : Compile.Head × List (String × Core.Ty)) => x.snd) (List.find? (fun (x : Compile.Head × List (String × Core.Ty)) => x.fst == Compile.Head.ctor ctor) heads) = some ftys) (hv : Value.hasTy p (Value.obj ctor fields) ty = true) :
                                                                                                                                                                                                                        Value.hasFieldTys p fields ftys = true

                                                                                                                                                                                                                        The fields a constructor pattern reads, as the type checker sees them and as the value holds them. signature is the compiler's view of a type's constructors; Value.hasTy is the reference semantics'.

                                                                                                                                                                                                                        Used by
                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                          Lean2Js.matchPat_binds

                                                                                                                                                                                                                          source
                                                                                                                                                                                                                          [Core.Discriminators] {p : Core.Program} {ty : Core.Ty} {path : Js.Expr} {pat : Core.Pat} {v : Value} {tests : List Js.Expr} {pbinds : List (String × Js.Expr × Core.Ty)} {binds : Env} :
                                                                                                                                                                                                                          Value.hasTy p v ty = true → Compile.patParts p.types ty path pat = Except.ok (tests, pbinds) → matchPat pat v = some binds → BindsAgree p binds (List.map (fun (b : String × Js.Expr × Core.Ty) => (b.fst, b.snd.snd)) pbinds)

                                                                                                                                                                                                                          A pattern that matched bound exactly what the compiler compiled the arm against.

                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                            theorem

                                                                                                                                                                                                                            Lean2Js.matchPats_binds

                                                                                                                                                                                                                            source
                                                                                                                                                                                                                            [Core.Discriminators] {p : Core.Program} {tys : List Core.Ty} {paths : List Js.Expr} {pats : List Core.Pat} {vs : List Value} {tests : List Js.Expr} {pbinds : List (String × Js.Expr × Core.Ty)} {binds : Env} :
                                                                                                                                                                                                                            ValuesTyped p vs tys → Compile.patPartsList p.types tys paths pats = Except.ok (tests, pbinds) → matchPats pats vs = some binds → BindsAgree p binds (List.map (fun (b : String × Js.Expr × Core.Ty) => (b.fst, b.snd.snd)) pbinds)
                                                                                                                                                                                                                            Used by
                                                                                                                                                                                                                              theorem

                                                                                                                                                                                                                              Lean2Js.foldPatParts_binds

                                                                                                                                                                                                                              source
                                                                                                                                                                                                                              [Core.Discriminators] {p : Core.Program} {tn : String} {ta : List Core.Ty} {result : Core.Ty} {path : Js.Expr} {pat : Core.Pat} {ctor : String} {fields : List (String × Value)} {c : Core.CtorDef} {tests : List Js.Expr} {pbinds : List (String × Js.Expr × Core.Ty)} {binds : Env} (hfind : ((List.find? (fun (x : Core.TypeDef) => x.name == tn) p.types).bind fun (t : Core.TypeDef) => t.findAt? ta ctor) = some c) (hv : Value.hasFieldTys p fields (Compile.foldFieldTys tn ta result c.fields) = true) (hpp : Compile.foldPatParts p.types tn ta result path pat = Except.ok (tests, pbinds)) (hm : matchPat pat (Value.obj ctor fields) = some binds) :
                                                                                                                                                                                                                              BindsAgree p binds (List.map (fun (b : String × Js.Expr × Core.Ty) => (b.fst, b.snd.snd)) pbinds)

                                                                                                                                                                                                                              A fold's alternative binds what the compiler compiled its arm against. The rebuilt node carries the answer for every field that came round, so the types the binders take are foldFieldTys' and not the declared ones; everything nested inside a field reads through patPartsList unchanged.

                                                                                                                                                                                                                              Used by
                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                Lean2Js.firstMatch_mem

                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                [Core.Discriminators] {alts : List Core.Alt} {sv : Value} {binds : Env} {body : Core.Expr} (h : firstMatch alts sv = some (binds, body)) :
                                                                                                                                                                                                                                ∃ (alt : Core.Alt), alt ∈ alts ∧ body = alt.body
                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                  Lean2Js.compileAlts_firstMatch

                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                  [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {tscrut : Core.Ty} {sv : Value} (hsv : Value.hasTy p sv tscrut = true) (alts : List Core.Alt) (arms : List Compile.Arm) (binds : Env) (body : Core.Expr) :
                                                                                                                                                                                                                                  Compile.compileAlts p ctx tscrut alts = Except.ok arms → firstMatch alts sv = some (binds, body) → ∃ (arm : Compile.Arm), ∃ (bctx : Compile.Ctx), arm ∈ arms ∧ BindsAgree p binds bctx ∧ Compile.compileExpr p (bctx ++ ctx) body = Except.ok (arm.body, arm.ty)
                                                                                                                                                                                                                                  Used by
                                                                                                                                                                                                                                    theorem

                                                                                                                                                                                                                                    Lean2Js.compileFoldAlts_firstMatch

                                                                                                                                                                                                                                    source
                                                                                                                                                                                                                                    [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {tn : String} {ta : List Core.Ty} {result : Core.Ty} {ctor : String} {fields : List (String × Value)} {c : Core.CtorDef} (hfind : ((List.find? (fun (x : Core.TypeDef) => x.name == tn) p.types).bind fun (t : Core.TypeDef) => t.findAt? ta ctor) = some c) (hv : Value.hasFieldTys p fields (Compile.foldFieldTys tn ta result c.fields) = true) (alts : List Core.Alt) (arms : List Compile.Arm) (binds : Env) (body : Core.Expr) :
                                                                                                                                                                                                                                    Compile.compileFoldAlts p ctx tn ta result alts = Except.ok arms → firstMatch alts (Value.obj ctor fields) = some (binds, body) → ∃ (arm : Compile.Arm), ∃ (bctx : Compile.Ctx), arm ∈ arms ∧ BindsAgree p binds bctx ∧ Compile.compileExpr p (bctx ++ ctx) body = Except.ok (arm.body, arm.ty)

                                                                                                                                                                                                                                    The arm a fold's rebuilt node fell to is one the compiler compiled, against the context the pattern's binders give it. compileAlts_firstMatch over foldPatParts.

                                                                                                                                                                                                                                    Used by
                                                                                                                                                                                                                                      theorem

                                                                                                                                                                                                                                      Lean2Js.compileExpr_matchE_inv

                                                                                                                                                                                                                                      source
                                                                                                                                                                                                                                      [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {scrut : Core.Expr} {alts : List Core.Alt} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (scrut.matchE alts) = Except.ok (je, ty)) :
                                                                                                                                                                                                                                      ∃ (jscrut : Js.Expr), ∃ (tscrut : Core.Ty), ∃ (arm0 : Compile.Arm), ∃ (arms : List Compile.Arm), Compile.compileExpr p ctx scrut = Except.ok (jscrut, tscrut) ∧ Compile.compileAlts p ctx tscrut alts = Except.ok (arm0 :: arms) ∧ ((arm0 :: arms).all fun (a : Compile.Arm) => a.ty == arm0.ty) = true ∧ ty = arm0.ty ∧ je = Js.Expr.arrowCall [Compile.scrutName] (Compile.compileExpr.chain (arm0 :: arms)) [jscrut]
                                                                                                                                                                                                                                      Used by
                                                                                                                                                                                                                                        theorem

                                                                                                                                                                                                                                        Lean2Js.compileExpr_foldE_inv

                                                                                                                                                                                                                                        source
                                                                                                                                                                                                                                        [Core.Discriminators] {p : Core.Program} {ctx : Compile.Ctx} {scrut : Core.Expr} {tn : String} {ta : List Core.Ty} {result : Core.Ty} {alts : List Core.Alt} {je : Js.Expr} {ty : Core.Ty} (hc : Compile.compileExpr p ctx (scrut.foldE tn ta result alts) = Except.ok (je, ty)) :
                                                                                                                                                                                                                                        ∃ (jscrut : Js.Expr), ∃ (arms : List Compile.Arm), ∃ (t : Core.TypeDef), ∃ (first : Core.CtorDef), ∃ (rest : List Core.CtorDef), Compile.compileExpr p ctx scrut = Except.ok (jscrut, Core.Ty.named tn ta) ∧ Compile.compileFoldAlts p ctx tn ta result alts = Except.ok arms ∧ (arms.all fun (a : Compile.Arm) => a.ty == result) = true ∧ List.find? (fun (x : Core.TypeDef) => x.name == tn) p.types = some t ∧ t.ctors = first :: rest ∧ je = jscrut.foldJs (Core.keyFor first.name) (Compile.foldSpecOf p.types tn ta) Compile.scrutName (Compile.compileExpr.chain arms) ∧ ty = result

                                                                                                                                                                                                                                        What the compiler had in hand where it built a fold: a scrutinee at the type the fold names, a type with at least one constructor to read the key off, arms it compiled, and every one of them answering at the fold's result type.

                                                                                                                                                                                                                                        Used by

                                                                                                                                                                                                                                          Walking a traversal #

                                                                                                                                                                                                                                          A traversal evaluates its body under an environment that changes from element to element, so these take the induction hypothesis of typeSound over every environment rather than the one at the traversal. filter, find and all / any need no hypothesis at all: what they return is an element they were given, or a Bool they decided.

                                                                                                                                                                                                                                          theorem

                                                                                                                                                                                                                                          Lean2Js.hasElemTy_of_mapItems

                                                                                                                                                                                                                                          source
                                                                                                                                                                                                                                          [Core.Discriminators] {p : Core.Program} {f : Nat} {ctx : Compile.Ctx} {env : Env} {binder : String} {bodyE : Core.Expr} {jbody : Js.Expr} {elem tbody : Core.Ty} (ih : ∀ (ctx : Compile.Ctx) (env : Env) (e : Core.Expr) (je : Js.Expr) (ty : Core.Ty) (v : Value), TypeChecked e → EnvTyped p env ctx → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.ok v → Value.hasTy p v ty = true) (hbody : TypeChecked bodyE) (henv : EnvTyped p env ctx) (hcb : Compile.compileExpr p ((binder, elem) :: ctx) bodyE = Except.ok (jbody, tbody)) (xs vs : List Value) :
                                                                                                                                                                                                                                          Value.hasElemTy p xs elem = true → evalMapItems p f env binder bodyE xs = Except.ok vs → Value.hasElemTy p vs tbody = true
                                                                                                                                                                                                                                          Used by
                                                                                                                                                                                                                                            structure

                                                                                                                                                                                                                                            Lean2Js.ProgramTyped

                                                                                                                                                                                                                                            source

                                                                                                                                                                                                                                            What the compiler establishes about every declaration of a program it accepted: each body compiles, under the context its parameters give, at the type the declaration is declared to return.

                                                                                                                                                                                                                                            A call is where a proof about one expression reaches into another declaration, so this is the shape the whole program has to be handed in, names included: the generated code calls a declaration by its name, which has to be one the environment cannot be holding. Decl.programTyped_of_compileProgram reads both off the module.

                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                              Used by

                                                                                                                                                                                                                                                Walking a fold #

                                                                                                                                                                                                                                                A fold recurses on the value rather than on the expression, so its four walkers need an induction of their own: one strong induction on a bound for the value's size, carrying all four at once because they call each other. The arms run at the fold's own fuel, so the fuel induction's hypothesis is what types their bodies.

                                                                                                                                                                                                                                                theorem

                                                                                                                                                                                                                                                Lean2Js.typeSound

                                                                                                                                                                                                                                                source
                                                                                                                                                                                                                                                [Core.Discriminators] (p : Core.Program) (hprog : ProgramTyped p) (f : Nat) (ctx : Compile.Ctx) (env : Env) (e : Core.Expr) (je : Js.Expr) (ty : Core.Ty) (v : Value) :
                                                                                                                                                                                                                                                TypeChecked e → EnvTyped p env ctx → Compile.compileExpr p ctx e = Except.ok (je, ty) → evalExpr p f env e = Except.ok v → Value.hasTy p v ty = true

                                                                                                                                                                                                                                                If the compiler judged an expression to have type T and eval returns a value, the value satisfies T.

                                                                                                                                                                                                                                                Used by
                                                                                                                                                                                                                                                  theorem

                                                                                                                                                                                                                                                  Lean2Js.hasFieldTys_of_evalFoldFields

                                                                                                                                                                                                                                                  source
                                                                                                                                                                                                                                                  [Core.Discriminators] {p : Core.Program} (hprog : ProgramTyped p) (f : Nat) {ctx : Compile.Ctx} {env : Env} {tn : String} {ta : List Core.Ty} {result : Core.Ty} {alts : List Core.Alt} {arms : List Compile.Arm} {fields : List (String × Value)} {fs : List Core.Field} {ps : List (String × Value)} (halts : ∀ (alt : Core.Alt), alt ∈ alts → TypeChecked alt.body) (henv : EnvTyped p env ctx) (hca : Compile.compileFoldAlts p ctx tn ta result alts = Except.ok arms) (hsame : (arms.all fun (a : Compile.Arm) => a.ty == result) = true) (hfields : ∀ (fd : Core.Field), fd ∈ fs → ∀ (v : Value), lookupFieldV fields fd.name = some v → Value.hasTy p v fd.ty = true) (hfs : evalFoldFields p f env tn ta alts fields fs = Except.ok ps) :

                                                                                                                                                                                                                                                  The node a fold's walk rebuilt carries the fields Compile.foldFieldTys names: each one that came round holds the fold's answer for it, and the rest hold what they held. A fold's alternatives are compiled against exactly that, so it is what a proof about the arms needs of the node they run on — hasTy_of_fold's fourth walker, at the fuel typeSound was proved for.

                                                                                                                                                                                                                                                  Used by