1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! [`LeanMetaService`]—sealed descriptor for a registered bounded
//! `MetaM` service.
//!
//! Each pinned service ties together:
//!
//! - the Lean-side `@[export]` symbol name the dispatcher resolves;
//! - the list of `.olean` modules that must be imported into the
//! session before the service can run;
//! - the typed request / response shape (encoded as `PhantomData<fn(Req)
//! -> Resp>`) the [`crate::LeanSession::run_meta`] generic
//! parameters must agree with.
//!
//! The struct has no public constructor—the only `LeanMetaService`
//! values downstream code can name are returned by the four free
//! functions in this module, which form the closed registry. Adding a
//! new service requires landing a Lean `@[export]` *and* a Rust-side
//! constructor here.
use PhantomData;
use LeanExpr;
use LeanMetaTransparency;
/// Sealed descriptor for one registered `MetaM` service.
///
/// `Req` is the Rust-side type the call site supplies; `Resp` is the
/// type the typed payload decodes into on the `Ok` branch. The phantom
/// `fn(Req) -> Resp` keeps the marker invariant in both parameters
/// (matching how Lake's emitted signature treats them).
// -- The four pinned services ------------------------------------------
//
// Each constructor returns the typed descriptor `'lean`-parameterised
// over the request/response payload. The Lean-side symbol names and
// import strings are pinned here; the `LeanMetaService` shape is
// otherwise sealed.
const REQUIRED_IMPORTS: & = &;
/// Register the `Meta.inferType` service.
///
/// Calling [`crate::LeanSession::run_meta`] with the returned
/// descriptor and a [`LeanExpr`] returns a typed
/// [`super::LeanMetaResponse`] carrying the inferred type expression on
/// `Ok`.
/// Register the `Meta.whnf` service.
///
/// Returns the weak-head normal form of the supplied expression under
/// the bundle's reducibility setting.
/// Register the diagnostic heartbeat-burn service.
///
/// The Lean-side action loops on `Core.checkMaxHeartbeats`; any nonzero
/// heartbeat budget below the loop bound trips
/// `Lean.Exception.isMaxHeartbeat` and surfaces as
/// `LeanMetaResponse::TimeoutOrHeartbeat`. The supplied `LeanExpr` is
/// ignored—the request shape is uniform with the inference / whnf
/// services so callers do not need a separate "no input" descriptor.
/// Register the `Meta.isDefEq` service.
///
/// The request is the Lean product `(lhs, rhs, transparency)`. The
/// response remains a [`super::LeanMetaResponse<bool>`], so heartbeat
/// exhaustion and Lean exceptions stay distinct from a successful
/// `false`.
/// Register the `Lean.PrettyPrinter.ppExpr` service.
///
/// Returns the pretty-printed string form of the supplied expression—
/// the form a Lean user reads. `MetaM`-bounded, so a deeply nested
/// term under a tight heartbeat budget surfaces as
/// [`super::LeanMetaResponse::TimeoutOrHeartbeat`]. For a cheap,
/// deterministic, ugly alternative that pays no `MetaM` cost, use
/// [`crate::LeanSession::expr_to_string_raw`].
///
/// Optional symbol: capability dylibs that predate this shim still
/// load, and [`crate::LeanSession::run_meta`] returns
/// [`super::LeanMetaResponse::Unsupported`] for the call. Callers that
/// want graceful degradation should fall through to
/// [`crate::LeanSession::expr_to_string_raw`] on the `Unsupported`
/// branch.