@calcit/procs 0.12.56 → 0.12.57

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.
Files changed (155) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/build.rs +36 -2
  3. package/editing-history/202608011759-issue-routing-in-agent-guide.md +17 -0
  4. package/editing-history/202608011833-schema-type-symbols.md +20 -0
  5. package/editing-history/202608011852-wasm-dynamic-string-tag.md +7 -0
  6. package/editing-history/202608011908-consolidate-history.md +6 -0
  7. package/editing-history/202608012022-consolidate-cli-and-test-duplication.md +28 -0
  8. package/editing-history/202608012123-review-follow-up.md +18 -0
  9. package/editing-history/202608012320-release-0.12.57.md +5 -0
  10. package/editing-history/ARCHIVE.md +15 -0
  11. package/editing-history/README.md +21 -0
  12. package/lib/package.json +1 -1
  13. package/package.json +1 -1
  14. package/editing-history/2026-02-13-1841-trait-origin-structural-eq.md +0 -91
  15. package/editing-history/2026-02-14-2050-js-codegen-recursion-tag-migration.md +0 -39
  16. package/editing-history/2026-02-14-2358-emit-js-modularization-shift-left.md +0 -63
  17. package/editing-history/2026-02-15-0000-diagnostics-consolidated.md +0 -35
  18. package/editing-history/2026-02-15-1941-macro-diagnostics-refinement.md +0 -39
  19. package/editing-history/2026-02-16-2043-core-api-docs-cleanup.md +0 -40
  20. package/editing-history/2026-02-23-0834-migrate-to-defstruct.md +0 -91
  21. package/editing-history/2026-02-23-2321-ns-imports-code-fixes.md +0 -42
  22. package/editing-history/2026-02-25-0002-language-behavior-eval-mode.md +0 -93
  23. package/editing-history/2026-02-25-0111-guidebook-no-check-block-upgrades.md +0 -52
  24. package/editing-history/2026-02-25-0113-runtime-type-validation-and-macro-quoting.md +0 -41
  25. package/editing-history/2026-02-25-1131-check-md-eval-improvements.md +0 -13
  26. package/editing-history/2026-02-26-1324-check-md-inprocess-cache-and-path-labels.md +0 -7
  27. package/editing-history/2026-02-27-1640-unify-markdown-readers.md +0 -16
  28. package/editing-history/2026-02-27-1958-tree-rewrite-command-and-reference-model.md +0 -18
  29. package/editing-history/2026-02-27-2200-split-def-command.md +0 -29
  30. package/editing-history/2026-02-27-2212-tree-raise-wrap.md +0 -33
  31. package/editing-history/2026-02-27-2223-calcit-agent-docs-optimize.md +0 -41
  32. package/editing-history/2026-03-01-0212-query-search-entry-and-ffi-warning.md +0 -53
  33. package/editing-history/2026-03-03-1934-check-types-and-core-annotations.md +0 -17
  34. package/editing-history/2026-03-04-0000-generics-fn-typevar-identity.md +0 -30
  35. package/editing-history/2026-03-04-1331-tag-call-warning-and-dot-access-migration.md +0 -28
  36. package/editing-history/2026-03-04-1548-impl-new-dot-method-input-and-doc-hints.md +0 -33
  37. package/editing-history/2026-03-04-1645-calcit-eq-contract-refactor-and-macro-tests.md +0 -28
  38. package/editing-history/2026-03-04-2200-assert-type-assert-traits-composable-runtime-checks.md +0 -18
  39. package/editing-history/2026-03-05-0042-type-inference-argtypes-and-core-hints.md +0 -54
  40. package/editing-history/2026-03-05-0115-calcit-core-generic-refinements.md +0 -57
  41. package/editing-history/2026-03-05-1930-schema-migration-cr-edit.md +0 -30
  42. package/editing-history/2026-03-05-1939-query-schema-adaptation.md +0 -42
  43. package/editing-history/2026-03-06-0120-schema-hint-migration-batch.md +0 -38
  44. package/editing-history/2026-03-06-1416-core-macro-schema-migration.md +0 -20
  45. package/editing-history/2026-03-06-1552-core-schema-and-hintfn-migration.md +0 -63
  46. package/editing-history/2026-03-06-1936-schema-normalization-and-preprocess-preload.md +0 -12
  47. package/editing-history/2026-03-07-0000-migrate-hint-fn-to-schema.md +0 -29
  48. package/editing-history/2026-03-07-0000-remove-enum-prototype-field.md +0 -43
  49. package/editing-history/2026-03-07-0000-schema-args-type-enforcement.md +0 -66
  50. package/editing-history/2026-03-07-0142-unit-type-and-builtin-schemas.md +0 -82
  51. package/editing-history/2026-03-07-1652-decouple-snapshot-schema-to-calcit-type.md +0 -112
  52. package/editing-history/2026-03-07-1821-snapshot-schema-validation.md +0 -6
  53. package/editing-history/2026-03-07-1959-schema-def-kind-arity-validation.md +0 -96
  54. package/editing-history/2026-03-08-0031-schema-generics-quote-normalization.md +0 -35
  55. package/editing-history/2026-03-08-1905-schema-typeref-and-assert-migration.md +0 -34
  56. package/editing-history/2026-03-08-2033-schema-wrapper-migration.md +0 -45
  57. package/editing-history/2026-03-08-2315-late-schema-cleanup-and-warning-compat.md +0 -27
  58. package/editing-history/2026-03-09-1753-schema-type-fail-tests.md +0 -17
  59. package/editing-history/2026-03-10-1040-edit-schema-primitive-tag-support.md +0 -42
  60. package/editing-history/2026-03-10-1754-ns-entry-snapshot-migration.md +0 -66
  61. package/editing-history/2026-03-13-2216-validate-struct-type-arg-arity.md +0 -24
  62. package/editing-history/2026-03-16-2353-runtime-boundary-cleanup.md +0 -14
  63. package/editing-history/2026-03-17-0150-runtime-boundary-lookup-cleanup.md +0 -28
  64. package/editing-history/2026-03-20-0116-json-builtins-and-runtime-docs.md +0 -48
  65. package/editing-history/2026-03-26-2013-docs-frontmatter-and-module-search.md +0 -58
  66. package/editing-history/2026-04-07-1550-path-format-at-prefix-migration.md +0 -46
  67. package/editing-history/2026-04-12-1524-js-codegen-map-to-record.md +0 -26
  68. package/editing-history/2026-04-12-1549-map-to-record-field-validation.md +0 -29
  69. package/editing-history/2026-04-13-1600-tuple-to-enum-rewrite.md +0 -13
  70. package/editing-history/2026-04-13-2309-typeslot-enum-compile-safety.md +0 -45
  71. package/editing-history/2026-04-14-1500-loose-record-syntax.md +0 -32
  72. package/editing-history/2026-04-14-2259-bidir-type-check-refactor.md +0 -63
  73. package/editing-history/2026-04-15-0120-match-syntax-exhaustiveness.md +0 -20
  74. package/editing-history/2026-04-15-1211-record-nth-optimization.md +0 -44
  75. package/editing-history/2026-04-16-1936-predicate-narrowing-expansion.md +0 -31
  76. package/editing-history/2026-04-17-0132-monomorphize-map-filter.md +0 -50
  77. package/editing-history/2026-04-17-0135-monomorphize-includes-reverse.md +0 -31
  78. package/editing-history/2026-04-17-0140-fold-type-predicates.md +0 -44
  79. package/editing-history/2026-04-17-0154-generic-dispatch-records-tuples.md +0 -52
  80. package/editing-history/2026-04-17-0520-simplify-generic-defns-via-method-dispatch.md +0 -49
  81. package/editing-history/2026-05-21-0055-tree-show-cr-config-and-edit-cleanup.md +0 -81
  82. package/editing-history/2026-05-31-2052-macro-schema-roundtrip-and-weak-types.md +0 -6
  83. package/editing-history/2026-05-31-2105-map-generic-weak-types-followup.md +0 -15
  84. package/editing-history/2026-06-01-0003-update-callback-field-specialization.md +0 -19
  85. package/editing-history/2026-06-01-2317-data-definition-where-bounds.md +0 -6
  86. package/editing-history/2026-06-02-0114-data-definition-where-macro-followup.md +0 -21
  87. package/editing-history/2026-06-03-0000-check-md-edn-errors.md +0 -5
  88. package/editing-history/2026-06-03-1600-check-md-entry-modules.md +0 -6
  89. package/editing-history/2026-06-04-0000-check-md-app-main-init.md +0 -6
  90. package/editing-history/2026-06-04-2218-compiled-executable-runtime-backfill.md +0 -6
  91. package/editing-history/2026-06-09-0000-with-type-slot-scoped-binding.md +0 -83
  92. package/editing-history/2026-06-09-1241-remove-bind-type.md +0 -64
  93. package/editing-history/2026-06-09-1800-core-effect-tags.md +0 -57
  94. package/editing-history/2026-06-10-1200-get-def-doc-schema-builtin.md +0 -7
  95. package/editing-history/2026-06-15-1500-effects-graph-mvp.md +0 -30
  96. package/editing-history/2026-06-16-1700-effects-graph-ste-tree.md +0 -84
  97. package/editing-history/2026-06-27-0052-cli-improvements.md +0 -41
  98. package/editing-history/2026-06-27-0202-docs-indexing-improvements.md +0 -22
  99. package/editing-history/2026-06-27-0315-file-splits.md +0 -17
  100. package/editing-history/2026-06-27-0416-agent-advanced-split.md +0 -15
  101. package/editing-history/archived/2025-04-12-1453-map-to-record-rewrite.md +0 -33
  102. package/editing-history/archived/2025-04-16-0117-wasm-codegen-and-catalog-update.md +0 -40
  103. package/editing-history/archived/2025-07-16-0207-wasm-encoder-migration.md +0 -48
  104. package/editing-history/archived/2025-07-16-1633-wasm-data-structures.md +0 -61
  105. package/editing-history/archived/2026-02-13-1926-docs-tests-followup.md +0 -33
  106. package/editing-history/archived/2026-02-16-2128-docs-smoke-and-trait-errors.md +0 -20
  107. package/editing-history/archived/2026-02-25-1234-watch-mode-default-once.md +0 -5
  108. package/editing-history/archived/2026-03-07-1302-calcit-agent-docs-update.md +0 -32
  109. package/editing-history/archived/2026-03-09-1819-add-test-fail-script.md +0 -5
  110. package/editing-history/archived/2026-03-09-1944-split-type-fail-tests.md +0 -8
  111. package/editing-history/archived/2026-03-16-1449-profiling-tools-reorg.md +0 -13
  112. package/editing-history/archived/2026-03-17-2026-afternoon-runtime-boundary-optimization-summary.md +0 -87
  113. package/editing-history/archived/2026-03-18-1802-tips-level-and-overwrite-schema-preservation.md +0 -26
  114. package/editing-history/archived/2026-03-20-1229-query-window-3-with-parent-preview.md +0 -72
  115. package/editing-history/archived/2026-03-23-1137-command-echo-tool-output-cleanup.md +0 -71
  116. package/editing-history/archived/2026-04-10-0011-snapshot-empty-version-pipe-marker.md +0 -23
  117. package/editing-history/archived/2026-04-16-0131-wasm-math-and-test-integration.md +0 -28
  118. package/editing-history/archived/2026-04-16-1507-wasm-data-structures-and-rfc-rename.md +0 -27
  119. package/editing-history/archived/2026-04-16-1520-wasm-bitwise-and-match.md +0 -21
  120. package/editing-history/archived/2026-04-16-1542-wasm-cross-ns-host-imports.md +0 -38
  121. package/editing-history/archived/2026-04-17-0026-wasm-rest-args.md +0 -62
  122. package/editing-history/archived/2026-04-17-0048-wasm-type-of.md +0 -70
  123. package/editing-history/archived/2026-04-17-0051-wasm-derived-predicates.md +0 -34
  124. package/editing-history/archived/2026-04-17-2316-wasm-do-println-fixes.md +0 -41
  125. package/editing-history/archived/2026-04-18-1208-split-emit-wasm-and-bump-version.md +0 -15
  126. package/editing-history/archived/2026-04-18-1430-wasm-list-match-and-method-dispatch.md +0 -5
  127. package/editing-history/archived/2026-04-18-2041-cr-wasm-split-and-runtime-stability.md +0 -18
  128. package/editing-history/archived/2026-04-18-2045-v0.12.23-ci-wasm-fix.md +0 -13
  129. package/editing-history/archived/2026-04-21-1818-wasm-string-ops-v2.md +0 -57
  130. package/editing-history/archived/2026-04-21-2332-split-emit-wasm.md +0 -45
  131. package/editing-history/archived/2026-04-22-0114-wasm-hof-intercepts-and-set-intersection.md +0 -82
  132. package/editing-history/archived/2026-04-22-0136-wasm-enum-tuple-bool-str-fixes.md +0 -68
  133. package/editing-history/archived/2026-04-22-1340-wasm-map-diff-new-and-let-intercept.md +0 -53
  134. package/editing-history/archived/2026-04-23-1419-v0.12.26-wasm-bisection-fixes.md +0 -7
  135. package/editing-history/archived/2026-04-23-1645-release-conventions.md +0 -14
  136. package/editing-history/archived/2026-04-25-1940-wasm-suite-multi-module-entry.md +0 -53
  137. package/editing-history/archived/2026-04-25-2003-wasm-method-includes-string-and-set-refactor.md +0 -71
  138. package/editing-history/archived/2026-04-25-2010-wasm-suite-add-fn-lens-edn.md +0 -43
  139. package/editing-history/archived/2026-04-25-2051-display-by.md +0 -39
  140. package/editing-history/archived/2026-04-28-1728-fix-gensym-stable.md +0 -31
  141. package/editing-history/archived/2026-04-29-1400-fix-bind-type-precompile.md +0 -38
  142. package/editing-history/archived/2026-05-26-0957-match-docs-check-md.md +0 -24
  143. package/editing-history/archived/2026-05-31-2059-ci-docs-test-and-fn-helper-tightening.md +0 -3
  144. package/editing-history/archived/2026-06-01-0005-release-0.12.36.md +0 -16
  145. package/editing-history/archived/2026-06-01-2230-enum-struct-payload-docs.md +0 -4
  146. package/editing-history/archived/2026-06-03-1620-release-0.12.38.md +0 -6
  147. package/editing-history/archived/2026-06-04-0000-release-0.12.39.md +0 -4
  148. package/editing-history/archived/2026-06-04-2230-release-0.12.40.md +0 -5
  149. package/editing-history/archived/2026-06-12-1525-weak-types-dots-format.md +0 -15
  150. package/editing-history/archived/2026-06-13-1200-primitive_schema_tags.md +0 -9
  151. package/editing-history/archived/2026-06-20-1142-ts-declaration-d-mts.md +0 -5
  152. package/editing-history/archived/2026-06-29-0117-upgrade-doc-snapshot-migration.md +0 -2
  153. package/editing-history/archived/2026-06-29-calcit-cli.md +0 -80
  154. package/editing-history/archived/2026-06-29-typed-calcit-cli-schemas.md +0 -23
  155. package/editing-history/archived/20260630-duplication-analysis.md +0 -116
