diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index 9cc5e7e..d82f2d3 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -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.into_iter().map(Arc::new).collect(); + executor.sources = execution.sources; executor.stream_sources = execution.stream_sources; executor.generated_inputs = execution.generated_inputs; executor.split_discards = execution.split_discards; @@ -3306,7 +3306,7 @@ impl Executor { } else { ParagraphMode::Vertical }, - sources: self.sources.into_iter().map(Arc::unwrap_or_clone).collect(), + sources: self.sources, 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.into_iter().map(Arc::unwrap_or_clone).collect(), + sources: self.sources, 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.into_iter().map(Arc::unwrap_or_clone).collect(), + sources: self.sources, stream_sources: self.stream_sources, generated_inputs: self.generated_inputs, reads: self.reads, diff --git a/crates/texrra-tex-core/src/execution/format_image.rs b/crates/texrra-tex-core/src/execution/format_image.rs index 73f85d9..2363290 100644 --- a/crates/texrra-tex-core/src/execution/format_image.rs +++ b/crates/texrra-tex-core/src/execution/format_image.rs @@ -114,7 +114,7 @@ impl FormatImage { schema: SCHEMA, engine: ENGINE.into(), state, - sources: execution.sources.into_iter().map(Arc::new).collect(), + sources: execution.sources, stream_sources: execution.stream_sources, generated_inputs: execution.generated_inputs, resources, diff --git a/crates/texrra-tex-core/src/execution/mod.rs b/crates/texrra-tex-core/src/execution/mod.rs index 4b70a64..5ab2661 100644 --- a/crates/texrra-tex-core/src/execution/mod.rs +++ b/crates/texrra-tex-core/src/execution/mod.rs @@ -654,7 +654,8 @@ pub struct Execution { /// Physical scanner position, independent of macro definition/call spans. pub input_position: Option<(usize, usize)>, pub paragraph_mode: ParagraphMode, - pub sources: Vec, + /// Physical and generated inputs in span-source order. + pub sources: Vec>, /// Source IDs backed by the bytes delivered through an input stream. #[serde(default)] pub stream_sources: BTreeSet, @@ -697,7 +698,7 @@ pub struct Error { /// not a resumable executor checkpoint or a successful document. #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct ExecutionEvidence { - pub sources: Vec, + pub sources: Vec>, pub source_versions: Vec, pub stream_sources: BTreeSet, pub generated_inputs: std::collections::BTreeMap, diff --git a/crates/texrra-tex-core/src/execution/session.rs b/crates/texrra-tex-core/src/execution/session.rs index e4689ba..c3c5946 100644 --- a/crates/texrra-tex-core/src/execution/session.rs +++ b/crates/texrra-tex-core/src/execution/session.rs @@ -56,8 +56,8 @@ impl RevisionExecution { .iter() .enumerate() .map(|(id, source)| { - // The previous result was built by this session. Match the - // scanned bytes, including generated and stream input. + // A shared source keeps its exact bytes across revisions. + // Independently loaded sources can also have identical content. previous .and_then(|old| { old.execution @@ -65,7 +65,7 @@ impl RevisionExecution { .get(id) .zip(old.source_versions.get(id)) }) - .filter(|(old_source, _)| *old_source == source) + .filter(|(old_source, _)| Arc::ptr_eq(old_source, source) || old_source.as_ref() == source.as_ref()) .map_or_else( || SourceVersion { sha256: format!("{:x}", Sha256::digest(&source.data)), diff --git a/docs/P2_M1_PROGRESS.md b/docs/P2_M1_PROGRESS.md index 257e32d..cba9f52 100644 --- a/docs/P2_M1_PROGRESS.md +++ b/docs/P2_M1_PROGRESS.md @@ -18,6 +18,30 @@ | W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 | | W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 | +## 2026-11-28 发布来源与指纹复用 + +成功执行和失败证据都直接交付内核的来源对象,以 Arc 保存条目。 +来源仍按实际扫描顺序编号,JSON 继续输出源文件名和原始字节。调用者可以借用 +条目,也可用 Arc::unwrap_or_clone 取得独立值。格式 dump 和作业恢复共用这一 +表示。流追加及格式路径重绑仍各自取得独立值。 + +会话校验来源指纹时,共享同一个对象即可复用上一修订的指纹。重新读取文件时 +按实际名字及字节比较,内容变化时计算新指纹。先前发布的结果继续持有原来源, +新一轮对生成文件的读取会带来自己的字节和版本。 + +依次编辑原样 A4 的主文件和子文件,两次发布均与上次共享全部 54 份 +格式来源。实测将同一组来源复制为独立值会分配 5,177,986 字节。 +两轮的 PDF、绘制列表、SVG、实际来源字节、指纹、aux 与独立全量一致。 +生成文件版本替换和数学修订的错误恢复通过定向回归。 + +已为下一批准备 XeTeX 命名色彩空间基线。原版生成两页专色与 Lab 样例, +包含跨页颜色栈、独立填充和描边。当前原生在名为 @ink 的色彩空间上 +报错。原样输入、参考 PDF 和首个失败记录见 target/p3-xdv-resource-colors/。 +[参考驱动的色彩空间解析](https://raw.githubusercontent.com/TeX-Live/texlive-source/e49735c7ed1aa2ed9c2e68e6632d27f20d42eca7/texk/dvipdfm-x/spc_util.c) + +本地证据见 target/p4-shared-published-sources/。 +正式编辑可见 p95、峰值内存及出版模板矩阵仍按总门禁验收。 + ## 2026-11-28 格式来源与检查点共享字节 格式镜像、从镜像创建的作业和检查点共享已有来源字节。输入游标为各次 diff --git a/src/native_checkpoint_guard.rs b/src/native_checkpoint_guard.rs index f174db6..bdbf599 100644 --- a/src/native_checkpoint_guard.rs +++ b/src/native_checkpoint_guard.rs @@ -1754,6 +1754,17 @@ fn generated_input_change_uses_a_checkpoint_before_the_read() { assert_eq!(updated.source_map.sources, full.source_map.sources); assert_eq!(updated.source_map.pages, full.source_map.pages); assert!(updated.execution.execution == full.execution.execution); + let aux_source = |result: &CompiledDocument| { + let (id, source) = result.execution.execution.sources.iter().enumerate() + .find(|(_, source)| Path::new(&source.name) == aux).unwrap(); + (source.clone(), result.execution.source_versions[id].clone()) + }; + let (old_source, old_version) = aux_source(&original); + let (current_source, current_version) = aux_source(&updated); + assert!(!Arc::ptr_eq(&old_source, ¤t_source)); + assert_eq!(old_source.data, b"\\def\\widthfromaux{11}\n"); + assert_eq!(current_source.data, b"\\def\\widthfromaux{22}\n"); + assert_ne!(old_version, current_version); assert_eq!(fs::read(&aux).unwrap(), b"\\def\\widthfromaux{22}\n"); }