Preserve read evidence and box accounting in settled suffix reuse
This commit is contained in:
1 parent
473b3beace
commit
f78aff25c5
12 files changed
+381
-46
No files matched your search
@@ -1762,6 +1762,106 @@ fn settled_suffix_carries_a_verified_prefix_into_later_edits() {
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_keeps_new_prefix_reads_but_rejects_missing_reads() {
|
||||
use texrra_tex_core::execution::Dependency;
|
||||
|
||||
let cwd = directory("settled-prefix-dependencies");
|
||||
let entry = cwd.join("main.tex");
|
||||
let body = |ignored| format!(r"
|
||||
\catcode64=9 \catcode63=9
|
||||
?\relax
|
||||
\shipout\hbox{{Cover}}\relax
|
||||
{ignored}\relax
|
||||
\shipout\hbox{{Checkpoint}}\relax
|
||||
\shipout\hbox{{Suffix}}\relax
|
||||
\endinput\shipout\hbox{{Final}}\relax\end
|
||||
");
|
||||
for (before, after, reuse) in [('?', '@', true), ('@', '?', false)] {
|
||||
let project = ProjectSnapshot::new(atomic_definition(&cwd, 1, &body(before))).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let donor = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let new_read = Dependency::CatCode('@');
|
||||
assert_eq!(donor.execution.execution.reads.contains(&new_read), before == '@');
|
||||
let source = format!("{HEADER}{}", body(after));
|
||||
let project = project.with_file_edits(
|
||||
2, [(entry.clone(), Arc::from(source.into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let input = request.with_project(project);
|
||||
let updated = session.compile(input.clone()).unwrap();
|
||||
let work = &updated.entry_checkpoint_work;
|
||||
assert!(!work.reused_completion, "{work:?}");
|
||||
assert_eq!(work.reused_suffix_steps > 0, reuse, "{work:?}");
|
||||
assert_eq!(updated.execution.execution.reads.contains(&new_read), after == '@');
|
||||
let log = fs::read(cwd.join("job.log")).unwrap();
|
||||
let full = NativeCompiler::default().compile(input).unwrap();
|
||||
assert_eq!(updated.execution.execution, full.execution.execution);
|
||||
assert_eq!(updated.pdf, full.pdf);
|
||||
assert_eq!(updated.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(log, fs::read(cwd.join("job.log")).unwrap());
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_translates_cumulative_box_charges_in_both_directions() {
|
||||
use texrra_tex_core::execution::{Event, StatisticsPhase};
|
||||
|
||||
let cwd = directory("settled-box-charge");
|
||||
let entry = cwd.join("main.tex");
|
||||
let body = |variant| format!(r"
|
||||
\tracingstats=2
|
||||
\setbox0=\vbox{{\kern1sp\kern2sp}}
|
||||
\def\variantA{{\relax}}
|
||||
\def\variantB{{\setbox7=\copy0\setbox7=\box9\relax}}
|
||||
\variantA\variantB\relax
|
||||
\shipout\hbox{{Cover}}\relax
|
||||
\variant{variant}\relax
|
||||
\shipout\hbox{{Checkpoint}}\relax
|
||||
\shipout\hbox{{Suffix}}\relax
|
||||
\endinput\shipout\hbox{{Final}}\relax\end
|
||||
");
|
||||
let final_charge = |document: &CompiledDocument| {
|
||||
let Some(Event::Statistics(report)) = document.execution.execution.events.last() else {
|
||||
panic!("missing final resource report");
|
||||
};
|
||||
let StatisticsPhase::End { usage, .. } = &report.phase else {
|
||||
panic!("expected final resource report");
|
||||
};
|
||||
usage.box_nodes_created
|
||||
};
|
||||
|
||||
for (before, after) in [('A', 'B'), ('B', 'A')] {
|
||||
let project = ProjectSnapshot::new(atomic_definition(&cwd, 1, &body(before))).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let donor = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let source = format!("{HEADER}{}", body(after));
|
||||
let project = project.with_file_edits(
|
||||
2, [(entry.clone(), Arc::from(source.into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let input = request.with_project(project);
|
||||
let updated = session.compile(input.clone()).unwrap();
|
||||
let work = &updated.entry_checkpoint_work;
|
||||
assert!(!work.reused_completion && work.reused_suffix_steps > 0, "{work:?}");
|
||||
if after == 'B' {
|
||||
assert!(final_charge(&updated) > final_charge(&donor));
|
||||
} else {
|
||||
assert!(final_charge(&updated) < final_charge(&donor));
|
||||
}
|
||||
let log = fs::read(cwd.join("job.log")).unwrap();
|
||||
let full = NativeCompiler::default().compile(input).unwrap();
|
||||
assert_eq!(updated.execution.execution, full.execution.execution);
|
||||
assert_eq!(updated.resources.trace, full.resources.trace);
|
||||
assert_eq!(updated.pdf, full.pdf);
|
||||
assert_eq!(log, fs::read(cwd.join("job.log")).unwrap());
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resized_entry_prefix_reuses_verified_statistics() {
|
||||
let cwd = directory("resized-entry-statistics");
|
||||
|
||||
Reference in new issue
Block a user