Reuse validated checkpoint executors during native preview
This commit is contained in:
1 parent
69de8a6599
commit
43231a48c0
8 files changed
+160
-50
No files matched your search
+80
-37
@@ -587,12 +587,19 @@ impl NativeCompiler {
|
||||
}
|
||||
|
||||
struct PreparedJob {
|
||||
executor: Executor,
|
||||
executor: Option<Executor>,
|
||||
format_preparation: Option<FormatPreparation>,
|
||||
source: SourceFile,
|
||||
files: Files,
|
||||
output: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum KernelPreparation {
|
||||
Fresh,
|
||||
Resume,
|
||||
}
|
||||
|
||||
fn prepare(
|
||||
request: &CompileRequest,
|
||||
dump: bool,
|
||||
@@ -608,6 +615,7 @@ fn prepare(
|
||||
evidence,
|
||||
None,
|
||||
EffectMode::Live,
|
||||
KernelPreparation::Fresh,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -619,6 +627,7 @@ fn prepare_checked(
|
||||
evidence: &mut AttemptEvidence,
|
||||
check_inputs: Option<Box<PreparedInputsCheck<'_>>>,
|
||||
effects: EffectMode,
|
||||
kernel: KernelPreparation,
|
||||
) -> Result<PreparedJob, CompileError> {
|
||||
use texrra_tex_core::resources::ResourceKind;
|
||||
check(cancellation)?;
|
||||
@@ -735,36 +744,61 @@ fn prepare_checked(
|
||||
FormatPreparation::Decoded,
|
||||
),
|
||||
};
|
||||
let executor = image.fork_job_with_file_dates(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
request.time,
|
||||
request.limits,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?;
|
||||
let executor = if kernel == KernelPreparation::Resume {
|
||||
image.validate_job_inputs(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?;
|
||||
None
|
||||
} else {
|
||||
Some(image.fork_job_with_file_dates(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
request.time,
|
||||
request.limits,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?)
|
||||
};
|
||||
check(cancellation)?;
|
||||
if preparation == FormatPreparation::Decoded {
|
||||
cache.insert(loaded.version, image);
|
||||
}
|
||||
(executor, Some(preparation))
|
||||
}
|
||||
None => (
|
||||
FormatImage::decode(&loaded.data)?.new_job_with_file_dates(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
request.time,
|
||||
request.limits,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?,
|
||||
Some(FormatPreparation::Decoded),
|
||||
),
|
||||
None => {
|
||||
let image = FormatImage::decode(&loaded.data)?;
|
||||
let executor = if kernel == KernelPreparation::Resume {
|
||||
image.validate_job_inputs(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?;
|
||||
None
|
||||
} else {
|
||||
Some(image.new_job_with_file_dates(
|
||||
state.profile(),
|
||||
request.input_profile,
|
||||
request.time,
|
||||
request.limits,
|
||||
&mut world,
|
||||
read,
|
||||
date,
|
||||
)?)
|
||||
};
|
||||
(executor, Some(FormatPreparation::Decoded))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(Executor::new(state, request.limits), None)
|
||||
let executor =
|
||||
(kernel == KernelPreparation::Fresh).then(|| Executor::new(state, request.limits));
|
||||
(executor, None)
|
||||
};
|
||||
check(cancellation)?;
|
||||
Ok((path, source, executor, output, format_preparation))
|
||||
@@ -786,11 +820,13 @@ fn prepare_checked(
|
||||
evidence.inputs = Some(failure.inputs);
|
||||
CompileError::Host(failure.error)
|
||||
})?;
|
||||
let executor = if request.target == Target::Shipouts {
|
||||
executor.with_native_pages()
|
||||
} else {
|
||||
executor
|
||||
};
|
||||
let executor = executor.map(|executor| {
|
||||
if request.target == Target::Shipouts {
|
||||
executor.with_native_pages()
|
||||
} else {
|
||||
executor
|
||||
}
|
||||
});
|
||||
Ok(PreparedJob {
|
||||
executor,
|
||||
format_preparation,
|
||||
@@ -900,6 +936,7 @@ impl CompileJob {
|
||||
} else {
|
||||
EffectMode::Live
|
||||
},
|
||||
KernelPreparation::Fresh,
|
||||
)
|
||||
.map_err(|error| {
|
||||
if cancellation.is_cancelled() {
|
||||
@@ -922,20 +959,25 @@ impl CompileJob {
|
||||
evidence.phase = AttemptPhase::Executing;
|
||||
let cache = &self.compiler.line_break_cache;
|
||||
let before = cache.work();
|
||||
let executor = executor.with_line_break_cache(cache.clone());
|
||||
let (executed, next_checkpoint) = if let Some(current) = active_checkpoint {
|
||||
debug_assert!(executor.is_none());
|
||||
let (executed, next) =
|
||||
current.resume(self.job, source, files, &mut entry_checkpoint_work)?;
|
||||
(executed, Some(next))
|
||||
} else if let Some(cache) = checkpoints {
|
||||
let (executed, captured) =
|
||||
cache.capture(&request, self.job, executor, source, files);
|
||||
if let Some(snapshot) = &captured {
|
||||
snapshot.report_capture(&mut entry_checkpoint_work);
|
||||
}
|
||||
(executed, captured)
|
||||
} else {
|
||||
(self.job.run_detailed(executor, source, files), None)
|
||||
let executor = executor
|
||||
.expect("fresh native job has an executor")
|
||||
.with_line_break_cache(cache.clone());
|
||||
if let Some(cache) = checkpoints {
|
||||
let (executed, captured) =
|
||||
cache.capture(&request, self.job, executor, source, files);
|
||||
if let Some(snapshot) = &captured {
|
||||
snapshot.report_capture(&mut entry_checkpoint_work);
|
||||
}
|
||||
(executed, captured)
|
||||
} else {
|
||||
(self.job.run_detailed(executor, source, files), None)
|
||||
}
|
||||
};
|
||||
let execution = match executed {
|
||||
Ok(execution) => {
|
||||
@@ -1186,6 +1228,7 @@ fn dump_format_observed(
|
||||
let result = (|| -> Result<BuiltFormat, CompileError> {
|
||||
evidence.phase = AttemptPhase::Executing;
|
||||
let executed = executor
|
||||
.expect("format dump has a fresh executor")
|
||||
.with_cancellation(cancellation.clone())
|
||||
.run_detailed(source, &mut files);
|
||||
let execution = match executed {
|
||||
|
||||
@@ -264,6 +264,7 @@ impl SelectedCheckpoint {
|
||||
)
|
||||
})),
|
||||
EffectMode::Draft,
|
||||
KernelPreparation::Resume,
|
||||
)?;
|
||||
for call in &self.set.calls[..checkpoint.replay_count] {
|
||||
check(cancellation)?;
|
||||
@@ -524,9 +525,11 @@ fn prefix_guard_checks_actual_dependencies_and_preserves_live_artifacts_on_rejec
|
||||
let initial = files.preparation().generated_initial.clone().unwrap();
|
||||
let mut recording = checkpoint_probe::RecordingHost::new(&mut files);
|
||||
let (executed, checkpoint) =
|
||||
executor.run_capturing_entry(source, &mut recording, PREFIX.len() - 25, |host| {
|
||||
(host.capture(), host.resource_usage().unwrap().unwrap())
|
||||
});
|
||||
executor
|
||||
.unwrap()
|
||||
.run_capturing_entry(source, &mut recording, PREFIX.len() - 25, |host| {
|
||||
(host.capture(), host.resource_usage().unwrap().unwrap())
|
||||
});
|
||||
assert!(executed.is_ok());
|
||||
let (checkpoint, (recorded, usage)) = checkpoint.unwrap();
|
||||
let (calls, trace) = recorded.unwrap();
|
||||
@@ -560,6 +563,7 @@ fn prefix_guard_checks_actual_dependencies_and_preserves_live_artifacts_on_rejec
|
||||
Ok(())
|
||||
})),
|
||||
effects,
|
||||
KernelPreparation::Resume,
|
||||
)
|
||||
};
|
||||
let rejected = |candidate: &CompileRequest, reason: &str| {
|
||||
|
||||
@@ -255,7 +255,7 @@ fn original_a3_resume_uses_real_host_and_matches_independent_full_jobs() {
|
||||
files: &mut files,
|
||||
calls: Some(Vec::new()),
|
||||
};
|
||||
let (original_execution, captured) = executor.run_capturing_entry(
|
||||
let (original_execution, captured) = executor.unwrap().run_capturing_entry(
|
||||
source,
|
||||
&mut record,
|
||||
marker_start.saturating_sub(1200),
|
||||
|
||||
Reference in new issue
Block a user