Reuse settled TeX suffixes after physical line edits

This commit is contained in:
gloamxun committed 2026-12-01 23:49:39 +08:00
1 parent 5b86a7ac7e
commit ac5f691a48
15 files changed
+518 -30

No files matched your search

+18 -8
View File
@@ -1,4 +1,4 @@
use std::collections::{BTreeSet, VecDeque};
use std::collections::{BTreeMap, BTreeSet, VecDeque};
use std::hash::{BuildHasher, RandomState};
use std::sync::Arc;
@@ -282,6 +282,7 @@ pub struct Executor {
format_image_warnings: Vec<String>,
pdf_force_pagebox_warned: bool,
input_position: Option<(usize, usize)>,
line_observations: BTreeMap<usize, usize>,
paragraph: Option<super::paragraph::Builder>,
vertical: super::boxes::VerticalBuilder,
box_frames: Vec<boxes::BoxFrame>,
@@ -617,6 +618,7 @@ impl Executor {
format_image_warnings: Vec::new(),
pdf_force_pagebox_warned: false,
input_position: None,
line_observations: BTreeMap::new(),
paragraph: None,
vertical,
box_frames: Vec::new(),
@@ -702,6 +704,10 @@ impl Executor {
self.state.page_marks.clear();
self
}
/// Keep every observation even when its source was already read in the prefix.
fn observe_line_number(&mut self, source: usize) {
*self.line_observations.entry(source).or_default() += 1;
}
fn error(&self, message: impl Into<String>, span: Span) -> Error {
let mut error = Error::at(&self.sources, self.state.input_profile(), message, span);
if let Some(generated) = self.generated_inputs.get(&span.source) {
@@ -2781,6 +2787,7 @@ impl Executor {
self.error("no native input position available", self.current)
})?;
self.reads.insert(Dependency::InputPosition(source));
self.observe_line_number(source);
i32::try_from(line)
.map_err(|_| self.error("input line number overflow", self.current))
}
@@ -3253,10 +3260,10 @@ impl Executor {
.decode_line(&line[bom..bom + length], base + bom, &self.state, &mut self.reads)
.map_err(|e| self.error(e, Span { source, start: base + bom, end }))?;
if warnings > 0 {
self.observe_xe_utf8_warnings(
vec![(self.input_position.map_or(1, |(_, line)| line), warnings)],
files,
)?;
let (line_source, line) = self
.input_position
.map_or((None, 1), |(source, line)| (Some(source), line));
self.observe_xe_utf8_warnings(line_source, vec![(line, warnings)], files)?;
}
chars
} else {
@@ -3352,7 +3359,7 @@ impl Executor {
return self.fail("native read token limit exceeded");
}
}
self.observe_xe_utf8_warnings(mouth.take_utf8_warnings(), files)?;
self.observe_xe_utf8_warnings(Some(source), mouth.take_utf8_warnings(), files)?;
if depth == 0 {
break;
}
@@ -3584,6 +3591,7 @@ impl Executor {
stream_sources: self.stream_sources,
generated_inputs: self.generated_inputs,
reads,
line_observations: Some(self.line_observations),
events: self.events.into_vec(),
steps: self.steps,
reads_event_history: self.reads_event_history,
@@ -4089,6 +4097,7 @@ impl Executor {
stream_sources: self.stream_sources,
generated_inputs: self.generated_inputs,
reads,
line_observations: Some(self.line_observations),
incoming_state,
steps: self.steps,
reads_event_history: self.reads_event_history,
@@ -4187,11 +4196,12 @@ impl Executor {
let Some(InputFrame::Source { source, mouth, .. }) = self.inputs.last_mut() else {
unreachable!("new job starts with its entry source");
};
let source = *source;
let line = mouth
.load_line(&self.state, &mut self.reads)
.map(|_| (*source, mouth.line_number()));
.map(|_| (source, mouth.line_number()));
let warnings = mouth.take_utf8_warnings();
self.observe_xe_utf8_warnings(warnings, files)?;
self.observe_xe_utf8_warnings(Some(source), warnings, files)?;
self.input_position =
Some(line.map_err(|(span, message)| self.error(message, span))?);
self.push_mode_hook(TokenParameter::Everyjob)?;