Reuse closed events and line breaking after a checkpoint
This commit is contained in:
1 parent
fc6786d9f4
commit
393fba42d8
7 files changed
+140
-16
No files matched your search
@@ -139,6 +139,55 @@ impl ConditionalLimit {
|
||||
}
|
||||
}
|
||||
|
||||
// Closed chunks keep their original order and are shared by entry checkpoints.
|
||||
// The live tail is the only part changed while a continuation executes.
|
||||
#[derive(Clone, Default)]
|
||||
struct ExecutionEvents {
|
||||
prefix: Vec<std::sync::Arc<Vec<Event>>>,
|
||||
prefix_len: usize,
|
||||
tail: Vec<Event>,
|
||||
}
|
||||
|
||||
impl ExecutionEvents {
|
||||
fn push(&mut self, event: Event) {
|
||||
self.tail.push(event);
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.prefix_len + self.tail.len()
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &Event> {
|
||||
self.prefix
|
||||
.iter()
|
||||
.flat_map(|chunk| chunk.iter())
|
||||
.chain(&self.tail)
|
||||
}
|
||||
|
||||
fn seal_prefix(&mut self) {
|
||||
if !self.tail.is_empty() {
|
||||
self.prefix_len += self.tail.len();
|
||||
self.prefix
|
||||
.push(std::sync::Arc::new(std::mem::take(&mut self.tail)));
|
||||
}
|
||||
}
|
||||
|
||||
fn into_vec(self) -> Vec<Event> {
|
||||
if self.prefix.is_empty() {
|
||||
return self.tail;
|
||||
}
|
||||
let mut events = Vec::with_capacity(self.len());
|
||||
for chunk in self.prefix {
|
||||
match std::sync::Arc::try_unwrap(chunk) {
|
||||
Ok(chunk) => events.extend(chunk),
|
||||
Err(chunk) => events.extend_from_slice(&chunk),
|
||||
}
|
||||
}
|
||||
events.extend(self.tail);
|
||||
events
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Executor {
|
||||
state: State,
|
||||
@@ -155,7 +204,7 @@ pub struct Executor {
|
||||
conditionals: Vec<Conditional>,
|
||||
in_csname: bool,
|
||||
command_trace_mode: Option<&'static str>,
|
||||
events: Vec<Event>,
|
||||
events: ExecutionEvents,
|
||||
steps: usize,
|
||||
ligature_carry: super::ligature::Carry,
|
||||
current: Span,
|
||||
@@ -243,7 +292,7 @@ impl EntryCheckpoint {
|
||||
files: &mut impl SourceProvider,
|
||||
cancellation: Cancellation,
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
self.resume_observed(source, files, cancellation, |_, _, _| {})
|
||||
self.resume_observed(source, files, cancellation, None, |_, _, _| {})
|
||||
}
|
||||
|
||||
pub(super) fn resume_capturing_entries_after_host_replay<F: SourceProvider, S>(
|
||||
@@ -251,6 +300,7 @@ impl EntryCheckpoint {
|
||||
source: SourceFile,
|
||||
files: &mut F,
|
||||
cancellation: Cancellation,
|
||||
line_break_cache: std::sync::Arc<super::LineBreakCache>,
|
||||
select: impl FnMut(usize, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
@@ -258,6 +308,7 @@ impl EntryCheckpoint {
|
||||
source,
|
||||
files,
|
||||
cancellation,
|
||||
Some(line_break_cache),
|
||||
Executor::entry_observer(self.incoming_state, select, capture),
|
||||
)
|
||||
}
|
||||
@@ -267,12 +318,14 @@ impl EntryCheckpoint {
|
||||
source: SourceFile,
|
||||
files: &mut F,
|
||||
cancellation: Cancellation,
|
||||
capture_boundary: impl FnMut(&Executor, usize, &mut F),
|
||||
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
|
||||
capture_boundary: impl FnMut(&mut Executor, usize, &mut F),
|
||||
) -> Option<Result<Execution, ExecutionFailure>> {
|
||||
if !self.accepts_entry(&source) {
|
||||
return None;
|
||||
}
|
||||
let mut executor = self.executor.clone().with_cancellation(cancellation);
|
||||
executor.line_break_cache = line_break_cache;
|
||||
let Some(InputFrame::Source { mouth, .. }) = executor.inputs.first_mut() else {
|
||||
unreachable!("entry checkpoints start with the physical source frame");
|
||||
};
|
||||
@@ -310,7 +363,7 @@ impl Executor {
|
||||
conditionals: Vec::new(),
|
||||
in_csname: false,
|
||||
command_trace_mode: None,
|
||||
events: Vec::new(),
|
||||
events: ExecutionEvents::default(),
|
||||
steps: 0,
|
||||
ligature_carry: super::ligature::Carry::default(),
|
||||
current: Span::default(),
|
||||
@@ -2740,7 +2793,7 @@ impl Executor {
|
||||
stream_sources: self.stream_sources,
|
||||
generated_inputs: self.generated_inputs,
|
||||
reads: self.reads,
|
||||
events: self.events,
|
||||
events: self.events.into_vec(),
|
||||
steps: self.steps,
|
||||
})
|
||||
}
|
||||
@@ -3040,7 +3093,7 @@ impl Executor {
|
||||
incoming_state: u64,
|
||||
mut select: impl FnMut(usize, usize) -> Option<S>,
|
||||
mut capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> impl FnMut(&Self, usize, &mut F) {
|
||||
) -> impl FnMut(&mut Self, usize, &mut F) {
|
||||
move |engine, initial_depth, files| {
|
||||
if engine.job_ended {
|
||||
return;
|
||||
@@ -3074,12 +3127,14 @@ impl Executor {
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
let entry = *source;
|
||||
engine.events.seal_prefix();
|
||||
let mut executor = engine.clone();
|
||||
executor.cancellation = None;
|
||||
executor.line_break_cache = None;
|
||||
let checkpoint = EntryCheckpoint {
|
||||
executor,
|
||||
entry: *source,
|
||||
entry,
|
||||
initial_depth,
|
||||
incoming_state,
|
||||
frontier,
|
||||
@@ -3109,7 +3164,7 @@ impl Executor {
|
||||
stream_sources: self.stream_sources,
|
||||
generated_inputs: self.generated_inputs,
|
||||
reads: self.reads,
|
||||
events: self.events,
|
||||
events: self.events.into_vec(),
|
||||
input_position: self.input_position,
|
||||
incoming_state,
|
||||
outgoing_state: self.state.fingerprint(),
|
||||
@@ -3133,7 +3188,7 @@ impl Executor {
|
||||
job_name: self.job_name,
|
||||
interaction_mode: self.interaction_mode,
|
||||
after_assignment: self.after_assignment,
|
||||
events: self.events,
|
||||
events: self.events.into_vec(),
|
||||
native_page: self.native_page,
|
||||
split_discards: self.split_discards,
|
||||
outgoing_state: self.state.fingerprint(),
|
||||
@@ -3153,7 +3208,7 @@ impl Executor {
|
||||
&mut self,
|
||||
file: SourceFile,
|
||||
files: &mut F,
|
||||
capture_boundary: impl FnMut(&Self, usize, &mut F),
|
||||
capture_boundary: impl FnMut(&mut Self, usize, &mut F),
|
||||
) -> Result<(), Error> {
|
||||
self.check_cancellation()?;
|
||||
self.change_interaction_mode(self.interaction_mode, files)?;
|
||||
@@ -3252,7 +3307,7 @@ impl Executor {
|
||||
&mut self,
|
||||
initial_depth: usize,
|
||||
files: &mut F,
|
||||
mut capture_boundary: impl FnMut(&Self, usize, &mut F),
|
||||
mut capture_boundary: impl FnMut(&mut Self, usize, &mut F),
|
||||
) -> Result<(), Error> {
|
||||
loop {
|
||||
self.check_box_capacity(None)?;
|
||||
|
||||
@@ -112,7 +112,7 @@ impl Executor {
|
||||
InputFrame::Boundary => {}
|
||||
}
|
||||
}
|
||||
for e in &self.events {
|
||||
for e in self.events.iter() {
|
||||
if matches!(e, Event::Statistics(_)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use sha2::{Digest, Sha256};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::{
|
||||
Cancellation, EntryCheckpoint, Error, Execution, ExecutionFailure, Executor, SourceFile,
|
||||
SourceProvider,
|
||||
Cancellation, EntryCheckpoint, Error, Execution, ExecutionFailure, Executor, LineBreakCache,
|
||||
SourceFile, SourceProvider,
|
||||
};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
@@ -203,6 +203,7 @@ impl RevisionJob {
|
||||
checkpoint: &EntryCheckpoint,
|
||||
source: SourceFile,
|
||||
files: &mut F,
|
||||
line_break_cache: Arc<LineBreakCache>,
|
||||
select: impl FnMut(usize, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F),
|
||||
) -> Option<Result<Arc<RevisionExecution>, RevisionFailure>> {
|
||||
@@ -210,6 +211,7 @@ impl RevisionJob {
|
||||
source,
|
||||
files,
|
||||
self.cancellation.clone(),
|
||||
line_break_cache,
|
||||
select,
|
||||
capture,
|
||||
)?;
|
||||
|
||||
+16
-2
@@ -239,14 +239,28 @@ SHA-256 为 `eb91a271962e06b1279875538bc2ed0c88256c013b23fb2efd0da271c2f524b5`
|
||||
准备了真实 A3 前段与后页的交替浏览器对照,每个构建包含每类30次编辑。
|
||||
pdfTeX 已核对该序列的页数、受影响页和稳定 aux。浏览器延迟仍待实测。
|
||||
|
||||
### 续跑断行和已执行事件
|
||||
|
||||
自动续跑接回现有断行搜索缓存。编辑一个段落时,后续未改段落可复用求解,
|
||||
仍按本轮原始节点重新构造量测与来源映射。已完成的事件区间由检查点共享,
|
||||
统计、错误证据和公开结果保留完整事件顺序。
|
||||
548项定向回归零失败,原样 A3 的两轮续跑、独立全量、页面差量、SVG、来源
|
||||
映射、aux 和日志通过。定向日志 `target/p4-suffix-reuse-next/directed.log`
|
||||
SHA-256 为 `47cb200c753e1f05270fa83f2d0f87d67a58f01292876f326990b2577d83215d`。
|
||||
A3 日志 SHA-256 为 `99e2e14be446aaa2b8cf823b1f764881a4bdc22fa9f947e0a6a5da2d38cc6fb0`。
|
||||
下一组浏览器比较需单独测量这两项改动的延迟和内存。
|
||||
|
||||
### schema27 与主线兼容性
|
||||
|
||||
合并了真实重复盒及 PDF 书签布局,并保留主线的宏参数分隔符和流式失败报告。
|
||||
按483项源码和测试指纹核对的工作区回归通过1617项,零失败。日志
|
||||
`target/p3-schema27-main-reconcile/workspace.log` 的 SHA-256 为
|
||||
`561766e409640fa3d407a365b4e3e88885bcc2a7e7f9bfc49f680ad92b7370f4`。
|
||||
独立 schema27 候选已使用真实 LaTeX 格式通过七份原样 article 的21轮 PDF 及
|
||||
版面对照,合并后的优化构建将单独复验。
|
||||
主线合并版本的优化程序以原版 LaTeX 启动新建真实 schema27 格式,复验
|
||||
七份原样 article 的21轮。参考页数、字体、词框、墨迹、原始字形和规则坐标、
|
||||
aux 和引用全部通过。回执
|
||||
`target/p3-schema27-main-reconcile/release-articles/native-article-audit.json`
|
||||
SHA-256 为 `ce9abcee0891dd6b466ac1cc6b2d4fd3b8dbb575aa34f2a628279abc049fc1cf`。
|
||||
|
||||
### schema25 主干验收
|
||||
|
||||
|
||||
@@ -974,6 +974,7 @@ impl CompileJob {
|
||||
self.job,
|
||||
source,
|
||||
files,
|
||||
cache.clone(),
|
||||
&mut entry_checkpoint_work,
|
||||
)?;
|
||||
(executed, Some(next))
|
||||
|
||||
@@ -348,6 +348,7 @@ impl SelectedCheckpoint {
|
||||
job: RevisionJob,
|
||||
source: SourceFile,
|
||||
files: &mut Files,
|
||||
line_break_cache: Arc<texrra_tex_core::execution::LineBreakCache>,
|
||||
work: &mut EntryCheckpointWork,
|
||||
) -> Result<
|
||||
(
|
||||
@@ -388,6 +389,7 @@ impl SelectedCheckpoint {
|
||||
&checkpoint.entry,
|
||||
source,
|
||||
&mut recording,
|
||||
line_break_cache,
|
||||
|offset, pages| {
|
||||
if offset > frontier {
|
||||
schedule.select(offset, pages)
|
||||
|
||||
@@ -367,6 +367,56 @@ fn atomic_definition(p: &Path, revision: u64, body: &str) -> ProjectDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resumed_suffix_reuses_search_for_unchanged_paragraphs() {
|
||||
let p = directory("resumed-paragraphs");
|
||||
let original = "The first paragraph contains a few distinct words.";
|
||||
let changed =
|
||||
"The first paragraph now occupies a different number of lines in the measured box.";
|
||||
let body = format!(
|
||||
r"
|
||||
\hsize=82pt \parindent=0pt \tolerance=10000 \pretolerance=10000
|
||||
\rightskip=0pt plus20pt \parfillskip=0pt plus1fil
|
||||
\shipout\hbox{{Stable first page}}
|
||||
\shipout\vbox{{
|
||||
\noindent {original}\par
|
||||
\noindent Second material remains in place while the first text changes its length.\par
|
||||
\noindent Each reused break still lays out the paragraph from the current measured nodes.\par
|
||||
}}
|
||||
\end
|
||||
"
|
||||
);
|
||||
let project = ProjectSnapshot::new(atomic_definition(&p, 1, &body)).unwrap();
|
||||
let first_request = request(&p)
|
||||
.with_project(project.clone())
|
||||
.observe_generated_initial();
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let first = compiler.compile(first_request.clone()).unwrap();
|
||||
assert_eq!(first.pages.len(), 2);
|
||||
|
||||
let edit = format!("{HEADER}{}", body.replace(original, changed));
|
||||
let edited = project
|
||||
.with_file_edits(
|
||||
2,
|
||||
BTreeMap::from([(p.join("main.tex"), Arc::from(edit.into_bytes()))]),
|
||||
)
|
||||
.unwrap();
|
||||
let repeat = first_request.with_project(edited);
|
||||
let resumed = compiler.compile(repeat.clone()).unwrap();
|
||||
let full = NativeCompiler::default().compile(repeat).unwrap();
|
||||
assert!(resumed.entry_checkpoint_work.reused_steps > 0);
|
||||
assert!(resumed.line_break_work.reused_passes >= 2);
|
||||
assert!(resumed.line_break_work.examined_edges < full.line_break_work.examined_edges);
|
||||
assert_eq!(resumed.pdf, full.pdf);
|
||||
assert_eq!(resumed.pages, full.pages);
|
||||
assert_eq!(resumed.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(
|
||||
resumed.execution.execution_resources,
|
||||
full.execution.execution_resources
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn library_cli_bytes_final_resource_closure_and_immutable_revision_match() {
|
||||
let p = directory("closure");
|
||||
|
||||
Reference in new issue
Block a user