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