Bind native format inputs after moving a project tree
This commit is contained in:
1 parent
c2e1e64a60
commit
1ad9c4db82
8 files changed
+509
-23
No files matched your search
+52
-13
@@ -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();
|
||||
|
||||
@@ -615,6 +615,7 @@ struct PrefixInputGuard {
|
||||
immutable: BTreeSet<PathBuf>,
|
||||
generated: BTreeSet<PathBuf>,
|
||||
lookups: Vec<ResourceLookup>,
|
||||
format_input_bindings: BTreeMap<PathBuf, PathBuf>,
|
||||
clock_environment: Option<[Option<OsString>; 3]>,
|
||||
}
|
||||
|
||||
@@ -696,6 +697,7 @@ impl PrefixInputGuard {
|
||||
immutable,
|
||||
generated,
|
||||
lookups: trace.lookups.clone(),
|
||||
format_input_bindings: trace.format_input_bindings.clone(),
|
||||
clock_environment: (!trace.file_modifications.is_empty()).then(date_environment),
|
||||
})
|
||||
}
|
||||
@@ -765,6 +767,9 @@ impl PrefixInputGuard {
|
||||
preparation: &HostPreparation,
|
||||
) -> Result<(), String> {
|
||||
let current = self.verify_project(request)?;
|
||||
if self.format_input_bindings != world.trace().format_input_bindings {
|
||||
return Err("checkpoint format input bindings changed".into());
|
||||
}
|
||||
if world.trace().reads.first() != current.file(&self.entry).map(|file| &file.version) {
|
||||
return Err("checkpoint entry resolved to a different path".into());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user