clm-kernel 0.0.24

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
// @generated by tools/types/sync_fiber_descriptor.py from types/lattice/fiber_descriptor.json
// DO NOT EDIT MANUALLY — run `python3 tools/types/sync_fiber_descriptor.py --write`
// Normative Invariant: INV-625 (one lifecycle descriptor, three projections)
//! Fiber lifecycle tables for the `legacy_rust` profile, projected from types/lattice/fiber_descriptor.json.

pub const DESCRIPTOR_VERSION: &str = "fiber-descriptor-v1";
pub const PROFILE: &str = "legacy_rust";

/// The lifecycle states of the `legacy_rust` profile.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FiberState {
    /// InitialBottom.
    Pending,
    /// Intermediate.
    Loading,
    /// Intermediate.
    Active,
    /// Intermediate.
    Paused,
    /// Intermediate.
    Suspended,
    /// Intermediate.
    Unloading,
    /// TerminalTop.
    Disposed,
    /// Exception; the payload is the failure reason.
    Failed(String),
}

impl FiberState {
    /// The descriptor name of this state.
    pub const fn name(&self) -> &'static str {
        match self {
            Self::Pending => "pending",
            Self::Loading => "loading",
            Self::Active => "active",
            Self::Paused => "paused",
            Self::Suspended => "suspended",
            Self::Unloading => "unloading",
            Self::Disposed => "disposed",
            Self::Failed(_) => "error",
        }
    }

    /// The name this profile publishes for this state.
    pub const fn published_name(&self) -> &'static str {
        match self {
            Self::Pending => "pending",
            Self::Loading => "loading",
            Self::Active => "active",
            Self::Paused => "paused",
            Self::Suspended => "suspended",
            Self::Unloading => "unloading",
            Self::Disposed => "disposed",
            Self::Failed(_) => "failed",
        }
    }
}

/// The state a new fiber starts in; with no required coeffect it starts in the alias state.
pub fn initial_state(coeffects_empty: bool) -> FiberState {
    if coeffects_empty { FiberState::Active } else { FiberState::Pending }
}

/// Whether the profile's table carries the ordinary transition `from -> to`.
#[inline]
pub const fn valid_transition(from: &FiberState, to: &FiberState) -> bool {
    matches!(
        (from, to),
        (FiberState::Pending, FiberState::Loading) |
        (FiberState::Pending, FiberState::Active) |
        (FiberState::Loading, FiberState::Active) |
        (FiberState::Loading, FiberState::Failed(_)) |
        (FiberState::Active, FiberState::Active) |
        (FiberState::Active, FiberState::Loading) |
        (FiberState::Active, FiberState::Paused) |
        (FiberState::Active, FiberState::Suspended) |
        (FiberState::Active, FiberState::Unloading) |
        (FiberState::Active, FiberState::Failed(_)) |
        (FiberState::Paused, FiberState::Active) |
        (FiberState::Suspended, FiberState::Active) |
        (FiberState::Suspended, FiberState::Unloading) |
        (FiberState::Unloading, FiberState::Disposed) |
        (FiberState::Unloading, FiberState::Failed(_))
    )
}

/// The PlaceRole of a state.
pub const fn state_role(state: &FiberState) -> &'static str {
    match state {
        FiberState::Pending => "InitialBottom",
        FiberState::Loading => "Intermediate",
        FiberState::Active => "Intermediate",
        FiberState::Paused => "Intermediate",
        FiberState::Suspended => "Intermediate",
        FiberState::Unloading => "Intermediate",
        FiberState::Disposed => "TerminalTop",
        FiberState::Failed(_) => "Exception",
    }
}

/// The receipt spelling of a traced state.
pub const fn trace_name(state: &FiberState) -> Option<&'static str> {
    match state {
        FiberState::Pending => Some("PENDING"),
        FiberState::Loading => Some("LOADING"),
        FiberState::Active => Some("ACTIVE"),
        FiberState::Suspended => Some("SUSPENDED"),
        FiberState::Unloading => Some("UNLOADING"),
        FiberState::Disposed => Some("DISPOSED"),
        _ => None,
    }
}

/// A named escape edge that `method` fires outside the transition table.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FiberBypass {
    pub name: &'static str,
    pub method: &'static str,
    pub sources: &'static [&'static str],
    pub targets: &'static [&'static str],
    pub drains: bool,
}

/// Every state of the profile, in descriptor order.
pub const FIBER_STATES: &[&str] = &[
    "pending",
    "loading",
    "active",
    "paused",
    "suspended",
    "unloading",
    "disposed",
    "error",
];

/// The state a new fiber starts in.
pub const INITIAL_STATE: &str = "pending";

/// States with no way out.
pub const TERMINAL_STATES: &[&str] = &["disposed"];

/// The targets an ordinary transition may take from each state.
pub const VALID_TRANSITIONS: &[(&str, &[&str])] = &[
    ("pending", &["loading", "active"]),
    ("loading", &["active", "error"]),
    ("active", &["loading", "active", "paused", "suspended", "unloading", "error"]),
    ("paused", &["active"]),
    ("suspended", &["active", "unloading"]),
    ("unloading", &["disposed", "error"]),
    ("disposed", &[]),
    ("error", &[]),
];

