Reuse native checkpoints for unchanged file-size observations

This commit is contained in:
gloamxun committed 2026-11-29 09:24:06 +08:00
1 parent 061e484001
commit 4162c88826
5 files changed
+177 -17

No files matched your search

+20 -9
View File
@@ -1,8 +1,8 @@
//! Capture and verify the native host calls made by an entry prefix.
use super::*;
use std::{collections::BTreeSet, fmt::Debug};
use std::{collections::BTreeSet, fmt::Debug, path::Path};
#[cfg(test)]
use std::{fs, path::Path};
use std::fs;
#[cfg(test)]
use texrra_tex_core::source_map::SourceMap;
use texrra_tex_core::{
@@ -36,16 +36,27 @@ pub(super) struct RebindableSourceObservations {
}
impl Call {
pub(super) fn observed_file_size(&self) -> Option<(&Path, u64)> {
let Self::FileSize(read) = self else { return None };
let version = read.read.as_ref()?;
(read.observed == Ok(Some(version.bytes))).then_some((&version.path, version.bytes))
}
pub(super) fn replay(&self, files: &mut Files, partial_source: Option<&ResourceVersion>) -> Result<(), String> {
match self {
Self::Checked(call) => call(files),
Self::FileSize(read) => {
let before = files.resource_trace().reads.len();
let observed = files.file_size(&read.name, &read.from);
if observed == read.observed {
Ok(())
} else {
Err(format!("file size changed: expected {:?}, observed {observed:?}", read.observed))
if observed != read.observed {
return Err(format!("file size changed: expected {:?}, observed {observed:?}", read.observed));
}
if let Some(expected) = &read.read
&& !matches!(&files.resource_trace().reads[before..], [actual] if actual.path == expected.path)
{
return Err(format!("file size lookup changed: {}", expected.path.display()));
}
Ok(())
}
Self::ReadSource(read) => {
let SourceRead { name, from, expected } = read.as_ref();
@@ -104,9 +115,9 @@ impl<'a> RecordingHost<'a> {
Some((self.calls.take()?, trace))
}
pub(super) fn prefix(&self) -> Option<(&ResourceTrace, usize)> {
let count = self.calls.as_ref()?.len();
(count < MAX_REPLAY_CALLS).then(|| (self.files.resource_trace(), count))
pub(super) fn prefix(&self) -> Option<(&ResourceTrace, &[Call])> {
let calls = self.calls.as_deref()?;
(calls.len() < MAX_REPLAY_CALLS).then(|| (self.files.resource_trace(), calls))
}
pub(super) fn rebindable_source_observations(