feat(vm)!: implement typed callables and single-context execution
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good

Add structural Fn signatures, typed capture environments, indirect calls and Trait dispatch while preserving logical parameter and result groups, ownership and budgets.

Remove guest coroutine execution and legacy loading. Activate bounded sealed PBX v1 with mandatory capture metadata, preserve frame continuations and root return results, and migrate producers and shipped cartridges.

Publish coordinated specs, handoffs and the completed runtime lesson. Validation: 880 workspace tests passed, 9 existing tests ignored; both cartridges completed six production-host frames.
This commit is contained in:
2026-10-09 05:47:24 +01:00
parent 86bade3e1f
commit ec84a6bba5
96 changed files with 3656 additions and 6075 deletions
@@ -2,114 +2,33 @@ use super::*;
impl VirtualMachine {
pub(super) fn handle_safepoint(&mut self) -> Result<(), ResourceFailure> {
if self.gc_alloc_threshold > 0 {
let live_now = self.heap.len();
let since_last = live_now.saturating_sub(self.last_gc_live_count);
if since_last >= self.gc_alloc_threshold {
// Parameters/locals are already in the operand buffer. Stream roots
// without a duplicate collection; suspended contexts are scanned by Heap.
let roots = self
.operand_stack
.iter()
.chain(self.globals.iter())
.filter_map(crate::roots::value_heap_ref)
.chain(self.current_coro);
self.heap.mark_session_roots(roots)?;
self.heap.sweep();
self.last_gc_live_count = self.heap.len();
}
if self.gc_alloc_threshold > 0
&& self.heap.len().saturating_sub(self.last_gc_live_count) >= self.gc_alloc_threshold
{
let roots = self
.operand_stack
.iter()
.chain(self.globals.iter())
.filter_map(crate::roots::value_heap_ref)
.chain(self.call_stack.iter().filter_map(|frame| frame.closure));
self.heap.mark_session_roots(roots)?;
self.heap.sweep();
self.last_gc_live_count = self.heap.len();
}
if let Some(strings) = &self.strings {
strings.reconcile();
}
self.current_tick = self.current_tick.wrapping_add(1);
self.scheduler.wake_ready(self.current_tick)?;
let mut switched_out = false;
if let Some(cur) = self.current_coro {
if let Some(wake) = self.sleep_requested_until {
self.scheduler.sleep_until(cur, wake)?;
self.sleep_requested_until = None;
if let Some(co) = self.heap.coroutine_data_mut(cur) {
co.pc = self.pc;
co.stack = self.operand_stack.take();
co.frames = self.call_stack.take();
co.state = CoroutineState::Sleeping;
co.wake_tick = wake;
}
self.current_coro = None;
self.scheduler.clear_current();
switched_out = true;
} else if self.yield_requested {
self.scheduler.enqueue_ready(cur)?;
if let Some(co) = self.heap.coroutine_data_mut(cur) {
co.pc = self.pc;
co.stack = self.operand_stack.take();
co.frames = self.call_stack.take();
co.state = CoroutineState::Ready;
}
self.current_coro = None;
self.scheduler.clear_current();
switched_out = true;
} else if self.halted || self.pc >= self.program.rom.len() {
if let Some(co) = self.heap.coroutine_data_mut(cur) {
co.pc = self.pc;
co.stack = self.operand_stack.take();
co.frames = self.call_stack.take();
co.state = CoroutineState::Finished;
}
self.current_coro = None;
self.scheduler.clear_current();
switched_out = true;
}
}
if self.current_coro.is_none() {
if let Some(next) = self.scheduler.dequeue_next() {
if let Some(co) = self.heap.coroutine_data_mut(next) {
self.pc = co.pc;
self.operand_stack = co.stack.take();
self.call_stack = co.frames.take();
co.state = CoroutineState::Running;
}
self.current_coro = Some(next);
self.scheduler.set_current(self.current_coro);
} else if switched_out && !self.scheduler.has_sleeping() {
self.halted = true;
}
} else {
self.scheduler.set_current(self.current_coro);
}
self.yield_requested = false;
Ok(())
}
pub fn visit_roots<V: RootVisitor + ?Sized>(&self, visitor: &mut V) {
for value in &self.operand_stack {
for value in self.operand_stack.iter().chain(self.globals.iter()) {
visit_value_for_roots(value, visitor);
}
for frame in &self.call_stack {
if let Some(func_meta) = self.program.functions.get(frame.func_idx) {
let start = frame.stack_base;
let frame_slots =
(func_meta.param_slots as usize) + (func_meta.local_slots as usize);
let mut end = start.saturating_add(frame_slots);
if end > self.operand_stack.len() {
end = self.operand_stack.len();
}
for index in start..end {
if let Some(value) = self.operand_stack.get(index) {
visit_value_for_roots(value, visitor);
}
}
if let Some(closure) = frame.closure {
visitor.visit_heap_ref(closure);
}
}
for global in &self.globals {
visit_value_for_roots(global, visitor);
}
}
}