Enable automatic native checkpoints and browser preview

This commit is contained in:
gloamxun committed 2026-11-19 10:05:41 +08:00
1 parent bb1a166c4c
commit 06463399bb
10 files changed
+877 -92

No files matched your search

+45 -12
View File
@@ -183,6 +183,7 @@ pub struct Executor {
split_discards: Vec<NativeVerticalNode>,
output_frame: Option<page::OutputFrame>,
pending_shipouts: VecDeque<NativeBox>,
shipped_pages: usize,
job_ended: bool,
fresh_job: bool,
job_name: Option<String>,
@@ -306,6 +307,7 @@ impl Executor {
split_discards: Vec::new(),
output_frame: None,
pending_shipouts: VecDeque::new(),
shipped_pages: 0,
job_ended: false,
fresh_job: true,
job_name: None,
@@ -2939,7 +2941,7 @@ impl Executor {
/// Capture the first eligible entry command boundary at or beyond the
/// requested physical byte. The callback captures the matching host state.
pub fn run_capturing_entry<F: SourceProvider, H>(
mut self,
self,
file: SourceFile,
files: &mut F,
minimum_frontier: usize,
@@ -2948,11 +2950,38 @@ impl Executor {
Result<Execution, ExecutionFailure>,
Option<(EntryCheckpoint, H)>,
) {
let incoming_state = self.state.fingerprint();
let mut requested = false;
let mut capture_host = Some(capture_host);
let mut captured = None;
let result = self.run_capturing_entries(
file,
files,
|frontier, _| {
if requested || frontier < minimum_frontier {
return None;
}
requested = true;
Some(())
},
|(), checkpoint, files| {
captured = Some((checkpoint, capture_host.take().unwrap()(files)));
},
);
(result, captured)
}
/// Observe eligible boundaries during normal execution. Only clone the
/// state when the caller selects a boundary, giving it its matching host.
pub fn run_capturing_entries<F: SourceProvider, S>(
mut self,
file: SourceFile,
files: &mut F,
mut select: impl FnMut(usize, usize) -> Option<S>,
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
) -> Result<Execution, ExecutionFailure> {
let incoming_state = self.state.fingerprint();
let result = self.run_observed(file, files, |engine, initial_depth, files| {
if capture_host.is_none() || engine.job_ended {
if engine.job_ended {
return;
}
let Some(InputFrame::Source {
@@ -2970,16 +2999,20 @@ impl Executor {
};
// Keep the active macro and argument cursors, but a second
// physical source would have an independent unread frontier.
if frontier < minimum_frontier
|| engine.inputs[1..]
.iter()
.any(|frame| matches!(frame, InputFrame::Source { .. }))
|| engine.sources.iter().enumerate().any(|(index, other)| {
index != *source && other.name == engine.sources[*source].name
})
if engine.inputs[1..]
.iter()
.any(|frame| matches!(frame, InputFrame::Source { .. }))
{
return;
}
let Some(slot) = select(frontier, engine.shipped_pages) else {
return;
};
if engine.sources.iter().enumerate().any(|(index, other)| {
index != *source && other.name == engine.sources[*source].name
}) {
return;
}
let mut executor = engine.clone();
executor.cancellation = None;
executor.line_break_cache = None;
@@ -2990,9 +3023,9 @@ impl Executor {
incoming_state,
frontier,
};
captured = Some((checkpoint, capture_host.take().unwrap()(files)));
capture(slot, checkpoint, files);
});
(self.finish_execution(result, incoming_state), captured)
self.finish_execution(result, incoming_state)
}
fn finish_execution(
mut self,
@@ -306,9 +306,13 @@ impl Executor {
return self.fail("cannot ship a PDF link operation to DVI");
}
match link {
LinkNode::Start(_) if link_depth == 10 => return self.fail("PDF link stack capacity exceeded"),
LinkNode::Start(_) if link_depth == 10 => {
return self.fail("PDF link stack capacity exceeded");
}
LinkNode::Start(_) => link_depth += 1,
LinkNode::End if link_depth == 0 => return self.fail("\\pdfendlink used without \\pdfstartlink"),
LinkNode::End if link_depth == 0 => {
return self.fail("\\pdfendlink used without \\pdfstartlink");
}
LinkNode::End => link_depth -= 1,
LinkNode::Destination { .. } => {}
}
@@ -336,6 +340,7 @@ impl Executor {
self.current = current;
self.native_page.as_mut().unwrap().dead_cycles = 0;
let before = self.statistics_before_shipout(&b, files)?;
self.shipped_pages += 1;
self.events.push(Event::Shipout(Box::new(NativeShipout {
box_node: b,
device,
@@ -169,22 +169,19 @@ impl RevisionJob {
self.finish_execution(executed, files)
}
/// Capture a possible entry continuation while executing the full revision.
pub fn run_capturing_entry<F: SourceProvider, H>(
/// Capture selected entry continuations while running the full revision.
pub fn run_capturing_entries<F: SourceProvider, S>(
self,
executor: Executor,
source: SourceFile,
files: &mut F,
minimum_frontier: usize,
capture_host: impl FnOnce(&mut F) -> H,
) -> (
Result<Arc<RevisionExecution>, RevisionFailure>,
Option<(EntryCheckpoint, H)>,
) {
let (executed, captured) = executor
select: impl FnMut(usize, usize) -> Option<S>,
capture: impl FnMut(S, EntryCheckpoint, &mut F),
) -> Result<Arc<RevisionExecution>, RevisionFailure> {
let executed = executor
.with_cancellation(self.cancellation.clone())
.run_capturing_entry(source, files, minimum_frontier, capture_host);
(self.finish_execution(executed, files), captured)
.run_capturing_entries(source, files, select, capture);
self.finish_execution(executed, files)
}
/// Resume after the host has validated prefix dependencies and replayed