@calcit/procs 0.12.55 → 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 (161) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/RFCs/07-31-unsafe-coerce-driven-static-type-boundary-plan.md +170 -0
  3. package/build.rs +36 -2
  4. package/editing-history/202607310224-strengthen-namespace-import-diagnostics.md +23 -0
  5. package/editing-history/202607311940-strengthen-unsafe-coerce-boundaries.md +20 -0
  6. package/editing-history/202608010103-warn-on-duplicate-imports.md +18 -0
  7. package/editing-history/202608010111-release-0.12.56.md +15 -0
  8. package/editing-history/202608011654-library-quality-gates.md +23 -0
  9. package/editing-history/202608011759-issue-routing-in-agent-guide.md +17 -0
  10. package/editing-history/202608011833-schema-type-symbols.md +20 -0
  11. package/editing-history/202608011852-wasm-dynamic-string-tag.md +7 -0
  12. package/editing-history/202608011908-consolidate-history.md +6 -0
  13. package/editing-history/202608012022-consolidate-cli-and-test-duplication.md +28 -0
  14. package/editing-history/202608012123-review-follow-up.md +18 -0
  15. package/editing-history/202608012320-release-0.12.57.md +5 -0
  16. package/editing-history/ARCHIVE.md +15 -0
  17. package/editing-history/README.md +21 -0
  18. package/lib/package.json +1 -1
  19. package/package.json +1 -1
  20. package/editing-history/2026-02-13-1841-trait-origin-structural-eq.md +0 -91
  21. package/editing-history/2026-02-14-2050-js-codegen-recursion-tag-migration.md +0 -39
  22. package/editing-history/2026-02-14-2358-emit-js-modularization-shift-left.md +0 -63
  23. package/editing-history/2026-02-15-0000-diagnostics-consolidated.md +0 -35
  24. package/editing-history/2026-02-15-1941-macro-diagnostics-refinement.md +0 -39
  25. package/editing-history/2026-02-16-2043-core-api-docs-cleanup.md +0 -40
  26. package/editing-history/2026-02-23-0834-migrate-to-defstruct.md +0 -91
  27. package/editing-history/2026-02-23-2321-ns-imports-code-fixes.md +0 -42
  28. package/editing-history/2026-02-25-0002-language-behavior-eval-mode.md +0 -93
  29. package/editing-history/2026-02-25-0111-guidebook-no-check-block-upgrades.md +0 -52
  30. package/editing-history/2026-02-25-0113-runtime-type-validation-and-macro-quoting.md +0 -41
  31. package/editing-history/2026-02-25-1131-check-md-eval-improvements.md +0 -13
  32. package/editing-history/2026-02-26-1324-check-md-inprocess-cache-and-path-labels.md +0 -7
  33. package/editing-history/2026-02-27-1640-unify-markdown-readers.md +0 -16
  34. package/editing-history/2026-02-27-1958-tree-rewrite-command-and-reference-model.md +0 -18
  35. package/editing-history/2026-02-27-2200-split-def-command.md +0 -29
  36. package/editing-history/2026-02-27-2212-tree-raise-wrap.md +0 -33
  37. package/editing-history/2026-02-27-2223-calcit-agent-docs-optimize.md +0 -41
  38. package/editing-history/2026-03-01-0212-query-search-entry-and-ffi-warning.md +0 -53
  39. package/editing-history/2026-03-03-1934-check-types-and-core-annotations.md +0 -17
  40. package/editing-history/2026-03-04-0000-generics-fn-typevar-identity.md +0 -30
  41. package/editing-history/2026-03-04-1331-tag-call-warning-and-dot-access-migration.md +0 -28
  42. package/editing-history/2026-03-04-1548-impl-new-dot-method-input-and-doc-hints.md +0 -33
  43. package/editing-history/2026-03-04-1645-calcit-eq-contract-refactor-and-macro-tests.md +0 -28
  44. package/editing-history/2026-03-04-2200-assert-type-assert-traits-composable-runtime-checks.md +0 -18
  45. package/editing-history/2026-03-05-0042-type-inference-argtypes-and-core-hints.md +0 -54
  46. package/editing-history/2026-03-05-0115-calcit-core-generic-refinements.md +0 -57
  47. package/editing-history/2026-03-05-1930-schema-migration-cr-edit.md +0 -30
  48. package/editing-history/2026-03-05-1939-query-schema-adaptation.md +0 -42
  49. package/editing-history/2026-03-06-0120-schema-hint-migration-batch.md +0 -38
  50. package/editing-history/2026-03-06-1416-core-macro-schema-migration.md +0 -20
  51. package/editing-history/2026-03-06-1552-core-schema-and-hintfn-migration.md +0 -63
  52. package/editing-history/2026-03-06-1936-schema-normalization-and-preprocess-preload.md +0 -12
  53. package/editing-history/2026-03-07-0000-migrate-hint-fn-to-schema.md +0 -29
  54. package/editing-history/2026-03-07-0000-remove-enum-prototype-field.md +0 -43
  55. package/editing-history/2026-03-07-0000-schema-args-type-enforcement.md +0 -66
  56. package/editing-history/2026-03-07-0142-unit-type-and-builtin-schemas.md +0 -82
  57. package/editing-history/2026-03-07-1652-decouple-snapshot-schema-to-calcit-type.md +0 -112
  58. package/editing-history/2026-03-07-1821-snapshot-schema-validation.md +0 -6
  59. package/editing-history/2026-03-07-1959-schema-def-kind-arity-validation.md +0 -96
  60. package/editing-history/2026-03-08-0031-schema-generics-quote-normalization.md +0 -35
  61. package/editing-history/2026-03-08-1905-schema-typeref-and-assert-migration.md +0 -34
  62. package/editing-history/2026-03-08-2033-schema-wrapper-migration.md +0 -45
  63. package/editing-history/2026-03-08-2315-late-schema-cleanup-and-warning-compat.md +0 -27
  64. package/editing-history/2026-03-09-1753-schema-type-fail-tests.md +0 -17
  65. package/editing-history/2026-03-10-1040-edit-schema-primitive-tag-support.md +0 -42
  66. package/editing-history/2026-03-10-1754-ns-entry-snapshot-migration.md +0 -66
  67. package/editing-history/2026-03-13-2216-validate-struct-type-arg-arity.md +0 -24
  68. package/editing-history/2026-03-16-2353-runtime-boundary-cleanup.md +0 -14
  69. package/editing-history/2026-03-17-0150-runtime-boundary-lookup-cleanup.md +0 -28
  70. package/editing-history/2026-03-20-0116-json-builtins-and-runtime-docs.md +0 -48
  71. package/editing-history/2026-03-26-2013-docs-frontmatter-and-module-search.md +0 -58
  72. package/editing-history/2026-04-07-1550-path-format-at-prefix-migration.md +0 -46
  73. package/editing-history/2026-04-12-1524-js-codegen-map-to-record.md +0 -26
  74. package/editing-history/2026-04-12-1549-map-to-record-field-validation.md +0 -29
  75. package/editing-history/2026-04-13-1600-tuple-to-enum-rewrite.md +0 -13
  76. package/editing-history/2026-04-13-2309-typeslot-enum-compile-safety.md +0 -45
  77. package/editing-history/2026-04-14-1500-loose-record-syntax.md +0 -32
  78. package/editing-history/2026-04-14-2259-bidir-type-check-refactor.md +0 -63
  79. package/editing-history/2026-04-15-0120-match-syntax-exhaustiveness.md +0 -20
  80. package/editing-history/2026-04-15-1211-record-nth-optimization.md +0 -44
  81. package/editing-history/2026-04-16-1936-predicate-narrowing-expansion.md +0 -31
  82. package/editing-history/2026-04-17-0132-monomorphize-map-filter.md +0 -50
  83. package/editing-history/2026-04-17-0135-monomorphize-includes-reverse.md +0 -31
  84. package/editing-history/2026-04-17-0140-fold-type-predicates.md +0 -44
  85. package/editing-history/2026-04-17-0154-generic-dispatch-records-tuples.md +0 -52
  86. package/editing-history/2026-04-17-0520-simplify-generic-defns-via-method-dispatch.md +0 -49
  87. package/editing-history/2026-05-21-0055-tree-show-cr-config-and-edit-cleanup.md +0 -81
  88. package/editing-history/2026-05-31-2052-macro-schema-roundtrip-and-weak-types.md +0 -6
  89. package/editing-history/2026-05-31-2105-map-generic-weak-types-followup.md +0 -15
  90. package/editing-history/2026-06-01-0003-update-callback-field-specialization.md +0 -19
  91. package/editing-history/2026-06-01-2317-data-definition-where-bounds.md +0 -6
  92. package/editing-history/2026-06-02-0114-data-definition-where-macro-followup.md +0 -21
  93. package/editing-history/2026-06-03-0000-check-md-edn-errors.md +0 -5
  94. package/editing-history/2026-06-03-1600-check-md-entry-modules.md +0 -6
  95. package/editing-history/2026-06-04-0000-check-md-app-main-init.md +0 -6
  96. package/editing-history/2026-06-04-2218-compiled-executable-runtime-backfill.md +0 -6
  97. package/editing-history/2026-06-09-0000-with-type-slot-scoped-binding.md +0 -83
  98. package/editing-history/2026-06-09-1241-remove-bind-type.md +0 -64
  99. package/editing-history/2026-06-09-1800-core-effect-tags.md +0 -57
  100. package/editing-history/2026-06-10-1200-get-def-doc-schema-builtin.md +0 -7
  101. package/editing-history/2026-06-15-1500-effects-graph-mvp.md +0 -30
  102. package/editing-history/2026-06-16-1700-effects-graph-ste-tree.md +0 -84
  103. package/editing-history/2026-06-27-0052-cli-improvements.md +0 -41
  104. package/editing-history/2026-06-27-0202-docs-indexing-improvements.md +0 -22
  105. package/editing-history/2026-06-27-0315-file-splits.md +0 -17
  106. package/editing-history/2026-06-27-0416-agent-advanced-split.md +0 -15
  107. package/editing-history/archived/2025-04-12-1453-map-to-record-rewrite.md +0 -33
  108. package/editing-history/archived/2025-04-16-0117-wasm-codegen-and-catalog-update.md +0 -40
  109. package/editing-history/archived/2025-07-16-0207-wasm-encoder-migration.md +0 -48
  110. package/editing-history/archived/2025-07-16-1633-wasm-data-structures.md +0 -61
  111. package/editing-history/archived/2026-02-13-1926-docs-tests-followup.md +0 -33
  112. package/editing-history/archived/2026-02-16-2128-docs-smoke-and-trait-errors.md +0 -20
  113. package/editing-history/archived/2026-02-25-1234-watch-mode-default-once.md +0 -5
  114. package/editing-history/archived/2026-03-07-1302-calcit-agent-docs-update.md +0 -32
  115. package/editing-history/archived/2026-03-09-1819-add-test-fail-script.md +0 -5
  116. package/editing-history/archived/2026-03-09-1944-split-type-fail-tests.md +0 -8
  117. package/editing-history/archived/2026-03-16-1449-profiling-tools-reorg.md +0 -13
  118. package/editing-history/archived/2026-03-17-2026-afternoon-runtime-boundary-optimization-summary.md +0 -87
  119. package/editing-history/archived/2026-03-18-1802-tips-level-and-overwrite-schema-preservation.md +0 -26
  120. package/editing-history/archived/2026-03-20-1229-query-window-3-with-parent-preview.md +0 -72
  121. package/editing-history/archived/2026-03-23-1137-command-echo-tool-output-cleanup.md +0 -71
  122. package/editing-history/archived/2026-04-10-0011-snapshot-empty-version-pipe-marker.md +0 -23
  123. package/editing-history/archived/2026-04-16-0131-wasm-math-and-test-integration.md +0 -28
  124. package/editing-history/archived/2026-04-16-1507-wasm-data-structures-and-rfc-rename.md +0 -27
  125. package/editing-history/archived/2026-04-16-1520-wasm-bitwise-and-match.md +0 -21
  126. package/editing-history/archived/2026-04-16-1542-wasm-cross-ns-host-imports.md +0 -38
  127. package/editing-history/archived/2026-04-17-0026-wasm-rest-args.md +0 -62
  128. package/editing-history/archived/2026-04-17-0048-wasm-type-of.md +0 -70
  129. package/editing-history/archived/2026-04-17-0051-wasm-derived-predicates.md +0 -34
  130. package/editing-history/archived/2026-04-17-2316-wasm-do-println-fixes.md +0 -41
  131. package/editing-history/archived/2026-04-18-1208-split-emit-wasm-and-bump-version.md +0 -15
  132. package/editing-history/archived/2026-04-18-1430-wasm-list-match-and-method-dispatch.md +0 -5
  133. package/editing-history/archived/2026-04-18-2041-cr-wasm-split-and-runtime-stability.md +0 -18
  134. package/editing-history/archived/2026-04-18-2045-v0.12.23-ci-wasm-fix.md +0 -13
  135. package/editing-history/archived/2026-04-21-1818-wasm-string-ops-v2.md +0 -57
  136. package/editing-history/archived/2026-04-21-2332-split-emit-wasm.md +0 -45
  137. package/editing-history/archived/2026-04-22-0114-wasm-hof-intercepts-and-set-intersection.md +0 -82
  138. package/editing-history/archived/2026-04-22-0136-wasm-enum-tuple-bool-str-fixes.md +0 -68
  139. package/editing-history/archived/2026-04-22-1340-wasm-map-diff-new-and-let-intercept.md +0 -53
  140. package/editing-history/archived/2026-04-23-1419-v0.12.26-wasm-bisection-fixes.md +0 -7
  141. package/editing-history/archived/2026-04-23-1645-release-conventions.md +0 -14
  142. package/editing-history/archived/2026-04-25-1940-wasm-suite-multi-module-entry.md +0 -53
  143. package/editing-history/archived/2026-04-25-2003-wasm-method-includes-string-and-set-refactor.md +0 -71
  144. package/editing-history/archived/2026-04-25-2010-wasm-suite-add-fn-lens-edn.md +0 -43
  145. package/editing-history/archived/2026-04-25-2051-display-by.md +0 -39
  146. package/editing-history/archived/2026-04-28-1728-fix-gensym-stable.md +0 -31
  147. package/editing-history/archived/2026-04-29-1400-fix-bind-type-precompile.md +0 -38
  148. package/editing-history/archived/2026-05-26-0957-match-docs-check-md.md +0 -24
  149. package/editing-history/archived/2026-05-31-2059-ci-docs-test-and-fn-helper-tightening.md +0 -3
  150. package/editing-history/archived/2026-06-01-0005-release-0.12.36.md +0 -16
  151. package/editing-history/archived/2026-06-01-2230-enum-struct-payload-docs.md +0 -4
  152. package/editing-history/archived/2026-06-03-1620-release-0.12.38.md +0 -6
  153. package/editing-history/archived/2026-06-04-0000-release-0.12.39.md +0 -4
  154. package/editing-history/archived/2026-06-04-2230-release-0.12.40.md +0 -5
  155. package/editing-history/archived/2026-06-12-1525-weak-types-dots-format.md +0 -15
  156. package/editing-history/archived/2026-06-13-1200-primitive_schema_tags.md +0 -9
  157. package/editing-history/archived/2026-06-20-1142-ts-declaration-d-mts.md +0 -5
  158. package/editing-history/archived/2026-06-29-0117-upgrade-doc-snapshot-migration.md +0 -2
  159. package/editing-history/archived/2026-06-29-calcit-cli.md +0 -80
  160. package/editing-history/archived/2026-06-29-typed-calcit-cli-schemas.md +0 -23
  161. package/editing-history/archived/20260630-duplication-analysis.md +0 -116
