Skip to main content

vyre_self_substrate/
lib.rs

1#![allow(
2    clippy::doc_lazy_continuation,
3    clippy::double_must_use,
4    clippy::manual_div_ceil,
5    clippy::needless_range_loop,
6    clippy::collapsible_if,
7    clippy::match_like_matches_macro,
8    clippy::redundant_closure
9)]
10//! Self-substrate  -  vyre using its own primitives to compile/dispatch vyre.
11//!
12//! These modules realize the **recursion thesis** (#30): every Tier-2.5
13//! primitive shipped in `vyre-primitives` also has a vyre-self consumer
14//! here that uses the same Program at compile / dispatch time.
15//!
16//! # Layering (audit cleanup A10, 2026-04-30)
17//!
18//! Extracted from `vyre-driver/src/self_substrate/` into a dedicated
19//! crate so the substrate-self-uses live at a layer that depends only
20//! on `vyre-foundation` + `vyre-primitives`  -  eliminating the layering
21//! muddle where backend-specific dispatch code and substrate self-uses
22//! shared one home in `vyre-driver`.
23//!
24//! ```text
25//!   vyre-foundation
26//!         ↑
27//!   vyre-primitives
28//!         ↑
29//!   vyre-self-substrate          ← THIS CRATE (no driver deps)
30//!         ↑
31//!   vyre-driver / vyre-runtime / vyre-libs / vyre-driver-{cuda,wgpu}
32//! ```
33//!
34//! No cycles. Every consumer above this crate reaches the substrate
35//! via `vyre_self_substrate::*` directly.
36//!
37//! `vyre-foundation` cannot consume `self_substrate` from here because
38//! `self_substrate` depends on `vyre-primitives` which depends on
39//! `vyre-foundation`  -  that's the cycle that justifies the dedicated
40//! crate. Foundation has its own smaller substrate at
41//! `vyre_foundation::pass_substrate` (with the math kernels it needs
42//! inlined locally  -  same pattern Linux uses for arch-local libs vs
43//! `lib/`).
44//!
45//! # Module list
46//!
47//! - `dataflow_fixpoint` (#26)  -  Region-graph dataflow fixpoint via
48//!   `vyre-primitives::math::semiring_gemm` over the Region adjacency.
49//! - `cost_model` (#28)  -  probabilistic dispatch cost model via
50//!   `vyre-primitives::graph::sum_product_circuit` + conformal
51//!   intervals from `vyre-primitives::math::conformal`.
52//! - `vsa_fingerprint` (#29)  -  VSA op-cache key via
53//!   `vyre-primitives::hash::hypervector`.
54//! - `spectral_schedule` (#23)  -  spectral clustering of dispatch
55//!   graph via `vyre-primitives::graph::chebyshev_filter` +
56//!   `vyre-primitives::math::spectral_shape`.
57//! - `differentiable_autotune` (#27)  -  differentiable autotuner via
58//!   `vyre-primitives::math::differentiable`.
59//! - `polyhedral_fusion` (#19)  -  polyhedral / affine fusion via
60//!   `vyre-primitives::math::semiring_gemm` on the affine-dependency
61//!   adjacency.
62//! - `megakernel_schedule` (#22)  -  megakernel ILP relaxation via
63//!   `vyre-primitives::opt::homotopy` continuation.
64//! - `tensor_train_chain_fusion` (#6)  -  chain-shaped Region fusion via
65//!   `vyre-primitives::math::tensor_train::tt_contract_step` contraction.
66//! - `do_calculus_change_impact` (#36)  -  rule-graph change-impact analysis
67//!   via `vyre-primitives::graph::do_calculus` graph surgery.
68//! - `scallop_provenance` (#39)  -  GPU-resident rule provenance closure via
69//!   `vyre-primitives::math::scallop_join` Datalog fixpoint.
70//! - `matroid_megakernel_scheduler` (#46)  -  discrete fusion-grouping via
71//!   matroid intersection augmenting paths. Complements
72//!   `megakernel_schedule` (#22 homotopy continuous solver) with the
73//!   exact combinatorial selection.
74//! - `mori_zwanzig_region_coarsen` (#58)  -  Region-tree coarse-graining
75//!   via Mori-Zwanzig projection. Reduces O(N²) all-pairs analyses to
76//!   O(K²) at workspace scale with quantified projection error.
77//! - `fmm_polyhedral_compress` (#51)  -  FMM hierarchical compression of
78//!   #19 polyhedral fusion's all-pairs affinity. Drops cost from O(N²)
79//!   to O(N log N) at workspace scale.
80//! - `submodular_cache_eviction` (#45)  -  pipeline-cache eviction via
81//!   submodular maximization. Replaces LRU's heuristic with the
82//!   provably-(1-1/e) greedy approximation.
83//! - `qsvt_matrix_function_fusion` (#34)  -  transport-based fusion
84//!   analysis via QSVT-applied matrix functions. Computes Wasserstein
85//!   distances on dispatch graphs in O(K·N²) instead of O(N³).
86//! - `persistent_homology_loop_signature` (#15)  -  Region-tree loop
87//!   topology via Vietoris-Rips filtration. Fusion-vs-fission decision
88//!   informed by H₁ persistent features.
89//! - `adjustment_set_pass_dependency` (#37)  -  optimizer pass-ordering
90//!   validity via causal back-door analysis on the rewrite-precondition
91//!   graph.
92//! - `functorial_pass_composition` (#52)  -  IR transform passes as
93//!   categorical functors. Compositionality, equational reasoning, free
94//!   adjoint pairs  -  pass framework moves from hand-managed DAG to a
95//!   typed functor-category.
96//! - `string_diagram_ir_rewrite` (#53)  -  Vyre IR Region tree IS a
97//!   string diagram in Cat(GPU buffers, Programs). Optimizer rewrites
98//!   become string-diagram rewrites; coherence theorems give free
99//!   correctness proofs.
100//! - `planar_rewrite_pass_scheduler` (#11)  -  schedule batch IR rewrites
101//!   onto disjoint sub-trees via planar non-overlapping selection.
102//!   Drops dispatch count from O(N) sequential to O(log N) batched.
103
104#[cfg(feature = "analysis")]
105pub mod analysis;
106#[cfg(feature = "data")]
107pub mod data;
108#[cfg(feature = "graph-solvers")]
109pub mod graph;
110#[cfg(feature = "optimizer")]
111pub mod hardware;
112#[cfg(feature = "logic")]
113pub mod logic;
114#[cfg(feature = "math-solvers")]
115pub mod math;
116#[cfg(feature = "scheduling")]
117pub mod scheduling;
118#[cfg(feature = "telemetry")]
119pub mod telemetry;
120
121#[cfg(all(test, feature = "data"))]
122mod test_support;
123
124#[cfg(feature = "optimizer")]
125/// Self-hosted optimizer keystone  -  the encoder + GPU passes that run
126/// the compiler against its own substrate. Exposed at the lib root so
127/// external consumers (driver-cuda parity tests, conform runners) can
128/// reach `OptimizerDispatcher`, the per-pass `*_via_encoded` entry
129/// points, and optimizer contract metadata without descending into
130/// private module paths.
131pub mod optimizer;
132
133#[cfg(feature = "analysis")]
134pub use analysis::{
135    cost_model, dataflow_fixpoint, decision_telemetry, diagnostic_aggregation,
136    effect_signature_check, incremental_invalidation, knowledge_compile_pass_precondition,
137    linear_type_check, persistent_fixpoint_program, shape_smt_check,
138};
139
140#[cfg(feature = "logic")]
141pub use logic::{
142    adjustment_set_pass_dependency, categorical_check, dnnf_compile, do_calculus_change_impact,
143    functorial_pass_composition, string_diagram_ir_rewrite, zx_rewrite,
144};
145
146#[cfg(feature = "data")]
147pub use data::{
148    bitset_compression, bitset_summary, matroid_exact_megakernel, matroid_megakernel_scheduler,
149    parsing_dispatch_pipeline, scallop_provenance, scallop_provenance_wide, vsa_fingerprint,
150};
151
152#[cfg(feature = "telemetry")]
153pub use telemetry::observability;
154
155#[cfg(feature = "scheduling")]
156pub use scheduling::{
157    branch_compaction, frontier_partitioning, frontier_typed_ir, megakernel_schedule,
158    multi_corpus_batching, planar_rewrite_pass_scheduler, polyhedral_fusion, spectral_schedule,
159    submodular_cache_eviction,
160};
161
162#[cfg(feature = "graph-solvers")]
163pub use graph::{
164    adaptive_traverse, alias_registry, csr_bidirectional, csr_forward_or_changed,
165    csr_frontier_queue_batch_memory, csr_frontier_queue_batch_resident,
166    csr_frontier_queue_resident, dominator_frontier, exploded, level_wave_pass, motif,
167    path_reconstruct, persistent_bfs, structural_kernel_pipeline, toposort,
168    traversal_dispatch_pipeline, union_find_emit, vast_tree_walk,
169};
170
171#[cfg(feature = "math-solvers")]
172pub use math::{
173    amg_pass_solver, bellman_tn_order, differentiable_autotune, fmm_polyhedral_compress,
174    kfac_autotune_step, mori_zwanzig_region_coarsen, multigrid_matroid_solver,
175    natural_gradient_autotuner, persistent_homology_loop_signature, qsvt_matrix_function_fusion,
176    sheaf_heterophilic_dispatch, sheaf_spectral_clustering, sinkhorn_dispatch_clustering,
177    sinkhorn_full_clustering, tensor_network_fusion_order, tensor_train_chain_fusion,
178    tensor_train_compression,
179};
180
181#[cfg(feature = "optimizer")]
182pub(crate) use hardware::dispatch_buffers;
183#[cfg(feature = "optimizer")]
184pub use hardware::{
185    device_resident_token_fact_graph, gpu_probe_contract, memory_ownership_contract,
186};