Reuse native command meanings within a binding revision
This commit is contained in:
1 parent
9f4cc64c8f
commit
d8af3518a7
4 files changed
+135
-32
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use std::collections::{BTreeSet, HashSet, VecDeque};
|
||||
use std::collections::{BTreeSet, HashMap, VecDeque};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::job::InputStream;
|
||||
@@ -233,7 +233,9 @@ pub struct Executor {
|
||||
stream_sources: BTreeSet<usize>,
|
||||
generated_inputs: std::collections::BTreeMap<usize, GeneratedInput>,
|
||||
reads: DependencyReads,
|
||||
meaning_reads: HashSet<CommandName>,
|
||||
// Cache the resolved meaning alongside the already required read evidence.
|
||||
// The revision is only valid within this executor and its checkpoints.
|
||||
meaning_reads: HashMap<CommandName, (u64, Meaning)>,
|
||||
reads_tracing_macros: bool,
|
||||
conditionals: Vec<Conditional>,
|
||||
in_csname: bool,
|
||||
@@ -488,7 +490,7 @@ impl Executor {
|
||||
stream_sources: BTreeSet::new(),
|
||||
generated_inputs: Default::default(),
|
||||
reads: DependencyReads::default(),
|
||||
meaning_reads: HashSet::new(),
|
||||
meaning_reads: HashMap::new(),
|
||||
reads_tracing_macros: false,
|
||||
conditionals: Vec::new(),
|
||||
in_csname: false,
|
||||
@@ -724,26 +726,30 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn record_meaning_read(&mut self, name: &CommandName) {
|
||||
if !self.meaning_reads.contains(name) {
|
||||
self.meaning_reads.insert(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn take_dependency_reads(&mut self) -> BTreeSet<Dependency> {
|
||||
let mut reads = std::mem::take(&mut self.reads).into_ordered();
|
||||
reads.extend(self.meaning_reads.drain().map(Dependency::Meaning));
|
||||
reads.extend(self.meaning_reads.drain().map(|(name, _)| Dependency::Meaning(name)));
|
||||
reads
|
||||
}
|
||||
|
||||
fn meaning(&mut self, token: &Token) -> Meaning {
|
||||
match &token.kind {
|
||||
TokenKind::Command(name) => {
|
||||
self.record_meaning_read(name);
|
||||
self.state.meaning(name)
|
||||
let TokenKind::Command(name) = &token.kind else {
|
||||
return Meaning::Character(token.kind.clone());
|
||||
};
|
||||
self.lookup_meaning(name)
|
||||
}
|
||||
fn lookup_meaning(&mut self, name: &CommandName) -> Meaning {
|
||||
let revision = self.state.command_revision();
|
||||
if let Some((cached_revision, meaning)) = self.meaning_reads.get_mut(name) {
|
||||
if *cached_revision != revision {
|
||||
*meaning = self.state.meaning(name);
|
||||
*cached_revision = revision;
|
||||
}
|
||||
kind => Meaning::Character(kind.clone()),
|
||||
return meaning.clone();
|
||||
}
|
||||
let meaning = self.state.meaning(name);
|
||||
self.meaning_reads.insert(name.clone(), (revision, meaning.clone()));
|
||||
meaning
|
||||
}
|
||||
fn primitive(&mut self, token: &Token) -> Option<Primitive> {
|
||||
match self.meaning(token) {
|
||||
@@ -1357,8 +1363,7 @@ impl Executor {
|
||||
Etexrevision => self.print_tokens(".6", token)?,
|
||||
Csname => {
|
||||
let name = self.csname(files)?;
|
||||
self.record_meaning_read(&name);
|
||||
if self.state.meaning(&name) == Meaning::Undefined {
|
||||
if self.lookup_meaning(&name) == Meaning::Undefined {
|
||||
self.define_traced(
|
||||
name.clone(),
|
||||
Meaning::Primitive(Relax),
|
||||
@@ -1756,8 +1761,7 @@ impl Executor {
|
||||
}
|
||||
Ifcsname => {
|
||||
let name = self.csname(files)?;
|
||||
self.record_meaning_read(&name);
|
||||
self.state.meaning(&name) != Meaning::Undefined
|
||||
self.lookup_meaning(&name) != Meaning::Undefined
|
||||
}
|
||||
Ifincsname => self.in_csname,
|
||||
Ifeof => {
|
||||
|
||||
@@ -796,12 +796,23 @@ enum PdftexRevision {
|
||||
R24,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
struct CommandBindings(HashMap<Arc<CommandName>, Meaning>);
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct CommandBindings {
|
||||
by_name: HashMap<Arc<CommandName>, Meaning>,
|
||||
revision: u64,
|
||||
}
|
||||
|
||||
impl PartialEq for CommandBindings {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.by_name == other.by_name
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for CommandBindings {}
|
||||
|
||||
impl CommandBindings {
|
||||
fn ordered(&self) -> Vec<(&Arc<CommandName>, &Meaning)> {
|
||||
let mut entries: Vec<_> = self.0.iter().collect();
|
||||
let mut entries: Vec<_> = self.by_name.iter().collect();
|
||||
entries.sort_unstable_by(|(left, _), (right, _)| left.cmp(right));
|
||||
entries
|
||||
}
|
||||
@@ -824,7 +835,10 @@ impl<'de> serde::Deserialize<'de> for CommandBindings {
|
||||
let entries = <Vec<(Arc<CommandName>, Meaning)> as serde::Deserialize>::deserialize(
|
||||
deserializer,
|
||||
)?;
|
||||
Ok(Self(entries.into_iter().collect()))
|
||||
Ok(Self {
|
||||
by_name: entries.into_iter().collect(),
|
||||
revision: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,7 +978,7 @@ fn buffered_fingerprint_matches_the_ordered_state_hash() {
|
||||
assert_eq!(state.fingerprint(), direct.finish());
|
||||
let mut ordered_hash = DefaultHasher::new();
|
||||
let mut table_hash = DefaultHasher::new();
|
||||
let ordered: BTreeMap<_, _> = state.commands.0.iter().collect();
|
||||
let ordered: BTreeMap<_, _> = state.commands.by_name.iter().collect();
|
||||
ordered.hash(&mut ordered_hash);
|
||||
state.commands.hash(&mut table_hash);
|
||||
assert_eq!(table_hash.finish(), ordered_hash.finish());
|
||||
@@ -1451,8 +1465,8 @@ impl State {
|
||||
}
|
||||
return;
|
||||
}
|
||||
c.usage.state.command_entries = self.commands.0.len();
|
||||
for (name, meaning) in &self.commands.0 {
|
||||
c.usage.state.command_entries = self.commands.by_name.len();
|
||||
for (name, meaning) in &self.commands.by_name {
|
||||
if let CommandName::Control(name) = name.as_ref() {
|
||||
c.usage.state.control_name_bytes += name.len();
|
||||
}
|
||||
@@ -2050,7 +2064,7 @@ impl State {
|
||||
let name = CommandName::Control(name.into());
|
||||
if enabled {
|
||||
self.command_bindings_mut().entry(name.into()).or_insert(meaning);
|
||||
} else if self.commands.0.get(&name) == Some(&meaning) {
|
||||
} else if self.commands.by_name.get(&name) == Some(&meaning) {
|
||||
self.command_bindings_mut().remove(&name);
|
||||
}
|
||||
}
|
||||
@@ -2227,7 +2241,7 @@ impl State {
|
||||
let meaning = Meaning::Primitive(primitive);
|
||||
if self.input_profile != super::InputProfile::TeX8Bit {
|
||||
self.command_bindings_mut().insert(name.into(), meaning);
|
||||
} else if self.commands.0.get(&name) == Some(&meaning) {
|
||||
} else if self.commands.by_name.get(&name) == Some(&meaning) {
|
||||
self.command_bindings_mut().remove(&name);
|
||||
}
|
||||
}
|
||||
@@ -2297,7 +2311,7 @@ impl State {
|
||||
let state = Self::initex().with_input_profile(self.input_profile);
|
||||
let state = if extended { state.with_etex() } else { state };
|
||||
Arc::unwrap_or_clone(state.commands)
|
||||
.0
|
||||
.by_name
|
||||
.into_iter()
|
||||
.filter_map(|(name, meaning)| match Arc::unwrap_or_clone(name) {
|
||||
CommandName::Control(name) => Some((name, meaning)),
|
||||
@@ -2310,7 +2324,13 @@ impl State {
|
||||
}
|
||||
|
||||
fn command_bindings_mut(&mut self) -> &mut HashMap<Arc<CommandName>, Meaning> {
|
||||
&mut Arc::make_mut(&mut self.commands).0
|
||||
let bindings = Arc::make_mut(&mut self.commands);
|
||||
bindings.revision += 1;
|
||||
&mut bindings.by_name
|
||||
}
|
||||
|
||||
pub(super) fn command_revision(&self) -> u64 {
|
||||
self.commands.revision
|
||||
}
|
||||
|
||||
pub fn meaning(&self, name: &CommandName) -> Meaning {
|
||||
@@ -2320,7 +2340,7 @@ impl State {
|
||||
CommandName::FrozenPrimitive(_) => self.original_primitive(name)
|
||||
.map(|(_, meaning)| meaning.clone()).unwrap_or(Meaning::Undefined),
|
||||
CommandName::Font(font) => Meaning::Font(*font),
|
||||
_ => self.commands.0.get(name).cloned().unwrap_or(Meaning::Undefined),
|
||||
_ => self.commands.by_name.get(name).cloned().unwrap_or(Meaning::Undefined),
|
||||
}
|
||||
}
|
||||
/// Classic projection for byte-table consumers. A code outside the
|
||||
@@ -2719,7 +2739,7 @@ impl State {
|
||||
return;
|
||||
}
|
||||
let value = match &key {
|
||||
Key::Command(name) => Saved::Command(self.commands.0.get(name).cloned()),
|
||||
Key::Command(name) => Saved::Command(self.commands.by_name.get(name).cloned()),
|
||||
Key::Catcode(c) => Saved::Catcode(self.catcodes.get(c).copied()),
|
||||
Key::Count(index) => Saved::Integer(self.count(*index)),
|
||||
Key::Endlinechar => Saved::Integer(self.endlinechar),
|
||||
|
||||
@@ -50,3 +50,53 @@ fn meaning_reads_survive_deduplication_and_include_negative_csname_queries() {
|
||||
Meaning::Primitive(Primitive::Relax)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resumed_command_reads_follow_local_restores_and_global_redefinitions() {
|
||||
let prefix = br"\catcode123=1 \catcode125=2
|
||||
\ifcsname value\endcsname\message{unexpected}\else\message{absent}\fi
|
||||
\def\value{outer}\message{\value}
|
||||
";
|
||||
let source_with = |label: &str| SourceFile {
|
||||
name: "probe.tex".into(),
|
||||
data: [
|
||||
prefix.as_slice(),
|
||||
format!(r"\begingroup\def\value{{{label}}}\message{{\value}}\endgroup").as_bytes(),
|
||||
br"
|
||||
\message{\value}
|
||||
\begingroup\global\let\value\missing\endgroup
|
||||
\ifcsname value\endcsname\message{unexpected}\else\message{absent}\fi
|
||||
\gdef\value{global}\message{\value}
|
||||
\end",
|
||||
]
|
||||
.concat(),
|
||||
};
|
||||
let engine = || Executor::new(State::initex().with_etex(), Limits::default());
|
||||
let (original, captured) =
|
||||
engine().run_capturing_entry(source_with("old"), &mut NoFiles, prefix.len(), |_| ());
|
||||
original.unwrap();
|
||||
let (checkpoint, ()) = captured.unwrap();
|
||||
assert_eq!(checkpoint.frontier(), prefix.len());
|
||||
|
||||
let edited = source_with("local");
|
||||
let full = engine().run(edited.clone(), &mut NoFiles).unwrap();
|
||||
let resumed = checkpoint
|
||||
.resume_after_host_replay(edited, &mut NoFiles, Cancellation::default())
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(resumed, full);
|
||||
let messages: Vec<_> = resumed
|
||||
.events
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
Event::Message { text, .. } => Some(text.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(messages, ["absent", "outer", "local", "outer", "absent", "global"]);
|
||||
assert!(
|
||||
resumed
|
||||
.reads
|
||||
.contains(&Dependency::Meaning(CommandName::Control("value".into())))
|
||||
);
|
||||
}
|
||||
@@ -18,6 +18,35 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-29 合并命令含义查询与依赖记录
|
||||
|
||||
原生命令查询在执行器中一次索引即返回已解析的含义,并记下读取的
|
||||
命令名。命令定义、别名及出组恢复共用命令表的递增版本。版本变化
|
||||
后重新查表,包括此前查不到的命令。检查点保留配套版本和查询记录。
|
||||
命令表版本仅用于执行中失效,持久格式、状态比较、状态指纹及输出的
|
||||
有序读集合仍使用真实内容。
|
||||
|
||||
15 项定向检查通过,覆盖检查点后局部覆盖与出组恢复、全局撤销
|
||||
并重新定义、负查找、宏扫描、赋值和格式重载。优化构建用同一份
|
||||
NeurIPS 2025 原样项目、XeLaTeX 镜像、字体和生成初态重跑原探针。
|
||||
|
||||
| 执行阶段 | 基线 | 候选 | 仍执行的步骤 |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| 初次编译 | 7.893 s | 7.275 s | 19,570,891 |
|
||||
| 第 3 页标点编辑 | 3.651 s | 2.924 s | 5,281,627 |
|
||||
| 出错后恢复原文 | 3.337 s | 2.947 s | 5,181,446 |
|
||||
|
||||
编辑和恢复各只转换第 3 页。两个版本都用独立全量核对 PDF、SVG、
|
||||
页列表、来源、依赖、辅助文件和最终状态指纹。故障期间保留上次
|
||||
成功发布。候选输出与上轮归档的四份 PDF/SVG 逐字节相同。两次
|
||||
成功修订的末态、页面构建器、流状态和依赖集合也分别与其前一份
|
||||
成功修订相同。已确认末态收敛,下一步应在第 3 页后的出页边界
|
||||
定位最早能做相同核验的位置,并校验未执行后缀的资源和文件效果。
|
||||
此次改动降低现有执行成本。正式浏览器可见延迟和内存沿用原门禁。
|
||||
|
||||
证据在 target/p4-neurips-tail/,SHA256SUMS 指纹为
|
||||
e26eab52fc6286dcd5b0229da24083e30af493591fc7ee41b1ceae578f08ae11。
|
||||
|
||||
## 2026-11-29 TeX 资源大小写查找与原样 Wiley 双栏
|
||||
|
||||
Unix 上的 TeX 资源查找按配置路径顺序,在每个路径项内尝试全部精确
|
||||
|
||||
Reference in new issue
Block a user