lean2js

Lean2Js.Js

source

The AST of the JavaScript to emit, and the ESM and .d.ts printers #

The AST of the JavaScript to emit, and the ESM / .d.ts printers.

Parentheses are always written, without consulting precedence. A precedence table would go on the compiler's trusted base and buy only prettier output.

inductive

Lean2Js.Js.TyDesc

source

A type expanded into what the generated code needs in order to check a value against it at runtime. Ty.named is resolved away here rather than emitting a table of type definitions, so a function carries only the shapes it actually accepts and a bundler can still drop the ones nobody imported.

Instances For
    Used by
      instance

      Lean2Js.Js.instInhabitedTyDesc

      source
      @[instance_reducible]
      Equations
      Used by
        instance

        Lean2Js.Js.instBEqTyDesc

        source
        @[instance_reducible]
        Equations
        Used by
          partial def

          Lean2Js.Js.instBEqTyDesc.beq

          source
          :
          Used by
            abbrev

            Lean2Js.Js.TyAlts

            source
            @[reducible, inline]

            A declared type's constructors as the descriptor carries them: the constructor's name, and its fields in declared order.

            Equations
            Instances For
              Used by
                abbrev

                Lean2Js.Js.TyEnv

                source
                @[reducible, inline]

                What the mu nodes a walk is inside have bound, nearest first: the key a constructor's name is carried under, and the alternatives.

                A ref continues at an entry of this rather than at a descriptor read out of it, which is what keeps the walk measured by the value: the entry is fed back as a ctors node, which descends into fields, so no step can land on another ref.

                Equations
                Instances For
                  Used by
                    inductive

                    Lean2Js.Js.FoldKind

                    source

                    How a fold carries one of a constructor's fields: the declared type coming round, a list of it coming round, or neither. It is what EncDeriving.kindOf already computes at the deriving, written where the generated code reads it.

                    Instances For
                      Used by
                        instance

                        Lean2Js.Js.instBEqFoldKind

                        source
                        @[instance_reducible]
                        Equations
                        Used by
                          def

                          Lean2Js.Js.instBEqFoldKind.beq

                          source
                          Equations
                          Instances For
                            Used by
                              def

                              Lean2Js.Js.instReprFoldKind.repr

                              source
                              Equations
                              Instances For
                                Used by
                                  instance

                                  Lean2Js.Js.instReprFoldKind

                                  source
                                  @[instance_reducible]
                                  Equations
                                  Used by
                                    instance

                                    Lean2Js.Js.instInhabitedFoldKind

                                    source
                                    @[instance_reducible]
                                    Equations
                                    Used by
                                      instance

                                      Lean2Js.Js.instDecidableEqFoldKind

                                      source
                                      @[instance_reducible]
                                      Equations
                                      Used by
                                        def

                                        Lean2Js.Js.FoldKind.render

                                        source
                                        Equations
                                        Instances For
                                          Used by
                                            abbrev

                                            Lean2Js.Js.FoldFields

                                            source
                                            @[reducible, inline]

                                            A constructor's fields in declared order, each with the way the fold carries it.

                                            Equations
                                            Instances For
                                              Used by
                                                abbrev

                                                Lean2Js.Js.FoldSpec

                                                source
                                                @[reducible, inline]

                                                What a fold is given about a declared type: its constructors by name, each with its fields.

                                                Apart from TyAlts, which carries the same names, because the two say different things: one is what a value is checked against, this is which of a node's fields the walk goes into. A fold reads it at the constructor the value carries, so a name it does not hold is a value the walk declines to answer for.

                                                Equations
                                                Instances For
                                                  Used by
                                                    def

                                                    Lean2Js.Js.renderFoldFields

                                                    source

                                                    A constructor's fields as the generated code reads them: each field's name beside the way the fold carries it, in declared order. Written as a recursion rather than through List.map, for the reason the rest of the printer is: the text the artifact carries has to be something a proof can unfold.

                                                    Equations
                                                    Instances For
                                                      Used by
                                                        def

                                                        Lean2Js.Js.renderFoldSpec

                                                        source

                                                        The spec __fold reads, printed as the object it indexes by the constructor's name. Spelled { and } the way Expr.objLit is, so that the reader tells the end of an empty one from the start of an entry by the same one character of lookahead.

                                                        Equations
                                                        Instances For
                                                          Used by
                                                            def

                                                            Lean2Js.Js.TyDesc.render

                                                            source
                                                            @[irreducible]

                                                            The descriptor the entry check reads. Total for the reason Expr.render is: the text the artifact carries has to be something a proof can unfold.

                                                            Equations
                                                            Instances For
                                                              Used by
                                                                def

                                                                Lean2Js.Js.TyDesc.renderFields

                                                                source
                                                                @[irreducible]
                                                                Equations
                                                                Instances For
                                                                  Used by
                                                                    def

                                                                    Lean2Js.Js.TyDesc.renderAlts

                                                                    source
                                                                    @[irreducible]
                                                                    Equations
                                                                    Instances For
                                                                      Used by

                                                                        Descriptors that reach no dictionary crossing as an object #

                                                                        A dictionary declared to cross as a plain object is the one node a declaration's walk out moves, so a return type whose expanded descriptor reaches none needs no walk at all: the entry hands the body's result straight back and is byte-for-byte what it was before a dictionary could cross as an object. A ref says nothing on its own — it resolves against the environment — so envNoDictObj is the other half of the reading.

                                                                        def

                                                                        Lean2Js.Js.descNoDictObj

                                                                        source
                                                                        @[irreducible]
                                                                        :
                                                                        Equations
                                                                        Instances For
                                                                          Used by
                                                                            def

                                                                            Lean2Js.Js.fieldsNoDictObj

                                                                            source
                                                                            @[irreducible]
                                                                            Equations
                                                                            Instances For
                                                                              Used by
                                                                                def

                                                                                Lean2Js.Js.altsNoDictObj

                                                                                source
                                                                                @[irreducible]
                                                                                Equations
                                                                                Instances For
                                                                                  Used by
                                                                                    def

                                                                                    Lean2Js.Js.envNoDictObj

                                                                                    source
                                                                                    :
                                                                                    Equations
                                                                                    Instances For
                                                                                      Used by
                                                                                        def

                                                                                        Lean2Js.Js.renderNames

                                                                                        source

                                                                                        A comma-separated list of names. Written as a recursion rather than String.intercalate, which walks an accumulator and does not unfold in a proof, for the reason the rest of the printer is: the file the compiler writes has to be something a proof can read back.

                                                                                        Equations
                                                                                        Instances For
                                                                                          Used by
                                                                                            inductive

                                                                                            Lean2Js.Js.Expr

                                                                                            source
                                                                                            Instances For
                                                                                              Used by
                                                                                                instance

                                                                                                Lean2Js.Js.instInhabitedExpr

                                                                                                source
                                                                                                @[instance_reducible]
                                                                                                Equations
                                                                                                Used by
                                                                                                  instance

                                                                                                  Lean2Js.Js.instBEqExpr

                                                                                                  source
                                                                                                  @[instance_reducible]
                                                                                                  Equations
                                                                                                  Used by
                                                                                                    partial def

                                                                                                    Lean2Js.Js.instBEqExpr.beq

                                                                                                    source
                                                                                                    :
                                                                                                    Expr → Expr → Bool
                                                                                                    Used by
                                                                                                      inductive

                                                                                                      Lean2Js.Js.Stmt

                                                                                                      source
                                                                                                      Instances For
                                                                                                        Used by
                                                                                                          instance

                                                                                                          Lean2Js.Js.instInhabitedStmt

                                                                                                          source
                                                                                                          @[instance_reducible]
                                                                                                          Equations
                                                                                                          Used by
                                                                                                            def

                                                                                                            Lean2Js.Js.instBEqStmt.beq

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

                                                                                                                Lean2Js.Js.instBEqStmt

                                                                                                                source
                                                                                                                @[instance_reducible]
                                                                                                                Equations
                                                                                                                Used by
                                                                                                                  structure

                                                                                                                  Lean2Js.Js.Func

                                                                                                                  source
                                                                                                                  Instances For
                                                                                                                    Used by
                                                                                                                      instance

                                                                                                                      Lean2Js.Js.instInhabitedFunc

                                                                                                                      source
                                                                                                                      @[instance_reducible]
                                                                                                                      Equations
                                                                                                                      Used by
                                                                                                                        instance

                                                                                                                        Lean2Js.Js.instBEqFunc

                                                                                                                        source
                                                                                                                        @[instance_reducible]
                                                                                                                        Equations
                                                                                                                        Used by
                                                                                                                          def

                                                                                                                          Lean2Js.Js.instBEqFunc.beq

                                                                                                                          source
                                                                                                                          :
                                                                                                                          Func → Func → Bool
                                                                                                                          Equations
                                                                                                                          Instances For
                                                                                                                            Used by
                                                                                                                              structure

                                                                                                                              Lean2Js.Js.Module

                                                                                                                              source
                                                                                                                              Instances For
                                                                                                                                Used by
                                                                                                                                  instance

                                                                                                                                  Lean2Js.Js.instInhabitedModule

                                                                                                                                  source
                                                                                                                                  @[instance_reducible]
                                                                                                                                  Equations
                                                                                                                                  Used by
                                                                                                                                    instance

                                                                                                                                    Lean2Js.Js.instBEqModule

                                                                                                                                    source
                                                                                                                                    @[instance_reducible]
                                                                                                                                    Equations
                                                                                                                                    Used by
                                                                                                                                      def

                                                                                                                                      Lean2Js.Js.instBEqModule.beq

                                                                                                                                      source
                                                                                                                                      :
                                                                                                                                      Equations
                                                                                                                                      Instances For
                                                                                                                                        Used by
                                                                                                                                          def

                                                                                                                                          Lean2Js.Js.Expr.render

                                                                                                                                          source
                                                                                                                                          @[irreducible]
                                                                                                                                          :

                                                                                                                                          The text the module carries. Written as a mutual recursion over the lists rather than partial, so a proof about the file the compiler writes can unfold it.

                                                                                                                                          Equations
                                                                                                                                          Instances For
                                                                                                                                            Used by
                                                                                                                                              def

                                                                                                                                              Lean2Js.Js.Expr.renderList

                                                                                                                                              source
                                                                                                                                              @[irreducible]
                                                                                                                                              Equations
                                                                                                                                              Instances For
                                                                                                                                                Used by
                                                                                                                                                  def

                                                                                                                                                  Lean2Js.Js.Expr.renderFields

                                                                                                                                                  source
                                                                                                                                                  @[irreducible]
                                                                                                                                                  Equations
                                                                                                                                                  Instances For
                                                                                                                                                    Used by
                                                                                                                                                      def

                                                                                                                                                      Lean2Js.Js.Expr.renderEntries

                                                                                                                                                      source
                                                                                                                                                      @[irreducible]
                                                                                                                                                      Equations
                                                                                                                                                      Instances For
                                                                                                                                                        Used by
                                                                                                                                                          def

                                                                                                                                                          Lean2Js.Js.Stmt.render

                                                                                                                                                          source
                                                                                                                                                          :
                                                                                                                                                          Equations
                                                                                                                                                          Instances For
                                                                                                                                                            Used by
                                                                                                                                                              def

                                                                                                                                                              Lean2Js.Js.Stmt.renderAll

                                                                                                                                                              source
                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                Used by
                                                                                                                                                                  def

                                                                                                                                                                  Lean2Js.Js.Func.render

                                                                                                                                                                  source
                                                                                                                                                                  (f : Func) :
                                                                                                                                                                  Equations
                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                  Instances For
                                                                                                                                                                    Used by
                                                                                                                                                                      def

                                                                                                                                                                      Lean2Js.Js.runtime

                                                                                                                                                                      source

                                                                                                                                                                      The runtime helpers the generated code calls, printed from Helper.defs.

                                                                                                                                                                      Equations
                                                                                                                                                                      Instances For
                                                                                                                                                                        Used by
                                                                                                                                                                          def

                                                                                                                                                                          Lean2Js.Js.Func.renderAll

                                                                                                                                                                          source
                                                                                                                                                                          Equations
                                                                                                                                                                          Instances For
                                                                                                                                                                            Used by
                                                                                                                                                                              def

                                                                                                                                                                              Lean2Js.Js.preambleComment

                                                                                                                                                                              source

                                                                                                                                                                              Named apart from the preamble, and the preamble associated to the right, so a proof can read the length of what the file opens with without unfolding the runtime behind it.

                                                                                                                                                                              Equations
                                                                                                                                                                              Instances For
                                                                                                                                                                                Used by
                                                                                                                                                                                  def

                                                                                                                                                                                  Lean2Js.Js.preamble

                                                                                                                                                                                  source

                                                                                                                                                                                  Named rather than spelled out at the use site: a proof about the file has to unfold the printer around them, and the runtime is four thousand characters the elaborator would otherwise carry.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For
                                                                                                                                                                                    Used by
                                                                                                                                                                                      def

                                                                                                                                                                                      Lean2Js.Js.Module.render

                                                                                                                                                                                      source
                                                                                                                                                                                      (m : Module) :

                                                                                                                                                                                      The text of the file the compiler writes.

                                                                                                                                                                                      Equations
                                                                                                                                                                                      Instances For
                                                                                                                                                                                        Used by
                                                                                                                                                                                          def

                                                                                                                                                                                          Lean2Js.Js.tsType

                                                                                                                                                                                          source
                                                                                                                                                                                          @[irreducible]

                                                                                                                                                                                          The type the .d.ts gives a value of this type. Total for the reason the renderers are: the file the compiler writes has to be something a proof can unfold.

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For
                                                                                                                                                                                            Used by
                                                                                                                                                                                              def

                                                                                                                                                                                              Lean2Js.Js.tsTypeList

                                                                                                                                                                                              source
                                                                                                                                                                                              @[irreducible]
                                                                                                                                                                                              Equations
                                                                                                                                                                                              Instances For
                                                                                                                                                                                                Used by
                                                                                                                                                                                                  def

                                                                                                                                                                                                  Lean2Js.Js.tsParams

                                                                                                                                                                                                  source
                                                                                                                                                                                                  @[irreducible]
                                                                                                                                                                                                  (i : Nat) :
                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                    Used by
                                                                                                                                                                                                      def

                                                                                                                                                                                                      Lean2Js.Js.tsTypeOut

                                                                                                                                                                                                      source
                                                                                                                                                                                                      @[irreducible]

                                                                                                                                                                                                      The type the .d.ts gives a value of this type where it is being handed back. A Dict.Obj V parameter is printed as the union above because the entry takes either spelling; a Dict.Obj V return is the plain object alone, because the entry walked it out to one and nothing else can come back. Stops at a declared type: one interface is printed for both directions, so a Dict.Obj field there keeps the union.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                        Used by
                                                                                                                                                                                                          def

                                                                                                                                                                                                          Lean2Js.Js.declareFunc

                                                                                                                                                                                                          source
                                                                                                                                                                                                          (d : Core.Decl) (codes : List String) (doc : Option String := none) :

                                                                                                                                                                                                          The .d.ts is the only thing a consumer reads before calling, so it carries what the author wrote about the function and the one fact the types cannot say: the call throws rather than returning a value the semantics would not stand behind.

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

                                                                                                                                                                                                              Lean2Js.Js.renderDts

                                                                                                                                                                                                              source
                                                                                                                                                                                                              (p : Core.Program) (docs : List (String × String) := []) :

                                                                                                                                                                                                              Only the types a consumer can name. A declaration that takes a function does not cross the boundary, and neither does a type that only ever holds an intermediate value -- an accumulator a foldl carries appears in no public signature, and printing it would invite a consumer to build one.

                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                Used by