Promote edit-only entry checkpoints to proven line ends

This commit is contained in:
gloamxun committed 2026-12-02 05:37:34 +08:00
1 parent e05ad41a66
commit 8f4ad600ef
1 file changed
+37 -9
+37 -9
View File
@@ -126,7 +126,7 @@ struct CaptureSchedule {
next_page: usize, next_page: usize,
fixed_frontier: Option<usize>, fixed_frontier: Option<usize>,
pending_edit_frontier: Option<usize>, pending_edit_frontier: Option<usize>,
pending_line_end: Option<(usize, usize, usize)>, pending_line_end: Option<(usize, CaptureSlots, usize)>,
settled_page: usize, settled_page: usize,
} }
@@ -145,7 +145,7 @@ const NESTED_INTERVALS: usize = 2;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
enum Capture { enum Capture {
Entry(CaptureSlots), Entry(CaptureSlots),
LineEnd { interval: usize }, LineEnd { slots: CaptureSlots },
Nested { file: usize, interval: usize }, Nested { file: usize, interval: usize },
Settled { page: usize, regular: Option<CaptureSlots> }, Settled { page: usize, regular: Option<CaptureSlots> },
} }
@@ -205,16 +205,16 @@ impl CaptureSchedule {
let regular = self.select(source.frontier, pages); let regular = self.select(source.frontier, pages);
let mut line_end = None; let mut line_end = None;
if self.fixed_frontier.is_none() { if self.fixed_frontier.is_none() {
if let Some(slots) = regular.filter(|slots| slots.early) { if let Some(slots) = regular.filter(|slots| slots.early || slots.edit) {
self.pending_line_end = (!source.line_consumed) self.pending_line_end = (!source.line_consumed)
.then_some((source.frontier, slots.interval, pages)); .then_some((source.frontier, slots, pages));
} else if let Some((frontier, interval, before_pages)) = self.pending_line_end { } else if let Some((frontier, slots, before_pages)) = self.pending_line_end {
if frontier != source.frontier { if frontier != source.frontier {
self.pending_line_end = None; self.pending_line_end = None;
} else if source.line_consumed { } else if source.line_consumed {
self.pending_line_end = None; self.pending_line_end = None;
if pages == before_pages { if pages == before_pages {
line_end = Some(Capture::LineEnd { interval }); line_end = Some(Capture::LineEnd { slots });
} }
} }
} }
@@ -374,8 +374,9 @@ impl<'a> CapturedEntries<'a> {
let Some(regular) = regular else { return; }; let Some(regular) = regular else { return; };
Capture::Entry(regular) Capture::Entry(regular)
} }
Capture::LineEnd { interval } => { Capture::LineEnd { slots } => {
let Some(earlier) = &self.early[interval] else { return; }; let earlier = if slots.edit { &self.edit } else { &self.early[slots.interval] };
let Some(earlier) = earlier else { return; };
// With the same host prefix, finishing an already loaded // With the same host prefix, finishing an already loaded
// line narrows no resource dependency or replay opportunity. // line narrows no resource dependency or replay opportunity.
if !host.prefix().is_some_and(|(_, calls)| calls.len() == earlier.replay_count) if !host.prefix().is_some_and(|(_, calls)| calls.len() == earlier.replay_count)
@@ -383,7 +384,6 @@ impl<'a> CapturedEntries<'a> {
{ {
return; return;
} }
let Capture::Entry(slots) = earlier.slots else { unreachable!() };
Capture::Entry(CaptureSlots { page: false, ..slots }) Capture::Entry(CaptureSlots { page: false, ..slots })
} }
other => other, other => other,
@@ -2434,6 +2434,34 @@ fn immutable_file_creation_and_removal_replay_real_lookup_results() {
assert_eq!(pdfs.values().collect::<BTreeSet<_>>().len(), 4); assert_eq!(pdfs.values().collect::<BTreeSet<_>>().len(), 4);
} }
#[test]
fn edit_only_entry_checkpoint_advances_to_its_line_end() {
let mut schedule = CaptureSchedule::new(400, None, Some(290));
let source = |frontier, line_consumed| CheckpointSource {
id: 0,
name: "main.tex",
bytes: 400,
frontier,
is_entry: true,
line_consumed,
output_returned: true,
};
assert!(matches!(
schedule.select_source(source(215, true), 0),
Some(Capture::Entry(CaptureSlots { early: true, .. }))
));
assert!(matches!(
schedule.select_source(source(290, false), 0),
Some(Capture::Entry(CaptureSlots { early: false, edit: true, .. }))
));
assert!(schedule.select_source(source(290, false), 0).is_none());
assert!(matches!(
schedule.select_source(source(290, true), 0),
Some(Capture::LineEnd { slots: CaptureSlots { early: false, edit: true, .. } })
));
assert!(schedule.select_source(source(290, true), 0).is_none());
}
#[test] #[test]
fn automatic_checkpoints_refresh_the_previous_edit_line_after_a_child_edit() { fn automatic_checkpoints_refresh_the_previous_edit_line_after_a_child_edit() {
let mut schedule = CaptureSchedule::new(400, None, Some(290)); let mut schedule = CaptureSchedule::new(400, None, Some(290));