Share native format and checkpoint source bytes

This commit is contained in:
gloamxun committed 2026-11-28 23:16:20 +08:00
1 parent 11c8ad1eaa
commit c09d545da6
7 files changed
+44 -23

No files matched your search

+11 -11
View File
@@ -208,7 +208,7 @@ pub struct Executor {
line_break_cache: Option<std::sync::Arc<super::LineBreakCache>>,
interaction_mode: u8,
inputs: Vec<InputFrame>,
sources: Vec<SourceFile>,
sources: Vec<Arc<SourceFile>>,
stream_sources: BTreeSet<usize>,
generated_inputs: std::collections::BTreeMap<usize, GeneratedInput>,
reads: BTreeSet<Dependency>,
@@ -362,7 +362,7 @@ impl EntryCheckpoint {
unreachable!("entry checkpoints start with the physical source frame");
};
mouth.rebind_loaded_prefix(source.data.clone());
executor.sources[self.entry] = source;
executor.sources[self.entry] = Arc::new(source);
let result = executor
.check_cancellation()
.and_then(|_| executor.run_active_input(self.initial_depth, files, capture_boundary));
@@ -472,7 +472,7 @@ impl Executor {
executor.fresh_job = false;
executor.job_name = execution.job_name;
executor.interaction_mode = execution.interaction_mode;
executor.sources = execution.sources;
executor.sources = execution.sources.into_iter().map(Arc::new).collect();
executor.stream_sources = execution.stream_sources;
executor.generated_inputs = execution.generated_inputs;
executor.split_discards = execution.split_discards;
@@ -483,7 +483,7 @@ impl Executor {
}
pub(super) fn new_format_job(
state: State,
sources: Vec<SourceFile>,
sources: Vec<Arc<SourceFile>>,
stream_sources: BTreeSet<usize>,
generated_inputs: std::collections::BTreeMap<usize, GeneratedInput>,
limits: Limits,
@@ -605,7 +605,7 @@ impl Executor {
let mouth = Mouth::with_encoding(
source, file.data.clone(), profile, &self.state.xe_default_encoding,
);
self.sources.push(file);
self.sources.push(Arc::new(file));
self.reads.insert(Dependency::Source(source));
self.inputs.push(InputFrame::Source {
source,
@@ -2900,10 +2900,10 @@ impl Executor {
.map_err(|e| self.error(e, self.current))?
{
let source = self.sources.len();
self.sources.push(SourceFile {
self.sources.push(Arc::new(SourceFile {
name,
data: Vec::new(),
});
}));
self.stream_sources.insert(source);
let xe_encoding = (self.state.input_profile() == InputProfile::XeTeX).then(|| {
self.reads.insert(Dependency::XeDefaultInputEncoding);
@@ -2968,7 +2968,7 @@ impl Executor {
}
let base = self.sources[source].data.len();
let line = line.unwrap_or_default();
self.sources[source].data.extend_from_slice(&line);
Arc::make_mut(&mut self.sources[source]).data.extend_from_slice(&line);
let end = self.sources[source].data.len();
self.reads.insert(Dependency::EndLineChar);
if readline {
@@ -3306,7 +3306,7 @@ impl Executor {
} else {
ParagraphMode::Vertical
},
sources: self.sources,
sources: self.sources.into_iter().map(Arc::unwrap_or_clone).collect(),
stream_sources: self.stream_sources,
generated_inputs: self.generated_inputs,
reads: self.reads,
@@ -3740,7 +3740,7 @@ impl Executor {
})
.collect();
let evidence = ExecutionEvidence {
sources: self.sources,
sources: self.sources.into_iter().map(Arc::unwrap_or_clone).collect(),
source_versions,
stream_sources: self.stream_sources,
generated_inputs: self.generated_inputs,
@@ -3784,7 +3784,7 @@ impl Executor {
io: self.io,
input_position: self.input_position,
paragraph_mode: ParagraphMode::Vertical,
sources: self.sources,
sources: self.sources.into_iter().map(Arc::unwrap_or_clone).collect(),
stream_sources: self.stream_sources,
generated_inputs: self.generated_inputs,
reads: self.reads,
@@ -206,7 +206,7 @@ impl Executor {
stream.xe_skip_lf =
terminator == Some(13) && bom + length + framing.unit_width() == line.len();
if empty_after_bom || skipped_lf {
self.sources[source].data.extend_from_slice(&line);
Arc::make_mut(&mut self.sources[source]).data.extend_from_slice(&line);
} else {
return Ok((Some(line), Some(encoding)));
}
@@ -350,10 +350,10 @@ impl Executor {
let traced = self.read_parameter(Parameter::Tracingscantokens).width() > 0;
let source = self.sources.len();
let mouth = Mouth::generated(source, bytes.clone(), profile, separator);
self.sources.push(SourceFile {
self.sources.push(Arc::new(SourceFile {
name: "<scantokens>".into(),
data: bytes,
});
}));
self.generated_inputs
.insert(source, GeneratedInput { origin, separator });
self.reads.insert(Dependency::Source(source));
@@ -27,7 +27,7 @@ pub struct FormatImage {
schema: u32,
engine: String,
state: State,
sources: Vec<SourceFile>,
sources: Vec<Arc<SourceFile>>,
#[serde(default)]
stream_sources: BTreeSet<usize>,
generated_inputs: BTreeMap<usize, GeneratedInput>,
@@ -114,7 +114,7 @@ impl FormatImage {
schema: SCHEMA,
engine: ENGINE.into(),
state,
sources: execution.sources,
sources: execution.sources.into_iter().map(Arc::new).collect(),
stream_sources: execution.stream_sources,
generated_inputs: execution.generated_inputs,
resources,
@@ -138,7 +138,7 @@ impl FormatImage {
if !self.generated_inputs.contains_key(&id)
&& let Some(path) = bindings.get(Path::new(&source.name))
{
source.name = path.to_string_lossy().into_owned();
Arc::make_mut(source).name = path.to_string_lossy().into_owned();
}
}
for resource in &mut self.resources {
+2 -2
View File
@@ -718,12 +718,12 @@ pub struct ExecutionFailure {
impl Error {
fn at(
sources: &[SourceFile],
sources: &[impl std::borrow::Borrow<SourceFile>],
profile: InputProfile,
message: impl Into<String>,
span: Span,
) -> Self {
let source = sources.get(span.source);
let source = sources.get(span.source).map(std::borrow::Borrow::borrow);
let name = source.map_or("<input>", |s| s.name.as_str()).to_owned();
let prefix = source.map_or(&[][..], |s| &s.data[..span.start.min(s.data.len())]);
let (mut line, mut column, mut carriage_return) = (1, 1, false);
@@ -1,5 +1,5 @@
use super::{CatCode, CommandName, Dependency, Span, State, Token, TokenKind};
use std::collections::BTreeSet;
use std::{collections::BTreeSet, sync::Arc};
use super::xe_encoding::{Character, Encoding};
@@ -282,7 +282,7 @@ enum LineBreaks {
#[derive(Clone)]
pub(super) struct Mouth {
source: usize,
data: Vec<u8>,
data: Arc<Vec<u8>>,
profile: super::InputProfile,
offset: usize,
line: Vec<Character>,
@@ -321,7 +321,7 @@ impl Mouth {
}
pub(super) fn rebind_loaded_prefix(&mut self, data: Vec<u8>) {
debug_assert!(self.matches_loaded_prefix(&data));
self.data = data;
self.data = Arc::new(data);
}
pub(super) fn payload_bytes(&self) -> usize {
self.data.len()
@@ -351,7 +351,7 @@ impl Mouth {
};
Self {
source,
data,
data: Arc::new(data),
profile,
offset,
line: Vec::new(),