@@ -1,24 +0,0 @@
1
- # 2026-03-13 22:16 validate struct type arg arity
2
-
3
- ## 背景
4
-
5
- 发现类型注解里可以写出 `:: Pair :number :string` 这样的形式,即使 `Pair` 是非泛型 `defstruct`。旧逻辑会把后续类型参数直接附着到 `Struct(...)` 注解上,但并不会校验 `generics` 个数,最终在值匹配时只看 struct 名字,导致漏检。
6
-
7
- ## 本次修改
8
-
9
- - 在 `src/calcit/type_annotation.rs` 为 `CalcitTypeAnnotation` / `CalcitFnTypeAnnotation` 增加 `validate_applied_type_args()`。
10
- - 对 `Struct` 注解增加规则:
11
- - 非泛型 struct 不允许携带类型参数;
12
- - 泛型 struct 必须严格匹配声明的类型参数个数。
13
- - 对 `Enum` 注解增加保守规则:当前不接受额外类型参数。
14
- - 在 `src/builtins/records.rs` 中,`defstruct` 字段类型解析后立即做校验。
15
- - 在 `src/calcit/sum_type.rs` 中,`defenum` payload 类型解析后立即做校验。
16
- - 在 `src/calcit/sum_type.rs` 与 `src/calcit/type_annotation.rs` 补充回归测试,覆盖:
17
- - 非泛型 struct 带类型参数时报错;
18
- - 泛型 struct 类型参数个数不匹配时报错;
19
- - enum payload 中引用非法 struct 类型注解时报错。
20
- - 同时修正 `calcit/test-generics.cirru` 中 `Wrapped` 的 payload 类型,把错误的 `:: Pair :number :string` 改为 `Pair`。
21
-
22
- ## 结论
23
-
24
- 现在像 `:: Pair :number :string` 这种写法不会再静默通过;定义期就会被校验出来,避免文档和测试继续误导后续修改。
@@ -1,14 +0,0 @@
1
- # Runtime Boundary Cleanup
2
-
3
- ## Summary
4
-
5
- - removed the dead `CalcitImport.coord` compatibility path and the related runner parameter flow
6
- - renamed remaining `evaled`-era runtime lookup terminology to `runtime-ready` / `runtime cache`
7
- - synced the runtime boundary refactor draft with the current migration state and recent cleanup progress
8
-
9
- ## Knowledge
10
-
11
- - `CalcitImport.def_id` is now the stable import-side runtime lookup anchor; the old `coord -> EntryBook` path no longer needs to be preserved in import metadata
12
- - type-annotation lookup registration should describe runtime-ready value lookup, not the removed evaled-store model
13
- - incremental reload messaging should talk about clearing runtime caches rather than evaled states to match the current architecture
14
- - this migration tail is now mostly about narrowing fallback bridges and improving reload coverage, not about preserving old runtime naming or lookup compatibility
@@ -1,28 +0,0 @@
1
- # Runtime boundary lookup cleanup
2
-
3
- ## Summary
4
-
5
- - Consolidated runtime-vs-compiled lookup helpers inside `program` and removed extra `runner` bridging paths.
6
- - Tightened snapshot fallback and codegen metadata lookup so source-backed defs no longer silently rely on runtime-derived compiled entries.
7
- - Skipped runtime-only placeholder defs in JS/IR codegen and added program-level regression tests for reload invalidation and snapshot behavior.
8
- - Reframed the runtime-boundary draft into a closure plan focused on stabilizing compiled/runtime boundaries, adding watch-reload regression coverage, and avoiding new architectural layers.
9
- - Simplified `runner` and `preprocess` lookup flow by removing thin wrappers, deduplicating repeated symbol fallback order, and collapsing silent program-value reads onto shared helpers.
10
- - Added regression coverage for reload package clearing, source-backed snapshot rebuild after changes, compiled fallback cache behavior, and strict-vs-lenient runtime resolution semantics.
11
-
12
- ## Knowledge points
13
-
14
- - Runtime execution helpers should live in `program` so `runner` only maps runtime state to evaluation flow and user-facing errors.
15
- - Metadata queries such as codegen type hints should prefer compiled/source schema and only fall back to ready runtime values, never by executing compiled payloads.
16
- - Reload invalidation needs direct transitive-dependency tests plus namespace-header coverage; otherwise runtime cache cleanup regresses quietly.
17
- - If compiled execution is used as a fallback read path, tests must assert it does not implicitly backfill runtime cells; otherwise compiled/runtime boundaries drift back together.
18
- - Keep cleanup work biased toward removing duplicate lookup order and unused parameters before introducing any new abstraction; the stable payoff is clearer boundaries with lower entity count.
19
- - `runner`-side error mapping for strict runtime resolution is still a meaningful boundary, but repeated namespace lookup order and required-value program reads can be shared safely.
20
-
21
- ## Validation
22
-
23
- - `cargo fmt`
24
- - release fibo profiling during optimization review
25
- - `cargo test clear_runtime_caches_for_reload -- --nocapture`
26
- - `cargo test snapshot_rebuilds_changed_source_backed_def_after_reload_changes -- --nocapture`
27
- - `cargo test program::tests -- --nocapture`
28
- - `cargo test -q`
@@ -1,48 +0,0 @@
1
- ## Summary
2
-
3
- This commit moves JSON parsing and serialization into Calcit builtins and aligns the surrounding runtime/docs/tooling updates needed to ship it cleanly.
4
-
5
- 1. Added builtin JSON runtime functions
6
-
7
- - Introduced `json-parse`, `json-stringify`, and `json-pretty` in Rust builtin dispatch and JS runtime exports.
8
- - Added fast arity/type checks on exposed runtime entry points.
9
- - Normalized integer-valued numbers to encode as JSON integers in Rust, matching JS output.
10
- - Added native tests and Calcit-level coverage for parse/stringify/pretty behavior and error paths.
11
-
12
- 2. Updated core docs and runtime placeholder naming
13
-
14
- - Added `calcit.core` docs/examples for the JSON runtime functions.
15
- - Renamed the runtime placeholder spelling from `runtime-inplementation` to `runtime-implementation` across core snapshot metadata and Rust handling.
16
- - Preserved an explicit `cr <snapshot-file> edit format` example in `docs/CalcitAgent.md`.
17
-
18
- 3. Snapshot formatting workflow
19
-
20
- - Re-ran `cr edit format` against the touched Cirru snapshot files:
21
- - `src/cirru/calcit-core.cirru`
22
- - `calcit/test.cirru`
23
-
24
- ## Files touched (high level)
25
-
26
- - Rust builtin registration and implementation for JSON runtime support.
27
- - JS runtime proc exports for JSON behavior and validation.
28
- - Calcit core snapshot docs/examples and test snapshot updates.
29
- - CLI/codegen placeholder spelling cleanup.
30
- - Agent guide example for `edit format`.
31
-
32
- ## Validation notes
33
-
34
- - `cargo test json_`
35
- - `cargo test validate_runtime_impl_is_skipped -- --nocapture`
36
- - `cargo test runtime_placeholder -- --nocapture`
37
- - `cargo run --bin cr -- calcit/test.cirru -1`
38
- - `yarn check-all`
39
-
40
- ## Release size check
41
-
42
- Measured `target/release/cr` against `HEAD` using a detached worktree build:
43
-
44
- - Current: `5192960` bytes (`5.0M`)
45
- - Base: `5174400` bytes (`4.9M`)
46
- - Delta: `+18560` bytes (about `+18.1 KiB`)
47
-
48
- Conclusion: the builtin JSON work increases the release binary size slightly, but the delta is small relative to the ~5 MB target.
@@ -1,58 +0,0 @@
1
- # Docs frontmatter 与模块检索整理
2
-
3
- ## 变更概述
4
-
5
- - 为 `cr docs search/read/read-lines` 增加 `scope/module` 维度,支持核心文档、模块文档和跨域检索。
6
- - 为 core docs 建立统一的 frontmatter 规范,并补充 `title/scope/kind/category/aliases/entry_for` 元数据。
7
- - 将 `docs` 检索逻辑从纯文件名匹配升级为结合 frontmatter、路径、标题与条目词的综合解析与排序。
8
- - 给文档系统补充规范页与验证页,方便后续扩展 `cr docs` 时保持行为稳定。
9
- - 调整 Cirru 校验错误提示,让“其实是字符串”的场景给出更直接的修复建议。
10
-
11
- ## 关键实现
12
-
13
- - `src/cli_args.rs`
14
- - 为 `docs search`、`docs read`、`docs read-lines` 增加 `--scope`、`--module` 参数。
15
-
16
- - `src/bin/cli_handlers/command_echo.rs`
17
- - 同步回显新增 docs 参数,确保工具模式下能看到完整检索上下文。
18
-
19
- - `src/bin/cli_handlers/docs.rs`
20
- - 引入 `GuideDocFrontmatter`、`GuideDocScope`、`DocsSearchScope`。
21
- - 支持解析 Markdown frontmatter,并在加载时校验 `category`。
22
- - 支持从 core docs 与 `~/.config/calcit/modules/<module>/docs/` 同时加载文档。
23
- - 统一 `search/read/read-lines` 的查询解析逻辑,允许通过文件名、路径片段、标题、`aliases`、`entry_for` 命中目标。
24
- - 增加更偏向 guide/reference 页的排序策略,减少 spec/索引页抢占结果。
25
- - 抽出 `match_score`、`accumulate_match_score`、`parse_guide_doc` 等辅助函数,压缩主文件重复逻辑。
26
-
27
- - `src/bin/cli_handlers/docs_tests.rs`
28
- - 将 docs 相关测试从 `docs.rs` 拆出,单独维护解析、排序、模块加载与校验场景。
29
-
30
- - `docs/docs-indexing.md`
31
- - 固化 frontmatter 字段、分类注册表、scope 布局与 authoring 约束。
32
-
33
- - `docs/docs-validation.md`
34
- - 记录 `cr docs` 的可执行回归命令,覆盖 `search/read/read-lines` 与 module scope。
35
-
36
- - `src/bin/cli_handlers/cirru_validator.rs`
37
- - 当 token 更像“应写成字符串的文本”时,提示使用 `|text` 或 `"|text with spaces"`,减少样式值与括号文本误写的排查成本。
38
-
39
- ## 文档整理原则
40
-
41
- - `category` 只允许稳定注册值,避免搜索元数据失控膨胀。
42
- - `aliases` 主要承接用户会直接输入的别名或术语,`entry_for` 主要承接命令/API/任务入口。
43
- - `Agents.md` 与普通 docs 页复用同一套 frontmatter 机制,但渲染时默认隐藏元数据正文。
44
- - 模块领域知识保留在模块 docs 中,Calcit core 只提供通用索引与加载能力,不内置 Respo 特殊语义。
45
-
46
- ## 验证
47
-
48
- - `cargo fmt`
49
- - `cargo test docs --bin cr`
50
- - 手动验证:
51
- - `cargo run --bin cr -- docs search target-replace`
52
- - `cargo run --bin cr -- docs search 'cr eval'`
53
- - `cargo run --bin cr -- docs read polymorphism.md`
54
-
55
- ## 后续经验
56
-
57
- - docs 元数据一旦进入 CLI 行为,就应该配套规范页与验证页,否则后续加字段很容易出现“文档能写、检索却不稳定”的分叉。
58
- - 模块文档检索要尽量和 core docs 走同一套 resolver,这样使用者不需要记两套命令心智模型。
@@ -1,46 +0,0 @@
1
- ## Path format migration: `@` prefix for display paths
2
-
3
- ### What changed
4
-
5
- All display-level Cirru tree paths now use `@` prefix notation when rendered to user.
6
-
7
- ### Display format change
8
-
9
- - `1.2.3.4` → `@1.2.3.4` (bare path)
10
- - `[1.2.3.4]` → `[@1.2.3.4]` (bracketed path)
11
- - `NodeLocation::Display` now outputs `ns/def [@1.2.3]` instead of `ns/def [1.2.3]`
12
-
13
- ### Backward compatibility
14
-
15
- - `parse_path()` strips leading `@` if present, so CLI input still accepts both `@1.2.3` and `1.2.3`
16
- - Error messages and help text updated to show `@` format
17
-
18
- ### Files modified
19
-
20
- **Core functions:**
21
-
22
- - `src/bin/cli_handlers/common.rs`: `format_path()` returns `@1.2.3`; `parse_path()` strips `@` prefix; test assertions updated
23
- - `src/calcit.rs`: `NodeLocation::Display` outputs `[@1.2.3]`; test assertion updated
24
- - `src/bin/cli_handlers/cirru_validator.rs`: local `format_path()` updated
25
- - `src/type_coverage.rs`: `format_cirru_path()` updated
26
- - `src/bin/cli_handlers/chunk_display.rs`: `compare_coords()` strips `@`; test `fragment()` helper uses `@`
27
- - `src/runner/preprocess/mod.rs`: `[&inspect-type]` debug output uses `@`
28
-
29
- **Tree/edit handlers:**
30
-
31
- - `src/bin/cli_handlers/tree.rs`: inline path formatting in swap handler
32
- - `src/bin/cli_handlers/edit.rs`: error message example
33
- - `src/cli_args.rs`: help text examples (3 locations)
34
-
35
- **Documentation:**
36
-
37
- - `docs/CalcitAgent.md`: 19 path examples updated
38
- - `docs/run/agent-advanced.md`: 23 path examples updated
39
- - `docs/run/edit-tree.md`: 6 path examples updated
40
- - `docs/Respo-Agent.md` (respo project): 26 path examples updated
41
-
42
- ### Why
43
-
44
- - `@` prefix helps LLMs distinguish path coordinates from other dotted numeric patterns (like version numbers or floats)
45
- - `@` is safe in shell (no escaping needed)
46
- - All display output now consistent with `@` prefix
@@ -1,26 +0,0 @@
1
- # JS Codegen Fix for Map-to-Record Rewrite
2
-
3
- ## Problem
4
- The map-to-record rewrite (from previous commit) inserted `Calcit::Struct` directly into the AST. The interpreter handles this, but JS codegen (`emit_js.rs` line 319) has no arm for `Calcit::Struct` → panics with `unreachable!`.
5
-
6
- ## Key Insight
7
- The `%{}` macro normally expands to `&%{}` with a **symbol/import reference** as the first arg (not a literal `Calcit::Struct`). JS codegen relies on this — it emits the symbol as a variable reference (e.g., `Element`), and the JS runtime `_$n__PCT__$M_` function accepts the struct object at runtime.
8
-
9
- ## Solution
10
- 1. Added `resolve_to_struct_with_ref()` to `CalcitTypeAnnotation` — returns `Option<(CalcitStruct, Option<(Arc<str>, Arc<str>)>)>` with ns/def path from TypeRef annotations.
11
- 2. Modified `try_rewrite_single_map_to_record()` to emit `Calcit::Import(CalcitImport { ... })` instead of `Calcit::Struct`:
12
- - `ImportInfo::SameFile` when struct is in same namespace (avoids self-import duplicate declaration)
13
- - `ImportInfo::NsReferDef` when struct is in a different namespace (generates proper cross-ns import)
14
- - Falls back to `Calcit::Struct` only when no ns/def path is available
15
-
16
- ## Pitfall: Self-Import Duplicate Declaration
17
- First attempt used `NsReferDef` for all imports — caused `SyntaxError: Identifier 'Point2D' has already been declared` because a self-import was generated when struct is in same namespace. Fix: detect `ns == file_ns` and use `SameFile`.
18
-
19
- ## Verification in Respo
20
- - Typed `element->string` as `'respo.schema/Element`, `make-string` as `'respo.schema/Component`
21
- - Test passes `{}` map to `element->string` → auto-rewritten to `%{} Element ...` record construction
22
- - Generated JS: `import { Element } from "./respo.schema.mjs"` + `$clt._$n__PCT__$M_(Element, ...)`
23
-
24
- ## Files Changed
25
- - `src/calcit/type_annotation.rs`: Added `resolve_to_struct_with_ref()`
26
- - `src/runner/preprocess.rs`: Emit Import reference in `try_rewrite_single_map_to_record()`
@@ -1,29 +0,0 @@
1
- # Map-to-Record Field Validation and Nil Fill
2
-
3
- ## Problem
4
- Map-to-record rewrite was passing through ALL map keys without validation, and emitting only
5
- the keys present in the map. This caused:
6
- 1. Maps with keys not in the struct (e.g., `:x`) being incorrectly rewritten to records
7
- 2. "fields size does not match" runtime error when the map has fewer keys than struct fields
8
-
9
- ## Fix (preprocess.rs)
10
- 1. **Field validation**: Check each map key against `struct_def.fields`. If any key is not a
11
- valid struct field, skip the rewrite entirely (stay as map).
12
- 2. **Nil fill**: Emit ALL struct fields in definition order. For fields not present in the map,
13
- emit `Calcit::Nil`. This ensures the record always has the correct field count.
14
- 3. **HashMap tracking**: Build a `HashMap<EdnTag, &Calcit>` of provided fields for O(1) lookup
15
- during emission.
16
-
17
- ## Key Types
18
- - `struct_def.fields` is `Vec<EdnTag>` — compare with `EdnTag` directly, not `Arc<str>`
19
- - `provided_fields` is `HashMap<EdnTag, &Calcit>` — avoids the `Arc<str>: Borrow<EdnTag>` issue
20
-
21
- ## Respo DomProps Design
22
- - 29 fields with `(:: :optional <type>)` annotations
23
- - Strings: class-name, id, type, href, src, placeholder, name, title, data-name, data-comp, target
24
- - Dynamic: style (map), value, inner-text
25
- - Bools: disabled, checked, spell-check, read-only, selected
26
- - Number: tab-index
27
- - Fns: on-click, on-input, on-focus, on-blur, on-keydown, on-keyup, on-change
28
- - Maps: on, event
29
- - `create-element`/`create-list-element` convert record props to map via `&record:to-map`
@@ -1,13 +0,0 @@
1
- ## 概要
2
-
3
- 为 tuple-to-enum 自动改写实现预处理阶段支持。当函数参数 schema 标注为 enum 类型时,
4
- 调用者传递的 untyped tuple `:: :tag payload` 自动改写为 `%:: Enum :tag payload`。
5
-
6
- ## 知识点
7
-
8
- - `CalcitTypeAnnotation::resolve_to_enum_with_ref()` 对应 struct 端已有的 `resolve_to_struct_with_ref()`
9
- - `resolve_enum_from_program()` 通过 `lookup_runtime_ready_registered` + `lookup_def_code_registered` 两级缓存查找
10
- - tuple 改写只替换 head proc (`NativeTuple` → `NativeEnumTupleNew`) 并插入 enum 引用,不对 tag/payload 做验证(由 `check_enum_tuple_construction` 兜底)
11
- - JS codegen 需要 `Calcit::Import` 而非 `Calcit::Enum` 内联值,通过 TypeRef 路径判断走 SameFile 还是 NsReferDef
12
- - map-to-record 改写验证 key 合法性,tuple-to-enum 改写不验证(差异源于 struct field 是封闭集合,enum tag 验证已有独立检查)
13
- - Cirru tag-match 零载荷变体的 pattern 是 `(:ok)` 而非 `:ok`(后者在 pair 中被当作 body)
@@ -1,45 +0,0 @@
1
- # TypeSlot + Enum 编译期安全增强
2
-
3
- ## 概要
4
-
5
- 让 `deftype-slot` / `bind-type` 机制真正实现编译期 enum variant 校验。此前 TypeSlot 绑定的 enum 在自动推导 (`:: → %::`) 路径上缺乏变体验证,导致拼写错误或不存在的 variant 无法在 `cr js` / `--check-only` 时报出。
6
-
7
- ## 修改的文件
8
-
9
- ### `src/calcit/type_annotation.rs`
10
-
11
- - `resolve_to_enum_with_ref()`: 新增 `TypeSlot` 分支,通过 `resolve_type_slot()` 解析绑定类型后委托
12
- - `matches_with_bindings()`: 双向 `Tuple/Enum` 匹配 — 原先只有 `(Tuple, Enum)` 方向,TypeSlot 解析后顺序会翻转,新增 `(Enum, Tuple)` 方向
13
-
14
- ### `src/calcit.rs`
15
-
16
- - 将 `resolve_type_slot` 加入 `pub use` 导出列表
17
-
18
- ### `src/runner/preprocess.rs`
19
-
20
- - `resolve_enum_value()`: 在 `as_struct()` 调用前增加 TypeSlot 解析(避免 `&CalcitStruct` 生命周期问题)
21
- - 新增 `try_rewrite_local_fn_tuple_args_to_enum_tuples()`: 对本地函数调用(如回调 `d!`)也执行 tuple→enum 自动重写
22
- - 主预处理 `Calcit::Local` 分支: 增加 local fn 调用的重写+类型检查(clone 避免借用冲突)
23
- - `try_rewrite_single_tuple_to_enum_tuple()`: 增加变体验证 — 重写后立即检查 tag 是否是 enum 的合法 variant,不合法则发出警告
24
-
25
- ### `src/bin/cr_tests/type_fail.rs`
26
-
27
- - 新增 `type_fail_type_slot_enum_invalid_variant` 测试,验证 TypeSlot 绑定的 enum 在自动重写路径下能正确检测不存在的 variant
28
-
29
- ### `calcit/type-fail/type-slot-enum-invalid-variant.cirru`
30
-
31
- - 新增测试 fixture:声明 `defenum Action`、通过 TypeSlot 绑定、调用 `takes-action $ :: :nonexistent |hello`,期望产生 variant 不存在警告
32
-
33
- ## 知识点
34
-
35
- 1. **TypeSlot 解析链**: `TypeSlot(name) → resolve_type_slot(name) → CalcitTypeAnnotation (通常是 TypeRef)` → 再通过 `resolve_to_enum_with_ref()` 得到 enum 定义。这是一个两步间接过程。
36
-
37
- 2. **`matches_with_bindings` 双向性**: TypeSlot 被解析后会调 `bound.matches_with_bindings(other, bindings)`,此时 self/other 顺序可能翻转。所有组合型匹配(如 Tuple/Enum)都需要双向 pattern。
38
-
39
- 3. **`as_struct()` 返回引用**: `CalcitTypeAnnotation::as_struct()` 返回 `Option<&CalcitStruct>`,无法从临时解析结果中返回引用。修复方案是在调用点先解析 TypeSlot 再调 `as_struct()`。
40
-
41
- 4. **自动重写的 `%::` 不经过 `preprocess_expr`**: `try_rewrite_single_tuple_to_enum_tuple` 构造的 `[NativeEnumTupleNew, ...]` 列表是在预处理完参数后生成的,不会经过 `check_proc_arg_types` 中的 `check_enum_tuple_construction`。因此变体验证必须在重写函数内部完成。
42
-
43
- 5. **Local fn 调用缺少自动重写**: 原先只有 `CalcitFn` 调用走 `try_rewrite_tuple_args_to_enum_tuples`。`Calcit::Local` 调用(如回调参数 `d!`)需要单独处理。新函数接受 `CalcitFnTypeAnnotation` 而非 `CalcitFn`。
44
-
45
- 6. **Lambda-in-map 的 EXPECTED_FN_TYPE 盲区**: `fn (e d!)` 在 hashmap 值(如 `:on-click`)中时,`d!` 不会获得 `EXPECTED_FN_TYPE` 注入的类型信息。目前通过显式 `%:: Op :variant` 写法绕过,属于已知架构限制。
@@ -1,32 +0,0 @@
1
- # 2026-04-14 15:00 — `?{}` 松散 Record 语法
2
-
3
- ## 概要
4
-
5
- 新增 `?{}` 松散 record 语法,允许不声明 struct 就创建 record,与 `::` 无类型 tuple 对称。
6
- 在函数参数有 struct 类型标注时,预处理阶段自动改写为 `%{} StructDef ...`。
7
-
8
- ## 改动文件
9
-
10
- | 文件 | 变更 |
11
- |------|------|
12
- | `src/calcit/proc_name.rs` | 新增 `NativeLooseRecord` proc 变体,`?{}` 序列化,类型签名 |
13
- | `src/data/cirru.rs` | `"?{}"` token 解析为 `Calcit::Proc(NativeLooseRecord)` |
14
- | `src/calcit/record.rs` | `LOOSE_RECORD_NAME`、`is_loose()`、`from_loose_pairs()` |
15
- | `src/builtins/records.rs` | `call_loose_record()` 运行时:验证 tag 键、排序、排重 |
16
- | `src/builtins.rs` | 分发 `NativeLooseRecord => call_loose_record(args)` |
17
- | `src/calcit.rs` | Display: 松散 record 显示为 `(?{} ...)` |
18
- | `src/runner/preprocess.rs` | `try_rewrite_loose_record_args_to_struct_records`、类型推断、skip core arg check |
19
- | `ts-src/js-record.mts` | JS 运行时 `_$q__$M_` 函数 |
20
- | `calcit/test-record.cirru` | `test-loose-record-rewrite` 集成测试 |
21
- | `docs/features/records.md` | 文档:松散 record 语法、自动改写、类型对称表 |
22
-
23
- ## 性能优化
24
-
25
- - **预处理改写链合并重建**:三步改写(map→record、loose→struct、tuple→enum)原先每步都重建 `ys` (CalcitList),优化为仅在有改写时统一重建一次,减少 CalcitList push 操作。
26
- - **JS 排序比较器修正**:将重复字段检测从 sort comparator 中移出(comparator 内 throw 违反排序契约),改为排序后线性扫描相邻元素,行为更可靠。
27
-
28
- ## 知识点
29
-
30
- - `EdnTag::cmp` 按全局 tag 池分配顺序排序(整数 index),**不是**字典序。record 字段排序必须用 `ref_str().cmp()` 保持字母序。
31
- - CalcitList 基于 persistent ternary tree,`.clone()` 是 O(1) 引用计数操作。
32
- - Sort comparator 不应抛异常——不同排序算法对异常行为未定义。
@@ -1,63 +0,0 @@
1
- # 202604142259 — Bidirectional Type Checking Architecture Refactoring
2
-
3
- ## 概要
4
-
5
- 将 `src/runner/preprocess.rs`(6199 行单体文件)拆分为模块化目录结构,
6
- 按双向类型检查(bidirectional type checking)的概念分离关注点。
7
-
8
- ## 改动详情
9
-
10
- ### 模块拆分
11
-
12
- `preprocess.rs` → `preprocess/` 目录模块:
13
-
14
- | 模块 | 行数 | 职责 |
15
- |---|---|---|
16
- | `mod.rs` | ~4744 | 预处理核心:符号解析、宏展开、作用域管理、特殊语法 |
17
- | `type_inference.rs` | ~693 | 类型合成(synthesis):自下而上推导表达式类型 |
18
- | `type_checking.rs` | ~402 | 类型检查(checking):自上而下验证参数类型 |
19
- | `type_rewriting.rs` | ~398 | 类型定向重写:根据期望类型重写 AST 字面量 |
20
-
21
- ### 代码去重
22
-
23
- 1. **统一参数重写循环** (`rewrite_args_by_expected_type`):
24
- - 原先 4 个 `try_rewrite_*_args_to_*` 函数各自包含相同的外层循环(~30 LOC × 4)
25
- - 提取为泛型 `rewrite_args_by_expected_type<F>` 函数,4 个入口各只保留闭包调用
26
-
27
- 2. **统一参数类型检查循环** (`check_arg_types_loop`):
28
- - 原先 `check_local_fn_call_arg_types` 和 `check_user_fn_arg_types` 共享相同的
29
- zip → resolve_type_value → matches_with_bindings → gen_check_warning 模式
30
- - 提取为泛型 `check_arg_types_loop<F>` 函数,包含 variadic 处理和 spread 跳过逻辑
31
-
32
- 3. **统一引用节点构建** (`build_struct_ref_node` / `build_enum_ref_node`):
33
- - 原先 map→record 和 loose-record→struct 各自复制 Import vs Struct/Enum 分支
34
- - 提取为共享的 `build_struct_ref_node` 和 `build_enum_ref_node` 函数
35
-
36
- ### Proc 推导提取
37
-
38
- - `infer_type_from_expr` 中的 `Calcit::Proc` 分支(~100 行 match arms)
39
- 提取为独立的 `infer_proc_call_return_type` 函数,提高可读性
40
-
41
- ## 双向类型检查映射
42
-
43
- 参照 Dunfield & Krishnaswami 的框架:
44
-
45
- | 方向 | 模块 | 入口函数 |
46
- |---|---|---|
47
- | **Synthesis** (⇒) | `type_inference` | `infer_type_from_expr`, `resolve_type_value` |
48
- | **Checking** (⇐) | `type_checking` | `check_*_arg_types`, `check_function_return_type` |
49
- | **Rewriting** (结构适配) | `type_rewriting` | `try_rewrite_*` |
50
- | **Context** (线程局部) | `mod.rs` | `EXPECTED_FN_TYPE`, `EXPECTED_STRUCT_TYPE` |
51
-
52
- ## 为后续 match 语法扩展铺路
53
-
54
- - `type_checking.rs` 的 `check_arg_types_loop` 模式可直接复用于 match 分支检查
55
- - `type_inference.rs` 中已有 `infer_if_return_type` 作为分支合并的模板
56
- - 未来只需在相应模块中添加新函数,无需修改 `mod.rs` 的核心调度
57
-
58
- ## 验证
59
-
60
- - `cargo check --lib` ✅ 零警告
61
- - `cargo clippy --lib -- -D warnings` ✅ 零警告
62
- - `cargo fmt` ✅ 格式一致
63
- - 链接器问题(`ld: library 'System' not found`)是环境问题,非代码变更引起
@@ -1,20 +0,0 @@
1
- # match syntax with exhaustiveness checking
2
-
3
- ## Summary
4
-
5
- Added native `match` syntax for enum pattern matching with compile-time exhaustiveness detection,
6
- as a safer alternative to `tag-match` macro. See `drafts/match-syntax-rfc.md` for full design.
7
-
8
- ## Files modified
9
-
10
- - `src/calcit/syntax_name.rs` — `CalcitSyntax::Match`
11
- - `src/builtins/syntax.rs` — `syntax_match()` runtime
12
- - `src/builtins.rs` — dispatch entry
13
- - `src/runner/preprocess/mod.rs` — `preprocess_match()` with exhaustiveness
14
- - `src/codegen/emit_js.rs` — `gen_match_code()` JS output
15
- - `calcit/test-enum.cirru` — test cases
16
-
17
- ## Key takeaway
18
-
19
- Cirru indentation creates pair-based `(pattern body)` children — same format as `tag-match`.
20
- Flat alternating format doesn't survive Cirru serialization round-trips.
@@ -1,44 +0,0 @@
1
- # `&record:nth` — Compile-Time Record Field Index Optimization
2
-
3
- ## 概述
4
-
5
- 新增 `NativeRecordNth` / `&record:nth` 过程,在预处理阶段将 record 字段访问优化为 O(1) 索引访问,绕过运行时的类型分发链和二分查找。
6
-
7
- ## 优化前访问路径
8
-
9
- - `(:field record)` → 重写为 `(get arg :field)` → 运行时 6 次类型判断 (`nil?` → `string?` → `map?` → `list?` → `tuple?` → `record?`) → `&record:get` → `index_of()` O(log n) 二分查找
10
- - `&record:get record :field` → 运行时 `index_of()` O(log n) 二分查找
11
-
12
- ## 优化后访问路径
13
-
14
- 当预处理阶段可以通过 `resolve_type_value` + `as_struct()` 解析出 record 的 struct 定义时:
15
-
16
- - `(:field record)` → 直接重写为 `(&record:nth record <compile-time-idx>)` → 运行时 O(1) `values[idx]`
17
- - `&record:get record :field` → 重写为 `(&record:nth record <compile-time-idx>)` → 运行时 O(1)
18
-
19
- ## 触发条件
20
-
21
- 优化仅在类型信息明确时激活:
22
- - record 由 `%Struct ...` 构造器在本地 `let` 中创建
23
- - 函数参数有显式 struct 类型的 schema 标注
24
-
25
- 若类型不明,回 fallback 到原有路径,不影响运行时行为。
26
-
27
- ## 修改文件
28
-
29
- 1. **`src/calcit/proc_name.rs`** — 新增 `NativeRecordNth` 变体 (`&record:nth`),签名 `(record, number) → dynamic`
30
- 2. **`src/builtins/records.rs`** — 实现 `record_nth(xs)` 运行时函数,直接 `values[idx]` 访问
31
- 3. **`src/builtins.rs`** — 分发表连线 `NativeRecordNth => records::record_nth`
32
- 4. **`src/runner/preprocess/mod.rs`** — 两个重写点:
33
- - Tag-call (`Calcit::Tag` as head):解析 arg 类型后索引重写
34
- - `NativeRecordGet` proc call:解析 record arg 类型后索引重写
35
- 5. **`src/runner/preprocess/type_inference.rs`** — `infer_record_nth_type()` 根据 struct 的 `field_types[idx]` 推断返回类型
36
- 6. **`src/runner/preprocess/type_checking.rs`** — 将 `NativeRecordNth` 加入 core arg type check 跳过列表
37
- 7. **`src/codegen/emit_js.rs`** — JS 内联代码生成 `record.values[idx]`,无函数调用开销
38
-
39
- ## 知识点
40
-
41
- - `CalcitStruct.index_of(field_str)` 在编译期使用,用字段名解析排序位置
42
- - `resolve_type_value()` 返回 `None` 时优化不触发,安全回退
43
- - JS CalcitRecord 的 `.values` 数组和 Rust 端的 `values` Vec 索引一致(均按字段名字母序排序)
44
- - 对于真实项目(如 respo),函数参数通常缺少 struct 类型标注,优化暂不触发;后续若 schema 推断增强,无需改动 rewrite 逻辑即可自动生效
@@ -1,31 +0,0 @@
1
- # 扩展 extract_predicate_binding 支持更多类型谓词
2
-
3
- ## 改动概要
4
-
5
- 将 `extract_predicate_binding` 重构为 `extract_predicate_bindings`,支持双向窄化(true/false 分支),并新增 6 个类型谓词的窄化支持。
6
-
7
- ## 修改文件
8
-
9
- ### src/runner/preprocess/mod.rs
10
-
11
- - 重构 `extract_predicate_binding` → `extract_predicate_bindings`,返回 `PredicateNarrowing` 结构体(包含 `true_binding` 和 `false_binding`)
12
- - `preprocess_if` 中 false 分支也应用窄化信息
13
- - 新增谓词:`tag?` → `:tag`、`bool?` → `:bool`、`symbol?` → `:symbol`、`fn?` → `:fn`
14
- - 新增 `nil?`/`some?`:当变量已知为 `Optional(T)` 时,nil? 的 false 分支窄化为 `T`,some? 的 true 分支窄化为 `T`
15
-
16
- ### src/calcit/proc_name.rs
17
-
18
- - `TurnTag` 的参数签名从 `some_tag("string")` 改为 `dynamic_tag()`,因为 `turn-tag` 在运行时接受 tag/symbol/string,旧签名在 `tag?` 窄化后误报
19
-
20
- ## 知识点
21
-
22
- 1. **双向窄化**:`if (nil? x) ... else ...`,false 分支可从 `Optional(T)` 解包为 `T`,这在链式 if 模式中可以传播类型信息
23
- 2. **新窄化暴露的类型签名问题**:`tag?` 窄化后,`(turn-tag x)` 触发了 arg-type-mismatch 警告,因为 `turn-tag` 签名过严。类似 coercion 函数应使用 `dynamic_tag()`
24
- 3. **核心库中 `if (tag? ...)` 出现 5 次、`if (nil? ...)` 26 次、`if (list? ...)` 41 次**——窄化覆盖面广
25
- 4. **JS 端 tuple `.nth` 缺失**:prior session 简化了多态函数(移除 tuple? 分支),但 JS runtime 的 `invoke_method` 没有对应的 core-tuple-methods 注册,导致 JS 测试 `test_refs` 失败。这是 JS procs 层的问题,不是预处理阶段的问题
26
-
27
- ## 测试结果
28
-
29
- - Rust: 246 tests pass(67 cirru + 179 unit)
30
- - Clippy: clean
31
- - JS: 已知 pre-existing failure(tuple .nth in JS runtime)
@@ -1,50 +0,0 @@
1
- # Monomorphize `map` / `filter` at Compile Time
2
-
3
- ## 背景
4
-
5
- `try_specialize_polymorphic_call`(`src/runner/preprocess/mod.rs`)原本只能把
6
- `count`、`empty?`、`first`、`rest`、`nth`、`get`、`assoc`、`contains?` 等
7
- **built-in 多态 proc** 特化成 native proc(`NativeListCount` / `NativeMapGet`
8
- 等),彻底避免运行时按 `type_of` 做分支。
9
-
10
- 但是 Calcit 里最常见的集合高阶函数 `map` / `filter` / `reduce` 等都是在
11
- `calcit-core.cirru` 里用 Calcit 本身定义的用户级 defn(例如 `&list:map`、
12
- `&map:map`、`&set:filter`),原先不能在预处理阶段复用这套机制,运行时仍要靠
13
- `list?`/`map?`/`set?` 三条 `cond` 分支来分发。
14
-
15
- 本次把能力扩展到 Calcit 级别的 core def,当 receiver 的静态类型可推断时,
16
- 直接把 `(map xs f)` 改写成 `(calcit.core/&list:map xs f)` 等形式。
17
-
18
- ## 关键改动
19
-
20
- - `src/runner/preprocess/mod.rs`
21
- - `try_specialize_polymorphic_call` 新增 `file_ns: &str` 参数,用于构造
22
- `Calcit::Import` 头的 `ImportInfo::Core { at_ns }`。
23
- - 在已有的 proc 特化表之前新增一张“core def 特化表”:
24
- - `("map", List(_)) -> &list:map`
25
- - `("map", Map(_, _)) -> &map:map`
26
- - `("filter", List(_)) -> &list:filter`
27
- - `("filter", Map(_, _)) -> &map:filter`
28
- - `("filter", Set(_)) -> &set:filter`
29
- - 命中时直接构造 `Calcit::Import(CalcitImport { ns: "calcit.core", def, info:
30
- Core { at_ns: file_ns }, def_id: Some(program::ensure_def_id(...).0) })`
31
- 作为新的 head,保持已 preprocess 过的参数不变,避免重复预处理。
32
- - 禁止对 `&list:map` / `&map:map` / `&set:map` / `&list:filter` /
33
- `&map:filter` / `&set:filter` 自身再次 monomorphize,避免潜在 cycle。
34
- - 调用点 `Ok(Calcit::from(CalcitList::from(ys)))` 前的 specialize 调用传入
35
- `file_ns`。
36
-
37
- ## 验证
38
-
39
- - `cargo fmt && cargo clippy --release -- -D warnings` ✓
40
- - `cargo test --release` ✓ 所有现有测试通过
41
- - `yarn check-all` ✓ 全量集成测试 + WASM 测试全部 OK
42
-
43
- ## 后续思路
44
-
45
- - 可继续把 `reduce` / `last` / `reverse` / `concat` / `to-list` / `to-set`
46
- 等也加入特化表;其中 `concat` / `reverse` 已有 native proc(`NativeListConcat`
47
- / `NativeListReverse`),加到已有 proc 表即可。
48
- - 可以考虑把谓词(`list?`、`map?`、`number?`、`string?` …)在类型已知时直接折叠成
49
- `true` / `false`,进一步帮 WASM / JS codegen 消冗余分支。
50
- - 未来 `&set:map` 如果单独实现,即可补齐 `("map", Set(_))` 分支。
@@ -1,31 +0,0 @@
1
- # Monomorphize `includes?` and `reverse`
2
-
3
- ## 背景
4
-
5
- 继 `map` / `filter` 之后,继续扩展 `try_specialize_polymorphic_call`:
6
-
7
- - `includes?` 原实现(calcit-core.cirru L3228)有 5 条 `if` 分支
8
- (`nil?` / `list?` / `map?` / `set?` / `string?` fallback `.includes?`)。
9
- - `reverse` 实际上在 runtime 就是 `&list:reverse` 的别名,但以前每次调用还是要
10
- 经过一层 Calcit user-def 间接。
11
-
12
- ## 改动
13
-
14
- 在 `src/runner/preprocess/mod.rs` 的 proc 特化表中追加:
15
-
16
- ```text
17
- ("includes?", T::List(_)) -> NativeListIncludes
18
- ("includes?", T::Map(_, _)) -> NativeMapIncludes
19
- ("includes?", T::Set(_)) -> NativeSetIncludes
20
- ("includes?", T::String) -> NativeStrIncludes
21
- ("reverse", T::List(_)) -> NativeListReverse
22
- ```
23
-
24
- `concat` 因为是变长参数 defn,暂不在这里处理;后续可以在 preprocess 阶段
25
- 把已知都是 list 的 `(concat a b)` 展开为 `(&list:concat a b)` 的折叠形式。
26
-
27
- ## 验证
28
-
29
- - `cargo fmt && cargo clippy --release -- -D warnings` ✓
30
- - `cargo test --release` ✓
31
- - `yarn check-all` ✓