Translate logical step counts when replaying native suffixes

This commit is contained in:
gloamxun committed 2026-12-01 21:16:41 +08:00
1 parent 9a6c162b46
commit 465a574124
8 files changed
+337 -86

No files matched your search

+6 -3
View File
@@ -416,8 +416,11 @@ impl<'a> CapturedEntries<'a> {
let project = self.request.project.as_deref().expect("settled replay uses a project");
let bytes = project.file(&completed.guard.entry).expect("settled entry").data.len();
let stride = bytes.div_ceil(SOURCE_INTERVALS).max(1);
let offset = texrra_tex_core::execution::StepOffset::new(
prior.entry.completed_steps(), current.completed_steps(),
);
let mut later = [const { None }; SOURCE_INTERVALS];
if let Some(rebase) = current.prepare_suffix_rebase(&prior.entry, &completed.result.execution) {
if let Some(mut rebase) = current.prepare_suffix_rebase(&prior.entry, &completed.result.execution) {
// Keep the deepest compatible settled continuation per source interval.
for (&page, anchor) in completed.settled.range((std::ops::Bound::Excluded(page), std::ops::Bound::Unbounded)).rev() {
let interval = (anchor.entry.frontier() - 1) / stride;
@@ -438,7 +441,7 @@ impl<'a> CapturedEntries<'a> {
let Some(calls) = completed.calls.get(replayed..anchor.call_count) else {
continue;
};
host.replay_suffix(calls, cancellation)?;
host.replay_suffix(calls, offset, cancellation)?;
replayed = anchor.call_count;
if anchor.host == host.files().replay_boundary() {
let regular = CaptureSlots {
@@ -451,7 +454,7 @@ impl<'a> CapturedEntries<'a> {
self.capture(Capture::Settled { page, regular: Some(regular) }, Arc::new(entry), host);
}
}
host.replay_suffix(&completed.calls[replayed..], cancellation)?;
host.replay_suffix(&completed.calls[replayed..], offset, cancellation)?;
completed.guard.verify_replayed_inputs(host.files(), project).map_err(|error| error.to_string())
}
+27 -3
View File
@@ -6,7 +6,7 @@ use std::fs;
#[cfg(test)]
use texrra_tex_core::source_map::SourceMap;
use texrra_tex_core::{
execution::{Error, HostResourceUsage, WriteDestination},
execution::{Error, HostResourceUsage, StatisticsPhase, StatisticsReport, StepOffset, WriteDestination},
resources::{LoadedResource, ResourceKind, ResourceVersion},
};
@@ -16,6 +16,7 @@ pub(super) enum Call {
Checked(Arc<CheckedCall>),
ReadSource(Arc<SourceRead>),
FileSize(Arc<SizeRead>),
EndStatistics(Arc<StatisticsReport>),
}
pub(super) struct SourceRead {
@@ -45,6 +46,7 @@ impl Call {
pub(super) fn replay(&self, files: &mut Files, partial_source: Option<&ResourceVersion>) -> Result<(), String> {
match self {
Self::Checked(call) => call(files),
Self::EndStatistics(report) => files.observe_statistics(report),
Self::FileSize(read) => {
let before = files.resource_trace().reads.len();
let observed = files.file_size(&read.name, &read.from);
@@ -150,16 +152,27 @@ impl<'a> RecordingHost<'a> {
self.files
}
pub(super) fn replay_suffix(&mut self, calls: &[Call], cancellation: &Cancellation) -> Result<(), String> {
pub(super) fn replay_suffix(
&mut self,
calls: &[Call],
offset: StepOffset,
cancellation: &Cancellation,
) -> Result<(), String> {
let recorded = self.calls.as_mut().ok_or("host calls are unavailable")?;
if recorded.len() + calls.len() >= MAX_REPLAY_CALLS {
return Err("completed suffix exceeds the host recording budget".into());
}
for call in calls {
check(cancellation).map_err(|error| error.to_string())?;
let call = match call {
Call::EndStatistics(report) if !offset.is_identity() => Call::EndStatistics(
Arc::new(report.with_step_offset(offset).ok_or("invalid replayed statistics")?),
),
call => call.clone(),
};
call.replay(self.files, None)?;
recorded.push(call);
}
recorded.extend_from_slice(calls);
Ok(())
}
@@ -384,6 +397,17 @@ impl SourceProvider for RecordingHost<'_> {
let text = text.to_owned();
call!(self, observe_diagnostic(destination, &text))
}
fn observe_statistics(&mut self, report: &StatisticsReport) -> Result<(), String> {
// Shipout reports do not write the step count in their transcript.
if !matches!(&report.phase, StatisticsPhase::End { .. }) {
return self.observe_diagnostic(report.destination, &report.text);
}
self.files.observe_statistics(report)?;
if let Some(calls) = &mut self.calls && calls.len() < MAX_REPLAY_CALLS {
calls.push(Call::EndStatistics(Arc::new(report.clone())));
}
Ok(())
}
fn observe_inline_diagnostic(
&mut self,
destination: WriteDestination,