Skip to content

fix(native): canonical Number round-trip text for self-host parity - #168

Open
xingxuling wants to merge 7 commits into
mainfrom
codex/canonical-number-roundtrip-v095
Open

fix(native): canonical Number round-trip text for self-host parity#168
xingxuling wants to merge 7 commits into
mainfrom
codex/canonical-number-roundtrip-v095

Conversation

@xingxuling

@xingxuling xingxuling commented Sep 6, 2026

Copy link
Copy Markdown
Owner

中文摘要

修复 RCL native runtime 的 text(Number) 只使用 %.15g 导致的 self-host 编译器浮点语义漂移,并同步重建受 source-hash 约束的 Windows 原生分发。

根因

Self-host compiler 在解析 NUMBER 时会经过:

token text -> number_from_text -> text(number) -> LiteralExpr

JS runtime 的 text(Number) 使用 String(value);native VM 原实现使用 snprintf("%.15g")。长小数因此损失 1-10 ULP,并同时造成:

  • RBC Number Pool 出现实际可执行浮点差异;
  • canonical program JSON 的 Number literal 文本变化;
  • programRoot/sourceRoot 连锁变化;
  • native self-host compiler 与 JS reference compiler 不再 byte-identical。

sourceRoot 本身在 native VM 中只做索引校验/输出,不参与 opcode 执行或 semantic state root;但这次 parity failure 不是纯 metadata,因为 Number Pool 中 9 个初始 MLP 参数也真实漂移。

修复

native VM 现在:

  1. 在 1..17 位有效数字中寻找能精确 round-trip 回同一 IEEE-754 double 的最短候选;
  2. 再按 ECMAScript Number::toString 的 fixed/scientific 阈值规范化文本;
  3. -0 规范化为 0
  4. 保留 NaN / Infinity 文本语义。

这不是把 parity gate 降级,而是修复 native 数字文本 ABI,使 self-host 输出重新和 JS canonical compiler 对齐。

新回归

tests/native-number-text-parity.test.mjs 同时验证:

  • native text(number_from_text(...)) 与 JS String(Number(...)) 逐字一致;
  • 覆盖 DWAC K08 暴露出的长小数,以及 1e-6 / 1e-7 / 1e20 / 1e21 / 0.5000 / -0 等边界;
  • 含长小数的 .rcl 经 native rclc 与 JS reference compiler 再次产生整份 byte-identical RBC。

Windows 原生分发

修改 native/rclvm.c 后,旧 Windows prebuilt manifest 正确以 source hash 不一致拒绝旧二进制;没有绕过该保护。

随后在 Windows runner + Zig 0.16.0 上重新构建并记录:

  • rclvm.exe
  • rclc.exe
  • rclvmd.exe
  • provider_demo.exe
  • rclfoundation.exe
  • librclvm.a
  • rclvm.dll
  • rclvm.lib
  • native-windows-manifest.json

重建后 scripts/build-native.mjs 的 prebuilt/source verification PASS。

已执行验证

Ubuntu one-shot:

  • native runtime rebuild PASS;
  • Number text ABI + self-host byte parity PASS;
  • K08-B General MLP native regression PASS。

Windows rebuild runner:

  • Zig 0.16.0 native distribution rebuild PASS;
  • source/artifact manifest verification PASS;
  • Number text ABI + self-host byte parity PASS;
  • K08-B General MLP native regression PASS。

DWAC v0.18 集成验证也已在 Ubuntu 直接恢复完整 .rcl -> native rclc -> RBC -> native rclvm -> register -> Live AI PASS,bytecode divergence diagnostic 不再触发。

临时 one-shot patch/rebuild workflows 已删除,不进入主线。

权威边界

  • 不改变 RCL Evidence / authority ownership;
  • 不降低 native/reference byte parity 要求;
  • 不声明新的 AI 能力层级;
  • 修复的是跨 JS/native/self-host 的 Number 文本 ABI 与确定性。

@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rcl-rncs-mcp Ready Ready Preview Sep 6, 2026 11:04am UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant