feat(migrate): M7 迁移与版本门 — per-file markup + migrate labels + 全仓迁移

原计划的"翻转默认 + 旧形硬报错"不可行:`[键](集合)` 与 `[描述](实现)` 外形相同,
翻转会让 506 处取元静默变义,硬报错又拿不到证据。改为**按文件声明**。

一、per-file markup
- frontmatter `markup: occlusion`(或 `标记: 遮蔽`)决定该文件模式
- load.rs 先取模式,用 parse::expr::with_markup(线程局部压栈)包住解析
- 同一进程可同时加载两种模式的文件(imports);MARQDO_MARKUP 仍作进程默认
- 好处:迁移逐文件、可增量、可回滚,不存在半迁移的静默错义

二、`marqdo migrate labels [--write|--json]`
改写规则:
  [键](集合)      → [键](access(集合, "键"))
  [`名`](集合)    → [名](access(集合, `名`))
  - [项](集合)    → - [项](遍历 集合 为 项)

安全模型:改写 → 重解析 → 证明等价 → 才写
- 原文件按 classic 解析得 AST-A;改写后按 occlusion 解析得 AST-B
- 反归一化 B(标签与键同名且 payload 为 access 的遮蔽还原成 Index)
- Debug(A) == Debug(反归一化(B))(抹掉行号)才写入,否则原文件一字不动

只改代码行(LineKind::Code);表格行只改 **…** 单元格,散文 markdown 链接不碰;
链式索引由内向外改写,已迁移的有守卫不二次改。

三、access 提升为宿主函数 HostFn::Access(u16 id 212)
与旧取元逐字一致(Map 按键 / List 1-based / 缺键 missing map key);
进 HostFn 是为了两个后端共用同一实现,interp 里的特例已删除。

四、顺带修的两处真实语义缺陷
1. payload 继承外层"文本模式":`f text=[k](access(c,k))` 中 access 不被当调用
   → `()` 内永远允许 callee(args)
2. 遮蔽形状判定过宽:`[问候] ([格式化] "Bo")` 误判为遮蔽
   → 要求 `]` 后紧跟 `(`,否则落回方括号调用

五、全仓迁移结果
migrate labels: 256 index, 23 loop, 80 file written;0 文件被等价性拒绝;
迁移后 cargo test --release → 604 passed / 0 failed;再跑迁移幂等。

等价性检查先后抓出 4 类改写 bug(表格散文链接、payload 文本模式、链式索引、
遮蔽与方括号调用混淆),每类都是先拦下再修工具,未污染文件。

测试:6 个单测 + 3 个集成(干跑不写盘 / 写入后运行输出不变且幂等 /
等价失败文件不动);全量 604 passed / 0 failed(M3 后 595 + 9);双后端一致。

文档:doc/design/change-m7-migration.md
This commit is contained in:
cflmy committed 2026-10-22 15:33:31 +08:00
1 parent 9dbcc728b6
commit 4488a3cb70
98 files changed
+1354 -278

No files matched your search

+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/foreign — foreign kernels v2
description: Structured execution, JSON calls, parallel fan-out, persistent kernels and an explicit state bridge
import foreign:lib/foreign.mq.md
@@ -17,8 +18,8 @@ Probe before you run.
**node = > foreign.probe lang="node"**
> print text=[ok](`node`)
> print text=[version](`node`)
> print text=[ok](access(`node`, "ok"))
> print text=[version](access(`node`, "version"))
`probe` returns `{lang, cmd, path, ok, version, error}`. Omit `lang` to inspect every known language.
@@ -33,9 +34,9 @@ console.log("hello from a foreign kernel");
**record = > foreign.invoke code=`marker`**
> print text=[ok](`record`)
> print text=[stdout](`record`)
> print text=[code](`record`)
> print text=[ok](access(`record`, "ok"))
> print text=[stdout](access(`record`, "stdout"))
> print text=[code](access(`record`, "code"))
`invoke` never throws on a process failure. Read `ok`, `code`, `stdout`, `stderr`, `ms`, `timed_out`, `truncated`, `result` and `error` from one record.
@@ -87,7 +88,7 @@ A persistent kernel.
**second = > foreign.session_eval id=`session` source="total * 2"**
> print text=[result](`second`)
> print text=[result](access(`second`, "result"))
Variables created in the first evaluation survive into the second. The kernel is not a shell: use `session_eval`, `session_get`, `session_names`, then `session_close`.
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/table — collections
description: put, append, and map helpers (code-as-docs pilot)
import table:lib/table.mq.md
@@ -21,6 +22,6 @@ Read with link-index get. Use json for parse/stringify only.
**`xs` = [table.put] in=`xs` at=1 value="A"**
**`n` = [table.rows] xs=`xs`**
**打印 内容=[Authorization](h)**
**打印 内容=[1](xs)**
**打印 内容=[Authorization](access(h, "Authorization"))**
**打印 内容=[1](access(xs, "1"))**
**打印 内容=`n`**
+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/外联 — 外联内核 v2
description: 结构化执行、JSON 调用、并行扇出、持久内核与显式状态桥
导入 外联:lib/外联.mq.md
@@ -17,8 +18,8 @@ stdin: 21
**node = > 外联.探测 语言="node"**
> 打印 内容=[ok](`node`)
> 打印 内容=[version](`node`)
> 打印 内容=[ok](access(`node`, "ok"))
> 打印 内容=[version](access(`node`, "version"))
`探测` 返回 `{lang, cmd, path, ok, version, error}`。省略语言时探测所有已知语言。
@@ -33,9 +34,9 @@ console.log("来自外联内核的问候");
**记录 = > 外联.执行 代码=`标记`**
> 打印 内容=[ok](`记录`)
> 打印 内容=[stdout](`记录`)
> 打印 内容=[code](`记录`)
> 打印 内容=[ok](access(`记录`, "ok"))
> 打印 内容=[stdout](access(`记录`, "stdout"))
> 打印 内容=[code](access(`记录`, "code"))
`执行` 在进程失败时不抛错,而是在一条记录里给出 `ok`、`code`、`stdout`、`stderr`、`ms`、`timed_out`、`truncated`、`result` 与 `error`。
@@ -87,7 +88,7 @@ process.stdin.on("end", () => {
**第二次 = > 外联.会话求值 标识=`会话` 源码="total * 2"**
> 打印 内容=[result](`第二次`)
> 打印 内容=[result](access(`第二次`, "result"))
第一次求值创建的变量会保留到第二次。内核不是 shell:用 `会话求值`、`会话取值`、`会话变量`,最后 `会话关闭`。
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/表 — 列表与字典
description: 改 / 行数 / 取行(代码即文档试点)
导入 表:lib/表.mq.md
@@ -19,6 +20,6 @@ description: 改 / 行数 / 取行(代码即文档试点)
**`n` = [表.行数] xs=`xs`**
**`r` = [表.取行] xs=`xs` i=0**
**打印 内容=[1](xs)**
**打印 内容=[1](access(xs, "1"))**
**打印 内容=`n`**
**打印 内容=`r`**