@@ -1,61 +0,0 @@
1
- # WASM Data Structures: List, Map, Set + Optional Args + Raise
2
-
3
- ## Summary
4
-
5
- Comprehensive data structure support for WASM codegen: list (16 ops), map (9 ops), set (6 ops), plus `raise` and optional argument handling.
6
-
7
- ## Changes
8
-
9
- ### 1. Optional Args (`CalcitArgLabel::OptionalMark`)
10
- - `compile_fn`: Skip `OptionalMark` markers — they aren't parameters, just annotations. The actual Idx labels become WASM params.
11
- - Added `fn_arity` map alongside `fn_index` to track each function's WASM arity (counting only `Idx` labels).
12
- - At call sites (`Calcit::Import`, `Calcit::Symbol`), pad missing optional args with `f64.const 0` (nil) to match target arity.
13
- - **Key insight**: The Calcit preprocessor doesn't always fill nil for omitted optional args in the code tree; WASM codegen must handle the arity mismatch at the call site.
14
-
15
- ### 2. Raise
16
- - `CalcitProc::Raise` → evaluate and drop all args, emit `Instruction::Unreachable`.
17
-
18
- ### 3. Memory Layouts
19
- - **List**: `[count:f64] [elem0:f64] [elem1:f64] ...` — size `(1+count)*8`
20
- - **Map**: `[count:f64] [key0:f64] [val0:f64] [key1:f64] [val1:f64] ...` — size `(1+count*2)*8`
21
- - **Set**: Same as list — `[count:f64] [elem0:f64] ...`
22
-
23
- ### 4. Helper Functions
24
- - `emit_bump_alloc_dynamic(ctx, size_local, ptr_local)` — bump allocator with dynamic size
25
- - `emit_ptr_to_i32(ctx, expr)` — evaluate expression to i32 pointer in a local
26
- - `emit_load_count_i32(ctx, ptr)` — load count from first f64 slot as i32
27
- - `emit_addr_offset(ctx, base, offset)` — compute base+offset into new local
28
- - `emit_copy_f64_loop(ctx, dst, src, n)` — copy N f64 slots between addresses
29
- - `emit_ds_count(ctx, args)` — shared count accessor (list/map/set)
30
- - `emit_ds_empty(ctx, args)` — shared empty? check
31
- - `emit_alloc_with_count(ctx, count, total_slots)` — allocate and write count header
32
-
33
- ### 5. List Operations (16)
34
- - Constructor: `emit_list_new` — `[] elem0 elem1 ...`
35
- - Access: `emit_list_nth`, `emit_list_first`, `emit_list_rest`
36
- - Mutation: `emit_list_append`, `emit_list_prepend`, `emit_list_butlast`
37
- - Slicing: `emit_list_slice`, `emit_list_reverse`, `emit_list_concat`
38
- - Update: `emit_list_assoc`, `emit_list_dissoc`
39
- - Query: `emit_list_contains`, `emit_list_includes`
40
-
41
- ### 6. Map Operations (9)
42
- - Constructor: `emit_map_new` — `&{} key val ...`
43
- - Access: `emit_map_get_op` — linear key scan, return value or nil
44
- - Mutation: `emit_map_assoc` (scan for existing key, branch: update vs append), `emit_map_dissoc` (scan + copy-with-skip)
45
- - Query: `emit_map_contains`, `emit_map_includes`
46
- - Transform: `emit_map_to_pairs` — creates list of 2-elem lists (nested allocation in loop)
47
-
48
- ### 7. Set Operations (6)
49
- - Constructor: `emit_set_new` — `#{} elem ...`
50
- - Access: `emit_set_includes` (delegates to list_includes — same layout)
51
- - Mutation: `emit_set_include` (scan + conditional append), `emit_set_exclude` (scan + copy-with-skip)
52
-
53
- ## WASM Patterns Used
54
- - **Copy loop**: `block/loop/br_if/br` with i32 counter for bulk f64 element copying
55
- - **Scan loop**: Same pattern with `f64.eq` comparison for key/value lookup; `found_idx` local with -1 sentinel
56
- - **Conditional allocation**: `if/else` for map_assoc (new key vs update) and set_include (already present vs append)
57
- - **Select instruction**: For boolean returns (`contains?`, `empty?`) — `select(true_val, false_val, condition)`
58
-
59
- ## Test Results
60
- - 90 WASM checks (55 existing + 35 new) — all pass
61
- - 246 cargo tests — all pass
@@ -1,33 +0,0 @@
1
- # 2026-02-13 19:26 文档与测试补充(跟进)
2
-
3
- ## 背景
4
-
5
- 在完成 trait/macro 相关优化(P1/P2/P3)后,补做“是否需要补充测试与文档”的审计。
6
-
7
- ## 本次结论
8
-
9
- 需要补充,且已补最小必要范围:
10
-
11
- 1. 文档:
12
- - `guidebook/docs/features/macros.md`
13
- - 增加 `with-gensyms` 用法示例。
14
- - 增加 `macroexpand`/`macroexpand-1`/`macroexpand-all` 的展开链路说明(stderr)。
15
- - `guidebook/docs/features/traits.md`
16
- - 增加 `warn-dyn-method` 下的新增诊断说明。
17
- - 明确 `&trait-call` 按 impl 的 trait origin 匹配,而非仅按名称文本匹配。
18
-
19
- 2. 测试:
20
- - `src/calcit/calcit_trait.rs`
21
- - 新增 default identity 单测:
22
- - `def_ref` 相同 => trait 相等且 hash 一致;
23
- - 无 `def_ref` 时走函数元信息 fallback,并校验等价/不等价边界。
24
-
25
- ## 验证
26
-
27
- - `cargo test -q calcit_trait::tests` 通过。
28
- - `yarn check-all` 通过(本轮补丁后再跑)。
29
-
30
- ## 经验点
31
-
32
- - 文档应及时反映“诊断开关”边界(默认流程 vs `warn-dyn-method`)。
33
- - identity 规则变化必须配对 hash/eq 回归测试,避免后续 refactor 引入行为漂移。
@@ -1,20 +0,0 @@
1
- # Docs smoke cases and trait misuse error normalization
2
-
3
- ## Summary
4
-
5
- - Added executable docs smoke tests for key trait semantics.
6
- - Integrated smoke tests into main test entry.
7
- - Normalized high-frequency misuse messages with `Expected/Actual/Fix` guidance.
8
- - Stabilized cross-runtime smoke assertions so `yarn check-all` passes in both eval and js modes.
9
-
10
- ## Knowledge points
11
-
12
- - `assert-traits` first argument is enforced at preprocess as local-only.
13
- - `impl-traits` targets definition-level values (`struct`/`enum`), not instances.
14
- - Error string matching in JS runtime should avoid host-error-dependent formatting; keep strict message-content checks in eval mode.
15
-
16
- ## Validation
17
-
18
- - `cargo fmt`
19
- - `cargo run --bin cr -- calcit/test.cirru -1`
20
- - `yarn check-all` (exit code 0)
@@ -1,5 +0,0 @@
1
- # watch mode default-once update
2
-
3
- - Unified run mode behavior for `cr`, `cr js`, and `cr ir`: default to once.
4
- - Added explicit `-w/--watch` switches for top-level direct run and `ir` subcommand.
5
- - Updated watch-mode related docs in `Agents.md` and `docs/CalcitAgent.md`.
@@ -1,32 +0,0 @@
1
- # 2026-03-07 CalcitAgent.md 文档更新
2
-
3
- ## 修改内容
4
-
5
- ### 1. 新增 `--no-tips` 全局标志文档
6
-
7
- 在「主要运行命令」小节中,`cr js --check-only` 之后新增:
8
-
9
- ```
10
- - `cr --no-tips <subcommand> ...` - 隐藏所有编辑/查询命令输出的 "Tips:" 提示行(适合脚本/Agent 使用)
11
- - 示例:`cr --no-tips demos/calcit.cirru query def calcit.core/foldl`
12
- ```
13
-
14
- **背景**:`aa21b3a` 提交新增了 `--no-tips` 全局开关(`TIPS_SUPPRESSED: AtomicBool`,通过 `suppress_tips()` 设置),文档中缺少记录。
15
-
16
- ### 2. 新增 HOF 高阶函数回调类型检查说明
17
-
18
- 在「类型标注与检查 → 3. 支持的类型标签」之后,`约定:动态类型标注…` 注释的下方新增章节:
19
-
20
- **高阶函数(HOF)回调类型检查:**
21
- `foldl`、`sort`、`filter`、`find`、`find-index`、`filter-not`、`mapcat`、`group-by` 等内置 HOF 的回调参数已强制要求 `:fn` 类型,传入非函数值时预处理阶段会触发类型警告。附正/误示例。
22
-
23
- **背景**:`aa21b3a` 提交修复了以下两条路径的类型检查:
24
-
25
- - Cirru `defn` schema (`calcit-core.cirru`):`filter-not`/`find`/`find-index`/`foldl`/`foldl'`/`foldl-compare`/`mapcat`/`group-by`/`sort` 的回调参数由 `:dynamic` 改为 `:fn`(部分带泛型注解)
26
- - `ProcTypeSignature` (`proc_name.rs`):`Foldl`/`Sort`/`FoldlShortcut`/`FoldrShortcut` 的回调参数 `dynamic` → `some_fn()`/`optional_fn()`
27
-
28
- ## 知识点
29
-
30
- - **文档中不需要描述 `ProTypeSignature` 实现细节**,面向 Agent 只需说明行为:哪些 HOF 要求 `:fn` 参数。
31
- - **`--no-tips` 定位**:全局开关,放在 subcommand 前;所有 `Tips::print()` 调用均受其控制。
32
- - CalcitAgent.md 未发现旧 `-s/--stdin` 残留,无需清理。
@@ -1,5 +0,0 @@
1
- # add test-fail script
2
-
3
- - 在 `package.json` 中新增 `yarn test-fail`,用于日常单独执行 schema/type-fail 相关测试。
4
- - 该命令当前映射到 `cargo test -q --bin cr type_fail_`,覆盖 `src/bin/cr.rs` 中新增的 fixture 测试。
5
- - 更新 `calcit/type-fail/README.md`,补充 `yarn test-fail` 的使用说明。
@@ -1,8 +0,0 @@
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`
@@ -1,13 +0,0 @@
1
- # Profiling tools reorganization
2
-
3
- ## Summary
4
-
5
- - Moved profiling scripts from `scripts/` into dedicated `profiling/` directory.
6
- - Added `profiling/README.md` with end-to-end usage for xctrace and samply workflows.
7
- - Removed obsolete `scripts/profiling.sh` flamegraph helper script.
8
-
9
- ## Knowledge notes
10
-
11
- - Keep profiling tooling isolated under `profiling/` to reduce script namespace clutter.
12
- - `samply` profiling should run against built `target/*/cr` binaries to avoid sampling `rustc` compile threads.
13
- - Preserve `.tmp-profiles/` as transient output directory for trace artifacts.
@@ -1,87 +0,0 @@
1
- # 2026-03-17 下午至晚间改动总结(1739-2031)
2
-
3
- ## 总览
4
-
5
- - 时间段:`2026-0317-1739` 至 `2026-0317-2031`
6
- - 主要改动:测试减法、program/preprocess 架构减法、类型注解热路径优化、samply 验证、计划文档同步
7
-
8
- ## 关键变更(按时间顺序)
9
-
10
- ### 1) 测试减法(1739 / 1745)
11
-
12
- - 清理 `src/program/tests.rs` 中 helper/重复语义测试:
13
- - `runtime_snapshot_fallback_only_allows_runtime_only_defs`
14
- - `preprocess_ns_def_accepts_compiled_only_value_without_source_lookup`
15
- - 保留行为级回归用例,继续覆盖 snapshot/runtime-only 与 compiled-only 消费边界。
16
-
17
- ### 2) preprocess 推断逻辑去重(1751)
18
-
19
- - 文件:`src/runner/preprocess.rs`
20
- - 抽取 `infer_return_type_from_compiled_callable(...)`,统一 `Import`/`Symbol` 分支的 compiled callable 返回类型推断。
21
- - 保留 `Symbol` 分支对源码 tag 的回退解析行为。
22
-
23
- ### 3) program snapshot helper 内联(1753)
24
-
25
- - 文件:`src/program.rs`
26
- - 删除并内联单次用途 helper:
27
- - `collect_referenced_compiled_def_ids(...)`
28
- - `should_use_runtime_snapshot_fallback(...)`
29
- - 逻辑并入 `collect_snapshot_fill_tasks(...)` 与 `build_snapshot_fill_compiled_def(...)`。
30
-
31
- ### 4) 文档刷新 + 首轮热路径减法(1812)
32
-
33
- - 文件:`drafts/runtime-boundary-refactor-plan.md`
34
- - 修正过时描述:`run_program_with_docs` 现状与 preprocess 返回值关系。
35
- - 将阶段状态与 `samply` 观察、下一步优先级对齐。
36
- - 文件:`src/runner/preprocess.rs`
37
- - 去除 `drop_left` 中间列表分配。
38
- - `resolve_generic_return_type` 改为接收迭代器,调用处直接 `iter().skip(1)`。
39
-
40
- ### 5) materialize executable fast path(2012)
41
-
42
- - 文件:`src/program.rs`
43
- - `materialize_compiled_executable_payload(...)`:
44
- - `Proc | Syntax` 直接返回 `preprocessed_code`。
45
- - `Fn | Macro` 继续 `evaluate_expr` materialize。
46
- - `LazyValue | Value` 继续保持不可执行语义。
47
- - 删除无调用 helper:`with_compiled_executable_payload(...)`。
48
-
49
- ### 6) type-annotation 单次扫描收敛(2023)
50
-
51
- - 文件:`src/calcit/type_annotation.rs`
52
- - 在 `parse_fn_annotation_from_schema_form` 中引入 `collect_fn_schema_fields`,由多次 key 扫描改为一次遍历收集。
53
- - 删除无用 helper:`schema_has_any_field`。
54
-
55
- ### 7) schema key 热路径进一步减法(2031)
56
-
57
- - 文件:`src/calcit/type_annotation.rs`
58
- - 新增单 key 快路径:
59
- - `schema_key_matches(...)`
60
- - `extract_schema_value_single(...)`
61
- - 将常见单 key 查询点改为快路径:
62
- - `extract_return_type_from_hint_form`
63
- - `extract_generics_from_hint_form`
64
- - `extract_arg_types_from_hint_form`
65
- - 清理过渡遗留 helper:
66
- - `schema_key_matches_any(...)`
67
- - `extract_schema_value(...)`
68
-
69
- ## 验证汇总
70
-
71
- - 多轮定向测试均通过:
72
- - `cargo test -q program::tests`
73
- - `cargo test -q runner::preprocess::tests`
74
- - `cargo test -q calcit::type_annotation::tests`
75
- - 全量 Rust 测试持续通过:`cargo test -q`(会话末保持全绿)
76
- - 语义门禁持续通过:`yarn check-all`
77
-
78
- ## profiling 结论汇总
79
-
80
- - 使用既有流程:`profiling/samply-once.sh` + `profiling/samply-summary.py`
81
- - 在 materialize 目标链路过滤中,样本权重由 14 降至 7(单轮观测,方向符合预期)。
82
- - 在 schema-key 相关过滤中,基线 `fibo-release-iter5-20260317.samply` 为 21,本轮新采样 `fibo-release-20260317-203129.samply` 为 5,方向上显著下降。
83
-
84
- ## 本轮经验
85
-
86
- - 以“删 helper/删重复分支/删中间分配”为主线做减法,优先保证行为级测试覆盖。
87
- - 每次改动后固定执行“定向测试 → 全量 Rust → `yarn check-all`”可有效阻断语义回退。
@@ -1,26 +0,0 @@
1
- ## Summary
2
-
3
- This commit finalizes two CLI workflow improvements:
4
-
5
- 1. **Tips policy refactor**
6
- - Added `--tips-level` support (`minimal|full|none`) as a unified switch.
7
- - Kept `--tips` as a shortcut for full tips output.
8
- - Updated handlers so tips rendering is centralized and priority-aware.
9
- - Updated docs to align with the new default behavior (minimal, high-priority-first hints).
10
-
11
- 2. **`cr edit def --overwrite` metadata safety**
12
- - Fixed overwrite behavior to preserve existing definition metadata (`doc`, `examples`, `schema`).
13
- - Overwrite now updates only the `code` field when the definition already exists.
14
- - This avoids accidental schema loss during whole-definition rewrites.
15
-
16
- ## Files touched (high level)
17
-
18
- - CLI args and command wiring for tips level handling.
19
- - Query/tree/tips handler integration and output behavior updates.
20
- - `edit` handler overwrite logic for metadata-preserving updates.
21
- - Agent docs and advanced workflow docs reflecting the new tips model.
22
-
23
- ## Validation notes
24
-
25
- - Rust formatting/lint/tests were run during implementation iterations.
26
- - Manual end-to-end verification confirmed schema is retained after `--overwrite`.
@@ -1,72 +0,0 @@
1
- # Query 搜索结果分层、降噪与路径/预览优化(合并记录)
2
-
3
- ## 变更概述
4
-
5
- - 初始实现:为 `cr query` 搜索类命令引入结果分层展示(详情窗口 + 压缩输出)。
6
- - 参数命名收敛:将 `--prefer` 直接改为 `--detail-offset`(不保留兼容别名)。
7
- - 输出降噪:删除冗长提示,保留定位核心信息(定义、路径、命中片段)。
8
- - 路径统一:搜索输出与 `--start-path` 示例统一为点号分隔;解析层仅接受点号输入。
9
- - 详情窗口进一步从 5 缩小为 3,并在窗口内增加“所在表达式 + 父表达式”预览(可省略复杂父表达式)。
10
-
11
- ## 覆盖命令
12
-
13
- - `cr query find`
14
- - `cr query usages`
15
- - `cr query search`
16
- - `cr query search-expr`
17
-
18
- ## 关键实现
19
-
20
- - `src/cli_args.rs`
21
- - 参数字段统一为 `detail_offset`。
22
- - 参数统一为 `#[argh(option, long = "detail-offset", default = "0")]`。
23
- - 参数说明更新为“3 detailed items”。
24
- - `query search --start-path` 示例更新为点号格式 `2.1.0`。
25
-
26
- - `src/bin/cli_handlers/query.rs`
27
- - 结果窗口逻辑:
28
- - `DETAILED_RESULTS_WINDOW = 3`
29
- - `detailed_window(detail_offset, total)`
30
- - `in_detail_window(index, total, detail_offset)`
31
- - `print_detail_window_hint(...)`
32
- - 搜索结果降噪:
33
- - `search/search-expr` 按命中数排序定义(高命中优先)。
34
- - 详情行输出为 `[path] <preview>`;窗口外仅输出压缩条数(`N matches compressed outside window`)。
35
- - 移除 `Next steps`/批量替换等长提示块。
36
- - 预览增强:
37
- - 新增 `preview_node_oneline(...)` 并修复叶子节点空预览问题。
38
- - 新增 `path_parent(...)`、`get_node_at_path(...)`、`count_nodes_limited(...)`、`can_show_parent_preview(...)`、`expression_and_parent_preview(...)`。
39
- - 最终形态改为“单行预览”:优先显示父节点预览;无父节点时回退到当前表达式(避免重复展示两遍)。
40
-
41
- - Tips 与 exact 语义修正:
42
- - `--exact` 高优先级提示文案统一为英文:`Many matches (N); add --exact to show exact matches only`。
43
- - 仅在 contains 模式且命中数 `> 10` 时展示该提示;`--exact` 模式不再显示冗余提示。
44
- - 修复 exact 模式下的误导性高亮:只在 token 边界高亮,避免将 `states` 中的 `state` 误标为命中。
45
-
46
- - 命名收敛:将旧命名 `prefer` 在函数参数/调用链/提示文案中统一改为 `detail_offset` / `detail-offset`。
47
-
48
- - `src/bin/cli_handlers/common.rs`
49
- - `parse_path(...)` 改为仅接受点号分隔;逗号输入报错并提示改用点号。
50
-
51
- ## 降噪策略
52
-
53
- - 深度嵌套(路径过深)或分支复杂(节点过大)时,父表达式预览自动省略。
54
- - 详细窗口外仍然输出压缩占位,不展开上下文。
55
-
56
- ## 验证
57
-
58
- - `cargo check --bin cr` 通过。
59
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query find --help`
60
- - 可见 `--detail-offset` 参数。
61
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search --help`
62
- - `--start-path` 示例为点号格式。
63
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state --filter respo.app.comp.todolist/comp-todolist --detail-offset 5`
64
- - 输出降噪,路径为点号,窗口外压缩。
65
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state --filter respo.app.comp.todolist/comp-todolist --detail-offset 0`
66
- - 详情窗口为 `[0, 3)`,每条命中仅展示一行(优先父节点预览)。
67
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state --filter respo.app.comp.todolist/comp-todolist --detail-offset 0 --exact`
68
- - 精确命中不再把 `states` 视觉误判为 `state`;且不显示“add --exact”提示。
69
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search-expr state --filter respo.app.comp.todolist/comp-todolist --detail-offset 0`
70
- - 输出样式一致(单行预览)。
71
- - `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search-expr state --filter respo.app.comp.todolist/comp-todolist --detail-offset 0 --exact`
72
- - 结果为 `No matches found`,符合结构精确匹配预期。
@@ -1,71 +0,0 @@
1
- # Command Echo 主导的工具输出收敛与 tree replace 差异摘要
2
-
3
- ## 变更概述
4
-
5
- - 将 `cr` 的命令回显进一步固定为工具主语境:前置、单行、语义化参数展示。
6
- - 为工具型命令引入更安静的 runtime 输出模式,避免版本、模块目录、模块加载、平台 API 注册等噪音干扰结果读取。
7
- - 大范围清理 `docs/query/tree` 正文里对 `target/path/pattern/entry/deps` 的重复回显,统一交给 command echo 表达。
8
- - 修正 `docs/CalcitAgent.md` 中示意性 Cirru 代码块的检查模式,避免 `check-md` 将结构示例误判为 runnable 程序。
9
- - 单独重构 `tree replace` 输出:从“Preview + From/To”双份重复,改成“Changed node + Containing expression”的单次差异摘要。
10
-
11
- ## 关键实现
12
-
13
- - `src/bin/cr.rs`
14
- - 在启用 command echo 时同步启用 `calcit::set_quiet_tool_output(true)`。
15
- - 屏蔽工具模式下的运行环境提示:
16
- - `calcit version`
17
- - `module folder`
18
- - `stack trace disabled`
19
- - `running entry`
20
-
21
- - `src/lib.rs`
22
- - 新增全局 quiet flag:
23
- - `set_quiet_tool_output(...)`
24
- - `quiet_tool_output()`
25
- - `load_module(...)` 在工具模式下不再打印 `loading: ...`。
26
-
27
- - `src/bin/injection/mod.rs`
28
- - `inject_platform_apis()` 在工具模式下不再打印 `registered platform APIs`。
29
-
30
- - `src/bin/cli_handlers/docs.rs`
31
- - `docs check-md` 不再重复回显 `entry/deps`。
32
- - 移除只服务旧回显的路径展示 helper。
33
-
34
- - `src/bin/cli_handlers/query.rs`
35
- - 删除 `query def/peek/schema/examples/usages` 中重复的 target 标题。
36
- - 删除 `query search/search-expr` 中重复的 pattern/filter/entry/start-path 摘要。
37
- - `query find` 摘要从“重复 symbol”收敛为纯结果计数。
38
-
39
- - `src/bin/cli_handlers/tree.rs`
40
- - 删除 `tree show` 与多类 tree 写操作中的冗余 follow-up 命令提示。
41
- - 删除成功文案里重复的 `path/target/pattern` 回显。
42
- - `tree replace` 改为:
43
- - `✓ Replaced node`
44
- - `Changed node` 下单次展示 `Before/After`
45
- - 非 root path 额外展示 `Containing expression`,帮助快速看出修改落点。
46
-
47
- - `docs/CalcitAgent.md`
48
- - 将示意性代码块改成 `cirru.no-check`,避免 `docs check-md` 因不存在的符号或非独立程序片段失败。
49
-
50
- ## 输出策略结论
51
-
52
- - 输入参数语境:由 `Command: ...` 统一承担。
53
- - 正文输出:只保留结果、差异、结构上下文、或真正新增的信息。
54
- - 不再在正文里重复打印 command echo 已经覆盖的 target/path/pattern/entry/deps。
55
-
56
- ## 验证摘要
57
-
58
- - `cargo fmt`
59
- - `cargo run --bin cr -- calcit/test.cirru analyze js-escape 'demo?'`
60
- - `cargo run --bin cr -- calcit/test.cirru analyze js-unescape 'demo_$q_'`
61
- - `cargo run --bin cr -- calcit/test.cirru query ns app.main`
62
- - `cargo run --bin cr -- calcit/test.cirru query find render`
63
- - `cargo run --bin cr -- calcit/test.cirru tree show app.main/test-json --path ''`
64
- - `cargo run --bin cr -- calcit/test.cirru docs search chunk --filename agent-advanced.md`
65
- - `cargo run --bin cr -- demos/calcit.cirru docs check-md docs/CalcitAgent.md`
66
- - `cargo run --bin cr -- /tmp/calcit-cli-demo/calcit.cirru tree replace ...` 多次人工检查 replace 输出形态
67
-
68
- ## 经验
69
-
70
- - command echo 一旦语义化,就应把正文里的“参数再描述一遍”系统性删掉,否则会让工具输出看起来像教程而不是结果。
71
- - tree 类命令相比简单成功提示,更需要“差异摘要 + 所在表达式”,这样既不冗余,也能快速判断改动是否落在预期结构。
@@ -1,23 +0,0 @@
1
- # 2026-0410-0011 — 修复 snapshot `configs.version` 对 `||` 空字符串的漏判
2
-
3
- ## 背景
4
-
5
- PR `snapshot-format` 新增了空 `configs.version` 的回归测试,但 GitHub Actions 上加载运行时快照文件(`calcit.cirru` / legacy `compact.cirru`)时,`(:version ||)` 会解析成字符串 `"|"`,没有命中原先仅检查空白字符串的校验。
6
-
7
- ## 知识点
8
-
9
- - Cirru 的空字符串字面量 `||` 在这条解析路径里会落成 `"|"`,不能只靠 `trim().is_empty()` 判断是否为空。
10
- - `configs.version` 的校验要同时覆盖真正空串和这个 pipe marker,才能在加载阶段稳定报出 `configs.version cannot be empty`。
11
-
12
- ## 修改
13
-
14
- - `src/snapshot.rs`
15
- - 将 `parse_snapshot_config_string_field` 中 `version` 的空值判断扩展为:`text.trim().is_empty() || text == "|"`。
16
-
17
- ## 验证
18
-
19
- ```bash
20
- cargo fmt -- src/snapshot.rs
21
- ```
22
-
23
- 本地 `cargo test` 在当前机器仍受 macOS 链接器环境影响(`ld: library 'System' not found`),实际正确性改由 GitHub Actions 复核。
@@ -1,28 +0,0 @@
1
- # 202604160131 — WASM codegen 扩展: 数学函数 + 测试集成
2
-
3
- ## 新增 WASM 操作
4
-
5
- - `floor` → `f64.floor`
6
- - `ceil` → `f64.ceil`
7
- - `round` → `f64.nearest`
8
- - `sqrt` → `f64.sqrt`
9
- - `identical?` → `f64.eq`
10
- - `sin`/`cos`/`pow` 明确报错(WASM 无对应指令)
11
-
12
- ## 新增文件
13
-
14
- - `calcit/test-wasm.cirru` — 17 个纯数值函数测试(fibo, factorial, add-two, sum-range, floor, ceil, round, sqrt, rem, compare, not, let-chain, collatz-steps, gcd 等)
15
- - `scripts/test-wasm.sh` — WASM 验证脚本(生成 WAT → wasmtime compile → 逐函数验证返回值)
16
-
17
- ## 修改文件
18
-
19
- - `src/codegen/emit_wasm.rs` — 新增 `unary_op` 辅助函数, 添加 Floor/Ceil/Round/Sqrt/Identical 分支
20
- - `package.json` — `check-all` 加入 `try-wasm` 步骤; 新增 `try-wasm` 脚本
21
- - `docs/wasm-codegen.md` — 更新支持列表、测试说明、路线图
22
-
23
- ## 验证
24
-
25
- - `yarn check-all` 通过(含 compile, try-rs, try-js, try-ir, try-wasm)
26
- - `cargo test` 246/246 pass
27
- - `cargo clippy -- -D warnings` clean
28
- - wasmtime 逐函数验证: 17/17 assertions pass
@@ -1,27 +0,0 @@
1
- # 202604161507 - WASM 数据结构编译 & rfc 目录重命名
2
-
3
- ## rfc 目录整理
4
-
5
- - `drafts/` 重命名为 `rfc/`,所有文件加上 `MM-DD-` 创建日期前缀(从 git 历史提取)
6
- - README.md 更新为完整索引,补全之前遗漏的 5 个文件条目
7
- - Cargo.toml 中 `drafts/` 引用更新为 `rfc/`
8
-
9
- ## WASM 数据结构编译
10
-
11
- ### 新增能力
12
-
13
- - **Memory Section**: 1 页 64KB 线性内存,Global section 维护 `heap_ptr` 作为 bump allocator
14
- - **Tag 编译**: `collect_all_tags()` 在编译期为所有 tag 字面量分配整数 ID,运行时直接用 f64 表示
15
- - **Record 编译**: `emit_record_new()` 在堆上分配 `[struct_tag_id, field0, field1, ...]`,`emit_record_nth()` 通过偏移直接读取
16
- - **Tuple 编译**: `emit_tuple_new()` 在堆上分配 `[tag_id, payload0, payload1, ...]`,`emit_tuple_nth()` 直接读取
17
- - **静态结构解析**: `try_parse_defrecord_form()` 从源码 AST 静态提取 `defrecord` 的字段定义,不依赖运行时宏展开
18
-
19
- ### 关键设计决策
20
-
21
- - 全 f64 ABI:所有值(包括指针)用 f64 传递,需要 `i32.trunc_f64_u` / `f64.convert_i32_u` 转换
22
- - record 字段按字母序排列(与 Calcit runtime 一致)
23
- - bump allocator 不回收,适合短生命周期 WASM 模块
24
-
25
- ### 测试覆盖
26
-
27
- - 22 项 WASM 检查全部通过:17 个数值运算 + 2 个 tag 比较 + 2 个 record 求和 + 1 个 tuple 求和
@@ -1,21 +0,0 @@
1
- # 202604161520 - WASM 位运算 & match 语法编译
2
-
3
- ## 位运算 (bitwise operations)
4
-
5
- - 新增 `bit-and`, `bit-or`, `bit-xor`, `bit-not`, `bit-shl`, `bit-shr` 6 个 WASM 编译支持
6
- - 策略: f64 → i32 (trunc_f64_s) → 执行 i32 位运算 → i32 → f64 (convert_i32_s)
7
- - 使用有符号转换 (I32TruncF64S / F64ConvertI32S) 保持负数语义
8
-
9
- ## match 语法编译
10
-
11
- - 实现 `match` 表达式的 WASM codegen, 支持 enum tuple 模式匹配
12
- - 策略: 加载 tuple 的 tag_id (offset 0), 对各分支做嵌套 if/else 比较
13
- - 支持 tag 模式 `(:variant a b)` — 从 tuple 内存按偏移读取 payload 绑定到局部变量
14
- - 支持 wildcard `_` 作为 fallback 分支
15
- - 注意 block_depth 正确更新以保持 recur 分支跳转的一致性
16
-
17
- ## 测试覆盖
18
-
19
- - 31 项 WASM 检查全部通过 (原 22 + 6 bitwise + 3 match)
20
- - 246 cargo tests 通过 (179 + 67)
21
- - clippy 零警告
@@ -1,38 +0,0 @@
1
- # WASM: Cross-namespace calls & host imports (pow, sin, cos)
2
-
3
- ## 概要
4
-
5
- 为 WASM codegen 增加了跨命名空间函数调用和宿主函数导入两大功能。
6
-
7
- ## 知识点
8
-
9
- ### 跨命名空间调用
10
-
11
- - `emit_wasm()` 从只处理 `init_ns` 改为遍历 `program_data` 全部命名空间
12
- - `fn_defs` 从 3-tuple `(def, args, body)` 扩展为 4-tuple `(ns, def, args, body)`
13
- - `fn_index` 同时保存 `"ns/def"` 全限定名和 `"def"` 裸名两种键
14
- - `emit_call_expr` 中遇到 `Import` 节点时,先尝试全限定名再尝试裸名
15
- - `collect_all_tags` 更名为 `collect_all_tags_from` 适配 4-tuple
16
-
17
- ### 宿主函数导入 (Host Imports)
18
-
19
- - 新增 `HostImport` 结构体和 `HOST_IMPORTS` 常量数组(pow/sin/cos)
20
- - WASM 模块新增 `ImportSection`,从 `"math"` 模块导入函数
21
- - **关键约束**:导入函数占据函数索引 0..N,用户函数从 N 开始
22
- - TypeSection: 先写 host import 的类型, 再写 user function 的类型
23
- - FunctionSection: 只写 user function(import 自动拥有类型)
24
- - ExportSection / fn_index: 用户函数索引均需加 `num_imports` 偏移
25
- - `emit_host_call()` 辅助函数:按名称查找 HOST_IMPORTS 并发出 Call 指令
26
- - `CalcitProc::Sin/Cos/Pow` 从返回错误改为调用 `emit_host_call`
27
-
28
- ### 测试
29
-
30
- - `test-wasm.cirru` 新增 `test-wasm.helper` 命名空间(含 `add-and-double`)
31
- - `test-wasm.mjs` 新增 `math` 导入对象 + `checkApprox()` 浮点近似断言
32
- - 测试从 31 项增加到 39 项,全部通过
33
-
34
- ## 注意事项
35
-
36
- - WASM 规范要求 Import section 必须在 Function section 之前
37
- - 添加新 host import 时需更新 HOST_IMPORTS 数组,并确认 JS 测试 runner 提供对应实现
38
- - 后续可考虑将 host import 模块名参数化(目前硬编码 `"math"`)
@@ -1,62 +0,0 @@
1
- # WASM: 可变参数 (rest args) 支持
2
-
3
- ## 背景
4
-
5
- 此前 `(defn f (a b & xs) ...)` 形式的函数在 WASM codegen 中会直接报错
6
- "rest args not supported in WASM codegen" 而被跳过。这阻塞了 `calcit.core` 中
7
- `<`、`-`、`/`、`dissoc`、`exclude`、`intersection`、`difference`、
8
- `merge-non-nil`、`&str-spaced` 等大量可变参数函数的 WASM 编译。
9
-
10
- ## 实现
11
-
12
- 函数签名约定(匹配现有数据结构表示):
13
-
14
- - rest 参数表现为一个 f64 参数,承载一个 list 指针。
15
- - `(defn f (a b & xs) ...)` 的 WASM 签名是 `(a: f64, b: f64, xs: f64) -> f64`,
16
- 其中 `xs` 是调用方构造的 list 指针。
17
-
18
- 关键改动(全部在 `src/codegen/emit_wasm.rs`):
19
-
20
- 1. 新增 `compute_fn_arity(args) -> (wasm_arity, Option<rest_fixed>)`:
21
- 替代原来散落的 arity 计算,同时返回是否含 rest 以及固定参数数。
22
- 2. 新增 `fn_has_rest: HashMap<String, u32>`,记录每个有 rest 的函数的固定
23
- 参数数(`wasm_arity - 1`)。随 `fn_index` / `fn_arity` 一起在
24
- `compile_fn` 之前建好。
25
- 3. `WasmGenCtx` 新增 `fn_has_rest` 字段,与其他 lookup 表一起 clone 进上下文。
26
- 4. `compile_fn`:
27
- - 不再对 `CalcitArgLabel::RestMark` 报错。
28
- - 跳过 `RestMark` 本身,但把 `&` 后的 `Idx` 仍然作为一个普通 f64 参数
29
- 压入 `param_names`(它承载 list 指针)。
30
- 5. `emit_call_expr`:提取新助手 `emit_call_args`,根据 callee 是否有 rest
31
- 分两条路径:
32
- - 无 rest:照旧逐个 `emit_expr`,缺失的 optional 参数用 `f64_const(0.0)` 填补。
33
- - 有 rest:前 `fixed` 个参数照旧求值,多余参数调用 `emit_list_new` 打包
34
- 成 list 指针作为最后一个参数。
35
-
36
- ## 踩坑记录
37
-
38
- - **`bash scripts/test-wasm.sh` 用的是 release 产物,不是 `cargo run`**。改完
39
- Rust 代码后一定要 `cargo build --release --bin cr`,否则看到的仍是旧行为。
40
- 这次调试时一度以为 `collect-rest` 还会被跳过,源头是 release binary 陈旧。
41
- - `emit_list_new` 签名接受 `&[Calcit]`,直接传入 `&args_list[fixed..]`
42
- 就够用;不需要手动写 header/slot。
43
-
44
- ## 测试
45
-
46
- 新增 `calcit/test-wasm.cirru` 三个用例:
47
-
48
- - `test-rest-count`:`collect-rest 1 2 3 4` 返回的 list 长度为 3。
49
- - `test-rest-sum`:`sum-rest 1 2 3 4 5 = 15`,验证打包 list 后由被调函数
50
- 通过 `&list:first` / `&list:rest` / `recur` 逐项展开并求和。
51
- - `test-rest-empty`:`sum-rest 10 20 = 30`,验证没有额外参数时 list 为空。
52
-
53
- `scripts/test-wasm.mjs` 对应 3 条 `check(...)`。`yarn check-all` 全绿。
54
-
55
- ## 遗留
56
-
57
- 尚未支持的 WASM 功能(下一步继续攻克):
58
-
59
- - `type-of`、各类 `xxx?` 谓词(需要运行时类型标记,难度较大)。
60
- - `foldl` / `foldl-shortcut`(依赖闭包或函数指针)。
61
- - 嵌套 `defn` / 闭包。
62
- - 字符串字面量和字符串操作。