Resume native editor jobs through verified checkpoints
This commit is contained in:
1 parent
31364ae33e
commit
0abf700817
19 files changed
+2311
-93
No files matched your search
+169
-41
@@ -1,18 +1,27 @@
|
||||
//! Shared strict Route-D compilation, resource closure and revision publication.
|
||||
//! No process cwd changes, legacy frontend, or external TeX compilation.
|
||||
#[path = "native_checkpoint_guard.rs"]
|
||||
mod checkpoint_guard;
|
||||
#[path = "native_checkpoint_probe.rs"]
|
||||
mod checkpoint_probe;
|
||||
|
||||
pub use crate::native_generated::{GeneratedInitialState, GeneratedInputPolicy};
|
||||
pub use crate::native_host::{
|
||||
HostMetadata, HostObservation, HostPreparation, HostPreparationPhase, LedgerRead,
|
||||
VersionExpectation,
|
||||
};
|
||||
pub use crate::native_job::job_time;
|
||||
use crate::native_job::{Files, PreparedOutput, absolute_output, file_modification_date};
|
||||
use crate::native_job::{
|
||||
EffectMode, Files, PreparedInputsCheck, PreparedOutput, absolute_output, file_modification_date,
|
||||
};
|
||||
use crate::native_preview::PreviewState;
|
||||
pub use crate::native_preview::{PreviewPage, PreviewUpdate};
|
||||
pub use crate::native_stream::{
|
||||
DescriptorIdentity, InputOpened, InputStorage, ReleaseCause, StreamEffect, StreamEvent,
|
||||
StreamJournal, WriteAttempt, WriteOutcome,
|
||||
};
|
||||
use checkpoint_guard::CheckpointCache;
|
||||
pub use checkpoint_guard::EntryCheckpointWork;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
@@ -22,14 +31,14 @@ pub use texrra_tex_core::resources::{WorldFailure, WorldObservation};
|
||||
use texrra_tex_core::{
|
||||
execution::{
|
||||
Cancellation, ExecutionFailure, Executor, FormatImage, InputProfile, JobTime, Limits,
|
||||
NativeSession, RevisionError, RevisionExecution, RevisionJob, SourceFile, SourceProvider,
|
||||
State,
|
||||
NativeSession, RevisionError, RevisionExecution, RevisionFailure, RevisionJob, SourceFile,
|
||||
SourceProvider, State,
|
||||
},
|
||||
render::DisplayList,
|
||||
resources::{FileWorld, InputSnapshot, ResourceTrace, ResourceVersion, WorldConfig},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Entry {
|
||||
Bootstrap,
|
||||
Initex,
|
||||
@@ -172,6 +181,7 @@ pub struct ResourceSnapshot {
|
||||
|
||||
pub struct CompiledDocument {
|
||||
pub execution: Arc<RevisionExecution>,
|
||||
pub entry_checkpoint_work: EntryCheckpointWork,
|
||||
pub format_preparation: Option<FormatPreparation>,
|
||||
/// Actual paragraph search performed or reused in this revision.
|
||||
pub line_break_work: texrra_tex_core::execution::LineBreakWork,
|
||||
@@ -506,6 +516,7 @@ pub struct NativeCompiler {
|
||||
jobs: Arc<Mutex<()>>,
|
||||
format_cache: Arc<FormatCache>,
|
||||
line_break_cache: Arc<texrra_tex_core::execution::LineBreakCache>,
|
||||
entry_checkpoints: Option<Arc<CheckpointCache>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -535,6 +546,14 @@ pub struct CompileJob {
|
||||
job: RevisionJob,
|
||||
}
|
||||
impl NativeCompiler {
|
||||
/// Enable entry-prefix reuse for atomic project shipout jobs. The byte
|
||||
/// position is a lower bound for a physical command boundary to retain.
|
||||
/// Invalidated prefixes use the same full compiler in the same revision.
|
||||
pub fn with_entry_checkpoints(mut self, minimum_frontier: usize) -> Self {
|
||||
self.entry_checkpoints = Some(Arc::new(CheckpointCache::new(minimum_frontier)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn start(&self) -> CompileJob {
|
||||
CompileJob {
|
||||
compiler: self.clone(),
|
||||
@@ -574,9 +593,36 @@ fn prepare(
|
||||
format_cache: Option<&FormatCache>,
|
||||
cancellation: &Cancellation,
|
||||
evidence: &mut AttemptEvidence,
|
||||
) -> Result<PreparedJob, CompileError> {
|
||||
prepare_checked(
|
||||
request,
|
||||
dump,
|
||||
format_cache,
|
||||
cancellation,
|
||||
evidence,
|
||||
None,
|
||||
EffectMode::Live,
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_checked(
|
||||
request: &CompileRequest,
|
||||
dump: bool,
|
||||
format_cache: Option<&FormatCache>,
|
||||
cancellation: &Cancellation,
|
||||
evidence: &mut AttemptEvidence,
|
||||
check_inputs: Option<Box<PreparedInputsCheck<'_>>>,
|
||||
effects: EffectMode,
|
||||
) -> Result<PreparedJob, CompileError> {
|
||||
use texrra_tex_core::resources::ResourceKind;
|
||||
check(cancellation)?;
|
||||
if effects == EffectMode::Draft
|
||||
&& (dump || request.layout_manifest.is_some() || request.resource_manifest.is_some())
|
||||
{
|
||||
return Err(CompileError::Host(
|
||||
"draft effects require a document job without external reports".into(),
|
||||
));
|
||||
}
|
||||
if request.layout_manifest.is_some() && (dump || request.target != Target::Shipouts) {
|
||||
return Err(CompileError::Host(
|
||||
"--layout-manifest requires a native document job".into(),
|
||||
@@ -726,6 +772,8 @@ fn prepare(
|
||||
request.terminal,
|
||||
&request.generated_inputs,
|
||||
&mut evidence.host_preparation,
|
||||
check_inputs,
|
||||
effects,
|
||||
)
|
||||
.map_err(|failure| {
|
||||
evidence.trace = Some(failure.trace);
|
||||
@@ -762,8 +810,14 @@ impl CompileJob {
|
||||
}
|
||||
pub fn compile_detailed(
|
||||
self,
|
||||
request: CompileRequest,
|
||||
mut request: CompileRequest,
|
||||
) -> Result<Arc<CompiledDocument>, CompileFailure> {
|
||||
if self.compiler.entry_checkpoints.is_some()
|
||||
&& checkpoint_guard::can_stage(&request)
|
||||
&& matches!(&request.generated_inputs, GeneratedInputPolicy::Live)
|
||||
{
|
||||
request.generated_inputs = GeneratedInputPolicy::Observe;
|
||||
}
|
||||
let mut evidence = AttemptEvidence::new(self.revision());
|
||||
let summary = AttemptRequest::from(&request);
|
||||
match self.compile_observed(request, &mut evidence) {
|
||||
@@ -787,29 +841,64 @@ impl CompileJob {
|
||||
.map_err(|_| CompileError::Host("native job queue poisoned".into()))?;
|
||||
let revision = self.job.revision();
|
||||
evidence.phase = AttemptPhase::Preparing;
|
||||
let checkpoints = self
|
||||
.compiler
|
||||
.entry_checkpoints
|
||||
.as_deref()
|
||||
.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);
|
||||
let prepared = match active_checkpoint.as_ref() {
|
||||
Some(candidate) => {
|
||||
match candidate.prepare(&request, format_cache, &cancellation, evidence) {
|
||||
Ok(prepared) => Some(prepared),
|
||||
Err(error) => {
|
||||
check(&cancellation)?;
|
||||
*evidence = AttemptEvidence::new(revision);
|
||||
entry_checkpoint_work.rejection = Some(error.to_string());
|
||||
active_checkpoint = None;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let PreparedJob {
|
||||
executor,
|
||||
format_preparation,
|
||||
source,
|
||||
mut files,
|
||||
files,
|
||||
output,
|
||||
} = prepare(
|
||||
&request,
|
||||
false,
|
||||
Some(&self.compiler.format_cache),
|
||||
&cancellation,
|
||||
evidence,
|
||||
)
|
||||
.map_err(|error| {
|
||||
if cancellation.is_cancelled() {
|
||||
CompileError::Cancelled
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?;
|
||||
} = if let Some(prepared) = prepared {
|
||||
prepared
|
||||
} else {
|
||||
prepare_checked(
|
||||
&request,
|
||||
false,
|
||||
Some(format_cache),
|
||||
&cancellation,
|
||||
evidence,
|
||||
None,
|
||||
if checkpoints.is_some() {
|
||||
EffectMode::Draft
|
||||
} else {
|
||||
EffectMode::Live
|
||||
},
|
||||
)
|
||||
.map_err(|error| {
|
||||
if cancellation.is_cancelled() {
|
||||
CompileError::Cancelled
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?
|
||||
};
|
||||
let mut available_host = Some(files);
|
||||
evidence.inputs = None;
|
||||
evidence.trace = None;
|
||||
let result = (|| -> Result<Arc<CompiledDocument>, CompileError> {
|
||||
let files = available_host.as_mut().expect("prepared native host");
|
||||
if let Some(path) = &request.layout_manifest {
|
||||
files.check_layout_manifest_path(path, request.resource_manifest.as_deref())?;
|
||||
}
|
||||
@@ -819,16 +908,29 @@ impl CompileJob {
|
||||
let cache = &self.compiler.line_break_cache;
|
||||
let before = cache.work();
|
||||
let executor = executor.with_line_break_cache(cache.clone());
|
||||
let execution = match self.job.run_detailed(executor, source, &mut files) {
|
||||
let (executed, next_checkpoint) = if let Some(current) = active_checkpoint {
|
||||
let executed =
|
||||
current.resume(self.job, source, files, &mut entry_checkpoint_work)?;
|
||||
(executed, Some(current))
|
||||
} else if let Some(cache) = checkpoints {
|
||||
let (executed, captured) =
|
||||
cache.capture(&request, self.job, executor, source, files);
|
||||
entry_checkpoint_work.captured_frontier =
|
||||
captured.as_ref().map(|entry| entry.frontier());
|
||||
(executed, captured)
|
||||
} else {
|
||||
(self.job.run_detailed(executor, source, files), None)
|
||||
};
|
||||
let execution = match executed {
|
||||
Ok(execution) => {
|
||||
evidence.completed_execution = Some(execution.clone());
|
||||
report(&files, &request)?;
|
||||
report(files, &request)?;
|
||||
execution
|
||||
}
|
||||
Err(failure) => {
|
||||
evidence.failed_execution = failure.failed_execution;
|
||||
evidence.completed_execution = failure.completed_execution;
|
||||
if let Err(error) = report(&files, &request) {
|
||||
if let Err(error) = report(files, &request) {
|
||||
evidence.gaps.push(error.to_string());
|
||||
}
|
||||
return Err(match failure.error {
|
||||
@@ -875,8 +977,8 @@ impl CompileJob {
|
||||
files.write_layout_manifest(path, e, &pages, &source_map)?;
|
||||
}
|
||||
evidence.phase = AttemptPhase::Fonts;
|
||||
let fonts = texrra_tex_core::native_font::resolve_native_fonts(&mut pages, &mut files);
|
||||
let reported = report(&files, &request);
|
||||
let fonts = texrra_tex_core::native_font::resolve_native_fonts(&mut pages, files);
|
||||
let reported = report(files, &request);
|
||||
if let Err(error) = fonts {
|
||||
if let Err(report) = reported {
|
||||
evidence.gaps.push(report.to_string());
|
||||
@@ -919,7 +1021,7 @@ impl CompileJob {
|
||||
}
|
||||
evidence.phase = AttemptPhase::Finishing;
|
||||
let finished = files.finish();
|
||||
let reported = report(&files, &request);
|
||||
let reported = report(files, &request);
|
||||
if let Err(error) = finished {
|
||||
if let Err(report) = reported {
|
||||
evidence.gaps.push(report.to_string());
|
||||
@@ -954,6 +1056,7 @@ impl CompileJob {
|
||||
);
|
||||
let result = Arc::new(CompiledDocument {
|
||||
format_preparation,
|
||||
entry_checkpoint_work,
|
||||
line_break_work,
|
||||
execution,
|
||||
pages,
|
||||
@@ -975,26 +1078,51 @@ impl CompileJob {
|
||||
&cancellation,
|
||||
)?;
|
||||
evidence.phase = AttemptPhase::Publishing;
|
||||
let published = self
|
||||
.compiler
|
||||
.session
|
||||
.publish_current(result.revision(), || {
|
||||
if let Some(prepared) = prepared {
|
||||
prepared.commit(&output)?;
|
||||
}
|
||||
*self
|
||||
.compiler
|
||||
.latest
|
||||
.lock()
|
||||
.expect("native completed result poisoned") = Some(result.clone());
|
||||
Ok::<_, String>(())
|
||||
})?;
|
||||
let expose = || {
|
||||
*self
|
||||
.compiler
|
||||
.latest
|
||||
.lock()
|
||||
.expect("native completed result poisoned") = Some(result.clone());
|
||||
};
|
||||
let published = if let Some(cache) = checkpoints {
|
||||
let publication = available_host
|
||||
.take()
|
||||
.expect("prepared draft host")
|
||||
.seal_draft(prepared)
|
||||
.and_then(|draft| {
|
||||
draft.publish_current(&self.compiler.session, result.revision(), || {
|
||||
cache.set(next_checkpoint);
|
||||
expose();
|
||||
})
|
||||
});
|
||||
if !matches!(publication, Ok(Some(()))) {
|
||||
evidence.host_preparation = result.host_preparation.clone();
|
||||
evidence.inputs = Some(result.inputs.clone());
|
||||
evidence.trace = Some(result.resources.trace.clone());
|
||||
evidence.resources = Some(result.resources.clone());
|
||||
evidence.host_runtime = result.host_runtime.clone();
|
||||
}
|
||||
publication?
|
||||
} else {
|
||||
self.compiler
|
||||
.session
|
||||
.publish_current(result.revision(), || {
|
||||
if let Some(prepared) = prepared {
|
||||
prepared.commit(&output)?;
|
||||
}
|
||||
expose();
|
||||
Ok::<_, String>(())
|
||||
})?
|
||||
};
|
||||
if published.is_none() {
|
||||
return Err(CompileError::Cancelled);
|
||||
}
|
||||
Ok(result)
|
||||
})();
|
||||
if result.is_err() {
|
||||
if result.is_err()
|
||||
&& let Some(mut files) = available_host
|
||||
{
|
||||
evidence.gaps.extend(files.finish_failed());
|
||||
if let Err(error) = report(&files, &request) {
|
||||
evidence.gaps.push(error.to_string());
|
||||
|
||||
Reference in new issue
Block a user