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

+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 方括号标记调用与前置修饰语
description: 礼貌 [问候] …;嵌套 ([…]);与 [键](集合) 取元消歧
---
@@ -15,7 +16,7 @@ description: 礼貌 [问候] …;嵌套 ([…]);与 [键](集合) 取元消
|------|------|
| 18 | 28 |
**价 = [拿铁](菜单)**
**价 = [拿铁](access(菜单, "拿铁"))**
**打印 内容=`价`**
## 问候
+8 -7
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table cell expressions
description: Data cells evaluate like call-arg values (`var`, paths, hyphen prose).
---
@@ -14,9 +15,9 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---------|-------|------|
| `secret` | `name` | https://api.openai.com/v1 |
> print text=[api_key](`cfg`)
> print text=[model](`cfg`)
> print text=[base](`cfg`)
> print text=[api_key](access(`cfg`, "api_key"))
> print text=[model](access(`cfg`, "model"))
> print text=[base](access(`cfg`, "base"))
`paths` =
@@ -24,7 +25,7 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---|
| /chat/completions |
> print text=[1](`paths`)
> print text=[1](access(`paths`, "1"))
`rec` =
@@ -32,7 +33,7 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
|---|------|---------|
| 1 | user | `secret` |
> print text=[content]([1](`rec`))
> print text=[content](access([1](access(`rec`, "1")), "content"))
`ratios` =
@@ -41,5 +42,5 @@ description: Data cells evaluate like call-arg values (`var`, paths, hyphen pros
| "1/5" |
| "16/9" |
> print text=[1](`ratios`)
> print text=[2](`ratios`)
> print text=[1](access(`ratios`, "1"))
> print text=[2](access(`ratios`, "2"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 横表多行 → 字典套列表
---
@@ -11,14 +12,14 @@ title: 横表多行 → 字典套列表
| 红富士 | 青瓜 |
| 嘎啦 | 黄瓜条 |
**第一种苹果 = [1]([苹果](货架))**
**第一种苹果 = [1](access([苹果](access(货架, "苹果")), "1"))**
> print text=`第一种苹果`
**列 = [苹果](货架)**
**列 = [苹果](access(货架, "苹果"))**
> print text=`列`
**第二种黄瓜 = [2]([黄瓜](货架))**
**第二种黄瓜 = [2](access([黄瓜](access(货架, "黄瓜")), "2"))**
> print text=`第二种黄瓜`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 横表单行 → 字典
---
@@ -10,17 +11,17 @@ title: 横表单行 → 字典
|------|------|------|
| 水果 | 蔬菜 | 数码用品 |
**种 = [苹果](分类)**
**种 = [苹果](access(分类, "苹果"))**
> print text=`种`
**种 = [黄瓜](分类)**
**种 = [黄瓜](access(分类, "黄瓜"))**
> print text=`种`
**种 = [鼠标](分类)**
**种 = [鼠标](access(分类, "鼠标"))**
> print text=`种`
- [键](分类)
- [键](遍历 分类 为 键)
> print text=`键`
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: row records with @ marker
---
@@ -11,10 +12,10 @@ title: row records with @ marker
| 1 | apple | 2 |
| 2 | pear | 3 |
**n = [name]([1](orders))**
**n = [name](access([1](access(orders, "1")), "name"))**
> print text=`n`
**q = [qty]([2](orders))**
**q = [qty](access([2](access(orders, "2")), "qty"))**
> print text=`q`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 行向记录表(首列 行 / @)
---
@@ -11,17 +12,17 @@ title: 行向记录表(首列 行 / @)
| 1 | 苹果 | 2 |
| 2 | 梨 | 3 |
**第一 = [1](订单)**
**第一 = [1](access(订单, "1"))**
> print text=`第一`
**名 = [品名]([1](订单))**
**名 = [品名](access([1](access(订单, "1")), "品名"))**
> print text=`名`
**量 = [数量]([2](订单))**
**量 = [数量](access([2](access(订单, "2")), "数量"))**
> print text=`量`
- [记录](订单)
- [记录](遍历 订单 为 记录)
> print text=`记录`
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 集合(表格)示例
---
@@ -12,5 +13,5 @@ title: 集合(表格)示例
| 梨 |
| 桃 |
- [果](篮子)
- [果](遍历 篮子 为 果)
> print text=`果`
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 链接形取元
description: [键](集合) 为主语法;脚注取元仍兼容
---
@@ -19,9 +20,9 @@ description: [键](集合) 为主语法;脚注取元仍兼容
| 杏 |
**名 = "拿铁"**
**价 = [`名`](菜单)**
**价 = [名](access(菜单, `名`))**
**打印 内容=`价`**
**静 = [美式](菜单)**
**静 = [美式](access(菜单, "美式"))**
**打印 内容=`静`**
**第一 = [1](篮子)**
**第一 = [1](access(篮子, "1"))**
**打印 内容=`第一`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 循环示例
---
@@ -21,5 +22,5 @@ title: 循环示例
| 苹果 |
| 梨 |
- [果](篮子)
- [果](遍历 篮子 为 果)
> print text=今天吃`果`