Verify retained TeX accounting before reusing executed suffixes

This commit is contained in:
gloamxun committed 2026-11-29 08:23:58 +08:00
1 parent 0117449023
commit 57ce7116ad
8 files changed
+236 -15

No files matched your search

@@ -25,7 +25,7 @@ impl Executor {
}
// Packing can move existing lists or replace an old register. Recount
// actual storage here, counting each shared list allocation once.
self.reads_event_history = true;
self.accounts_event_history = true;
let usage = self.collect_usage(shipping, None, Collector::for_capacity());
self.material_charge = usage
.active_material
@@ -41,7 +41,7 @@ impl Executor {
shipping: Option<&NativeBox>,
host: Option<HostResourceUsage>,
) -> ResourceUsage {
self.reads_event_history = true;
self.accounts_event_history = true;
self.collect_usage(shipping, host, Collector::default())
}
@@ -49,8 +49,19 @@ impl Executor {
&self,
shipping: Option<&NativeBox>,
host: Option<HostResourceUsage>,
mut c: Collector,
c: Collector,
) -> ResourceUsage {
let mut c = self.collect_live_usage(shipping, host, c);
Self::collect_event_usage(self.events.iter(), &mut c);
c.usage
}
fn collect_live_usage(
&self,
shipping: Option<&NativeBox>,
host: Option<HostResourceUsage>,
mut c: Collector,
) -> Collector {
self.state.collect_statistics(&mut c);
c.usage.steps = self.steps;
c.usage.source_files = self.sources.len();
@@ -122,7 +133,11 @@ impl Executor {
InputFrame::Boundary => {}
}
}
for e in self.events.iter() {
c
}
fn collect_event_usage<'a>(events: impl Iterator<Item = &'a Event>, c: &mut Collector) {
for e in events {
if matches!(e, Event::Statistics(_)) {
continue;
}
@@ -164,8 +179,30 @@ impl Executor {
_ => {}
}
}
c.usage
}
pub(super) fn equivalent_accounting_history(&self, old: &Self) -> bool {
// These containers may reintroduce previously retained allocations
// that are outside the accounting walk at this boundary.
let fully_visited = |engine: &Self| {
engine.state.pdf_forms.is_empty()
&& engine.native_page.as_ref().is_none_or(|page| page.insertions.held.is_empty())
};
if !fully_visited(self) || !fully_visited(old) {
return false;
}
[Collector::for_capacity, Collector::default].into_iter().all(|collector| {
let mut history = collector();
let mut old_history = collector();
Self::collect_event_usage(self.events.iter(), &mut history);
Self::collect_event_usage(old.events.iter(), &mut old_history);
let live = self.collect_live_usage(None, None, collector().tracking_aliases());
let old_live = old.collect_live_usage(None, None, collector().tracking_aliases());
live.has_equivalent_history(&old_live, &history, &old_history)
})
}
pub(super) fn statistics_before_shipout(
&mut self,
b: &NativeBox,