Skip to main content

LeanWorkerSession

Struct LeanWorkerSession 

Source
pub struct LeanWorkerSession<'worker> { /* private fields */ }
Expand description

Narrow host-session adapter over a live LeanWorker.

Dropping this value does not stop the worker. If a request is cancelled while in flight, the supervisor cycles the child process and this session is invalidated; open a fresh session before issuing more host requests.

Implementations§

Source§

impl LeanWorkerSession<'_>

Source

pub fn request_timeout(&self) -> Duration

Return the timeout used for subsequent requests on this session.

Source

pub fn set_request_timeout(&mut self, timeout: Duration)

Change the timeout for subsequent requests on this session.

A timeout is parent-enforced. If it fires, the supervisor kills and replaces the child process and invalidates this session.

Source

pub fn elaborate( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerElabResult, LeanWorkerError>

Elaborate one term and return only process-safe success/diagnostic data.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails.

Source

pub fn kernel_check( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerKernelResult, LeanWorkerError>

Kernel-check one declaration and return only process-safe status/diagnostics.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails.

Source

pub fn declaration_kinds( &mut self, names: &[&str], cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Vec<String>, LeanWorkerError>

Query declaration kinds in bulk.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails.

Source

pub fn declaration_names( &mut self, names: &[&str], cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Vec<String>, LeanWorkerError>

Render declaration names in bulk.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails.

Source

pub fn infer_type( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerMetaResult<LeanWorkerRendered>, LeanWorkerError>

Elaborate source and infer the resulting expression’s type.

The child attempts notation-aware rendering via the optional meta_pp_expr shim (Lean.PrettyPrinter.ppExpr) and falls back to Expr.toString when the shim is absent or reports Unsupported. The returned LeanWorkerRendered::rendering reports which path produced the value.

Heartbeat budgeting: each MetaM pass (the primary inferType call and the pretty-printer) runs under the same LeanWorkerElabOptions::heartbeat_limit value, independently bounded — the pretty-printer does not consume budget left over from the primary call. A Failed or TimeoutOrHeartbeat reported by the pretty-printer surfaces as the whole call’s failure (matching in-process behaviour); there is no path that returns the inferred expression alongside a pretty-printer failure. Only Unsupported from pp_expr triggers the raw fallback.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails. Lean-side failures (type errors, heartbeat exhaustion, missing capability) surface inside the returned LeanWorkerMetaResult rather than as Err.

Source

pub fn whnf( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerMetaResult<LeanWorkerRendered>, LeanWorkerError>

Elaborate source and reduce it to weak head normal form.

Rendering and heartbeat-budgeting semantics match Self::infer_type: the child attempts notation-aware rendering via meta_pp_expr and falls back to Expr.toString when the shim reports Unsupported. Each MetaM pass is independently bounded by heartbeat_limit; a Failed or TimeoutOrHeartbeat from the pretty-printer surfaces as the whole call’s failure.

§Errors

Returns LeanWorkerError under the same conditions as Self::infer_type. Lean-side failures surface inside the returned LeanWorkerMetaResult.

Source

pub fn is_def_eq( &mut self, lhs: &str, rhs: &str, transparency: LeanWorkerMetaTransparency, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerMetaResult<bool>, LeanWorkerError>

Elaborate lhs and rhs and ask Lean whether they are definitionally equal at the supplied transparency.

§Errors

Returns LeanWorkerError under the same conditions as Self::infer_type. Lean-side failures surface inside the returned LeanWorkerMetaResult.

Source

pub fn describe( &mut self, name: &str, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Option<LeanWorkerDeclarationRow>, LeanWorkerError>

Describe a declaration: its kind, rendered type, and source range.

Returns Ok(None) when the name is not in the session’s open environment.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails.

Source

pub fn list_declarations_strings( &mut self, filter: &LeanWorkerDeclarationFilter, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Vec<String>, LeanWorkerError>

Enumerate the session’s open environment and return the matching declaration names as dotted strings.

The child streams names one per protocol frame so total payload size is unbounded; any single Lean name fits well under the per-frame cap.

§Errors

Returns LeanWorkerError under the same conditions as Self::describe.

Source

pub fn describe_bulk( &mut self, names: &[&str], cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Vec<LeanWorkerDeclarationRow>, LeanWorkerError>

Describe a batch of declarations in one IPC round-trip.

Each input name produces one row in the returned vector, in the same order. Absent names keep their slot with kind == "missing", type_signature: None, and source: None so callers can correlate rows back to inputs positionally.

§Errors

Returns LeanWorkerError under the same conditions as Self::describe.

Source

pub fn process_file( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerProcessFileOutcome, LeanWorkerError>

Parse, elaborate, and project a Lean source string into an Elab.InfoTree projection. The session’s open environment supplies the imports; the source must not declare its own header.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host error, cancellation is observed, a progress sink panics, or protocol communication fails. Per-command elaboration failures appear inside LeanWorkerProcessedFile::diagnostics; the LeanWorkerProcessFileOutcome::Unsupported arm surfaces missing capability shims.

Source

pub fn process_module( &mut self, source: &str, options: &LeanWorkerElabOptions, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerProcessModuleOutcome, LeanWorkerError>

Parse a Lean module header (import declarations and prelude) and elaborate the body; project both into an Elab.InfoTree projection plus the parsed import list.

§Errors

Returns LeanWorkerError under the same conditions as Self::process_file. Header-parse failures, missing imports, and missing capability shims surface as variants of LeanWorkerProcessModuleOutcome.

Source

pub fn run_data_stream( &mut self, export: &str, request: &Value, rows: &dyn LeanWorkerDataSink, diagnostics: Option<&dyn LeanWorkerDiagnosticSink>, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerStreamSummary, LeanWorkerError>

Run a downstream streaming export and deliver JSON rows to rows.

The Lean export must have ABI String -> USize -> USize -> IO UInt8. The child supplies the callback handle and trampoline; the parent only sees validated LeanWorkerDataRow values.

§Errors

Returns LeanWorkerError if the worker is dead, the child reports a host or stream error, cancellation is observed, a sink panics, or protocol communication fails. In-flight cancellation cycles the child and invalidates this session.

Source

pub fn run_json_command<Req, Resp>( &mut self, command: &LeanWorkerJsonCommand<Req, Resp>, request: &Req, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<Resp, LeanWorkerError>
where Req: Serialize, Resp: DeserializeOwned,

Run a typed non-streaming downstream JSON command.

The Lean export must have ABI String -> IO String. The request is serialized from Req; the returned JSON string is decoded into Resp. Use this for commands that return one terminal JSON value and no rows.

§Errors

Returns LeanWorkerError if request encoding fails, the worker is dead, the session was invalidated, the export is missing, response decoding fails, cancellation or timeout is observed, a progress sink panics, or protocol communication fails.

Source

pub fn run_streaming_command<Req, Row, Summary>( &mut self, command: &LeanWorkerStreamingCommand<Req, Row, Summary>, request: &Req, rows: &dyn LeanWorkerTypedDataSink<Row>, diagnostics: Option<&dyn LeanWorkerDiagnosticSink>, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerTypedStreamSummary<Summary>, LeanWorkerError>
where Req: Serialize, Row: DeserializeOwned, Summary: DeserializeOwned,

Run a typed downstream streaming command.

The Lean export must have ABI String -> USize -> USize -> IO UInt8. The request is serialized from Req; each row payload is decoded into Row; terminal metadata is decoded into Summary when present. Raw-row access remains available through run_data_stream.

§Errors

Returns LeanWorkerError if request encoding fails, row or summary decoding fails, the worker is dead, the session was invalidated, the export fails, cancellation or timeout is observed, a sink panics, or protocol communication fails. Row decode errors include the stream and sequence that identified the bad payload.

Source

pub fn capability_metadata( &mut self, export: &str, request: &Value, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerCapabilityMetadata, LeanWorkerError>

Query generic metadata from a downstream capability export.

The Lean export must have ABI String -> IO String. The request and response strings are JSON, but callers receive a typed metadata envelope rather than private protocol frames.

§Errors

Returns LeanWorkerError if the worker is dead, the session was invalidated, the export is missing, request or response JSON is malformed, cancellation or timeout is observed, a progress sink panics, or protocol communication fails.

Source

pub fn capability_doctor( &mut self, export: &str, request: &Value, cancellation: Option<&LeanWorkerCancellationToken>, progress: Option<&dyn LeanWorkerProgressSink>, ) -> Result<LeanWorkerDoctorReport, LeanWorkerError>

Run a generic doctor check from a downstream capability export.

The Lean export must have ABI String -> IO String. Doctor diagnostics are capability-layer facts; data rows remain reserved for downstream streaming payloads.

§Errors

Returns LeanWorkerError if the worker is dead, the session was invalidated, the export is missing, request or response JSON is malformed, cancellation or timeout is observed, a progress sink panics, or protocol communication fails.

Auto Trait Implementations§

§

impl<'worker> Freeze for LeanWorkerSession<'worker>

§

impl<'worker> RefUnwindSafe for LeanWorkerSession<'worker>

§

impl<'worker> Send for LeanWorkerSession<'worker>

§

impl<'worker> Sync for LeanWorkerSession<'worker>

§

impl<'worker> Unpin for LeanWorkerSession<'worker>

§

impl<'worker> UnsafeUnpin for LeanWorkerSession<'worker>

§

impl<'worker> !UnwindSafe for LeanWorkerSession<'worker>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more