#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EngineRole {
Canonical,
AdapterOnly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EngineOwnership {
pub engine: &'static str,
pub role: EngineRole,
pub instruction_semantics_owner: &'static str,
pub scheduler_policy_owner: &'static str,
pub trace_semantics_owner: &'static str,
}
pub const CANONICAL_ENGINE: &str = "ProtocolMachineKernel";
pub const CROSS_TARGET_CONTRACT: &str =
"NativeThreaded ~= NativeSingleThreaded ~= WasmCooperative (modulo effects)";
pub const EQUIVALENCE_SURFACES: &[&str] = &[
"normalized_vm_observable_trace",
"normalized_scheduler_step_trace",
"effect_trace",
];
pub const ENGINE_OWNERSHIP: &[EngineOwnership] = &[
EngineOwnership {
engine: "ProtocolMachineKernel",
role: EngineRole::Canonical,
instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
trace_semantics_owner: "ProtocolMachineKernel commit path",
},
EngineOwnership {
engine: "ProtocolMachine",
role: EngineRole::AdapterOnly,
instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
trace_semantics_owner: "ProtocolMachineKernel commit path",
},
EngineOwnership {
engine: "ThreadedProtocolMachine",
role: EngineRole::AdapterOnly,
instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
trace_semantics_owner: "ProtocolMachineKernel commit path",
},
EngineOwnership {
engine: "WasmCooperativeDriver",
role: EngineRole::AdapterOnly,
instruction_semantics_owner: "ProtocolMachineKernel + exec::*",
scheduler_policy_owner: "ProtocolMachineKernel + scheduler::Scheduler",
trace_semantics_owner: "ProtocolMachineKernel commit path",
},
];
#[cfg(test)]
mod tests {
use super::{
EngineRole, CANONICAL_ENGINE, CROSS_TARGET_CONTRACT, ENGINE_OWNERSHIP, EQUIVALENCE_SURFACES,
};
#[test]
fn canonical_engine_is_declared_once() {
let canon = ENGINE_OWNERSHIP
.iter()
.filter(|o| o.role == EngineRole::Canonical)
.collect::<Vec<_>>();
assert_eq!(canon.len(), 1);
assert_eq!(canon[0].engine, CANONICAL_ENGINE);
}
#[test]
fn cross_target_contract_declares_required_surfaces() {
assert!(CROSS_TARGET_CONTRACT.contains("modulo effects"));
assert_eq!(EQUIVALENCE_SURFACES.len(), 3);
assert!(EQUIVALENCE_SURFACES.contains(&"normalized_vm_observable_trace"));
assert!(EQUIVALENCE_SURFACES.contains(&"normalized_scheduler_step_trace"));
assert!(EQUIVALENCE_SURFACES.contains(&"effect_trace"));
}
}