Reuse cached layouts for relocated native shipouts
This commit is contained in:
1 parent
41a459b4ca
commit
57c05d9635
8 files changed
+394
-26
No files matched your search
@@ -1872,10 +1872,10 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let mut previous = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
|
||||
for (revision, letter, note) in [(2, 'B', "expanded comment"), (3, 'C', "x")] {
|
||||
// Only the current document can donate the suffix in either direction.
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let previous = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let source = format!("{HEADER}{}", body(letter, note, tail_query));
|
||||
let tail_offset = source.find("Suffix glyphs").unwrap();
|
||||
let bytes = i32::try_from(source.len()).unwrap();
|
||||
@@ -1886,9 +1886,16 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
let updated = session.compile(job.clone()).unwrap();
|
||||
let work = &updated.entry_checkpoint_work;
|
||||
assert_eq!(work.reused_suffix_steps > 0, tail_query.is_empty(), "{work:?}");
|
||||
if !tail_query.is_empty() {
|
||||
let layout = &updated.shipout_layout_work;
|
||||
if tail_query.is_empty() {
|
||||
// The cover and both pages in the accepted tail reuse local layout.
|
||||
assert!(layout.reused_pages >= 3, "{work:?} {layout:?}");
|
||||
} else {
|
||||
// Only the cover can use its original source coordinates.
|
||||
assert_eq!(layout.reused_pages, 1, "{work:?} {layout:?}");
|
||||
assert_eq!(updated.execution.execution.state.count(42), bytes);
|
||||
}
|
||||
assert_eq!(layout.lowered_pages + layout.reused_pages, 5);
|
||||
let preview = updated.preview_since(Some(previous.revision())).unwrap();
|
||||
assert_eq!(preview.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [1]);
|
||||
assert!(updated.source_map.pages[3].entries.iter().any(|glyph| {
|
||||
@@ -1905,12 +1912,75 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
assert_eq!(updated.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(updated.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(log, fs::read(cwd.join("job.log")).unwrap());
|
||||
previous = updated;
|
||||
}
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relocated_suffix_cannot_reuse_layouts_from_a_different_donor() {
|
||||
let cwd = directory("relocated-suffix-older-donor");
|
||||
let entry = cwd.join("main.tex");
|
||||
let middle = "\\shipout\\hbox{Middle}\\relax\n".repeat(5);
|
||||
let body = |early, early_comment, late, late_comment| format!(r"
|
||||
\tracingstats=2
|
||||
\shipout\hbox{{Cover ABCXYZ}}
|
||||
\setbox3=\hbox{{{early}}}\relax%{early_comment}
|
||||
\shipout\box3
|
||||
\relax
|
||||
{middle}\setbox3=\hbox{{{late}}}\relax%{late_comment}
|
||||
\shipout\box3
|
||||
\relax
|
||||
\shipout\hbox{{Checkpoint}}\relax
|
||||
\shipout\hbox{{Suffix glyphs}}\relax
|
||||
\shipout\hbox{{Final}}\relax
|
||||
\end
|
||||
");
|
||||
let original = body('A', "early", 'X', "late");
|
||||
let mut project = ProjectSnapshot::new(atomic_definition(&cwd, 1, &original)).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
|
||||
let early_edit = body('B', "expanded early comment", 'X', "late");
|
||||
project = project.with_file_edits(
|
||||
2, [(entry.clone(), Arc::from(format!("{HEADER}{early_edit}").into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let latest = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let first_work = &latest.entry_checkpoint_work;
|
||||
assert!(first_work.reused_suffix_steps > 0, "{first_work:?}");
|
||||
|
||||
// Relative to the latest layout this changes two lines. Only the older
|
||||
// execution, which differs on the late line alone, can donate the suffix.
|
||||
let late_edit = body('A', "early", 'Y', "x");
|
||||
project = project.with_file_edits(
|
||||
3, [(entry, Arc::from(format!("{HEADER}{late_edit}").into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let job = request.with_project(project);
|
||||
let updated = session.compile(job.clone()).unwrap();
|
||||
let work = &updated.entry_checkpoint_work;
|
||||
let layout = &updated.shipout_layout_work;
|
||||
assert!(work.reused_suffix_steps > 0, "{work:?}");
|
||||
assert_eq!(layout.reused_pages, 1, "{work:?} {layout:?}");
|
||||
assert_eq!(layout.lowered_pages, updated.pages.len() - 1);
|
||||
let changed: Vec<_> = updated.preview_since(Some(latest.revision())).unwrap()
|
||||
.pages.into_iter().map(|page| page.index).collect();
|
||||
assert_eq!(changed, [1, 7]);
|
||||
|
||||
let log = fs::read(cwd.join("job.log")).unwrap();
|
||||
let full = NativeCompiler::default().compile(job).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!(updated.pages, full.pages);
|
||||
assert_eq!(updated.preview_since(None).unwrap().pages, full.preview_since(None).unwrap().pages);
|
||||
assert_eq!(updated.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(updated.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(log, fs::read(cwd.join("job.log")).unwrap());
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_translates_step_counts_and_enforces_the_limit() {
|
||||
let cwd = directory("settled-step-counts");
|
||||
|
||||
Reference in new issue
Block a user