Move the advanced child executor into the live job

This commit is contained in:
gloamxun committed 2026-11-29 12:22:54 +08:00
1 parent d98d7b44c1
commit f6f447dd59
4 files changed
+27 -31

No files matched your search

+16 -14
View File
@@ -331,8 +331,8 @@ pub struct CheckpointSource<'a> {
/// validated and replayed the previous suffix into this revision's draft.
pub enum CheckpointDecision {
Continue,
/// Move to a validated later command boundary in the same input.
Advance(Arc<EntryCheckpoint>),
/// Move to a validated later command boundary and select captures there.
Advance(Box<EntryCheckpoint>),
Reuse(Box<Execution>),
ReplayFailed(String),
}
@@ -557,13 +557,16 @@ impl EntryCheckpoint {
}
impl Executor {
fn rebind_checkpoint_source(&mut self, id: usize, file: SourceFile) {
let mouth = self.inputs.iter_mut().rev().find_map(|frame| match frame {
fn source_mouth_mut(&mut self, id: usize) -> &mut Mouth {
self.inputs.iter_mut().rev().find_map(|frame| match frame {
InputFrame::Source { source, mouth, .. } if *source == id => Some(mouth),
_ => None,
}).expect("checkpoint retains the active scanner");
}).expect("checkpoint retains the source scanner")
}
fn rebind_checkpoint_source(&mut self, id: usize, file: SourceFile) {
if self.sources[id].as_ref() != &file {
mouth.rebind_loaded_prefix(file.data.clone());
self.source_mouth_mut(id).rebind_loaded_prefix(file.data.clone());
self.sources[id] = Arc::new(file);
}
}
@@ -3976,7 +3979,7 @@ impl Executor {
mut select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
mut capture: impl FnMut(S, EntryCheckpoint, &mut F) -> CheckpointDecision,
) -> impl FnMut(&mut Self, usize, bool, &mut F) -> CheckpointDecision {
move |engine, initial_depth, pages_processed, files| {
move |engine, initial_depth, pages_processed, files| loop {
if engine.job_ended {
return CheckpointDecision::Continue;
}
@@ -4031,14 +4034,13 @@ impl Executor {
};
match capture(slot, checkpoint, files) {
CheckpointDecision::Advance(checkpoint) => {
let cancellation = engine.cancellation.take();
let line_break_cache = engine.line_break_cache.take();
*engine = checkpoint.executor.clone();
engine.cancellation = cancellation;
engine.line_break_cache = line_break_cache;
CheckpointDecision::Continue
debug_assert!(checkpoint.completed_steps() > engine.steps);
let mut advanced = checkpoint.executor;
advanced.cancellation = engine.cancellation.take();
advanced.line_break_cache = engine.line_break_cache.take();
*engine = advanced;
}
decision => decision,
decision => return decision,
}
}
}
@@ -140,7 +140,8 @@ impl EntryCheckpoint {
return None;
}
let mut executor = later.executor.clone();
executor.rebind_checkpoint_source(child, (**source).clone());
executor.source_mouth_mut(child).share_loaded_source(self.source_mouth(child));
executor.sources[child] = Arc::clone(source);
executor.deferred_accounting = Some(Arc::new(DeferredAccounting {
current: Arc::clone(self),
basis,
@@ -350,6 +350,11 @@ impl Mouth {
debug_assert!(self.matches_loaded_prefix(&data));
self.data = Arc::new(data);
}
pub(super) fn share_loaded_source(&mut self, current: &Self) {
debug_assert!(self.matches_loaded_prefix(&current.data));
self.data = Arc::clone(&current.data);
}
pub(super) fn payload_bytes(&self) -> usize {
self.data.len()
}
+4 -16
View File
@@ -687,10 +687,9 @@ impl PublishedCheckpoints {
}
impl CheckpointSet {
fn advance_child(&self, current: &CachedCheckpoint) -> Option<(EntryCheckpoint, Option<Capture>)> {
fn advance_child(&self, current: &CachedCheckpoint) -> Option<EntryCheckpoint> {
let boundary = current.child_boundary.as_ref()?;
let child = current.guard.nested_source.as_ref()?;
let Capture::Nested { file, interval: 0 } = current.slots else { return None; };
let previous = self.entries.iter().find(|candidate| {
matches!(candidate.slots, Capture::Nested { interval: 0, .. })
&& candidate.entry.frontier() == current.entry.frontier()
@@ -707,14 +706,7 @@ impl CheckpointSet {
{
return None;
}
let advanced = current.entry.advance_within_child(&previous.entry, &later.entry)?;
let bytes = usize::try_from(child.observed_size?).ok()?;
// A valid advance can land before the new midpoint. Leave the
// later slot available so the current run can capture it there.
let retain = (advanced.frontier() > bytes.div_ceil(NESTED_INTERVALS)
&& advanced.frontier() < bytes)
.then_some(Capture::Nested { file, interval: 1 });
Some((advanced, retain))
current.entry.advance_within_child(&previous.entry, &later.entry)
})
}
@@ -937,16 +929,12 @@ impl SelectedCheckpoint {
if allow_suffix && let Capture::Nested { file, interval: 0 } = slots
&& let Some(current) = captures.nested[file][0].as_ref()
&& Arc::ptr_eq(&current.entry, &entry)
&& let Some((advanced, slots)) = self.set.advance_child(current)
&& let Some(advanced) = self.set.advance_child(current)
{
let advanced = Arc::new(advanced);
let reused = advanced.completed_steps() - entry.completed_steps();
if let Some(slots) = slots {
captures.capture(slots, advanced.clone(), host);
}
work.reused_steps += reused;
work.reused_suffix_steps += reused;
return CheckpointDecision::Advance(advanced);
return CheckpointDecision::Advance(Box::new(advanced));
}
let Capture::Settled { page, .. } = slots else {
return CheckpointDecision::Continue;