Relocate source provenance when native suffixes move
This commit is contained in:
1 parent
6acd82dbfa
commit
41a459b4ca
16 files changed
+1507
-79
No files matched your search
@@ -414,13 +414,20 @@ impl<'a> CapturedEntries<'a> {
|
||||
cancellation: &Cancellation,
|
||||
) -> Result<(), String> {
|
||||
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 path = &completed.guard.entry;
|
||||
let bytes = project.file(path).expect("settled entry").data.len();
|
||||
let previous_bytes = completed.guard.project.file(path).expect("prior settled entry").data.len();
|
||||
let resize = (previous_bytes != bytes).then_some((previous_bytes, bytes));
|
||||
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(mut rebase) = current.prepare_suffix_rebase(&prior.entry, &completed.result.execution) {
|
||||
// Untranslated live continuations and their source intervals still
|
||||
// refer to the old entry when its length changed.
|
||||
if resize.is_none()
|
||||
&& 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;
|
||||
@@ -441,7 +448,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
let Some(calls) = completed.calls.get(replayed..anchor.call_count) else {
|
||||
continue;
|
||||
};
|
||||
host.replay_suffix(calls, offset, cancellation)?;
|
||||
host.replay_suffix(calls, offset, None, cancellation)?;
|
||||
replayed = anchor.call_count;
|
||||
if anchor.host == host.files().replay_boundary() {
|
||||
let regular = CaptureSlots {
|
||||
@@ -454,7 +461,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
self.capture(Capture::Settled { page, regular: Some(regular) }, Arc::new(entry), host);
|
||||
}
|
||||
}
|
||||
host.replay_suffix(&completed.calls[replayed..], offset, cancellation)?;
|
||||
host.replay_suffix(&completed.calls[replayed..], offset, resize, cancellation)?;
|
||||
completed.guard.verify_replayed_inputs(host.files(), project).map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
@@ -970,7 +977,8 @@ impl SelectedCheckpoint {
|
||||
};
|
||||
let Some((completed, old, execution)) = suffixes.clone().find_map(|completed| {
|
||||
let old = completed.settled.get(&page)?;
|
||||
if old.call_count != new.call_count || old.host != new.host
|
||||
if old.call_count != new.call_count
|
||||
|| !new.host.matches_for_suffix(&old.host)
|
||||
|| !can_replay_completed_suffix(completed, request, host.files())
|
||||
{
|
||||
return None;
|
||||
|
||||
@@ -178,6 +178,7 @@ impl<'a> RecordingHost<'a> {
|
||||
&mut self,
|
||||
calls: &[Call],
|
||||
offset: StepOffset,
|
||||
resize: Option<(usize, usize)>,
|
||||
cancellation: &Cancellation,
|
||||
) -> Result<(), String> {
|
||||
let recorded = self.calls.as_mut().ok_or("host calls are unavailable")?;
|
||||
@@ -187,9 +188,16 @@ impl<'a> RecordingHost<'a> {
|
||||
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::EndStatistics(report) if !offset.is_identity() || resize.is_some() => {
|
||||
let report = report.with_step_offset(offset).ok_or("invalid replayed statistics")?;
|
||||
let report = if let Some((previous, current)) = resize {
|
||||
report.with_suffix_entry_resize(previous, current)
|
||||
.ok_or("invalid replayed entry size in statistics")?
|
||||
} else {
|
||||
report
|
||||
};
|
||||
Call::EndStatistics(Arc::new(report))
|
||||
}
|
||||
call => call.clone(),
|
||||
};
|
||||
call.replay(self.files, None)?;
|
||||
|
||||
+23
-6
@@ -159,6 +159,20 @@ struct DraftLedger {
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub(super) struct ReplayBoundary {
|
||||
entry_bytes: Option<u64>,
|
||||
state: ReplayState,
|
||||
}
|
||||
|
||||
impl ReplayBoundary {
|
||||
/// Ignore only the first entry read's length. The caller authenticates
|
||||
/// that read and checks all later observations of the entry path.
|
||||
pub(super) fn matches_for_suffix(&self, prior: &Self) -> bool {
|
||||
self.entry_bytes.is_some() && prior.entry_bytes.is_some() && self.state == prior.state
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct ReplayState {
|
||||
inputs: Vec<(u8, u64, PathBuf, u64, std::collections::VecDeque<u8>)>,
|
||||
outputs: Vec<(u8, u64, PathBuf, u64)>,
|
||||
next_handle: u64,
|
||||
@@ -671,11 +685,13 @@ impl Files {
|
||||
pub(super) fn replay_boundary(&self) -> ReplayBoundary {
|
||||
let mut trace = self.resource_trace().clone();
|
||||
trace.project_version = None;
|
||||
// The caller compared the live scanner bytes and validates later
|
||||
// whole-file reads separately. Keep this entry's path and length.
|
||||
if let Some(entry) = trace.reads.first_mut() {
|
||||
// The entry scanner verifies source bytes separately. Retain the
|
||||
// first read's path in the comparison and store its length apart,
|
||||
// since later live checkpoints still require exact lengths.
|
||||
let entry_bytes = trace.reads.first_mut().map(|entry| {
|
||||
entry.sha256.clear();
|
||||
}
|
||||
std::mem::take(&mut entry.bytes)
|
||||
});
|
||||
let mut stream_events = self.stream_io.events().to_vec();
|
||||
for event in &mut stream_events {
|
||||
if let crate::native_stream::StreamEffect::OutputOpened {
|
||||
@@ -687,7 +703,7 @@ impl Files {
|
||||
identity.unix_identity = None;
|
||||
}
|
||||
}
|
||||
ReplayBoundary {
|
||||
let state = ReplayState {
|
||||
inputs: self.inputs.iter().map(|(&index, input)| {
|
||||
(index, input.handle, input.path.clone(), input.offset, input.xe_lookahead.clone())
|
||||
}).collect(),
|
||||
@@ -702,7 +718,8 @@ impl Files {
|
||||
generated_written: self.generated_written.clone(),
|
||||
trace,
|
||||
stream_events,
|
||||
}
|
||||
};
|
||||
ReplayBoundary { entry_bytes, state }
|
||||
}
|
||||
|
||||
pub(super) fn replay_world(&self) -> &FileWorld {
|
||||
|
||||
Reference in new issue
Block a user