Retain the Unicode checkpoint after package input returns
This commit is contained in:
1 parent
38665f9af5
commit
a2c0ab19c4
4 files changed
+139
-33
No files matched your search
Generated
+1
-1
@@ -3237,7 +3237,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "texrra-desktop"
|
||||
version = "0.1.11"
|
||||
version = "0.1.12"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "texrra-desktop"
|
||||
version = "0.1.11"
|
||||
version = "0.1.12"
|
||||
edition = "2024"
|
||||
rust-version = "1.92"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Texrra",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"identifier": "org.texrra.desktop",
|
||||
"build": {
|
||||
"frontendDist": "../startup"
|
||||
|
||||
+136
-30
@@ -167,17 +167,20 @@ struct CaptureSchedule {
|
||||
pending_edit_frontier: Option<usize>,
|
||||
pending_edit_fallback: Option<usize>,
|
||||
pending_preamble: Option<usize>,
|
||||
pending_preamble_after_input: Option<usize>,
|
||||
nested_since_entry: bool,
|
||||
pending_line_end: Option<(usize, CaptureSlots, usize)>,
|
||||
settled_page: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct CaptureSlots {
|
||||
interval: usize,
|
||||
early: bool,
|
||||
page: bool,
|
||||
edit: bool,
|
||||
preamble: bool,
|
||||
preamble_after_input: bool,
|
||||
next_page: usize,
|
||||
}
|
||||
|
||||
@@ -240,6 +243,8 @@ impl CaptureSchedule {
|
||||
pending_edit_frontier: edit_frontier,
|
||||
pending_edit_fallback: None,
|
||||
pending_preamble: None,
|
||||
pending_preamble_after_input: None,
|
||||
nested_since_entry: false,
|
||||
pending_line_end: None,
|
||||
settled_page: 0,
|
||||
}
|
||||
@@ -260,12 +265,19 @@ impl CaptureSchedule {
|
||||
// with the begin-document line loaded and the body still unread.
|
||||
self.pending_preamble = document_start_line(source, MIN_PREAMBLE_INTERVAL_BYTES)
|
||||
.and_then(|(start, end)| (start > 0 && end < source.len()).then_some(end));
|
||||
self.pending_preamble_after_input = self.pending_preamble;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn observe_nested_input(&mut self) {
|
||||
self.nested_since_entry = self.pending_preamble_after_input.is_some() && self.pending_preamble.is_none();
|
||||
}
|
||||
|
||||
fn select_source(&mut self, source: CheckpointSource<'_>, pages: usize) -> Option<Capture> {
|
||||
let regular = self.select(source.frontier, pages);
|
||||
let returned_from_input = std::mem::take(&mut self.nested_since_entry);
|
||||
let frontier = source.frontier;
|
||||
let mut regular = self.select(frontier, pages);
|
||||
let mut line_end = None;
|
||||
if self.fixed_frontier.is_none() {
|
||||
if let Some(slots) = regular.filter(|slots| slots.early || slots.edit) {
|
||||
@@ -282,6 +294,21 @@ impl CaptureSchedule {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Package loading can peek at the begin-document line before opening
|
||||
// any package files. Keep a separate continuation when the executor
|
||||
// returns from that input stack with the body line still unread.
|
||||
if self.pending_preamble_after_input.is_some_and(|pending| frontier > pending) {
|
||||
self.pending_preamble_after_input = None;
|
||||
}
|
||||
if returned_from_input
|
||||
&& self.pending_preamble_after_input.take_if(|pending| *pending == frontier).is_some()
|
||||
{
|
||||
regular.get_or_insert(CaptureSlots {
|
||||
interval: (frontier - 1) / self.stride,
|
||||
next_page: self.next_page,
|
||||
..CaptureSlots::default()
|
||||
}).preamble_after_input = true;
|
||||
}
|
||||
if self.fixed_frontier.is_none() && source.output_returned && pages > self.settled_page {
|
||||
self.settled_page = pages;
|
||||
// A wider grid is a subset of the earlier grid, so a new run
|
||||
@@ -329,6 +356,7 @@ impl CaptureSchedule {
|
||||
page: false,
|
||||
edit: false,
|
||||
preamble: false,
|
||||
preamble_after_input: false,
|
||||
next_page: self.next_page,
|
||||
});
|
||||
}
|
||||
@@ -352,6 +380,7 @@ impl CaptureSchedule {
|
||||
page,
|
||||
edit,
|
||||
preamble,
|
||||
preamble_after_input: false,
|
||||
next_page: self.next_page,
|
||||
})
|
||||
}
|
||||
@@ -374,6 +403,8 @@ impl CaptureSchedule {
|
||||
&& self.take_edit_frontier(frontier, early || slots.page),
|
||||
preamble: frontier < self.bytes
|
||||
&& self.pending_preamble.take_if(|pending| *pending == frontier).is_some(),
|
||||
preamble_after_input: slots.preamble_after_input
|
||||
&& self.pending_preamble_after_input.take_if(|pending| *pending == frontier).is_some(),
|
||||
..slots
|
||||
})
|
||||
}
|
||||
@@ -387,6 +418,7 @@ struct CapturedEntries<'a> {
|
||||
shipped: [Option<Arc<CachedCheckpoint>>; SOURCE_INTERVALS],
|
||||
edit: Option<Arc<CachedCheckpoint>>,
|
||||
preamble: Option<Arc<CachedCheckpoint>>,
|
||||
preamble_after_input: Option<Arc<CachedCheckpoint>>,
|
||||
nested: [[Option<Arc<CachedCheckpoint>>; NESTED_INTERVALS]; NESTED_FILES],
|
||||
changed: bool,
|
||||
settled: BTreeMap<usize, SettledCheckpoint>,
|
||||
@@ -407,6 +439,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
shipped: Default::default(),
|
||||
edit: None,
|
||||
preamble: None,
|
||||
preamble_after_input: None,
|
||||
nested: Default::default(),
|
||||
changed: false,
|
||||
settled: BTreeMap::new(),
|
||||
@@ -434,6 +467,9 @@ impl<'a> CapturedEntries<'a> {
|
||||
if slots.preamble {
|
||||
self.preamble = Some(checkpoint.clone());
|
||||
}
|
||||
if slots.preamble_after_input {
|
||||
self.preamble_after_input = Some(checkpoint.clone());
|
||||
}
|
||||
if slots.page {
|
||||
self.shipped[slots.interval] = Some(checkpoint);
|
||||
}
|
||||
@@ -558,6 +594,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
page: true,
|
||||
edit: false,
|
||||
preamble: false,
|
||||
preamble_after_input: false,
|
||||
next_page: page.saturating_add(1),
|
||||
};
|
||||
self.capture(Capture::Settled { page, regular: Some(regular) }, Arc::new(entry), host);
|
||||
@@ -614,10 +651,10 @@ impl<'a> CapturedEntries<'a> {
|
||||
.expect("the full schedule has ordinary continuations");
|
||||
entries.remove(index);
|
||||
}
|
||||
if let Some(preamble) = self.preamble
|
||||
&& !entries.iter().any(|entry| Arc::ptr_eq(entry, &preamble))
|
||||
{
|
||||
entries.push(preamble);
|
||||
for preamble in [self.preamble, self.preamble_after_input].into_iter().flatten() {
|
||||
if !entries.iter().any(|entry| Arc::ptr_eq(entry, &preamble)) {
|
||||
entries.push(preamble);
|
||||
}
|
||||
}
|
||||
let before_child = recording.prefix().and_then(|(_, calls)| {
|
||||
// Keep one existing parent anchor before a child's first size
|
||||
@@ -806,6 +843,7 @@ impl CheckpointCache {
|
||||
if source.is_entry {
|
||||
schedule.select_source(source, pages)
|
||||
} else if self.minimum_frontier.is_none() {
|
||||
schedule.observe_nested_input();
|
||||
nested.select(source, cwd)
|
||||
} else {
|
||||
None
|
||||
@@ -1218,13 +1256,16 @@ impl SelectedCheckpoint {
|
||||
if source.is_entry {
|
||||
// The loaded entry line can be shared by several shipouts.
|
||||
if source.frontier > entry_frontier
|
||||
|| (source.frontier == entry_frontier && pages >= schedule.next_page)
|
||||
|| (source.frontier == entry_frontier
|
||||
&& (pages >= schedule.next_page
|
||||
|| schedule.pending_preamble_after_input == Some(entry_frontier)))
|
||||
{
|
||||
schedule.select_source(source, pages)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
schedule.observe_nested_input();
|
||||
nested_schedule.select(source, cwd)
|
||||
}
|
||||
},
|
||||
@@ -2622,7 +2663,7 @@ fn large_automatic_schedule_keeps_a_preamble_anchor_once() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_xetex_schedule_keeps_a_boundary_before_body_bytes() {
|
||||
fn short_xetex_schedule_keeps_both_boundaries_before_body_bytes() {
|
||||
for newline in ["\n", "\r\n", "\r"] {
|
||||
let prefix = format!("\\documentclass{{article}}{newline}\\usepackage[UTF8,scheme=plain,fontset=fandol]{{ctex}}{newline}");
|
||||
let begin = format!("{prefix}\\begin{{document}}{newline}");
|
||||
@@ -2630,45 +2671,90 @@ fn short_xetex_schedule_keeps_a_boundary_before_body_bytes() {
|
||||
let bytes = source.as_bytes();
|
||||
let mut schedule = CaptureSchedule::new(bytes.len(), None, None)
|
||||
.with_preamble_anchor(bytes, InputProfile::XeTeX);
|
||||
let source = |frontier| CheckpointSource {
|
||||
id: 0,
|
||||
name: "main.tex",
|
||||
bytes: bytes.len(),
|
||||
frontier,
|
||||
is_entry: true,
|
||||
line_consumed: false,
|
||||
output_returned: true,
|
||||
};
|
||||
assert_eq!((prefix.len() - 1) / schedule.stride, (begin.len() - 1) / schedule.stride);
|
||||
assert!(schedule.select(prefix.len(), 0).unwrap().early);
|
||||
let anchor = schedule.select(begin.len(), 0).unwrap();
|
||||
assert!(anchor.preamble && !anchor.early && !anchor.edit && !anchor.page);
|
||||
assert!(schedule.select(begin.len(), 0).is_none());
|
||||
assert!(matches!(
|
||||
schedule.select_source(source(begin.len()), 0),
|
||||
Some(Capture::Entry(CaptureSlots { preamble: true, preamble_after_input: false, .. }))
|
||||
));
|
||||
assert!(schedule.select_source(source(begin.len()), 0).is_none());
|
||||
|
||||
schedule.observe_nested_input();
|
||||
assert!(matches!(
|
||||
schedule.select_source(source(begin.len()), 0),
|
||||
Some(Capture::Entry(CaptureSlots { preamble: false, preamble_after_input: true, .. }))
|
||||
));
|
||||
schedule.observe_nested_input();
|
||||
assert!(schedule.select_source(source(begin.len()), 0).is_none());
|
||||
}
|
||||
|
||||
let inline_body = b"\\usepackage{ctex}\n\\begin{document}body\n\\end{document}\n";
|
||||
assert!(
|
||||
CaptureSchedule::new(inline_body.len(), None, None)
|
||||
.with_preamble_anchor(inline_body, InputProfile::XeTeX)
|
||||
.pending_preamble_after_input.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_xetex_body_edit_reuses_the_preamble_and_rejects_a_changed_input() {
|
||||
fn short_xetex_body_edits_reuse_the_return_from_package_loading() {
|
||||
let cwd = std::env::temp_dir().join(format!("texrra-xetex-preamble-{}", std::process::id()));
|
||||
fs::create_dir(&cwd).unwrap();
|
||||
let cwd = cwd.canonicalize().unwrap();
|
||||
let entry = cwd.join("main.tex");
|
||||
let package = cwd.join("preamble.tex");
|
||||
let prefix = "\\relax \\input preamble.tex % an input on the same grid interval as the next line\n";
|
||||
let begin = format!("{prefix}\\begin{{document}}\n");
|
||||
let document = |height| format!("{begin}\\shipout\\hbox{{\\vrule width\\rulewidth height{height}pt}}\\end\n");
|
||||
let preamble = |width| {
|
||||
let package_child = cwd.join("classdefs.tex");
|
||||
let aux = cwd.join("main.aux");
|
||||
let stable_aux = b"\\def\\auxwidth{6pt}\n";
|
||||
let changed_aux = b"\\def\\auxwidth{8pt}\n";
|
||||
fs::write(&aux, stable_aux).unwrap();
|
||||
// futurelet pulls the next line's first token before the package opens.
|
||||
let begin = concat!(
|
||||
"\\catcode123=1 \\catcode125=2 \\catcode35=6\n",
|
||||
"\\def\\loadpackage#1{\\def\\pendingpackage{#1 }\\futurelet\\look\\performload}\n",
|
||||
"\\def\\performload{\\input\\pendingpackage\\relax}\n",
|
||||
"\\loadpackage{preamble.tex}%\n",
|
||||
"\\begin{document}\n",
|
||||
);
|
||||
let document = |height| {
|
||||
format!(
|
||||
"\\catcode123=1 \\catcode125=2 \\catcode35=6\n\\def\\begin#1{{\\relax}}\n\\def\\rulewidth{{{width}pt}}\n{}",
|
||||
"\\advance\\count0by1\n".repeat(64),
|
||||
"{begin}\\shipout\\hbox{{\\vrule width\\rulewidth height{height}pt \\vrule width\\auxwidth height1pt}}\\end\n"
|
||||
)
|
||||
};
|
||||
let preamble = concat!(
|
||||
"\\relax \\input classdefs.tex\n",
|
||||
"\\def\\begin#1{\\relax}\n",
|
||||
"\\relax \\input main.aux\n",
|
||||
"\\immediate\\openout1=main.aux\n",
|
||||
"\\immediate\\write1{\\string\\def\\string\\auxwidth{6pt}}\n",
|
||||
"\\immediate\\closeout1\n",
|
||||
);
|
||||
let child = |width| format!("\\def\\rulewidth{{{width}pt}}\n{}", "\\advance\\count0by1\n".repeat(512));
|
||||
let original = document(1);
|
||||
let mut world = WorldConfig::new(&cwd);
|
||||
world.input_policy = InputPolicy::Tex;
|
||||
let project = ProjectSnapshot::new(ProjectDefinition {
|
||||
let mut project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: BTreeSet::from([cwd.clone()]),
|
||||
files: BTreeMap::from([
|
||||
(entry.clone(), Arc::from(original.as_bytes())),
|
||||
(package.clone(), Arc::from(preamble(10).into_bytes())),
|
||||
(package, Arc::from(preamble.as_bytes())),
|
||||
(package_child.clone(), Arc::from(child(10).into_bytes())),
|
||||
]),
|
||||
directories: BTreeSet::new(),
|
||||
aliases: BTreeMap::new(),
|
||||
generated_roots: BTreeSet::from([cwd.clone()]),
|
||||
generated: BTreeSet::new(),
|
||||
generated: BTreeSet::from([aux.clone()]),
|
||||
})
|
||||
.unwrap();
|
||||
let mut request = CompileRequest::new(
|
||||
@@ -2681,25 +2767,44 @@ fn short_xetex_body_edit_reuses_the_preamble_and_rejects_a_changed_input() {
|
||||
request.input_profile = InputProfile::XeTeX;
|
||||
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let before = compiler.compile(request.clone()).unwrap();
|
||||
let mut project = project;
|
||||
let mut last = compiler.compile(request.clone()).unwrap();
|
||||
let initial = compiler.entry_checkpoints.as_ref().unwrap().current().unwrap();
|
||||
let find_anchor = |after_input| {
|
||||
initial.current.entries.iter().find(|candidate| match candidate.slots {
|
||||
Capture::Entry(slots) if after_input => slots.preamble_after_input,
|
||||
Capture::Entry(slots) => slots.preamble,
|
||||
_ => false,
|
||||
}).unwrap()
|
||||
};
|
||||
let early = find_anchor(false);
|
||||
let later = find_anchor(true);
|
||||
assert_eq!(early.entry.frontier(), begin.len());
|
||||
assert_eq!(later.entry.frontier(), begin.len());
|
||||
let later_steps = later.entry.completed_steps();
|
||||
assert!(later_steps >= early.entry.completed_steps() + 512);
|
||||
assert!(later.replay_count > early.replay_count);
|
||||
let cases = [
|
||||
(entry, Arc::from(document(2).into_bytes()), true),
|
||||
(package, Arc::from(preamble(15).into_bytes()), false),
|
||||
(entry.clone(), Arc::from(document(2).into_bytes()), stable_aux, true),
|
||||
(entry.clone(), Arc::from(document(12).into_bytes()), stable_aux, true),
|
||||
(package_child, Arc::from(child(15).into_bytes()), stable_aux, false),
|
||||
(entry, Arc::from(document(13).into_bytes()), changed_aux, false),
|
||||
];
|
||||
let mut last = before;
|
||||
for (index, (path, contents, anchored)) in cases.into_iter().enumerate() {
|
||||
for (index, (path, contents, starting_aux, anchored)) in cases.into_iter().enumerate() {
|
||||
project = project.with_file_edits(index as u64 + 2, BTreeMap::from([(path, contents)])).unwrap();
|
||||
let request = request.clone().with_project(project.clone());
|
||||
fs::write(&aux, starting_aux).unwrap();
|
||||
let actual = compiler.compile(request.clone()).unwrap();
|
||||
assert_eq!(fs::read(&aux).unwrap(), stable_aux);
|
||||
fs::write(&aux, starting_aux).unwrap();
|
||||
let full = NativeCompiler::default().compile(request).unwrap();
|
||||
|
||||
let work = &actual.entry_checkpoint_work;
|
||||
let reused_prefix = work.reused_steps - work.reused_suffix_steps;
|
||||
if anchored {
|
||||
assert_eq!(work.reused_frontier, Some(begin.len()), "{work:?}");
|
||||
assert!(work.reused_steps >= 64 && work.replayed_calls > 0, "{work:?}");
|
||||
assert!(reused_prefix >= 512 && work.replayed_calls > 0, "{work:?}");
|
||||
} else {
|
||||
assert!(work.reused_frontier.is_none_or(|frontier| frontier < begin.len()), "{work:?}");
|
||||
assert!(work.reused_steps < 64, "{work:?}");
|
||||
assert!(reused_prefix < later_steps, "{work:?}");
|
||||
}
|
||||
assert_ne!(last.pdf, actual.pdf);
|
||||
assert_eq!(actual.pdf, full.pdf);
|
||||
@@ -2708,6 +2813,7 @@ fn short_xetex_body_edit_reuses_the_preamble_and_rejects_a_changed_input() {
|
||||
assert_eq!(actual.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(actual.execution.execution, full.execution.execution);
|
||||
assert_eq!(actual.resources.trace.lookups, full.resources.trace.lookups);
|
||||
assert_eq!(fs::read(&aux).unwrap(), stable_aux);
|
||||
last = actual;
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
|
||||
Reference in new issue
Block a user