@calcit/procs 0.11.7 → 0.11.8
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.
- package/.yarn/install-state.gz +0 -0
- package/editing-history/2026-0303-1934-check-types-and-core-annotations.md +17 -0
- package/editing-history/2026-0304-1331-tag-call-warning-and-dot-access-migration.md +28 -0
- package/editing-history/2026-0304-1548-impl-new-dot-method-input-and-doc-hints.md +33 -0
- package/editing-history/2026-0304-1645-calcit-eq-contract-refactor-and-macro-tests.md +28 -0
- package/editing-history/2026-0304-2200-assert-type-assert-traits-composable-runtime-checks.md +18 -0
- package/editing-history/2026-0304-generics-fn-typevar-identity.md +30 -0
- package/lib/calcit-data.mjs +6 -0
- package/lib/calcit.procs.mjs +3 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit-data.mts +6 -0
- package/ts-src/calcit.procs.mts +3 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## 本次修改摘要
|
|
2
|
+
|
|
3
|
+
- 新增 `cr analyze check-types` 子命令,用于统计定义的类型标注覆盖度。
|
|
4
|
+
- 支持按命名空间过滤:`--ns`、`--ns-prefix`,以及是否包含依赖:`--deps`。
|
|
5
|
+
- 支持覆盖度分层与筛选:`none/partial/full`,并通过 `--only` 过滤输出。
|
|
6
|
+
- 优化输出格式:按定义类型(fn/macro/data)分块展示,参数与断言信息合并展示,`return-type` 标签统一为 `return`。
|
|
7
|
+
- 持续补充 `calcit.core` 中函数参数 `assert-type` 标注,`partial` 覆盖项降至 0(`--only partial` 无结果)。
|
|
8
|
+
|
|
9
|
+
## 验证
|
|
10
|
+
|
|
11
|
+
- 执行 `yarn check-all`:通过。
|
|
12
|
+
- 执行 `./target/debug/cr calcit/test.cirru analyze check-types --ns calcit.core --deps --only partial`:无 `partial` 定义。
|
|
13
|
+
|
|
14
|
+
## 经验记录
|
|
15
|
+
|
|
16
|
+
- 日常编辑可优先使用全局 `cr tree/edit`,减少 `cargo run` 反复编译开销。
|
|
17
|
+
- 若全局 `cr` 尚未包含新子命令(如 `analyze check-types`),统计/验证阶段需使用仓库内最新二进制(如 `./target/debug/cr`)。
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# trait/impl 方法键 tag 写法 warning 与点号迁移评估
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
- `deftrait` / `defimpl` 里方法键目前使用 `:foo` 形式,语义上对应方法名。
|
|
6
|
+
- 为逐步迁移到点号方法表示(如 `.foo`)需要先在 trait/impl 场景给出提示,避免误伤普通 tag/map 使用。
|
|
7
|
+
|
|
8
|
+
## 本次改动
|
|
9
|
+
|
|
10
|
+
- 在 `src/runner/preprocess.rs` 的宏预处理分支新增 warning:
|
|
11
|
+
- 仅在 `deftrait` / `defimpl` 检查方法键(默认展示)。
|
|
12
|
+
- 检测到 `:foo` 方法键时提示迁移到 `.foo` 风格(兼容性保留)。
|
|
13
|
+
- 移除对普通 `(:k obj)` 访问调用的迁移 warning,避免范围跑偏。
|
|
14
|
+
- 新增单测 `warns_on_trait_impl_method_tag_syntax`,确保 warning 范围和文案稳定。
|
|
15
|
+
- 同步在 `calcit/*.cirru` 的 trait/impl 测试与示例中开始迁移到 `.foo` 写法。
|
|
16
|
+
|
|
17
|
+
## 迁移建议(分阶段)
|
|
18
|
+
|
|
19
|
+
1. **当前阶段(已落地)**:默认 warning + 兼容旧写法。
|
|
20
|
+
2. **下一阶段**:在文档与脚手架模板中默认采用 `.foo` 方法键表示。
|
|
21
|
+
3. **后续阶段(可选)**:提供自动改写工具(`deftrait/defimpl` 的 `:foo` -> `.foo`)并支持批量修复。
|
|
22
|
+
4. **最终阶段(可选)**:再评估是否提升 warning 严格度(例如 lint 级别开关)。
|
|
23
|
+
|
|
24
|
+
## 验证
|
|
25
|
+
|
|
26
|
+
- 定向测试:
|
|
27
|
+
- `cargo test warns_on_trait_impl_method_tag_syntax -- --nocapture`
|
|
28
|
+
- `cargo test warns_on_dynamic_trait_call -- --nocapture`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 2026-03-04 15:48 `&impl::new` dot-method 输入与文档提示对齐
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
在 trait/impl method key 迁移到 `.method` 的过程中,声明层(`deftrait`/`defimpl`)已支持并迁移,但原生构造入口 `&impl::new` 在不同后端对 `.method` 输入支持不一致:Rust 侧与 JS 侧行为存在差异,导致 `yarn check-all` 的 JS 路径报错。
|
|
6
|
+
|
|
7
|
+
## 本次改动要点
|
|
8
|
+
|
|
9
|
+
- 扩展 `&impl::new` 字段键解析,支持 `.method` 输入并规范化为内部 tag 键:
|
|
10
|
+
- Rust: `src/builtins/records.rs` 接受 `Calcit::Method` 作为 field key。
|
|
11
|
+
- JS: `ts-src/calcit.procs.mts` 为 method closure 写入 `__calcitMethodName` 元信息;`ts-src/calcit-data.mts` 的 `castTag` 可读取该元信息并转为 tag。
|
|
12
|
+
- 增加回归用例:
|
|
13
|
+
- `calcit/test-doc-smoke.cirru` 新增 `test-native-impl-new-dot-method`,直接覆盖 `&impl::new` + `.method` 场景。
|
|
14
|
+
- 补齐文档与示例提示(用于 `query examples` 与错误 hint 链路):
|
|
15
|
+
- `src/cirru/calcit-core.cirru` 新增 `calcit.core/&impl::new` 的 `CodeEntry` 和 `.method` 示例。
|
|
16
|
+
- 更新 `&impl:get` 参数说明支持 `.method`,并新增 `&impl:get DemoImpl .show` 示例。
|
|
17
|
+
|
|
18
|
+
## 迁移语义结论
|
|
19
|
+
|
|
20
|
+
- 声明层:推荐 `.method`,legacy `:method` 兼容(并有 warning 提示)。
|
|
21
|
+
- 存储层:继续保持 tag 作为内部键(兼容和最小改动优先);本次仅扩展输入层与提示层,不改内部数据结构。
|
|
22
|
+
|
|
23
|
+
## 验证
|
|
24
|
+
|
|
25
|
+
- `cargo fmt --check`
|
|
26
|
+
- `cargo clippy -- -D warnings`
|
|
27
|
+
- `yarn compile`
|
|
28
|
+
- `cargo test`
|
|
29
|
+
- `yarn check-all`
|
|
30
|
+
- `cargo run --bin cr -- demos/compact.cirru query examples 'calcit.core/&impl::new'`
|
|
31
|
+
- `cargo run --bin cr -- demos/compact.cirru query examples 'calcit.core/&impl:get'`
|
|
32
|
+
|
|
33
|
+
以上在本次改动后均通过。
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 2026-03-04 16:45 `Calcit` 等值契约收敛、比较逻辑拆分与宏测试期望对齐
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
在将 `Calcit` 的 `Eq/Hash/Ord` 契约对齐后,`Symbol/Local/Import` 的跨变种相等被移除,暴露了若干 `macroexpand-all` 测试中“符号 vs 已解析 core import”比较不一致的问题。
|
|
6
|
+
|
|
7
|
+
## 本次改动
|
|
8
|
+
|
|
9
|
+
- 运行时契约修复(`src/calcit.rs`):
|
|
10
|
+
- 移除 `Symbol/Local/Import` 跨变种相等特判。
|
|
11
|
+
- 补齐 `Trait/Impl/Struct` 相关 hash 字段,避免 `Eq` 与 `Hash` 不一致。
|
|
12
|
+
- `Struct/Enum/Trait/Impl` 的 `Ord` 比较从仅按 name 改为与 `Eq` 语义一致。
|
|
13
|
+
- 比较辅助函数拆分(`src/calcit/compare.rs`):
|
|
14
|
+
- 将 `compare_*` 辅助逻辑独立成模块,减轻 `calcit.rs` 体积与复杂度。
|
|
15
|
+
- 宏测试期望修复(`calcit/test-macro.cirru`):
|
|
16
|
+
- 将多处 `quasiquote` 直接期望改为“左右均 `macroexpand-all` 再比较”,避免因 `calcit.core/+`、`calcit.core/=` 的 `Import`/`Symbol` 差异导致伪失败。
|
|
17
|
+
|
|
18
|
+
## 经验与约束
|
|
19
|
+
|
|
20
|
+
- 当核心值语义从“宽松相等”收敛为“严格相等”后,宏展开测试应优先比较**同一归一化阶段**产物,而不是混比 `quasiquote` 与 `macroexpand-all` 原始结果。
|
|
21
|
+
- 若测试目标是“展开形状正确”,可比较两侧都经过 `macroexpand-all` 的 AST,降低名称解析层差异带来的噪声。
|
|
22
|
+
|
|
23
|
+
## 验证
|
|
24
|
+
|
|
25
|
+
- `cargo test`
|
|
26
|
+
- `yarn check-all`
|
|
27
|
+
|
|
28
|
+
均通过。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# assert-type/assert-traits 可组合语义与检查路径修复
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
- `assert-type`/`assert-traits` 之前在 runtime 路径不完整,且 `assert-type` 不可组合。
|
|
5
|
+
- 在补 runtime 之后出现过 `yarn check-all` 栈溢出,需要在可组合性与稳定性间做执行路径分流。
|
|
6
|
+
|
|
7
|
+
## 关键调整
|
|
8
|
+
- `assert-type` 通过时返回原值,失败时报错,可嵌套表达式。
|
|
9
|
+
- `assert-traits` 接入 syntax runtime,支持多个 trait 断言并返回原值。
|
|
10
|
+
- preprocess 分流:
|
|
11
|
+
- local 目标:保留静态类型注入/细化(避免破坏加载路径);
|
|
12
|
+
- expression 目标:保留到 runtime 断言,保证组合性。
|
|
13
|
+
- 补齐 `if` 返回类型推断与方法参数泛型绑定匹配。
|
|
14
|
+
|
|
15
|
+
## 验证
|
|
16
|
+
- 新增/更新单测通过(runtime + preprocess 路径)。
|
|
17
|
+
- `cargo test` 通过。
|
|
18
|
+
- `yarn check-all` 通过(EXIT 0)。
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# 泛型函数 TypeVar 返回类型推导 (identity 用例)
|
|
2
|
+
|
|
3
|
+
## 概要
|
|
4
|
+
|
|
5
|
+
实现 `hint-fn (generics 'T)` 语法用于函数泛型声明,使 `identity` 等泛型函数的返回类型能在调用处根据实参类型自动推导。
|
|
6
|
+
|
|
7
|
+
## 核心改动
|
|
8
|
+
|
|
9
|
+
### `src/calcit/type_annotation.rs`
|
|
10
|
+
|
|
11
|
+
- 新增 `substitute_type_vars(&self, bindings) -> Arc<CalcitTypeAnnotation>`:将注解中的 `TypeVar` 替换为 `bindings` 中已绑定的具体类型,未绑定的保留原样。递归处理 `List`、`Map`、`Set`、`Ref`、`Optional`、`Variadic`、`Fn`、`AppliedStruct` 等复合类型。
|
|
12
|
+
- 新增 `contains_type_var(&self) -> bool`:判断注解中是否包含 `TypeVar`,用于快速跳过不需要泛型解析的路径。
|
|
13
|
+
- `extract_generics_from_hint_form` 中增加对 `"generics"` 关键字的识别(原来只识别 `"type-vars"`)。
|
|
14
|
+
|
|
15
|
+
### `src/runner/preprocess.rs`
|
|
16
|
+
|
|
17
|
+
- 新增 `resolve_generic_return_type(fn_info, call_args, scope_types)`:当被调函数的返回类型包含 TypeVar 时,用 `matches_with_bindings` 将实参类型与形参注解匹配以收集绑定,然后用 `substitute_type_vars` 替换返回类型中的 TypeVar。
|
|
18
|
+
- `infer_type_from_expr` 中 4 个返回 `info.return_type.clone()` 的路径(Import evaled、Import code、Symbol lookup、直接 Fn head)在检测到 TypeVar 返回类型时,优先尝试 `resolve_generic_return_type`。
|
|
19
|
+
- `check_function_return_type` 中,当声明的返回类型包含 TypeVar 时跳过定义体校验(泛型返回类型只在调用处才可确定)。
|
|
20
|
+
|
|
21
|
+
### `calcit/test-types-inference.cirru`
|
|
22
|
+
|
|
23
|
+
- 新增 `test-generics-identity` 测试:验证 `identity 42` 推导为 `:number`、`identity |hello` 推导为 `:string`。
|
|
24
|
+
|
|
25
|
+
## 验证
|
|
26
|
+
|
|
27
|
+
- `cargo test` 全部通过
|
|
28
|
+
- `cargo clippy -- -D warnings` 无警告
|
|
29
|
+
- `yarn check-all` 全量集成测试通过
|
|
30
|
+
- `&inspect-type` 输出确认 `'n => number`、`'s => string`
|
package/lib/calcit-data.mjs
CHANGED
|
@@ -146,6 +146,12 @@ export let castTag = (x) => {
|
|
|
146
146
|
if (x instanceof CalcitSymbol) {
|
|
147
147
|
return newTag(x.value);
|
|
148
148
|
}
|
|
149
|
+
if (typeof x === "function") {
|
|
150
|
+
const methodName = x.__calcitMethodName;
|
|
151
|
+
if (typeof methodName === "string") {
|
|
152
|
+
return newTag(methodName);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
149
155
|
throw new Error(`Cannot cast this to tag: ${x}`);
|
|
150
156
|
};
|
|
151
157
|
export var refsRegistry = new Map();
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1584,9 +1584,11 @@ export let register_calcit_builtin_impls = (options) => {
|
|
|
1584
1584
|
};
|
|
1585
1585
|
/** method used as closure */
|
|
1586
1586
|
export function invoke_method_closure(p) {
|
|
1587
|
-
|
|
1587
|
+
const f = (obj, ...args) => {
|
|
1588
1588
|
return invoke_method(p, obj, ...args);
|
|
1589
1589
|
};
|
|
1590
|
+
f.__calcitMethodName = p;
|
|
1591
|
+
return f;
|
|
1590
1592
|
}
|
|
1591
1593
|
function normalize_builtin_impls(entry) {
|
|
1592
1594
|
if (entry == null)
|
package/lib/package.json
CHANGED
package/package.json
CHANGED
package/ts-src/calcit-data.mts
CHANGED
|
@@ -168,6 +168,12 @@ export let castTag = (x: CalcitValue): CalcitTag => {
|
|
|
168
168
|
if (x instanceof CalcitSymbol) {
|
|
169
169
|
return newTag(x.value);
|
|
170
170
|
}
|
|
171
|
+
if (typeof x === "function") {
|
|
172
|
+
const methodName = (x as { __calcitMethodName?: unknown }).__calcitMethodName;
|
|
173
|
+
if (typeof methodName === "string") {
|
|
174
|
+
return newTag(methodName);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
171
177
|
throw new Error(`Cannot cast this to tag: ${x}`);
|
|
172
178
|
};
|
|
173
179
|
|
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -1714,9 +1714,11 @@ export let register_calcit_builtin_impls = (options: typeof calcit_builtin_impls
|
|
|
1714
1714
|
|
|
1715
1715
|
/** method used as closure */
|
|
1716
1716
|
export function invoke_method_closure(p: string) {
|
|
1717
|
-
|
|
1717
|
+
const f = (obj: CalcitValue, ...args: CalcitValue[]) => {
|
|
1718
1718
|
return invoke_method(p, obj, ...args);
|
|
1719
1719
|
};
|
|
1720
|
+
(f as { __calcitMethodName?: string }).__calcitMethodName = p;
|
|
1721
|
+
return f;
|
|
1720
1722
|
}
|
|
1721
1723
|
|
|
1722
1724
|
function normalize_builtin_impls(entry: CalcitImplEntry): CalcitImpl[] | null {
|