wasm4pm_compat/lib.rs
1//! # wasm4pm-compat
2//!
3//! A **nightly-only, paper-complete, structure-only** Rust process-evidence
4//! standard.
5//!
6//! > **Start with compatibility. Graduate to execution.**
7//!
8//! ## Nightly requirement
9//!
10//! This crate **requires nightly Rust** unconditionally. The `rust-toolchain.toml`
11//! pins the toolchain to nightly. The following features are declared at the
12//! crate root with no cfg gate:
13//!
14//! - `generic_const_exprs` — law machinery and `WfNetConst<SOUNDNESS>`
15//! - `adt_const_params` — `ConditionCell<BITS>`, `Between01<NUM,DEN>`, and
16//! `Metric<KIND,NUM,DEN>`
17//! - `const_trait_impl` — compile-time trait dispatch in law surfaces
18//! - `min_specialization` — type-law narrowing in `nightly_foundry`
19//! - `portable_simd` — SIMD-width type-law surface in `nightly_foundry`
20//!
21//! There is no stable build target and no MSRV. Applications must conform
22//! *upward* to the type law, not the other way around.
23//!
24//! ## What this crate IS
25//!
26//! - A *structure-only* standard: the **shape** of process evidence and the
27//! **laws** of admission, refusal, and lossy projection.
28//! - A boundary layer: external formats are admitted into typed compat values,
29//! then exported back out (or graduated to `wasm4pm`) — never laundered
30//! raw-to-raw.
31//! - A place where **refusal is first-class**: every serious surface refuses
32//! with a *specific named law* (e.g. `DanglingEventObjectLink`,
33//! `MissingFinalMarking`, `UnsoundWfNet`), never a bare `InvalidInput`.
34//! - Built from **small, transparent, strongly-named types**: `PhantomData`
35//! witness/state markers and zero-cost `#[repr(transparent)]` ID wrappers.
36//!
37//! ## What this crate is NOT
38//!
39//! - **Not** a lite version of `wasm4pm`. It contains **no engines**: no
40//! discovery, no conformance checking, no replay, no alignment, no
41//! optimization, no visualization.
42//! - **Not** a data-laundering tool. Lossy projection always requires a named
43//! projection, a [`crate::loss::LossPolicy`], a [`crate::loss::LossReport`], and a refusal
44//! path.
45//!
46//! ## The one-way door
47//!
48//! The central invariant is a typed, one-way lifecycle enforced by the type system:
49//!
50//! ```text
51//! Raw ──parse──▶ Parsed ──admit──▶ Admitted ──▶ {Projected | Exportable | Receipted}
52//! │ ▲
53//! └────────────── refuse ────────────┴──▶ Refused (terminal; carries a named law)
54//! ```
55//!
56//! [Evidence<T, State, W>](crate::evidence::Evidence) is the universal carrier. `State` and `W`
57//! are zero-sized `PhantomData` tags — zero runtime cost. `Evidence<T, Raw, W>` and
58//! `Evidence<T, Admitted, W>` are **different types**. A function demanding admitted
59//! evidence cannot be called with raw evidence. The `Admitted` constructor is
60//! `pub(crate)` — the **only** public path to admitted evidence is
61//! [`crate::admission::Admit::admit`].
62//!
63//! ## Feature model
64//!
65//! The public feature surface is **exactly three**. They control *capability
66//! stages*, not *canon knowledge* — the base profile already knows every shape.
67//!
68//! | Feature | Default | Meaning |
69//! |------------|:-------:|----------------------------------------------------------------|
70//! | `formats` | yes | import/export contracts, round-trip claims, loss surfaces |
71//! | `strict` | no | opt-in boundary judgment: strict admission/refusal surfaces |
72//! | `wasm4pm` | no | graduation bridge traits toward the `wasm4pm` execution engine |
73//!
74//! There are **no per-format flags** (no `ocel`/`xes`/`bpmn`/…). Nightly is
75//! **not** a Cargo feature: the crate requires nightly unconditionally.
76//! `nightly_foundry.rs` is a staging module that is always on.
77//!
78//! ## Test surfaces
79//!
80//! Three distinct surfaces with different purposes and cadences:
81//!
82//! - **Fast loop** — `cargo test --all-features --tests`: unit and integration
83//! tests; sub-second after the initial build. Run on every change.
84//! - **ALIVE gate** — `cargo test --test ui_tests -- --ignored`: trybuild
85//! compile-fail and compile-pass fixtures that certify the type law. Explicit
86//! opt-in; ~4 min cold. A compile-fail fixture failing for the *wrong* reason
87//! is not a valid type-law receipt.
88//! - **Documentation audit** — `cargo test --doc --all-features`: verifies
89//! every public doctest compiles. Explicit opt-in; slow on nightly (each
90//! doctest touching nightly features is a separate `rustc` invocation).
91//!
92//! Doctests are **disabled** in the default test run (`doctest = false` in
93//! `Cargo.toml`) to keep the dev loop fast.
94//!
95//! ## Adoption example
96//!
97//! Build the core event-log shape via the [`crate::prelude`]:
98//!
99//! ```ignore
100//! use wasm4pm_compat::prelude::*;
101//!
102//! // Build a single event, fold it into a trace, and a trace into a log.
103//! let event = Event::new("place_order");
104//! let trace = Trace::from_events([event]);
105//! let log = EventLog::from_traces([trace]);
106//! assert_eq!(log.trace_count(), 1);
107//! ```
108//!
109//! The full `Raw → Admitted` path:
110//!
111//! ```ignore
112//! use wasm4pm_compat::admission::{Admit, Admission, Refusal};
113//! use wasm4pm_compat::evidence::Evidence;
114//! use wasm4pm_compat::state::Raw;
115//! use wasm4pm_compat::witness::Ocel20;
116//!
117//! enum LinkedOcel {}
118//!
119//! impl Admit for LinkedOcel {
120//! type Raw = bool;
121//! type Admitted = bool;
122//! type Reason = &'static str;
123//! type Witness = Ocel20;
124//! fn admit(raw: Evidence<bool, Raw, Ocel20>)
125//! -> Result<Admission<bool, Ocel20>, Refusal<&'static str, Ocel20>>
126//! {
127//! if raw.value { Ok(Admission::new(true)) }
128//! else { Err(Refusal::new("DanglingEventObjectLink")) }
129//! }
130//! }
131//!
132//! let admitted = LinkedOcel::admit(Evidence::raw(true)).unwrap().into_evidence();
133//! let exportable = admitted.into_exportable();
134//! assert_eq!(exportable.value, true);
135//! ```
136//!
137//! Examples are `ignore`d here; see the `examples/` directory for runnable
138//! walkthroughs of each capability stage.
139//!
140//! ## Graduation path
141//!
142//! When you need to *run* something — discover a model, check conformance, replay a
143//! log — you graduate. With the `wasm4pm` feature, bridge traits hand your typed
144//! compat evidence to the execution engine. The compat crate stays structure-only;
145//! the engine does the work.
146
147// ── Nightly features — unconditional (nightly toolchain required) ────────────
148#![feature(generic_const_exprs)]
149#![feature(adt_const_params)]
150#![feature(unsized_const_params)]
151#![feature(const_trait_impl)]
152#![feature(min_specialization)]
153#![feature(portable_simd)]
154#![allow(incomplete_features)]
155#![forbid(unsafe_code)]
156
157// ── Always-on: the canon of process-evidence structure ──────────────────────
158
159/// Admission and refusal: the first-class boundary verdict surface.
160pub mod admission;
161/// BPMN model shape.
162pub mod bpmn;
163/// Causal net structural shapes (Heuristics Miner output — Weijters & Ribeiro 2011).
164pub mod causal_net;
165/// Causal consistency law: CausalChain, CausalLink, CausalConsistency, CausallyOrderedEvidence.
166pub mod causality;
167/// Conformance verdict shape (structure only — no checking engine).
168pub mod conformance;
169/// Cross-log correlation law: CorrelationKey, CorrelatedLog, CorrelationSchema shapes.
170pub mod correlation;
171/// Declare constraint shape.
172pub mod declare;
173/// Directly-follows graph (DFG) shape.
174pub mod dfg;
175/// Diagnostic shapes for explaining admission and refusal.
176pub mod diagnostic;
177/// Event, trace, and event-log shapes.
178pub mod eventlog;
179/// Receipt-shaped evidence values (structure only).
180pub mod evidence;
181/// Zero-cost `#[repr(transparent)]` identifier wrappers.
182pub mod ids;
183/// Interop traits: import, export, round-trip claim plumbing.
184pub mod interop;
185/// Compile-time law kernel: `ConstParamTy` enums, bounds machinery, `ConditionCell`, `Between01`.
186pub mod law;
187/// Loss policy, loss report, and named projection law.
188pub mod loss;
189/// Multi-perspective process evidence: ControlFlow/Data/Resource/Time perspective markers.
190pub mod multiperspective;
191/// Object lifecycle law: typed phase markers and lawful phase transitions.
192pub mod object_lifecycle;
193/// Object-centric event log (OCEL) shape.
194pub mod ocel;
195/// Object-centric process query (OCPQ) shape.
196pub mod ocpq;
197/// Petri net shape.
198pub mod petri;
199/// POWL (partially ordered workflow language) shape.
200pub mod powl;
201/// POWL8 operator discriminant — compact `u8` wire-format companion to [`crate::powl::PowlNodeKind`].
202pub mod powl8_op;
203/// Prediction problem shape (structure only — no predictor).
204pub mod prediction;
205/// Core adoption surface — re-exports the most-needed shapes and laws.
206pub mod prelude;
207/// Process cube dimensional structure (van der Aalst 2013 — multi-perspective comparison).
208pub mod process_cube;
209/// Process tree shape.
210pub mod process_tree;
211/// Receipt shape: provenance-bearing evidence envelope.
212pub mod receipt;
213/// Typestate tokens: `Raw`, `Parsed`, `Admitted`, `Refused`, `Projected`, …
214pub mod state;
215/// Streaming evidence context law: online vs. offline collection markers and EventWindow.
216pub mod streaming;
217/// Temporal ordering and profile law surfaces.
218pub mod temporal;
219/// Witness markers and witness families (type-level proof carriers).
220#[macro_use]
221pub mod witness;
222/// Compiled witness marker declarations — one entry per WitnessMarker in the ontology.
223/// Generated by `ggen sync --rule witness-markers`; maintained via TTL + ggen, not by hand.
224pub mod witnesses;
225/// Typestate-based parallel workflow tracking.
226pub mod workflow;
227/// XES interchange shape.
228pub mod xes;
229
230// ── Feature-gated: capability stages ────────────────────────────────────────
231
232/// Graduation bridge traits toward the `wasm4pm` execution engine.
233#[cfg(feature = "wasm4pm")]
234pub mod engine_bridge;
235/// Import/export contracts, round-trip claims, and loss surfaces.
236#[cfg(feature = "formats")]
237pub mod formats;
238/// Opt-in boundary judgment: strict admission/refusal declaration surfaces.
239#[cfg(feature = "strict")]
240pub mod strict;
241
242// ── Test helper builders (test-only) ────────────────────────────────────────
243
244/// Test helper builders for common law-compliant constructions.
245///
246/// Available only under `#[cfg(test)]`. Provides zero-boilerplate constructors
247/// for shapes most frequently needed in unit and integration tests.
248#[cfg(test)]
249pub mod test_utils;
250
251// ── Nightly foundry — always-on staging area for paper-derived law surfaces ──
252
253/// Nightly foundry: zero-cost type-law surfaces from process-mining papers.
254///
255/// Contains `petri_law`, `powl_law`, `evidence_law`, and `token_law` —
256/// four surfaces that use `generic_const_exprs`, `adt_const_params`,
257/// `min_specialization`, and `portable_simd` respectively. This is an
258/// experimental staging module; the main type law lives in [`crate::law`], [`crate::petri`],
259/// [`crate::conformance`], [`crate::process_tree`], [`crate::powl`], [`crate::formats`], and [`crate::strict`].
260pub mod nightly_foundry;
261
262// ── Flat re-exports: most-used types available at the crate root ─────────────
263//
264// These re-exports let users write `wasm4pm_compat::EventId` instead of
265// `wasm4pm_compat::ids::EventId`. They do not replace the submodule paths.
266
267pub use crate::admission::{Admission, Admit, Refusal};
268pub use crate::dfg::{DfgMiner, DirectlyFollowsGraph};
269pub use crate::eventlog::{Event, EventLog, EventLogClassifier, Trace};
270pub use crate::evidence::Evidence;
271pub use crate::ids::{ActivityId, CaseId, EventId, ObjectId};
272pub use crate::loss::{LossPolicy, ProjectionName};
273pub use crate::ocel::OcelLog;
274pub use crate::petri::{PetriNet, PetriNetBuilder, WfNet, WfNetConst};
275pub use crate::powl8_op::{Powl8Op, Powl8OpError};
276pub use crate::receipt::Blake3Hash;
277pub use crate::receipt::ProvenanceChain;
278pub use crate::receipt::ReceiptEnvelope;
279pub use crate::state::{Admitted, Exportable, Parsed, Projected, Raw, Receipted, Refused};
280pub use crate::streaming::{OfflineEvidence, OnlineEvidence};
281pub use crate::workflow::{
282 BranchToken, Canceled, Completed, CompletedWorkflow, JoinPoint, ParallelWorkflow, Pending,
283 Running,
284};
285pub use crate::xes::XesLog;