sim/lib.rs
1//! # sim-nest -- the SIM umbrella crate (imported as `sim`)
2//!
3//! Published on crates.io as **`sim-nest`** (the bare name `sim` is taken), while
4//! its library import identifier is `sim`. Depend on `sim-nest` and write
5//! `use sim::...`; `use sim_nest::...` does not resolve. The `#[sim::sim_lib]`
6//! and `#[sim::sim_fn]` macros use the same stable import identifier.
7//!
8//! SIM is an expandable Rust runtime built around a small protocol kernel and
9//! loadable libraries. Its data flow is:
10//!
11//! ```text
12//! tokens -> checked forms -> objects -> checked calls -> objects -> encoded forms
13//! ```
14//!
15//! Lisp is one codec, not the system identity. Syntax, codecs, classes,
16//! functions, number domains, checkers, evaluators, wasm adapters, loaders, and
17//! the standard language surface are libraries loaded above the kernel.
18//!
19//! ## Umbrella role
20//!
21//! This crate aggregates the constellation's implementation crates through an
22//! optional-dependency feature map and re-exports stable aliases including
23//! `sim::kernel`, `sim::shape`, `sim::codec`, and the `codec_*`, `lib_*`,
24//! `table_*`, and `list_*` families. The opt-in `expr-tree` feature exposes the
25//! canonical expression-tree crates without adding facade policy. Authoring
26//! helpers (`functions`, `classes`, `macros`, `shapes`, and `runtime`) are
27//! available with `shape`. The canonical feature map is in `Cargo.toml`.
28//!
29//! ## Kernel boundary
30//!
31//! The kernel owns identity and transport types, coordination types such as
32//! `Cx`, `Registry`, `Lib`, `Linker`, and `ExportRecord`, capabilities, stores,
33//! ledgers, control policy, object/callable/class/shape/factory/evaluation
34//! contracts, match results, and ABI transport shapes. It does not own concrete
35//! language or codec parsing, number domains, arithmetic, user-facing help and
36//! browse behavior, guest behavior above ABI transport, or product policy.
37//! Extensible metadata remains open `ExportRecord`-style data; concrete
38//! behavior is installed through `Lib`, `Linker`, and `ExportRecord`.
39//!
40//! ## Load-bearing concepts
41//!
42//! - **`Shape`** is the shared engine for parsing, checking, binding, dispatch,
43//! macro syntax, codec grammar, lambda locals, and overload selection.
44//! - **Codecs are first-class runtime objects**, split into decoders and
45//! position-aware encoders. General codecs round-trip every shared `Expr`;
46//! domain codecs fail closed outside the domain they accept.
47//! - **`realize` and `EvalFabric`** provide location-transparent distributed
48//! evaluation. Evaluation strategy is an injectable `EvalPolicy`.
49//! - **Capabilities make power explicit.** Read-construct is the narrow path
50//! behind Lisp `#(...)`; it is distinct from broad read-eval, which remains
51//! disabled by default for untrusted input.
52//! - **Number domains, lists, and tables are pluggable libraries.**
53//! - **Wasm is a first-class runtime target and portable plugin ABI.**
54//!
55//! ## Embedding
56//!
57//! `runtime::install_core_runtime` is the embedding entry point when `shape` is
58//! enabled. Build a `Cx`, install the core runtime, then install codecs and
59//! behavior libraries through their helpers or through `Lib` and `Linker`:
60//!
61//! ```ignore
62//! use std::sync::Arc;
63//! use sim::kernel::{Cx, DefaultFactory, EagerPolicy};
64//! use sim::runtime::install_core_runtime;
65//!
66//! let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
67//! install_core_runtime(&mut cx);
68//! ```
69//!
70//! The installer loads the registry-backed core and enabled default number
71//! domains; applications then add only the libraries their distribution needs.
72#![deny(unsafe_code)]
73#![deny(missing_docs)]
74#![allow(deprecated)]
75extern crate self as sim;
76
77#[rustfmt::skip]
78#[cfg(any(feature = "femm-assembly", feature = "femm-codec", feature = "femm-core", feature = "femm-fixtures", feature = "femm-field", feature = "femm-flow", feature = "femm-function", feature = "femm-geometry", feature = "femm-material", feature = "femm-mesh", feature = "femm-ode", feature = "femm-physics", feature = "femm-post", feature = "femm-prelude", feature = "femm-sensitiv", feature = "femm-solve", feature = "femm-space", feature = "femm-tape"))]
79pub use femm_exports::*;
80#[rustfmt::skip] #[allow(unused_imports)] pub use numbers_exports::*;
81#[rustfmt::skip] #[allow(unused_imports)] pub use standard_exports::*;
82#[rustfmt::skip]
83#[cfg(any(feature = "server-net-http", feature = "agent-net", feature = "glasses", feature = "openai-server-http", feature = "standard", feature = "rank-codec-fallback", feature = "rank-expr", feature = "rank-learn", feature = "rank-music", feature = "rank-scatter", feature = "stream-bridge", feature = "stream-host"))]
84const _: bool = true;
85#[allow(unused_imports)]
86pub use roadmap11_exports::*;
87#[rustfmt::skip]
88#[cfg(any(feature = "compute-auto", feature = "compute-cli", feature = "compute-cuda", feature = "compute-femm", feature = "compute-model", feature = "compute-rocm", feature = "compute-wgpu"))]
89pub use compute_exports::*;
90#[rustfmt::skip]
91#[cfg(any(feature = "interference-core", feature = "interference-solve", feature = "interference-runtime", feature = "interference-compute", feature = "view-interference"))]
92pub use interference_exports::*;
93#[cfg(feature = "expr-tree")]
94pub use expr_tree_exports::*;
95#[cfg(feature = "agent")]
96pub use sim_lib_agent::{self as lib_agent, install_agent_lib};
97/// Native class authoring helpers: a `Class` implementation plus the lib
98/// wrapper that registers a host-defined class, its constructor, and members.
99#[cfg(all(feature = "core", feature = "shape"))]
100pub mod classes;
101/// Stable SDK surface for capturing behavior before a refactor and comparing it afterward.
102///
103/// Enable the `standard-core` feature, declare a bounded [`ScenarioSpec`], and
104/// record only canonical observations. Publish captures when a content-addressed
105/// evidence identity is required; use [`compare_characterization_captures`] for
106/// a strict comparison whose differences retain stable field paths and both
107/// canonical values.
108#[cfg(feature = "standard-core")]
109pub mod characterization {
110 pub use sim_lib_standard_core::{
111 BoundedLane, CanonicalFailure, CanonicalObservation, CanonicalOutcome, CaptureComparison,
112 CaptureComparisonProjection, CaptureDifference, CharacterizationCapture, FailureLocation,
113 ScenarioInput, ScenarioLimits, ScenarioObservationLane, ScenarioSpec,
114 characterization_capture_kind, characterization_capture_predicate,
115 compare_characterization_captures, publish_characterization_capture,
116 };
117}
118#[rustfmt::skip]
119#[cfg(all(test, feature = "shape", feature = "codec-lisp", feature = "codec-json", feature = "codec-binary", feature = "codec-binary-base64", feature = "codec-algol", feature = "codec-bridge", feature = "bridge"))]
120mod codec_matrix_tests;
121/// Stable hashing of lib manifests, shapes, and codecs for compatibility
122/// checks across versions of the constellation.
123#[cfg(feature = "core")]
124pub mod compat;
125mod compute_exports;
126#[cfg(feature = "expr-tree")]
127mod expr_tree_exports;
128mod femm_exports;
129/// Shared raised-exception contract for guest runtimes.
130///
131/// A guest obtains a class from its declared class descriptor, constructs
132/// [`Raised`], selects handlers through [`match_raised_class`], and stores
133/// recursive guest relations as stable edges in [`ManagedException`].
134// conformance: the facade exports the canonical raised envelope, matcher, and
135// managed relation adapter without defining a second exception carrier.
136#[cfg(feature = "control")]
137pub mod exceptions {
138 pub use sim_lib_control::{
139 BoundedSubclassOutcome, ClassMatchBudget, ClassMatchEvidence, ClassMatchOutcome,
140 ExceptionGraphBudget, ExceptionGraphEdge, ExceptionGraphView, ManagedException, Raised,
141 RaisedBrowseBudget, RaisedBrowseProjection, RaisedShape, match_raised_class,
142 };
143
144 #[cfg(test)]
145 mod tests {
146 #[allow(unused_imports)]
147 use super::match_raised_class;
148 use super::{ManagedException, Raised};
149
150 #[test]
151 fn exports_envelope_matcher_and_managed_adapter() {
152 let _ = std::any::type_name::<Raised>();
153 let _ = std::any::type_name::<ManagedException<(), ()>>();
154 }
155 }
156}
157/// Function authoring helpers built on the shared `Shape` engine: overload
158/// cases, native function objects, and member-table construction.
159#[cfg(all(feature = "core", feature = "shape"))]
160pub mod functions;
161/// Managed-object collector selection for standard and minimal/test distributions.
162#[cfg(feature = "standard-mutation")]
163pub mod gc;
164mod interference_exports;
165/// Lib loaders for the supported source formats (host, Lisp source, binary
166/// pack, native dynamic library, and wasm) plus the standard loader registry.
167#[cfg(feature = "core")]
168pub mod loaders;
169/// Macro authoring and expansion: the `LispMacro` contract, macro objects, the
170/// registry-backed expander, and shape constructors for macro syntax.
171#[cfg(all(feature = "core", feature = "shape"))]
172pub mod macros;
173mod music_algorithm_exports;
174/// End-to-end music rendering stack that lowers a score to MIDI and renders it
175/// to PCM audio through the sound libs.
176#[cfg(feature = "sound-music")]
177pub mod music_stack;
178mod numbers_exports;
179#[allow(unused_imports)]
180pub use music_algorithm_exports::*;
181mod roadmap11_exports;
182/// Core runtime installer and the embedding entry point that wires classes,
183/// shapes, functions, and the default number domains into a `Cx`.
184#[cfg(all(feature = "core", feature = "shape"))]
185pub mod runtime;
186/// Canonical host-built source admission contracts.
187///
188/// This module presents the shared runtime owner directly. Build one
189/// [`source_authority::SourceAuthority`] in trusted host code, then pass it to
190/// [`source_authority::ReadEvalRequest::new`] or a
191/// [`source_authority::DynamicSourcePolicy`] evaluation method.
192/// Guest-language crates own syntax and semantics, not authority envelopes.
193#[cfg(feature = "core")]
194pub mod source_authority {
195 pub use sim_lib_core::{
196 DynamicSourcePolicy, ReadEvalAdmission, ReadEvalBroker, ReadEvalDecision, ReadEvalOutcome,
197 ReadEvalRequest, ReadEvalSource, RequestOrigin, SourceAuthority,
198 };
199
200 #[cfg(test)]
201 mod tests {
202 use super::{DynamicSourcePolicy, ReadEvalRequest, SourceAuthority};
203
204 #[test]
205 fn exposes_canonical_request_builders_without_a_facade_envelope() {
206 let _ = std::any::type_name::<SourceAuthority>();
207 let _ = std::any::type_name::<ReadEvalRequest>();
208 let _ = std::any::type_name::<DynamicSourcePolicy>();
209 }
210 }
211}
212#[cfg(feature = "serial-music")]
213pub mod serial_music;
214/// Shape authoring helpers: documented and value-backed shape wrappers plus
215/// shape registration and checking utilities.
216#[cfg(all(feature = "core", feature = "shape"))]
217pub mod shapes;
218mod standard_exports;
219#[cfg(feature = "proc-macros")]
220pub use sim_macros::*;
221// The macros' native_export output emits `::sim::codec_binary::{decode_frame,
222// encode_frame}`, so the feature that enables the macros must also expose that
223// module. `proc-macros` pulls `codec-binary`; this contract asserts it, so an
224// edit that drops it fails to compile instead of shipping macros that cannot expand.
225#[cfg(all(feature = "proc-macros", not(feature = "codec-binary")))]
226compile_error!("feature `proc-macros` requires `codec-binary` (macros emit `::sim::codec_binary`)");
227#[cfg(feature = "wasm")]
228pub use sim_wasm_abi as wasm_abi;
229#[cfg(test)]
230mod feature_contract_tests;
231#[cfg(all(test, feature = "music-stack"))]
232mod music_stack_tests;
233#[cfg(all(test, feature = "skill"))]
234mod skill_tests;