In this section

A build publishes the module <name> into <out_dir>/<name>, by default $OUT_DIR/lungo/<name>, where <name> is the Lake package’s name unless configured (see configuration). The directory is replaced atomically: it holds either the previous complete output or the new one.

Files

File Contents
<name>.rs The aggregate include target: the public facade and the compiler layer.
modules/<Module>.rs Compiled code of one module of the program, included by the aggregate. File names replace . by - and other non-identifier characters by +<hex>+.
names.json Name mappings.
externs.json Extern resolutions.
sources.json Source locations of compiled declarations.
manifest.json Versions, modules and exports.
assurance.json The program’s assurance document: what its Lean code claims and proves of each export, what it trusts, and what it assumes of the host.
build-info.json Build key and inputs, for incremental rebuilds. Not compiled into the crate.
native/liblungo_oracle_<name>.a LeanOracle mode only: Lean’s native code for the project (- in <name> becomes _).

Paths recorded in these files are relative to the Cargo package; files outside it are written <lean>/… (toolchain sources) or <package>/… (Lake dependencies). No file except build-info.json records machine-specific paths.

The aggregate module

lungo::include_lean!("<name>") includes the aggregate from the default output directory, where it expands to include!(concat!(env!("OUT_DIR"), "/lungo/<name>/<name>.rs")). It is usually the only item of a Rust module:

pub mod formal {
    lungo::include_lean!("formal");
}
Item Contents
types and functions The facade: one item per exported declaration and per type reachable from exports and rust_extern functions, except extern types. Declarations in the facade namespace are at the root; A.B.f is a::b::f; other names are under _root_.
<Op>Handler traits One per async facility the exports use, in the module of its operation type Op: see async exports.
__meta Metadata; see below.
__lean_main(), __lean_main_with(args) Present when a root module defines main. Run the Lean program with the process arguments (or args) and return its exit code.
__lng, __opaque, __oracle Hidden: the compiler layer, marker types of opaque values, the LeanOracle backend. Not a stable interface.

Every facade function initializes the program’s modules on first use. Its doc comment records the Lean name, type and source location, unless disable_comments selects it. Generated types derive Clone, Debug (unless skip_debug selects them), and PartialEq, Eq and Hash where all their fields implement them, followed by the configured attributes.

Facility operations

The operations of the program’s facilities (@[lungo_operation] externs) are implemented by the Rust functions rust_extern maps them to. The compiled code calls each through a generated adapter, so the function takes and returns facade types: an operation hostLookup (key : @& String) : Option Nat is implemented by fn lookup(key: String) -> Option<lungo::Nat>, and an IO operation returns Result<T, lungo::IoError>. An operation with a pure Lean type must answer the same arguments the same way: Lean may evaluate a call once and keep its value.

Async exports

An export returning Lungo.Async.Program Op α is an async fn whose first parameter is a handler of the async facility over Op:

pub trait AskHandler {
    /// What a method fails with.
    type Error;
    /// Performs `Host.Ask.fetch`.
    fn fetch(&self, key: String) -> impl Future<Output = Result<Result<Nat, String>, Self::Error>>;
    /// Performs `Host.Ask.tool`.
    fn tool(&self, name: String) -> impl Future<Output = Result<LeanClosure<fn(Nat) -> Nat>, Self::Error>>;
}

pub async fn sum_keys<H: AskHandler>(handler: &H, keys: List<String>) -> Result<Nat, H::Error>;

The trait is named after the operation type, <Op>Handler, with one method per constructor of Op, taking the constructor’s fields and answering with the type the facility’s Lungo.Async.Interface instance gives it (async fn implements such a method). The function runs the program, awaits the handler for each operation it asks, and resumes the program with the answer. A method’s error abandons the program and the function returns it. Dropping the future before it completes releases the program and everything it holds. The function needs no particular executor.

__meta

Item Type
LEAN_VERSION, LEAN_GITHASH &str: the toolchain the code was compiled with.
BIR_VERSION u32
GENERATOR_VERSION &str: the lungo version.
declaration(lean_name) Option<&'static lungo::DeclarationInfo> for an exported declaration.
declarations() &'static [DeclarationInfo], sorted by Lean name.
module_source(module), source(lean_name) Option<&'static str>: embedded Lean source. Present with embed_sources.
assurance() &'static lungo::Assurance: the program’s assurance, typed. See below.
ASSURANCE_JSON &str: the text of assurance.json, byte for byte.