/// Ordinary transitions that unwind disposables when they fire.
pub const DRAINING_TRANSITIONS: &[(&str, &str)] = &[];

/// The shortest ordinary-edge path from each state to a terminal state.
pub const TERMINAL_PATHS: &[(&str, &[&str])] = &[
    ("pending", &["active", "unloading", "disposed"]),
    ("loading", &["active", "unloading", "disposed"]),
    ("active", &["unloading", "disposed"]),
    ("paused", &["active", "unloading", "disposed"]),
    ("suspended", &["unloading", "disposed"]),
    ("unloading", &["disposed"]),
    ("disposed", &[]),
];

/// The PlaceRole of each state.
pub const STATE_ROLES: &[(&str, &str)] = &[
    ("pending", "InitialBottom"),
    ("loading", "Intermediate"),
    ("active", "Intermediate"),
    ("paused", "Intermediate"),
    ("suspended", "Intermediate"),
    ("unloading", "Intermediate"),
    ("disposed", "TerminalTop"),
    ("error", "Exception"),
];

/// The Meet of every profile: the five-state firing trace.
pub const CORE_STATES: &[&str] = &["pending", "loading", "active", "unloading", "disposed"];

/// The receipt spelling of each traced descriptor state.
pub const TRACE_NAMES: &[(&str, &str)] = &[
    ("pending", "PENDING"),
    ("loading", "LOADING"),
    ("active", "ACTIVE"),
    ("suspended", "SUSPENDED"),
    ("unloading", "UNLOADING"),
    ("disposed", "DISPOSED"),
];

/// The union of every profile's states.
pub const DESCRIPTOR_STATES: &[&str] = &[
    "pending",
    "loading",
    "active",
    "paused",
    "suspended",
    "unloading",
    "disposed",
    "error",
];

/// Each profile's states.
pub const PROFILE_STATES: &[(&str, &[&str])] = &[
    ("canonical", &["pending", "loading", "active", "suspended", "unloading", "disposed", "error"]),
    ("legacy_python", &["pending", "loading", "active", "unloading", "disposed"]),
    ("legacy_rust", &["pending", "loading", "active", "paused", "suspended", "unloading", "disposed", "error"]),
];

/// Each profile's ordinary transition table, in descriptor state names.
pub const PROFILE_TRANSITIONS: &[(&str, &[(&str, &[&str])])] = &[
    ("canonical", &[
        ("pending", &["loading", "error"]),
        ("loading", &["active", "error"]),
        ("active", &["suspended", "unloading", "error"]),
        ("suspended", &["active", "unloading", "error"]),
        ("unloading", &["disposed", "error"]),
        ("disposed", &[]),
        ("error", &["disposed"]),
    ]),
    ("legacy_python", &[
        ("pending", &["loading"]),
        ("loading", &["active", "disposed"]),
        ("active", &["unloading"]),
        ("unloading", &["disposed"]),
        ("disposed", &[]),
    ]),
    ("legacy_rust", &[
        ("pending", &["loading", "active"]),
        ("loading", &["active", "error"]),
        ("active", &["loading", "active", "paused", "suspended", "unloading", "error"]),
        ("paused", &["active"]),
        ("suspended", &["active", "unloading"]),
        ("unloading", &["disposed", "error"]),
        ("disposed", &[]),
        ("error", &[]),
    ]),
];

/// The ordinary transition table in the names this profile publishes.
pub const PUBLISHED_TRANSITIONS: &[(&str, &[&str])] = &[
    ("pending", &["loading", "active"]),
    ("loading", &["active", "failed"]),
    ("active", &["loading", "active", "paused", "suspended", "unloading", "failed"]),
    ("paused", &["active"]),
    ("suspended", &["active", "unloading"]),
    ("unloading", &["disposed", "failed"]),
    ("disposed", &[]),
    ("failed", &[]),
];

/// The receipt spelling of the core states: the firing trace.
pub const CORE_TRACE: [&str; 5] = ["PENDING", "LOADING", "ACTIVE", "UNLOADING", "DISPOSED"];

/// The receipt spelling of each traced state, by name.
pub mod trace {
    pub const PENDING: &str = "PENDING";
    pub const LOADING: &str = "LOADING";
    pub const ACTIVE: &str = "ACTIVE";
    pub const SUSPENDED: &str = "SUSPENDED";
    pub const UNLOADING: &str = "UNLOADING";
    pub const DISPOSED: &str = "DISPOSED";
}

/// The `rust_dispose` escape edge, fired by `dispose`.
pub const RUST_DISPOSE: FiberBypass = FiberBypass { name: "rust_dispose", method: "dispose", sources: &["pending", "loading", "active", "paused", "suspended", "unloading", "error"], targets: &["unloading"], drains: true };

/// The escape edges of the profile; each source is a non-terminal state.
pub const BYPASSES: &[FiberBypass] = &[
    RUST_DISPOSE,
];