Documentation

Lean.Idbg

Runtime support for the interactive debug expression evaluator (idbg) #

idbg enables live communication between a running compiled Lean program and the language server. This module contains the parts used by the compiled program, whose entry point Lean.Idbg.idbgClientLoop is declared in Lean.Setup. The elaborator is in Lean.Elab.Idbg.

Protocol #

Communication uses a length-prefixed TCP protocol over localhost. Both server (language server side) and client (compiled program side) compute a deterministic port from the source location hash.

Custom Name serialization that preserves the exact structure. The standard ToJson/FromJson Name uses toString/toName which doesn't round-trip for hygienic names (e.g., names containing @).

Equations
Instances For

    Deserialize Literal from JSON.

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

      Serialize Level to JSON.

      Deserialize Level from JSON.

      partial def Lean.Idbg.exprToJson :

      Serialize Expr to JSON. Metadata is stripped; free variables are preserved.

      Deserialize Expr from JSON.

      Deterministic port for a given idbg site, in range [10000, 65535].

      Equations
      Instances For
        Equations
        Instances For
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def Lean.Idbg.idbgServer (siteId : String) (exprJson : Json) :

            Start a TCP server on the deterministic port for this site, wait for one connection, send expression JSON, and receive the result string. Returns none if the port is still held by a previous (cancelled) server.

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

              Load the program's environment from its imports. The imports include the current module (appended last by the elaborator) so that same-file declarations are available. If its .olean is not found (e.g., when running lean directly), we fall back to just the transitive imports.

              Equations
              Instances For
                def Lean.Idbg.idbgCompileAndEval (α : Type) [Nonempty α] (env : Environment) (type value : Expr) :
                IO α

                Compile and evaluate an expression in the given environment.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[export lean_idbg_client_loop]
                  def Lean.Idbg.idbgClientLoopImpl (siteId : String) (imports : Array Import) (apply : NonScalar → String) :

                  Connect to the debug server, receive expressions, evaluate, send results. Loops forever.

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