lean2js

Lean2Js.Denote

source

Imports 2

An author's theorem as a claim about the shipped JavaScript #

Lean2Js/Example.lean proves theorems about ordinary Lean functions. This is the descent: what one of those theorems says about the module the compiler writes.

The step that crosses is the certificate, which certificates% wrote next to the declaration. Everything else — that the generated function agrees with the reference semantics, that it throws the same codes, that arguments the entry refuses never reach the body — is proved once about every program and cited here without knowing what the declaration looks like.

What the walk refuses is pinned here too: a refusal is part of the subset's boundary, and a #guard_msgs is what keeps the wording from drifting.

theorem

Lean2Js.Denote.encode_toValue

source
Used by
    theorem

    Lean2Js.Denote.decl_ships

    source
    [Core.Discriminators] (m : Js.Module) (hm : Compile.compileProgram Example.program = Except.ok m) (fn : String) (d : Core.Decl) (jargs : List Js.JsValue) (args : List Value) {α : Type} [Enc α] (t : α) (hd : Example.program.find? fn = some d) (hpub : d.paramsCheckable = true) (htyped : ParamsTyped Example.program d.params args) (hdec : Decl.ArgsDecode Example.program d.params jargs args) (hcert : Denotes Example.program (bindParams d.params args) d.body t) :
    ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' fn jargs = Except.ok (encodeAt Example.program d.ret (Enc.toValue t)) ∨ ∃ (err : Err), Js.callFunctionAt m g' fn jargs = Except.error err.code

    One declaration, as the claim an author wants: on arguments the entry accepts, the shipped function either answers what the author's own def computes, read out through the type the declaration gave it, or throws one of the codes Err enumerates. The certificate is the only part of this that changes from one declaration to the next.

    The reading is encodeAt rather than encodeValue because a return type may say a dictionary crosses as a plain object, and then the two differ. Where it says no such thing — encodeAt_eq_encodeValue, which each concrete claim below is rewritten through — they are the same function and the claim is the one it has always been.

    Used by
      theorem

      Lean2Js.Denote.add_ships

      source
      Used by
        theorem

        Lean2Js.Denote.lineTotal_ships

        source
        [Core.Discriminators] (m : Js.Module) (hm : Compile.compileProgram Example.program = Except.ok m) (unitPrice quantity : Int) (hp : Enc.accepts Example.program unitPrice) (hq : Enc.accepts Example.program quantity) :
        ∃ (g : Nat), ∀ (g' : Nat), g ≤ g' → Js.callFunctionAt m g' "lineTotal" [Js.JsValue.num unitPrice, Js.JsValue.num quantity] = Except.ok (Js.JsValue.num (Example.lineTotal unitPrice quantity)) ∨ ∃ (err : Err), Js.callFunctionAt m g' "lineTotal" [Js.JsValue.num unitPrice, Js.JsValue.num quantity] = Except.error err.code

        The one that makes the shape worth the trouble: lineTotal calls clampQuantity, and the step that crosses the call is clampQuantity's own certificate — cited by the walk, not written here.

        Used by
          theorem

          Lean2Js.Denote.roleRank_ships

          source
          Used by
            theorem

            Lean2Js.Denote.add_comm_ships

            source

            add_comm is proved about Example.add, and rewriting it into add_ships is the whole descent. Nothing in this step knows what the declaration looks like.

            Used by

              The fold deriving Enc writes for a type that names itself #

              A type that names itself has a walk over it, and the subset has no recursion to spell one with, so the walk has to be a name — and a name per type, because the algebra has one function per constructor. deriving Enc writes that name beside the encoding and marks it with the type it walks, so that the walk is found by the mark rather than by a suffix an author's own Category.fold would also carry.

              Beside the fold it writes the alternatives a fold is reified to and the certificate that the subset's walk over them computes it. Reify reads all three where an author calls the fold, so what is pinned here is what that reading stands on.

              The alternatives: one per constructor, in declaration order, every field bound. An author writes no match to fold, so there is no matcher to read them off — Reify writes them, and binding every field is what makes them exhaustive at every column the walk goes into.

              And the two halves meeting, which is what a reified fold will be: the plumbing takes the scrutinee and a walk, deriving Enc wrote the walk for the type that has one, and the alternatives the walk was proved about are the ones Reify writes. Nothing here knows what the bodies are — only that each denotes its constructor's own function, which is what reifying the algebra's lambda hands over.

              What the walk refuses #

              A refusal that cannot name what to write instead names the rule the term broke, and the three rules are the three questions the subset reference opens with: what may be a value, how a program repeats, and whose vocabulary it reads. One fixture per rule is what keeps the two sides from drifting — the wording lives in Lean2Js.Reify and is read back here.

              Lean's / on Int rounds towards negative infinity and the subset's truncates, so / is not a form the walk may quietly accept. It refuses at the reify_decl% call rather than at the author's /: Lean.Expr carries no source positions, so pointing at the author's own syntax needs more than the elaborated term.

              A lambda is a value nowhere: the traversals carry their binder and body as syntax, and every other position wants a value the boundary can carry.

              A type with no Enc has no place in Value, so there is nothing for the boundary to carry it as.

              abbrev

              _private.Lean2Js.Denote.0.Lean2Js.Denote.Untagged.amount

              source
              @[reducible]
              (self : Untagged) :
              Equations
              Instances For
                Used by

                  == is the one refusal about the type rather than about the term. eval compares encodings, so a type whose BEq is not known to decide equality has nothing to say about what that comparison means.

                  inductive

                  Lean2Js.Denote.Tier

                  source
                  Instances For
                    Used by
                      def

                      Lean2Js.Denote.instBEqTier.beq

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

                          Lean2Js.Denote.instBEqTier

                          source
                          @[instance_reducible]
                          Equations
                          Used by
                            def

                            Lean2Js.Denote.Tier.accepts

                            source
                            (p : Core.Program) (x : Tier) :
                            Equations
                            Instances For
                              Used by
                                def

                                Lean2Js.Denote.Tier.toValue

                                source
                                (x : Tier) :
                                Equations
                                Instances For
                                  Used by
                                    theorem

                                    Lean2Js.Denote.Tier.ty_eq

                                    source
                                    @[simp]
                                    Used by
                                      theorem

                                      Lean2Js.Denote.Tier.toValue_hasTy

                                      source
                                      {p : Core.Program} {x : Tier} :
                                      Used by
                                        instance

                                        Lean2Js.Denote.instEncTier

                                        source
                                        @[instance_reducible]
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Used by
                                          theorem

                                          Lean2Js.Denote.Tier.toValue_eq

                                          source
                                          @[simp]
                                          Used by
                                            theorem

                                            Lean2Js.Denote.Tier.ofValue_toValue

                                            source
                                            Used by
                                              def

                                              Lean2Js.Denote.Tier.typeDef

                                              source
                                              Equations
                                              Instances For
                                                Used by
                                                  def

                                                  Lean2Js.Denote.Tier.ofValue

                                                  source
                                                  Equations
                                                  Instances For
                                                    Used by

                                                      A call is the one refusal the author can act on, so it says which certificate was missing rather than that the term was unreadable.

                                                      def

                                                      Lean2Js.Denote.uncertified

                                                      source
                                                      (x : Int) :
                                                      Equations
                                                      Instances For
                                                        Used by
                                                          def

                                                          Lean2Js.Denote.callsUncertified

                                                          source
                                                          (x : Int) :
                                                          Equations
                                                          Instances For
                                                            Used by

                                                              A function crosses the boundary as a declaration's name, so a function the author wrote inline has no name to cross as.