Skip to main content

olean_export/
lib.rs

1//! Read Lean 4 `.olean` files directly and emit the lean4export NDJSON stream, without
2//! starting Lean.
3#![allow(
4    clippy::missing_errors_doc,
5    clippy::redundant_pub_crate,
6    clippy::too_many_lines,
7    clippy::missing_panics_doc,
8    clippy::module_name_repetitions,
9    clippy::similar_names,
10    clippy::many_single_char_names
11)]
12
13mod env;
14mod error;
15mod export;
16mod olean;
17
18pub use env::{
19    search_path, Binder, Body, Const, Ctor, Defn, Env, Expr, ExprId, Exprs, Hints, Id, Inductive,
20    Kind, Level, LevelId, Name, NameId, QuotKind, Rec, Rule, Table, ANON, ZERO,
21};
22pub use error::{Error, Result};
23pub use export::{Counts, Exporter};
24pub use olean::{Header, SUPPORTED};
25
26const STACK: usize = 1 << 30;
27
28/// Run `f` on a thread with a stack deep enough for long application spines and binder chains,
29/// re-raising its panic if it has one. [`Exporter`] recurses over terms, so run it inside this.
30pub fn with_big_stack<T: Send>(f: impl FnOnce() -> T + Send) -> T {
31    std::thread::scope(|s| {
32        std::thread::Builder::new()
33            .stack_size(STACK)
34            .spawn_scoped(s, f)
35            .expect("spawn")
36            .join()
37            .unwrap_or_else(|e| std::panic::resume_unwind(e))
38    })
39}