Let resumed SVG drafts precede a new final-state fingerprint
This commit is contained in:
1 parent
1a2379a6c2
commit
58b0f16998
9 files changed
+519
-84
No files matched your search
@@ -1,9 +1,11 @@
|
||||
//! Revision-gated publication for native executions.
|
||||
use crate::resources::ResourceTrace;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::{
|
||||
Cancellation, CheckpointCloneTimings, EntryCheckpoint, Error, Execution, ExecutionFailure,
|
||||
Cancellation, CheckpointCloneTimings, DeferredStateFingerprint, EntryCheckpoint, Error,
|
||||
Execution, ExecutionFailure,
|
||||
Executor, LineBreakCache,
|
||||
SourceFile, SourceProvider,
|
||||
};
|
||||
@@ -33,7 +35,7 @@ pub struct RevisionExecution {
|
||||
/// Versions of the actual scanned bytes, indexed by span source ID.
|
||||
pub source_versions: Vec<SourceVersion>,
|
||||
/// The host trace through execution. PDF embedding may read more resources later.
|
||||
pub execution_resources: Option<crate::resources::ResourceTrace>,
|
||||
pub execution_resources: Option<ResourceTrace>,
|
||||
}
|
||||
impl RevisionExecution {
|
||||
/// Attach actual source identities to a completed kernel result. This does
|
||||
@@ -41,7 +43,7 @@ impl RevisionExecution {
|
||||
pub fn from_execution(
|
||||
revision: u64,
|
||||
execution: Execution,
|
||||
resources: Option<crate::resources::ResourceTrace>,
|
||||
resources: Option<ResourceTrace>,
|
||||
) -> Self {
|
||||
Self::with_previous_sources(revision, execution, resources, None)
|
||||
}
|
||||
@@ -49,10 +51,20 @@ impl RevisionExecution {
|
||||
fn with_previous_sources(
|
||||
revision: u64,
|
||||
execution: Execution,
|
||||
resources: Option<crate::resources::ResourceTrace>,
|
||||
resources: Option<ResourceTrace>,
|
||||
previous: Option<&Self>,
|
||||
) -> Self {
|
||||
let source_versions = execution
|
||||
let source_versions = Self::source_versions(&execution, previous);
|
||||
Self {
|
||||
revision,
|
||||
execution,
|
||||
source_versions,
|
||||
execution_resources: resources,
|
||||
}
|
||||
}
|
||||
|
||||
fn source_versions<F>(execution: &Execution<F>, previous: Option<&Self>) -> Vec<SourceVersion> {
|
||||
execution
|
||||
.sources
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -75,12 +87,58 @@ impl RevisionExecution {
|
||||
|(_, version)| version.clone(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
Self {
|
||||
revision,
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Successful resumed kernel output whose final state digest is still pending.
|
||||
pub struct PreparedRevisionExecution {
|
||||
job: RevisionJob,
|
||||
execution: Execution<DeferredStateFingerprint>,
|
||||
source_versions: Vec<SourceVersion>,
|
||||
resources: Option<ResourceTrace>,
|
||||
previous: Option<Arc<RevisionExecution>>,
|
||||
}
|
||||
|
||||
impl PreparedRevisionExecution {
|
||||
pub fn execution(&self) -> &Execution<DeferredStateFingerprint> {
|
||||
&self.execution
|
||||
}
|
||||
|
||||
pub fn source_map(
|
||||
&self,
|
||||
pages: &[crate::render::DisplayList],
|
||||
) -> Result<crate::source_map::SourceMap, String> {
|
||||
crate::source_map::SourceMap::from_execution_checked(
|
||||
self.job.revision, &self.execution, &self.source_versions, pages, false,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> Result<Arc<RevisionExecution>, RevisionFailure> {
|
||||
let execution = self.execution.finish_fingerprint(
|
||||
self.previous.as_deref().map(|revision| &revision.execution),
|
||||
);
|
||||
let complete = Arc::new(RevisionExecution {
|
||||
revision: self.job.revision,
|
||||
execution,
|
||||
source_versions,
|
||||
execution_resources: resources,
|
||||
source_versions: self.source_versions,
|
||||
execution_resources: self.resources,
|
||||
});
|
||||
self.job.publish_execution(Ok(complete), None)
|
||||
}
|
||||
}
|
||||
|
||||
/// A resumed result may be used for a draft before its receipt is finalized.
|
||||
pub enum ResumedExecution {
|
||||
Complete(Arc<RevisionExecution>),
|
||||
Prepared(Box<PreparedRevisionExecution>),
|
||||
}
|
||||
|
||||
impl ResumedExecution {
|
||||
fn finish(self) -> Result<Arc<RevisionExecution>, RevisionFailure> {
|
||||
match self {
|
||||
Self::Complete(result) => Ok(result),
|
||||
Self::Prepared(prepared) => prepared.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +162,7 @@ pub struct RevisionFailure {
|
||||
/// Execution can finish just before its revision is superseded. It still
|
||||
/// must not be published as the current successful execution.
|
||||
pub completed_execution: Option<Arc<RevisionExecution>>,
|
||||
pub resources: Option<crate::resources::ResourceTrace>,
|
||||
pub resources: Option<ResourceTrace>,
|
||||
}
|
||||
|
||||
impl NativeSession {
|
||||
@@ -324,12 +382,59 @@ impl RevisionJob {
|
||||
select: impl FnMut(super::CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> super::CheckpointDecision,
|
||||
) -> Result<Option<Result<Arc<RevisionExecution>, RevisionFailure>>, String> {
|
||||
Ok(self.resume_deciding_suffix_prepared(
|
||||
checkpoint, source, nested, files, line_break_cache, timings, false, select, capture,
|
||||
)?.map(|result| result.and_then(ResumedExecution::finish)))
|
||||
}
|
||||
|
||||
/// Resume in the editor, with the option to compute a new final digest
|
||||
/// after consuming the verified output for a draft preview.
|
||||
pub fn resume_deciding_suffix_prepared<F: SourceProvider, S>(
|
||||
&self,
|
||||
checkpoint: &EntryCheckpoint,
|
||||
source: SourceFile,
|
||||
nested: Option<SourceFile>,
|
||||
files: &mut F,
|
||||
line_break_cache: Arc<LineBreakCache>,
|
||||
timings: Option<&mut CheckpointCloneTimings>,
|
||||
defer_fingerprint: bool,
|
||||
select: impl FnMut(super::CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> super::CheckpointDecision,
|
||||
) -> Result<Option<Result<ResumedExecution, RevisionFailure>>, String> {
|
||||
let previous = self.session.latest();
|
||||
let executed = checkpoint.resume_deciding_suffix(
|
||||
source, nested, files, self.cancellation.clone(), line_break_cache,
|
||||
previous.as_deref().map(|item| &item.execution), timings, select, capture,
|
||||
)?;
|
||||
Ok(executed.map(|result| self.finish_execution(result, files, previous.as_deref())))
|
||||
Ok(executed.map(|result| {
|
||||
match result {
|
||||
Ok(execution)
|
||||
if defer_fingerprint && execution.needs_fingerprint()
|
||||
&& !self.cancellation.is_cancelled() =>
|
||||
{
|
||||
let resources = files.execution_resource_trace().cloned();
|
||||
let source_versions = RevisionExecution::source_versions(&execution, previous.as_deref());
|
||||
Ok(ResumedExecution::Prepared(Box::new(PreparedRevisionExecution {
|
||||
job: RevisionJob {
|
||||
session: self.session.clone(),
|
||||
revision: self.revision,
|
||||
cancellation: self.cancellation.clone(),
|
||||
},
|
||||
execution,
|
||||
source_versions,
|
||||
resources,
|
||||
previous,
|
||||
})))
|
||||
}
|
||||
result => {
|
||||
let executed = result.map(|execution| execution.finish_fingerprint(
|
||||
previous.as_deref().map(|item| &item.execution),
|
||||
));
|
||||
self.finish_execution(executed, files, previous.as_deref())
|
||||
.map(ResumedExecution::Complete)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/// Publish a completed result after the caller verifies the same inputs
|
||||
@@ -359,6 +464,14 @@ impl RevisionJob {
|
||||
previous,
|
||||
))
|
||||
});
|
||||
self.publish_execution(result, resources)
|
||||
}
|
||||
|
||||
fn publish_execution(
|
||||
&self,
|
||||
result: Result<Arc<RevisionExecution>, ExecutionFailure>,
|
||||
resources: Option<ResourceTrace>,
|
||||
) -> Result<Arc<RevisionExecution>, RevisionFailure> {
|
||||
let mut state = self
|
||||
.session
|
||||
.state
|
||||
|
||||
Reference in new issue
Block a user