Share verified lookup records across checkpoint captures
This commit is contained in:
1 parent
41b3a22061
commit
97ee13fa31
1 file changed
+42
-23
@@ -351,6 +351,7 @@ struct CapturedEntries<'a> {
|
||||
nested: [[Option<Arc<CachedCheckpoint>>; NESTED_INTERVALS]; NESTED_FILES],
|
||||
changed: bool,
|
||||
settled: BTreeMap<usize, SettledCheckpoint>,
|
||||
captured_lookups: Vec<Arc<ResourceLookup>>,
|
||||
}
|
||||
|
||||
impl<'a> CapturedEntries<'a> {
|
||||
@@ -369,6 +370,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
nested: Default::default(),
|
||||
changed: false,
|
||||
settled: BTreeMap::new(),
|
||||
captured_lookups: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +442,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
calls,
|
||||
host.generated_outputs(),
|
||||
initial.clone(),
|
||||
&mut self.captured_lookups,
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
@@ -530,7 +533,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
}
|
||||
|
||||
fn finish<'b>(
|
||||
self,
|
||||
mut self,
|
||||
recording: RecordingHost,
|
||||
refresh_on_resume: bool,
|
||||
suffix_base: Option<Arc<CompletedExecution>>,
|
||||
@@ -612,6 +615,7 @@ impl<'a> CapturedEntries<'a> {
|
||||
calls,
|
||||
recording.generated_outputs(),
|
||||
self.initial?,
|
||||
&mut self.captured_lookups,
|
||||
).ok()?;
|
||||
Some((guard, trace.clone()))
|
||||
}).flatten();
|
||||
@@ -1397,7 +1401,7 @@ struct PrefixInputGuard {
|
||||
immutable_sizes: BTreeMap<PathBuf, u64>,
|
||||
immutable_stream_prefixes: BTreeMap<PathBuf, usize>,
|
||||
generated: BTreeSet<PathBuf>,
|
||||
lookups: Vec<ResourceLookup>,
|
||||
lookups: Vec<Arc<ResourceLookup>>,
|
||||
stream_reads: Vec<ResourceReadRange>,
|
||||
format_input_bindings: BTreeMap<PathBuf, PathBuf>,
|
||||
clock_environment: Option<[Option<OsString>; 3]>,
|
||||
@@ -1463,6 +1467,7 @@ impl PrefixInputGuard {
|
||||
calls: &[Call],
|
||||
written: &BTreeSet<PathBuf>,
|
||||
initial: GeneratedInitialState,
|
||||
captured_lookups: &mut Vec<Arc<ResourceLookup>>,
|
||||
) -> Result<Self, String> {
|
||||
let project = request
|
||||
.project
|
||||
@@ -1498,6 +1503,9 @@ impl PrefixInputGuard {
|
||||
let mut immutable = BTreeSet::new();
|
||||
let mut generated = BTreeSet::new();
|
||||
for path in tracked {
|
||||
if immutable.contains(path) || generated.contains(path) {
|
||||
continue;
|
||||
}
|
||||
if project.file(path).is_some() {
|
||||
immutable.insert(path.to_path_buf());
|
||||
} else if initial.files().contains_key(path) {
|
||||
@@ -1525,28 +1533,37 @@ impl PrefixInputGuard {
|
||||
// A stream can have unconsumed bytes even though the host pinned a
|
||||
// complete buffer. Whole-file consumers, dates and observed EOF
|
||||
// still require the immutable input version.
|
||||
let whole_files: BTreeSet<_> = trace
|
||||
.reads
|
||||
.iter()
|
||||
.map(|version| version.path.as_path())
|
||||
.chain(trace.file_modifications.iter().map(|item| item.path.as_path()))
|
||||
.chain(trace.stream_reads.iter().filter(|item| item.eof).map(|item| item.path.as_path()))
|
||||
.collect();
|
||||
let mut immutable_stream_prefixes = BTreeMap::<PathBuf, usize>::new();
|
||||
for range in &trace.stream_reads {
|
||||
if !immutable.contains(&range.path) || whole_files.contains(range.path.as_path()) {
|
||||
continue;
|
||||
if !trace.stream_reads.is_empty() {
|
||||
let whole_files: BTreeSet<_> = trace
|
||||
.reads
|
||||
.iter()
|
||||
.map(|version| version.path.as_path())
|
||||
.chain(trace.file_modifications.iter().map(|item| item.path.as_path()))
|
||||
.chain(trace.stream_reads.iter().filter(|item| item.eof).map(|item| item.path.as_path()))
|
||||
.collect();
|
||||
for range in &trace.stream_reads {
|
||||
if !immutable.contains(&range.path) || whole_files.contains(range.path.as_path()) {
|
||||
continue;
|
||||
}
|
||||
let end = range
|
||||
.offset
|
||||
.checked_add(range.bytes)
|
||||
.and_then(|end| usize::try_from(end).ok())
|
||||
.filter(|&end| project.file(&range.path).is_some_and(|file| end <= file.data.len()))
|
||||
.ok_or("checkpoint stream range exceeds its captured input")?;
|
||||
let prefix = immutable_stream_prefixes.entry(range.path.clone()).or_default();
|
||||
*prefix = (*prefix).max(end);
|
||||
}
|
||||
let end = range
|
||||
.offset
|
||||
.checked_add(range.bytes)
|
||||
.and_then(|end| usize::try_from(end).ok())
|
||||
.filter(|&end| project.file(&range.path).is_some_and(|file| end <= file.data.len()))
|
||||
.ok_or("checkpoint stream range exceeds its captured input")?;
|
||||
let prefix = immutable_stream_prefixes.entry(range.path.clone()).or_default();
|
||||
*prefix = (*prefix).max(end);
|
||||
}
|
||||
let immutable_sizes = size_only_inputs(project, trace, calls);
|
||||
// Keep the original order and payloads. As the trace grows, earlier
|
||||
// checkpoints can share the exact same lookup observations.
|
||||
let shared = captured_lookups.iter().zip(&trace.lookups)
|
||||
.take_while(|(previous, current)| previous.as_ref() == *current)
|
||||
.count();
|
||||
captured_lookups.truncate(shared);
|
||||
captured_lookups.extend(trace.lookups[shared..].iter().cloned().map(Arc::new));
|
||||
Ok(Self {
|
||||
original: AttemptRequest::from(request),
|
||||
project: project.clone(),
|
||||
@@ -1557,7 +1574,7 @@ impl PrefixInputGuard {
|
||||
immutable_sizes,
|
||||
immutable_stream_prefixes,
|
||||
generated,
|
||||
lookups: trace.lookups.clone(),
|
||||
lookups: captured_lookups.clone(),
|
||||
stream_reads: trace.stream_reads.clone(),
|
||||
format_input_bindings: trace.format_input_bindings.clone(),
|
||||
clock_environment: (!trace.file_modifications.is_empty()).then(date_environment),
|
||||
@@ -1675,7 +1692,7 @@ impl PrefixInputGuard {
|
||||
|
||||
fn verify_replayed_lookups(&self, files: &Files) -> Result<(), CompileError> {
|
||||
let trace = files.resource_trace();
|
||||
if trace.lookups != self.lookups
|
||||
if !trace.lookups.iter().eq(self.lookups.iter().map(Arc::as_ref))
|
||||
|| !trace.read_errors.is_empty()
|
||||
|| !trace.namespace_capture_failures.is_empty()
|
||||
{
|
||||
@@ -1834,7 +1851,9 @@ fn prefix_guard_checks_actual_dependencies_and_preserves_live_artifacts_on_rejec
|
||||
.iter()
|
||||
.any(|lookup| lookup.name == "optional.tex" && lookup.resolved.is_none())
|
||||
);
|
||||
let guard = PrefixInputGuard::capture(&request, &entry, &trace, &calls, &written, initial).unwrap();
|
||||
let guard = PrefixInputGuard::capture(
|
||||
&request, &entry, &trace, &calls, &written, initial, &mut Vec::new(),
|
||||
).unwrap();
|
||||
assert!(guard.generated.contains(&aux));
|
||||
assert!(!guard.generated.contains(&seed));
|
||||
assert!(guard.immutable.contains(&library));
|
||||
|
||||
Reference in new issue
Block a user