Share packed native lists across copied boxes and shipouts

This commit is contained in:
gloamxun committed 2026-11-28 08:01:14 +08:00
1 parent ca3730338e
commit da48cf9cad
16 files changed
+157 -67

No files matched your search

@@ -70,7 +70,11 @@ impl SourceProvider for Files {
}
}
fn native(source: &str, files: &mut Files) -> Result<Execution, Error> {
Executor::new(State::initex().with_etex(), Limits::default())
native_with_limits(source, files, Limits::default())
}
fn native_with_limits(source: &str, files: &mut Files, limits: Limits) -> Result<Execution, Error> {
Executor::new(State::initex().with_etex(), limits)
.with_native_pages()
.run(
SourceFile {
@@ -311,23 +315,15 @@ fn nested_box_views_share_diagnostic_storage_at_the_node_limit() {
let p = directory();
let material = r"\kern1sp ".repeat(96);
let wrapping = r"\setbox0=\hbox{\box0}".repeat(16);
let source = format!(r"{HEADER}\setbox0=\hbox{{{material}}}{wrapping}\shipout\box0\end");
let mut files = Files::new(&p);
let execution = Executor::new(
State::initex().with_etex(),
let source = format!(r"\setbox0=\hbox{{{material}}}{wrapping}\shipout\box0\end");
let execution = native_with_limits(
&source,
&mut Files::new(&p),
Limits {
tokens: 1024,
..Limits::default()
},
)
.with_native_pages()
.run(
SourceFile {
name: "probe.tex".into(),
data: source.into_bytes(),
},
&mut files,
)
.unwrap();
let boxes = execution
@@ -344,6 +340,49 @@ fn nested_box_views_share_diagnostic_storage_at_the_node_limit() {
fs::remove_dir_all(p).unwrap();
}
#[test]
fn packed_lists_share_storage_across_shipout_copies_and_keep_split_results_isolated() {
let p = directory();
let material = r"\kern1sp ".repeat(96);
let copies = r"\shipout\copy1 ".repeat(8);
let source = format!(
r"\splittopskip=0pt \splitmaxdepth=10pt
\setbox0=\hbox{{\vrule width4pt height5pt {material}}}
\setbox1=\vbox{{\copy0\penalty-10000 \copy0}}
{copies}\setbox2=\vsplit1 to5pt \shipout\box2\shipout\box1\end"
);
let execution = native_with_limits(
&source,
&mut Files::new(&p),
Limits {
tokens: 1024,
..Limits::default()
},
)
.unwrap();
let pages = execution
.events
.iter()
.filter_map(|event| {
let Event::Shipout(page) = event else { return None };
let BoxContent::Vertical(nodes) = &page.box_node.content else {
panic!("expected a vertical box on every page");
};
Some(nodes)
})
.collect::<Vec<_>>();
assert_eq!(pages.len(), 10);
assert!(pages[..8].iter().all(|nodes| std::sync::Arc::ptr_eq(pages[0], nodes)));
let box_count = |nodes: &[NativeVerticalNode]| {
nodes.iter().filter(|node| matches!(node, NativeVerticalNode::Box(_))).count()
};
assert_eq!(box_count(pages[0]), 2);
assert_eq!(box_count(pages[8]), 1);
assert_eq!(box_count(pages[9]), 1);
fs::remove_dir_all(p).unwrap();
}
#[test]
fn statistics_observe_real_paragraph_math_output_and_language_data_without_rewriting_lists() {
let p = directory();