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
- Lean.Idbg.nameToJson Lean.Name.anonymous = Lean.Json.null
- Lean.Idbg.nameToJson (p.str s) = Lean.Json.mkObj [("str", Lean.Json.arr #[Lean.Idbg.nameToJson p, Lean.toJson s])]
- Lean.Idbg.nameToJson (p.num n) = Lean.Json.mkObj [("num", Lean.Json.arr #[Lean.Idbg.nameToJson p, Lean.Json.num (Lean.JsonNumber.fromNat n)])]
Instances For
Serialize BinderInfo to JSON.
Equations
- Lean.Idbg.binderInfoToJson Lean.BinderInfo.default = Lean.Json.str "default"
- Lean.Idbg.binderInfoToJson Lean.BinderInfo.implicit = Lean.Json.str "implicit"
- Lean.Idbg.binderInfoToJson Lean.BinderInfo.strictImplicit = Lean.Json.str "strictImplicit"
- Lean.Idbg.binderInfoToJson Lean.BinderInfo.instImplicit = Lean.Json.str "instImplicit"
Instances For
Deserialize BinderInfo from JSON.
Equations
- Lean.Idbg.binderInfoFromJson? (Lean.Json.str "default") = Except.ok Lean.BinderInfo.default
- Lean.Idbg.binderInfoFromJson? (Lean.Json.str "implicit") = Except.ok Lean.BinderInfo.implicit
- Lean.Idbg.binderInfoFromJson? (Lean.Json.str "strictImplicit") = Except.ok Lean.BinderInfo.strictImplicit
- Lean.Idbg.binderInfoFromJson? (Lean.Json.str "instImplicit") = Except.ok Lean.BinderInfo.instImplicit
- Lean.Idbg.binderInfoFromJson? x✝ = Except.error (toString "expected BinderInfo, got " ++ toString x✝)
Instances For
Serialize Literal to JSON.
Equations
Instances For
Serialize Expr to JSON. Metadata is stripped; free variables are preserved.
Deterministic port for a given idbg site, in range [10000, 65535].
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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
- Lean.Idbg.idbgLoadEnv imports = tryCatch (Lean.importModules imports ∅) fun (x : IO.Error) => Lean.importModules imports.pop ∅
Instances For
Compile and evaluate an expression in the given environment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.