@calcit/procs 0.12.56 → 0.12.58
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/RFCs/02-04-runtime-traits-plan.md +67 -573
- package/build.rs +36 -2
- package/editing-history/202608011759-issue-routing-in-agent-guide.md +17 -0
- package/editing-history/202608011833-schema-type-symbols.md +20 -0
- package/editing-history/202608011852-wasm-dynamic-string-tag.md +7 -0
- package/editing-history/202608011908-consolidate-history.md +6 -0
- package/editing-history/202608012022-consolidate-cli-and-test-duplication.md +28 -0
- package/editing-history/202608012123-review-follow-up.md +18 -0
- package/editing-history/202608012320-release-0.12.57.md +5 -0
- package/editing-history/202608012344-release-main-policy.md +5 -0
- package/editing-history/202608020058-data-api-and-trait-coverage.md +26 -0
- package/editing-history/ARCHIVE.md +15 -0
- package/editing-history/README.md +21 -0
- package/history/202608021153-runtime-traits.md +23 -0
- package/history/202608021227-format-markdown-cirru.md +18 -0
- package/history/202608021239-review-trait-followups.md +19 -0
- package/history/202608021251-defimpl-symbol-traits.md +8 -0
- package/history/202608021255-doc-type-symbols.md +6 -0
- package/history/202608021322-postfix-enum-methods.md +12 -0
- package/history/202608021327-postfix-unwrap-examples.md +10 -0
- package/history/202608021507-receiver-first-static-inference.md +21 -0
- package/history/202608021550-review-type-correctness.md +6 -0
- package/history/202608021730-release-0.12.58.md +5 -0
- package/lib/calcit.procs.d.mts +1 -0
- package/lib/calcit.procs.mjs +57 -47
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit.procs.mts +62 -44
- package/editing-history/2026-02-13-1841-trait-origin-structural-eq.md +0 -91
- package/editing-history/2026-02-14-2050-js-codegen-recursion-tag-migration.md +0 -39
- package/editing-history/2026-02-14-2358-emit-js-modularization-shift-left.md +0 -63
- package/editing-history/2026-02-15-0000-diagnostics-consolidated.md +0 -35
- package/editing-history/2026-02-15-1941-macro-diagnostics-refinement.md +0 -39
- package/editing-history/2026-02-16-2043-core-api-docs-cleanup.md +0 -40
- package/editing-history/2026-02-23-0834-migrate-to-defstruct.md +0 -91
- package/editing-history/2026-02-23-2321-ns-imports-code-fixes.md +0 -42
- package/editing-history/2026-02-25-0002-language-behavior-eval-mode.md +0 -93
- package/editing-history/2026-02-25-0111-guidebook-no-check-block-upgrades.md +0 -52
- package/editing-history/2026-02-25-0113-runtime-type-validation-and-macro-quoting.md +0 -41
- package/editing-history/2026-02-25-1131-check-md-eval-improvements.md +0 -13
- package/editing-history/2026-02-26-1324-check-md-inprocess-cache-and-path-labels.md +0 -7
- package/editing-history/2026-02-27-1640-unify-markdown-readers.md +0 -16
- package/editing-history/2026-02-27-1958-tree-rewrite-command-and-reference-model.md +0 -18
- package/editing-history/2026-02-27-2200-split-def-command.md +0 -29
- package/editing-history/2026-02-27-2212-tree-raise-wrap.md +0 -33
- package/editing-history/2026-02-27-2223-calcit-agent-docs-optimize.md +0 -41
- package/editing-history/2026-03-01-0212-query-search-entry-and-ffi-warning.md +0 -53
- package/editing-history/2026-03-03-1934-check-types-and-core-annotations.md +0 -17
- package/editing-history/2026-03-04-0000-generics-fn-typevar-identity.md +0 -30
- package/editing-history/2026-03-04-1331-tag-call-warning-and-dot-access-migration.md +0 -28
- package/editing-history/2026-03-04-1548-impl-new-dot-method-input-and-doc-hints.md +0 -33
- package/editing-history/2026-03-04-1645-calcit-eq-contract-refactor-and-macro-tests.md +0 -28
- package/editing-history/2026-03-04-2200-assert-type-assert-traits-composable-runtime-checks.md +0 -18
- package/editing-history/2026-03-05-0042-type-inference-argtypes-and-core-hints.md +0 -54
- package/editing-history/2026-03-05-0115-calcit-core-generic-refinements.md +0 -57
- package/editing-history/2026-03-05-1930-schema-migration-cr-edit.md +0 -30
- package/editing-history/2026-03-05-1939-query-schema-adaptation.md +0 -42
- package/editing-history/2026-03-06-0120-schema-hint-migration-batch.md +0 -38
- package/editing-history/2026-03-06-1416-core-macro-schema-migration.md +0 -20
- package/editing-history/2026-03-06-1552-core-schema-and-hintfn-migration.md +0 -63
- package/editing-history/2026-03-06-1936-schema-normalization-and-preprocess-preload.md +0 -12
- package/editing-history/2026-03-07-0000-migrate-hint-fn-to-schema.md +0 -29
- package/editing-history/2026-03-07-0000-remove-enum-prototype-field.md +0 -43
- package/editing-history/2026-03-07-0000-schema-args-type-enforcement.md +0 -66
- package/editing-history/2026-03-07-0142-unit-type-and-builtin-schemas.md +0 -82
- package/editing-history/2026-03-07-1652-decouple-snapshot-schema-to-calcit-type.md +0 -112
- package/editing-history/2026-03-07-1821-snapshot-schema-validation.md +0 -6
- package/editing-history/2026-03-07-1959-schema-def-kind-arity-validation.md +0 -96
- package/editing-history/2026-03-08-0031-schema-generics-quote-normalization.md +0 -35
- package/editing-history/2026-03-08-1905-schema-typeref-and-assert-migration.md +0 -34
- package/editing-history/2026-03-08-2033-schema-wrapper-migration.md +0 -45
- package/editing-history/2026-03-08-2315-late-schema-cleanup-and-warning-compat.md +0 -27
- package/editing-history/2026-03-09-1753-schema-type-fail-tests.md +0 -17
- package/editing-history/2026-03-10-1040-edit-schema-primitive-tag-support.md +0 -42
- package/editing-history/2026-03-10-1754-ns-entry-snapshot-migration.md +0 -66
- package/editing-history/2026-03-13-2216-validate-struct-type-arg-arity.md +0 -24
- package/editing-history/2026-03-16-2353-runtime-boundary-cleanup.md +0 -14
- package/editing-history/2026-03-17-0150-runtime-boundary-lookup-cleanup.md +0 -28
- package/editing-history/2026-03-20-0116-json-builtins-and-runtime-docs.md +0 -48
- package/editing-history/2026-03-26-2013-docs-frontmatter-and-module-search.md +0 -58
- package/editing-history/2026-04-07-1550-path-format-at-prefix-migration.md +0 -46
- package/editing-history/2026-04-12-1524-js-codegen-map-to-record.md +0 -26
- package/editing-history/2026-04-12-1549-map-to-record-field-validation.md +0 -29
- package/editing-history/2026-04-13-1600-tuple-to-enum-rewrite.md +0 -13
- package/editing-history/2026-04-13-2309-typeslot-enum-compile-safety.md +0 -45
- package/editing-history/2026-04-14-1500-loose-record-syntax.md +0 -32
- package/editing-history/2026-04-14-2259-bidir-type-check-refactor.md +0 -63
- package/editing-history/2026-04-15-0120-match-syntax-exhaustiveness.md +0 -20
- package/editing-history/2026-04-15-1211-record-nth-optimization.md +0 -44
- package/editing-history/2026-04-16-1936-predicate-narrowing-expansion.md +0 -31
- package/editing-history/2026-04-17-0132-monomorphize-map-filter.md +0 -50
- package/editing-history/2026-04-17-0135-monomorphize-includes-reverse.md +0 -31
- package/editing-history/2026-04-17-0140-fold-type-predicates.md +0 -44
- package/editing-history/2026-04-17-0154-generic-dispatch-records-tuples.md +0 -52
- package/editing-history/2026-04-17-0520-simplify-generic-defns-via-method-dispatch.md +0 -49
- package/editing-history/2026-05-21-0055-tree-show-cr-config-and-edit-cleanup.md +0 -81
- package/editing-history/2026-05-31-2052-macro-schema-roundtrip-and-weak-types.md +0 -6
- package/editing-history/2026-05-31-2105-map-generic-weak-types-followup.md +0 -15
- package/editing-history/2026-06-01-0003-update-callback-field-specialization.md +0 -19
- package/editing-history/2026-06-01-2317-data-definition-where-bounds.md +0 -6
- package/editing-history/2026-06-02-0114-data-definition-where-macro-followup.md +0 -21
- package/editing-history/2026-06-03-0000-check-md-edn-errors.md +0 -5
- package/editing-history/2026-06-03-1600-check-md-entry-modules.md +0 -6
- package/editing-history/2026-06-04-0000-check-md-app-main-init.md +0 -6
- package/editing-history/2026-06-04-2218-compiled-executable-runtime-backfill.md +0 -6
- package/editing-history/2026-06-09-0000-with-type-slot-scoped-binding.md +0 -83
- package/editing-history/2026-06-09-1241-remove-bind-type.md +0 -64
- package/editing-history/2026-06-09-1800-core-effect-tags.md +0 -57
- package/editing-history/2026-06-10-1200-get-def-doc-schema-builtin.md +0 -7
- package/editing-history/2026-06-15-1500-effects-graph-mvp.md +0 -30
- package/editing-history/2026-06-16-1700-effects-graph-ste-tree.md +0 -84
- package/editing-history/2026-06-27-0052-cli-improvements.md +0 -41
- package/editing-history/2026-06-27-0202-docs-indexing-improvements.md +0 -22
- package/editing-history/2026-06-27-0315-file-splits.md +0 -17
- package/editing-history/2026-06-27-0416-agent-advanced-split.md +0 -15
- package/editing-history/archived/2025-04-12-1453-map-to-record-rewrite.md +0 -33
- package/editing-history/archived/2025-04-16-0117-wasm-codegen-and-catalog-update.md +0 -40
- package/editing-history/archived/2025-07-16-0207-wasm-encoder-migration.md +0 -48
- package/editing-history/archived/2025-07-16-1633-wasm-data-structures.md +0 -61
- package/editing-history/archived/2026-02-13-1926-docs-tests-followup.md +0 -33
- package/editing-history/archived/2026-02-16-2128-docs-smoke-and-trait-errors.md +0 -20
- package/editing-history/archived/2026-02-25-1234-watch-mode-default-once.md +0 -5
- package/editing-history/archived/2026-03-07-1302-calcit-agent-docs-update.md +0 -32
- package/editing-history/archived/2026-03-09-1819-add-test-fail-script.md +0 -5
- package/editing-history/archived/2026-03-09-1944-split-type-fail-tests.md +0 -8
- package/editing-history/archived/2026-03-16-1449-profiling-tools-reorg.md +0 -13
- package/editing-history/archived/2026-03-17-2026-afternoon-runtime-boundary-optimization-summary.md +0 -87
- package/editing-history/archived/2026-03-18-1802-tips-level-and-overwrite-schema-preservation.md +0 -26
- package/editing-history/archived/2026-03-20-1229-query-window-3-with-parent-preview.md +0 -72
- package/editing-history/archived/2026-03-23-1137-command-echo-tool-output-cleanup.md +0 -71
- package/editing-history/archived/2026-04-10-0011-snapshot-empty-version-pipe-marker.md +0 -23
- package/editing-history/archived/2026-04-16-0131-wasm-math-and-test-integration.md +0 -28
- package/editing-history/archived/2026-04-16-1507-wasm-data-structures-and-rfc-rename.md +0 -27
- package/editing-history/archived/2026-04-16-1520-wasm-bitwise-and-match.md +0 -21
- package/editing-history/archived/2026-04-16-1542-wasm-cross-ns-host-imports.md +0 -38
- package/editing-history/archived/2026-04-17-0026-wasm-rest-args.md +0 -62
- package/editing-history/archived/2026-04-17-0048-wasm-type-of.md +0 -70
- package/editing-history/archived/2026-04-17-0051-wasm-derived-predicates.md +0 -34
- package/editing-history/archived/2026-04-17-2316-wasm-do-println-fixes.md +0 -41
- package/editing-history/archived/2026-04-18-1208-split-emit-wasm-and-bump-version.md +0 -15
- package/editing-history/archived/2026-04-18-1430-wasm-list-match-and-method-dispatch.md +0 -5
- package/editing-history/archived/2026-04-18-2041-cr-wasm-split-and-runtime-stability.md +0 -18
- package/editing-history/archived/2026-04-18-2045-v0.12.23-ci-wasm-fix.md +0 -13
- package/editing-history/archived/2026-04-21-1818-wasm-string-ops-v2.md +0 -57
- package/editing-history/archived/2026-04-21-2332-split-emit-wasm.md +0 -45
- package/editing-history/archived/2026-04-22-0114-wasm-hof-intercepts-and-set-intersection.md +0 -82
- package/editing-history/archived/2026-04-22-0136-wasm-enum-tuple-bool-str-fixes.md +0 -68
- package/editing-history/archived/2026-04-22-1340-wasm-map-diff-new-and-let-intercept.md +0 -53
- package/editing-history/archived/2026-04-23-1419-v0.12.26-wasm-bisection-fixes.md +0 -7
- package/editing-history/archived/2026-04-23-1645-release-conventions.md +0 -14
- package/editing-history/archived/2026-04-25-1940-wasm-suite-multi-module-entry.md +0 -53
- package/editing-history/archived/2026-04-25-2003-wasm-method-includes-string-and-set-refactor.md +0 -71
- package/editing-history/archived/2026-04-25-2010-wasm-suite-add-fn-lens-edn.md +0 -43
- package/editing-history/archived/2026-04-25-2051-display-by.md +0 -39
- package/editing-history/archived/2026-04-28-1728-fix-gensym-stable.md +0 -31
- package/editing-history/archived/2026-04-29-1400-fix-bind-type-precompile.md +0 -38
- package/editing-history/archived/2026-05-26-0957-match-docs-check-md.md +0 -24
- package/editing-history/archived/2026-05-31-2059-ci-docs-test-and-fn-helper-tightening.md +0 -3
- package/editing-history/archived/2026-06-01-0005-release-0.12.36.md +0 -16
- package/editing-history/archived/2026-06-01-2230-enum-struct-payload-docs.md +0 -4
- package/editing-history/archived/2026-06-03-1620-release-0.12.38.md +0 -6
- package/editing-history/archived/2026-06-04-0000-release-0.12.39.md +0 -4
- package/editing-history/archived/2026-06-04-2230-release-0.12.40.md +0 -5
- package/editing-history/archived/2026-06-12-1525-weak-types-dots-format.md +0 -15
- package/editing-history/archived/2026-06-13-1200-primitive_schema_tags.md +0 -9
- package/editing-history/archived/2026-06-20-1142-ts-declaration-d-mts.md +0 -5
- package/editing-history/archived/2026-06-29-0117-upgrade-doc-snapshot-migration.md +0 -2
- package/editing-history/archived/2026-06-29-calcit-cli.md +0 -80
- package/editing-history/archived/2026-06-29-typed-calcit-cli-schemas.md +0 -23
- package/editing-history/archived/20260630-duplication-analysis.md +0 -116
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -202,46 +202,35 @@ export let _$n_assert_traits = function (value: CalcitValue, traitDef: CalcitVal
|
|
|
202
202
|
if (!(traitDef instanceof CalcitTrait)) {
|
|
203
203
|
throw new Error(`&assert-traits expected a trait definition, but received: ${toString(traitDef, true)}`);
|
|
204
204
|
}
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (!exists) missing.push(method.toString());
|
|
205
|
+
// Use the same merged builtin + attached impl list as method dispatch.
|
|
206
|
+
// Otherwise records and tuples can call a builtin method while
|
|
207
|
+
// `assert-traits` incorrectly claims that the corresponding trait is absent.
|
|
208
|
+
const pair = lookup_impls(value);
|
|
209
|
+
if (pair == null) {
|
|
210
|
+
throw new Error(`&assert-traits cannot resolve impls for: ${toString(value, true)}`);
|
|
211
|
+
}
|
|
212
|
+
const impls = pair[0];
|
|
213
|
+
const reverse =
|
|
214
|
+
value instanceof CalcitRecord || value instanceof CalcitTuple || value instanceof CalcitStruct || value instanceof CalcitEnum;
|
|
215
|
+
const ordered = reverse ? [...impls].reverse() : impls;
|
|
216
|
+
const selected = ordered.find((impl) => impl != null && impl.origin === traitDef);
|
|
217
|
+
if (selected == null) {
|
|
218
|
+
const available = impls
|
|
219
|
+
.filter((impl) => impl?.origin != null)
|
|
220
|
+
.map((impl) => impl.origin!.name.toString())
|
|
221
|
+
.join(" ");
|
|
222
|
+
throw new Error(
|
|
223
|
+
`assert-traits failed: ${toString(value, true)} does not nominally implement ${traitDef.toString()}. Available trait impls: ${
|
|
224
|
+
available || "(none)"
|
|
225
|
+
}`
|
|
226
|
+
);
|
|
231
227
|
}
|
|
228
|
+
const missing = traitDef.methods.filter((method) => selected.getOrNil(method) == null);
|
|
232
229
|
if (missing.length > 0) {
|
|
233
|
-
const available: string[] = [];
|
|
234
|
-
for (let j = 0; j < impls.length; j++) {
|
|
235
|
-
const impl = impls[j];
|
|
236
|
-
if (impl == null) continue;
|
|
237
|
-
for (let k = 0; k < impl.fields.length; k++) {
|
|
238
|
-
available.push(impl.fields[k].toString());
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
230
|
throw new Error(
|
|
242
|
-
`assert-traits failed: ${toString(
|
|
231
|
+
`assert-traits failed: impl ${selected.name.toString()} for trait ${traitDef.name.toString()} is incomplete. Missing: ${missing.join(
|
|
243
232
|
" "
|
|
244
|
-
)}
|
|
233
|
+
)}`
|
|
245
234
|
);
|
|
246
235
|
}
|
|
247
236
|
return value;
|
|
@@ -306,12 +295,14 @@ export let _$n_impl_$o__$o_new = (name: CalcitValue, ...pairs: CalcitValue[]): C
|
|
|
306
295
|
if (name === undefined) throw new Error("&impl::new expected arguments");
|
|
307
296
|
const origin = name instanceof CalcitTrait ? name : null;
|
|
308
297
|
const implName = origin ? origin.name : castTag(name);
|
|
309
|
-
if (pairs.length === 0) {
|
|
310
|
-
return new CalcitImpl(implName, [], [], origin);
|
|
311
|
-
}
|
|
312
298
|
const entries: Array<{ tag: CalcitTag; value: CalcitValue }> = [];
|
|
313
|
-
|
|
314
|
-
|
|
299
|
+
let sourcePairs = pairs;
|
|
300
|
+
if (pairs.length === 1 && pairs[0] instanceof CalcitImpl) {
|
|
301
|
+
const sourceImpl = pairs[0];
|
|
302
|
+
sourcePairs = sourceImpl.fields.map((field, idx) => new CalcitTuple(field, [sourceImpl.values[idx]], null));
|
|
303
|
+
}
|
|
304
|
+
for (let idx = 0; idx < sourcePairs.length; idx++) {
|
|
305
|
+
const pairValue = sourcePairs[idx];
|
|
315
306
|
let fieldTag: CalcitTag;
|
|
316
307
|
let value: CalcitValue;
|
|
317
308
|
if (pairValue instanceof CalcitTuple) {
|
|
@@ -338,6 +329,21 @@ export let _$n_impl_$o__$o_new = (name: CalcitValue, ...pairs: CalcitValue[]): C
|
|
|
338
329
|
}
|
|
339
330
|
const fields = entries.map((entry) => entry.tag);
|
|
340
331
|
const values = entries.map((entry) => entry.value);
|
|
332
|
+
if (origin != null) {
|
|
333
|
+
const missing = origin.methods.filter((method) => !fields.some((field) => field.value === method.value));
|
|
334
|
+
const unexpected = fields.filter((field) => !origin.methods.some((method) => method.value === field.value));
|
|
335
|
+
if (missing.length > 0 || unexpected.length > 0) {
|
|
336
|
+
const details: string[] = [];
|
|
337
|
+
if (missing.length > 0) details.push(`missing methods: ${missing.join(" ")}`);
|
|
338
|
+
if (unexpected.length > 0) details.push(`methods not declared by the trait: ${unexpected.join(" ")}`);
|
|
339
|
+
throw new Error(`&impl::new does not conform to trait ${origin.name.toString()}: ${details.join("; ")}`);
|
|
340
|
+
}
|
|
341
|
+
for (const entry of entries) {
|
|
342
|
+
if (typeof entry.value !== "function") {
|
|
343
|
+
throw new Error(`&impl::new expects trait method .${entry.tag.value} to be a function, but received: ${toString(entry.value, true)}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
341
347
|
return new CalcitImpl(implName, fields, values, origin);
|
|
342
348
|
};
|
|
343
349
|
|
|
@@ -1884,6 +1890,7 @@ let calcit_builtin_impls = {
|
|
|
1884
1890
|
fn: null as CalcitImplEntry,
|
|
1885
1891
|
tuple: null as CalcitImplEntry,
|
|
1886
1892
|
record: null as CalcitImplEntry,
|
|
1893
|
+
scalar: null as CalcitImplEntry,
|
|
1887
1894
|
};
|
|
1888
1895
|
|
|
1889
1896
|
// need to register code from outside
|
|
@@ -1951,10 +1958,12 @@ function lookup_impls(obj: CalcitValue): [CalcitImpl[], string] {
|
|
|
1951
1958
|
// impls, so introspection tools like `&methods-of` can answer "what
|
|
1952
1959
|
// methods will instances of this type have" without a concrete instance.
|
|
1953
1960
|
tag = obj.name.toString();
|
|
1954
|
-
|
|
1961
|
+
const builtinRecordImpls = normalize_builtin_impls(calcit_builtin_impls.record) ?? [];
|
|
1962
|
+
impls = [...builtinRecordImpls, ...(obj.impls ?? [])];
|
|
1955
1963
|
} else if (obj instanceof CalcitEnum) {
|
|
1956
1964
|
tag = obj.name();
|
|
1957
|
-
|
|
1965
|
+
const builtinTupleImpls = normalize_builtin_impls(calcit_builtin_impls.tuple) ?? [];
|
|
1966
|
+
impls = [...builtinTupleImpls, ...(obj.impls ?? [])];
|
|
1958
1967
|
} else if (typeof obj === "number") {
|
|
1959
1968
|
tag = "&core-number-methods";
|
|
1960
1969
|
impls = normalize_builtin_impls(calcit_builtin_impls.number);
|
|
@@ -1964,6 +1973,15 @@ function lookup_impls(obj: CalcitValue): [CalcitImpl[], string] {
|
|
|
1964
1973
|
} else if (typeof obj === "function") {
|
|
1965
1974
|
tag = "&core-fn-methods";
|
|
1966
1975
|
impls = normalize_builtin_impls(calcit_builtin_impls.fn);
|
|
1976
|
+
} else if (
|
|
1977
|
+
obj == null ||
|
|
1978
|
+
typeof obj === "boolean" ||
|
|
1979
|
+
obj instanceof CalcitTag ||
|
|
1980
|
+
obj instanceof CalcitSymbol ||
|
|
1981
|
+
obj instanceof CalcitCirruQuote
|
|
1982
|
+
) {
|
|
1983
|
+
tag = "&core-scalar-impls";
|
|
1984
|
+
impls = normalize_builtin_impls(calcit_builtin_impls.scalar);
|
|
1967
1985
|
} else {
|
|
1968
1986
|
return null;
|
|
1969
1987
|
}
|
|
@@ -2110,7 +2128,7 @@ export function _$n_trait_call(traitDef: CalcitValue, method: CalcitValue, obj:
|
|
|
2110
2128
|
let idx = reverse ? impls.length - 1 : 0;
|
|
2111
2129
|
while (reverse ? idx >= 0 : idx < impls.length) {
|
|
2112
2130
|
const impl = impls[idx];
|
|
2113
|
-
if (impl != null && impl.origin
|
|
2131
|
+
if (impl != null && impl.origin === traitDef) {
|
|
2114
2132
|
const fn = impl.getOrNil(methodName);
|
|
2115
2133
|
if (fn != null) {
|
|
2116
2134
|
if (typeof fn !== "function") {
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# 202602131841 trait origin 匹配与结构化 trait 相等性
|
|
2
|
-
|
|
3
|
-
## 背景
|
|
4
|
-
|
|
5
|
-
本次提交延续了动态方法告警收敛与 trait 分发可靠性改进。
|
|
6
|
-
评审中提出的核心问题是:trait 分发不应只依赖 trait 名称匹配。
|
|
7
|
-
`impl` 记录本身已经携带了 trait 的 origin 元数据,因此匹配应直接基于 origin。
|
|
8
|
-
|
|
9
|
-
## 目标
|
|
10
|
-
|
|
11
|
-
1. 让 `&trait-call` 按 trait origin 相等性选择 impl,而不是按名称字符串匹配。
|
|
12
|
-
2. 让 trait/impl 的相等语义与上述运行时选择模型一致。
|
|
13
|
-
3. 在尽量保持兼容的前提下,提高歧义/重名场景下的正确性。
|
|
14
|
-
4. 保持现有优先级规则不变(用户 impl:后者覆盖前者;内建 impl:前者优先)。
|
|
15
|
-
|
|
16
|
-
## 思考过程
|
|
17
|
-
|
|
18
|
-
### 为什么 name-only 匹配不够
|
|
19
|
-
|
|
20
|
-
- 仅按名称匹配会把“同名但结构不同”的 trait 混为一类。
|
|
21
|
-
- 运行时已有 `CalcitImpl.origin: Option<Arc<CalcitTrait>>`,若忽略它会浪费已有语义信息。
|
|
22
|
-
- 使用显式 `&trait-call` 时,调用方预期的是“精确 trait 命中”,而非按名字近似匹配。
|
|
23
|
-
|
|
24
|
-
### 分发策略决定
|
|
25
|
-
|
|
26
|
-
在 `trait_call` 中:
|
|
27
|
-
|
|
28
|
-
- 旧逻辑:`imp.trait_name()` 与 `trait_def.name` 比较。
|
|
29
|
-
- 新逻辑:`imp.origin()` 与目标 trait 直接通过 `Eq` 比较。
|
|
30
|
-
|
|
31
|
-
该方案改动小、语义清晰,并与当前运行时模型一致,不引入额外解析复杂度。
|
|
32
|
-
|
|
33
|
-
### Eq/Hash 一致性
|
|
34
|
-
|
|
35
|
-
当分发切换到 origin 相等后,`CalcitTrait` 的相等语义就不能继续只看 `name`。
|
|
36
|
-
|
|
37
|
-
因此将 `CalcitTrait` 的 Eq/Hash 升级为结构化比较,包含:
|
|
38
|
-
|
|
39
|
-
- trait 名称
|
|
40
|
-
- 方法名列表
|
|
41
|
-
- 方法类型签名
|
|
42
|
-
- requires(依赖 trait)
|
|
43
|
-
- 默认实现槽位形状(每个位置是 `Some` 还是 `None`)
|
|
44
|
-
|
|
45
|
-
关于默认实现:
|
|
46
|
-
|
|
47
|
-
- 默认函数体(`CalcitFn`)不做深比较/深哈希,因为 `CalcitFn` 当前不提供完整 Eq/Hash。
|
|
48
|
-
- 这里只比较默认槽位可用性形状,以保证 Eq/Hash 契约一致,同时提升结构判断准确性。
|
|
49
|
-
|
|
50
|
-
## 文件级改动
|
|
51
|
-
|
|
52
|
-
### 运行时分发与文档
|
|
53
|
-
|
|
54
|
-
- `src/builtins/meta.rs`
|
|
55
|
-
- `trait_call` 改为按 `impl.origin` 相等匹配。
|
|
56
|
-
- 同步更新函数附近注释,确保文档与实现一致。
|
|
57
|
-
|
|
58
|
-
### impl 相等性
|
|
59
|
-
|
|
60
|
-
- `src/calcit/calcit_impl.rs`
|
|
61
|
-
- `PartialEq` 改为直接比较 `origin`(不再只比较 `origin.name`)。
|
|
62
|
-
|
|
63
|
-
### trait 相等性与哈希语义
|
|
64
|
-
|
|
65
|
-
- `src/calcit/calcit_trait.rs`
|
|
66
|
-
- `PartialEq` 从 name-only 改为结构化比较。
|
|
67
|
-
- `Hash` 同步到相同结构维度。
|
|
68
|
-
- 增加注释,说明默认函数比较策略。
|
|
69
|
-
|
|
70
|
-
### 相关一致性修正(同一工作区变更)
|
|
71
|
-
|
|
72
|
-
- `src/runner/preprocess.rs`
|
|
73
|
-
- 修复重命名后的测试守卫符号残留(`DynTraitCheckGuard` -> `WarnDynMethodGuard`)。
|
|
74
|
-
|
|
75
|
-
## 验证
|
|
76
|
-
|
|
77
|
-
- `cargo fmt`
|
|
78
|
-
- `cargo test -q`
|
|
79
|
-
- 结果:当前工作区下测试全部通过。
|
|
80
|
-
|
|
81
|
-
## 兼容性与风险
|
|
82
|
-
|
|
83
|
-
- 该行为变化是有意为之:同名但结构不同的 trait 不再被视为相等。
|
|
84
|
-
- 默认函数体差异仍不纳入 Eq/Hash。
|
|
85
|
-
- 方法分发优先级规则保持不变。
|
|
86
|
-
|
|
87
|
-
## 后续可选项
|
|
88
|
-
|
|
89
|
-
1. 如有需要,可补强默认实现身份比较(例如优先比较 def ref)。
|
|
90
|
-
2. 增加“同名不同结构 trait”相等性的显式测试用例。
|
|
91
|
-
3. 继续收敛 `warn-dyn-method` 全量运行中的剩余动态调用告警。
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# 2026-02-14 20:50 JS codegen recursion + tag migration
|
|
2
|
-
|
|
3
|
-
## 背景
|
|
4
|
-
|
|
5
|
-
在 trait/macro 改进后,继续针对 JavaScript 编译目标做性能与可维护性优化。
|
|
6
|
-
|
|
7
|
-
## 本次改动
|
|
8
|
-
|
|
9
|
-
1. 参数个数报错模板统一
|
|
10
|
-
|
|
11
|
-
- 在 runtime 新增 `_args_fewer_throw` / `_args_between_throw`,保留 `_args_throw`。
|
|
12
|
-
- emitter 中 `too few/too many` 模板改为调用统一 helper,错误信息继续携带期望与实际参数个数。
|
|
13
|
-
|
|
14
|
-
2. rest 参数处理优化
|
|
15
|
-
|
|
16
|
-
- 对 `&` rest 参数,仅在函数体实际引用时才注入 `arrayToList` 转换,避免不必要转换。
|
|
17
|
-
- 修复符号引用检测边界:`contains_symbol` 增加 `Calcit::Local` 分支。
|
|
18
|
-
|
|
19
|
-
3. tail recursion 模板优化
|
|
20
|
-
|
|
21
|
-
- watchdog 从每轮检查改为周期检查(`(times & 1023) === 0` 时再判断上限)。
|
|
22
|
-
- 对无 rest/optional 的固定参数函数,recur 回填改为索引赋值(`arg = ret.args[i]`),减少解构开销。
|
|
23
|
-
|
|
24
|
-
4. tag 初始化一次迁移
|
|
25
|
-
|
|
26
|
-
- runtime 新增 `init_tags` 与全局 tag 缓存。
|
|
27
|
-
- emitter 统一改为 `const _t_ = init_tags([...])` / `$clt.init_tags([...])`。
|
|
28
|
-
- 移除每模块内联 `forEach + newTag` 初始化模板。
|
|
29
|
-
- 修复 `calcit.core` 目标缺失导入,补上 `init_tags` import。
|
|
30
|
-
|
|
31
|
-
## 验证
|
|
32
|
-
|
|
33
|
-
- `yarn check-all` 通过。
|
|
34
|
-
- 额外执行了 JS 微基准(`test-recursion.main/test_loop`)用于观察 recursion 模板优化影响。
|
|
35
|
-
|
|
36
|
-
## 经验点
|
|
37
|
-
|
|
38
|
-
- JS 生成模板优化要先保证语义完整,再做结构性收敛(helper 化/去重复)。
|
|
39
|
-
- 对 codegen 的性能优化,建议配套微基准,并与 baseline 做同脚本对比。
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# 2026-02-14 23:58 emit_js modularization + shift-left contracts
|
|
2
|
-
|
|
3
|
-
## Scope
|
|
4
|
-
|
|
5
|
-
This round focuses on two tracks:
|
|
6
|
-
|
|
7
|
-
1. Continue low-risk modularization of `src/codegen/emit_js.rs` without changing runtime semantics.
|
|
8
|
-
2. Introduce AI-oriented "shift-left" validation contracts for expected warning/error paths.
|
|
9
|
-
|
|
10
|
-
## What changed
|
|
11
|
-
|
|
12
|
-
### Rust codegen modularization
|
|
13
|
-
|
|
14
|
-
- Removed duplicate legacy module file:
|
|
15
|
-
- `src/calcit/struct.rs`
|
|
16
|
-
- Split helpers from `emit_js.rs` into cohesive submodules:
|
|
17
|
-
- `src/codegen/emit_js/tags.rs`
|
|
18
|
-
- `src/codegen/emit_js/symbols.rs`
|
|
19
|
-
- `src/codegen/emit_js/paths.rs`
|
|
20
|
-
- `src/codegen/emit_js/runtime.rs`
|
|
21
|
-
- `src/codegen/emit_js/args.rs`
|
|
22
|
-
- `src/codegen/emit_js/deps.rs`
|
|
23
|
-
- `src/codegen/emit_js/helpers.rs`
|
|
24
|
-
- Kept behavior stable by only moving logic and wiring imports/call sites.
|
|
25
|
-
- Added targeted unit tests in extracted modules.
|
|
26
|
-
|
|
27
|
-
### Runtime helper boundary cleanup (TS)
|
|
28
|
-
|
|
29
|
-
- Grouped runtime helpers into dedicated modules:
|
|
30
|
-
- `ts-src/js-arity-helpers.mts` (`_args_throw`, `_args_fewer_throw`, `_args_between_throw`)
|
|
31
|
-
- `ts-src/js-tag-helpers.mts` (`init_tags` + internal cache)
|
|
32
|
-
- Switched `ts-src/calcit.procs.mts` to re-export these modules, keeping public API names unchanged.
|
|
33
|
-
|
|
34
|
-
### Test/validation workflow improvements
|
|
35
|
-
|
|
36
|
-
- Added contract-based shift-left script:
|
|
37
|
-
- `scripts/check-shift-left.mjs`
|
|
38
|
-
- Added npm script:
|
|
39
|
-
- `check-shift-left` in `package.json`
|
|
40
|
-
- This script enforces both:
|
|
41
|
-
- positive baseline must pass (`calcit/test.cirru -1`)
|
|
42
|
-
- selected negative cases must fail with expected diagnostic tokens.
|
|
43
|
-
|
|
44
|
-
### Planning/documentation updates
|
|
45
|
-
|
|
46
|
-
- Expanded and updated roadmap status:
|
|
47
|
-
- `drafts/project-modernization-roadmap.md`
|
|
48
|
-
- Added AI-oriented long-term section for:
|
|
49
|
-
- immutable core constraints
|
|
50
|
-
- earlier error detection
|
|
51
|
-
- contractized diagnostics
|
|
52
|
-
- staged execution strategy.
|
|
53
|
-
|
|
54
|
-
## Verification
|
|
55
|
-
|
|
56
|
-
- Ran targeted unit tests for extracted modules (`tags/symbols/paths/runtime/args/deps/helpers` where applicable).
|
|
57
|
-
- Repeated full validation with `yarn check-all` after each refactor batch.
|
|
58
|
-
- Ran `yarn check-shift-left` to validate diagnostic contracts.
|
|
59
|
-
|
|
60
|
-
## Notes
|
|
61
|
-
|
|
62
|
-
- Some standalone `calcit/test-*.cirru` files are intentionally warning/error reproductions or independent package entries; they are not safe to inline into `test.cirru` module list directly.
|
|
63
|
-
- Using a separate shift-left contract script avoids namespace collisions and preserves intent.
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# 2026-02-15 diagnostics 合并记录
|
|
2
|
-
|
|
3
|
-
本文件合并以下 diagnostics 相关记录,避免碎片化:
|
|
4
|
-
|
|
5
|
-
- 2026-0215-1011-preprocess-diagnostic-v1.md
|
|
6
|
-
- 2026-0215-1026-cli-diag-json.md
|
|
7
|
-
- 2026-0215-1104-diag-expected-actual-action-let.md
|
|
8
|
-
- 2026-0215-1110-eval-diag-fallbacks.md
|
|
9
|
-
- 2026-0215-1116-macro-diagnostic-protocol.md
|
|
10
|
-
- 2026-0215-1134-macro-diag-expansion-if-defn-assert.md
|
|
11
|
-
- 2026-0215-1152-runtime-fallback-tag-match-arity.md
|
|
12
|
-
- 2026-0215-1202-warning-arity-fallback-compat.md
|
|
13
|
-
- 2026-0215-1211-warning-learning-fields.md
|
|
14
|
-
- 2026-0215-1238-convergence-help-docs-diag.md
|
|
15
|
-
- 2026-0215-1306-text-diagnostics-convergence-fix.md
|
|
16
|
-
- 2026-0215-1332-diagnostics-simplification-example-driven.md
|
|
17
|
-
|
|
18
|
-
## 合并后的结论(当前保留)
|
|
19
|
-
|
|
20
|
-
- 已移除 `--diag json` 路径,CLI 统一使用文本诊断输出。
|
|
21
|
-
- warning 维持最小字段与文本展示,不再维护 JSON 结构演进。
|
|
22
|
-
- error 维持 call stack + examples 辅助定位,避免复杂规则映射。
|
|
23
|
-
- 文本模式保持简洁:优先 message/hint/location/stack,便于直接修复。
|
|
24
|
-
|
|
25
|
-
## 本轮简化(减法)
|
|
26
|
-
|
|
27
|
-
- 移除 warning 侧复杂增强字段:`fingerprint/convergence/help/learning`。
|
|
28
|
-
- 移除 error 侧复杂增强字段:`fingerprint/convergence/help/learning` 与大段规则映射。
|
|
29
|
-
- 将 error 的 expected/actual/action 处理改为“hint 优先 + 通用 message 提取 + 最小 fallback”。
|
|
30
|
-
|
|
31
|
-
## 设计原则(后续继续遵循)
|
|
32
|
-
|
|
33
|
-
- 诊断能力优先复用编译器已有信息(hint、message、stack、examples)。
|
|
34
|
-
- 尽量减少按错误码硬编码规则,避免语言层复杂度膨胀。
|
|
35
|
-
- LLM 修复入口尽量通用化:`query examples` + 最小可执行动作。
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Macro Diagnostics Refinement (2026-02-15 19:41)
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
This change improves diagnostic quality for macro misuse and warning flows without changing macro semantics.
|
|
6
|
-
|
|
7
|
-
## Key updates
|
|
8
|
-
|
|
9
|
-
- Added a shared diagnostics helper module:
|
|
10
|
-
- `src/diagnostics_help.rs`
|
|
11
|
-
- Centralizes message-to-help inference logic.
|
|
12
|
-
- Improved stack-rendered failure guidance:
|
|
13
|
-
- `src/call_stack.rs`
|
|
14
|
-
- Uses macro-context-aware help text.
|
|
15
|
-
- Keeps examples targeting user-facing macros over internal helper macros.
|
|
16
|
-
- Improved warning-path guidance:
|
|
17
|
-
- `src/bin/cr.rs`
|
|
18
|
-
- Reuses shared help inference for preprocessing/codegen warning blocks.
|
|
19
|
-
- Improved macro argument binding diagnostics in runtime:
|
|
20
|
-
- `src/runner.rs`
|
|
21
|
-
- Replaces low-level `Idx(...)` style arity failures with readable signatures and missing argument names.
|
|
22
|
-
- Refined macro-side error wording:
|
|
23
|
-
- `src/cirru/calcit-core.cirru`
|
|
24
|
-
- Better `list-match` branch-shape messages.
|
|
25
|
-
- Kept macro signatures intact where requested:
|
|
26
|
-
- `when`, `when-not`, `when-let` remain with explicit parameter forms.
|
|
27
|
-
|
|
28
|
-
## Validation
|
|
29
|
-
|
|
30
|
-
- Spot checks executed with `cr eval` for macro misuse cases:
|
|
31
|
-
- `when`, `when-not`, `when-let`, `if-not`, `tag-match`, `record-match`, `list-match`, `cond`, `let`, `thread-first`, `thread-last`.
|
|
32
|
-
- Confirmed help text differentiates macro misuse vs proc/function arity warnings.
|
|
33
|
-
- Full regression passed:
|
|
34
|
-
- `yarn check-all` => `EXIT:0`.
|
|
35
|
-
|
|
36
|
-
## Notes
|
|
37
|
-
|
|
38
|
-
- This iteration focuses on user-facing diagnostics quality.
|
|
39
|
-
- Behavior and compatibility are preserved; changes are primarily in error/help reporting paths.
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# 2026-02-16 20:43 core API/docs cleanup
|
|
2
|
-
|
|
3
|
-
## Scope
|
|
4
|
-
|
|
5
|
-
- Cleaned outdated draft references and status notes.
|
|
6
|
-
- Aligned core internal API names around trait attachment (`*:impl-traits`).
|
|
7
|
-
- Fixed `wo-js-log` export/definition mismatch.
|
|
8
|
-
- Merged symbol-resolution note into drafts and removed duplicated doc file.
|
|
9
|
-
|
|
10
|
-
## Key updates
|
|
11
|
-
|
|
12
|
-
1. **drafts cleanup**
|
|
13
|
-
- Added `drafts/README.md` as a state index (active/review-needed/archived).
|
|
14
|
-
- Fixed stale links between `assert-types-plan.md` and `assert-types.md`.
|
|
15
|
-
- Marked `drafts/last-session.md` as archived historical snapshot.
|
|
16
|
-
|
|
17
|
-
2. **core naming consistency**
|
|
18
|
-
- Updated internal entries in `src/cirru/calcit-core.cirru`:
|
|
19
|
-
- `&record:with-impls` -> `&record:impl-traits`
|
|
20
|
-
- `&tuple:with-impls` -> `&tuple:impl-traits`
|
|
21
|
-
- `&struct:with-impls` -> `&struct:impl-traits`
|
|
22
|
-
- `&enum:with-impls` -> `&enum:impl-traits`
|
|
23
|
-
- Updated `%::` doc hint to reference `&tuple:impl-traits`.
|
|
24
|
-
|
|
25
|
-
3. **debug macro fix**
|
|
26
|
-
- Fixed `wo-js-log` entry to define `wo-js-log` (not `w-js-log`).
|
|
27
|
-
|
|
28
|
-
4. **symbol note consolidation**
|
|
29
|
-
- Appended symbol-resolution appendix into `drafts/runtime-traits-plan.md`.
|
|
30
|
-
- Removed duplicated `docs/symbol-spec.md` after migration.
|
|
31
|
-
|
|
32
|
-
## Validation notes
|
|
33
|
-
|
|
34
|
-
- Verified `wo-js-log` evaluates successfully.
|
|
35
|
-
- Verified `&struct:impl-traits` resolves as runtime proc.
|
|
36
|
-
- Confirmed old `&struct:with-impls` now reports unknown symbol (no compatibility layer, by design).
|
|
37
|
-
|
|
38
|
-
## Follow-up
|
|
39
|
-
|
|
40
|
-
- If needed, add explicit migration note/changelog entry for removed `*-with-impls` internal names.
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# 2026-0223-0834 — 迁移到 defstruct 方案并实现 `%{}?` 可选字段 Record 宏
|
|
2
|
-
|
|
3
|
-
## 背景
|
|
4
|
-
|
|
5
|
-
将 Calcit Record 系统从旧的 `new-record`/`defrecord`/`defrecord!` 方案全面迁移到基于 `defstruct` 的新方案,同时新增 `%{}?` / `&%{}?` 支持可选字段初始化与更新。
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 知识点一:`%{}?` 与 `&%{}?` 的语义设计
|
|
10
|
-
|
|
11
|
-
`struct` 初始化为 record 时,部分字段在语义上是可选的,对应 TypeScript 中的 `{ a?: number; b?: number }`。原有的 `%{}` / `&%{}` 要求所有字段都必须显式传入。
|
|
12
|
-
|
|
13
|
-
### `%{}?`(macro)
|
|
14
|
-
|
|
15
|
-
- 初始化 record 时允许省略字段,省略的字段自动填 `nil`。
|
|
16
|
-
- 用法:`%{}? MyRecord (:x 1)`
|
|
17
|
-
|
|
18
|
-
### `&%{}?`(proc)
|
|
19
|
-
|
|
20
|
-
`call_record_partial` 的语义:
|
|
21
|
-
|
|
22
|
-
- **proto 是 Struct**:以全 `nil` 为基础 `values`,用传入的 k-v 覆盖对应位置。
|
|
23
|
-
- 传入未知字段 → 报错;传入重复字段 → 报错;`(args_size - 1) % 2 != 0` → 报错。
|
|
24
|
-
|
|
25
|
-
关键实现细节:`CalcitStruct.fields` 元素类型是 `EdnTag`,比较时用 `f.ref_str()` 而非 `f.as_ref()`(后者无 `AsRef` impl)。
|
|
26
|
-
|
|
27
|
-
### `%{}?` 宏定义
|
|
28
|
-
|
|
29
|
-
```cirru
|
|
30
|
-
defmacro %{}? (R & xs)
|
|
31
|
-
if
|
|
32
|
-
not $ and (list? xs) (every? xs list?)
|
|
33
|
-
raise $ str-spaced "|%{}? expects field entries in list, got:" xs
|
|
34
|
-
&let
|
|
35
|
-
args $ &list:concat & xs
|
|
36
|
-
quasiquote $ &%{}? ~R ~@args
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## 知识点二:Rust proc 注册流程
|
|
42
|
-
|
|
43
|
-
新增一个内置 proc 需要同时修改四处:
|
|
44
|
-
|
|
45
|
-
| 文件 | 修改内容 |
|
|
46
|
-
| -------------------------- | -------------------------------------------------------- |
|
|
47
|
-
| `src/calcit/proc_name.rs` | 添加枚举变体 `NativeRecordPartial` + `ProcTypeSignature` |
|
|
48
|
-
| `src/builtins/records.rs` | 实现 `call_record_partial` 函数 |
|
|
49
|
-
| `src/builtins.rs` | 在 `match proc` 中添加分发分支 |
|
|
50
|
-
| `src/runner/preprocess.rs` | 将新 proc 加入"跳过 arity 检查"的 `matches!` 列表 |
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## 知识点三:`%{}` 严格要求 Struct proto
|
|
55
|
-
|
|
56
|
-
- `call_record`(`%{}`):若 proto 为 `Calcit::Record`,直接返回错误提示改用 `defstruct`。
|
|
57
|
-
- `defstruct` 产生 `Calcit::Struct`(含 `field_types`),并作为 `%{}` / `%{}?` 的唯一原型来源。
|
|
58
|
-
|
|
59
|
-
### `&record:get-name` / `&record:struct` 的参数约束
|
|
60
|
-
|
|
61
|
-
- 两者统一要求传入 `record`,避免 `struct` / `record` 混用语义。
|
|
62
|
-
|
|
63
|
-
### `&record:matches?` 的参数约束
|
|
64
|
-
|
|
65
|
-
- 第一参数要求 `record`。
|
|
66
|
-
- 第二参数接受 `record` 或 `struct`(用于 `record-match` 的模式匹配场景)。
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## 修改文件
|
|
71
|
-
|
|
72
|
-
| 文件 | 变更内容 |
|
|
73
|
-
| ----------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
74
|
-
| `src/calcit/proc_name.rs` | 新增 `NativeRecordPartial` 枚举变体与类型签名;移除 `NewRecord` 变体 |
|
|
75
|
-
| `src/builtins/records.rs` | 新增 `call_record_partial`(struct-only);`matches` 调整为 `(record, record/struct)`;移除 `new_record` 函数 |
|
|
76
|
-
| `src/builtins.rs` | 分发 `NativeRecordPartial`;移除 `NewRecord` 分发 |
|
|
77
|
-
| `src/runner/preprocess.rs` | arity 检查豁免新增 `NativeRecordPartial` |
|
|
78
|
-
| `src/cirru/calcit-core.cirru` | 新增 `%{}?` 宏定义与 `&%{}?` 文档条目;`defrecord`/`defrecord!` 改为 raise error;删除 `new-record` 定义 |
|
|
79
|
-
| `calcit/test-record.cirru` | Cat/BirdShape/Person/City/A/B/C/Demo 全部改为 `defstruct`;删除所有 `new-record` let 绑定;修复各测试函数体 |
|
|
80
|
-
| `docs/CalcitAgent.md` | 类型标注示例中 `new-record` 改为 `defstruct` |
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## 验证
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
cargo run --bin cr -- calcit/test-record.cirru -1
|
|
88
|
-
cargo clippy -- -D warnings
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
全部通过,无 warning。
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# 2026-0223 命名空间 imports 操作 Bug 修复
|
|
2
|
-
|
|
3
|
-
## 背景
|
|
4
|
-
|
|
5
|
-
通过在 `demos/calcit.cirru` 上逐一测试 `cr edit` 的 namespace 相关子命令,发现三处导致 Agent 频繁用错的根本原因。
|
|
6
|
-
|
|
7
|
-
## 发现的 Bug
|
|
8
|
-
|
|
9
|
-
### Bug 1:`imports --code 'rule'` 产生平坦结构,与 `extract_require_rules` 不兼容
|
|
10
|
-
|
|
11
|
-
- **现象**:`imports --code 'respo.core :refer $ sym'` 成功,但之后执行 `add-import` 会丢失已有 imports
|
|
12
|
-
- **根因**:`handle_imports` 手工拼接 `ns_code_items`(平坦 list),产生结构:
|
|
13
|
-
```
|
|
14
|
-
["ns", "my.ns", ":require", "respo.core", ":refer", "$", "sym"]
|
|
15
|
-
```
|
|
16
|
-
而 `extract_require_rules`/`build_ns_code` 期望嵌套结构:
|
|
17
|
-
```
|
|
18
|
-
["ns", "my.ns", [":require", ["respo.core", ":refer", "$", "sym"]]]
|
|
19
|
-
```
|
|
20
|
-
导致后续任何依赖 `extract_require_rules` 的操作(`add-import`、`rm-import`)全部解析不到已有规则。
|
|
21
|
-
- **修复**:重写 `handle_imports` 的 rules 解析逻辑,统一调用 `build_ns_code` 生成嵌套结构。同时自动区分输入是单条规则(flat array of strings)还是多条规则(array of arrays)。
|
|
22
|
-
|
|
23
|
-
### Bug 2:`imports --code ':require ...'` 静默产生 `:require :require` 重复
|
|
24
|
-
|
|
25
|
-
- **现象**:写 `:require respo.core :refer $ sym` 不报错,但生成 `ns my.ns :require :require respo.core ...`
|
|
26
|
-
- **修复**:当 Cirru 解析后发现数组第一元素为 `:require` 字符串,立即返回错误消息,引导用户不包含 `:require` 前缀。
|
|
27
|
-
|
|
28
|
-
### Bug 3:`add-ns --code 'ns WRONG_NAME ...'` 名称不一致静默通过
|
|
29
|
-
|
|
30
|
-
- **现象**:`cr edit add-ns my.ns --code 'ns wrong.ns ...'` 成功,file-key 是 `my.ns`,但 ns 声明内写的是 `wrong.ns`,导致 `query ns my.ns` 看到内部名称错误
|
|
31
|
-
- **修复**:当输入解析为 `ns` 表达式时,校验第二个元素是否与位置参数一致,不一致则 Error。
|
|
32
|
-
|
|
33
|
-
## 修改文件
|
|
34
|
-
|
|
35
|
-
- `src/bin/cli_handlers/edit.rs`:`handle_imports`、`handle_add_ns` 函数
|
|
36
|
-
|
|
37
|
-
## 知识点
|
|
38
|
-
|
|
39
|
-
- `imports` 命令的 `--code` 输入格式:**不含 `:require` 前缀**,直接是规则体(`src-ns :refer $ sym`)。单条规则用 `--code`,多条规则用 `--file`(每行一条)或通过 stdin 传 JSON 数组(元素为数组)。
|
|
40
|
-
- `add-import` 和 `imports` 的格式一致,都是 `src-ns :refer $ sym`(无 `:require` 前缀)。
|
|
41
|
-
- `add-ns --code` 中若传完整 `ns` 表达式,内部名称必须与位置参数完全匹配。
|
|
42
|
-
- 最佳实践:优先使用 `add-import`(带保护和覆盖控制),`imports` 只在需要全量重置时使用。
|