refactor: retain bridge finalization context across layout pauses
Verify Tessera GUI / verify (push) Failing after 9m10s
Verify Tessera GUI / verify (push) Failing after 9m10s
This commit is contained in:
@@ -503,3 +503,6 @@ The source layout driver now uses Aster's resumable read-only call API with a so
|
||||
|
||||
|
||||
source_layout::start now returns either Complete(Draft) or Pending(Work). The host-owned Work retains the unpublished frame, derived runtime/cache snapshots, convergence plan and prepare root without borrowing caller frame/cache variables. Work::resume consumes the saved job and advances the same VM continuation; Work::cancel closes that continuation and releases the prepare root without merging a draft. A second start is rejected while any read-only execution is active. Every pending Work must be resumed or explicitly cancelled with its owning VM; dropping it is not cancellation. The current layout_frame adapter still drains jobs synchronously. Mount preparation/lifecycle cancellation and parking jobs in the execution worker remain unfinished.
|
||||
|
||||
|
||||
UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. layout_frame remains a synchronous adapter over this protocol. Cross-worker-turn scheduling and cancellation/rollback of prepared mounts are still unfinished; callers must not drop a pending bridge layout as a substitute for cancellation.
|
||||
|
||||
@@ -155,3 +155,6 @@ The source layout driver now uses Aster's resumable read-only call API with a so
|
||||
|
||||
|
||||
source_layout::start now returns either Complete(Draft) or Pending(Work). The host-owned Work retains the unpublished frame, derived runtime/cache snapshots, convergence plan and prepare root without borrowing caller frame/cache variables. Work::resume consumes the saved job and advances the same VM continuation; Work::cancel closes that continuation and releases the prepare root without merging a draft. A second start is rejected while any read-only execution is active. Every pending Work must be resumed or explicitly cancelled with its owning VM; dropping it is not cancellation. The current layout_frame adapter still drains jobs synchronously. Mount preparation/lifecycle cancellation and parking jobs in the execution worker remain unfinished.
|
||||
|
||||
|
||||
UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. layout_frame remains a synchronous adapter over this protocol. Cross-worker-turn scheduling and cancellation/rollback of prepared mounts are still unfinished; callers must not drop a pending bridge layout as a substitute for cancellation.
|
||||
|
||||
@@ -1133,6 +1133,9 @@ The source layout driver now uses Aster's resumable read-only call API with a so
|
||||
|
||||
source_layout::start now returns either Complete(Draft) or Pending(Work). The host-owned Work retains the unpublished frame, derived runtime/cache snapshots, convergence plan and prepare root without borrowing caller frame/cache variables. Work::resume consumes the saved job and advances the same VM continuation; Work::cancel closes that continuation and releases the prepare root without merging a draft. A second start is rejected while any read-only execution is active. Every pending Work must be resumed or explicitly cancelled with its owning VM; dropping it is not cancellation. The current layout_frame adapter still drains jobs synchronously. Mount preparation/lifecycle cancellation and parking jobs in the execution worker remain unfinished.
|
||||
|
||||
|
||||
UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. layout_frame remains a synchronous adapter over this protocol. Cross-worker-turn scheduling and cancellation/rollback of prepared mounts are still unfinished; callers must not drop a pending bridge layout as a substitute for cancellation.
|
||||
|
||||
## UI host object
|
||||
|
||||
Positional arguments only:
|
||||
|
||||
@@ -3889,6 +3889,56 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_layout_can_return_pending_before_committing_a_complete_frame() {
|
||||
let children = std::iter::repeat_n("item", 40)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let source = format!(
|
||||
"class Wide: Row {{\n function measure(self: Wide, mount: Mount, constraints: Constraints): MeasureResult {{ return MeasureResult(340, 60) }}\n}}\nitem = RectBlock(2, 20)\npage = Page()\npage.render(Wide(0, 0, {children}))"
|
||||
);
|
||||
let (mut session, _) = ReplSession::load(&source, "app.main", 270, 1).unwrap();
|
||||
session
|
||||
.bridge
|
||||
.set_viewport(
|
||||
&mut session.candidate.vm,
|
||||
Some(crate::layout::Size {
|
||||
width: 500.0,
|
||||
height: 300.0,
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
let root = session
|
||||
.bridge
|
||||
.prepare_frame(&mut session.candidate.vm)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let mut progress = session
|
||||
.bridge
|
||||
.begin_layout_frame(&mut session.candidate.vm, root)
|
||||
.unwrap();
|
||||
assert!(matches!(
|
||||
progress,
|
||||
crate::ui_bridge::LayoutProgress::Pending(_)
|
||||
));
|
||||
assert!(session.candidate.vm.has_suspended_call());
|
||||
loop {
|
||||
match progress {
|
||||
crate::ui_bridge::LayoutProgress::Pending(pending) => {
|
||||
progress = session
|
||||
.bridge
|
||||
.resume_layout_frame(&mut session.candidate.vm, *pending)
|
||||
.unwrap();
|
||||
}
|
||||
crate::ui_bridge::LayoutProgress::Complete(frame) => {
|
||||
assert_eq!(frame.mounts.last().unwrap().x, 78.0);
|
||||
assert!(!session.candidate.vm.has_suspended_call());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_slices_preserve_all_shared_occurrences() {
|
||||
let children = std::iter::repeat_n("item", 40)
|
||||
|
||||
@@ -929,35 +929,3 @@ fn finish(vm: &mut Vm, mut work: Work, value: Value, reads: Vec<ObjectRef>) -> R
|
||||
.collect();
|
||||
Ok(Progress::Complete(work.state))
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
vm: &mut Vm,
|
||||
desktop: ObjectRef,
|
||||
mounts: Vec<WeakObjectRef>,
|
||||
root: Arc<UiNode>,
|
||||
frame: &mut Frame,
|
||||
runtime: &mut LayoutRuntime,
|
||||
cache: &mut Cache,
|
||||
) -> Result<BTreeSet<ObjectRef>> {
|
||||
let state = Draft {
|
||||
frame: frame.clone(),
|
||||
runtime: runtime.clone(),
|
||||
cache: cache.clone(),
|
||||
reads: BTreeSet::new(),
|
||||
};
|
||||
let mut progress = start(vm, desktop, mounts, root, state, 256)?;
|
||||
loop {
|
||||
match progress {
|
||||
Progress::Pending(work) => {
|
||||
std::thread::yield_now();
|
||||
progress = work.resume(vm, 256)?;
|
||||
}
|
||||
Progress::Complete(state) => {
|
||||
*frame = state.frame;
|
||||
*runtime = state.runtime;
|
||||
*cache = state.cache;
|
||||
return Ok(state.reads);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+128
-18
@@ -1701,6 +1701,26 @@ impl NativeCallable for Function {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use = "pending layout must be resumed on its owning VM"]
|
||||
pub enum LayoutProgress {
|
||||
Pending(Box<PendingLayout>),
|
||||
Complete(Box<crate::document::Frame>),
|
||||
}
|
||||
|
||||
struct LayoutContext {
|
||||
root: Arc<UiNode>,
|
||||
tabs: Vec<crate::tabs::Tab>,
|
||||
full_viewport: Option<crate::layout::Size>,
|
||||
desktop: ObjectRef,
|
||||
window: u64,
|
||||
hooks: Option<ObjectRef>,
|
||||
}
|
||||
|
||||
pub struct PendingLayout {
|
||||
work: crate::source_layout::Work,
|
||||
context: LayoutContext,
|
||||
}
|
||||
|
||||
pub struct UiBridge {
|
||||
pub ui: ObjectRef,
|
||||
session: Shared,
|
||||
@@ -2462,11 +2482,15 @@ impl UiBridge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn layout_frame(
|
||||
pub fn begin_layout_frame(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
root: Option<Arc<UiNode>>,
|
||||
) -> Result<crate::document::Frame> {
|
||||
) -> Result<LayoutProgress> {
|
||||
anyhow::ensure!(
|
||||
!vm.has_suspended_call() && !vm.object_store().is_read_only(),
|
||||
"cannot prepare another frame during suspended layout"
|
||||
);
|
||||
let Some(root) = root else {
|
||||
self.session
|
||||
.lock()
|
||||
@@ -2496,9 +2520,9 @@ impl UiBridge {
|
||||
}
|
||||
};
|
||||
self.commit_frame(vm, None, &frame)?;
|
||||
return Ok(frame);
|
||||
return Ok(LayoutProgress::Complete(Box::new(frame)));
|
||||
};
|
||||
let (mut layout, mut cache, desktop, page, nodes) = {
|
||||
let (mut layout, cache, desktop, page, nodes) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
@@ -2548,16 +2572,88 @@ impl UiBridge {
|
||||
.synchronize(vm, desktop, page, nodes, &frame, true)?;
|
||||
(hooks, state.mounts.ordered())
|
||||
};
|
||||
let context = LayoutContext {
|
||||
root: root.clone(),
|
||||
tabs,
|
||||
full_viewport,
|
||||
desktop,
|
||||
window: frame.window,
|
||||
hooks,
|
||||
};
|
||||
let draft = crate::source_layout::Draft {
|
||||
frame,
|
||||
runtime: layout,
|
||||
cache,
|
||||
reads: std::collections::BTreeSet::new(),
|
||||
};
|
||||
let progress = crate::source_layout::start(vm, desktop, mounts, root, draft, 256);
|
||||
self.accept_layout_progress(vm, context, progress)
|
||||
}
|
||||
|
||||
pub fn resume_layout_frame(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
pending: PendingLayout,
|
||||
) -> Result<LayoutProgress> {
|
||||
let PendingLayout { work, context } = pending;
|
||||
if let Err(error) = self.select_window(context.window) {
|
||||
let cancelled = work.cancel(vm);
|
||||
let released = context.hooks.map(|hooks| vm.release(hooks)).transpose();
|
||||
cancelled?;
|
||||
released?;
|
||||
return Err(error);
|
||||
}
|
||||
let progress = work.resume(vm, 256);
|
||||
self.accept_layout_progress(vm, context, progress)
|
||||
}
|
||||
|
||||
fn accept_layout_progress(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
context: LayoutContext,
|
||||
progress: Result<crate::source_layout::Progress>,
|
||||
) -> Result<LayoutProgress> {
|
||||
match progress {
|
||||
Ok(crate::source_layout::Progress::Pending(work)) => {
|
||||
Ok(LayoutProgress::Pending(Box::new(PendingLayout {
|
||||
work,
|
||||
context,
|
||||
})))
|
||||
}
|
||||
Ok(crate::source_layout::Progress::Complete(draft)) => self
|
||||
.finish_layout_frame(vm, context, draft)
|
||||
.map(|frame| LayoutProgress::Complete(Box::new(frame))),
|
||||
Err(error) => {
|
||||
if let Some(hooks) = context.hooks {
|
||||
vm.release(hooks)?;
|
||||
}
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_layout_frame(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
context: LayoutContext,
|
||||
draft: crate::source_layout::Draft,
|
||||
) -> Result<crate::document::Frame> {
|
||||
let LayoutContext {
|
||||
root,
|
||||
tabs,
|
||||
full_viewport,
|
||||
desktop,
|
||||
window,
|
||||
hooks,
|
||||
} = context;
|
||||
let crate::source_layout::Draft {
|
||||
mut frame,
|
||||
runtime: mut layout,
|
||||
cache,
|
||||
reads,
|
||||
} = draft;
|
||||
let result = (|| {
|
||||
let reads = crate::source_layout::render(
|
||||
vm,
|
||||
desktop,
|
||||
mounts,
|
||||
root.clone(),
|
||||
&mut frame,
|
||||
&mut layout,
|
||||
&mut cache,
|
||||
)?;
|
||||
self.select_window(window)?;
|
||||
{
|
||||
let state = self
|
||||
.session
|
||||
@@ -2568,11 +2664,7 @@ impl UiBridge {
|
||||
// Native layout may replace the structural Frame; attach chrome only
|
||||
// after either layout path has produced the final page geometry.
|
||||
frame.tabs = tabs;
|
||||
frame.window = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.current;
|
||||
frame.window = window;
|
||||
// Capture versions before lifecycle hooks can change a dependency.
|
||||
let reads = reads
|
||||
.into_iter()
|
||||
@@ -2616,6 +2708,24 @@ impl UiBridge {
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn layout_frame(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
root: Option<Arc<UiNode>>,
|
||||
) -> Result<crate::document::Frame> {
|
||||
let mut progress = self.begin_layout_frame(vm, root)?;
|
||||
loop {
|
||||
match progress {
|
||||
LayoutProgress::Pending(pending) => {
|
||||
std::thread::yield_now();
|
||||
progress = self.resume_layout_frame(vm, *pending)?;
|
||||
}
|
||||
LayoutProgress::Complete(frame) => return Ok(*frame),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rendered(&self, vm: &Vm) -> Result<Option<Arc<UiNode>>> {
|
||||
let state = self
|
||||
.session
|
||||
|
||||
Reference in New Issue
Block a user