Skip to main content

sim_kernel/library/
boot.rs

1use crate::{Datum, ExportRecord, LibId, LibManifest, Symbol};
2
3/// A data-only library source suitable for boot receipts.
4///
5/// This mirrors the replayable variants of
6/// [`LibSource`](crate::library::LibSource). Host-constructed library objects
7/// are intentionally excluded because they contain live Rust behavior, not
8/// stable boot data.
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub enum LibSourceSpec {
11    /// A catalog-resolved library symbol.
12    Symbol(Symbol),
13    /// A loader-defined source carried as data.
14    Open {
15        /// Loader-defined source kind.
16        kind: Symbol,
17        /// Opaque payload interpreted by the loader that claims `kind`.
18        payload: Datum,
19    },
20}
21
22impl LibSourceSpec {
23    /// Builds a loader-defined source carried as opaque data.
24    pub fn open(kind: Symbol, payload: Datum) -> Self {
25        Self::Open { kind, payload }
26    }
27}
28
29/// A loaded dependency edge recorded in a boot receipt.
30#[derive(Clone, Debug, PartialEq, Eq)]
31pub struct LibBootDependency {
32    /// Stable id of the loaded dependency in the recorded boot session.
33    pub lib_id: LibId,
34    /// Manifest symbol of the loaded dependency.
35    pub symbol: Symbol,
36}
37
38/// The data-only receipt for one loaded library.
39#[derive(Clone, Debug, PartialEq, Eq)]
40pub struct LibBootReceipt {
41    /// Stable id assigned to the library during the recorded boot session.
42    pub lib_id: LibId,
43    /// Source requested by the caller.
44    pub requested_source: LibSourceSpec,
45    /// Source actually handed to the loader after catalog resolution.
46    pub resolved_source: LibSourceSpec,
47    /// Manifest loaded from the resolved source.
48    pub manifest: LibManifest,
49    /// Loaded dependency edges for this library.
50    pub dependencies: Vec<LibBootDependency>,
51    /// Committed export records produced by the load.
52    pub exports: Vec<ExportRecord>,
53}
54
55/// A data-only boot state for replaying a loaded registry surface.
56#[derive(Clone, Debug, Default, PartialEq, Eq)]
57pub struct RegistryBootState {
58    /// Receipts in load order.
59    pub receipts: Vec<LibBootReceipt>,
60}
61
62impl RegistryBootState {
63    /// Builds a boot state from load-order receipts.
64    pub fn new(receipts: Vec<LibBootReceipt>) -> Self {
65        Self { receipts }
66    }
67}