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
@@ -454,6 +454,7 @@ impl EntryCheckpoint {
|
||||
self.resume_observed(source, None, files, cancellation, None, None, None,
|
||||
|_, _, _, _| CheckpointDecision::Continue)
|
||||
.expect("ordinary resume cannot reject a cached suffix")
|
||||
.map(|result| result.map(|execution| execution.finish_fingerprint(None)))
|
||||
}
|
||||
|
||||
pub(super) fn resume_capturing_sources_after_host_replay<F: SourceProvider, S>(
|
||||
@@ -481,6 +482,7 @@ impl EntryCheckpoint {
|
||||
}),
|
||||
)
|
||||
.expect("ordinary resume cannot reject a cached suffix")
|
||||
.map(|result| result.map(|execution| execution.finish_fingerprint(previous)))
|
||||
}
|
||||
|
||||
pub(super) fn resume_deciding_suffix<F: SourceProvider, S>(
|
||||
@@ -494,7 +496,7 @@ impl EntryCheckpoint {
|
||||
timings: Option<&mut CheckpointCloneTimings>,
|
||||
select: impl FnMut(CheckpointSource<'_>, usize) -> Option<S>,
|
||||
capture: impl FnMut(S, EntryCheckpoint, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
) -> Result<Option<Result<Execution<super::DeferredStateFingerprint>, ExecutionFailure>>, String> {
|
||||
let measured = timings.is_some().then(Cell::default);
|
||||
let result = self.resume_observed(
|
||||
source, nested, files, cancellation, Some(line_break_cache), previous, measured.as_ref(),
|
||||
@@ -516,7 +518,7 @@ impl EntryCheckpoint {
|
||||
previous: Option<&Execution>,
|
||||
timings: Option<&Cell<CheckpointCloneTimings>>,
|
||||
capture_boundary: impl FnMut(&mut Executor, usize, bool, &mut F) -> CheckpointDecision,
|
||||
) -> Result<Option<Result<Execution, ExecutionFailure>>, String> {
|
||||
) -> Result<Option<Result<Execution<super::DeferredStateFingerprint>, ExecutionFailure>>, String> {
|
||||
if !self.accepts_entry(&source)
|
||||
|| match &nested {
|
||||
Some(nested) => !self.accepts_nested_source(&nested.name, &nested.data),
|
||||
@@ -559,14 +561,15 @@ impl EntryCheckpoint {
|
||||
});
|
||||
let result = match result {
|
||||
Ok(CheckpointDecision::Reuse(execution)) => {
|
||||
return Ok(Some(Ok(*execution)));
|
||||
let fingerprint = super::DeferredStateFingerprint(Some(execution.outgoing_state));
|
||||
return Ok(Some(Ok(execution.with_outgoing_state(fingerprint))));
|
||||
}
|
||||
Ok(CheckpointDecision::ReplayFailed(error)) => return Err(error),
|
||||
Ok(CheckpointDecision::Continue) => Ok(()),
|
||||
Err(error) => Err(error),
|
||||
};
|
||||
let result = executor.finish_observed_input(result, files);
|
||||
Ok(Some(executor.finish_execution(result, self.incoming_state, previous)))
|
||||
Ok(Some(executor.prepare_execution(result, self.incoming_state, previous)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4083,11 +4086,21 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
fn finish_execution(
|
||||
mut self,
|
||||
self,
|
||||
result: Result<(), Error>,
|
||||
incoming_state: u64,
|
||||
previous: Option<&Execution>,
|
||||
) -> Result<Execution, ExecutionFailure> {
|
||||
self.prepare_execution(result, incoming_state, previous)
|
||||
.map(|execution| execution.finish_fingerprint(previous))
|
||||
}
|
||||
|
||||
fn prepare_execution(
|
||||
mut self,
|
||||
result: Result<(), Error>,
|
||||
incoming_state: u64,
|
||||
previous: Option<&Execution>,
|
||||
) -> Result<Execution<super::DeferredStateFingerprint>, ExecutionFailure> {
|
||||
let (reads, dependency_evidence) = self.take_dependency_reads();
|
||||
let result = result.and_then(|()| {
|
||||
if self.shipped_pages > 0 && !self.format_dumped
|
||||
@@ -4136,10 +4149,11 @@ impl Executor {
|
||||
}
|
||||
// An identical completed state has the same fingerprint. Compare
|
||||
// the entire state, including token source spans and assignments.
|
||||
let outgoing_state = match previous {
|
||||
Some(last) if last.state == self.state => last.outgoing_state,
|
||||
last => self.state.fingerprint_with_prior(last.map(|last| &last.state)),
|
||||
};
|
||||
let outgoing_state = super::DeferredStateFingerprint(
|
||||
previous
|
||||
.filter(|last| last.state == self.state)
|
||||
.map(|last| last.outgoing_state),
|
||||
);
|
||||
let format_pdf_images = self.captured_format_pdf_images();
|
||||
Ok(Execution {
|
||||
format_dumped: self.format_dumped,
|
||||
|
||||
@@ -102,7 +102,8 @@ pub(crate) use registers::print_scaled;
|
||||
pub use registers::{Flex, Glue, Register, RegisterKind, RegisterValue};
|
||||
pub use rule::NativeRule;
|
||||
pub use session::{
|
||||
NativeSession, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceVersion,
|
||||
NativeSession, PreparedRevisionExecution, ResumedExecution, RevisionError, RevisionExecution,
|
||||
RevisionFailure, RevisionJob, SourceVersion,
|
||||
};
|
||||
pub use state::{CommandName, LinePenaltyKind, Macro, Meaning, Primitive, Profile, Replacement, State};
|
||||
|
||||
@@ -653,7 +654,7 @@ fn default_interaction_mode() -> u8 {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Execution {
|
||||
pub struct Execution<F = u64> {
|
||||
#[serde(default)]
|
||||
pub format_dumped: bool,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
@@ -689,7 +690,7 @@ pub struct Execution {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
line_observations: Option<BTreeMap<usize, usize>>,
|
||||
pub incoming_state: u64,
|
||||
pub outgoing_state: u64,
|
||||
pub outgoing_state: F,
|
||||
pub steps: usize,
|
||||
/// Completed charge count for proving remaining box capacity at a splice.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -700,6 +701,55 @@ pub struct Execution {
|
||||
accounts_event_history: bool,
|
||||
}
|
||||
|
||||
/// The exact final state is available for layout. Its fingerprint may still
|
||||
/// require the canonical hash before a completed execution can be published.
|
||||
#[derive(Debug)]
|
||||
pub struct DeferredStateFingerprint(Option<u64>);
|
||||
|
||||
impl<F> Execution<F> {
|
||||
fn with_outgoing_state<T>(self, outgoing_state: T) -> Execution<T> {
|
||||
Execution {
|
||||
format_dumped: self.format_dumped,
|
||||
format_pdf_images: self.format_pdf_images,
|
||||
job_name: self.job_name,
|
||||
interaction_mode: self.interaction_mode,
|
||||
native_page: self.native_page,
|
||||
split_discards: self.split_discards,
|
||||
after_assignment: self.after_assignment,
|
||||
events: self.events,
|
||||
state: self.state,
|
||||
io: self.io,
|
||||
input_position: self.input_position,
|
||||
paragraph_mode: self.paragraph_mode,
|
||||
sources: self.sources,
|
||||
stream_sources: self.stream_sources,
|
||||
generated_inputs: self.generated_inputs,
|
||||
reads: self.reads,
|
||||
dependency_evidence: self.dependency_evidence,
|
||||
line_observations: self.line_observations,
|
||||
incoming_state: self.incoming_state,
|
||||
outgoing_state,
|
||||
steps: self.steps,
|
||||
box_nodes_created: self.box_nodes_created,
|
||||
reads_event_history: self.reads_event_history,
|
||||
accounts_event_history: self.accounts_event_history,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Execution<DeferredStateFingerprint> {
|
||||
fn needs_fingerprint(&self) -> bool {
|
||||
self.outgoing_state.0.is_none()
|
||||
}
|
||||
|
||||
fn finish_fingerprint(self, previous: Option<&Execution>) -> Execution {
|
||||
let fingerprint = self.outgoing_state.0.unwrap_or_else(|| {
|
||||
self.state.fingerprint_with_prior(previous.map(|prior| &prior.state))
|
||||
});
|
||||
self.with_outgoing_state(fingerprint)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ScannerStatus {
|
||||
#[default]
|
||||
@@ -806,7 +856,7 @@ impl fmt::Display for Error {
|
||||
}
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl Execution {
|
||||
impl<F> Execution<F> {
|
||||
/// Paint actual shipped boxes using their captured device state. No
|
||||
/// pagination or application of the job's final device settings.
|
||||
pub fn shipout_display_lists(&self) -> Result<Vec<crate::render::DisplayList>, Error> {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! used to infer an origin. Source IDs are local to this revision, including
|
||||
//! independent opens of the same input stream.
|
||||
use crate::{
|
||||
execution::{GeneratedInput, RevisionExecution, SourceVersion, Span, TokenOrigin},
|
||||
execution::{Execution, GeneratedInput, RevisionExecution, SourceVersion, Span, TokenOrigin},
|
||||
pdf_device::{Affine, PdfGraphics},
|
||||
provenance::PaintSource,
|
||||
render::{DisplayItem, DisplayList, DisplayUnits},
|
||||
@@ -227,14 +227,25 @@ impl SourceMap {
|
||||
pages: &[DisplayList],
|
||||
verify_source_hashes: bool,
|
||||
) -> Result<Self, String> {
|
||||
let execution = &revision.execution;
|
||||
if revision.source_versions.len() != execution.sources.len() {
|
||||
Self::from_execution_checked(
|
||||
revision.revision, &revision.execution, &revision.source_versions, pages, verify_source_hashes,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn from_execution_checked<F>(
|
||||
revision: u64,
|
||||
execution: &Execution<F>,
|
||||
source_versions: &[SourceVersion],
|
||||
pages: &[DisplayList],
|
||||
verify_source_hashes: bool,
|
||||
) -> Result<Self, String> {
|
||||
if source_versions.len() != execution.sources.len() {
|
||||
return Err("source map version table does not match execution".into());
|
||||
}
|
||||
let sources: Vec<_> = execution
|
||||
.sources
|
||||
.iter()
|
||||
.zip(&revision.source_versions)
|
||||
.zip(source_versions)
|
||||
.enumerate()
|
||||
.map(|(id, (file, version))| {
|
||||
if version.bytes != file.data.len() as u64
|
||||
@@ -542,7 +553,7 @@ impl SourceMap {
|
||||
mapped_pages.push(map);
|
||||
}
|
||||
Ok(Self {
|
||||
revision: revision.revision,
|
||||
revision,
|
||||
sources,
|
||||
pages: mapped_pages,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user