Reuse verified native suffixes after settled output routines
This commit is contained in:
1 parent
f387b1db61
commit
0117449023
30 files changed
+791
-77
No files matched your search
@@ -487,7 +487,7 @@ impl NativeBox {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(super) struct VerticalBuilder {
|
||||
pub nodes: Vec<NativeVerticalNode>,
|
||||
pub prev_depth: i32,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use super::Dependency;
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub(super) struct DependencyReads {
|
||||
byte_catcodes: [u64; 4],
|
||||
other: HashSet<Dependency>,
|
||||
|
||||
@@ -39,6 +39,7 @@ mod scanning;
|
||||
mod scheduling;
|
||||
mod specials;
|
||||
mod statistics;
|
||||
mod continuation;
|
||||
mod xdv_annotation;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
@@ -57,7 +58,7 @@ impl Default for Limits {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct InputToken {
|
||||
token: Token,
|
||||
frozen: bool,
|
||||
@@ -131,7 +132,7 @@ enum InputFrame {
|
||||
},
|
||||
Boundary,
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum TokenInputKind {
|
||||
Inserted,
|
||||
BackedUp,
|
||||
@@ -144,7 +145,7 @@ enum TheValue {
|
||||
Tokens(Vec<Token>),
|
||||
Text(std::string::String),
|
||||
}
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct Conditional {
|
||||
primitive: Primitive,
|
||||
inverted: bool,
|
||||
@@ -241,6 +242,8 @@ pub struct Executor {
|
||||
in_csname: bool,
|
||||
command_trace_mode: Option<&'static str>,
|
||||
events: ExecutionEvents,
|
||||
// Set before operations that inspect earlier events beyond their count.
|
||||
reads_event_history: bool,
|
||||
steps: usize,
|
||||
ligature_carry: super::ligature::Carry,
|
||||
current: Span,
|
||||
@@ -314,6 +317,15 @@ pub struct CheckpointSource<'a> {
|
||||
pub bytes: usize,
|
||||
pub frontier: usize,
|
||||
pub is_entry: bool,
|
||||
pub output_returned: bool,
|
||||
}
|
||||
|
||||
/// Called only at a selected boundary. Reuse requires that the caller has
|
||||
/// validated and replayed the previous suffix into this revision's draft.
|
||||
pub enum CheckpointDecision {
|
||||
Continue,
|
||||
Reuse(Box<Execution>),
|
||||
ReplayFailed(String),
|
||||
}
|
||||
|
||||
/// A live, in-memory kernel continuation at an entry-file command boundary.
|
||||
@@ -387,7 +399,9 @@ impl EntryCheckpoint {
|
||||
files: &mut impl SourceProvider,
|
||||
cancellation: Cancellation,
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
self.resume_observed(source, None, files, cancellation, None, None, |_, _, _, _| {})
|
||||
self.resume_observed(source, None, files, cancellation, None, None,
|
||||
|_, _, _, _| CheckpointDecision::Continue)
|
||||
.expect("ordinary resume cannot reject a cached suffix")
|
||||
}
|
||||
|
||||
pub(super) fn resume_capturing_sources_after_host_replay<F: SourceProvider, S>(
|
||||
@@ -399,7 +413,7 @@ impl EntryCheckpoint {
|
||||
line_break_cache: std::sync::Arc<super::LineBreakCache>,
|
||||
previous: Option<&Execution>,
|
||||
select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
self.resume_observed(
|
||||
source,
|
||||
@@ -408,8 +422,27 @@ impl EntryCheckpoint {
|
||||
cancellation,
|
||||
Some(line_break_cache),
|
||||
previous,
|
||||
Executor::entry_observer(self.incoming_state, select, capture),
|
||||
Executor::entry_observer(self.incoming_state, select, |slot, entry, files| {
|
||||
capture(slot, entry, files);
|
||||
CheckpointDecision::Continue
|
||||
}),
|
||||
)
|
||||
.expect("ordinary resume cannot reject a cached suffix")
|
||||
}
|
||||
|
||||
pub(super) fn resume_deciding_suffix<F: SourceProvider, S>(
|
||||
&self,
|
||||
source: SourceFile,
|
||||
nested: Option<SourceFile>,
|
||||
files: &mut F,
|
||||
cancellation: Cancellation,
|
||||
line_break_cache: Arc<super::LineBreakCache>,
|
||||
previous: Option<&Execution>,
|
||||
select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
self.resume_observed(source, nested, files, cancellation, Some(line_break_cache), previous,
|
||||
Executor::entry_observer(self.incoming_state, select, capture))
|
||||
}
|
||||
|
||||
fn resume_observed<F: SourceProvider>(
|
||||
@@ -420,15 +453,15 @@ impl EntryCheckpoint {
|
||||
cancellation: Cancellation,
|
||||
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
|
||||
previous: Option<&Execution>,
|
||||
capture_boundary: impl FnMut(&mut Executor, usize, bool, &mut F),
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
capture_boundary: impl FnMut(&mut Executor, usize, bool, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
if !self.accepts_entry(&source)
|
||||
|| match &nested {
|
||||
Some(nested) => !self.accepts_nested_source(&nested.name, &nested.data),
|
||||
None => self.nested_source().is_some(),
|
||||
}
|
||||
{
|
||||
return None;
|
||||
return Ok(None);
|
||||
}
|
||||
let mut executor = self.executor.clone().with_cancellation(cancellation);
|
||||
executor.line_break_cache = line_break_cache;
|
||||
@@ -446,8 +479,16 @@ impl EntryCheckpoint {
|
||||
capture_boundary,
|
||||
)
|
||||
});
|
||||
let result = match result {
|
||||
Ok(CheckpointDecision::Reuse(execution)) => {
|
||||
return Ok(Some(Ok(*execution)));
|
||||
}
|
||||
Ok(CheckpointDecision::ReplayFailed(error)) => return Err(error),
|
||||
Ok(CheckpointDecision::Continue) => Ok(()),
|
||||
Err(error) => Err(error),
|
||||
};
|
||||
let result = executor.finish_observed_input(result, files);
|
||||
Some(executor.finish_execution(result, self.incoming_state, previous))
|
||||
Ok(Some(executor.finish_execution(result, self.incoming_state, previous)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,6 +537,7 @@ impl Executor {
|
||||
in_csname: false,
|
||||
command_trace_mode: None,
|
||||
events: ExecutionEvents::default(),
|
||||
reads_event_history: false,
|
||||
steps: 0,
|
||||
ligature_carry: super::ligature::Carry::default(),
|
||||
current: Span::default(),
|
||||
@@ -3491,6 +3533,7 @@ impl Executor {
|
||||
reads,
|
||||
events: self.events.into_vec(),
|
||||
steps: self.steps,
|
||||
reads_event_history: self.reads_event_history,
|
||||
})
|
||||
}
|
||||
fn check_input_character(&self, code: i32) -> Result<(), Error> {
|
||||
@@ -3785,7 +3828,7 @@ impl Executor {
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<Execution, ExecutionFailure> {
|
||||
let incoming_state = self.state.fingerprint();
|
||||
let result = self.run_observed(file, files, |_, _, _, _| {});
|
||||
let result = self.run_observed(file, files, |_, _, _, _| CheckpointDecision::Continue);
|
||||
self.finish_execution(result, incoming_state, None)
|
||||
}
|
||||
/// Capture the first eligible entry command boundary at or beyond the
|
||||
@@ -3841,13 +3884,16 @@ impl Executor {
|
||||
file: SourceFile,
|
||||
files: &mut F,
|
||||
select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> Result<Execution, ExecutionFailure> {
|
||||
let incoming_state = self.state.fingerprint();
|
||||
let result = self.run_observed(
|
||||
file,
|
||||
files,
|
||||
Self::entry_observer(incoming_state, select, capture),
|
||||
Self::entry_observer(incoming_state, select, |slot, entry, files| {
|
||||
capture(slot, entry, files);
|
||||
CheckpointDecision::Continue
|
||||
}),
|
||||
);
|
||||
self.finish_execution(result, incoming_state, None)
|
||||
}
|
||||
@@ -3855,17 +3901,17 @@ impl Executor {
|
||||
fn entry_observer<F: SourceProvider, S>(
|
||||
incoming_state: u64,
|
||||
mut select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> impl FnMut(&mut Self, usize, bool, &mut F) {
|
||||
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| {
|
||||
if engine.job_ended {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
}
|
||||
let Some(InputFrame::Source {
|
||||
source: entry, eof_seen: false, pseudo_trace: None, ..
|
||||
}) = engine.inputs.first()
|
||||
else {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
// Retain the active scanner plus its suspended parents. A pseudo
|
||||
// input or an EOF hook has no replaceable physical byte prefix.
|
||||
@@ -3873,10 +3919,10 @@ impl Executor {
|
||||
source, mouth, eof_seen: false, pseudo_trace: None, ..
|
||||
}) = engine.inputs.iter().rev().find(|frame| matches!(frame, InputFrame::Source { .. }))
|
||||
else {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
let Some(frontier) = mouth.physical_frontier() else {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
let (entry, active_source) = (*entry, *source);
|
||||
let file = &engine.sources[active_source];
|
||||
@@ -3886,14 +3932,15 @@ impl Executor {
|
||||
bytes: file.data.len(),
|
||||
frontier,
|
||||
is_entry: active_source == entry,
|
||||
output_returned: engine.output_frame.is_none(),
|
||||
};
|
||||
let Some(slot) = select(position, engine.shipped_pages) else {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
if engine.sources.iter().enumerate().any(|(index, other)| {
|
||||
index != active_source && other.name == file.name
|
||||
}) {
|
||||
return;
|
||||
return CheckpointDecision::Continue;
|
||||
}
|
||||
engine.events.seal_prefix();
|
||||
let mut executor = engine.clone();
|
||||
@@ -3908,7 +3955,7 @@ impl Executor {
|
||||
frontier,
|
||||
pages_processed,
|
||||
};
|
||||
capture(slot, checkpoint, files);
|
||||
capture(slot, checkpoint, files)
|
||||
}
|
||||
}
|
||||
fn finish_execution(
|
||||
@@ -3989,19 +4036,22 @@ impl Executor {
|
||||
reads,
|
||||
incoming_state,
|
||||
steps: self.steps,
|
||||
reads_event_history: self.reads_event_history,
|
||||
})
|
||||
}
|
||||
fn run_observed<F: SourceProvider>(
|
||||
&mut self,
|
||||
file: SourceFile,
|
||||
files: &mut F,
|
||||
capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F),
|
||||
capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F) -> CheckpointDecision,
|
||||
) -> Result<(), Error> {
|
||||
self.check_cancellation()?;
|
||||
self.change_interaction_mode(self.interaction_mode, files)?;
|
||||
let result = self.prepare_input(file, files).and_then(|initial_depth| {
|
||||
self.emit_format_image_warnings(files)?;
|
||||
self.run_active_input(initial_depth, false, files, capture_boundary)
|
||||
self.run_active_input(initial_depth, false, files, capture_boundary).map(|action| {
|
||||
debug_assert!(matches!(action, CheckpointDecision::Continue));
|
||||
})
|
||||
});
|
||||
self.finish_observed_input(result, files)
|
||||
}
|
||||
@@ -4116,20 +4166,26 @@ impl Executor {
|
||||
initial_depth: usize,
|
||||
mut pages_processed: bool,
|
||||
files: &mut F,
|
||||
mut capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F),
|
||||
) -> Result<(), Error> {
|
||||
mut capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F) -> CheckpointDecision,
|
||||
) -> Result<CheckpointDecision, Error> {
|
||||
let xe = self.state.input_profile() == InputProfile::XeTeX;
|
||||
loop {
|
||||
if !std::mem::take(&mut pages_processed) {
|
||||
self.check_box_capacity(None)?;
|
||||
capture_boundary(self, initial_depth, false, files);
|
||||
match capture_boundary(self, initial_depth, false, files) {
|
||||
CheckpointDecision::Continue => {}
|
||||
decision => return Ok(decision),
|
||||
}
|
||||
let shipped_pages = self.shipped_pages;
|
||||
self.process_native_pages(files)?;
|
||||
self.check_box_capacity(None)?;
|
||||
if self.shipped_pages != shipped_pages {
|
||||
// A following expandable command can read an input before
|
||||
// the next main-loop iteration.
|
||||
capture_boundary(self, initial_depth, true, files);
|
||||
match capture_boundary(self, initial_depth, true, files) {
|
||||
CheckpointDecision::Continue => {}
|
||||
decision => return Ok(decision),
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some((input, meaning)) = self.expanded_with_meaning(files, false)? else {
|
||||
@@ -4611,7 +4667,7 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(CheckpointDecision::Continue)
|
||||
}
|
||||
fn assignment(
|
||||
&mut self,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use super::super::boxes::{self, PackSpec, VerticalBuilder};
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) enum Boundary {
|
||||
Prefix,
|
||||
Entry,
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
use super::*;
|
||||
|
||||
impl InputFrame {
|
||||
fn same_at_shipout(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(
|
||||
Self::Source {
|
||||
source: a,
|
||||
mouth: am,
|
||||
eof_seen: ae,
|
||||
pseudo_trace: at,
|
||||
group_boundary: ag,
|
||||
conditional_boundary: ac,
|
||||
},
|
||||
Self::Source {
|
||||
source: b,
|
||||
mouth: bm,
|
||||
eof_seen: be,
|
||||
pseudo_trace: bt,
|
||||
group_boundary: bg,
|
||||
conditional_boundary: bc,
|
||||
},
|
||||
) => (a, ae, at, ag, ac) == (b, be, bt, bg, bc) && am.same_unread_input(bm),
|
||||
(
|
||||
Self::Tokens {
|
||||
tokens: a,
|
||||
cursor: ac,
|
||||
kind: ak,
|
||||
},
|
||||
Self::Tokens {
|
||||
tokens: b,
|
||||
cursor: bc,
|
||||
kind: bk,
|
||||
},
|
||||
) => (ac, ak) == (bc, bk) && a.iter().eq(b.iter()),
|
||||
(
|
||||
Self::Macro {
|
||||
definition: a,
|
||||
name: an,
|
||||
cursor: ac,
|
||||
arguments: aa,
|
||||
call: aspan,
|
||||
},
|
||||
Self::Macro {
|
||||
definition: b,
|
||||
name: bn,
|
||||
cursor: bc,
|
||||
arguments: ba,
|
||||
call: bspan,
|
||||
},
|
||||
) => (a, an, ac, aa, aspan) == (b, bn, bc, ba, bspan),
|
||||
(
|
||||
Self::Argument {
|
||||
tokens: a,
|
||||
cursor: ac,
|
||||
call: aspan,
|
||||
},
|
||||
Self::Argument {
|
||||
tokens: b,
|
||||
cursor: bc,
|
||||
call: bspan,
|
||||
},
|
||||
) => (a, ac, aspan) == (b, bc, bspan),
|
||||
(
|
||||
Self::Hook {
|
||||
parameter: a,
|
||||
tokens: at,
|
||||
cursor: ac,
|
||||
},
|
||||
Self::Hook {
|
||||
parameter: b,
|
||||
tokens: bt,
|
||||
cursor: bc,
|
||||
},
|
||||
) => (a, at, ac) == (b, bt, bc),
|
||||
(Self::Boundary, Self::Boundary) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EntryCheckpoint {
|
||||
/// Construct an execution with the current prefix and a previously
|
||||
/// completed suffix. The host must still validate and replay that suffix.
|
||||
pub fn splice_settled_suffix(&self, prior: &Self, completed: &Execution) -> Option<Execution> {
|
||||
if self.entry != self.active_source
|
||||
|| prior.entry != prior.active_source
|
||||
|| self.entry != prior.entry
|
||||
|| self.initial_depth != prior.initial_depth
|
||||
|| self.incoming_state != prior.incoming_state
|
||||
|| self.frontier != prior.frontier
|
||||
|| self.pages_processed != prior.pages_processed
|
||||
|| completed.incoming_state != prior.incoming_state
|
||||
|| completed.reads_event_history
|
||||
|| completed.format_dumped
|
||||
|| completed.steps <= prior.completed_steps()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let current = &self.executor;
|
||||
let old = &prior.executor;
|
||||
if !same_kernel_continuation(current, old) {
|
||||
return None;
|
||||
}
|
||||
if current.sources.len() != old.sources.len()
|
||||
|| current
|
||||
.sources
|
||||
.iter()
|
||||
.zip(&old.sources)
|
||||
.enumerate()
|
||||
.any(|(id, (new, old))| {
|
||||
if id == self.entry {
|
||||
new.name != old.name || new.data.len() != old.data.len()
|
||||
} else {
|
||||
new != old
|
||||
}
|
||||
})
|
||||
|| completed.sources.get(self.entry)? != &old.sources[self.entry]
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let mut sources = completed.sources.clone();
|
||||
sources[self.entry] = current.sources[self.entry].clone();
|
||||
let tail = completed.events.get(old.events.len()..)?;
|
||||
let mut events = current.events.clone().into_vec();
|
||||
events.extend_from_slice(tail);
|
||||
Some(Execution {
|
||||
format_dumped: completed.format_dumped,
|
||||
format_pdf_images: completed.format_pdf_images.clone(),
|
||||
job_name: completed.job_name.clone(),
|
||||
interaction_mode: completed.interaction_mode,
|
||||
native_page: completed.native_page.clone(),
|
||||
split_discards: completed.split_discards.clone(),
|
||||
after_assignment: completed.after_assignment.clone(),
|
||||
events,
|
||||
state: completed.state.clone(),
|
||||
io: completed.io.clone(),
|
||||
input_position: completed.input_position,
|
||||
paragraph_mode: completed.paragraph_mode,
|
||||
sources,
|
||||
stream_sources: completed.stream_sources.clone(),
|
||||
generated_inputs: completed.generated_inputs.clone(),
|
||||
reads: completed.reads.clone(),
|
||||
incoming_state: completed.incoming_state,
|
||||
outgoing_state: completed.outgoing_state,
|
||||
steps: completed.steps,
|
||||
reads_event_history: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
// Every field belongs to one of these checks. Adding kernel state requires
|
||||
// an explicit decision here before a later execution may be skipped.
|
||||
macro_rules! same_values {
|
||||
([$($value:ident),+ $(,)?], [$($planned:ident),+ $(,)?], [$($runtime:ident),+ $(,)?]) => {{
|
||||
let Executor {
|
||||
$($value,)+
|
||||
$($planned: _,)+
|
||||
$($runtime: _,)+
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
pdf_last_match: _,
|
||||
} = current;
|
||||
true $(&& *$value == prior.$value)+
|
||||
}};
|
||||
}
|
||||
if !same_values!(
|
||||
[
|
||||
state,
|
||||
limits,
|
||||
interaction_mode,
|
||||
stream_sources,
|
||||
generated_inputs,
|
||||
reads,
|
||||
reads_tracing_macros,
|
||||
conditionals,
|
||||
in_csname,
|
||||
command_trace_mode,
|
||||
steps,
|
||||
ligature_carry,
|
||||
current,
|
||||
expression_depth,
|
||||
scanner_depth,
|
||||
scanner_status,
|
||||
expansion_depth,
|
||||
io,
|
||||
pdf_colors,
|
||||
xdv_colors,
|
||||
pdf_running_links,
|
||||
pdf_interword_spaces,
|
||||
pdf_space_font,
|
||||
pdf_loaded_space_font,
|
||||
pdf_virtual_fonts,
|
||||
pdf_catalog_tokens,
|
||||
pdf_outlines,
|
||||
pdf_outline_payload,
|
||||
pdf_info_tokens,
|
||||
restored_pdf_image_count,
|
||||
format_image_warnings,
|
||||
pdf_force_pagebox_warned,
|
||||
input_position,
|
||||
vertical,
|
||||
box_nodes_created,
|
||||
material_charge,
|
||||
mark_cells_created,
|
||||
diagnostic_bytes,
|
||||
after_assignment,
|
||||
after_group_tokens,
|
||||
math_tokens_processed,
|
||||
native_page,
|
||||
split_discards,
|
||||
pending_shipouts,
|
||||
shipped_pages,
|
||||
job_ended,
|
||||
fresh_job,
|
||||
job_name,
|
||||
format_loaded,
|
||||
format_dumped,
|
||||
writing,
|
||||
stack_peaks,
|
||||
alignment_balance,
|
||||
],
|
||||
[
|
||||
inputs,
|
||||
sources,
|
||||
meaning_reads,
|
||||
events,
|
||||
reads_event_history,
|
||||
xdv_annotations,
|
||||
xdv_text,
|
||||
pdf_navigation_geometry,
|
||||
pdf_link_stack,
|
||||
pdf_active_thread,
|
||||
pdf_space_probe,
|
||||
pdf_images,
|
||||
paragraph,
|
||||
box_frames,
|
||||
math,
|
||||
display,
|
||||
output_frame,
|
||||
alignments,
|
||||
],
|
||||
[cancellation, line_break_cache]
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
let idle = |e: &Executor| {
|
||||
e.output_frame.is_none()
|
||||
&& e.paragraph.is_none()
|
||||
&& e.box_frames.is_empty()
|
||||
&& e.math.is_empty()
|
||||
&& e.display.is_none()
|
||||
&& e.alignments.is_empty()
|
||||
&& e.pdf_link_stack.is_empty()
|
||||
&& e.pdf_active_thread.is_none()
|
||||
&& e.pdf_space_probe.is_none()
|
||||
&& e.pdf_images.is_empty()
|
||||
&& !e.reads_event_history
|
||||
};
|
||||
if !idle(current) || !idle(prior) {
|
||||
return false;
|
||||
}
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
if current.pdf_last_match.as_deref() != prior.pdf_last_match.as_deref() {
|
||||
return false;
|
||||
}
|
||||
current
|
||||
.xdv_annotations
|
||||
.same_idle_state(&prior.xdv_annotations)
|
||||
&& current.xdv_text.same_state(&prior.xdv_text)
|
||||
&& current
|
||||
.pdf_navigation_geometry
|
||||
.same_state(&prior.pdf_navigation_geometry)
|
||||
&& current.events.len() == prior.events.len()
|
||||
&& current.meaning_reads.len() == prior.meaning_reads.len()
|
||||
&& current
|
||||
.meaning_reads
|
||||
.keys()
|
||||
.all(|name| prior.meaning_reads.contains_key(name))
|
||||
&& current.inputs.len() == prior.inputs.len()
|
||||
&& current
|
||||
.inputs
|
||||
.iter()
|
||||
.zip(&prior.inputs)
|
||||
.all(|(a, b)| a.same_at_shipout(b))
|
||||
}
|
||||
@@ -1089,6 +1089,7 @@ impl Executor {
|
||||
.map_err(|e| self.error(e, self.current))?;
|
||||
let mut shared = self.pdf_space_probe.take().unwrap_or_default();
|
||||
let prior = Arc::make_mut(&mut shared);
|
||||
self.reads_event_history = true;
|
||||
for event in self.events.iter().skip(prior.observed_events) {
|
||||
let Event::Shipout(shipped) = event else { continue };
|
||||
self.check_cancellation()?;
|
||||
|
||||
@@ -17,6 +17,13 @@ pub(super) struct NavigationGeometry {
|
||||
last_pdf_rect: [i64; 4],
|
||||
}
|
||||
|
||||
impl NavigationGeometry {
|
||||
pub(super) fn same_state(&self, other: &Self) -> bool {
|
||||
self.last_pdf_rect == other.last_pdf_rect
|
||||
&& self.matrix.map(|m| m.0.map(f64::to_bits)) == other.matrix.map(|m| m.0.map(f64::to_bits))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(super) struct ActiveLink {
|
||||
layout: LinkStart,
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::mem::MaybeUninit;
|
||||
use std::ops::Range;
|
||||
use std::ptr;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub(super) struct PdfMatch {
|
||||
input: Vec<u8>,
|
||||
captures: Vec<Option<Range<usize>>>,
|
||||
|
||||
@@ -25,6 +25,7 @@ impl Executor {
|
||||
}
|
||||
// Packing can move existing lists or replace an old register. Recount
|
||||
// actual storage here, counting each shared list allocation once.
|
||||
self.reads_event_history = true;
|
||||
let usage = self.collect_usage(shipping, None, Collector::for_capacity());
|
||||
self.material_charge = usage
|
||||
.active_material
|
||||
@@ -36,10 +37,11 @@ impl Executor {
|
||||
Ok(())
|
||||
}
|
||||
fn resource_usage(
|
||||
&self,
|
||||
&mut self,
|
||||
shipping: Option<&NativeBox>,
|
||||
host: Option<HostResourceUsage>,
|
||||
) -> ResourceUsage {
|
||||
self.reads_event_history = true;
|
||||
self.collect_usage(shipping, host, Collector::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ pub use case::CaseCode;
|
||||
pub use context::{ContextFrame, ContextKind, InputContext};
|
||||
pub use device::{NativeShipout, ShipoutDevice, ShipoutSpecial};
|
||||
pub use diagnostics::{DiagnosticBox, DiagnosticNode, ShowBoxReport};
|
||||
pub use engine::{CheckpointSource, EntryCheckpoint, Executor, Limits};
|
||||
pub use engine::{CheckpointDecision, CheckpointSource, EntryCheckpoint, Executor, Limits};
|
||||
pub use font_catalog::{
|
||||
FontCatalog, FontCharacter, FontId, FontInstance, FontLimits, FontResource,
|
||||
};
|
||||
@@ -669,6 +669,8 @@ pub struct Execution {
|
||||
pub incoming_state: u64,
|
||||
pub outgoing_state: u64,
|
||||
pub steps: usize,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
reads_event_history: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
use super::xe_encoding::{Character, Encoding};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct XePhysical {
|
||||
encoding: Encoding,
|
||||
autodetected: Option<(Encoding, usize)>,
|
||||
@@ -267,14 +267,14 @@ mod tests {
|
||||
assert_eq!(chars, "é界 B C ");
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum LineState {
|
||||
New,
|
||||
Middle,
|
||||
Skip,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
enum LineBreaks {
|
||||
Physical,
|
||||
Generated(Option<char>),
|
||||
@@ -297,6 +297,21 @@ pub(super) struct Mouth {
|
||||
}
|
||||
|
||||
impl Mouth {
|
||||
pub(super) fn same_unread_input(&self, other: &Self) -> bool {
|
||||
self.source == other.source
|
||||
&& self.profile == other.profile
|
||||
&& self.offset == other.offset
|
||||
&& self.line == other.line
|
||||
&& self.cursor == other.cursor
|
||||
&& self.state == other.state
|
||||
&& self.end_after_line == other.end_after_line
|
||||
&& self.line_breaks == other.line_breaks
|
||||
&& self.line_number == other.line_number
|
||||
&& self.xe == other.xe
|
||||
&& self.invalid_utf8 == other.invalid_utf8
|
||||
&& self.data[self.offset..] == other.data[other.offset..]
|
||||
}
|
||||
|
||||
pub(super) fn physical_frontier(&self) -> Option<usize> {
|
||||
(matches!(self.line_breaks, LineBreaks::Physical) && !self.end_after_line && self.offset > 0)
|
||||
.then_some(self.offset)
|
||||
|
||||
@@ -196,7 +196,7 @@ impl RevisionJob {
|
||||
.map_err(|failure| failure.error)
|
||||
}
|
||||
pub fn run_detailed(
|
||||
self,
|
||||
&self,
|
||||
executor: Executor,
|
||||
source: SourceFile,
|
||||
files: &mut impl SourceProvider,
|
||||
@@ -224,7 +224,7 @@ impl RevisionJob {
|
||||
|
||||
/// Capture selected physical source continuations, including child input.
|
||||
pub fn run_capturing_sources<F: SourceProvider, S>(
|
||||
self,
|
||||
&self,
|
||||
executor: Executor,
|
||||
source: SourceFile,
|
||||
files: &mut F,
|
||||
@@ -240,7 +240,7 @@ impl RevisionJob {
|
||||
/// Resume after the host has validated prefix dependencies and replayed
|
||||
/// their effects into the new revision's isolated file host.
|
||||
pub fn resume_entry_after_host_replay(
|
||||
self,
|
||||
&self,
|
||||
checkpoint: &EntryCheckpoint,
|
||||
source: SourceFile,
|
||||
files: &mut impl SourceProvider,
|
||||
@@ -270,7 +270,7 @@ impl RevisionJob {
|
||||
}
|
||||
|
||||
pub fn resume_capturing_sources_after_host_replay<F: SourceProvider, S>(
|
||||
self,
|
||||
&self,
|
||||
checkpoint: &EntryCheckpoint,
|
||||
source: SourceFile,
|
||||
nested: Option<SourceFile>,
|
||||
@@ -293,10 +293,31 @@ impl RevisionJob {
|
||||
Some(self.finish_execution(executed, files, previous.as_deref()))
|
||||
}
|
||||
|
||||
/// Resume normally unless the caller verifies and replays a matching suffix.
|
||||
/// A rejected replay leaves publication untouched, so the caller can discard
|
||||
/// the draft and execute again under the same revision.
|
||||
pub fn resume_deciding_suffix<F: SourceProvider, S>(
|
||||
&self,
|
||||
checkpoint: &EntryCheckpoint,
|
||||
source: SourceFile,
|
||||
nested: Option<SourceFile>,
|
||||
files: &mut F,
|
||||
line_break_cache: Arc<LineBreakCache>,
|
||||
select: impl FnMut(super::CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> super::CheckpointDecision,
|
||||
) -> Result<Option<Result<Arc<RevisionExecution>, RevisionFailure>>, String> {
|
||||
let previous = self.session.latest();
|
||||
let executed = checkpoint.resume_deciding_suffix(
|
||||
source, nested, files, self.cancellation.clone(), line_break_cache,
|
||||
previous.as_deref().map(|item| &item.execution), select, capture,
|
||||
)?;
|
||||
Ok(executed.map(|result| self.finish_execution(result, files, previous.as_deref())))
|
||||
}
|
||||
|
||||
/// Publish a completed result after the caller verifies the same inputs
|
||||
/// and replays every host call into the current revision's draft.
|
||||
pub fn reuse_completed_after_host_replay(
|
||||
self,
|
||||
&self,
|
||||
completed: &RevisionExecution,
|
||||
files: &impl SourceProvider,
|
||||
) -> Result<Arc<RevisionExecution>, RevisionFailure> {
|
||||
@@ -304,7 +325,7 @@ impl RevisionJob {
|
||||
}
|
||||
|
||||
fn finish_execution(
|
||||
self,
|
||||
&self,
|
||||
executed: Result<Execution, ExecutionFailure>,
|
||||
files: &impl SourceProvider,
|
||||
previous: Option<&RevisionExecution>,
|
||||
|
||||
@@ -63,7 +63,7 @@ impl XeLineFraming {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) struct Character {
|
||||
pub value: char,
|
||||
pub start: usize,
|
||||
|
||||
Reference in new issue
Block a user