Reuse valid checkpoints across auxiliary file changes
This commit is contained in:
1 parent
3a3913a385
commit
e4a265ca6c
5 files changed
+233
-111
No files matched your search
@@ -1024,8 +1024,12 @@ CVPR 2026 使用原样项目、实际 BibTeX 输出、同一格式和字体资
|
||||
`500c5281a724a06ea2462e6bc09f61cbee02916ba269473f0f8cf87ddf2c06ae`。
|
||||
隔离补丁 SHA-256 为
|
||||
`bd28142360baa0d3a56f91ca8f1f769776fe11277bef737d04da4e8ec1f251c3`。
|
||||
已将隔离补丁应用到单独的当前主线工作树,合并后完整工作区回归
|
||||
进行中。CVPR 的复用步数独立于 A4 100 ms 可见延迟门禁。
|
||||
与主线来源映射实现组合后,4项检查点守卫和38项原生编译发布
|
||||
测试通过,零失败,一项保留手动验证。按四份确切源码指纹合入
|
||||
主线。组合版全工作区作业在构建时停止,保留已通过的1628项
|
||||
工作区基线和本次日志。组合定向回执为
|
||||
`main-directed-guard.log`、`main-directed-pipeline.log`。
|
||||
CVPR 的复用步数独立于 A4 100 ms 可见延迟门禁。
|
||||
|
||||
### TeX 输入的默认扩展名候选
|
||||
|
||||
|
||||
+8
-19
@@ -934,31 +934,20 @@ impl CompileJob {
|
||||
.filter(|_| checkpoint_guard::can_stage(&request));
|
||||
let format_cache = &self.compiler.format_cache;
|
||||
let mut entry_checkpoint_work = EntryCheckpointWork::default();
|
||||
let mut active_checkpoint =
|
||||
checkpoints
|
||||
.and_then(CheckpointCache::current)
|
||||
.and_then(|available| match available.select(&request) {
|
||||
Ok(selected) => Some(selected),
|
||||
Err(error) => {
|
||||
entry_checkpoint_work.rejection = Some(error);
|
||||
None
|
||||
}
|
||||
});
|
||||
let prepared = match active_checkpoint.as_ref() {
|
||||
Some(candidate) => {
|
||||
match candidate.prepare(&request, format_cache, &cancellation, evidence) {
|
||||
Ok(prepared) => Some(prepared),
|
||||
let (active_checkpoint, prepared) =
|
||||
if let Some(available) = checkpoints.and_then(CheckpointCache::current) {
|
||||
match available.prepare(&request, format_cache, &cancellation, evidence) {
|
||||
Ok((selected, prepared)) => (Some(selected), Some(prepared)),
|
||||
Err(error) => {
|
||||
check(&cancellation)?;
|
||||
*evidence = AttemptEvidence::new(revision);
|
||||
entry_checkpoint_work.rejection = Some(error.to_string());
|
||||
active_checkpoint = None;
|
||||
None
|
||||
(None, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
let PreparedJob {
|
||||
executor,
|
||||
format_preparation,
|
||||
|
||||
+209
-89
@@ -170,8 +170,13 @@ impl<'a> CapturedEntries<'a> {
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let Ok(guard) = PrefixInputGuard::capture(self.request, path, trace, initial.clone())
|
||||
else {
|
||||
let Ok(guard) = PrefixInputGuard::capture(
|
||||
self.request,
|
||||
path,
|
||||
trace,
|
||||
host.generated_outputs(),
|
||||
initial.clone(),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
self.retain(
|
||||
@@ -306,24 +311,92 @@ impl CheckpointCache {
|
||||
}
|
||||
|
||||
impl PublishedCheckpoints {
|
||||
pub(super) fn select(&self, request: &CompileRequest) -> Result<SelectedCheckpoint, String> {
|
||||
let current = self.current.clone().select(request);
|
||||
let Some(previous) = &self.previous_body else {
|
||||
return current;
|
||||
};
|
||||
let completed = current
|
||||
.as_ref()
|
||||
.map_or(0, SelectedCheckpoint::completed_steps);
|
||||
if previous
|
||||
.entries
|
||||
.last()
|
||||
.is_some_and(|entry| entry.entry.completed_steps() > completed)
|
||||
&& let Ok(previous) = previous.clone().select(request)
|
||||
&& previous.completed_steps() > completed
|
||||
{
|
||||
return Ok(previous);
|
||||
pub(super) fn prepare(
|
||||
&self,
|
||||
request: &CompileRequest,
|
||||
cache: &FormatCache,
|
||||
cancellation: &Cancellation,
|
||||
evidence: &mut AttemptEvidence,
|
||||
) -> Result<(SelectedCheckpoint, PreparedJob), CompileError> {
|
||||
let project = request
|
||||
.project
|
||||
.as_deref()
|
||||
.ok_or_else(|| CompileError::Host("checkpoint requires an atomic project".into()))?;
|
||||
let mut candidates: Vec<_> = self
|
||||
.current
|
||||
.candidates()
|
||||
.chain(self.previous_body.iter().flat_map(|body| body.candidates()))
|
||||
.collect();
|
||||
candidates.sort_by_key(|candidate| std::cmp::Reverse(candidate.completed_steps()));
|
||||
let mut candidates = candidates.into_iter();
|
||||
let mut rejection = None;
|
||||
let first = candidates
|
||||
.by_ref()
|
||||
.find(|candidate| {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(_) => true,
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
CompileError::Host(
|
||||
rejection.unwrap_or_else(|| "no entry checkpoint retained".into()),
|
||||
)
|
||||
})?;
|
||||
|
||||
// Host preparation observes the actual generated files while the job
|
||||
// lock is held. Choose a valid prefix before replaying any effects.
|
||||
let mut selected = None;
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
evidence,
|
||||
Some(Box::new(|world, preparation| {
|
||||
let mut rejection = None;
|
||||
for candidate in std::iter::once(first).chain(candidates) {
|
||||
let checkpoint = &candidate.set.entries[candidate.index];
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify(request, world, preparation))
|
||||
{
|
||||
Ok(()) => {
|
||||
selected = Some(candidate);
|
||||
return Ok(());
|
||||
}
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
let selected = selected.expect("resume preparation chose a verified checkpoint");
|
||||
let checkpoint = &selected.set.entries[selected.index];
|
||||
for call in &selected.set.calls[..checkpoint.replay_count] {
|
||||
check(cancellation)?;
|
||||
call(&mut prepared.files)?;
|
||||
}
|
||||
current
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
{
|
||||
checkpoint.guard.verify_replayed_lookups(&prepared.files)?;
|
||||
}
|
||||
Ok((selected, prepared))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,27 +426,13 @@ impl CheckpointSet {
|
||||
work.captured_frontier = self.entries.last().map(|entry| entry.entry.frontier());
|
||||
}
|
||||
|
||||
pub(super) fn select(
|
||||
self: Arc<Self>,
|
||||
request: &CompileRequest,
|
||||
) -> Result<SelectedCheckpoint, String> {
|
||||
let project = request
|
||||
.project
|
||||
.as_deref()
|
||||
.ok_or("checkpoint requires an atomic project")?;
|
||||
let mut rejection = None;
|
||||
for (index, checkpoint) in self.entries.iter().enumerate().rev() {
|
||||
match checkpoint
|
||||
.accept_entry(project)
|
||||
.and_then(|()| checkpoint.guard.verify_project(request))
|
||||
{
|
||||
Ok(_) => return Ok(SelectedCheckpoint { set: self, index }),
|
||||
Err(error) => {
|
||||
rejection.get_or_insert(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(rejection.unwrap_or_else(|| "no entry checkpoint retained".into()))
|
||||
fn candidates(self: &Arc<Self>) -> impl Iterator<Item = SelectedCheckpoint> + '_ {
|
||||
(0..self.entries.len())
|
||||
.rev()
|
||||
.map(|index| SelectedCheckpoint {
|
||||
set: Arc::clone(self),
|
||||
index,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,50 +456,6 @@ impl SelectedCheckpoint {
|
||||
self.set.entries[self.index].entry.completed_steps()
|
||||
}
|
||||
|
||||
pub(super) fn prepare(
|
||||
&self,
|
||||
request: &CompileRequest,
|
||||
cache: &FormatCache,
|
||||
cancellation: &Cancellation,
|
||||
evidence: &mut AttemptEvidence,
|
||||
) -> Result<PreparedJob, CompileError> {
|
||||
let checkpoint = &self.set.entries[self.index];
|
||||
let mut prepared = prepare_checked(
|
||||
request,
|
||||
false,
|
||||
Some(cache),
|
||||
cancellation,
|
||||
evidence,
|
||||
Some(Box::new(|world, preparation| {
|
||||
checkpoint.guard.verify(request, world, preparation)?;
|
||||
checkpoint.accept_entry(
|
||||
world
|
||||
.project()
|
||||
.ok_or("checkpoint requires an atomic project")?,
|
||||
)
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
for call in &self.set.calls[..checkpoint.replay_count] {
|
||||
check(cancellation)?;
|
||||
call(&mut prepared.files)?;
|
||||
}
|
||||
let project = request
|
||||
.project
|
||||
.as_deref()
|
||||
.expect("validated atomic project");
|
||||
if !checkpoint
|
||||
.guard
|
||||
.project
|
||||
.immutable_paths()
|
||||
.eq(project.immutable_paths())
|
||||
{
|
||||
checkpoint.guard.verify_replayed_lookups(&prepared.files)?;
|
||||
}
|
||||
Ok(prepared)
|
||||
}
|
||||
|
||||
pub(super) fn resume(
|
||||
self,
|
||||
request: &CompileRequest,
|
||||
@@ -519,6 +534,7 @@ struct PrefixInputGuard {
|
||||
initial: GeneratedInitialState,
|
||||
entry: PathBuf,
|
||||
immutable: BTreeSet<PathBuf>,
|
||||
generated: BTreeSet<PathBuf>,
|
||||
lookups: Vec<ResourceLookup>,
|
||||
clock_environment: Option<[Option<OsString>; 3]>,
|
||||
}
|
||||
@@ -532,6 +548,7 @@ impl PrefixInputGuard {
|
||||
request: &CompileRequest,
|
||||
entry: &Path,
|
||||
trace: &ResourceTrace,
|
||||
written: &BTreeSet<PathBuf>,
|
||||
initial: GeneratedInitialState,
|
||||
) -> Result<Self, String> {
|
||||
let project = request
|
||||
@@ -566,16 +583,26 @@ impl PrefixInputGuard {
|
||||
.map(|item| item.target.as_path()),
|
||||
);
|
||||
let mut immutable = BTreeSet::new();
|
||||
let mut generated = BTreeSet::new();
|
||||
for path in tracked {
|
||||
if project.file(path).is_some() {
|
||||
immutable.insert(path.to_path_buf());
|
||||
} else if !initial.files().contains_key(path) {
|
||||
} else if initial.files().contains_key(path) {
|
||||
generated.insert(path.to_path_buf());
|
||||
} else {
|
||||
return Err(format!(
|
||||
"checkpoint input has no stable initial role: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
// Opening a generated output observes its pre-write version.
|
||||
generated.extend(
|
||||
written
|
||||
.iter()
|
||||
.filter(|path| initial.files().contains_key(*path))
|
||||
.cloned(),
|
||||
);
|
||||
for observed in &trace.file_modifications {
|
||||
if project.file(&observed.path).is_none() {
|
||||
return Err("checkpoint file date requires a captured immutable resource".into());
|
||||
@@ -588,6 +615,7 @@ impl PrefixInputGuard {
|
||||
initial,
|
||||
entry: entry.to_path_buf(),
|
||||
immutable,
|
||||
generated,
|
||||
lookups: trace.lookups.clone(),
|
||||
clock_environment: (!trace.file_modifications.is_empty()).then(date_environment),
|
||||
})
|
||||
@@ -665,7 +693,21 @@ impl PrefixInputGuard {
|
||||
.generated_initial
|
||||
.as_ref()
|
||||
.ok_or("checkpoint requires generated versions observed under the job lock")?;
|
||||
self.initial.check(current)
|
||||
if self.initial.cwd() != current.cwd() {
|
||||
return Err("generated initial workdir differs from the actual host".into());
|
||||
}
|
||||
for path in self.initial.files().keys().chain(current.files().keys()) {
|
||||
let before = self.initial.files().get(path);
|
||||
let after = current.files().get(path);
|
||||
let same_presence = before.map(Option::is_some) == after.map(Option::is_some);
|
||||
if !same_presence || (self.generated.contains(path) && before != after) {
|
||||
return Err(format!(
|
||||
"generated initial role or version mismatch: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,10 +800,14 @@ fn prefix_guard_checks_actual_dependencies_and_preserves_live_artifacts_on_rejec
|
||||
executor
|
||||
.unwrap()
|
||||
.run_capturing_entry(source, &mut recording, PREFIX.len() - 25, |host| {
|
||||
(host.capture(), host.resource_usage().unwrap().unwrap())
|
||||
(
|
||||
host.capture(),
|
||||
host.resource_usage().unwrap().unwrap(),
|
||||
host.generated_outputs().clone(),
|
||||
)
|
||||
});
|
||||
assert!(executed.is_ok());
|
||||
let (checkpoint, (recorded, usage)) = checkpoint.unwrap();
|
||||
let (checkpoint, (recorded, usage, written)) = checkpoint.unwrap();
|
||||
let (calls, trace) = recorded.unwrap();
|
||||
assert_eq!(usage.open_outputs, Some(1));
|
||||
assert!(
|
||||
@@ -770,7 +816,9 @@ fn prefix_guard_checks_actual_dependencies_and_preserves_live_artifacts_on_rejec
|
||||
.iter()
|
||||
.any(|lookup| lookup.name == "optional.tex" && lookup.resolved.is_none())
|
||||
);
|
||||
let guard = PrefixInputGuard::capture(&request, &entry, &trace, initial).unwrap();
|
||||
let guard = PrefixInputGuard::capture(&request, &entry, &trace, &written, initial).unwrap();
|
||||
assert!(guard.generated.contains(&aux));
|
||||
assert!(!guard.generated.contains(&seed));
|
||||
assert!(guard.immutable.contains(&library));
|
||||
assert!(!guard.immutable.contains(&unrelated));
|
||||
assert!(!guard.immutable.contains(&entry));
|
||||
@@ -1413,6 +1461,78 @@ fn immutable_file_creation_and_removal_replay_real_lookup_results() {
|
||||
assert_eq!(pdfs.values().collect::<BTreeSet<_>>().len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_input_change_uses_a_checkpoint_before_the_read() {
|
||||
let cwd = std::env::temp_dir().join(format!("texrra-generated-prefix-{}", std::process::id()));
|
||||
fs::create_dir(&cwd).unwrap();
|
||||
let cwd = cwd.canonicalize().unwrap();
|
||||
let entry = cwd.join("main.tex");
|
||||
let aux = cwd.join("observed.aux");
|
||||
fs::write(&aux, b"\\def\\widthfromaux{11}\n").unwrap();
|
||||
let source = format!(
|
||||
"\\catcode123=1 \\catcode125=2\n{}\\input observed.aux\n{}\\shipout\\hbox{{\\vrule width\\widthfromaux pt height1pt}}\n\\end",
|
||||
"\\advance\\count0 by 1\\relax\n".repeat(20),
|
||||
"\\advance\\count0 by 1\\relax\n".repeat(12),
|
||||
);
|
||||
let input_offset = source.find("\\input observed.aux").unwrap();
|
||||
let mut world = WorldConfig::new(&cwd);
|
||||
world.input_policy = texrra_tex_core::resources::InputPolicy::Tex;
|
||||
let project = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: BTreeSet::from([cwd.clone()]),
|
||||
files: BTreeMap::from([(entry, Arc::from(source.into_bytes()))]),
|
||||
directories: BTreeSet::new(),
|
||||
aliases: BTreeMap::new(),
|
||||
generated_roots: BTreeSet::from([cwd.clone()]),
|
||||
generated: BTreeSet::from([aux.clone()]),
|
||||
})
|
||||
.unwrap();
|
||||
let mut request = CompileRequest::new(
|
||||
world,
|
||||
"main.tex",
|
||||
"main.pdf",
|
||||
JobTime::new(2026, 11, 20, 540)
|
||||
.unwrap()
|
||||
.with_pdf_clock(0, 0)
|
||||
.unwrap(),
|
||||
)
|
||||
.with_project(project)
|
||||
.observe_generated_initial();
|
||||
request.entry = Entry::Initex;
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let original = session.compile(request.clone()).unwrap();
|
||||
let last = original.entry_checkpoint_work.captured_frontier.unwrap();
|
||||
assert!(last > input_offset);
|
||||
|
||||
fs::write(&aux, b"\\def\\widthfromaux{22}\n").unwrap();
|
||||
let updated = session.compile(request.clone()).unwrap();
|
||||
let full = NativeCompiler::default().compile(request).unwrap();
|
||||
let work = &updated.entry_checkpoint_work;
|
||||
assert!(work.reused_steps > 0, "{work:?}");
|
||||
assert!(work.reused_frontier.unwrap() < last, "{work:?}");
|
||||
for (document, width) in [(&original, 11_i64), (&updated, 22)] {
|
||||
let rules: Vec<_> = document
|
||||
.pages
|
||||
.iter()
|
||||
.flat_map(|page| &page.items)
|
||||
.filter_map(|item| match item {
|
||||
texrra_tex_core::render::DisplayItem::Rule { width, height, .. } => {
|
||||
Some((*width, *height))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(rules, [(width * 65_536, 65_536)]);
|
||||
}
|
||||
assert_ne!(updated.pdf, original.pdf);
|
||||
assert_eq!(updated.pdf, full.pdf);
|
||||
assert_eq!(updated.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(updated.source_map.pages, full.source_map.pages);
|
||||
assert!(updated.execution.execution == full.execution.execution);
|
||||
assert_eq!(fs::read(&aux).unwrap(), b"\\def\\widthfromaux{22}\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn automatic_checkpoints_follow_successive_edits_at_different_frontiers() {
|
||||
let cwd = std::env::temp_dir().join(format!("texrra-rolling-{}", std::process::id()));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Capture and verify the native host calls made by an entry prefix.
|
||||
use super::*;
|
||||
use std::fmt::Debug;
|
||||
use std::{collections::BTreeSet, fmt::Debug};
|
||||
#[cfg(test)]
|
||||
use std::{fs, path::Path};
|
||||
#[cfg(test)]
|
||||
@@ -42,6 +42,10 @@ impl<'a> RecordingHost<'a> {
|
||||
(count < MAX_REPLAY_CALLS).then(|| (self.files.resource_trace(), count))
|
||||
}
|
||||
|
||||
pub(super) fn generated_outputs(&self) -> &BTreeSet<PathBuf> {
|
||||
self.files.generated_outputs()
|
||||
}
|
||||
|
||||
pub(super) fn into_calls(self) -> Option<Vec<Call>> {
|
||||
self.calls
|
||||
}
|
||||
|
||||
@@ -638,6 +638,11 @@ impl Files {
|
||||
.borrow_mut()
|
||||
.operation(name, path, result);
|
||||
}
|
||||
|
||||
pub(super) fn generated_outputs(&self) -> &BTreeSet<PathBuf> {
|
||||
&self.generated_written
|
||||
}
|
||||
|
||||
pub fn resource_trace(&self) -> &texrra_tex_core::resources::ResourceTrace {
|
||||
self.world.trace()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user