This commit is contained in:
2026-03-24 13:40:41 +00:00
parent 24d6962c0f
commit d123919b73
3 changed files with 102 additions and 29 deletions
+19
View File
@@ -305,6 +305,25 @@ impl Heap {
/// Current number of allocated (live) objects.
pub fn len(&self) -> usize { self.objects.iter().filter(|s| s.is_some()).count() }
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Enumerate handles of coroutines that are currently suspended (i.e., not running):
/// Ready or Sleeping. These must be treated as GC roots by the runtime so their
/// stacks/frames are scanned during mark.
pub fn suspended_coroutine_handles(&self) -> Vec<HeapRef> {
let mut out = Vec::new();
for (idx, slot) in self.objects.iter().enumerate() {
if let Some(obj) = slot {
if obj.header.kind == ObjectKind::Coroutine {
if let Some(co) = &obj.coroutine {
if matches!(co.state, CoroutineState::Ready | CoroutineState::Sleeping) {
out.push(HeapRef(idx as u32));
}
}
}
}
}
out
}
}
#[cfg(test)]