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

+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table sort_by + cli
import table:lib/table.mq.md
import csv:lib/csv.mq.md
@@ -11,12 +12,12 @@ import cli:lib/cli.mq.md
**rows = > csv.parse text=`raw`**
**rows = > table.sort_by list=`rows` key="name"**
**r0 = > at value=`rows` index=0**
> print text=[name](`r0`)
> print text=[name](access(`r0`, "name"))
**args = > split value="--input,data.csv,rest,--verbose" sep=","**
**flags = > cli.parse args=`args`**
> print text=[input](`flags`)
> print text=[verbose](`flags`)
**pos = [_](`flags`)**
> print text=[input](access(`flags`, "input"))
> print text=[verbose](access(`flags`, "verbose"))
**pos = [_](access(`flags`, "_"))**
**p0 = > at value=`pos` index=0**
> print text=`p0`
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/csv smoke
import csv:lib/csv.mq.md
---
@@ -12,8 +13,8 @@ import csv:lib/csv.mq.md
> print text=`n`
**r0 = > at value=`rows` index=0**
> print text=[name](`r0`)
> print text=[note](`r0`)
> print text=[name](access(`r0`, "name"))
> print text=[note](access(`r0`, "note"))
**out = > csv.stringify rows=`rows`**
**rows2 = > csv.parse text=`out`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/datetime smoke
import dt:lib/datetime.mq.md
---
@@ -6,10 +7,10 @@ import dt:lib/datetime.mq.md
# main
**m = > dt.from_unix unix=0**
> print text=[iso](`m`)
> print text=[iso](access(`m`, "iso"))
**sh = > dt.in_zone dt=`m` zone="Asia/Shanghai"**
> print text=[iso](`sh`)
> print text=[iso](access(`sh`, "iso"))
**p = > dt.parse text="2020-01-02T03:04:05+08:00"**
**u = > dt.to_unix dt=`p`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign config load
import foreign:lib/foreign.mq.md
---
@@ -9,4 +10,4 @@ import foreign:lib/foreign.mq.md
> print text=`载入`
**运行 = > foreign.invoke lang="tinycfg" source="console.log('cfg')"**
> print text=[stdout](`运行`)
> print text=[stdout](access(`运行`, "stdout"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign env cwd timeout
import foreign:lib/foreign.mq.md
---
@@ -17,7 +18,7 @@ console.log(process.env.MODE + "|" + process.env.MARQDO_FOREIGN_LANG);
```
**检查 = > foreign.invoke code=`环境检查` env=`环境`**
**检查输出 = > trim [stdout](`检查`)**
**检查输出 = > trim [stdout](access(`检查`, "stdout"))**
> print text=`检查输出`
@@ -28,5 +29,5 @@ setTimeout(() => console.log("late"), 5000);
**超时 = > foreign.invoke code=`慢` timeout=0.5**
> print text=[ok](`超时`)
> print text=[timed_out](`超时`)
> print text=[ok](access(`超时`, "ok"))
> print text=[timed_out](access(`超时`, "timed_out"))
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign invoke record
import foreign:lib/foreign.mq.md
---
@@ -13,7 +14,7 @@ process.exit(3);
**记录 = > foreign.invoke code=`失败`**
> print text=[ok](`记录`)
> print text=[code](`记录`)
> print text=[stderr](`记录`)
> print text=[truncated](`记录`)
> print text=[ok](access(`记录`, "ok"))
> print text=[code](access(`记录`, "code"))
> print text=[stderr](access(`记录`, "stderr"))
> print text=[truncated](access(`记录`, "truncated"))
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign invoke JSON input
import foreign:lib/foreign.mq.md
---
@@ -25,8 +26,8 @@ process.stdin.on("end", () => {
```
**记录 = > foreign.invoke code=`统计` input=`数值表` output="json"**
**统计结果 = [result](`记录`)**
**统计结果 = [result](access(`记录`, "result"))**
> print text=[ok](`记录`)
> print text=[n](`统计结果`)
> print text=[sum](`统计结果`)
> print text=[ok](access(`记录`, "ok"))
> print text=[n](access(`统计结果`, "n"))
> print text=[sum](access(`统计结果`, "sum"))
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign probe and register
import foreign:lib/foreign.mq.md
---
@@ -6,8 +7,8 @@ import foreign:lib/foreign.mq.md
# main
**探测 = > foreign.probe lang="node"**
> print text=[ok](`探测`)
> print text=[lang](`探测`)
> print text=[ok](access(`探测`, "ok"))
> print text=[lang](access(`探测`, "lang"))
`模板` =
@@ -19,6 +20,6 @@ import foreign:lib/foreign.mq.md
**> foreign.register lang="tiny" template=`模板`**
**运行 = > foreign.invoke lang="tiny" source="console.log('tiny')"**
**运行输出 = > trim [stdout](`运行`)**
**运行输出 = > trim [stdout](access(`运行`, "stdout"))**
> print text=`运行输出`
**> foreign.unset lang="tiny"**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign python session
import foreign:lib/foreign.mq.md
---
@@ -9,7 +10,7 @@ import foreign:lib/foreign.mq.md
**设值 = > foreign.session_eval id=`会话` source="x = 41"**
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
> print text=[result](`求值`)
> print text=[result](access(`求值`, "result"))
**> foreign.session_set id=`会话` name="y" value=5**
**取值 = > foreign.session_get id=`会话` name="y"**
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign session timeout
import foreign:lib/foreign.mq.md
---
@@ -8,6 +9,6 @@ import foreign:lib/foreign.mq.md
**会话 = > foreign.session_open lang="node"**
**慢 = > foreign.session_eval id=`会话` source="(async () => { await new Promise(r => setTimeout(r, 5000)); return 1; })()" timeout=0.3**
> print text=[ok](`慢`)
> print text=[timed_out](`慢`)
> print text=[alive](`慢`)
> print text=[ok](access(`慢`, "ok"))
> print text=[timed_out](access(`慢`, "timed_out"))
> print text=[alive](access(`慢`, "alive"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: foreign persistent session
import foreign:lib/foreign.mq.md
---
@@ -9,7 +10,7 @@ import foreign:lib/foreign.mq.md
**设值 = > foreign.session_eval id=`会话` source="let x = 41"**
**求值 = > foreign.session_eval id=`会话` source="x + 1"**
> print text=[result](`求值`)
> print text=[result](access(`求值`, "result"))
**取x = > foreign.session_get id=`会话` name="x"**
> print text=`取x`
+4 -3
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: fs mid2 M9 smoke
import fs:lib/fs.mq.md
---
@@ -12,9 +13,9 @@ import fs:lib/fs.mq.md
> fs.write_text path="m9-tree/nested/b.txt" text="B"
**st = > fs.stat path="m9-tree/a.txt"**
> print text=[size](`st`)
> print text=[is_file](`st`)
> print text=[is_dir](`st`)
> print text=[size](access(`st`, "size"))
> print text=[is_file](access(`st`, "is_file"))
> print text=[is_dir](access(`st`, "is_dir"))
**w = > fs.walk path="m9-tree"**
**n = > len `w`**
+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: net cookie_parse
import net:lib/net.mq.md
---
@@ -9,9 +10,9 @@ import net:lib/net.mq.md
**resp = > net.cookie_parse text="id=42; Path=/; HttpOnly; Secure; SameSite=Lax, theme=light; Max-Age=3600" is_response=True**
> print text=[name]([1](`req`))
> print text=[value]([1](`req`))
> print text=[http_only]([1](`resp`))
> print text=[secure]([1](`resp`))
> print text=[same_site]([1](`resp`))
> print text=[max_age]([2](`resp`))
> print text=[name](access([1](access(`req`, "1")), "name"))
> print text=[value](access([1](access(`req`, "1")), "value"))
> print text=[http_only](access([1](access(`resp`, "1")), "http_only"))
> print text=[secure](access([1](access(`resp`, "1")), "secure"))
> print text=[same_site](access([1](access(`resp`, "1")), "same_site"))
> print text=[max_age](access([2](access(`resp`, "2")), "max_age"))
+7 -6
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: net multipart_parse
import net:lib/net.mq.md
---
@@ -11,9 +12,9 @@ import net:lib/net.mq.md
**parts = > net.multipart_parse body=`body` boundary=`boundary`**
> print text=[name]([1](`parts`))
> print text=[value]([1](`parts`))
> print text=[name]([2](`parts`))
> print text=[filename]([2](`parts`))
> print text=[content_type]([2](`parts`))
> print text=[value]([2](`parts`))
> print text=[name](access([1](access(`parts`, "1")), "name"))
> print text=[value](access([1](access(`parts`, "1")), "value"))
> print text=[name](access([2](access(`parts`, "2")), "name"))
> print text=[filename](access([2](access(`parts`, "2")), "filename"))
> print text=[content_type](access([2](access(`parts`, "2")), "content_type"))
> print text=[value](access([2](access(`parts`, "2")), "value"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: openai SSE parse offline
import net:lib/net.mq.md
import json:lib/json.mq.md
@@ -10,7 +11,7 @@ import json:lib/json.mq.md
**events = > net.openai_sse_parse text=`fixture`**
- [`ev`](`events`)
- [ev](遍历 `events` 为 `ev`)
**t = > json.get value=`ev` key="type"**
1. `t` == "delta"
**chunk = > json.get value=`ev` key="text"**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: sys.exec capture=True returns stdout map
description: GAP-09 optional capture.
import sys:lib/sys.mq.md
@@ -15,8 +16,8 @@ import json:lib/json.mq.md
**args = > json.parse text=["-c","printf hi-capture"]**
**out = > sys.exec cmd="sh" args=args capture=True**
**c = [code](out)**
**s = [stdout](out)**
**c = [code](access(out, "code"))**
**s = [stdout](access(out, "stdout"))**
1. `c` == 0
> print text=capture-code-ok
2. *
+6 -5
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: table collections
description: put + list/map helpers
import table:lib/table.mq.md
@@ -7,7 +8,7 @@ import table:lib/table.mq.md
# main
**h = > table.put in=None at="Authorization" value="Bearer-x"**
> print text=[Authorization](`h`)
> print text=[Authorization](access(`h`, "Authorization"))
`xs` =
@@ -17,8 +18,8 @@ import table:lib/table.mq.md
| b |
**xs = > table.put in=`xs` at=1 value="A"**
> print text=[1](`xs`)
> print text=[2](`xs`)
> print text=[1](access(`xs`, "1"))
> print text=[2](access(`xs`, "2"))
`req` =
@@ -31,8 +32,8 @@ import table:lib/table.mq.md
**messages = > table.append list=None item=`msg`**
**req = > table.put in=`req` at="messages" value=`messages`**
**req = > table.put in=`req` at="stream" value=True**
> print text=[content]([1]([messages](`req`)))
> print text=[stream](`req`)
> print text=[content](access([1](access([messages](access(`req`, "messages")), "1")), "content"))
> print text=[stream](access(`req`, "stream"))
**xs = > table.append list=`xs` item="c"**
**n = > table.len xs=`xs`**
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/toml html encoding M8 smoke
import toml:lib/toml.mq.md
import html:lib/html.mq.md
@@ -8,10 +9,10 @@ import enc:lib/encoding.mq.md
# main
**cfg = > toml.parse text="name = \"marqdo\"\ncount = 2\n[pkg]\nver = \"1\"\n"**
> print text=[name](`cfg`)
> print text=[count](`cfg`)
**pkg = [pkg](`cfg`)**
> print text=[ver](`pkg`)
> print text=[name](access(`cfg`, "name"))
> print text=[count](access(`cfg`, "count"))
**pkg = [pkg](access(`cfg`, "pkg"))**
> print text=[ver](access(`pkg`, "ver"))
**e = > html.escape text="a<b>&\"c'"**
> print text=`e`
+9 -8
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/url smoke
import url:lib/url.mq.md
---
@@ -6,16 +7,16 @@ import url:lib/url.mq.md
# main
**u = > url.parse text="https://example.com:8443/a/b?x=1&y=2#frag"**
> print text=[scheme](`u`)
> print text=[host](`u`)
> print text=[port](`u`)
> print text=[path](`u`)
> print text=[query](`u`)
> print text=[fragment](`u`)
> print text=[scheme](access(`u`, "scheme"))
> print text=[host](access(`u`, "host"))
> print text=[port](access(`u`, "port"))
> print text=[path](access(`u`, "path"))
> print text=[query](access(`u`, "query"))
> print text=[fragment](access(`u`, "fragment"))
**q = > url.query_parse text="a=1&b=hi%20x&a=2"**
> print text=[b](`q`)
**as = [a](`q`)**
> print text=[b](access(`q`, "b"))
**as = [a](access(`q`, "a"))**
**a0 = > at value=`as` index=0**
**a1 = > at value=`as` index=1**
> print text=`a0`
+5 -4
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/地址 烟测
导入 址:lib/地址.mq.md
---
@@ -6,7 +7,7 @@ title: lib/地址 烟测
# main
**u = > 址.解析 内容="https://example.com/a?x=1"**
> print text=[scheme](`u`)
> print text=[host](`u`)
> print text=[path](`u`)
> print text=[query](`u`)
> print text=[scheme](access(`u`, "scheme"))
> print text=[host](access(`u`, "host"))
> print text=[path](access(`u`, "path"))
> print text=[query](access(`u`, "query"))
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 文件 Mid2 M9 烟测
导入 文件:lib/文件.mq.md
---
@@ -10,7 +11,7 @@ title: 文件 Mid2 M9 烟测
> 文件.写文本 路径="m9-zh/a.txt" 内容="A"
**st = > 文件.状态 路径="m9-zh/a.txt"**
> print text=[is_file](`st`)
> print text=[is_file](access(`st`, "is_file"))
**w = > 文件.遍历 路径="m9-zh"**
**n = > 长度 `w`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/日期时间 烟测
导入 日时:lib/日期时间.mq.md
---
@@ -6,10 +7,10 @@ title: lib/日期时间 烟测
# main
**m = > 日时.自戳 秒=0**
> print text=[iso](`m`)
> print text=[iso](access(`m`, "iso"))
**sh = > 日时.时区 时刻=`m` 区="Asia/Shanghai"**
> print text=[iso](`sh`)
> print text=[iso](access(`sh`, "iso"))
**p = > 日时.解析 内容="2020-01-02T03:04:05+08:00"**
**u = > 日时.成戳 时刻=`p`**
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 表与命令行 烟测
导入 表:lib/表.mq.md
导入 命令行:lib/命令行.mq.md
@@ -13,5 +14,5 @@ title: 表与命令行 烟测
**args = > split value="--x,1,--flag" sep=","**
**flags = > 命令行.解析 参数=`args`**
> 打印 内容=[x](`flags`)
> 打印 内容=[flag](`flags`)
> 打印 内容=[x](access(`flags`, "x"))
> 打印 内容=[flag](access(`flags`, "flag"))
+3 -2
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: 表集合
description: 改 + 列表字典
导入 表:lib/表.mq.md
@@ -7,7 +8,7 @@ description: 改 + 列表字典
# main
**h = > 表.改 入=None 于="Authorization" 值="Bearer-x"**
> 打印 内容=[Authorization](`h`)
> 打印 内容=[Authorization](access(`h`, "Authorization"))
`xs` =
@@ -17,7 +18,7 @@ description: 改 + 列表字典
| b |
**xs = > 表.改 入=`xs` 于=1 值="A"**
> 打印 内容=[1](`xs`)
> 打印 内容=[1](access(`xs`, "1"))
**xs = > 表.追加 list=`xs` item="c"**
**n = > 表.长度 xs=`xs`**
+2 -1
View File
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/逗号表 烟测
导入 逗号表:lib/逗号表.mq.md
---
@@ -12,4 +13,4 @@ title: lib/逗号表 烟测
> 打印 内容=`n`
**r0 = > at value=`rows` index=0**
> 打印 内容=[a](`r0`)
> 打印 内容=[a](access(`r0`, "a"))
@@ -1,4 +1,5 @@
---
markup: occlusion
title: lib/配置表 超文本 编码 烟测
导入 配置:lib/配置表.mq.md
导入 超:lib/超文本.mq.md
@@ -8,8 +9,8 @@ title: lib/配置表 超文本 编码 烟测
# main
**cfg = > 配置.解析 内容="name = \"中文\"\nok = true\n"**
> print text=[name](`cfg`)
> print text=[ok](`cfg`)
> print text=[name](access(`cfg`, "name"))
> print text=[ok](access(`cfg`, "ok"))
**e = > 超.转义 内容="a<b>"**
> print text=`e`