Prove suffix reuse across unequal retained histories
This commit is contained in:
1 parent
f78aff25c5
commit
1ff049737f
9 files changed
+781
-153
No files matched your search
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use hashbrown::{HashMap, hash_map::RawEntryMut};
|
||||
|
||||
use super::dependency_reads::DependencyEvidence;
|
||||
use super::job::InputStream;
|
||||
use super::mouth::Mouth;
|
||||
use super::state::{GroupKind, Key, Replacement, command_hasher};
|
||||
@@ -238,9 +239,9 @@ pub struct Executor {
|
||||
stream_sources: BTreeSet<usize>,
|
||||
generated_inputs: std::collections::BTreeMap<usize, GeneratedInput>,
|
||||
reads: DependencyReads,
|
||||
// Cache the resolved meaning alongside the already required read evidence.
|
||||
// A shard's revision is only valid on this executor's state history.
|
||||
meaning_reads: HashMap<CommandName, (u64, Meaning), RandomState>,
|
||||
// Cache the resolved meaning alongside the last read epoch. A shard's
|
||||
// revision is only valid on this executor's state history.
|
||||
meaning_reads: HashMap<CommandName, (u64, Meaning, u32), RandomState>,
|
||||
reads_tracing_macros: bool,
|
||||
conditionals: Vec<Conditional>,
|
||||
in_csname: bool,
|
||||
@@ -501,6 +502,7 @@ impl EntryCheckpoint {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut executor = self.executor.clone().with_cancellation(cancellation);
|
||||
executor.reads.advance_epoch();
|
||||
executor.line_break_cache = line_break_cache;
|
||||
let previous_len = self.executor.sources[self.entry].data.len();
|
||||
let current_len = source.data.len();
|
||||
@@ -821,10 +823,14 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn take_dependency_reads(&mut self) -> BTreeSet<Dependency> {
|
||||
let mut reads = std::mem::take(&mut self.reads).into_ordered();
|
||||
reads.extend(self.meaning_reads.drain().map(|(name, _)| Dependency::Meaning(name)));
|
||||
reads
|
||||
fn dependency_observations(&self) -> impl Iterator<Item = (Dependency, u32)> + '_ {
|
||||
self.reads.observations().chain(self.meaning_reads.iter()
|
||||
.map(|(name, (_, _, epoch))| (Dependency::Meaning(name.clone()), *epoch)))
|
||||
}
|
||||
|
||||
fn take_dependency_reads(&mut self) -> (BTreeSet<Dependency>, DependencyEvidence) {
|
||||
std::mem::take(&mut self.reads).into_evidence(self.meaning_reads.drain()
|
||||
.map(|(name, (_, _, epoch))| (Dependency::Meaning(name), epoch)))
|
||||
}
|
||||
|
||||
fn meaning(&mut self, token: &Token) -> Meaning {
|
||||
@@ -836,9 +842,11 @@ impl Executor {
|
||||
fn lookup_meaning(&mut self, name: &CommandName) -> Meaning {
|
||||
let hash = self.meaning_reads.hasher().hash_one(name);
|
||||
let revision = self.state.command_revision(hash);
|
||||
let epoch = self.reads.current_epoch;
|
||||
match self.meaning_reads.raw_entry_mut().from_key_hashed_nocheck(hash, name) {
|
||||
RawEntryMut::Occupied(mut entry) => {
|
||||
let (cached_revision, meaning) = entry.get_mut();
|
||||
let (cached_revision, meaning, last_read) = entry.get_mut();
|
||||
*last_read = epoch;
|
||||
if *cached_revision != revision {
|
||||
*meaning = self.state.meaning_hashed(name, hash);
|
||||
*cached_revision = revision;
|
||||
@@ -847,7 +855,7 @@ impl Executor {
|
||||
}
|
||||
RawEntryMut::Vacant(entry) => {
|
||||
let meaning = self.state.meaning_hashed(name, hash);
|
||||
entry.insert_hashed_nocheck(hash, name.clone(), (revision, meaning.clone()));
|
||||
entry.insert_hashed_nocheck(hash, name.clone(), (revision, meaning.clone(), epoch));
|
||||
meaning
|
||||
}
|
||||
}
|
||||
@@ -3567,7 +3575,7 @@ impl Executor {
|
||||
for node in nodes {
|
||||
self.output_node(node, files)?;
|
||||
}
|
||||
let reads = self.take_dependency_reads();
|
||||
let (reads, dependency_evidence) = self.take_dependency_reads();
|
||||
let format_pdf_images = self.captured_format_pdf_images();
|
||||
Ok(Execution {
|
||||
format_dumped: self.format_dumped,
|
||||
@@ -3591,6 +3599,7 @@ impl Executor {
|
||||
stream_sources: self.stream_sources,
|
||||
generated_inputs: self.generated_inputs,
|
||||
reads,
|
||||
dependency_evidence,
|
||||
line_observations: Some(self.line_observations),
|
||||
events: self.events.into_vec(),
|
||||
steps: self.steps,
|
||||
@@ -4008,6 +4017,9 @@ impl Executor {
|
||||
}
|
||||
engine.events.seal_prefix();
|
||||
let mut executor = engine.clone();
|
||||
// Any subsequent read belongs to the suffix, even if it
|
||||
// happens before the next logical TeX execution step.
|
||||
engine.reads.advance_epoch();
|
||||
executor.cancellation = None;
|
||||
executor.line_break_cache = None;
|
||||
let checkpoint = EntryCheckpoint {
|
||||
@@ -4028,7 +4040,7 @@ impl Executor {
|
||||
incoming_state: u64,
|
||||
previous: Option<&Execution>,
|
||||
) -> Result<Execution, ExecutionFailure> {
|
||||
let reads = self.take_dependency_reads();
|
||||
let (reads, dependency_evidence) = self.take_dependency_reads();
|
||||
let result = result.and_then(|()| {
|
||||
if self.shipped_pages > 0 && !self.format_dumped
|
||||
&& let Some(objects) = self.state.pdf_objects.as_deref_mut()
|
||||
@@ -4098,6 +4110,7 @@ impl Executor {
|
||||
stream_sources: self.stream_sources,
|
||||
generated_inputs: self.generated_inputs,
|
||||
reads,
|
||||
dependency_evidence,
|
||||
line_observations: Some(self.line_observations),
|
||||
incoming_state,
|
||||
steps: self.steps,
|
||||
@@ -5275,3 +5288,19 @@ impl Executor {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cached_meaning_reads_are_observed_again_after_a_capture() {
|
||||
let name = CommandName::Control("relax".into());
|
||||
let read = Dependency::Meaning(name.clone());
|
||||
let mut executor = Executor::new(State::default(), Limits::default());
|
||||
executor.reads.insert(read.clone());
|
||||
assert_eq!(executor.lookup_meaning(&name), Meaning::Primitive(Primitive::Relax));
|
||||
let boundary_epoch = executor.reads.epoch().unwrap();
|
||||
executor.reads.advance_epoch();
|
||||
assert_eq!(executor.lookup_meaning(&name), Meaning::Primitive(Primitive::Relax));
|
||||
|
||||
let (reads, evidence) = executor.take_dependency_reads();
|
||||
assert_eq!(reads, BTreeSet::from([read]));
|
||||
assert_eq!(evidence.epochs().unwrap(), [boundary_epoch + 1]);
|
||||
}
|
||||
Reference in new issue
Block a user