axon_frontend/lib.rs
1//! AXON compiler frontend.
2//!
3//! Pure frontend of the AXON language: lexer, parser, AST, epistemic
4//! type primitives, type checker, IR generator, and the top-level
5//! compile-time checker that glues them together.
6//!
7//! # Design contract
8//!
9//! This crate has **zero runtime dependencies**. The only allowed
10//! external dep is `serde` (plus its proc-macro chain). Any addition
11//! of a runtime dep (tokio, axum, sqlx, reqwest, aws-*, jsonwebtoken,
12//! …) is rejected at CI time.
13//!
14//! # Consumers
15//!
16//! - `axon` crate (the AXON runtime in `../axon-rs/`) re-exports these
17//! modules so existing callers keep working.
18//! - `axon-lsp` (Language Server, separate repo) consumes the frontend
19//! directly without dragging runtime deps.
20//!
21//! # Byte-identical parity
22//!
23//! Outputs must match the Python reference implementation
24//! (`../axon/`) on the golden-file test corpus. Divergences are
25//! release blockers.
26
27pub mod ast;
28pub mod checker;
29pub mod cron;
30pub mod epistemic;
31pub mod ir_generator;
32pub mod ir_nodes;
33pub mod lexer;
34pub mod parser;
35pub mod smart_suggest;
36pub mod store_column_proof;
37pub mod store_introspect;
38/// §Fase 109.a — the symbolic differentiator + simplifier over the
39/// closed `Expr` (the proof-carrying derivative).
40pub mod expr_diff;
41pub mod store_schema;
42pub mod store_schema_manifest;
43pub mod tokens;
44pub mod type_checker;
45
46// §Fase 11.a — compile-time catalogs used by the type checker.
47// `refinement` declares the closed Trust<T> catalog; `stream_effect`
48// declares the closed backpressure policy catalog. Both are pure
49// enum-like definitions with `std::fmt` only — no runtime deps.
50// The matching runtime implementations (`trust_verifiers`,
51// `stream_runtime`) live in the `axon` runtime crate.
52pub mod refinement;
53/// §Fase 119.b — the `mandate` stability judgment (`D < |Kp+Ki+Kd| < 1/L`),
54/// shared verbatim with the runtime controller in axon-rs.
55pub mod stability;
56/// §Fase 119.e — the `fabric` substrate judgment (provider ↔ region ↔
57/// jurisdiction), shared verbatim with the runtime.
58pub mod substrate;
59pub mod stream_effect;
60
61// §Fase 11.c — closed catalogue of regulatory authorisations
62// (GDPR/CCPA/SOX/HIPAA/GLBA/PCI-DSS) used by the type checker to
63// enforce `@legal_basis` annotations. Pure catalog, no runtime deps.
64pub mod legal_basis;
65
66// §Fase 11.e — OTS (Ontological Tool Synthesis) compile-time slug
67// catalogs. Runtime pipeline execution lives in `axon::ots` and
68// re-exports these for backward compatibility.
69pub mod ots_catalog;
70
71// §Fase 13.g — LSP-facing analysis primitives for typed channels.
72// Pure AST helpers consumed by `axon-lsp` (sibling repo) to implement
73// hover, completion, go-to-definition and find-references. Zero
74// runtime deps — stays inside the Fase 12.c contract.
75pub mod channel_analysis;
76
77// §Fase 41.a — session types: the pure algebra of typed bidirectional
78// dialogue (WebSocket as a cognitive primitive). The session-type
79// grammar + the duality involution `(·)⊥` + regular-coinductive
80// equality for `μ`-types + the connection law (`peer ≡ self⊥`).
81// Grounded in Caires–Pfenning (session types = intuitionistic linear
82// propositions). Pure — no runtime deps; the `socket` surface (41.b),
83// credit-refined backpressure (41.c) and the typed-WS runtime (41.d,
84// in the `axon` crate) build on this. See
85// docs/paper_websocket_cognitive_primitive.md.
86pub mod session;
87// §Fase 41.h — multiparty session types (Honda–Yoshida–Carbone). A
88// `GlobalType` declares an n-party protocol; projection `G⌐r` extracts
89// each role's binary `SessionType` (the §41.a algebra). The safe-
90// realizability gate is `project_all`: a `Result::Ok` is the structural
91// certificate that independent per-role runtimes faithfully realise `G`.
92pub mod multiparty;
93
94// §Fase 6.a — the closed registry of every primitive AXON exposes as
95// a named language construct. Single source of truth for the ℰMCP
96// coverage gate + scaffold CLI + future LSP completions / docs-site
97// generators. Pure const data, no runtime deps. See the module-level
98// docs for the discipline (registry + corpus = atomic addition).
99/// §Fase 111 — the anti-drift gate. The public README is parsed at test time and
100/// every primitive it advertises must carry a human-attested statement of what
101/// its runtime actually does. A presence-only gate would not have caught a single
102/// §111 defect (`warden` and `quant` had a badge, a registry entry, a parser
103/// production AND a dispatch arm — and were no-ops), so this one forces the
104/// question no linter can decide.
105pub mod advertised;
106pub mod primitive_registry;
107
108// §Fase 115 — the Epistemic Module System, rebuilt natively in Rust
109// (docs/papers/paper_ems_axon.md). The retired Python EMS (v0.23.0,
110// gone since Fase 39) advertised separate compilation the Rust toolchain
111// never had: `import` parsed, lowered, and resolved NOTHING. §115 makes
112// it real — and goes one phase further: the LINKER exists, so a
113// multi-module program executes. Pure modules, zero new deps (SHA-256 is
114// the §38 hand-rolled `sha256_hex`); in-memory-first so the LSP and the
115// enterprise bundle loader resolve without a filesystem.
116pub mod compilation_cache;
117pub mod ems;
118pub mod epistemic_compat;
119pub mod module_interface;
120pub mod module_linker;
121pub mod module_resolver;
122pub use primitive_registry::{
123 by_category, coverage_summary, find as find_primitive, with_status, CoverageSummary,
124 DocStatus, PrimitiveInfo, PRIMITIVE_REGISTRY,
125};
126
127// §Fase 80.f — the blessed upstream preset catalog (versioned, forkable,
128// ordinary `.axon` source per D80.5) + the `from Preset@vN` expansion the
129// parser runs before type-check. Pure const data + a pure AST pass.
130pub mod upstream_presets;
131
132// §Fase 80.g — `voice` macro-expansion to source text (the `axon desugar`
133// payload). Pure AST pass run by the parser before preset expansion.
134pub mod voice_desugar;
135
136// §Fase 84 — Remote Hands: the pure, shared argv-template classifier + risk
137// catalog used by BOTH the type-checker and the runtime dispatcher (D84.1).
138pub mod technician;
139
140/// §Fase 92.a — convert a duration literal (the lexer's `Duration` token
141/// shape: digits + one of `s`/`ms`/`m`/`h`/`d`) into whole seconds. Pure,
142/// total over the token grammar; `None` for anything else (a malformed
143/// literal is `axon-T894` at the type-check layer). `ms` floors to whole
144/// seconds — a sub-second credential TTL is `0` and rejected by the same
145/// law. Shared by the IR lowering and the type checker so the two can
146/// never disagree about what a `ttl:` means.
147pub fn duration_literal_to_secs(literal: &str) -> Option<u64> {
148 let t = literal.trim();
149 let split = t.find(|c: char| !c.is_ascii_digit())?;
150 let (digits, suffix) = t.split_at(split);
151 let n: u64 = digits.parse().ok()?;
152 match suffix {
153 "s" => Some(n),
154 "ms" => Some(n / 1000),
155 "m" => n.checked_mul(60),
156 "h" => n.checked_mul(3600),
157 "d" => n.checked_mul(86_400),
158 _ => None,
159 }
160}