Skip to main content

LeanRuntime

Struct LeanRuntime 

Source
pub struct LeanRuntime { /* private fields */ }
Expand description

Handle for the process-wide Lean runtime.

LeanRuntime is a zero-sized type with no public constructor. The only way to obtain one is to call LeanRuntime::init, which returns a 'static borrow once the Lean runtime is up. Every later handle (Obj<'lean>, LeanExpr<'lean>, LeanSession<'lean, '_>, …) carries a 'lean lifetime tied to this borrow, so a value derived from Lean cannot outlive the runtime that produced it. This is the type-system anchor for the 'lean cascade described in docs/architecture/03-host-stack.md.

Neither Send nor Sync. The Lean runtime is per-thread, and shipping a Lean-derived handle to another OS thread is a soundness hazard rather than an ergonomic choice; the !Sync claim here forces &'lean LeanRuntime to be !Send, and every downstream handle that holds PhantomData<&'lean LeanRuntime> inherits the same restriction.

Implementations§

Source§

impl LeanRuntime

Source

pub fn init() -> LeanResult<&'static Self>

Initialize the Lean runtime if it has not already been initialized, and return a 'static borrow that anchors the 'lean lifetime cascade.

Idempotent and safe to call from any thread: the underlying initialization runs exactly once for the lifetime of the process. Subsequent calls—including calls from other threads—return the same borrow, or replay the cached failure if the first attempt failed.

§Worker threads

init starts a process-wide Lean task manager. The worker thread count is Lean’s compiled-in default—typically one worker per hardware core—unless the LEAN_RS_NUM_THREADS environment variable is set to a positive integer before the first call to init. The first call captures the value; later changes to the variable have no effect. Set LEAN_RS_NUM_THREADS when several Lean-using processes run side by side (CI test matrices, batch jobs, multi-tenant workers) to avoid oversubscribing cores. The pool is process-lifetime; there is no set_num_threads-style reconfiguration once init has run.

§Errors

Returns a LeanError::Host with stage HostStage::RuntimeInit if initialization failed. Today the only reachable failure is a caught panic from the Lean lean_initialize_* entry points; the panic payload is rendered into a bounded message so it cannot unwind into Lean or C frames.

Trait Implementations§

Source§

impl Debug for LeanRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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