@calcit/procs 0.12.0 → 0.12.2
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/build.rs +34 -3
- package/editing-history/2026-0310-1040-edit-schema-primitive-tag-support.md +42 -0
- package/editing-history/2026-0310-1754-ns-entry-snapshot-migration.md +66 -0
- package/editing-history/202603091753-schema-type-fail-tests.md +17 -0
- package/editing-history/202603091819-add-test-fail-script.md +5 -0
- package/editing-history/202603091944-split-type-fail-tests.md +8 -0
- package/lib/package.json +2 -1
- package/package.json +2 -1
- /package/editing-history/{2026-0304-generics-fn-typevar-identity.md → 2026-0304-0000-generics-fn-typevar-identity.md} +0 -0
- /package/editing-history/{2026-0307-migrate-hint-fn-to-schema.md → 2026-0307-0000-migrate-hint-fn-to-schema.md} +0 -0
- /package/editing-history/{2026-0307-remove-enum-prototype-field.md → 2026-0307-0000-remove-enum-prototype-field.md} +0 -0
- /package/editing-history/{2026-0307-schema-args-type-enforcement.md → 2026-0307-0000-schema-args-type-enforcement.md} +0 -0
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/build.rs
CHANGED
|
@@ -28,9 +28,15 @@ pub struct CodeEntry {
|
|
|
28
28
|
pub schema: Option<Edn>,
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
32
|
+
pub struct NsEntry {
|
|
33
|
+
pub doc: String,
|
|
34
|
+
pub code: Cirru,
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
32
38
|
pub struct FileInSnapShot {
|
|
33
|
-
pub ns:
|
|
39
|
+
pub ns: NsEntry,
|
|
34
40
|
pub defs: HashMap<String, CodeEntry>,
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -204,6 +210,31 @@ fn parse_code_entry(edn: Edn, owner: &str) -> Result<CodeEntry, String> {
|
|
|
204
210
|
})
|
|
205
211
|
}
|
|
206
212
|
|
|
213
|
+
fn parse_ns_entry(edn: Edn, owner: &str) -> Result<NsEntry, String> {
|
|
214
|
+
let record: EdnRecordView = match edn {
|
|
215
|
+
Edn::Record(r) => r,
|
|
216
|
+
other => {
|
|
217
|
+
return Err(format!(
|
|
218
|
+
"{owner}: expected NsEntry/CodeEntry record, got {}",
|
|
219
|
+
format_edn_preview(&other)
|
|
220
|
+
));
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
let mut doc = String::new();
|
|
224
|
+
let mut code: Option<Cirru> = None;
|
|
225
|
+
for (key, value) in &record.pairs {
|
|
226
|
+
match key.arc_str().as_ref() {
|
|
227
|
+
"doc" => doc = from_edn(value.clone()).map_err(|e| format!("{owner}: invalid `:doc`: {e}"))?,
|
|
228
|
+
"code" => code = Some(from_edn(value.clone()).map_err(|e| format!("{owner}: invalid `:code`: {e}"))?),
|
|
229
|
+
_ => {}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
Ok(NsEntry {
|
|
233
|
+
doc,
|
|
234
|
+
code: code.ok_or_else(|| format!("{owner}: missing `:code` field in NsEntry"))?,
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
|
|
207
238
|
fn parse_file_in_snapshot(edn: Edn, file_name: &str) -> Result<FileInSnapShot, String> {
|
|
208
239
|
let record: EdnRecordView = match edn {
|
|
209
240
|
Edn::Record(r) => r,
|
|
@@ -214,11 +245,11 @@ fn parse_file_in_snapshot(edn: Edn, file_name: &str) -> Result<FileInSnapShot, S
|
|
|
214
245
|
));
|
|
215
246
|
}
|
|
216
247
|
};
|
|
217
|
-
let mut ns: Option<
|
|
248
|
+
let mut ns: Option<NsEntry> = None;
|
|
218
249
|
let mut defs: HashMap<String, CodeEntry> = HashMap::new();
|
|
219
250
|
for (key, value) in &record.pairs {
|
|
220
251
|
match key.arc_str().as_ref() {
|
|
221
|
-
"ns" => ns = Some(
|
|
252
|
+
"ns" => ns = Some(parse_ns_entry(value.clone(), &format!("{file_name}/:ns"))?),
|
|
222
253
|
"defs" => {
|
|
223
254
|
let map = match value {
|
|
224
255
|
Edn::Map(m) => m,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# cr edit schema: support primitive type tag leaves
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
`cr edit schema` 原来只接受 `:: :fn $ {}` 这样的函数 schema 或 `{}` map 形式。
|
|
6
|
+
有些定义的类型本身就是简单原始类型(如 `:string`、`:number`),不是函数,需要直接用 tag 表达。
|
|
7
|
+
|
|
8
|
+
## 新语法
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
cr edit schema 'respo.comp.space/style-space' --leaf -e ':string'
|
|
12
|
+
cr edit schema 'some.ns/my-val' --leaf -e ':number'
|
|
13
|
+
cr edit schema 'some.ns/my-flag' --leaf -e ':bool'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
接受的 primitive 类型 tag:`bool`, `number`, `string`, `symbol`, `tag`, `list`, `map`, `set`, `fn`, `tuple`, `ref`, `buffer`, `dynamic`, `unit`
|
|
17
|
+
|
|
18
|
+
## 改动文件
|
|
19
|
+
|
|
20
|
+
### `src/calcit/type_annotation.rs`
|
|
21
|
+
|
|
22
|
+
- `builtin_tag_name` 改为 `pub(crate)`,供 snapshot 序列化侧调用。
|
|
23
|
+
|
|
24
|
+
### `src/snapshot.rs`
|
|
25
|
+
|
|
26
|
+
- 新增常量 `PRIMITIVE_SCHEMA_TAGS`:列出允许作为 leaf schema 的原始类型。
|
|
27
|
+
- `validate_schema_for_write`:对 `Cirru::Leaf` 先检查是否在允许列表,允许则直接 Ok;否则给出提示信息。
|
|
28
|
+
- `parse_loaded_schema_annotation`:新增对 `Edn::Tag` 的处理,返回对应 `CalcitTypeAnnotation`。
|
|
29
|
+
- 两处 `CodeEntry::From` impl:`_ => Edn::Nil` 改为调用 `builtin_tag_name().map(Edn::tag)` 把原始类型 tag 正确序列化到快照。
|
|
30
|
+
- 测试 `test_validate_schema_for_write`:更新为测试原始类型 leaf 通过、未知 leaf 拒绝。
|
|
31
|
+
|
|
32
|
+
### `src/bin/cli_handlers/edit.rs`
|
|
33
|
+
|
|
34
|
+
- `handle_schema`:`validate_schema_for_write` 通过后,若 `schema_payload` 是 `Cirru::Leaf`,用 `CalcitTypeAnnotation::from_tag_name` 直接设置 schema 并返回,不走函数 schema 解析路径。
|
|
35
|
+
|
|
36
|
+
## 完整数据流(以 `:string` 为例)
|
|
37
|
+
|
|
38
|
+
1. CLI 收到 `--leaf -e ':string'` → `Cirru::Leaf(":string")`
|
|
39
|
+
2. `validate_schema_for_write` → `"string"` 在 `PRIMITIVE_SCHEMA_TAGS` → Ok
|
|
40
|
+
3. `CalcitTypeAnnotation::from_tag_name("string")` → `CalcitTypeAnnotation::String`
|
|
41
|
+
4. 写入快照 → `CodeEntry::From` 序列化为 `Edn::tag("string")`
|
|
42
|
+
5. 读回快照 → `parse_loaded_schema_annotation(Edn::Tag("string"))` → `CalcitTypeAnnotation::String`
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# 2026-0310-1754 — snapshot namespace entry migrate to NsEntry
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
snapshot 里的 `:ns` 之前复用了 `CodeEntry` 结构,导致 namespace 也带着 `:schema` 和 `:examples` 字段,语义上并不合适,而且保存时经常只是写成 `(:schema nil)`。
|
|
6
|
+
|
|
7
|
+
这次改动把 namespace 入口单独收敛到 `NsEntry`,同时保持读取旧 `CodeEntry` 写法的兼容性。
|
|
8
|
+
|
|
9
|
+
## 核心改动
|
|
10
|
+
|
|
11
|
+
### `src/snapshot.rs`
|
|
12
|
+
|
|
13
|
+
- 新增 `NsEntry { doc, code }`
|
|
14
|
+
- `FileInSnapShot.ns` 从 `CodeEntry` 改为 `NsEntry`
|
|
15
|
+
- `RawFileInSnapShot.ns` 同步改为 `NsEntry`
|
|
16
|
+
- 新增 `TryFrom<Edn> for NsEntry` 与 `From<NsEntry> for Edn`
|
|
17
|
+
- 读取 snapshot 时,`ns` 只解析 `doc` 和 `code`,兼容旧 `CodeEntry` 形状并忽略 `schema/examples`
|
|
18
|
+
- 移除 `validate_snapshot_schemas_for_write` 对 `ns.schema` 的校验
|
|
19
|
+
- `gen_meta_ns`、`create_file_from_snippet` 等内部构造统一改为写 `NsEntry`
|
|
20
|
+
|
|
21
|
+
### `build.rs`
|
|
22
|
+
|
|
23
|
+
- 嵌入式 core snapshot 解析结构新增 `NsEntry`
|
|
24
|
+
- build 阶段读取 `src/cirru/calcit-core.cirru` 时,`ns` 不再解析为 `CodeEntry`
|
|
25
|
+
|
|
26
|
+
### `src/detailed_snapshot.rs`
|
|
27
|
+
|
|
28
|
+
- 新增 `DetailedNsEntry { doc, code }`
|
|
29
|
+
- `DetailedFileInSnapshot.ns` 从 `DetailedCodeEntry` 改为 `DetailedNsEntry`
|
|
30
|
+
- 详细快照读取仍兼容旧 namespace record,只提取 `doc` 和 `code`
|
|
31
|
+
|
|
32
|
+
### `src/bin/cr_sync.rs`
|
|
33
|
+
|
|
34
|
+
- namespace change payload 从 `CodeEntry` 拆成 `SnapshotEntry::Ns(NsEntry)`
|
|
35
|
+
- definition change payload 保持 `SnapshotEntry::Def(CodeEntry)`
|
|
36
|
+
- detailed snapshot 写回时,namespace 统一序列化为 `NsEntry`
|
|
37
|
+
|
|
38
|
+
### `src/bin/cli_handlers/edit.rs`
|
|
39
|
+
|
|
40
|
+
- `edit add-ns` 创建新 namespace 时直接写入 `NsEntry`
|
|
41
|
+
|
|
42
|
+
## 数据文件迁移
|
|
43
|
+
|
|
44
|
+
- 批量运行 `cr edit format`,将 compact snapshot 中旧的 `:ns $ %{} :CodeEntry ... (:schema nil) :examples []` 收敛为 `:NsEntry`
|
|
45
|
+
- 运行 `cr-sync` 重写 detailed snapshot:
|
|
46
|
+
- `demos/calcit.cirru`
|
|
47
|
+
- `calcit/editor/calcit.cirru`
|
|
48
|
+
- `src/cirru/calcit-core.cirru` 也已更新为 `NsEntry`
|
|
49
|
+
|
|
50
|
+
## 兼容策略
|
|
51
|
+
|
|
52
|
+
1. **读取兼容**:旧 snapshot/detailed snapshot 中 `ns` 仍然可以是 `CodeEntry` record
|
|
53
|
+
2. **内存收敛**:加载后统一存成 `NsEntry`
|
|
54
|
+
3. **保存统一**:以后重新保存或 format 都写回 `NsEntry`
|
|
55
|
+
|
|
56
|
+
## 验证
|
|
57
|
+
|
|
58
|
+
- `cargo fmt` ✅
|
|
59
|
+
- `cargo clippy -- -D warnings` ✅
|
|
60
|
+
- `cargo test` ✅
|
|
61
|
+
- `yarn check-all` ✅
|
|
62
|
+
|
|
63
|
+
## 备注
|
|
64
|
+
|
|
65
|
+
- `demos/compact.tmp.cirru` 不是合法 snapshot,`cr edit format` 会报 EDN 解析错误,因此未纳入统一格式化
|
|
66
|
+
- `demos/deps.cirru` 不是当前 snapshot loader 支持的结构,因此同样未走 `edit format`
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# schema type-fail tests and error codes
|
|
2
|
+
|
|
3
|
+
- 新增 `calcit/type-fail/` 下 schema 相关失败 fixture 的自动化测试,覆盖:
|
|
4
|
+
- `:args` required arity mismatch
|
|
5
|
+
- `:rest` presence mismatch
|
|
6
|
+
- `:kind` mismatch
|
|
7
|
+
- 基于 schema 的调用参数类型不匹配
|
|
8
|
+
- 在 `src/bin/cr.rs` 中补充 fixture 加载 helper,并通过 `run_check_only()` / preprocess warning 断言行为。
|
|
9
|
+
- 为类型/预处理相关告警补充 code:
|
|
10
|
+
- `W_FN_ARG_TYPE_MISMATCH`
|
|
11
|
+
- `W_PROC_ARG_TYPE_MISMATCH`
|
|
12
|
+
- `W_CORE_FN_ARG_TYPE_MISMATCH`
|
|
13
|
+
- `W_FN_RETURN_TYPE_MISMATCH`
|
|
14
|
+
- 为 schema 定义不匹配错误补充 code:
|
|
15
|
+
- `E_SCHEMA_DEF_MISMATCH`
|
|
16
|
+
- 为 `CalcitErr` 增加 `code` 字段和 `headline()`,让 CLI 输出可携带错误码。
|
|
17
|
+
- 更新 `calcit/type-fail/README.md`,记录自动化测试与当前相关 code。
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# split type-fail tests into separate file
|
|
2
|
+
|
|
3
|
+
- 将 `src/bin/cr.rs` 中与 `type-fail` fixture 相关的 helper 和测试拆分到独立文件 `src/bin/cr_type_fail_tests.rs`。
|
|
4
|
+
- 在 `src/bin/cr.rs` 顶部通过 `#[cfg(test)] mod cr_type_fail_tests;` 挂载测试模块。
|
|
5
|
+
- 保留 `cr.rs` 中的通用 schema/type 覆盖测试,减少主文件体积。
|
|
6
|
+
- 验证通过:
|
|
7
|
+
- `cargo test -q --bin cr`
|
|
8
|
+
- `yarn test-fail`
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@types/node": "^25.0.9",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"fmt-rs": "cargo fmt --all",
|
|
15
15
|
"lint-rs": "cargo clippy --all-targets -- -D warnings",
|
|
16
16
|
"test-rs": "cargo test -q",
|
|
17
|
+
"test-fail": "cargo test -q --bin cr type_fail_",
|
|
17
18
|
"test-snippets": "cargo test -q snippets::tests",
|
|
18
19
|
"bench-recur-smoke": "cargo run --bin cr -- calcit/test.cirru -1 js && node --input-type=module -e \"import { test_loop } from './js-out/test-recursion.main.mjs'; const n=3000; const t0=process.hrtime.bigint(); for(let i=0;i<n;i++) test_loop(); const dt=Number(process.hrtime.bigint()-t0)/1e6; console.log('test_loop_ms='+dt.toFixed(3));\"",
|
|
19
20
|
"check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@types/node": "^25.0.9",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"fmt-rs": "cargo fmt --all",
|
|
15
15
|
"lint-rs": "cargo clippy --all-targets -- -D warnings",
|
|
16
16
|
"test-rs": "cargo test -q",
|
|
17
|
+
"test-fail": "cargo test -q --bin cr type_fail_",
|
|
17
18
|
"test-snippets": "cargo test -q snippets::tests",
|
|
18
19
|
"bench-recur-smoke": "cargo run --bin cr -- calcit/test.cirru -1 js && node --input-type=module -e \"import { test_loop } from './js-out/test-recursion.main.mjs'; const n=3000; const t0=process.hrtime.bigint(); for(let i=0;i<n;i++) test_loop(); const dt=Number(process.hrtime.bigint()-t0)/1e6; console.log('test_loop_ms='+dt.toFixed(3));\"",
|
|
19
20
|
"check-smooth": "yarn fmt-rs && yarn lint-rs && yarn test-rs && yarn check-all",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|