feat: resume source paint across worker turns and cancel unpublished commands
This commit is contained in:
+56
-16
@@ -200,12 +200,19 @@ fn compile_plan_with_globals(
|
||||
|
||||
/// One real VM, owned only by the existing execution worker. No history replay.
|
||||
/// The UI bridge shares the same managed object heap and publishes atomic frames.
|
||||
struct PendingPaint {
|
||||
window: u64,
|
||||
document: RenderDocument,
|
||||
work: Box<crate::source_paint::Work>,
|
||||
}
|
||||
|
||||
struct RefreshWork {
|
||||
documents: std::collections::BTreeMap<u64, RenderDocument>,
|
||||
windows: std::collections::VecDeque<u64>,
|
||||
current: Option<u64>,
|
||||
root: Option<std::sync::Arc<crate::ui_bridge::UiNode>>,
|
||||
pending: Option<Box<crate::ui_bridge::PendingLayout>>,
|
||||
paint: Option<Box<PendingPaint>>,
|
||||
pass_start: bool,
|
||||
pass_changed: bool,
|
||||
changed: bool,
|
||||
@@ -595,6 +602,7 @@ impl ReplSession {
|
||||
current: None,
|
||||
root: None,
|
||||
pending: None,
|
||||
paint: None,
|
||||
pass_start: true,
|
||||
pass_changed: false,
|
||||
changed: false,
|
||||
@@ -625,6 +633,9 @@ impl ReplSession {
|
||||
}
|
||||
Err(error) => {
|
||||
self.faulted = true;
|
||||
if let Some(paint) = work.paint.take() {
|
||||
self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work)?;
|
||||
}
|
||||
if let Some(pending) = work.pending.take() {
|
||||
self.bridge
|
||||
.abort_layout_frame(&mut self.candidate.vm, *pending)?;
|
||||
@@ -656,6 +667,11 @@ impl ReplSession {
|
||||
return Ok(true);
|
||||
};
|
||||
self.bridge.select_window(id)?;
|
||||
if let Some(paint) = work.paint.take() {
|
||||
let PendingPaint { window, document, work: paint_work } = *paint;
|
||||
let progress = self.bridge.resume_paint_frame(&mut self.candidate.vm, *paint_work)?;
|
||||
return Self::accept_window_paint(work, window, document, progress);
|
||||
}
|
||||
let progress = if let Some(pending) = work.pending.take() {
|
||||
self.bridge
|
||||
.resume_layout_frame(&mut self.candidate.vm, *pending)?
|
||||
@@ -694,15 +710,32 @@ impl ReplSession {
|
||||
if work.work > 200_000 {
|
||||
bail!("layout dependencies did not stabilize within the rendering work budget");
|
||||
}
|
||||
self.bridge.paint_frame(
|
||||
let progress = self.bridge.begin_paint_frame(
|
||||
&mut self.candidate.vm,
|
||||
document.ui_root.as_deref(),
|
||||
&mut document.frame,
|
||||
document.ui_root.clone(),
|
||||
std::mem::take(&mut document.frame),
|
||||
)?;
|
||||
document.validate()?;
|
||||
work.documents.insert(id, document);
|
||||
work.pass_changed = true;
|
||||
work.changed = true;
|
||||
Self::accept_window_paint(work, id, document, progress)
|
||||
}
|
||||
|
||||
fn accept_window_paint(
|
||||
work: &mut RefreshWork,
|
||||
id: u64,
|
||||
mut document: RenderDocument,
|
||||
progress: crate::source_paint::Progress,
|
||||
) -> Result<bool> {
|
||||
match progress {
|
||||
crate::source_paint::Progress::Pending(paint) => {
|
||||
work.paint = Some(Box::new(PendingPaint { window: id, document, work: paint }));
|
||||
}
|
||||
crate::source_paint::Progress::Complete(draft) => {
|
||||
document.frame = draft.frame;
|
||||
document.validate()?;
|
||||
work.documents.insert(id, document);
|
||||
work.pass_changed = true;
|
||||
work.changed = true;
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
@@ -759,6 +792,13 @@ impl ReplSession {
|
||||
return Ok(());
|
||||
};
|
||||
let cancelled = work.pending.is_some();
|
||||
let cancelled_paint = work.paint.is_some();
|
||||
if let Some(paint) = work.paint.take()
|
||||
&& let Err(error) = self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work)
|
||||
{
|
||||
self.faulted = true;
|
||||
return Err(error);
|
||||
}
|
||||
if let Some(pending) = work.pending.take()
|
||||
&& let Err(error) = self
|
||||
.bridge
|
||||
@@ -767,7 +807,7 @@ impl ReplSession {
|
||||
self.faulted = true;
|
||||
return Err(error);
|
||||
}
|
||||
if let Err(error) = self.bridge.note_refresh_restart(cancelled) {
|
||||
if let Err(error) = self.bridge.note_refresh_restart(cancelled, cancelled_paint) {
|
||||
self.faulted = true;
|
||||
return Err(error);
|
||||
}
|
||||
@@ -1023,14 +1063,14 @@ impl ReplSession {
|
||||
|
||||
impl Drop for ReplSession {
|
||||
fn drop(&mut self) {
|
||||
if let Some(mut work) = self.refresh.take()
|
||||
&& let Some(pending) = work.pending.take()
|
||||
{
|
||||
// Close the read-only continuation and checkpoint roots before
|
||||
// Candidate releases the globals/services of a discarded domain.
|
||||
let _ = self
|
||||
.bridge
|
||||
.cancel_layout_frame(&mut self.candidate.vm, *pending);
|
||||
if let Some(mut work) = self.refresh.take() {
|
||||
if let Some(paint) = work.paint.take() {
|
||||
let _ = self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work);
|
||||
}
|
||||
if let Some(pending) = work.pending.take() {
|
||||
// Close the read-only call/checkpoint before Candidate roots.
|
||||
let _ = self.bridge.cancel_layout_frame(&mut self.candidate.vm, *pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user