telltale_machine/
architecture.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum EngineRole {
9 Canonical,
11 AdapterOnly,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct EngineOwnership {
18 pub engine: &'static str,
20 pub role: EngineRole,
22 pub instruction_semantics_owner: &'static str,
24 pub scheduler_policy_owner: &'static str,
26 pub trace_semantics_owner: &'static str,
28}
29
30pub const CANONICAL_ENGINE: &str = "ProtocolMachineKernel";
32
33pub const CROSS_TARGET_CONTRACT: &str =
38 "NativeThreaded ~= NativeSingleThreaded ~= WasmCooperative (modulo effects)";
39
40pub const EQUIVALENCE_SURFACES: &[&str] = &[
42 "normalized_vm_observable_trace",
43 "normalized_scheduler_step_trace",
44 "effect_trace",
45];
46
47pub const ENGINE_OWNERSHIP: &[EngineOwnership] = &[
49 EngineOwnership {
50 engine: "ProtocolMachineKernel",
51 role: EngineRole::Canonical,
52 instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
53 scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
54 trace_semantics_owner: "ProtocolMachineKernel commit path",
55 },
56 EngineOwnership {
57 engine: "ProtocolMachine",
58 role: EngineRole::AdapterOnly,
59 instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
60 scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
61 trace_semantics_owner: "ProtocolMachineKernel commit path",
62 },
63 EngineOwnership {
64 engine: "ThreadedProtocolMachine",
65 role: EngineRole::AdapterOnly,
66 instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
67 scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
68 trace_semantics_owner: "ProtocolMachineKernel commit path",
69 },
70 EngineOwnership {
71 engine: "WasmCooperativeDriver",
72 role: EngineRole::AdapterOnly,
73 instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
74 scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
75 trace_semantics_owner: "ProtocolMachineKernel commit path",
76 },
77];
78
79#[cfg(test)]
80mod tests {
81 use super::{
82 EngineRole, CANONICAL_ENGINE, CROSS_TARGET_CONTRACT, ENGINE_OWNERSHIP, EQUIVALENCE_SURFACES,
83 };
84
85 #[test]
86 fn canonical_engine_is_declared_once() {
87 let canon = ENGINE_OWNERSHIP
88 .iter()
89 .filter(|o| o.role == EngineRole::Canonical)
90 .collect::<Vec<_>>();
91 assert_eq!(canon.len(), 1);
92 assert_eq!(canon[0].engine, CANONICAL_ENGINE);
93 }
94
95 #[test]
96 fn cross_target_contract_declares_required_surfaces() {
97 assert!(CROSS_TARGET_CONTRACT.contains("modulo effects"));
98 assert_eq!(EQUIVALENCE_SURFACES.len(), 3);
99 assert!(EQUIVALENCE_SURFACES.contains(&"normalized_vm_observable_trace"));
100 assert!(EQUIVALENCE_SURFACES.contains(&"normalized_scheduler_step_trace"));
101 assert!(EQUIVALENCE_SURFACES.contains(&"effect_trace"));
102 }
103}