logicaffeine_compile/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3
4// Re-export base types
5pub use logicaffeine_base::{Arena, Interner, Symbol, SymbolEq};
6
7// Re-export language types needed for compilation
8pub use logicaffeine_language::{
9 analysis::{DiscoveryPass, PolicyCondition, PolicyRegistry, TypeRegistry},
10 arena_ctx::AstContext,
11 ast, drs, error, formatter, lexer, mwe, optimization, parser,
12 registry::SymbolRegistry,
13 token, Lexer, ParseError, Parser,
14};
15
16// Re-export kernel for extraction
17pub use logicaffeine_kernel as kernel;
18
19// Module loading
20pub mod loader;
21// The stdlib's text and the index the build script derives from it
22pub(crate) mod stdlib_text;
23pub use loader::{Loader, ModuleSource};
24
25// Compile-time analysis
26pub mod analysis;
27
28// Concurrency determinacy model + classifier.
29// Pure AST analysis — independent of the codegen feature.
30pub mod concurrency;
31
32// Code generation
33#[cfg(feature = "codegen")]
34pub mod codegen;
35
36// Counted-loop recognition shared by the for-range peephole and the unroller.
37// Gated with codegen because it reuses the peephole's pure-AST guard helpers;
38// the only consumer is the AOT (Rust-emitting) pipeline.
39#[cfg(feature = "codegen")]
40pub(crate) mod loop_shape;
41
42// C code generation (benchmark-only subset)
43#[cfg(feature = "codegen")]
44pub mod codegen_c;
45
46// LOGOS → RISC-V (RV64GC) AOT codegen tier
47pub mod codegen_riscv;
48
49// The ops no single-device AOT backend can lower (concurrency/networking),
50// classified once so the Tenstorrent and CUDA tiers cannot drift.
51#[cfg(feature = "codegen")]
52pub mod aot_unsupported;
53
54// LOGOS → Tenstorrent (TT-Metalium) AOT codegen tier — single Tensix baby-core
55// kernel + host, reusing the C compute body (needs the `codegen` C backend).
56#[cfg(feature = "codegen")]
57pub mod codegen_tt;
58
59// LOGOS → CUDA AOT codegen tier — one GPU kernel running a whole LOGOS program
60// (integer/bool scalar fragment), lifting the C tier's program body onto the device.
61#[cfg(feature = "codegen")]
62pub mod codegen_cuda;
63
64// The SPATIAL IR — one stage/buffer/handshake/placement program that EVERY spatial backend
65// (our fabric, the RDU, Tensix, a persistent GPU kernel) lowers FROM. Passes are target-parametric;
66// a lowering may only read the IR + its target descriptor, never invent choreography.
67#[cfg(feature = "codegen")]
68pub mod spatial;
69#[cfg(feature = "codegen")]
70pub mod model;
71// Model bring-up: a checkpoint's one program lowered by every chip that runs it (CUDA, the D5005, the SN50), each
72// artifact naming the cut of the program it was lowered from.
73#[cfg(feature = "codegen")]
74pub mod bringup;
75// Tensor programs as graphs of ops, and the transforms over them: reverse-mode differentiation.
76#[cfg(feature = "codegen")]
77pub mod tensor_graph;
78/// Backend-neutral tensor-op recognition (LOGOS AST → typed specs), shared by every codegen backend.
79pub mod tensor_recognize;
80
81// Our own sm_86 SASS assembler foundation (read/decode/patch machine code — the MaxAs lever)
82#[cfg(feature = "codegen")]
83pub mod codegen_sass;
84
85// LOGOS → analog (float dataflow) codegen tier — fail-closed refusal gate + artifact.
86#[cfg(feature = "codegen")]
87pub mod codegen_ana;
88
89// LOGOS → DRAM (ComputeDRAM bulk bitwise + RowClone) compute-in-memory co-processor tier —
90// op-subset descriptor + fail-closed refusal gate, reusing the codegen_sva::dram primitives.
91#[cfg(feature = "codegen")]
92pub mod codegen_dram;
93
94// SVA/PSL code generation for hardware verification
95pub mod codegen_sva;
96
97// The mixed-signal XPU composition: the digital wprog engine + the analog plane, with
98// certificate-gated region dispatch and digital fallback always compiled.
99#[cfg(feature = "codegen")]
100pub mod codegen_mx;
101
102// The accelerator backends' shared host/region framework: region discovery, the device lanes at their real
103// widths (a multi-word integer core and an exact binary64 softfloat), and the executable device models.
104#[cfg(feature = "codegen")]
105pub mod accel;
106
107// Native crypto acceleration for the interpreted tiers (byte-identical to the
108// pure-LOGOS reference in assets/std/crypto.lg).
109pub mod crypto_accel;
110
111// Compilation pipeline
112pub mod compile;
113pub use compile::{
114 classify_source, compile_program_full, compile_program_full_deterministic,
115 compile_program_full_with_proven, compile_to_rust, compile_to_rust_deterministic,
116 compile_to_rust_with_proven, first_parallel_block_independent, run_strict_tw,
117 run_strict_tw_with_args, run_strict_vm, run_strict_vm_with_args, send_check_source,
118 CompileOutput, CrateDependency, EngineId, EngineOutcome,
119};
120
121// Diagnostics
122pub mod diagnostic;
123
124// Source mapping
125pub mod sourcemap;
126
127// Extraction (proof term extraction)
128pub mod extraction;
129
130// Optimization passes
131pub mod optimize;
132
133// Interpreter
134pub mod interpreter;
135
136// Tail-call recognition shared by all three execution tiers (tree-walker, VM,
137// AOT) so "a self-tail-call runs in constant stack" is one definition, not three.
138pub(crate) mod tail_call;
139
140// An exhaustive rebuilding traversal of the imperative AST: every statement and expression variant
141// is named, so a rewriting pass built on it cannot silently skip one.
142pub(crate) use logicaffeine_language::ast_map;
143
144// Monomorphization for the tiers with no generics of their own: one concrete function per
145// (generic function, type arguments) a program uses, one registered type per applied generic.
146pub mod monomorphize;
147
148// Program bindings on the ahead-of-time tiers: the root bindings functions reach become the fields
149// of one record every such function takes as a `mutable` parameter.
150pub mod program_bindings;
151
152// Type-directed division resolution: rewrites `Divide → ExactDivide` where a `/`'s
153// result flows into a `Rational` context (the default stays floor — zero breakage).
154pub(crate) mod resolve_division;
155pub(crate) mod resolve_pop;
156pub(crate) mod resolve_program;
157pub(crate) mod supertask;
158
159// Observation elision for the compiled tiers: strips Note/Warn/Record and unwraps
160// During spans BEFORE the AOT optimizer/codegen, so observation can never perturb
161// a compiled artifact (§0.7 — locked by obs_zero_cost_codegen_lock).
162pub(crate) mod elide_observation;
163
164// Shared semantics kernel — ONE implementation of value semantics used by the
165// tree-walker, the bytecode VM, and (later) the JIT slow paths.
166pub mod semantics;
167
168// Register bytecode VM (fast portable interpreter — WASM engine + JIT substrate).
169pub mod vm;
170
171// The shared browser host for LOGOS→WASM DOM apps (CLI `emit`/`serve` + the web
172// Studio's live preview): the DOM/signal runtime, the default theme + favicon, the
173// build-error overlay, and the in-browser preview assembler.
174pub mod web_host;
175
176// The Studio bytecode debugger (step / breakpoints / time-travel). Zero production
177// cost — nothing here is on the execution path.
178pub mod debug;
179
180// UI Bridge - high-level compilation for web interface
181pub mod ui_bridge;
182
183// The `.replay` failure artifact — every failing run is a replayable execution.
184pub mod replay;
185
186// The `largo test` runner core — discovery, fresh-world execution, deterministic
187// reports. `MemVfs` (the sealed test
188// world) carries both `Vfs` trait shapes, so the runner compiles for the browser too
189// — the in-page test runner behind the guide's exercise grader.
190pub mod testrun;
191
192// One driver, several page tiers: the statements a `## Test` uses to work a page, carried out
193// on whichever tier executes the page (the tree-walker's own runtime, the lowered page on the
194// bytecode VM, a browser), and the per-statement traces that hold the tiers to one another.
195pub mod page_host;
196
197// The observation channel's emission buffer — Note/Warn/Record events flow to
198// sinks here, separate from program output.
199pub mod observe;
200
201// FrameEval — evaluate a LOGOS expression against a paused frame's bindings,
202// the one evaluator behind every debug surface (D4.2, Wave 10).
203pub mod frame_eval;
204
205// The DebugSession facade — the single DAP-vocabulary seam the `largo dap`
206// server and the Studio drawer both sit on, so they can never diverge.
207pub mod debug_session;
208
209// The replay-based interactive session behind `largo repl`.
210pub mod repl;
211pub use repl::{ReplOutcome, ReplSession};
212
213#[cfg(feature = "verification")]
214pub mod defeasible;
215
216// Verification pass (Z3-based, requires verification feature)
217#[cfg(feature = "verification")]
218pub mod verification;
219#[cfg(feature = "verification")]
220pub use verification::VerificationPass;
221
222// Re-export UI types at crate root for convenience
223pub use ui_bridge::{
224 answer_question, compile_for_proof, compile_for_ui, compile_theorem_for_ui,
225 extract_logic_module, extract_logic_rust, extract_math_module, extract_math_module_from_source,
226 extract_math_rust, extract_math_rust_from_source, grounded_grid_problem, interpret_for_ui,
227 interpret_for_ui_baseline, interpret_for_ui_baseline_sync_with_args,
228 interpret_for_ui_baseline_with_args, interpret_for_ui_sync, interpret_for_ui_sync_with_args,
229 interpret_for_ui_with_args, interpret_streaming, interpret_streaming_with_vfs,
230 interpret_streaming_with_vfs_observer, logic_compile_note, parse_math_statements,
231 partition_mixed, prove_theorem_trace, run_treewalker_concurrent_seeded, run_vm_concurrent,
232 run_vm_concurrent_seeded, run_vm_concurrent_with_config, run_vm_io_async, run_vm_net_async,
233 solve_grid, theorem_certificate, theorem_dependency_graph, theorem_proof_exprs, verify_theorem,
234 AstNode, CompileResult, GridColumn, ObserverCallback, ProofCompileResult, SolvedGrid,
235 TheoremCompileResult, TheoremTrace, TokenCategory, TokenInfo,
236};
237
238// The work-stealing M:N driver is native-only (no OS threads on wasm32).
239#[cfg(not(target_arch = "wasm32"))]
240pub use ui_bridge::run_vm_workstealing_seeded;
241#[cfg(feature = "verification")]
242pub use ui_bridge::{
243 check_theorem_defeasible, check_theorem_defeasible_consistent,
244 check_theorem_premises_consistent, check_theorem_smt,
245};
246#[cfg(feature = "codegen")]
247pub use ui_bridge::{generate_rust_code, generate_rust_code_with_proven};
248
249// Provide module aliases for internal code
250pub mod intern {
251 pub use logicaffeine_base::{Interner, Symbol, SymbolEq};
252}
253
254pub mod arena {
255 pub use logicaffeine_base::Arena;
256}
257
258pub mod arena_ctx {
259 pub use logicaffeine_language::arena_ctx::*;
260}
261
262pub mod registry {
263 pub use logicaffeine_language::registry::*;
264}
265
266pub mod style {
267 pub use logicaffeine_language::style::*;
268}