DeclarationInfo:

Field Type Meaning
lean_name &str Fully qualified Lean name.
module &str Defining module.
source_file Option<&str> Source file, package-relative.
range Option<SourceRange> One-based start/end SourcePosition { line, column }.
lean_type &str The Lean type, pretty-printed.
compiled_signature &str Runtime representation, e.g. (u8, obj) -> tobj; @& marks borrowed parameters.
rust_path &str Path of the Rust item within the aggregate module.
trust ExportTrust See below.
assurance ExportAssurance See below.

ExportTrust:

Field Meaning
axioms Axioms the definition depends on, excluding sorryAx.
depends_on_sorry Whether it depends on sorry.
unsafe_dependencies unsafe constants in the executable closure: the declaration itself and those outside the Lean toolchain.
partial_dependencies partial constants, with the same scope.
extern_dependencies Extern symbols the compiled code calls.

ExportAssurance:

Field Meaning
claims The claims about the export (their evidence theorems’ names).
assumptions The assumptions about the host those claims are conditional on, and those of the facilities the export calls.
facilities The facilities whose operations the export calls (Lean names).
roles The export’s roles, such as lungo.oracle.
asynchronous Whether the export returns an async program.

lungo::Assurance holds every record of the assurance document, each slice sorted by name: specifications (Specification: name, kind, statement, definition, package, fingerprint), facilities (Facility: name, id, asynchronous, operations, assumptions, package, fingerprint), assumptions (Assumption: name, facility, statement, definition, package, fingerprint), claims (Claim: name, relation, subjects, specifications, statement, status — ClaimStatus::Proved or ClaimStatus::Incomplete —, evidence_axioms, assumptions, package, fingerprint) and roles (Role: name, role, exported), with schema_version and program. claim(name), claims_about(lean_name), facility(name), assumption(name) and specification(name) look records up.

names.json

An array of records, one per public Rust name:

Field Meaning
lean_name The Lean name. Fields of structures are <Structure>.<field>; other constructor arguments <Constructor>.<binder>, or <Constructor>#<index> for unnamed binders.
kind type, function, constructor, field, or extern type for a type the application provides with extern_type.
rust_path The Rust path within the aggregate module (for an extern type, the configured path); fields are <constructor path>.<field>, e.g. Sess.is_open, Shape::Rect.width, Pixel.0.
renamed Whether the Rust identifier differs from the last component of the Lean name.

Items come first, in placement order, then constructors and fields.

externs.json

An array, one record per extern declaration in the program:

Field Meaning
declaration The Lean extern declaration.
key The symbol (or the declaration’s name for adhoc externs).
resolution lean_export (a Lean @[export] definition), runtime (a lungo primitive), or application (a rust_extern function).
implementation The Lean definition, runtime path, or Rust path.
lean_type The Lean type, when the declaration has a source-level constant.
source Source location, when known.

sources.json

An array of { lean_name, file, start, end }, with start/end as [line, column] or null, for every source-level declaration with compiled code.

manifest.json

Field Meaning
lean_version, lean_githash The toolchain.
bir_version, generator_version, runtime_abi lungo versions.
modules Modules of the program, in initialization order.
declarations Number of compiled declarations.
exports Per export: lean_name, module, rust_path, lean_type, source.

What the exports trust is in assurance.json, with their claims and assumptions.

assurance.json

The program’s assurance document, the same file byte for byte in every output lungo generates for the program, whatever the language. The aggregate module embeds its text as __meta::ASSURANCE_JSON and its records as __meta::assurance() (above). Its schema, ordering and fingerprints are in assurance.json.

build-info.json

Field Meaning
build_key Digest of everything the output depends on besides input files: toolchain identity, configuration, target, lungo and worker versions, generator binary.
lean_version, lean_githash, bir_version, adapter_version, lungo_version, runtime_abi, worker_identity Versions.
input_digests Input files (relative to the Lean project) and their content digests.
project The Lean project directory, relative to the package.
link_directives Cargo link directives (empty in PureRust mode).

Versioning

Generated code asserts the runtime ABI it was generated for at compile time (lungo::__runtime::assert_abi::<N>()), so output generated by a different lungo version fails to compile rather than running against an incompatible runtime.