aontu 0.52.1 → 0.53.0
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/README.md +88 -0
- package/bin/aontu-mcp.js +4 -0
- package/dist/agentsmd.d.ts +16 -0
- package/dist/agentsmd.js +107 -0
- package/dist/agentsmd.js.map +1 -0
- package/dist/aontu.d.ts +14 -3
- package/dist/aontu.js +96 -4
- package/dist/aontu.js.map +1 -1
- package/dist/cli.d.ts +44 -1
- package/dist/cli.js +2401 -44
- package/dist/cli.js.map +1 -1
- package/dist/ctx.d.ts +13 -0
- package/dist/ctx.js +43 -0
- package/dist/ctx.js.map +1 -1
- package/dist/diff.d.ts +22 -0
- package/dist/diff.js +141 -0
- package/dist/diff.js.map +1 -0
- package/dist/err.d.ts +3 -1
- package/dist/err.js +38 -7
- package/dist/err.js.map +1 -1
- package/dist/graph.d.ts +16 -0
- package/dist/graph.js +73 -0
- package/dist/graph.js.map +1 -0
- package/dist/hcanon.d.ts +3 -0
- package/dist/hcanon.js +146 -0
- package/dist/hcanon.js.map +1 -0
- package/dist/hints.js +167 -4
- package/dist/hints.js.map +1 -1
- package/dist/jsonschema.d.ts +20 -0
- package/dist/jsonschema.js +391 -0
- package/dist/jsonschema.js.map +1 -0
- package/dist/lang.js +512 -69
- package/dist/lang.js.map +1 -1
- package/dist/lsp.d.ts +9 -2
- package/dist/lsp.js +262 -47
- package/dist/lsp.js.map +1 -1
- package/dist/mcp-server.d.ts +20 -0
- package/dist/mcp-server.js +147 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp.d.ts +42 -0
- package/dist/mcp.js +814 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mod-tool.d.ts +58 -0
- package/dist/mod-tool.js +498 -0
- package/dist/mod-tool.js.map +1 -0
- package/dist/mod.d.ts +31 -0
- package/dist/mod.js +250 -0
- package/dist/mod.js.map +1 -0
- package/dist/patch.d.ts +44 -0
- package/dist/patch.js +506 -0
- package/dist/patch.js.map +1 -0
- package/dist/provenance.d.ts +40 -0
- package/dist/provenance.js +335 -0
- package/dist/provenance.js.map +1 -0
- package/dist/query.d.ts +27 -0
- package/dist/query.js +294 -0
- package/dist/query.js.map +1 -0
- package/dist/reach.d.ts +14 -0
- package/dist/reach.js +140 -0
- package/dist/reach.js.map +1 -0
- package/dist/relation.d.ts +19 -0
- package/dist/relation.js +305 -0
- package/dist/relation.js.map +1 -0
- package/dist/report-sarif.d.ts +14 -0
- package/dist/report-sarif.js +102 -0
- package/dist/report-sarif.js.map +1 -0
- package/dist/site.d.ts +4 -0
- package/dist/site.js +31 -0
- package/dist/site.js.map +1 -1
- package/dist/std.d.ts +1 -0
- package/dist/std.js +73 -0
- package/dist/std.js.map +1 -0
- package/dist/subsume.d.ts +39 -0
- package/dist/subsume.js +526 -0
- package/dist/subsume.js.map +1 -0
- package/dist/trim.d.ts +19 -0
- package/dist/trim.js +155 -0
- package/dist/trim.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +17 -1
- package/dist/type.js.map +1 -1
- package/dist/unify.d.ts +2 -1
- package/dist/unify.js +253 -36
- package/dist/unify.js.map +1 -1
- package/dist/utility.d.ts +9 -1
- package/dist/utility.js +122 -1
- package/dist/utility.js.map +1 -1
- package/dist/val/AggFuncVal.d.ts +33 -0
- package/dist/val/AggFuncVal.js +202 -0
- package/dist/val/AggFuncVal.js.map +1 -0
- package/dist/val/ArithFuncVal.d.ts +31 -0
- package/dist/val/ArithFuncVal.js +62 -0
- package/dist/val/ArithFuncVal.js.map +1 -0
- package/dist/val/BagVal.d.ts +5 -0
- package/dist/val/BagVal.js +96 -5
- package/dist/val/BagVal.js.map +1 -1
- package/dist/val/CloseFuncVal.js +9 -1
- package/dist/val/CloseFuncVal.js.map +1 -1
- package/dist/val/ConjunctVal.d.ts +1 -1
- package/dist/val/ConjunctVal.js +19 -0
- package/dist/val/ConjunctVal.js.map +1 -1
- package/dist/val/ConstraintVal.d.ts +7 -1
- package/dist/val/ConstraintVal.js +490 -40
- package/dist/val/ConstraintVal.js.map +1 -1
- package/dist/val/CopyFuncVal.d.ts +1 -2
- package/dist/val/CopyFuncVal.js +7 -0
- package/dist/val/CopyFuncVal.js.map +1 -1
- package/dist/val/Decimal.d.ts +1 -0
- package/dist/val/Decimal.js +13 -0
- package/dist/val/Decimal.js.map +1 -1
- package/dist/val/DeprecateFuncVal.d.ts +11 -0
- package/dist/val/DeprecateFuncVal.js +47 -0
- package/dist/val/DeprecateFuncVal.js.map +1 -0
- package/dist/val/DisjunctVal.js +130 -21
- package/dist/val/DisjunctVal.js.map +1 -1
- package/dist/val/EachFuncVal.d.ts +15 -0
- package/dist/val/EachFuncVal.js +75 -0
- package/dist/val/EachFuncVal.js.map +1 -0
- package/dist/val/ExpectVal.js +27 -4
- package/dist/val/ExpectVal.js.map +1 -1
- package/dist/val/FeatureVal.js +1 -1
- package/dist/val/FeatureVal.js.map +1 -1
- package/dist/val/FilterFuncVal.d.ts +15 -0
- package/dist/val/FilterFuncVal.js +91 -0
- package/dist/val/FilterFuncVal.js.map +1 -0
- package/dist/val/FuncBaseVal.d.ts +6 -1
- package/dist/val/FuncBaseVal.js +171 -1
- package/dist/val/FuncBaseVal.js.map +1 -1
- package/dist/val/HideFuncVal.js.map +1 -1
- package/dist/val/IdFuncVal.d.ts +13 -0
- package/dist/val/IdFuncVal.js +54 -0
- package/dist/val/IdFuncVal.js.map +1 -0
- package/dist/val/JunctionVal.js +7 -1
- package/dist/val/JunctionVal.js.map +1 -1
- package/dist/val/KeyFuncVal.d.ts +1 -1
- package/dist/val/KeyFuncVal.js +38 -30
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/ListVal.js +101 -14
- package/dist/val/ListVal.js.map +1 -1
- package/dist/val/LowerFuncVal.js.map +1 -1
- package/dist/val/MapVal.js +93 -8
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MatchFuncVal.d.ts +15 -0
- package/dist/val/MatchFuncVal.js +107 -0
- package/dist/val/MatchFuncVal.js.map +1 -0
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/NilVal.js +24 -0
- package/dist/val/NilVal.js.map +1 -1
- package/dist/val/OpBaseVal.d.ts +1 -1
- package/dist/val/OpBaseVal.js +19 -1
- package/dist/val/OpBaseVal.js.map +1 -1
- package/dist/val/OpenFuncVal.js +4 -1
- package/dist/val/OpenFuncVal.js.map +1 -1
- package/dist/val/PackFuncVal.d.ts +15 -0
- package/dist/val/PackFuncVal.js +108 -0
- package/dist/val/PackFuncVal.js.map +1 -0
- package/dist/val/PathFuncVal.js.map +1 -1
- package/dist/val/PlaceVal.d.ts +13 -0
- package/dist/val/PlaceVal.js +131 -0
- package/dist/val/PlaceVal.js.map +1 -0
- package/dist/val/PlusOpVal.js +11 -2
- package/dist/val/PlusOpVal.js.map +1 -1
- package/dist/val/PrefFuncVal.js.map +1 -1
- package/dist/val/PrefVal.d.ts +2 -2
- package/dist/val/PrefVal.js +78 -23
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/RefVal.d.ts +1 -1
- package/dist/val/RefVal.js +89 -7
- package/dist/val/RefVal.js.map +1 -1
- package/dist/val/ReferFuncVal.d.ts +36 -0
- package/dist/val/ReferFuncVal.js +303 -0
- package/dist/val/ReferFuncVal.js.map +1 -0
- package/dist/val/ScalarKindVal.d.ts +1 -2
- package/dist/val/ScalarKindVal.js +0 -11
- package/dist/val/ScalarKindVal.js.map +1 -1
- package/dist/val/TopVal.js.map +1 -1
- package/dist/val/TypeFuncVal.js.map +1 -1
- package/dist/val/UpperFuncVal.js.map +1 -1
- package/dist/val/Val.d.ts +8 -1
- package/dist/val/Val.js +150 -1
- package/dist/val/Val.js.map +1 -1
- package/dist/val/VarVal.js.map +1 -1
- package/dist/val/arith.d.ts +6 -0
- package/dist/val/arith.js +170 -0
- package/dist/val/arith.js.map +1 -0
- package/dist/vet.d.ts +45 -0
- package/dist/vet.js +776 -0
- package/dist/vet.js.map +1 -0
- package/dist/walk.d.ts +2 -0
- package/dist/walk.js +91 -0
- package/dist/walk.js.map +1 -0
- package/grammar/aontu.gbnf +130 -0
- package/grammar/aontu.lark +113 -0
- package/package.json +21 -6
- package/skill/SKILL.md +37 -0
- package/skill/error-codes.md +62 -0
- package/skill/examples.md +99 -0
- package/skill/grammar-card.md +57 -0
- package/src/agentsmd.ts +135 -0
- package/src/aontu.ts +135 -4
- package/src/cli.ts +2858 -71
- package/src/ctx.ts +73 -1
- package/src/diff.ts +196 -0
- package/src/err.ts +42 -7
- package/src/graph.ts +135 -0
- package/src/hcanon.ts +169 -0
- package/src/hints.ts +208 -4
- package/src/jsonschema.ts +511 -0
- package/src/lang.ts +570 -70
- package/src/lsp.ts +281 -48
- package/src/mcp-server.ts +187 -0
- package/src/mcp.ts +993 -0
- package/src/mod-tool.ts +679 -0
- package/src/mod.ts +344 -0
- package/src/patch.ts +624 -0
- package/src/provenance.ts +430 -0
- package/src/query.ts +379 -0
- package/src/reach.ts +184 -0
- package/src/relation.ts +395 -0
- package/src/report-sarif.ts +137 -0
- package/src/site.ts +36 -1
- package/src/std.ts +73 -0
- package/src/subsume.ts +690 -0
- package/src/trim.ts +195 -0
- package/src/tsconfig.json +10 -4
- package/src/type.ts +51 -2
- package/src/unify.ts +274 -36
- package/src/utility.ts +139 -1
- package/src/val/AggFuncVal.ts +319 -0
- package/src/val/ArithFuncVal.ts +108 -0
- package/src/val/BagVal.ts +101 -4
- package/src/val/CloseFuncVal.ts +9 -1
- package/src/val/ConjunctVal.ts +20 -0
- package/src/val/ConstraintVal.ts +542 -43
- package/src/val/CopyFuncVal.ts +7 -1
- package/src/val/Decimal.ts +15 -0
- package/src/val/DeprecateFuncVal.ts +84 -0
- package/src/val/DisjunctVal.ts +139 -28
- package/src/val/EachFuncVal.ts +133 -0
- package/src/val/ExpectVal.ts +28 -6
- package/src/val/FeatureVal.ts +1 -1
- package/src/val/FilterFuncVal.ts +154 -0
- package/src/val/FuncBaseVal.ts +192 -1
- package/src/val/HideFuncVal.ts +0 -2
- package/src/val/IdFuncVal.ts +91 -0
- package/src/val/JunctionVal.ts +7 -1
- package/src/val/KeyFuncVal.ts +39 -35
- package/src/val/ListVal.ts +108 -15
- package/src/val/LowerFuncVal.ts +0 -1
- package/src/val/MapVal.ts +99 -8
- package/src/val/MatchFuncVal.ts +176 -0
- package/src/val/MoveFuncVal.ts +0 -2
- package/src/val/NilVal.ts +25 -0
- package/src/val/OpBaseVal.ts +20 -1
- package/src/val/OpenFuncVal.ts +4 -2
- package/src/val/PackFuncVal.ts +175 -0
- package/src/val/PathFuncVal.ts +0 -1
- package/src/val/PlaceVal.ts +193 -0
- package/src/val/PlusOpVal.ts +11 -2
- package/src/val/PrefFuncVal.ts +0 -1
- package/src/val/PrefVal.ts +79 -36
- package/src/val/RefVal.ts +91 -8
- package/src/val/ReferFuncVal.ts +387 -0
- package/src/val/ScalarKindVal.ts +0 -13
- package/src/val/TopVal.ts +0 -1
- package/src/val/TypeFuncVal.ts +0 -2
- package/src/val/UpperFuncVal.ts +0 -1
- package/src/val/Val.ts +205 -2
- package/src/val/VarVal.ts +0 -1
- package/src/val/arith.ts +316 -0
- package/src/vet.ts +992 -0
- package/src/walk.ts +99 -0
package/src/val/ConstraintVal.ts
CHANGED
|
@@ -57,6 +57,7 @@ import { empty } from './Val'
|
|
|
57
57
|
import { cmpCodePoint } from '../keyorder'
|
|
58
58
|
|
|
59
59
|
import { ConjunctVal } from './ConjunctVal'
|
|
60
|
+
import { sizingResidue } from './BagVal'
|
|
60
61
|
|
|
61
62
|
import { top } from './top'
|
|
62
63
|
|
|
@@ -115,6 +116,8 @@ type ConstraintState = {
|
|
|
115
116
|
// over the integer domain -- the count atom reuses
|
|
116
117
|
// this same algebra recursively
|
|
117
118
|
uniq: boolean // members must be pairwise distinct (unique())
|
|
119
|
+
uniqBy: string[] // ... and distinct ON EACH OF THESE KEYS
|
|
120
|
+
// (unique(k)), sorted and deduplicated
|
|
118
121
|
musts: MustAtom[] // Band B checks, kept in written order, never simplified
|
|
119
122
|
clash?: boolean // a kind disagreement inside a length() argument, recorded
|
|
120
123
|
// rather than raised: the argument's own meet has no
|
|
@@ -180,6 +183,18 @@ type ConstraintState = {
|
|
|
180
183
|
// and `test/spec/files/regex-corpus.txt` pins that the two produce
|
|
181
184
|
// byte-identical output for every pattern in a generated corpus.
|
|
182
185
|
|
|
186
|
+
// The largest repeat count Aontu's pattern language admits. RE2 caps a
|
|
187
|
+
// repeat at 1000 and refuses to compile past it, where JavaScript's
|
|
188
|
+
// backtracking engine accepts any count -- so `re("^a{1001}$")` was
|
|
189
|
+
// VALID in TypeScript and an `error` verdict in Go, a cross-port
|
|
190
|
+
// verdict flip on a schema an agent could be handed
|
|
191
|
+
// (status-2026-08-21.md section 4). Under ADR-003 the host's own
|
|
192
|
+
// compile failure must never be what a user sees, so the bound is
|
|
193
|
+
// Aontu's: at most RE_REPEAT_MAX, refused identically in both ports
|
|
194
|
+
// before either engine compiles. Nested products beyond the cap were
|
|
195
|
+
// already refused, by the quantified-group rule below.
|
|
196
|
+
const RE_REPEAT_MAX = 1000
|
|
197
|
+
|
|
183
198
|
// The normative expansions. These are Aontu's definitions, not either
|
|
184
199
|
// host's; both hosts are rewritten to them.
|
|
185
200
|
const RE_CLASS_DIGIT = '0-9'
|
|
@@ -196,6 +211,67 @@ const RE_ESCAPE_PUNCT = '\\.+*?()[]{}|^$/'
|
|
|
196
211
|
// word boundary, and `\xHH`. Each was probed in both engines.
|
|
197
212
|
const RE_ESCAPE_PASS = 'tnrfv'
|
|
198
213
|
|
|
214
|
+
// A counted quantifier `{n}`, `{n,}` or `{n,m}` starting at `src[at]`.
|
|
215
|
+
// Two rules, both about what the hosts do NOT share:
|
|
216
|
+
//
|
|
217
|
+
// - A bound above RE_REPEAT_MAX: RE2 refuses to compile it, JavaScript
|
|
218
|
+
// accepts it.
|
|
219
|
+
// - A brace that does not open a well-formed counted quantifier at
|
|
220
|
+
// all (`x{y}`, `a{`, `{,5}`): JavaScript compiled with the `u` flag
|
|
221
|
+
// makes it a SYNTAX ERROR, while RE2 reads it as a literal brace, so
|
|
222
|
+
// `re("^x{y}$")` was `constraint_pattern` in TypeScript and a plain
|
|
223
|
+
// unresolved value in Go -- the same class of verdict flip as the
|
|
224
|
+
// repeat cap, found by sweeping around it. A literal brace is
|
|
225
|
+
// written escaped (`a\\{1001\\}`), which both engines share.
|
|
226
|
+
function repeatWhy(src: string, at: number): [string, number] {
|
|
227
|
+
const bad = (what: string): [string, number] => [
|
|
228
|
+
'a ' + what + ', which the two engines do not read the same way', -1]
|
|
229
|
+
|
|
230
|
+
let i = at + 1
|
|
231
|
+
let digits = ''
|
|
232
|
+
const bounds: number[] = []
|
|
233
|
+
let commas = 0
|
|
234
|
+
for (; i < src.length; i++) {
|
|
235
|
+
const c = src[i]
|
|
236
|
+
if ('0' <= c && c <= '9') {
|
|
237
|
+
digits += c
|
|
238
|
+
continue
|
|
239
|
+
}
|
|
240
|
+
if (',' === c) {
|
|
241
|
+
if ('' === digits || 0 < commas) {
|
|
242
|
+
return bad('{ that does not open a counted quantifier')
|
|
243
|
+
}
|
|
244
|
+
bounds.push(parseInt(digits, 10))
|
|
245
|
+
digits = ''
|
|
246
|
+
commas++
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
if ('}' === c) {
|
|
250
|
+
if ('' !== digits) {
|
|
251
|
+
bounds.push(parseInt(digits, 10))
|
|
252
|
+
}
|
|
253
|
+
else if (0 === commas) {
|
|
254
|
+
return bad('{ that does not open a counted quantifier')
|
|
255
|
+
}
|
|
256
|
+
break
|
|
257
|
+
}
|
|
258
|
+
return bad('{ that does not open a counted quantifier')
|
|
259
|
+
}
|
|
260
|
+
if (i >= src.length) {
|
|
261
|
+
return bad('{ that does not open a counted quantifier')
|
|
262
|
+
}
|
|
263
|
+
for (const b of bounds) {
|
|
264
|
+
if (RE_REPEAT_MAX < b) {
|
|
265
|
+
return ['a repeat count above ' + RE_REPEAT_MAX +
|
|
266
|
+
', which RE2 refuses to compile', -1]
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// A descending range (`{5,2}`) is refused by both engines' own
|
|
270
|
+
// compilers, so it needs no rule here.
|
|
271
|
+
return ['', i]
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
|
|
199
275
|
function isHexDigit(c: string | undefined): boolean {
|
|
200
276
|
return null != c && (
|
|
201
277
|
('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'))
|
|
@@ -302,8 +378,16 @@ function normaliseRe(src: string): [string, string] {
|
|
|
302
378
|
}
|
|
303
379
|
}
|
|
304
380
|
|
|
381
|
+
// Where the counted quantifier validated below closes, so its own
|
|
382
|
+
// `}` is told apart from a stray one; and whether the atom just
|
|
383
|
+
// emitted was `^` or `$`, which cannot be quantified.
|
|
384
|
+
let repeatEnd = -1
|
|
385
|
+
let anchorPrev = false
|
|
386
|
+
|
|
305
387
|
for (let i = 0; i < src.length; i++) {
|
|
306
388
|
const c = src[i]
|
|
389
|
+
const afterAnchor = anchorPrev
|
|
390
|
+
anchorPrev = false
|
|
307
391
|
|
|
308
392
|
if ('\\' === c) {
|
|
309
393
|
const [emit, why, extra] = normaliseEscape(src[i + 1], src, i, inClass)
|
|
@@ -311,6 +395,17 @@ function normaliseRe(src: string): [string, string] {
|
|
|
311
395
|
return ['', why]
|
|
312
396
|
}
|
|
313
397
|
out.push(emit)
|
|
398
|
+
// `\b` AND `\B` ARE ASSERTIONS TOO, and quantifying one is the
|
|
399
|
+
// same disagreement `^{1}` is: JavaScript under `u` calls it a
|
|
400
|
+
// syntax error, RE2 quantifies the assertion happily. The rule
|
|
401
|
+
// said "`\b` and `\B` quantify identically in both and are left
|
|
402
|
+
// alone" and that was measured wrong -- `re("\\b{1}x")` is
|
|
403
|
+
// `constraint_pattern` in TypeScript and an accepted schema in
|
|
404
|
+
// Go. Only OUTSIDE a class: inside one, `\b` is a backspace in
|
|
405
|
+
// both engines and repeats like any other character.
|
|
406
|
+
if (!inClass && ('b' === src[i + 1] || 'B' === src[i + 1])) {
|
|
407
|
+
anchorPrev = true
|
|
408
|
+
}
|
|
314
409
|
i += 1 + extra
|
|
315
410
|
continue
|
|
316
411
|
}
|
|
@@ -387,12 +482,43 @@ function normaliseRe(src: string): [string, string] {
|
|
|
387
482
|
}
|
|
388
483
|
|
|
389
484
|
if ('*' === c || '+' === c || '?' === c || '{' === c) {
|
|
485
|
+
// Nothing to repeat. JavaScript under the `u` flag makes this a
|
|
486
|
+
// SYNTAX ERROR, where RE2 quantifies the assertion happily and
|
|
487
|
+
// matches, so `re("^{1}")` was `constraint_pattern` in
|
|
488
|
+
// TypeScript and an accepted schema in Go. The four assertions
|
|
489
|
+
// behave alike here -- `^`, `$`, `\b` and `\B` -- so the rule
|
|
490
|
+
// names all four.
|
|
491
|
+
if (afterAnchor) {
|
|
492
|
+
return ['', 'a quantifier applied to `^`, `$`, `\\b` or ' +
|
|
493
|
+
'`\\B`, which has nothing to repeat']
|
|
494
|
+
}
|
|
495
|
+
if ('{' === c) {
|
|
496
|
+
const [why, end] = repeatWhy(src, i)
|
|
497
|
+
if ('' !== why) {
|
|
498
|
+
return ['', why]
|
|
499
|
+
}
|
|
500
|
+
repeatEnd = end
|
|
501
|
+
}
|
|
390
502
|
mark('q')
|
|
391
503
|
out.push(c)
|
|
392
504
|
continue
|
|
393
505
|
}
|
|
394
506
|
|
|
507
|
+
// A `}` that closes no counted quantifier: JavaScript under `u`
|
|
508
|
+
// refuses it as a lone quantifier bracket, RE2 reads it as a
|
|
509
|
+
// literal. Written escaped inside a class (`[}]`) it is a literal
|
|
510
|
+
// in both, which is the spelling that survives.
|
|
511
|
+
if ('}' === c) {
|
|
512
|
+
if (i !== repeatEnd) {
|
|
513
|
+
return ['', 'a `}` that closes no counted quantifier, which ' +
|
|
514
|
+
'the two engines do not read the same way']
|
|
515
|
+
}
|
|
516
|
+
out.push(c)
|
|
517
|
+
continue
|
|
518
|
+
}
|
|
519
|
+
|
|
395
520
|
out.push(c)
|
|
521
|
+
anchorPrev = ('^' === c || '$' === c)
|
|
396
522
|
}
|
|
397
523
|
|
|
398
524
|
if (inClass) {
|
|
@@ -480,6 +606,7 @@ class ConstraintVal extends FeatureVal {
|
|
|
480
606
|
res: ReAtom[] = []
|
|
481
607
|
count?: ConstraintState
|
|
482
608
|
uniq = false
|
|
609
|
+
uniqBy: string[] = []
|
|
483
610
|
musts: MustAtom[] = []
|
|
484
611
|
// An atom whose arguments have not settled yet (G1 phase 4). Held
|
|
485
612
|
// until unify has a ctx to resolve them through; never present on a
|
|
@@ -506,6 +633,7 @@ class ConstraintVal extends FeatureVal {
|
|
|
506
633
|
this.res = spec.state.res ?? []
|
|
507
634
|
this.count = spec.state.count
|
|
508
635
|
this.uniq = spec.state.uniq ?? false
|
|
636
|
+
this.uniqBy = spec.state.uniqBy ?? []
|
|
509
637
|
this.musts = spec.state.musts ?? []
|
|
510
638
|
this.invalid = spec.state.invalid
|
|
511
639
|
}
|
|
@@ -517,7 +645,14 @@ class ConstraintVal extends FeatureVal {
|
|
|
517
645
|
// in unify, where there is a ctx to resolve through, and the
|
|
518
646
|
// residual is built from the settled arguments. Only a settled
|
|
519
647
|
// argument of the wrong shape is an `invalid-arg`.
|
|
520
|
-
|
|
648
|
+
// The effectful-argument refusal happens HERE, on the written
|
|
649
|
+
// form, and not in fromAtom: settling is what runs the effect, so
|
|
650
|
+
// by the time fromAtom sees a settled `move($.b)` the move has
|
|
651
|
+
// already happened and the argument is just its result.
|
|
652
|
+
if ('must' === spec.atom && args.some((a: any) => holdsMove(a))) {
|
|
653
|
+
this.invalid = 'invalid-arg'
|
|
654
|
+
}
|
|
655
|
+
else if (args.some((a: any) => true !== a?.done)) {
|
|
521
656
|
this.pending = { atom: spec.atom, args }
|
|
522
657
|
}
|
|
523
658
|
else {
|
|
@@ -525,7 +660,8 @@ class ConstraintVal extends FeatureVal {
|
|
|
525
660
|
}
|
|
526
661
|
}
|
|
527
662
|
|
|
528
|
-
if (null != this.count || this.uniq || 0 < this.
|
|
663
|
+
if (null != this.count || this.uniq || 0 < this.uniqBy.length ||
|
|
664
|
+
0 < this.musts.length ||
|
|
529
665
|
(null != this.pending && lateAtom(this.pending.atom))) {
|
|
530
666
|
this.cjo = LATE_CJO
|
|
531
667
|
}
|
|
@@ -546,19 +682,32 @@ class ConstraintVal extends FeatureVal {
|
|
|
546
682
|
// SETTLED — the constructor routes an unsettled one to `pending` —
|
|
547
683
|
// so a shape this cannot use is a genuine `invalid-arg`, not a
|
|
548
684
|
// not-yet.
|
|
549
|
-
private fromAtom(atom: string, args: any[]) {
|
|
550
|
-
// Mark the residual invalid
|
|
551
|
-
//
|
|
552
|
-
|
|
685
|
+
private fromAtom(atom: string, args: any[]): void {
|
|
686
|
+
// Mark the residual invalid. It answers NOTHING: every caller
|
|
687
|
+
// spells its exit `return bad(...)` and none reads a value, so a
|
|
688
|
+
// return type would be a value nobody consumes -- and a routine
|
|
689
|
+
// that answers on some paths and not others is the shape a reader
|
|
690
|
+
// (and a static analyser) has to stop and check.
|
|
691
|
+
const bad = (why: string): void => {
|
|
553
692
|
this.invalid = why
|
|
554
|
-
return true
|
|
555
693
|
}
|
|
556
694
|
|
|
557
|
-
// `unique()`
|
|
558
|
-
//
|
|
559
|
-
//
|
|
695
|
+
// `unique()` is a property of the container -- not a comparison
|
|
696
|
+
// against a value -- so with no argument it says the members are
|
|
697
|
+
// pairwise DISTINCT. THE ONE ARGUMENT IS A PROJECTOR (the review's
|
|
698
|
+
// finding I: "unique()-by-field is reserved but absent", and the
|
|
699
|
+
// arity was reserved for exactly this): `unique(port)` says no two
|
|
700
|
+
// members share a `port`, which is how "no two services share a
|
|
701
|
+
// port" and "event ids are unique" are said.
|
|
560
702
|
if ('unique' === atom) {
|
|
561
|
-
|
|
703
|
+
if (0 === args.length) {
|
|
704
|
+
this.uniq = true
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
if (1 !== args.length || !stringLeaf(args[0])) {
|
|
708
|
+
return bad('invalid-arg')
|
|
709
|
+
}
|
|
710
|
+
this.uniqBy = [args[0].peg]
|
|
562
711
|
return
|
|
563
712
|
}
|
|
564
713
|
|
|
@@ -583,6 +732,9 @@ class ConstraintVal extends FeatureVal {
|
|
|
583
732
|
if (holdsNil(args[0])) {
|
|
584
733
|
return bad('invalid-arg')
|
|
585
734
|
}
|
|
735
|
+
// (An effectful argument is refused at construction, in the
|
|
736
|
+
// constructor: by the time this arm sees a settled `move($.b)`
|
|
737
|
+
// the move has already run.)
|
|
586
738
|
this.musts = [{ v: args[0], msg: args[1] }]
|
|
587
739
|
return
|
|
588
740
|
}
|
|
@@ -801,9 +953,9 @@ class ConstraintVal extends FeatureVal {
|
|
|
801
953
|
if (null == peer || (peer as any).isTop) {
|
|
802
954
|
return again
|
|
803
955
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
956
|
+
// No nil-peer arm: `unite` returns a nil operand before dispatching
|
|
957
|
+
// to any Val's unify (ts/src/unify.ts), so a nil never reaches here
|
|
958
|
+
// — and were one to, the conjunct below folds to it unchanged.
|
|
807
959
|
return new ConjunctVal({ peg: [again, peer] }, ctx)
|
|
808
960
|
}
|
|
809
961
|
|
|
@@ -811,8 +963,9 @@ class ConstraintVal extends FeatureVal {
|
|
|
811
963
|
// Membership: the peer scalar passes every part of the residual, or
|
|
812
964
|
// the whole meet is a located conflict.
|
|
813
965
|
private admit(peer: any, ctx: AontuContext): Val {
|
|
814
|
-
// No scalar has members, so a `unique()` residual admits none
|
|
815
|
-
|
|
966
|
+
// No scalar has members, so a `unique()` residual admits none --
|
|
967
|
+
// and neither does a `unique(k)` one, for the same reason.
|
|
968
|
+
if (this.uniq || 0 < this.uniqBy.length) {
|
|
816
969
|
return this.fail(ctx, peer)
|
|
817
970
|
}
|
|
818
971
|
if (!stateAdmits(this, peer)) {
|
|
@@ -829,7 +982,10 @@ class ConstraintVal extends FeatureVal {
|
|
|
829
982
|
return this.fail(ctx, peer)
|
|
830
983
|
}
|
|
831
984
|
}
|
|
832
|
-
|
|
985
|
+
// A SCALAR HAS NO MEMBERS to accumulate, so its musts are decided
|
|
986
|
+
// here and never residuate: the final reading is the only reading
|
|
987
|
+
// a scalar has.
|
|
988
|
+
const bad = this.checkMusts(peer, ctx, true)
|
|
833
989
|
if (null != bad) {
|
|
834
990
|
return bad
|
|
835
991
|
}
|
|
@@ -845,10 +1001,30 @@ class ConstraintVal extends FeatureVal {
|
|
|
845
1001
|
// The trial runs in an isolated collect context so a failing check
|
|
846
1002
|
// leaves nothing on the caller's error list — only the located nil
|
|
847
1003
|
// this returns, carrying the author's own message.
|
|
848
|
-
|
|
1004
|
+
// `final` is the generation-time reading (see settleContainer): a
|
|
1005
|
+
// must whose own check is a SIZING atom inherits that atom's
|
|
1006
|
+
// provisionality, because `must(length(2), …)` against a map that may
|
|
1007
|
+
// still gain members has not failed yet -- it has not been answered.
|
|
1008
|
+
// Without this the must would decide against whatever the container
|
|
1009
|
+
// held when it first settled, which is the very defect the sizing
|
|
1010
|
+
// atoms were fixed for (use-cases/BUGS.md §16, §17).
|
|
1011
|
+
private checkMusts(
|
|
1012
|
+
peer: any, ctx: AontuContext, final?: boolean): Val | undefined {
|
|
849
1013
|
for (const m of this.musts) {
|
|
850
1014
|
const trial = ctx.clone({ err: [], collect: true })
|
|
851
|
-
|
|
1015
|
+
let got: any = unite(trial, m.v.clone(trial), peer.clone(trial), 'must')
|
|
1016
|
+
// A must whose check is a SIZING atom answers a residue rather
|
|
1017
|
+
// than a verdict, because the atom is waiting for members that
|
|
1018
|
+
// may still arrive. Before generation that residue IS the answer
|
|
1019
|
+
// -- the must has not failed, it has not been asked yet -- and at
|
|
1020
|
+
// generation it is settled, because nothing more can arrive.
|
|
1021
|
+
const residue = sizingResidue(got)
|
|
1022
|
+
if (undefined !== residue) {
|
|
1023
|
+
if (true !== final) {
|
|
1024
|
+
continue
|
|
1025
|
+
}
|
|
1026
|
+
got = residue.con.settleContainer(residue.bag, trial)
|
|
1027
|
+
}
|
|
852
1028
|
if (true === (got as any)?.isNil || 0 < trial.err.length) {
|
|
853
1029
|
return makeNilErr(ctx, 'must', this, peer, undefined, {
|
|
854
1030
|
message: m.msg.peg,
|
|
@@ -861,6 +1037,16 @@ class ConstraintVal extends FeatureVal {
|
|
|
861
1037
|
}
|
|
862
1038
|
|
|
863
1039
|
|
|
1040
|
+
// THE FINAL READING of a sizing atom over a container: the same
|
|
1041
|
+
// checks admitContainer makes, with the provisional ones taken as
|
|
1042
|
+
// decided. Called from ConjunctVal.gen, which is where no more
|
|
1043
|
+
// members can arrive. Returns the container (to generate) or the
|
|
1044
|
+
// constraint's own nil (to report).
|
|
1045
|
+
settleContainer(peer: any, ctx: AontuContext): Val {
|
|
1046
|
+
return this.admitContainer(peer, ctx, true)
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
|
|
864
1050
|
// Membership for a container peer. Only the SIZING atoms have anything
|
|
865
1051
|
// to say about a map or a list; every other atom is scalar-domain and
|
|
866
1052
|
// refuses one.
|
|
@@ -872,7 +1058,8 @@ class ConstraintVal extends FeatureVal {
|
|
|
872
1058
|
// isolated collect context so nothing leaks into the caller's errors.
|
|
873
1059
|
// A mirror would be a second copy of a filter that has already grown
|
|
874
1060
|
// subtle, free to drift from it; asking is correct by construction.
|
|
875
|
-
private admitContainer(
|
|
1061
|
+
private admitContainer(
|
|
1062
|
+
peer: any, ctx: AontuContext, final?: boolean): Val {
|
|
876
1063
|
// A scalar-domain residual has no reading over a container.
|
|
877
1064
|
if (null != this.domain) {
|
|
878
1065
|
return this.fail(ctx, peer)
|
|
@@ -885,24 +1072,81 @@ class ConstraintVal extends FeatureVal {
|
|
|
885
1072
|
return new ConjunctVal({ peg: [this, peer] }, ctx)
|
|
886
1073
|
}
|
|
887
1074
|
|
|
888
|
-
const bad = this.checkMusts(peer, ctx)
|
|
1075
|
+
const bad = this.checkMusts(peer, ctx, final)
|
|
889
1076
|
if (null != bad) {
|
|
890
1077
|
return bad
|
|
891
1078
|
}
|
|
892
1079
|
|
|
893
|
-
|
|
894
|
-
|
|
1080
|
+
// A MUST OVER A CONTAINER RESIDUATES with the atoms, for the same
|
|
1081
|
+
// reason (use-cases/BUGS.md §17): `must({t: max(60)}, …)` beside a
|
|
1082
|
+
// `{t: integer}` schema was answered against the schema layer
|
|
1083
|
+
// ALONE, and discharged before the data it was written to judge
|
|
1084
|
+
// ever arrived. It is decided at generation, where the value is
|
|
1085
|
+
// whole -- unless there is nothing else on the constraint AND the
|
|
1086
|
+
// reading is already final.
|
|
1087
|
+
if (!this.uniq && 0 === this.uniqBy.length && null == this.count) {
|
|
1088
|
+
if (true === final || 0 === this.musts.length) {
|
|
1089
|
+
return peer
|
|
1090
|
+
}
|
|
1091
|
+
return this.hold(peer, ctx)
|
|
895
1092
|
}
|
|
896
1093
|
|
|
897
1094
|
const members = emittedMembers(peer, ctx)
|
|
898
1095
|
if (null == members) {
|
|
899
|
-
//
|
|
900
|
-
//
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1096
|
+
// NOT COUNTABLE YET IS NOT A PASS. A container that cannot
|
|
1097
|
+
// generate cannot be counted, and a SCHEMA is exactly that: the
|
|
1098
|
+
// members of `{a: integer}` are types, so nothing is emitted and
|
|
1099
|
+
// nothing can be counted. Discharging the atom here was the §16
|
|
1100
|
+
// defect wearing its other face -- `length(min(2)) & {a: integer}`
|
|
1101
|
+
// dropped its bound while still alone, so the data half of a
|
|
1102
|
+
// `vet` meet was never measured at all and short data vetted
|
|
1103
|
+
// clean against a bound the evaluator enforces.
|
|
1104
|
+
//
|
|
1105
|
+
// At generation the reading IS final: a container that still
|
|
1106
|
+
// cannot generate has its own error, and that error is the one
|
|
1107
|
+
// worth reporting, so it passes through untouched.
|
|
1108
|
+
if (true === final) {
|
|
1109
|
+
return peer
|
|
1110
|
+
}
|
|
1111
|
+
return this.hold(peer, ctx)
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// MONOTONE READINGS ONLY (the review's finding C, use-cases/BUGS.md
|
|
1115
|
+
// §16). Members ACCUMULATE under unification -- a meet adds keys and
|
|
1116
|
+
// never removes them -- so a settled container is settled ON ITS
|
|
1117
|
+
// OWN and not against every value that may still contribute. The
|
|
1118
|
+
// schema half of a `vet` meet, a document that is about to receive
|
|
1119
|
+
// an `@` include, a bag a later `pack` will fill: each settles, and
|
|
1120
|
+
// an atom that decided there decided too early.
|
|
1121
|
+
//
|
|
1122
|
+
// So a verdict is taken only when MORE MEMBERS CANNOT CHANGE IT:
|
|
1123
|
+
// - an upper bound VIOLATED is permanent -> refuse now;
|
|
1124
|
+
// satisfied is provisional -> keep the atom, re-check later.
|
|
1125
|
+
// - a lower bound SATISFIED is permanent -> that part may go;
|
|
1126
|
+
// violated is provisional -> keep the atom (which is why
|
|
1127
|
+
// `length(min(1))` beside a template no longer kills the schema
|
|
1128
|
+
// it was written for).
|
|
1129
|
+
// - a DUPLICATE is permanent -> refuse now; distinctness is
|
|
1130
|
+
// provisional -> keep the atom.
|
|
1131
|
+
// Anything provisional residuates, exactly as an unsettled
|
|
1132
|
+
// container does above, and the two spellings then agree.
|
|
1133
|
+
const count = null == this.count ? undefined : this.count
|
|
1134
|
+
const n = members.length
|
|
1135
|
+
if (null != count) {
|
|
1136
|
+
if (null != count.hi && !stateAdmits({ ...count, lo: undefined },
|
|
1137
|
+
countVal(n))) {
|
|
1138
|
+
return this.fail(ctx, peer)
|
|
1139
|
+
}
|
|
1140
|
+
if (0 < count.neqs.length && !stateAdmits(
|
|
1141
|
+
{ ...count, lo: undefined, hi: undefined }, countVal(n))) {
|
|
1142
|
+
return this.fail(ctx, peer)
|
|
1143
|
+
}
|
|
1144
|
+
// The provisional half, decided only when nothing more can
|
|
1145
|
+
// arrive: a lower bound still short is a refusal at generation
|
|
1146
|
+
// and a residue before it.
|
|
1147
|
+
if (true === final && !stateAdmits(count, countVal(n))) {
|
|
1148
|
+
return this.fail(ctx, peer)
|
|
1149
|
+
}
|
|
906
1150
|
}
|
|
907
1151
|
|
|
908
1152
|
if (this.uniq) {
|
|
@@ -921,7 +1165,68 @@ class ConstraintVal extends FeatureVal {
|
|
|
921
1165
|
}
|
|
922
1166
|
}
|
|
923
1167
|
|
|
924
|
-
|
|
1168
|
+
// ... and the same test per PROJECTED key. A member that has no such
|
|
1169
|
+
// key FAILS the constraint rather than being skipped: distinctness
|
|
1170
|
+
// it cannot be shown to have is distinctness it does not have, and
|
|
1171
|
+
// skipping would let one keyless record hide a duplicate.
|
|
1172
|
+
for (const field of this.uniqBy) {
|
|
1173
|
+
const seen = new Set<string>()
|
|
1174
|
+
for (const m of members) {
|
|
1175
|
+
const at: any = true === (m as any).isMap ?
|
|
1176
|
+
(m as any).peg[field] : undefined
|
|
1177
|
+
if (null == at) {
|
|
1178
|
+
return this.fail(ctx, peer)
|
|
1179
|
+
}
|
|
1180
|
+
const key = at.canon
|
|
1181
|
+
if (seen.has(key)) {
|
|
1182
|
+
return this.fail(ctx, peer)
|
|
1183
|
+
}
|
|
1184
|
+
seen.add(key)
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// WHAT IS LEFT IS PROVISIONAL, so the atom stays on the value. A
|
|
1189
|
+
// lower bound already met is the one reading that cannot be undone,
|
|
1190
|
+
// and an atom holding nothing else is spent: that is when it goes.
|
|
1191
|
+
const spent = true === final || (0 === this.musts.length &&
|
|
1192
|
+
!this.uniq && 0 === this.uniqBy.length &&
|
|
1193
|
+
(null == count ||
|
|
1194
|
+
(null == count.hi && 0 === count.neqs.length &&
|
|
1195
|
+
stateAdmits(count, countVal(n)))))
|
|
1196
|
+
if (spent) {
|
|
1197
|
+
return peer
|
|
1198
|
+
}
|
|
1199
|
+
// DONE, unlike the unsettled case above. The container HAS settled;
|
|
1200
|
+
// the atom is kept only because a LATER value could still add
|
|
1201
|
+
// members, and a residue that reported itself unresolved would
|
|
1202
|
+
// leave every enclosing value unresolved with it -- a `type()`
|
|
1203
|
+
// waiting on its argument for ever, and use case 09's whole
|
|
1204
|
+
// registry with it.
|
|
1205
|
+
// The ATOM is done too, not just the conjunct. An earlier pass may
|
|
1206
|
+
// have set `dc = 0` on the unsettled branch above, and a conjunct
|
|
1207
|
+
// recomputes its own doneness from its terms on every later meet --
|
|
1208
|
+
// so a stale 0 here would drag the residue, and every value holding
|
|
1209
|
+
// it, back to unresolved for ever.
|
|
1210
|
+
return this.hold(peer, ctx)
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
// The atom kept on a value whose reading is still provisional.
|
|
1215
|
+
// DONE, unlike the unsettled container above: the value HAS settled;
|
|
1216
|
+
// the atom is kept only because a LATER value could still add
|
|
1217
|
+
// members, and a residue that reported itself unresolved would leave
|
|
1218
|
+
// every enclosing value unresolved with it -- a `type()` waiting on
|
|
1219
|
+
// its argument for ever, and use case 09's whole registry with it.
|
|
1220
|
+
// The ATOM is done too, not just the conjunct. An earlier pass may
|
|
1221
|
+
// have set `dc = 0` on the unsettled branch, and a conjunct
|
|
1222
|
+
// recomputes its own doneness from its terms on every later meet --
|
|
1223
|
+
// so a stale 0 here would drag the residue, and every value holding
|
|
1224
|
+
// it, back to unresolved for ever.
|
|
1225
|
+
private hold(peer: any, ctx: AontuContext): Val {
|
|
1226
|
+
this.dc = DONE
|
|
1227
|
+
const held: any = new ConjunctVal({ peg: [this, peer] }, ctx)
|
|
1228
|
+
held.dc = DONE
|
|
1229
|
+
return held
|
|
925
1230
|
}
|
|
926
1231
|
|
|
927
1232
|
|
|
@@ -994,6 +1299,11 @@ class ConstraintVal extends FeatureVal {
|
|
|
994
1299
|
null == peer.count ? this.count : meetCount(this.count, peer.count)
|
|
995
1300
|
// `unique()` is idempotent: two of them are one.
|
|
996
1301
|
merged.uniq = this.uniq || peer.uniq
|
|
1302
|
+
// `unique(a) & unique(b)` is BOTH, not the later one: each names a
|
|
1303
|
+
// key on which the members must differ, and dropping either would
|
|
1304
|
+
// silently weaken the constraint. Sorted and deduplicated, so the
|
|
1305
|
+
// meet is commutative and `unique(a) & unique(a)` is one atom.
|
|
1306
|
+
merged.uniqBy = [...new Set([...this.uniqBy, ...peer.uniqBy])].sort()
|
|
997
1307
|
// Band B checks accumulate in written order and are never merged,
|
|
998
1308
|
// deduplicated or reordered: each carries its own author message,
|
|
999
1309
|
// and two checks with the same shape may still say different things.
|
|
@@ -1042,6 +1352,7 @@ class ConstraintVal extends FeatureVal {
|
|
|
1042
1352
|
res: [...this.res],
|
|
1043
1353
|
count: this.count,
|
|
1044
1354
|
uniq: this.uniq,
|
|
1355
|
+
uniqBy: [...this.uniqBy],
|
|
1045
1356
|
musts: [...this.musts],
|
|
1046
1357
|
invalid: this.invalid,
|
|
1047
1358
|
}
|
|
@@ -1061,6 +1372,7 @@ class ConstraintVal extends FeatureVal {
|
|
|
1061
1372
|
out.res = [...this.res]
|
|
1062
1373
|
out.count = this.count
|
|
1063
1374
|
out.uniq = this.uniq
|
|
1375
|
+
out.uniqBy = [...this.uniqBy]
|
|
1064
1376
|
out.musts = [...this.musts]
|
|
1065
1377
|
out.pending = this.pending
|
|
1066
1378
|
out.cjo = this.cjo
|
|
@@ -1137,10 +1449,11 @@ function dedupSorted(domain: 'number' | 'string', neqs: any[]): any[] {
|
|
|
1137
1449
|
// Is this value, or anything inside it, a nil? A written argument that
|
|
1138
1450
|
// holds one can never be satisfied, so the atom refuses it as an
|
|
1139
1451
|
// argument rather than reporting a mystery failure against every peer.
|
|
1452
|
+
// Every caller passes a Val: `args[0]` comes from atomArgs, and the
|
|
1453
|
+
// walk below descends only into container pegs, which hold Vals. The
|
|
1454
|
+
// null/non-Val guard this function used to open with was therefore
|
|
1455
|
+
// unreachable, and the coverage gate said so.
|
|
1140
1456
|
function holdsNil(v: any): boolean {
|
|
1141
|
-
if (null == v || true !== v.isVal) {
|
|
1142
|
-
return false
|
|
1143
|
-
}
|
|
1144
1457
|
if (true === v.isNil) {
|
|
1145
1458
|
return true
|
|
1146
1459
|
}
|
|
@@ -1159,6 +1472,31 @@ function holdsNil(v: any): boolean {
|
|
|
1159
1472
|
}
|
|
1160
1473
|
|
|
1161
1474
|
|
|
1475
|
+
// Whether a value, or anything inside it, is an effectful call — one
|
|
1476
|
+
// whose evaluation changes a node OTHER than the one being computed.
|
|
1477
|
+
// `move()` is the only builtin that does: it hides its resolution
|
|
1478
|
+
// target in place. Band B refuses one as an argument, because settling
|
|
1479
|
+
// it runs the effect against the live root before `must`'s trial clone
|
|
1480
|
+
// is taken, and a check that mutates cannot be report-only.
|
|
1481
|
+
function holdsMove(v: any): boolean {
|
|
1482
|
+
if (true === v.isFunc && 'move' === v.funcname?.()) {
|
|
1483
|
+
return true
|
|
1484
|
+
}
|
|
1485
|
+
const peg = v.peg
|
|
1486
|
+
if (Array.isArray(peg)) {
|
|
1487
|
+
return peg.some((c: any) => holdsMove(c))
|
|
1488
|
+
}
|
|
1489
|
+
if (null != peg && 'object' === typeof peg) {
|
|
1490
|
+
for (const k in peg) {
|
|
1491
|
+
if (holdsMove(peg[k])) {
|
|
1492
|
+
return true
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return false
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
|
|
1162
1500
|
// The written arguments of an atom, flattened.
|
|
1163
1501
|
//
|
|
1164
1502
|
// A multi-argument call arrives from the func-paren grammar as ONE
|
|
@@ -1217,6 +1555,12 @@ function canonState(s: ConstraintState): string {
|
|
|
1217
1555
|
if (s.uniq) {
|
|
1218
1556
|
parts.push('unique()')
|
|
1219
1557
|
}
|
|
1558
|
+
// After the bare atom, and sorted: canon is a normal form, so two
|
|
1559
|
+
// documents writing the same keys in different orders must render
|
|
1560
|
+
// the same string.
|
|
1561
|
+
for (const key of s.uniqBy) {
|
|
1562
|
+
parts.push('unique(' + JSON.stringify(key) + ')')
|
|
1563
|
+
}
|
|
1220
1564
|
for (const m of s.musts) {
|
|
1221
1565
|
parts.push('must(' + m.v.canon + ',' + m.msg.canon + ')')
|
|
1222
1566
|
}
|
|
@@ -1228,6 +1572,138 @@ function canonState(s: ConstraintState): string {
|
|
|
1228
1572
|
}
|
|
1229
1573
|
|
|
1230
1574
|
|
|
1575
|
+
// SUBSUMPTION over two residuals (G3, the query built on the table in
|
|
1576
|
+
// docs/reference-language.md "Subsumption"): does every value `s`
|
|
1577
|
+
// admits pass `g` too? Implemented here because the compare machinery
|
|
1578
|
+
// (cmpVal, sameScalar, the recursive count state) is this module's.
|
|
1579
|
+
//
|
|
1580
|
+
// Three-valued: true / false / 'undecided'. `must` on the GENERAL side
|
|
1581
|
+
// is undecided by construction (a Band B predicate is opaque — G3 maps
|
|
1582
|
+
// the table's "never" to the query's honest sub_evaluate_only); every
|
|
1583
|
+
// other approximation folds toward false, the safe direction.
|
|
1584
|
+
function constraintStateSubsumes(
|
|
1585
|
+
g: {
|
|
1586
|
+
domain?: 'number' | 'string', kind?: any, lo?: Bound, hi?: Bound,
|
|
1587
|
+
neqs: any[], res: ReAtom[], count?: ConstraintState, uniq: boolean,
|
|
1588
|
+
uniqBy: string[],
|
|
1589
|
+
musts: MustAtom[],
|
|
1590
|
+
},
|
|
1591
|
+
s: {
|
|
1592
|
+
domain?: 'number' | 'string', kind?: any, lo?: Bound, hi?: Bound,
|
|
1593
|
+
neqs: any[], res: ReAtom[], count?: ConstraintState, uniq: boolean,
|
|
1594
|
+
uniqBy: string[],
|
|
1595
|
+
musts: MustAtom[],
|
|
1596
|
+
},
|
|
1597
|
+
): boolean | 'undecided' {
|
|
1598
|
+
// A Band B predicate on the general side makes its admitted set
|
|
1599
|
+
// unknowable; an extra `must` on the SPECIFIC side only narrows it
|
|
1600
|
+
// and is ignored.
|
|
1601
|
+
if (0 < g.musts.length) {
|
|
1602
|
+
return 'undecided'
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// Domains must agree where both constrain one; a sizing-only residual
|
|
1606
|
+
// has no domain and passes this gate.
|
|
1607
|
+
if (null != g.domain && g.domain !== s.domain) {
|
|
1608
|
+
return false
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// A general leaf restriction requires the same leaf on the specific
|
|
1612
|
+
// side (leaves are disjoint; an unrestricted specific admits other
|
|
1613
|
+
// leaves the general refuses).
|
|
1614
|
+
if (null != g.kind && g.kind !== s.kind) {
|
|
1615
|
+
return false
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// Interval containment: the general's endpoints at or beyond the
|
|
1619
|
+
// specific's, and where they coincide the general's may not be the
|
|
1620
|
+
// open one.
|
|
1621
|
+
const d = g.domain ?? s.domain
|
|
1622
|
+
if (null != g.lo) {
|
|
1623
|
+
if (null == s.lo || null == d) {
|
|
1624
|
+
return false
|
|
1625
|
+
}
|
|
1626
|
+
const c = cmpVal(d, g.lo.v, s.lo.v)
|
|
1627
|
+
if (0 < c || (0 === c && g.lo.open && !s.lo.open)) {
|
|
1628
|
+
return false
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (null != g.hi) {
|
|
1632
|
+
if (null == s.hi || null == d) {
|
|
1633
|
+
return false
|
|
1634
|
+
}
|
|
1635
|
+
const c = cmpVal(d, g.hi.v, s.hi.v)
|
|
1636
|
+
if (c < 0 || (0 === c && g.hi.open && !s.hi.open)) {
|
|
1637
|
+
return false
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// Excluding FEWER values is more general: every general exclusion
|
|
1642
|
+
// must be excluded by the specific too.
|
|
1643
|
+
for (const n of g.neqs) {
|
|
1644
|
+
if (!s.neqs.some((m: any) => sameScalar(n, m))) {
|
|
1645
|
+
return false
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
// Patterns compare as TEXT sets (the sanctioned approximation:
|
|
1650
|
+
// deciding regex containment is what this algebra refuses to do).
|
|
1651
|
+
for (const r of g.res) {
|
|
1652
|
+
if (!s.res.some((q: ReAtom) => q.src === r.src)) {
|
|
1653
|
+
return false
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// `unique()` subsumes only itself on that axis: a general uniqueness
|
|
1658
|
+
// demand admits no container the unconstrained specific also admits.
|
|
1659
|
+
// ... and a general `unique(k)` needs the same key on the specific
|
|
1660
|
+
// side: distinctness on `port` says nothing about distinctness on
|
|
1661
|
+
// `name`.
|
|
1662
|
+
if (g.uniqBy.some((k: string) => !s.uniqBy.includes(k))) {
|
|
1663
|
+
return false
|
|
1664
|
+
}
|
|
1665
|
+
if (g.uniq && !s.uniq) {
|
|
1666
|
+
return false
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// The count atom reuses this same table over the integer domain.
|
|
1670
|
+
if (null != g.count) {
|
|
1671
|
+
if (null == s.count) {
|
|
1672
|
+
return false
|
|
1673
|
+
}
|
|
1674
|
+
return constraintStateSubsumes(g.count, s.count)
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
return true
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
// The query surface for ts/src/subsume.ts: residual-vs-residual, and
|
|
1682
|
+
// residual-vs-scalar membership (with `must` and `unique` making the
|
|
1683
|
+
// scalar case undecided/false exactly as the meet would).
|
|
1684
|
+
function constraintSubsumesConstraint(
|
|
1685
|
+
g: ConstraintVal, s: ConstraintVal): boolean | 'undecided' {
|
|
1686
|
+
return constraintStateSubsumes(g as any, s as any)
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
function constraintAdmitsScalar(
|
|
1690
|
+
g: ConstraintVal, scalar: any): boolean | 'undecided' {
|
|
1691
|
+
if (0 < g.musts.length) {
|
|
1692
|
+
return 'undecided'
|
|
1693
|
+
}
|
|
1694
|
+
if (g.uniq || 0 < g.uniqBy.length) {
|
|
1695
|
+
return false
|
|
1696
|
+
}
|
|
1697
|
+
// A count residual admits by LENGTH, which is the meet's business;
|
|
1698
|
+
// the query answers false (the safe direction) rather than
|
|
1699
|
+
// reimplementing the sizing walk here.
|
|
1700
|
+
if (null != (g as any).count) {
|
|
1701
|
+
return false
|
|
1702
|
+
}
|
|
1703
|
+
return stateAdmits(g as any, scalar)
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
|
|
1231
1707
|
// Does this residual's ORDER and MEMBERSHIP part admit the scalar? The
|
|
1232
1708
|
// sizing atoms are deliberately not consulted: `admit` applies them to
|
|
1233
1709
|
// the peer's length, and the count check applies this same function to
|
|
@@ -1345,7 +1821,8 @@ function stateEmpty(s: ConstraintState): boolean {
|
|
|
1345
1821
|
// members, so `integer & length(3)` and `min(2) & unique()` admit
|
|
1346
1822
|
// nothing. Uniqueness over the string domain is empty for the same
|
|
1347
1823
|
// reason -- a string's members are not values the algebra compares.
|
|
1348
|
-
if ('number' === d && (null != s.count || s.uniq
|
|
1824
|
+
if ('number' === d && (null != s.count || s.uniq ||
|
|
1825
|
+
0 < s.uniqBy.length)) {
|
|
1349
1826
|
return true
|
|
1350
1827
|
}
|
|
1351
1828
|
if ('string' === d && s.uniq) {
|
|
@@ -1374,7 +1851,9 @@ function countBase(): ConstraintState {
|
|
|
1374
1851
|
neqs: [],
|
|
1375
1852
|
res: [],
|
|
1376
1853
|
musts: [],
|
|
1854
|
+
// A COUNT is a number, and a number has no members to be distinct.
|
|
1377
1855
|
uniq: false,
|
|
1856
|
+
uniqBy: [],
|
|
1378
1857
|
}
|
|
1379
1858
|
}
|
|
1380
1859
|
|
|
@@ -1395,13 +1874,16 @@ function countVal(n: number): any {
|
|
|
1395
1874
|
function meetCount(a: ConstraintState, b: ConstraintState): ConstraintState {
|
|
1396
1875
|
return {
|
|
1397
1876
|
domain: 'number',
|
|
1398
|
-
|
|
1877
|
+
// `a` is always a countBase()-seeded residual, so its kind is
|
|
1878
|
+
// always Integer — there is no kindless side to fall back from.
|
|
1879
|
+
kind: a.kind,
|
|
1399
1880
|
lo: tighter('number', a.lo, b.lo, true),
|
|
1400
1881
|
hi: tighter('number', a.hi, b.hi, false),
|
|
1401
1882
|
neqs: dedupSorted('number', [...a.neqs, ...b.neqs]),
|
|
1402
1883
|
res: [],
|
|
1403
1884
|
musts: [],
|
|
1404
1885
|
uniq: false,
|
|
1886
|
+
uniqBy: [],
|
|
1405
1887
|
clash: true === a.clash || true === b.clash ||
|
|
1406
1888
|
(null != a.kind && null != b.kind && a.kind !== b.kind),
|
|
1407
1889
|
}
|
|
@@ -1426,7 +1908,7 @@ function countArgState(arg: any): ConstraintState | undefined {
|
|
|
1426
1908
|
domain: 'number',
|
|
1427
1909
|
lo: { v: arg, open: false },
|
|
1428
1910
|
hi: { v: arg, open: false },
|
|
1429
|
-
neqs: [], res: [], musts: [], uniq: false,
|
|
1911
|
+
neqs: [], res: [], musts: [], uniq: false, uniqBy: [],
|
|
1430
1912
|
}
|
|
1431
1913
|
}
|
|
1432
1914
|
|
|
@@ -1434,7 +1916,8 @@ function countArgState(arg: any): ConstraintState | undefined {
|
|
|
1434
1916
|
const c = arg as ConstraintVal
|
|
1435
1917
|
// A pattern, a sizing atom or a string bound inside a count is not
|
|
1436
1918
|
// a count constraint at all, and neither is a broken one.
|
|
1437
|
-
if (null != c.invalid || 0 < c.res.length || c.uniq ||
|
|
1919
|
+
if (null != c.invalid || 0 < c.res.length || c.uniq ||
|
|
1920
|
+
0 < c.uniqBy.length || null != c.count ||
|
|
1438
1921
|
'number' !== c.domain) {
|
|
1439
1922
|
return undefined
|
|
1440
1923
|
}
|
|
@@ -1444,18 +1927,24 @@ function countArgState(arg: any): ConstraintState | undefined {
|
|
|
1444
1927
|
lo: c.lo,
|
|
1445
1928
|
hi: c.hi,
|
|
1446
1929
|
neqs: [...c.neqs],
|
|
1447
|
-
res: [], musts: [], uniq: false,
|
|
1930
|
+
res: [], musts: [], uniq: false, uniqBy: [],
|
|
1448
1931
|
}
|
|
1449
1932
|
}
|
|
1450
1933
|
|
|
1451
1934
|
if (true === arg?.isScalarKind) {
|
|
1452
1935
|
const marker = arg.peg
|
|
1453
1936
|
if (Number === marker) {
|
|
1454
|
-
return {
|
|
1937
|
+
return {
|
|
1938
|
+
domain: 'number', neqs: [], res: [], musts: [],
|
|
1939
|
+
uniq: false, uniqBy: [],
|
|
1940
|
+
}
|
|
1455
1941
|
}
|
|
1456
1942
|
if (Integer === marker || Float === marker ||
|
|
1457
1943
|
BigInteger === marker || BigDecimal === marker) {
|
|
1458
|
-
return {
|
|
1944
|
+
return {
|
|
1945
|
+
domain: 'number', kind: marker, neqs: [], res: [], musts: [],
|
|
1946
|
+
uniq: false, uniqBy: [],
|
|
1947
|
+
}
|
|
1459
1948
|
}
|
|
1460
1949
|
return undefined
|
|
1461
1950
|
}
|
|
@@ -1487,7 +1976,12 @@ function genable(child: any): boolean {
|
|
|
1487
1976
|
return true === child.isScalar || true === child.isMap ||
|
|
1488
1977
|
true === child.isList || true === child.isPref ||
|
|
1489
1978
|
true === child.isRef || true === child.isDisjunct ||
|
|
1490
|
-
true === child.isNil
|
|
1979
|
+
true === child.isNil ||
|
|
1980
|
+
// A settled sizing residue generates through ConjunctVal.gen, so it
|
|
1981
|
+
// is a member like any other -- and a `length` that did not count
|
|
1982
|
+
// its sibling's `unique` would be the early-fold defect again, one
|
|
1983
|
+
// level up.
|
|
1984
|
+
undefined !== sizingResidue(child)
|
|
1491
1985
|
}
|
|
1492
1986
|
|
|
1493
1987
|
|
|
@@ -1624,7 +2118,7 @@ class UniqueConstraintVal extends ConstraintVal {
|
|
|
1624
2118
|
constructor(spec: ValSpec, ctx?: AontuContext) {
|
|
1625
2119
|
super({ ...spec, atom: 'unique' }, ctx)
|
|
1626
2120
|
}
|
|
1627
|
-
} /* node:coverage ignore next
|
|
2121
|
+
} /* node:coverage ignore next 23 */
|
|
1628
2122
|
|
|
1629
2123
|
|
|
1630
2124
|
export {
|
|
@@ -1632,6 +2126,11 @@ export {
|
|
|
1632
2126
|
// normalisers must produce byte-identical output, and that can only be
|
|
1633
2127
|
// checked by calling them.
|
|
1634
2128
|
normaliseRe,
|
|
2129
|
+
// Exported for the subsumption query (G3, ts/src/subsume.ts): the
|
|
2130
|
+
// residual-vs-residual and residual-vs-scalar rules live here beside
|
|
2131
|
+
// the compare machinery they reuse.
|
|
2132
|
+
constraintSubsumesConstraint,
|
|
2133
|
+
constraintAdmitsScalar,
|
|
1635
2134
|
ConstraintVal,
|
|
1636
2135
|
MinConstraintVal,
|
|
1637
2136
|
MaxConstraintVal,
|