Resume native edits from verified final-line shipouts
This commit is contained in:
1 parent
93d3d38983
commit
6a47d450f3
4 files changed
+120
-17
No files matched your search
@@ -297,6 +297,7 @@ pub struct EntryCheckpoint {
|
|||||||
initial_depth: usize,
|
initial_depth: usize,
|
||||||
incoming_state: u64,
|
incoming_state: u64,
|
||||||
frontier: usize,
|
frontier: usize,
|
||||||
|
pages_processed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EntryCheckpoint {
|
impl EntryCheckpoint {
|
||||||
@@ -325,7 +326,7 @@ impl EntryCheckpoint {
|
|||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
cancellation: Cancellation,
|
cancellation: Cancellation,
|
||||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||||
self.resume_observed(source, files, cancellation, None, None, |_, _, _| {})
|
self.resume_observed(source, files, cancellation, None, None, |_, _, _, _| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn resume_capturing_entries_after_host_replay<F: SourceProvider, S>(
|
pub(super) fn resume_capturing_entries_after_host_replay<F: SourceProvider, S>(
|
||||||
@@ -355,7 +356,7 @@ impl EntryCheckpoint {
|
|||||||
cancellation: Cancellation,
|
cancellation: Cancellation,
|
||||||
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
|
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
|
||||||
previous: Option<&Execution>,
|
previous: Option<&Execution>,
|
||||||
capture_boundary: impl FnMut(&mut Executor, usize, &mut F),
|
capture_boundary: impl FnMut(&mut Executor, usize, bool, &mut F),
|
||||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||||
if !self.accepts_entry(&source) {
|
if !self.accepts_entry(&source) {
|
||||||
return None;
|
return None;
|
||||||
@@ -369,7 +370,14 @@ impl EntryCheckpoint {
|
|||||||
executor.sources[self.entry] = Arc::new(source);
|
executor.sources[self.entry] = Arc::new(source);
|
||||||
let result = executor
|
let result = executor
|
||||||
.check_cancellation()
|
.check_cancellation()
|
||||||
.and_then(|_| executor.run_active_input(self.initial_depth, files, capture_boundary));
|
.and_then(|_| {
|
||||||
|
executor.run_active_input(
|
||||||
|
self.initial_depth,
|
||||||
|
self.pages_processed,
|
||||||
|
files,
|
||||||
|
capture_boundary,
|
||||||
|
)
|
||||||
|
});
|
||||||
let result = executor.finish_observed_input(result, files);
|
let result = executor.finish_observed_input(result, files);
|
||||||
Some(executor.finish_execution(result, self.incoming_state, previous))
|
Some(executor.finish_execution(result, self.incoming_state, previous))
|
||||||
}
|
}
|
||||||
@@ -3634,7 +3642,7 @@ impl Executor {
|
|||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
) -> Result<Execution, ExecutionFailure> {
|
) -> Result<Execution, ExecutionFailure> {
|
||||||
let incoming_state = self.state.fingerprint();
|
let incoming_state = self.state.fingerprint();
|
||||||
let result = self.run_observed(file, files, |_, _, _| {});
|
let result = self.run_observed(file, files, |_, _, _, _| {});
|
||||||
self.finish_execution(result, incoming_state, None)
|
self.finish_execution(result, incoming_state, None)
|
||||||
}
|
}
|
||||||
/// Capture the first eligible entry command boundary at or beyond the
|
/// Capture the first eligible entry command boundary at or beyond the
|
||||||
@@ -3691,8 +3699,8 @@ impl Executor {
|
|||||||
incoming_state: u64,
|
incoming_state: u64,
|
||||||
mut select: impl FnMut(usize, usize) -> Option<S>,
|
mut select: impl FnMut(usize, usize) -> Option<S>,
|
||||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||||
) -> impl FnMut(&mut Self, usize, &mut F) {
|
) -> impl FnMut(&mut Self, usize, bool, &mut F) {
|
||||||
move |engine, initial_depth, files| {
|
move |engine, initial_depth, pages_processed, files| {
|
||||||
if engine.job_ended {
|
if engine.job_ended {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3736,6 +3744,7 @@ impl Executor {
|
|||||||
initial_depth,
|
initial_depth,
|
||||||
incoming_state,
|
incoming_state,
|
||||||
frontier,
|
frontier,
|
||||||
|
pages_processed,
|
||||||
};
|
};
|
||||||
capture(slot, checkpoint, files);
|
capture(slot, checkpoint, files);
|
||||||
}
|
}
|
||||||
@@ -3824,13 +3833,13 @@ impl Executor {
|
|||||||
&mut self,
|
&mut self,
|
||||||
file: SourceFile,
|
file: SourceFile,
|
||||||
files: &mut F,
|
files: &mut F,
|
||||||
capture_boundary: impl FnMut(&mut Self, usize, &mut F),
|
capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F),
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.check_cancellation()?;
|
self.check_cancellation()?;
|
||||||
self.change_interaction_mode(self.interaction_mode, files)?;
|
self.change_interaction_mode(self.interaction_mode, files)?;
|
||||||
let result = self.prepare_input(file, files).and_then(|initial_depth| {
|
let result = self.prepare_input(file, files).and_then(|initial_depth| {
|
||||||
self.emit_format_image_warnings(files)?;
|
self.emit_format_image_warnings(files)?;
|
||||||
self.run_active_input(initial_depth, files, capture_boundary)
|
self.run_active_input(initial_depth, false, files, capture_boundary)
|
||||||
});
|
});
|
||||||
self.finish_observed_input(result, files)
|
self.finish_observed_input(result, files)
|
||||||
}
|
}
|
||||||
@@ -3943,15 +3952,24 @@ impl Executor {
|
|||||||
fn run_active_input<F: SourceProvider>(
|
fn run_active_input<F: SourceProvider>(
|
||||||
&mut self,
|
&mut self,
|
||||||
initial_depth: usize,
|
initial_depth: usize,
|
||||||
|
mut pages_processed: bool,
|
||||||
files: &mut F,
|
files: &mut F,
|
||||||
mut capture_boundary: impl FnMut(&mut Self, usize, &mut F),
|
mut capture_boundary: impl FnMut(&mut Self, usize, bool, &mut F),
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let xe = self.state.input_profile() == InputProfile::XeTeX;
|
let xe = self.state.input_profile() == InputProfile::XeTeX;
|
||||||
loop {
|
loop {
|
||||||
|
if !std::mem::take(&mut pages_processed) {
|
||||||
self.check_box_capacity(None)?;
|
self.check_box_capacity(None)?;
|
||||||
capture_boundary(self, initial_depth, files);
|
capture_boundary(self, initial_depth, false, files);
|
||||||
|
let shipped_pages = self.shipped_pages;
|
||||||
self.process_native_pages(files)?;
|
self.process_native_pages(files)?;
|
||||||
self.check_box_capacity(None)?;
|
self.check_box_capacity(None)?;
|
||||||
|
if self.shipped_pages != shipped_pages {
|
||||||
|
// A following expandable command can read an input before
|
||||||
|
// the next main-loop iteration.
|
||||||
|
capture_boundary(self, initial_depth, true, files);
|
||||||
|
}
|
||||||
|
}
|
||||||
let Some((input, meaning)) = self.expanded_with_meaning(files, false)? else {
|
let Some((input, meaning)) = self.expanded_with_meaning(files, false)? else {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,32 @@
|
|||||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||||
|
|
||||||
|
## 2026-11-29 末行出页检查点与出页后依赖
|
||||||
|
|
||||||
|
入口最后一条物理行读入后,可以在真实出页处保存检查点。同一物理位置
|
||||||
|
再出一页时,可以保留推进后的状态。处理完待出页列表并通过容量检查后,
|
||||||
|
展开下一条命令前也观察一次边界,覆盖出页后紧接 input 的情况。检查点
|
||||||
|
记录页处理已经完成的阶段,恢复从下一次展开开始。物理来源前缀、资源
|
||||||
|
版本、生成初态及宿主调用按既有契约重新核对。
|
||||||
|
|
||||||
|
以原样 A4 的副本加入真实 LaTeX enddocument/afterlastpage 钩子,钩子
|
||||||
|
读取 review.tex 并写实际 review.note。第一次编辑该文件,执行步数从
|
||||||
|
69,923 降到 35,165。正文编辑后再次编辑该文件,执行从 69,928 降到
|
||||||
|
35,159。新版均恢复到已出页检查点,未刷新 PDF 页面。中间的正文编辑
|
||||||
|
重跑步数与对照相同,正常刷新第 1 页。三次输出的 PDF、来源映射、
|
||||||
|
归一化日志、aux 和 note 与改动前同修订一致。最终版本从同一实际生成
|
||||||
|
初态独立全量编译,PDF、SVG、来源映射、日志、aux 和 note 一致。
|
||||||
|
故障编辑保留已发布的 PDF、辅助文件、日志与 note。
|
||||||
|
|
||||||
|
定向测试把两个文件读取留在入口的同一末行中。修改第一个文件新增第二页,
|
||||||
|
只转换新增页。随后修改第二个文件,恢复到同一物理位置的更新检查点,
|
||||||
|
两页绘制列表都复用。执行、资源观测、PDF、绘制列表、预览、来源映射
|
||||||
|
及日志逐次与独立全量一致。另三项针对失效、取消和晚绑定绘制的检查通过。
|
||||||
|
|
||||||
|
证据在 target/p4-closeout-checkpoints/。本轮测出实际减少的重执行范围。
|
||||||
|
普通正文修改后的安全尾部复用,以及浏览器编辑到可见的统一时延验收
|
||||||
|
继续按总目标推进。
|
||||||
|
|
||||||
## 2026-11-29 尾部执行范围与展开后的命令含义
|
## 2026-11-29 尾部执行范围与展开后的命令含义
|
||||||
|
|
||||||
正常展开将已读取的命令含义交给主执行循环和跳空格扫描,省去即时
|
正常展开将已读取的命令含义交给主执行循环和跳空格扫描,省去即时
|
||||||
|
|||||||
@@ -120,16 +120,19 @@ impl CaptureSchedule {
|
|||||||
next_page: self.next_page,
|
next_page: self.next_page,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if frontier >= self.bytes {
|
if frontier == 0 || frontier > self.bytes {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let interval = (frontier - 1) / self.stride;
|
let interval = (frontier - 1) / self.stride;
|
||||||
let early = !std::mem::replace(&mut self.seen[interval], true);
|
let entry_complete = frontier == self.bytes;
|
||||||
|
// A loaded final line can start closeout hooks or produce several
|
||||||
|
// pages. Keep page boundaries after the last earlier source anchor.
|
||||||
|
let early = !entry_complete && !std::mem::replace(&mut self.seen[interval], true);
|
||||||
let page = pages >= self.next_page;
|
let page = pages >= self.next_page;
|
||||||
if page {
|
if page {
|
||||||
self.next_page = pages.saturating_add((pages / 8).max(1).next_power_of_two());
|
self.next_page = pages.saturating_add((pages / 8).max(1).next_power_of_two());
|
||||||
}
|
}
|
||||||
let edit = self.take_edit_frontier(frontier, early || page);
|
let edit = !entry_complete && self.take_edit_frontier(frontier, early || page);
|
||||||
(early || page || edit).then_some(CaptureSlots {
|
(early || page || edit).then_some(CaptureSlots {
|
||||||
interval,
|
interval,
|
||||||
early,
|
early,
|
||||||
@@ -141,16 +144,19 @@ impl CaptureSchedule {
|
|||||||
|
|
||||||
fn retain(&mut self, checkpoint: &CachedCheckpoint) -> Option<CaptureSlots> {
|
fn retain(&mut self, checkpoint: &CachedCheckpoint) -> Option<CaptureSlots> {
|
||||||
let frontier = checkpoint.entry.frontier();
|
let frontier = checkpoint.entry.frontier();
|
||||||
if frontier >= self.bytes {
|
if frontier > self.bytes || (frontier == self.bytes && !checkpoint.slots.page) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let interval = (frontier - 1) / self.stride;
|
let interval = (frontier - 1) / self.stride;
|
||||||
let early = checkpoint.slots.early && !std::mem::replace(&mut self.seen[interval], true);
|
let early = frontier < self.bytes
|
||||||
|
&& checkpoint.slots.early
|
||||||
|
&& !std::mem::replace(&mut self.seen[interval], true);
|
||||||
self.next_page = self.next_page.max(checkpoint.slots.next_page);
|
self.next_page = self.next_page.max(checkpoint.slots.next_page);
|
||||||
Some(CaptureSlots {
|
Some(CaptureSlots {
|
||||||
interval,
|
interval,
|
||||||
early,
|
early,
|
||||||
edit: self.take_edit_frontier(frontier, early || checkpoint.slots.page),
|
edit: frontier < self.bytes
|
||||||
|
&& self.take_edit_frontier(frontier, early || checkpoint.slots.page),
|
||||||
..checkpoint.slots
|
..checkpoint.slots
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -585,7 +591,9 @@ impl SelectedCheckpoint {
|
|||||||
&mut recording,
|
&mut recording,
|
||||||
line_break_cache,
|
line_break_cache,
|
||||||
|offset, pages| {
|
|offset, pages| {
|
||||||
if offset > frontier {
|
// The loaded line may stay the same across several
|
||||||
|
// pages. A new sampled shipout is still forward progress.
|
||||||
|
if offset > frontier || (offset == frontier && pages >= schedule.next_page) {
|
||||||
schedule.select(offset, pages)
|
schedule.select(offset, pages)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -1344,6 +1344,57 @@ fn xetex_glyph_bounds_and_dash_breaks_follow_revision_local_parameters() {
|
|||||||
fs::remove_dir_all(p).unwrap();
|
fs::remove_dir_all(p).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checkpoint_reuses_shipouts_when_late_inputs_share_the_final_entry_line() {
|
||||||
|
let p = directory("shared-final-line");
|
||||||
|
let body = concat!(
|
||||||
|
"\n",
|
||||||
|
r"\shipout\hbox{Stable page}\input body.tex \relax \input review.tex \end",
|
||||||
|
);
|
||||||
|
let part = p.join("body.tex");
|
||||||
|
let review = p.join("review.tex");
|
||||||
|
let mut definition = atomic_definition(&p, 1, body);
|
||||||
|
definition.files.insert(part.clone(), Arc::from(br"\message{One page}".as_slice()));
|
||||||
|
definition.files.insert(review.clone(), Arc::from(br"\message{Review one}".as_slice()));
|
||||||
|
let entry_end = definition.files[&p.join("main.tex")].len();
|
||||||
|
let mut project = ProjectSnapshot::new(definition).unwrap();
|
||||||
|
let mut request = request(&p);
|
||||||
|
request.world = project.configuration();
|
||||||
|
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||||
|
let mut published = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||||
|
assert_eq!(published.pages.len(), 1);
|
||||||
|
|
||||||
|
for (version, path, content, lowered, expected_change) in [
|
||||||
|
(2, part, br"\shipout\hbox{New page}".as_slice(), 1, vec![1]),
|
||||||
|
(3, review, br"\message{Review two}".as_slice(), 0, vec![]),
|
||||||
|
] {
|
||||||
|
project = project.with_file_edits(version, [(path, Arc::from(content))].into()).unwrap();
|
||||||
|
let request = request.clone().with_project(project.clone());
|
||||||
|
let resumed = session.compile(request.clone()).unwrap();
|
||||||
|
let work = &resumed.entry_checkpoint_work;
|
||||||
|
assert_eq!(work.reused_frontier, Some(entry_end), "{work:?}");
|
||||||
|
assert_eq!(resumed.shipout_layout_work.lowered_pages, lowered);
|
||||||
|
assert_eq!(resumed.shipout_layout_work.reused_pages, 2 - lowered);
|
||||||
|
let changed: Vec<_> = resumed.preview_since(Some(published.revision())).unwrap()
|
||||||
|
.pages.into_iter().map(|page| page.index).collect();
|
||||||
|
assert_eq!(changed, expected_change);
|
||||||
|
let log = fs::read(p.join("job.log")).unwrap();
|
||||||
|
let full = NativeCompiler::default().compile(request).unwrap();
|
||||||
|
assert_eq!(resumed.execution.execution, full.execution.execution);
|
||||||
|
assert_eq!(resumed.resources.trace.lookups, full.resources.trace.lookups);
|
||||||
|
assert_eq!(resumed.resources.trace.reads, full.resources.trace.reads);
|
||||||
|
assert_eq!(resumed.pdf, full.pdf);
|
||||||
|
assert_eq!(resumed.pages, full.pages);
|
||||||
|
assert_eq!(resumed.source_map.sources, full.source_map.sources);
|
||||||
|
assert_eq!(resumed.source_map.pages, full.source_map.pages);
|
||||||
|
assert_eq!(resumed.preview_since(None).unwrap().pages, full.preview_since(None).unwrap().pages);
|
||||||
|
assert_eq!(log, fs::read(p.join("job.log")).unwrap());
|
||||||
|
eprintln!("revision={version} {work:?} layout={:?} changed={changed:?}", resumed.shipout_layout_work);
|
||||||
|
published = resumed;
|
||||||
|
}
|
||||||
|
fs::remove_dir_all(p).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checkpoint_keeps_late_special_tokens_until_the_updated_page_is_shipped() {
|
fn checkpoint_keeps_late_special_tokens_until_the_updated_page_is_shipped() {
|
||||||
let p = directory("late-special");
|
let p = directory("late-special");
|
||||||
|
|||||||
Reference in new issue
Block a user