Skip to main content

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