Relocate source provenance when native suffixes move
This commit is contained in:
1 parent
6acd82dbfa
commit
41a459b4ca
16 files changed
+1507
-79
No files matched your search
@@ -1,9 +1,11 @@
|
||||
use super::super::source_relocation::SourceRelocation;
|
||||
use super::*;
|
||||
mod material;
|
||||
mod relocate;
|
||||
use material::MaterialReuse;
|
||||
|
||||
impl InputFrame {
|
||||
fn same_at_shipout(&self, other: &Self) -> bool {
|
||||
fn same_at_shipout(&self, other: &Self, relocation: Option<&SourceRelocation>) -> bool {
|
||||
match (self, other) {
|
||||
(
|
||||
Self::Source {
|
||||
@@ -22,7 +24,11 @@ impl InputFrame {
|
||||
group_boundary: bg,
|
||||
conditional_boundary: bc,
|
||||
},
|
||||
) => (a, ae, at, ag, ac) == (b, be, bt, bg, bc) && am.same_unread_input(bm),
|
||||
) => (a, ae, at, ag, ac) == (b, be, bt, bg, bc)
|
||||
&& match relocation.filter(|map| map.source() == *a) {
|
||||
Some(map) => am.same_unread_input_relocated(bm, map),
|
||||
None => am.same_unread_input(bm),
|
||||
},
|
||||
(
|
||||
Self::Tokens {
|
||||
tokens: a,
|
||||
@@ -90,7 +96,6 @@ impl EntryCheckpoint {
|
||||
|| 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
|
||||
@@ -101,9 +106,6 @@ impl EntryCheckpoint {
|
||||
}
|
||||
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
|
||||
@@ -112,7 +114,7 @@ impl EntryCheckpoint {
|
||||
.enumerate()
|
||||
.any(|(id, (new, old))| {
|
||||
if id == self.entry {
|
||||
new.name != old.name || new.data.len() != old.data.len()
|
||||
new.name != old.name
|
||||
} else {
|
||||
new != old
|
||||
}
|
||||
@@ -121,6 +123,24 @@ impl EntryCheckpoint {
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let previous_bytes = &old.sources[self.entry].data;
|
||||
let current_bytes = ¤t.sources[self.entry].data;
|
||||
let entry_sizes = (previous_bytes.len() != current_bytes.len())
|
||||
.then_some((previous_bytes.len(), current_bytes.len()));
|
||||
let relocation = match entry_sizes {
|
||||
Some(_) => {
|
||||
let map = SourceRelocation::new(self.entry, previous_bytes, current_bytes)?;
|
||||
if map.relocate_offset(prior.frontier) != Some(self.frontier) {
|
||||
return None;
|
||||
}
|
||||
Some(map)
|
||||
}
|
||||
None if self.frontier == prior.frontier => None,
|
||||
None => return None,
|
||||
};
|
||||
if !same_kernel_continuation(current, old, relocation.as_ref()) {
|
||||
return None;
|
||||
}
|
||||
let offset = StepOffset::new(old.steps, current.steps);
|
||||
let steps = offset.apply(completed.steps)?;
|
||||
// Kernel work only advances the step counter. A successful suffix
|
||||
@@ -131,20 +151,14 @@ impl EntryCheckpoint {
|
||||
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) {
|
||||
if completed.accounts_event_history
|
||||
&& !current.equivalent_accounting_history_with_entry_sizes(old, entry_sizes)
|
||||
{
|
||||
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();
|
||||
if offset.is_identity() {
|
||||
events.extend_from_slice(tail);
|
||||
} else {
|
||||
for event in tail {
|
||||
events.push(offset_event_steps(event, offset)?);
|
||||
}
|
||||
}
|
||||
Some(Execution {
|
||||
let mut execution = Execution {
|
||||
format_dumped: completed.format_dumped,
|
||||
format_pdf_images: completed.format_pdf_images.clone(),
|
||||
job_name: completed.job_name.clone(),
|
||||
@@ -152,7 +166,7 @@ impl EntryCheckpoint {
|
||||
native_page: completed.native_page.clone(),
|
||||
split_discards: completed.split_discards.clone(),
|
||||
after_assignment: completed.after_assignment.clone(),
|
||||
events,
|
||||
events: current.events.clone().into_vec(),
|
||||
state: completed.state.clone(),
|
||||
io: completed.io.clone(),
|
||||
input_position: completed.input_position,
|
||||
@@ -166,7 +180,17 @@ impl EntryCheckpoint {
|
||||
steps,
|
||||
reads_event_history: false,
|
||||
accounts_event_history: completed.accounts_event_history,
|
||||
})
|
||||
};
|
||||
if let Some((map, sizes)) = relocation.as_ref().zip(entry_sizes) {
|
||||
relocate::append_suffix(&mut execution, tail, offset, map, sizes, old.sources.len())?;
|
||||
} else if offset.is_identity() {
|
||||
execution.events.extend_from_slice(tail);
|
||||
} else {
|
||||
for event in tail {
|
||||
execution.events.push(offset_event_steps(event, offset)?);
|
||||
}
|
||||
}
|
||||
Some(execution)
|
||||
}
|
||||
/// Carry later checkpoints from the suffix accepted by
|
||||
/// splice_settled_suffix into this revision. The host must still replay
|
||||
@@ -176,6 +200,12 @@ impl EntryCheckpoint {
|
||||
prior: &'a Self,
|
||||
completed: &Execution,
|
||||
) -> Option<impl FnMut(&Self) -> Option<Self> + 'a> {
|
||||
// A carried executor still contains scanner positions from the old source.
|
||||
if self.executor.sources[self.entry].data.len()
|
||||
!= prior.executor.sources[prior.entry].data.len()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
// A restored checkpoint may later be asked to account for its
|
||||
// history, even if the job that furnished the suffix did not.
|
||||
if !completed.accounts_event_history
|
||||
@@ -306,7 +336,11 @@ fn is_idle_continuation(e: &Executor) -> bool {
|
||||
&& !e.reads_event_history
|
||||
}
|
||||
|
||||
fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
fn same_kernel_continuation(
|
||||
current: &Executor,
|
||||
prior: &Executor,
|
||||
relocation: Option<&SourceRelocation>,
|
||||
) -> 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 {
|
||||
@@ -321,20 +355,19 @@ fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
true $(&& *$value == prior.$value)+
|
||||
}};
|
||||
}
|
||||
if !is_idle_continuation(current) || !is_idle_continuation(prior) {
|
||||
return false;
|
||||
}
|
||||
if !same_values!(
|
||||
[
|
||||
state,
|
||||
limits,
|
||||
interaction_mode,
|
||||
stream_sources,
|
||||
generated_inputs,
|
||||
reads,
|
||||
reads_tracing_macros,
|
||||
conditionals,
|
||||
in_csname,
|
||||
command_trace_mode,
|
||||
ligature_carry,
|
||||
current,
|
||||
expression_depth,
|
||||
scanner_depth,
|
||||
scanner_status,
|
||||
@@ -347,25 +380,17 @@ fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
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,
|
||||
@@ -378,6 +403,18 @@ fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
accounts_event_history,
|
||||
],
|
||||
[
|
||||
state,
|
||||
generated_inputs,
|
||||
conditionals,
|
||||
current,
|
||||
pdf_catalog_tokens,
|
||||
pdf_outlines,
|
||||
pdf_info_tokens,
|
||||
vertical,
|
||||
after_assignment,
|
||||
native_page,
|
||||
split_discards,
|
||||
pending_shipouts,
|
||||
inputs,
|
||||
sources,
|
||||
steps,
|
||||
@@ -402,30 +439,49 @@ fn same_kernel_continuation(current: &Executor, prior: &Executor) -> bool {
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if !is_idle_continuation(current) || !is_idle_continuation(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)
|
||||
if 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()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let relocated;
|
||||
let prior = if let Some(map) = relocation {
|
||||
relocated = match relocate::kernel_continuation(prior, map) {
|
||||
Some(executor) => executor,
|
||||
None => return false,
|
||||
};
|
||||
&relocated
|
||||
} else {
|
||||
prior
|
||||
};
|
||||
current.state == prior.state
|
||||
&& current.generated_inputs == prior.generated_inputs
|
||||
&& current.conditionals == prior.conditionals
|
||||
&& current.current == prior.current
|
||||
&& current.pdf_catalog_tokens == prior.pdf_catalog_tokens
|
||||
&& current.pdf_outlines == prior.pdf_outlines
|
||||
&& current.pdf_info_tokens == prior.pdf_info_tokens
|
||||
&& current.vertical == prior.vertical
|
||||
&& current.after_assignment == prior.after_assignment
|
||||
&& current.native_page == prior.native_page
|
||||
&& current.split_discards == prior.split_discards
|
||||
&& current.pending_shipouts == prior.pending_shipouts
|
||||
&& 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))
|
||||
.all(|(a, b)| a.same_at_shipout(b, relocation))
|
||||
}
|
||||
Reference in new issue
Block a user