@calcit/procs 0.12.41 → 0.12.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,64 @@
1
+ # 2026-0609-1241 移除 bind-type(Breaking Change)
2
+
3
+ ## 概要
4
+
5
+ 彻底移除 `bind-type` 内置过程,所有类型槽绑定统一使用 `with-type-slot`。
6
+
7
+ ## 动机
8
+
9
+ `bind-type` 是全局绑定,每个槽只能绑定一次,多入口项目(client/server)会产生冲突或需要分程序加载。`with-type-slot` 提供了基于词法作用域的替代方案,在入口函数体内局部绑定,天然支持多入口并行编译。
10
+
11
+ ## 删除范围
12
+
13
+ ### Rust 核心
14
+
15
+ | 文件 | 改动 |
16
+ |------|------|
17
+ | `src/calcit/proc_name.rs` | 删除 `BindType` 枚举变体及其 `ProcTypeSignature` |
18
+ | `src/calcit/type_annotation.rs` | 删除 `bind_type_slot()` 函数(`TYPE_SLOTS` 仍保留用于 `deftype-slot` 声明) |
19
+ | `src/calcit.rs` | 删除 `bind_type_slot` 的 re-export |
20
+ | `src/builtins.rs` | 删除 `BindType => meta::bind_type(args)` dispatch arm |
21
+ | `src/builtins/meta.rs` | 删除 `bind_type()` 函数及其 `bind_type_slot` 导入 |
22
+ | `src/runner/preprocess/mod.rs` | 删除 `BindType` 预处理块(~90 行)及 `precompile_bind_type_defs()` 函数 |
23
+ | `src/lib.rs` | 删除 `precompile_bind_type_defs` 调用 |
24
+ | `src/program.rs` | 删除 `calcit_contains_bind_type()` 及 snapshot 任务排序中的优先级逻辑 |
25
+ | `src/codegen/emit_js.rs` | 从 JS codegen no-op 分支中移除 `BindType` |
26
+
27
+ ### 测试与固件
28
+
29
+ | 文件 | 改动 |
30
+ |------|------|
31
+ | `calcit/type-fail/type-slot-bind-duplicate.cirru` | **删除**(测试已无法成立) |
32
+ | `calcit/type-fail/type-slot-bind-unknown.cirru` | **删除**(`with-type-slot` 不需要预先声明) |
33
+ | `calcit/type-fail/type-slot-enum-invalid-variant.cirru` | `bind-type` → `with-type-slot (:dispatch-op Action)` |
34
+ | `calcit/type-fail/type-slot-record-call-arg-type-mismatch.cirru` | `bind-type` → `with-type-slot (:payload ...)` |
35
+ | `calcit/type-fail/type-slot-entry-scope.cirru` | `bind-type` → `with-type-slot` |
36
+ | `src/bin/cr_tests/type_fail.rs` | 删除 `type_fail_type_slot_fixtures_report_errors` 测试;更新注释 |
37
+
38
+ ### 文档
39
+
40
+ | 文件 | 改动 |
41
+ |------|------|
42
+ | `docs/features/static-analysis.md` | "Binding a Type Slot" 章节改用 `with-type-slot` 说明 |
43
+
44
+ ### 外部项目
45
+
46
+ | 文件 | 改动 |
47
+ |------|------|
48
+ | `calcium-workflow/calcit.cirru` (`app.server/main!`) | `(bind-type :dispatch-op Op)` → `with-type-slot (:dispatch-op Op)` |
49
+
50
+ ## 验证
51
+
52
+ - `cargo build --bin cr` — 零警告、零错误
53
+ - `cargo clippy -- -D warnings` — 通过
54
+ - `cargo test` — 85 个测试全部通过
55
+ - `calcium-workflow --check-only`(client + server 入口)— 均通过
56
+
57
+ ## 迁移指南
58
+
59
+ 将所有 `bind-type :slot-name TypeExpr` 替换为:
60
+
61
+ ```cirru
62
+ with-type-slot (:slot-name TypeExpr)
63
+ ;; 原来在 bind-type 之后的代码全部作为 body
64
+ ```
@@ -0,0 +1,83 @@
1
+ # with-type: 局部作用域类型绑定
2
+
3
+ 日期:2026-06-09
4
+
5
+ ## 功能概要
6
+
7
+ 实现 `with-type-slot` 表达式,允许在局部代码块范围内绑定 type-slot,替代全局 `bind-type` 的全局副作用。
8
+
9
+ ## 语法
10
+
11
+ ```cirru
12
+ with-type-slot (:slot-name TypeExpr)
13
+ body-expr1
14
+ body-expr2
15
+ ...
16
+ ```
17
+
18
+ - 第一个参数必须是二元列表 `(:slot-name TypeExpr)`
19
+ - 后续参数是 body 表达式
20
+ - 返回最后一个 body 表达式的值
21
+
22
+ ## 与 bind-type 的对比
23
+
24
+ | 特性 | bind-type | with-type-slot |
25
+ |------|-----------|-----------|
26
+ | 作用域 | 全局(整个预处理 pass) | 局部(仅 body 范围内) |
27
+ | 是否可重叠 | 单次绑定,不可重复 | 可嵌套,栈式覆盖 |
28
+ | 使用位置 | 通常在 main! 最顶部 | 任意代码块 |
29
+
30
+ ## 实现细节
31
+
32
+ ### 修改文件
33
+
34
+ 1. **`src/calcit/type_annotation.rs`**
35
+ - 新增 `TYPE_SLOT_OVERRIDES` thread-local(HashMap of Vec)
36
+ - 新增 `push_type_slot_override(name, ty)`:压栈一个作用域覆盖
37
+ - 新增 `pop_type_slot_override(name)`:弹栈,自动清理空栈
38
+ - 修改 `resolve_type_slot`:优先检查 override 栈,再回退到基础 `TYPE_SLOTS`
39
+ - 修改 `clear_type_slots`:同时清理 override 栈
40
+
41
+ 2. **`src/calcit/proc_name.rs`**
42
+ - 添加 `WithType` 枚举变体(strum serialize = "with-type")
43
+ - `get_type_signature` 返回 `None`(type-checking 在预处理阶段处理)
44
+
45
+ 3. **`src/builtins.rs`**
46
+ - 添加 `WithType => meta::with_type_runtime(args)` dispatch
47
+
48
+ 4. **`src/builtins/meta.rs`**
49
+ - 添加 `with_type_runtime()` 运行时 no-op(返回最后一个 body 值)
50
+
51
+ 5. **`src/runner/preprocess/mod.rs`**
52
+ - 新增 `preprocess_with_type_block()` 函数:
53
+ - 解析 binding pair → 解析类型注解
54
+ - push override → 预处理 body → pop override(错误时也 pop)
55
+ - 在 `preprocess_list_call` 中:在 generic `Calcit::Proc` 分支之前插入 `WithType` 特殊分支
56
+
57
+ 6. **`src/calcit.rs`**
58
+ - re-export `push_type_slot_override`, `pop_type_slot_override`
59
+
60
+ ### 运行时行为
61
+
62
+ `with-type-slot` 在运行时是 no-op:类型绑定仅影响预处理阶段的类型检查,不影响运行时值。运行时返回最后一个 body 表达式的值。
63
+
64
+ ### 预处理时机
65
+
66
+ `with-type-slot` 的 body 在 override 激活期间被预处理。由于 `ensure_ns_def_compiled` 是懒加载的,所有从 body 中引用的 def(包括传递依赖)都会在 override 有效时被编译,从而获得正确的类型检查。
67
+
68
+ ## 验证
69
+
70
+ 使用 calcium-workflow 项目验证:将 `app.client/main!` 从 `bind-type` 改写为 `with-type-slot`:
71
+
72
+ ```cirru
73
+ ;; 改写前
74
+ defn main! () (bind-type :dispatch-op Op)
75
+ ...
76
+
77
+ ;; 改写后
78
+ defn main! ()
79
+ with-type-slot (:dispatch-op Op)
80
+ ...
81
+ ```
82
+
83
+ 运行 `cr calcit.cirru --check-only` 验证通过:`✓ Check passed (59ms)`
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.12.41",
3
+ "version": "0.12.43",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^25.7.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.12.41",
3
+ "version": "0.12.43",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^25.7.0",