Reuse byte-verified source versions after checkpoint resume

This commit is contained in:
gloamxun committed 2026-11-20 13:02:50 +08:00
1 parent 0ff8597ab4
commit 592d1ef2a3
2 files changed
+43 -8

No files matched your search

@@ -41,13 +41,38 @@ impl RevisionExecution {
revision: u64,
execution: Execution,
resources: Option<crate::resources::ResourceTrace>,
) -> Self {
Self::with_previous_sources(revision, execution, resources, None)
}
fn with_previous_sources(
revision: u64,
execution: Execution,
resources: Option<crate::resources::ResourceTrace>,
previous: Option<&Self>,
) -> Self {
let source_versions = execution
.sources
.iter()
.map(|source| SourceVersion {
sha256: format!("{:x}", Sha256::digest(&source.data)),
bytes: source.data.len() as u64,
.enumerate()
.map(|(id, source)| {
// The previous result was built by this session. Match the
// scanned bytes, including generated and stream input.
previous
.and_then(|old| {
old.execution
.sources
.get(id)
.zip(old.source_versions.get(id))
})
.filter(|(old_source, _)| *old_source == source)
.map_or_else(
|| SourceVersion {
sha256: format!("{:x}", Sha256::digest(&source.data)),
bytes: source.data.len() as u64,
},
|(_, version)| version.clone(),
)
})
.collect();
Self {
@@ -166,7 +191,7 @@ impl RevisionJob {
let executed = executor
.with_cancellation(self.cancellation.clone())
.run_detailed(source, files);
self.finish_execution(executed, files)
self.finish_execution(executed, files, None)
}
/// Capture selected entry continuations while running the full revision.
@@ -181,7 +206,7 @@ impl RevisionJob {
let executed = executor
.with_cancellation(self.cancellation.clone())
.run_capturing_entries(source, files, select, capture);
self.finish_execution(executed, files)
self.finish_execution(executed, files, None)
}
/// Resume after the host has validated prefix dependencies and replayed
@@ -192,9 +217,10 @@ impl RevisionJob {
source: SourceFile,
files: &mut impl SourceProvider,
) -> Option<Result<Arc<RevisionExecution>, RevisionFailure>> {
let previous = self.session.latest();
let executed =
checkpoint.resume_after_host_replay(source, files, self.cancellation.clone())?;
Some(self.finish_execution(executed, files))
Some(self.finish_execution(executed, files, previous.as_deref()))
}
/// Resume a verified prefix and observe new boundaries in the executed suffix.
@@ -217,22 +243,24 @@ impl RevisionJob {
select,
capture,
)?;
Some(self.finish_execution(executed, files))
Some(self.finish_execution(executed, files, previous.as_deref()))
}
fn finish_execution(
self,
executed: Result<Execution, ExecutionFailure>,
files: &impl SourceProvider,
previous: Option<&RevisionExecution>,
) -> Result<Arc<RevisionExecution>, RevisionFailure> {
// Host observations can themselves supersede the revision. Do not
// invoke the host while holding the session publication lock.
let resources = files.execution_resource_trace().cloned();
let result = executed.map(|execution| {
Arc::new(RevisionExecution::from_execution(
Arc::new(RevisionExecution::with_previous_sources(
self.revision,
execution,
resources.clone(),
previous,
))
});
let mut state = self