Resume verified preambles while preparing desktop bibliographies
This commit is contained in:
1 parent
32cfd6240a
commit
fd16e9a740
8 files changed
+270
-48
No files matched your search
+68
-12
@@ -463,6 +463,21 @@ impl From<&CompileRequest> for AttemptRequest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AttemptRequest {
|
||||
fn matches_checkpoint_job(&self, request: &CompileRequest) -> bool {
|
||||
self.input == request.input
|
||||
&& self.output == request.output
|
||||
&& self.entry == request.entry
|
||||
&& self.target == request.target
|
||||
&& self.etex == request.etex
|
||||
&& self.input_profile == request.input_profile
|
||||
&& self.translation_file == request.translation_file
|
||||
&& self.time == request.time
|
||||
&& self.limits == request.limits
|
||||
&& self.terminal == request.terminal
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for CompileFailure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.error.fmt(f)
|
||||
@@ -1095,6 +1110,11 @@ fn report(files: &Files, request: &CompileRequest) -> Result<(), CompileError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct OpeningSeed<'a> {
|
||||
previous: Option<&'a OpeningPreamble>,
|
||||
captured: &'a mut Option<OpeningPreamble>,
|
||||
}
|
||||
|
||||
impl CompileJob {
|
||||
pub fn revision(&self) -> u64 {
|
||||
self.job.revision()
|
||||
@@ -1115,9 +1135,21 @@ impl CompileJob {
|
||||
pub fn compile_opening_seed(
|
||||
self,
|
||||
request: CompileRequest,
|
||||
) -> (Result<Arc<CompiledDocument>, CompileFailure>, Option<OpeningPreamble>) {
|
||||
self.compile_opening_seed_with_preamble(request, None)
|
||||
}
|
||||
|
||||
/// Continue from a prior live seed if the current host verifies the prefix.
|
||||
pub fn compile_opening_seed_with_preamble(
|
||||
self,
|
||||
request: CompileRequest,
|
||||
previous: Option<&OpeningPreamble>,
|
||||
) -> (Result<Arc<CompiledDocument>, CompileFailure>, Option<OpeningPreamble>) {
|
||||
let mut preamble = None;
|
||||
let result = self.compile_attempt_with_preamble(request, Some(&mut preamble));
|
||||
let result = self.compile_attempt_with_preamble(
|
||||
request,
|
||||
Some(OpeningSeed { previous, captured: &mut preamble }),
|
||||
);
|
||||
if result.is_err() {
|
||||
preamble = None;
|
||||
}
|
||||
@@ -1155,7 +1187,7 @@ impl CompileJob {
|
||||
fn compile_attempt_with_preamble(
|
||||
&self,
|
||||
mut request: CompileRequest,
|
||||
preamble: Option<&mut Option<OpeningPreamble>>,
|
||||
preamble: Option<OpeningSeed<'_>>,
|
||||
) -> Result<Arc<CompiledDocument>, CompileFailure> {
|
||||
if self.compiler.entry_checkpoints.is_some()
|
||||
&& checkpoint_guard::can_stage(&request)
|
||||
@@ -1208,7 +1240,7 @@ impl CompileJob {
|
||||
evidence: &mut AttemptEvidence,
|
||||
retry_suffix: Option<(String, usize)>,
|
||||
suffix_failure: &mut Option<(String, usize)>,
|
||||
opening_preamble: Option<&mut Option<OpeningPreamble>>,
|
||||
opening_preamble: Option<OpeningSeed<'_>>,
|
||||
) -> Result<Arc<CompiledDocument>, CompileError> {
|
||||
let cancellation = self.job.cancellation();
|
||||
check(&cancellation)?;
|
||||
@@ -1226,6 +1258,15 @@ impl CompileJob {
|
||||
.entry_checkpoints
|
||||
.as_deref()
|
||||
.filter(|_| checkpoint_guard::can_stage(&request));
|
||||
let opening_preamble = opening_preamble.filter(|_| {
|
||||
self.compiler.entry_checkpoints.is_some()
|
||||
&& request.inputs.is_none()
|
||||
&& request.project.is_none()
|
||||
&& request.target == Target::Shipouts
|
||||
&& !request.terminal
|
||||
&& request.resource_manifest.is_none()
|
||||
&& request.layout_manifest.is_none()
|
||||
});
|
||||
let format_cache = &self.compiler.format_cache;
|
||||
let mut entry_checkpoint_work = EntryCheckpointWork::default();
|
||||
let allow_suffix = retry_suffix.is_none();
|
||||
@@ -1233,7 +1274,7 @@ impl CompileJob {
|
||||
entry_checkpoint_work.rejection = Some(error);
|
||||
entry_checkpoint_work.discarded_suffix_attempt_steps = discarded_steps;
|
||||
}
|
||||
let (active_checkpoint, prepared) =
|
||||
let (active_checkpoint, mut 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)),
|
||||
@@ -1247,6 +1288,20 @@ impl CompileJob {
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
let mut opening_resume = None;
|
||||
if let Some(previous) = opening_preamble.as_ref().and_then(|seed| seed.previous) {
|
||||
match previous.prepare_next(request, revision, format_cache, &cancellation, evidence) {
|
||||
Ok((preamble, host)) => {
|
||||
opening_resume = Some(preamble);
|
||||
prepared = Some(host);
|
||||
}
|
||||
Err(error) => {
|
||||
check(&cancellation)?;
|
||||
*evidence = AttemptEvidence::new(revision);
|
||||
entry_checkpoint_work.rejection = Some(error.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
let PreparedJob {
|
||||
executor,
|
||||
format_preparation,
|
||||
@@ -1308,6 +1363,13 @@ impl CompileJob {
|
||||
suffix_failure,
|
||||
)?;
|
||||
(executed, None, Some(next), reused_layouts)
|
||||
} else if let Some(preamble) = opening_resume {
|
||||
debug_assert!(executor.is_none());
|
||||
let executed = preamble.resume(
|
||||
&self.job, source, files, cache.clone(), &mut entry_checkpoint_work,
|
||||
);
|
||||
*opening_preamble.expect("resumed an opening seed").captured = Some(preamble);
|
||||
(executed.map(ResumedExecution::Complete), None, None, None)
|
||||
} else {
|
||||
let executor = executor
|
||||
.expect("fresh native job has an executor")
|
||||
@@ -1319,16 +1381,10 @@ impl CompileJob {
|
||||
snapshot.report_capture(&mut entry_checkpoint_work);
|
||||
}
|
||||
(executed.map(ResumedExecution::Complete), captured, None, None)
|
||||
} else if let Some(preamble) = opening_preamble
|
||||
&& self.compiler.entry_checkpoints.is_some()
|
||||
&& request.inputs.is_none()
|
||||
&& request.project.is_none()
|
||||
&& request.target == Target::Shipouts
|
||||
&& !request.terminal
|
||||
{
|
||||
} else if let Some(preamble) = opening_preamble {
|
||||
let (executed, captured) =
|
||||
OpeningPreamble::discover(request, &self.job, executor, source, files);
|
||||
*preamble = captured;
|
||||
*preamble.captured = captured;
|
||||
(executed.map(ResumedExecution::Complete), None, None, None)
|
||||
} else {
|
||||
(self.job.run_detailed(executor, source, files).map(ResumedExecution::Complete),
|
||||
|
||||
+104
-17
@@ -52,11 +52,12 @@ pub struct OpeningPreamble {
|
||||
}
|
||||
|
||||
struct OpeningBoundary {
|
||||
entry: EntryCheckpoint,
|
||||
entry: Arc<EntryCheckpoint>,
|
||||
slots: CaptureSlots,
|
||||
trace: ResourceTrace,
|
||||
written: BTreeSet<PathBuf>,
|
||||
call_count: usize,
|
||||
live: Option<crate::native_job::ReplayBoundary>,
|
||||
}
|
||||
|
||||
impl OpeningPreamble {
|
||||
@@ -91,18 +92,28 @@ impl OpeningPreamble {
|
||||
return None;
|
||||
}
|
||||
match schedule.select_source(source, pages) {
|
||||
Some(Capture::Entry(slots)) if slots.preamble || slots.preamble_after_input => Some(slots),
|
||||
Some(Capture::Entry(slots)) if slots.preamble || slots.preamble_after_input => {
|
||||
Some((slots, pages == 0))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
|slots, entry, host| {
|
||||
|(slots, before_shipout), entry, host| {
|
||||
if let Some((trace, calls)) = host.prefix() {
|
||||
let live = if before_shipout && trace.read_errors.is_empty()
|
||||
&& trace.namespace_capture_failures.is_empty()
|
||||
{
|
||||
host.files().opening_replay_boundary()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
entries.push(OpeningBoundary {
|
||||
entry,
|
||||
entry: Arc::new(entry),
|
||||
slots,
|
||||
trace: trace.clone(),
|
||||
written: host.generated_outputs().clone(),
|
||||
call_count: calls.len(),
|
||||
live,
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -122,6 +133,93 @@ impl OpeningPreamble {
|
||||
(result, preamble)
|
||||
}
|
||||
|
||||
pub(super) fn prepare_next(
|
||||
&self,
|
||||
request: &CompileRequest,
|
||||
revision: u64,
|
||||
cache: &FormatCache,
|
||||
cancellation: &Cancellation,
|
||||
evidence: &mut AttemptEvidence,
|
||||
) -> Result<(Self, PreparedJob), CompileError> {
|
||||
if self.original.world != request.world
|
||||
|| !self.original.matches_checkpoint_job(request)
|
||||
|| !matches!(self.original.generated_inputs, GeneratedInputPolicy::Observe)
|
||||
|| !matches!(request.generated_inputs, GeneratedInputPolicy::Observe)
|
||||
{
|
||||
return Err("opening preamble job parameters changed".to_owned().into());
|
||||
}
|
||||
let mut rejected = "no read-only opening preamble retained".to_owned();
|
||||
for boundary in self.entries.iter().rev() {
|
||||
let Some(previous_host) = &boundary.live else { continue; };
|
||||
let mut attempt = AttemptEvidence::new(revision);
|
||||
attempt.phase = evidence.phase;
|
||||
let mut prepared = prepare_checked(
|
||||
request, false, Some(cache), cancellation, &mut attempt, None,
|
||||
EffectMode::Live, KernelPreparation::Resume,
|
||||
)?;
|
||||
let files = &mut prepared.files;
|
||||
if files.resource_trace().reads.first() != boundary.trace.reads.first()
|
||||
|| !boundary.entry.accepts_entry_bytes(&prepared.source.name, &prepared.source.data)
|
||||
{
|
||||
return Err("opening preamble entry changed".to_owned().into());
|
||||
}
|
||||
let calls = &self.calls[..boundary.call_count];
|
||||
let replay = calls.iter().try_for_each(|call| {
|
||||
check(cancellation)?;
|
||||
call.replay(files, None).map_err(CompileError::Host)
|
||||
});
|
||||
if let Err(error) = replay {
|
||||
rejected = error.to_string();
|
||||
continue;
|
||||
}
|
||||
// The host compares what the prefix actually observed. An AUX
|
||||
// created by the earlier pass can change the initial ledger
|
||||
// without changing anything read by this preamble.
|
||||
let live = files.opening_replay_boundary();
|
||||
if live.as_ref() != Some(previous_host) {
|
||||
rejected = "opening preamble observations changed".into();
|
||||
continue;
|
||||
}
|
||||
let initial = files.preparation().generated_initial.clone()
|
||||
.ok_or("opening replay requires observed generated inputs".to_owned())?;
|
||||
let next = Self {
|
||||
revision,
|
||||
original: AttemptRequest::from(request),
|
||||
entry_path: self.entry_path.clone(),
|
||||
initial,
|
||||
entries: vec![OpeningBoundary {
|
||||
entry: boundary.entry.clone(),
|
||||
slots: boundary.slots,
|
||||
trace: files.resource_trace().clone(),
|
||||
written: BTreeSet::new(),
|
||||
call_count: calls.len(),
|
||||
live,
|
||||
}],
|
||||
calls: calls.to_vec(),
|
||||
};
|
||||
*evidence = attempt;
|
||||
return Ok((next, prepared));
|
||||
}
|
||||
Err(rejected.into())
|
||||
}
|
||||
|
||||
pub(super) fn resume(
|
||||
&self,
|
||||
job: &RevisionJob,
|
||||
source: SourceFile,
|
||||
files: &mut Files,
|
||||
line_break_cache: Arc<texrra_tex_core::execution::LineBreakCache>,
|
||||
work: &mut EntryCheckpointWork,
|
||||
) -> Result<Arc<RevisionExecution>, RevisionFailure> {
|
||||
let entry = &self.entries[0].entry;
|
||||
work.reused_frontier = Some(entry.frontier());
|
||||
work.reused_steps = entry.completed_steps();
|
||||
work.replayed_calls = self.calls.len();
|
||||
job.resume_capturing_sources_after_host_replay(
|
||||
entry, source, None, files, line_break_cache, |_, _| None::<()>, |(), _, _| {},
|
||||
).expect("the opening checkpoint already accepted the complete entry")
|
||||
}
|
||||
|
||||
pub(super) fn bind(self, request: &CompileRequest) -> Option<Arc<CheckpointSet>> {
|
||||
if request.world != self.original.world {
|
||||
return None;
|
||||
@@ -140,7 +238,7 @@ impl OpeningPreamble {
|
||||
) {
|
||||
guard.original = self.original.clone();
|
||||
entries.push(Arc::new(CachedCheckpoint {
|
||||
entry: Arc::new(boundary.entry),
|
||||
entry: boundary.entry,
|
||||
guard,
|
||||
replay_count: boundary.call_count,
|
||||
slots: Capture::Entry(boundary.slots),
|
||||
@@ -1885,18 +1983,7 @@ impl PrefixInputGuard {
|
||||
request: &'a CompileRequest,
|
||||
closed_source: Option<&Path>,
|
||||
) -> Result<&'a ProjectSnapshot, String> {
|
||||
let old = &self.original;
|
||||
if old.input != request.input
|
||||
|| old.output != request.output
|
||||
|| old.entry != request.entry
|
||||
|| old.target != request.target
|
||||
|| old.etex != request.etex
|
||||
|| old.input_profile != request.input_profile
|
||||
|| old.translation_file != request.translation_file
|
||||
|| old.time != request.time
|
||||
|| old.limits != request.limits
|
||||
|| old.terminal != request.terminal
|
||||
{
|
||||
if !self.original.matches_checkpoint_job(request) {
|
||||
return Err("checkpoint job parameters changed".into());
|
||||
}
|
||||
let current = request
|
||||
|
||||
@@ -759,6 +759,14 @@ impl Files {
|
||||
ReplayBoundary { entry_bytes, state }
|
||||
}
|
||||
|
||||
pub(super) fn opening_replay_boundary(&self) -> Option<ReplayBoundary> {
|
||||
// An attempted open can already have touched a file even if it
|
||||
// ultimately reports a failure. Live replay may only write its log.
|
||||
self.stream_io.events().iter().all(|event| {
|
||||
!matches!(event.effect, StreamEffect::OpenOutputRequested { .. })
|
||||
}).then(|| self.replay_boundary())
|
||||
}
|
||||
|
||||
pub(super) fn replay_world(&self) -> &FileWorld {
|
||||
&self.world
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user