Bind native format inputs after moving a project tree

This commit is contained in:
gloamxun committed 2026-11-28 01:29:28 +08:00
1 parent c2e1e64a60
commit 1ad9c4db82
8 files changed
+509 -23

No files matched your search

+52 -13
View File
@@ -24,7 +24,8 @@ pub use crate::native_stream::{
use checkpoint_guard::CheckpointCache;
pub use checkpoint_guard::EntryCheckpointWork;
use std::{
path::PathBuf,
collections::BTreeMap,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
pub use texrra_tex_core::resources::{ProjectDefinition, ProjectSnapshot, ProjectVersion};
@@ -578,23 +579,24 @@ pub struct NativeCompiler {
#[derive(Default)]
struct FormatCache(Mutex<Option<CachedFormat>>);
#[derive(Clone)]
struct CachedFormat {
version: ResourceVersion,
image: Arc<FormatImage>,
bindings: Arc<BTreeMap<PathBuf, PathBuf>>,
}
impl FormatCache {
fn get(&self, version: &ResourceVersion) -> Option<Arc<FormatImage>> {
fn get(&self, version: &ResourceVersion) -> Option<CachedFormat> {
let cache = self.0.lock().expect("decoded native format cache poisoned");
cache
.as_ref()
.filter(|old| old.version == *version)
.map(|old| old.image.clone())
.cloned()
}
fn insert(&self, version: ResourceVersion, image: Arc<FormatImage>) {
*self.0.lock().expect("decoded native format cache poisoned") =
Some(CachedFormat { version, image });
fn insert(&self, format: CachedFormat) {
*self.0.lock().expect("decoded native format cache poisoned") = Some(format);
}
}
pub struct CompileJob {
@@ -738,6 +740,9 @@ fn prepare_checked(
world.capture_inputs();
world
};
if dump {
world.capture_lookup_paths();
}
let prepared = (|| -> Result<_, CompileError> {
evidence.host_preparation.phase = HostPreparationPhase::OutputPaths;
let output = evidence
@@ -791,15 +796,46 @@ fn prepare_checked(
check(cancellation).map_err(|e| e.to_string())?;
file_modification_date(world, name, from)
};
let bindings_for = |image: &FormatImage, world: &mut FileWorld| {
let bindings = image.input_bindings(&loaded.version.path, |candidate: &Path| {
check(cancellation).map_err(|e| e.to_string())?;
world.resolve(ResourceKind::Tex, &candidate.to_string_lossy(), &path)
})?;
world.record_format_input_bindings(&bindings);
Ok::<_, CompileError>(bindings)
};
match format_cache {
Some(cache) => {
let (image, preparation) = match cache.get(&loaded.version) {
Some(image) => (image, FormatPreparation::Reused),
None => (
Arc::new(FormatImage::decode(&loaded.data)?),
let (cached, preparation) = if let Some(cached) = cache.get(&loaded.version) {
let bindings = bindings_for(&cached.image, &mut world)?;
if *cached.bindings == bindings {
(cached, FormatPreparation::Reused)
} else {
let mut image = FormatImage::decode(&loaded.data)?;
image.bind_inputs(&bindings);
(
CachedFormat {
version: loaded.version,
image: Arc::new(image),
bindings: Arc::new(bindings),
},
FormatPreparation::Decoded,
)
}
} else {
let mut image = FormatImage::decode(&loaded.data)?;
let bindings = bindings_for(&image, &mut world)?;
image.bind_inputs(&bindings);
(
CachedFormat {
version: loaded.version,
image: Arc::new(image),
bindings: Arc::new(bindings),
},
FormatPreparation::Decoded,
),
)
};
let image = &cached.image;
let executor = if kernel == KernelPreparation::Resume {
image.validate_shared_job_inputs(
state.profile(),
@@ -822,12 +858,14 @@ fn prepare_checked(
};
check(cancellation)?;
if preparation == FormatPreparation::Decoded {
cache.insert(loaded.version, image);
cache.insert(cached);
}
(executor, Some(preparation))
}
None => {
let image = FormatImage::decode(&loaded.data)?;
let mut image = FormatImage::decode(&loaded.data)?;
let bindings = bindings_for(&image, &mut world)?;
image.bind_inputs(&bindings);
let executor = if kernel == KernelPreparation::Resume {
image.validate_shared_job_inputs(
state.profile(),
@@ -1360,6 +1398,7 @@ fn dump_format_observed(
// Keep the completed kernel result available if format validation/encoding
// fails. This extra offline copy is not part of interactive compilation.
let bytes = FormatImage::from_dump_with_trace(execution.execution.clone(), trace)?
.with_project_location(&output, trace)
.encode()?;
evidence.phase = AttemptPhase::Finishing;
let finished = files.finish();