294 lines
9.7 KiB
Rust
294 lines
9.7 KiB
Rust
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()..)?;
|
|
if completed.accounts_event_history && !current.equivalent_accounting_history(old) {
|
|
return None;
|
|
}
|
|
// The joined events are published results. Resumption always starts
|
|
// from a live checkpoint, whose original shared allocations stay intact.
|
|
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,
|
|
accounts_event_history: completed.accounts_event_history,
|
|
})
|
|
}
|
|
}
|
|
|
|
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,
|
|
accounts_event_history,
|
|
],
|
|
[
|
|
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))
|
|
}
|