Reuse session-verified source versions in native source maps
This commit is contained in:
1 parent
225736ce80
commit
0a21eb27a7
5 files changed
+68
-9
No files matched your search
@@ -152,6 +152,19 @@ impl NativeSession {
|
|||||||
commit().map(Some)
|
commit().map(Some)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build a source map for a completed execution. The current result
|
||||||
|
/// already has byte-verified sources owned by this session.
|
||||||
|
pub fn source_map(
|
||||||
|
&self,
|
||||||
|
revision: &Arc<RevisionExecution>,
|
||||||
|
pages: &[crate::render::DisplayList],
|
||||||
|
) -> Result<crate::source_map::SourceMap, String> {
|
||||||
|
let current = self
|
||||||
|
.latest()
|
||||||
|
.is_some_and(|latest| Arc::ptr_eq(&latest, revision));
|
||||||
|
crate::source_map::SourceMap::from_revision_checked(revision, pages, !current)
|
||||||
|
}
|
||||||
|
|
||||||
/// Last successfully published result, with its own revision identity.
|
/// Last successfully published result, with its own revision identity.
|
||||||
pub fn latest(&self) -> Option<Arc<RevisionExecution>> {
|
pub fn latest(&self) -> Option<Arc<RevisionExecution>> {
|
||||||
self.state
|
self.state
|
||||||
|
|||||||
@@ -196,6 +196,13 @@ impl SourceMap {
|
|||||||
pub fn from_revision(
|
pub fn from_revision(
|
||||||
revision: &RevisionExecution,
|
revision: &RevisionExecution,
|
||||||
pages: &[DisplayList],
|
pages: &[DisplayList],
|
||||||
|
) -> Result<Self, String> {
|
||||||
|
Self::from_revision_checked(revision, pages, true)
|
||||||
|
}
|
||||||
|
pub(crate) fn from_revision_checked(
|
||||||
|
revision: &RevisionExecution,
|
||||||
|
pages: &[DisplayList],
|
||||||
|
verify_source_hashes: bool,
|
||||||
) -> Result<Self, String> {
|
) -> Result<Self, String> {
|
||||||
let execution = &revision.execution;
|
let execution = &revision.execution;
|
||||||
if revision.source_versions.len() != execution.sources.len() {
|
if revision.source_versions.len() != execution.sources.len() {
|
||||||
@@ -208,7 +215,8 @@ impl SourceMap {
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(id, (file, version))| {
|
.map(|(id, (file, version))| {
|
||||||
if version.bytes != file.data.len() as u64
|
if version.bytes != file.data.len() as u64
|
||||||
|| version.sha256 != format!("{:x}", Sha256::digest(&file.data))
|
|| (verify_source_hashes
|
||||||
|
&& version.sha256 != format!("{:x}", Sha256::digest(&file.data)))
|
||||||
{
|
{
|
||||||
return Err(format!("source map version mismatch for source {id}"));
|
return Err(format!("source map version mismatch for source {id}"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,6 +283,43 @@ fn generated_input_has_its_own_bytes_version_and_real_parent_origin() {
|
|||||||
.starts_with(b"AB")
|
.starts_with(b"AB")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn verified_source_versions_require_the_sessions_exact_execution_result() {
|
||||||
|
let session = NativeSession::default();
|
||||||
|
let revision = session
|
||||||
|
.start()
|
||||||
|
.run(
|
||||||
|
Executor::new(State::initex(), Limits::default()).with_native_pages(),
|
||||||
|
SourceFile {
|
||||||
|
name: "main.tex".into(),
|
||||||
|
data: br"\catcode123=1 \catcode125=2 \shipout\hbox{\vrule width4pt height1pt}\end"
|
||||||
|
.to_vec(),
|
||||||
|
},
|
||||||
|
&mut NoFiles,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let pages = revision.execution.shipout_display_lists().unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
session.source_map(&revision, &pages).unwrap(),
|
||||||
|
SourceMap::from_revision(&revision, &pages).unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut versions = revision.source_versions.clone();
|
||||||
|
versions[0].sha256 = "invalid".into();
|
||||||
|
let copied = Arc::new(RevisionExecution {
|
||||||
|
revision: revision.revision,
|
||||||
|
execution: revision.execution.clone(),
|
||||||
|
source_versions: versions,
|
||||||
|
execution_resources: None,
|
||||||
|
});
|
||||||
|
assert!(
|
||||||
|
session
|
||||||
|
.source_map(&copied, &pages)
|
||||||
|
.unwrap_err()
|
||||||
|
.contains("version mismatch")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn malformed_versions_spans_generated_parents_and_paint_indices_are_rejected() {
|
fn malformed_versions_spans_generated_parents_and_paint_indices_are_rejected() {
|
||||||
let source = format!(r"{HEADER}\shipout\hbox{{\scantokens{{A}}}}\end");
|
let source = format!(r"{HEADER}\shipout\hbox{{\scantokens{{A}}}}\end");
|
||||||
|
|||||||
@@ -947,7 +947,10 @@ PDF、SVG、来源和 aux 与各自的增量版本一致。
|
|||||||
隔离候选用会话当前持有的确切执行结果建立来源映射。会话生成源版本
|
隔离候选用会话当前持有的确切执行结果建立来源映射。会话生成源版本
|
||||||
时已计算内容指纹,校验页布局和构造映射时复用这份指纹。外部传入的
|
时已计算内容指纹,校验页布局和构造映射时复用这份指纹。外部传入的
|
||||||
执行结果仍核对其实际内容,包括相同修订号的独立结果。61项定向和
|
执行结果仍核对其实际内容,包括相同修订号的独立结果。61项定向和
|
||||||
端到端测试通过。
|
端到端测试通过。已按候选补丁和四份源文件指纹合入主线。完整工作区
|
||||||
|
1628项通过、零失败,两项保持手动验证。113组测试结果及日志记录在
|
||||||
|
`target/p4-source-map-session-identity/workspace.log`,SHA-256 为
|
||||||
|
`283d20de596e48ba3453ef887cdfcb5f17fcf82198797b61609409f7d5d6180d`。
|
||||||
|
|
||||||
原样 A4 各24次主文件热编辑的定向采样中,基线559个 CPU 样本中
|
原样 A4 各24次主文件热编辑的定向采样中,基线559个 CPU 样本中
|
||||||
有28个 SHA-256 样本,候选517个中有2个。布局与字体阶段中位数为
|
有28个 SHA-256 样本,候选517个中有2个。布局与字体阶段中位数为
|
||||||
@@ -975,7 +978,6 @@ PDF、SVG、来源和 aux 与各自的增量版本一致。
|
|||||||
和 `27d3cf03f10596999b9c570022e6fdab8c9dcc434c0cac99a1bdba967af5c577`。
|
和 `27d3cf03f10596999b9c570022e6fdab8c9dcc434c0cac99a1bdba967af5c577`。
|
||||||
两轮独立全量 `full-equivalence-{1,2}/receipt.json` 的 SHA-256 同为
|
两轮独立全量 `full-equivalence-{1,2}/receipt.json` 的 SHA-256 同为
|
||||||
`2c73f84608fe5b2cbaf23a2eb0e5ab2d7038078880ec4990e93af303d52c2756`。
|
`2c73f84608fe5b2cbaf23a2eb0e5ab2d7038078880ec4990e93af303d52c2756`。
|
||||||
完整工作区回归已启动。
|
|
||||||
|
|
||||||
对以上两轮各30次主文件编辑按样本拆分可见延迟。候选分别复用
|
对以上两轮各30次主文件编辑按样本拆分可见延迟。候选分别复用
|
||||||
558821步,剩余执行约78500步。执行阶段中位数为76.1和76.3 ms,
|
558821步,剩余执行约78500步。执行阶段中位数为76.1和76.3 ms,
|
||||||
@@ -985,8 +987,9 @@ PDF、SVG、来源和 aux 与各自的增量版本一致。
|
|||||||
按每个样本扣除执行阶段后,剩余时间的 p95 为146.2和169.5 ms。
|
按每个样本扣除执行阶段后,剩余时间的 p95 为146.2和169.5 ms。
|
||||||
该算术分解用于定位下一处要测量的边界。正式门禁仍用原样项目
|
该算术分解用于定位下一处要测量的边界。正式门禁仍用原样项目
|
||||||
编辑到可见页面的完整耗时。执行阶段继续区分有效 TeX 执行、
|
编辑到可见页面的完整耗时。执行阶段继续区分有效 TeX 执行、
|
||||||
检查点恢复和再捕获。编译就绪到首字节到达的余量需要区分
|
检查点恢复和再捕获。此前的独立双点记录已测得同类 A4 请求的
|
||||||
响应构造、发送调度和传输。原浏览器报告逐份核对 SHA-256。
|
Linux 进程内响应残差 p50 约0.9 ms,进程外两段合计约49–51 ms。
|
||||||
|
后续独立比较本地页面交付路径。原浏览器报告逐份核对 SHA-256。
|
||||||
按最近秩聚合的分解回执为
|
按最近秩聚合的分解回执为
|
||||||
`target/p4-source-map-session-identity/edge/critical-path-budget.json`,
|
`target/p4-source-map-session-identity/edge/critical-path-budget.json`,
|
||||||
SHA-256 为 `581a4b15a938f913be07aa4faa056ac0a1678534dd0de168d46ee144700a1914`。
|
SHA-256 为 `581a4b15a938f913be07aa4faa056ac0a1678534dd0de168d46ee144700a1914`。
|
||||||
|
|||||||
+2
-4
@@ -1080,8 +1080,7 @@ impl CompileJob {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
if let Some(path) = &request.layout_manifest {
|
if let Some(path) = &request.layout_manifest {
|
||||||
let source_map =
|
let source_map = self.compiler.session.source_map(&execution, &pages)?;
|
||||||
texrra_tex_core::source_map::SourceMap::from_revision(&execution, &pages)?;
|
|
||||||
files.write_layout_manifest(path, e, &pages, &source_map)?;
|
files.write_layout_manifest(path, e, &pages, &source_map)?;
|
||||||
}
|
}
|
||||||
evidence.phase = AttemptPhase::Fonts;
|
evidence.phase = AttemptPhase::Fonts;
|
||||||
@@ -1094,8 +1093,7 @@ impl CompileJob {
|
|||||||
return Err(CompileError::Host(error));
|
return Err(CompileError::Host(error));
|
||||||
}
|
}
|
||||||
reported?;
|
reported?;
|
||||||
let source_map =
|
let source_map = self.compiler.session.source_map(&execution, &pages)?;
|
||||||
texrra_tex_core::source_map::SourceMap::from_revision(&execution, &pages)?;
|
|
||||||
notify(
|
notify(
|
||||||
&request,
|
&request,
|
||||||
revision,
|
revision,
|
||||||
|
|||||||
Reference in new issue
Block a user