Phase 11.8/12: MIR Core-13 roadmap, Nyash ABI design, async/await enhancements with TaskGroupBox foundation
Major additions:
- Phase 11.8 MIR cleanup specification (Core-15→14→13 roadmap)
- Nyash ABI unified design document (3×u64 structure)
- TaskGroupBox foundation with cancelAll/joinAll methods
- Enhanced async/await with checkpoint auto-insertion
- Structured concurrency preparation (parent-child task relationships)
Documentation:
- docs/development/roadmap/phases/phase-11.8_mir_cleanup/: Complete Core-13 path
- docs/development/roadmap/phases/phase-12/NYASH-ABI-DESIGN.md: Unified ABI spec
- Updated Phase 12 README with AOT/JIT explanation for script performance
- Added async_task_system/ design docs
Implementation progress:
- FutureBox spawn tracking with weak/strong reference management
- VM checkpoint integration before/after await
- LLVM backend async support preparation
- Verifier rules for await-checkpoint enforcement
- Result<T,E> normalization for timeout/cancellation
Technical insights:
- MIR as 'atomic instructions', Box as 'molecules' philosophy
- 'Everything is Box' enables full-stack with minimal instructions
- Unified BoxCall for array/plugin/async operations future consolidation
Next steps:
- Complete TaskGroupBox implementation
- Migrate from global to scoped task management
- Implement LIFO cleanup on scope exit
- Continue Core-13 instruction consolidation
🚀 'From 15 atoms to infinite programs: The Nyash Box Theory'
This commit is contained in:
77
src/boxes/task_group_box.rs
Normal file
77
src/boxes/task_group_box.rs
Normal file
@ -0,0 +1,77 @@
|
||||
use crate::box_trait::{NyashBox, BoxCore, BoxBase, StringBox, BoolBox, VoidBox};
|
||||
use std::any::Any;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TaskGroupInner {
|
||||
pub(super) strong: Mutex<Vec<crate::boxes::future::FutureBox>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TaskGroupBox {
|
||||
base: BoxBase,
|
||||
// Skeleton: cancellation token owned by this group (future wiring)
|
||||
cancelled: bool,
|
||||
pub(crate) inner: Arc<TaskGroupInner>,
|
||||
}
|
||||
|
||||
impl TaskGroupBox {
|
||||
pub fn new() -> Self {
|
||||
Self { base: BoxBase::new(), cancelled: false, inner: Arc::new(TaskGroupInner { strong: Mutex::new(Vec::new()) }) }
|
||||
}
|
||||
pub fn cancel_all(&mut self) { self.cancelled = true; }
|
||||
/// Cancel all child tasks (scaffold) and return void
|
||||
pub fn cancelAll(&mut self) -> Box<dyn NyashBox> {
|
||||
self.cancel_all();
|
||||
Box::new(VoidBox::new())
|
||||
}
|
||||
/// Join all child tasks with optional timeout (ms); returns void
|
||||
pub fn joinAll(&self, timeout_ms: Option<i64>) -> Box<dyn NyashBox> {
|
||||
let ms = timeout_ms.unwrap_or(2000).max(0) as u64;
|
||||
self.join_all_inner(ms);
|
||||
Box::new(VoidBox::new())
|
||||
}
|
||||
pub fn is_cancelled(&self) -> bool { self.cancelled }
|
||||
|
||||
/// Register a Future into this group's ownership
|
||||
pub fn add_future(&self, fut: &crate::boxes::future::FutureBox) {
|
||||
if let Ok(mut v) = self.inner.strong.lock() {
|
||||
v.push(fut.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn join_all_inner(&self, timeout_ms: u64) {
|
||||
use std::time::{Duration, Instant};
|
||||
let deadline = Instant::now() + Duration::from_millis(timeout_ms);
|
||||
loop {
|
||||
let mut all_ready = true;
|
||||
if let Ok(mut list) = self.inner.strong.lock() {
|
||||
list.retain(|f| !f.ready());
|
||||
if !list.is_empty() { all_ready = false; }
|
||||
}
|
||||
if all_ready { break; }
|
||||
if Instant::now() >= deadline { break; }
|
||||
crate::runtime::global_hooks::safepoint_and_poll();
|
||||
std::thread::yield_now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BoxCore for TaskGroupBox {
|
||||
fn box_id(&self) -> u64 { self.base.id }
|
||||
fn parent_type_id(&self) -> Option<std::any::TypeId> { None }
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "TaskGroup(cancelled={})", self.cancelled)
|
||||
}
|
||||
fn as_any(&self) -> &dyn Any { self }
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any { self }
|
||||
}
|
||||
|
||||
impl NyashBox for TaskGroupBox {
|
||||
fn to_string_box(&self) -> StringBox { StringBox::new(format!("TaskGroup(cancelled={})", self.cancelled)) }
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
if let Some(g) = other.as_any().downcast_ref::<TaskGroupBox>() { BoolBox::new(self.base.id == g.base.id) } else { BoolBox::new(false) }
|
||||
}
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> { Box::new(self.clone()) }
|
||||
fn share_box(&self) -> Box<dyn NyashBox> { self.clone_box() }
|
||||
}
|
||||
Reference in New Issue
Block a user