Defer child replay accounting and reuse verified macro aliases
This commit is contained in:
1 parent
64adf51b20
commit
d98d7b44c1
10 files changed
+364
-33
No files matched your search
@@ -2944,6 +2944,143 @@ fn child_segments_reuse_only_after_live_state_and_inputs_converge() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deferred_child_accounting_revalidates_before_statistics_or_capacity() {
|
||||
struct PublishedAux {
|
||||
path: PathBuf,
|
||||
bytes: Vec<u8>,
|
||||
checks: AtomicU64,
|
||||
}
|
||||
|
||||
impl CompileObserver for PublishedAux {
|
||||
fn stage(&self, _revision: u64, stage: CompileStage) -> Result<(), String> {
|
||||
if matches!(stage, CompileStage::Prepared | CompileStage::Executed) {
|
||||
assert_eq!(fs::read(&self.path).unwrap(), self.bytes);
|
||||
self.checks.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
for (label, form, capacity) in [
|
||||
("verified-statistics", false, false),
|
||||
("retried-statistics", true, false),
|
||||
("retried-capacity", true, true),
|
||||
] {
|
||||
let root = directory(label).canonicalize().unwrap();
|
||||
let entry = root.join("main.tex");
|
||||
let child = root.join("child.tex");
|
||||
let aux = root.join("child.aux");
|
||||
let mut world = WorldConfig::new(&root);
|
||||
world.input_policy = texrra_tex_core::resources::InputPolicy::Tex;
|
||||
let register_form = if form { r"\setbox0=\hbox{\vrule width2pt height1pt}\pdfxform0\relax" } else { "" };
|
||||
let form_ref = if form { r"\pdfrefxform\pdflastxform" } else { "" };
|
||||
let main = format!(
|
||||
r"\catcode123=1 \catcode125=2
|
||||
\pdfoutput=1 {register_form}
|
||||
\def\material{{\setbox1=\hbox{{\vrule width1pt height1pt}}}}
|
||||
\def\repeatmaterial{{\material\ifnum\count1<300
|
||||
\advance\count1 by 1\relax\expandafter\repeatmaterial\fi}}
|
||||
\begingroup\edef\measured{{\pdffilesize{{child.tex}}}}
|
||||
\ifnum\measured>0 \relax\else\errmessage{{empty child}}\fi\endgroup
|
||||
\input child.tex
|
||||
\immediate\openout3=child.aux
|
||||
\immediate\write3{{\the\count0}}\immediate\closeout3
|
||||
\shipout\hbox{{{form_ref}\vrule width\count0 pt height2pt}}\end
|
||||
"
|
||||
);
|
||||
let middle = "\\advance\\count0 by 1\\relax\n".repeat(160);
|
||||
let prefix = format!("\\relax{{}}\n{middle}");
|
||||
let tail = "\\tracingstats=0\\relax\\ifnum0=1 \\repeatmaterial\\fi\n";
|
||||
let original = format!("{prefix}{tail}");
|
||||
let grown = format!("{prefix}{tail}\\advance\\count0 by 2\\relax\n");
|
||||
let observed = if capacity {
|
||||
grown.replace("\\ifnum0=1", "\\ifnum1=1")
|
||||
} else {
|
||||
grown.replace("\\tracingstats=0", "\\tracingstats=1")
|
||||
}
|
||||
.replace("\\count0 by 2", "\\count0 by 3");
|
||||
assert_eq!(grown.len(), observed.len());
|
||||
let mut project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: [root.clone()].into(),
|
||||
files: [
|
||||
(entry, Arc::from(main.into_bytes())),
|
||||
(child.clone(), Arc::from(original.into_bytes())),
|
||||
]
|
||||
.into(),
|
||||
directories: Default::default(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [root.clone()].into(),
|
||||
generated: [aux.clone()].into(),
|
||||
})
|
||||
.unwrap();
|
||||
let mut request = CompileRequest::new(
|
||||
world,
|
||||
"main.tex",
|
||||
"job.pdf",
|
||||
JobTime::new(2026, 11, 29, 0)
|
||||
.unwrap()
|
||||
.with_pdf_clock(0, 0)
|
||||
.unwrap(),
|
||||
)
|
||||
.observe_generated_initial();
|
||||
request.entry = Entry::Initex;
|
||||
request.etex = true;
|
||||
if capacity {
|
||||
request.limits.tokens = 250;
|
||||
}
|
||||
let seed = request.clone().with_project(project.clone());
|
||||
NativeCompiler::default().compile(seed.clone()).unwrap();
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
session.compile(seed).unwrap();
|
||||
project = project
|
||||
.with_file_edits(2, [(child.clone(), Arc::from(grown.into_bytes()))].into())
|
||||
.unwrap();
|
||||
let grown = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
assert!(grown.entry_checkpoint_work.reused_suffix_steps > 500, "{label}: {:?}", grown.entry_checkpoint_work);
|
||||
let initial_aux = fs::read(&aux).unwrap();
|
||||
assert_eq!(initial_aux, b"162\n");
|
||||
let observer = Arc::new(PublishedAux {
|
||||
path: aux.clone(),
|
||||
bytes: initial_aux.clone(),
|
||||
checks: AtomicU64::new(0),
|
||||
});
|
||||
|
||||
project = project
|
||||
.with_file_edits(3, [(child.clone(), Arc::from(observed.into_bytes()))].into())
|
||||
.unwrap();
|
||||
let request = request.with_project(project);
|
||||
let mut watched = request.clone();
|
||||
watched.observer = Some(observer.clone());
|
||||
let edited = session.compile(watched).unwrap();
|
||||
let work = &edited.entry_checkpoint_work;
|
||||
assert_eq!(observer.checks.load(Ordering::Relaxed), 2, "{label}: {work:?}");
|
||||
if form {
|
||||
assert_eq!(work.rejection.as_deref(), Some("child continuation accounting differs"), "{work:?}");
|
||||
assert!(work.discarded_suffix_attempt_steps > 0, "{work:?}");
|
||||
} else {
|
||||
assert!(work.rejection.is_none(), "{work:?}");
|
||||
assert_eq!(work.reused_source.as_deref(), Some(child.as_path()));
|
||||
assert!(work.reused_frontier.unwrap() > 1000, "{work:?}");
|
||||
}
|
||||
|
||||
let out_aux = fs::read(&aux).unwrap();
|
||||
assert_eq!(out_aux, b"163\n");
|
||||
fs::write(&aux, initial_aux).unwrap();
|
||||
let full = NativeCompiler::default().compile(request).unwrap();
|
||||
assert_eq!(fs::read(&aux).unwrap(), out_aux);
|
||||
assert_eq!(edited.pdf, full.pdf, "{label}");
|
||||
assert_eq!(edited.execution.execution, full.execution.execution, "{label}");
|
||||
assert_eq!(edited.source_map.pages, full.source_map.pages, "{label}");
|
||||
assert_eq!(edited.source_map.sources, full.source_map.sources, "{label}");
|
||||
assert_eq!(edited.resources.trace.reads, full.resources.trace.reads, "{label}");
|
||||
assert_eq!(edited.resources.trace.lookups, full.resources.trace.lookups, "{label}");
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replay_rejection_resumes_earlier_without_publishing_rejected_effects() {
|
||||
struct PublishedBeforeExecution(Vec<(PathBuf, Vec<u8>)>);
|
||||
|
||||
Reference in new issue
Block a user