@eagleoutice/flowr 2.17.12 → 2.17.14
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 +15 -15
- package/cli/repl/core.js +9 -27
- package/config.d.ts +1 -0
- package/config.js +4 -2
- package/data/r-datasets.generated.js +2 -2
- package/dataflow/environments/ambient-effect.d.ts +4 -0
- package/dataflow/environments/ambient-effect.js +5 -4
- package/dataflow/environments/ambient-state-name.d.ts +2 -2
- package/dataflow/environments/ambient-state-name.js +3 -3
- package/dataflow/environments/built-in-props.d.ts +5 -0
- package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/base-functions.js +6 -2
- package/dataflow/environments/default-builtin-config/base-language.d.ts +12 -1
- package/dataflow/environments/default-builtin-config/base-language.js +3 -2
- package/dataflow/environments/default-builtin-config/guards.js +3 -1
- package/dataflow/environments/default-builtin-config/index.d.ts +12 -2
- package/dataflow/environments/default-builtin-config/misc-packages.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/misc-packages.js +2 -0
- package/dataflow/environments/default-builtin-config/shared-configs.d.ts +24 -0
- package/dataflow/environments/default-builtin-config/shared-configs.js +8 -6
- package/dataflow/environments/pkg-name.d.ts +1 -0
- package/dataflow/eval/resolve/alias-tracking.js +11 -12
- package/dataflow/extractor.js +58 -0
- package/dataflow/fn/guards/built-in-guards.js +4 -4
- package/dataflow/fn/guards/call-contracts.js +8 -8
- package/dataflow/fn/guards/condition-grouping.js +4 -3
- package/dataflow/fn/guards/function-guards.js +103 -97
- package/dataflow/fn/guards/group-method-guards.js +10 -8
- package/dataflow/fn/guards/guard-claims.js +152 -128
- package/dataflow/fn/guards/guard-knowledge.js +19 -18
- package/dataflow/fn/guards/guard-term-syntax.js +13 -12
- package/dataflow/fn/guards/guard-term.d.ts +71 -0
- package/dataflow/fn/guards/guard-term.js +183 -75
- package/dataflow/graph/df-helper.d.ts +6 -6
- package/dataflow/graph/df-helper.js +1 -1
- package/dataflow/graph/graph.d.ts +9 -0
- package/dataflow/graph/graph.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +18 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +29 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +6 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +9 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +12 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +24 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +19 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +35 -3
- package/documentation/doc-readme.js +1 -2
- package/documentation/doc-util/doc-query.d.ts +1 -1
- package/documentation/doc-util/doc-query.js +4 -2
- package/documentation/wiki-interface.js +1 -0
- package/documentation/wiki-linter.d.ts +2 -0
- package/documentation/wiki-linter.js +7 -1
- package/documentation/wiki-query.js +28 -0
- package/linter/linter-format.d.ts +5 -1
- package/linter/linter-format.js +4 -0
- package/linter/linter-output.js +18 -16
- package/linter/linter-rules.d.ts +50 -0
- package/linter/linter-rules.js +5 -1
- package/linter/rules/notebook-cell-order.d.ts +43 -0
- package/linter/rules/notebook-cell-order.js +97 -0
- package/linter/rules/project-entry-point.d.ts +53 -0
- package/linter/rules/project-entry-point.js +62 -0
- package/linter/rules/undefined-symbol.d.ts +2 -0
- package/linter/rules/undefined-symbol.js +6 -1
- package/notebook/cell-graph.d.ts +23 -0
- package/notebook/cell-graph.js +48 -0
- package/notebook/cell-order-mermaid.d.ts +16 -0
- package/notebook/cell-order-mermaid.js +51 -0
- package/notebook/cell-order.d.ts +270 -0
- package/notebook/cell-order.js +1452 -0
- package/notebook/cell-split.d.ts +27 -0
- package/notebook/cell-split.js +99 -0
- package/package.json +1 -1
- package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -0
- package/project/context/flowr-analyzer-files-context.d.ts +2 -0
- package/project/flowr-analyzer.js +5 -1
- package/project/plugins/file-plugins/files/cell-runner.d.ts +22 -0
- package/project/plugins/file-plugins/files/cell-runner.js +32 -0
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +4 -0
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +22 -6
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +22 -0
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +63 -7
- package/project/plugins/file-plugins/files/flowr-rsession-file.d.ts +2 -0
- package/project/plugins/file-plugins/files/flowr-rsession-file.js +2 -0
- package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +3 -5
- package/project/plugins/file-plugins/files/flowr-sweave-file.js +6 -0
- package/project/plugins/file-plugins/files/recorded-runs.d.ts +2 -0
- package/queries/catalog/aliases-query/aliases-query-executor.d.ts +6 -0
- package/queries/catalog/aliases-query/aliases-query-executor.js +108 -0
- package/queries/catalog/aliases-query/aliases-query-format.d.ts +21 -0
- package/queries/catalog/aliases-query/aliases-query-format.js +34 -0
- package/queries/catalog/cell-order-query/cell-order-query-format.d.ts +81 -0
- package/queries/catalog/cell-order-query/cell-order-query-format.js +82 -0
- package/queries/catalog/linter-query/linter-query-format.js +2 -1
- package/queries/query.d.ts +17 -2
- package/queries/query.js +6 -2
- package/queries/virtual-query/compound-query.d.ts +1 -1
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/mermaid/ast.js +4 -11
- package/util/mermaid/cfg.js +1 -2
- package/util/mermaid/dfg.d.ts +5 -0
- package/util/mermaid/dfg.js +23 -4
- package/util/mermaid/mermaid.d.ts +5 -0
- package/util/mermaid/mermaid.js +8 -0
- package/util/r-datasets.d.ts +2 -0
- package/util/r-datasets.js +3 -0
- package/util/text/playground-link.d.ts +2 -2
- package/util/text/playground-link.js +2 -2
|
@@ -23,6 +23,7 @@ const guard_facts_1 = require("../../environments/guard-facts");
|
|
|
23
23
|
const set_1 = require("../../../util/collections/set");
|
|
24
24
|
const guard_knowledge_1 = require("./guard-knowledge");
|
|
25
25
|
const condition_grouping_1 = require("./condition-grouping");
|
|
26
|
+
const objects_1 = require("../../../util/objects");
|
|
26
27
|
const AllTypes = (0, guard_knowledge_1.typeNames)(guard_facts_1.AnyType).length;
|
|
27
28
|
/** The types as a set, which is top once it holds every one of them. */
|
|
28
29
|
function typeSet(types) {
|
|
@@ -37,21 +38,30 @@ function ofValues(values) {
|
|
|
37
38
|
return values === undefined ? NoValues : NoValues.create(values);
|
|
38
39
|
}
|
|
39
40
|
const Unconstrained = { types: typeSet(guard_facts_1.AnyType), plain: typeSet(guard_facts_1.AnyType), values: NoValues, partial: false, classes: undefined, bounds: new Map(), notNA: false, callable: false, whole: false, resolves: new Map() };
|
|
41
|
+
/** {@link Unconstrained} but for what `part` claims. */
|
|
42
|
+
function constrained(part) {
|
|
43
|
+
return { ...Unconstrained, ...part };
|
|
44
|
+
}
|
|
40
45
|
function ofTypes(types, classed = false) {
|
|
41
|
-
return {
|
|
46
|
+
return constrained({ types: typeSet(types), plain: typeSet(classed ? 0 : types) });
|
|
42
47
|
}
|
|
43
48
|
function ofBound(measure, lower, upper) {
|
|
44
|
-
return {
|
|
49
|
+
return constrained({ bounds: new Map([[measure, new interval_domain_1.IntervalDomain([lower, upper])]]) });
|
|
45
50
|
}
|
|
46
51
|
function combineMaps(a, b, meet) {
|
|
47
52
|
const result = new Map();
|
|
48
|
-
for (const key of
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
53
|
+
for (const [key, left] of a) {
|
|
54
|
+
const right = b.get(key);
|
|
55
|
+
if (right !== undefined) {
|
|
51
56
|
result.set(key, meet ? left.meet(right) : left.join(right));
|
|
52
57
|
}
|
|
53
58
|
else if (meet) {
|
|
54
|
-
result.set(key,
|
|
59
|
+
result.set(key, left);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const [key, right] of meet ? b : []) {
|
|
63
|
+
if (!a.has(key)) {
|
|
64
|
+
result.set(key, right);
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
return result;
|
|
@@ -87,7 +97,7 @@ function either(a, b) {
|
|
|
87
97
|
notNA: a.notNA && b.notNA,
|
|
88
98
|
callable: a.callable && b.callable,
|
|
89
99
|
whole: a.whole && b.whole,
|
|
90
|
-
resolves: new Map(
|
|
100
|
+
resolves: new Map(a.resolves.entries().filter(([expression]) => b.resolves.has(expression)))
|
|
91
101
|
};
|
|
92
102
|
}
|
|
93
103
|
function isFormal(term, formal) {
|
|
@@ -101,51 +111,58 @@ function valuesOf(constants) {
|
|
|
101
111
|
function ofPredicate(call, formal, holds, facts) {
|
|
102
112
|
const [first, second] = call.args.map(a => a.value);
|
|
103
113
|
const name = guard_term_1.GuardTerm.bareName(call.fn);
|
|
104
|
-
if (call.fn ===
|
|
105
|
-
return holds && isFormal(first, formal) ? both(ofTypes(guard_facts_1.RValueType.Logical), ofBound(
|
|
114
|
+
if (call.fn === guard_term_1.GuardFn.IsTrue || call.fn === guard_term_1.GuardFn.IsFalse) {
|
|
115
|
+
return holds && isFormal(first, formal) ? both(ofTypes(guard_facts_1.RValueType.Logical), ofBound(guard_term_1.GuardFn.Length, 1, 1)) : Unconstrained;
|
|
106
116
|
}
|
|
107
117
|
const stated = facts(name);
|
|
108
118
|
const predicate = stated?.predicate;
|
|
109
119
|
if (predicate !== undefined && isFormal(first, formal)) {
|
|
110
120
|
if (holds) {
|
|
111
|
-
const types =
|
|
112
|
-
const typed = predicate.
|
|
113
|
-
return predicate.scalar ? both(typed, ofBound(
|
|
121
|
+
const types = typeSet(predicate.yes | (predicate.classedToo ?? 0));
|
|
122
|
+
const typed = constrained({ types, plain: typeSet(predicate.classed ? 0 : predicate.yes), callable: predicate.callable === true });
|
|
123
|
+
return predicate.scalar ? both(typed, ofBound(guard_term_1.GuardFn.Length, 1, 1)) : typed;
|
|
114
124
|
}
|
|
115
125
|
const others = typeSet(guard_facts_1.AnyType & ~predicate.yes);
|
|
116
|
-
const ruledOut = predicate.exact === 'unclassed' ? {
|
|
126
|
+
const ruledOut = predicate.exact === 'unclassed' ? constrained({ plain: others }) : predicate.exact ? constrained({ types: others, plain: others }) : Unconstrained;
|
|
117
127
|
/* whatever a string can be measured against, this is not one */
|
|
118
|
-
return call.fn ===
|
|
128
|
+
return call.fn === guard_term_1.GuardFn.IsCharacter ? { ...ruledOut, values: NoValues.bottom() } : ruledOut;
|
|
119
129
|
}
|
|
120
|
-
else if (isFormal(first, formal) && (holds ? name === 'is.finite' : name ===
|
|
121
|
-
return {
|
|
130
|
+
else if (isFormal(first, formal) && (holds ? name === 'is.finite' : name === guard_term_1.GuardFn.IsNa || name === 'anyNA')) {
|
|
131
|
+
return constrained({ notNA: true });
|
|
122
132
|
}
|
|
123
133
|
else if (stated?.measures !== undefined && isFormal(first, formal) && call.args.length === 1) {
|
|
124
|
-
return holds ? boundOf(name,
|
|
134
|
+
return holds ? boundOf(name, guard_term_1.GuardFn.GreaterEqual, 1) : boundOf(name, guard_term_1.GuardFn.Equal, 0);
|
|
125
135
|
}
|
|
126
|
-
else if (holds && call.fn ===
|
|
136
|
+
else if (holds && call.fn === guard_term_1.GuardFn.Inherits && isFormal(first, formal) && call.args.length === 2) {
|
|
127
137
|
const classes = valuesOf(guard_term_1.GuardTerm.constantsOf(second) ?? []);
|
|
128
|
-
return classes?.size ? {
|
|
138
|
+
return classes?.size ? constrained({ classes: new Set(classes.values().map(String)) }) : Unconstrained;
|
|
129
139
|
}
|
|
130
140
|
return Unconstrained;
|
|
131
141
|
}
|
|
132
142
|
/** The comparison operator read the other way around, `1 < x` being `x > 1`. */
|
|
133
|
-
const Swapped = {
|
|
143
|
+
const Swapped = {
|
|
144
|
+
[guard_term_1.GuardFn.Less]: guard_term_1.GuardFn.Greater,
|
|
145
|
+
[guard_term_1.GuardFn.Greater]: guard_term_1.GuardFn.Less,
|
|
146
|
+
[guard_term_1.GuardFn.LessEqual]: guard_term_1.GuardFn.GreaterEqual,
|
|
147
|
+
[guard_term_1.GuardFn.GreaterEqual]: guard_term_1.GuardFn.LessEqual,
|
|
148
|
+
[guard_term_1.GuardFn.Equal]: guard_term_1.GuardFn.Equal,
|
|
149
|
+
[guard_term_1.GuardFn.NotEqual]: guard_term_1.GuardFn.NotEqual
|
|
150
|
+
};
|
|
134
151
|
function boundOf(measure, op, value) {
|
|
135
152
|
/* what counts comes in whole numbers, so a bound between two of them, or a strict one, says more than it spells out */
|
|
136
153
|
const whole = measure !== 'value';
|
|
137
154
|
switch (op) {
|
|
138
|
-
case
|
|
155
|
+
case guard_term_1.GuardFn.Equal:
|
|
139
156
|
return ofBound(measure, value, value);
|
|
140
|
-
case
|
|
157
|
+
case guard_term_1.GuardFn.Greater:
|
|
141
158
|
return ofBound(measure, whole ? Math.floor(value) + 1 : value, Infinity);
|
|
142
|
-
case
|
|
159
|
+
case guard_term_1.GuardFn.GreaterEqual:
|
|
143
160
|
return ofBound(measure, whole ? Math.ceil(value) : value, Infinity);
|
|
144
|
-
case
|
|
161
|
+
case guard_term_1.GuardFn.Less:
|
|
145
162
|
return ofBound(measure, -Infinity, whole ? Math.ceil(value) - 1 : value);
|
|
146
|
-
case
|
|
163
|
+
case guard_term_1.GuardFn.LessEqual:
|
|
147
164
|
return ofBound(measure, -Infinity, whole ? Math.floor(value) : value);
|
|
148
|
-
case
|
|
165
|
+
case guard_term_1.GuardFn.NotEqual:
|
|
149
166
|
return measure !== 'value' && value === 0 ? ofBound(measure, 1, Infinity) : Unconstrained;
|
|
150
167
|
default:
|
|
151
168
|
return Unconstrained;
|
|
@@ -156,13 +173,13 @@ function ofComparison(read, op, right, formal, facts) {
|
|
|
156
173
|
const constants = guard_term_1.GuardTerm.constantsOf(right);
|
|
157
174
|
if (guard_term_1.GuardTerm.isCall(read) && read.known && isFormal(read.args[0]?.value, formal) && read.args.length === 1) {
|
|
158
175
|
const reader = facts(read.fn)?.reads;
|
|
159
|
-
const values = (op ===
|
|
176
|
+
const values = (op === guard_term_1.GuardFn.Equal || op === guard_term_1.GuardFn.In) && constants !== undefined ? valuesOf(constants) : undefined;
|
|
160
177
|
if (reader !== undefined && values !== undefined) {
|
|
161
|
-
const types =
|
|
178
|
+
const types = Array.from(values, v => reader[String(v)]);
|
|
162
179
|
return types.every(t => t !== undefined) ? ofTypes(types.reduce((acc, t) => acc | t, 0)) : Unconstrained;
|
|
163
180
|
}
|
|
164
|
-
else if (read.fn ===
|
|
165
|
-
return {
|
|
181
|
+
else if (read.fn === guard_term_1.GuardFn.Class && values !== undefined) {
|
|
182
|
+
return constrained({ classes: new Set(values.values().map(String)) });
|
|
166
183
|
}
|
|
167
184
|
const number = constants?.length === 1 ? constants[0].value : undefined;
|
|
168
185
|
return facts(read.fn)?.measures !== undefined && typeof number === 'number' ? boundOf(read.fn, op, number) : Unconstrained;
|
|
@@ -171,20 +188,20 @@ function ofComparison(read, op, right, formal, facts) {
|
|
|
171
188
|
return Unconstrained;
|
|
172
189
|
}
|
|
173
190
|
const number = constants.length === 1 ? constants[0].value : undefined;
|
|
174
|
-
if (op ===
|
|
191
|
+
if (op === guard_term_1.GuardFn.In || (op === guard_term_1.GuardFn.Equal && typeof number !== 'number')) {
|
|
175
192
|
const values = valuesOf(constants);
|
|
176
|
-
return values === undefined ? Unconstrained : {
|
|
193
|
+
return values === undefined ? Unconstrained : constrained({ values: ofValues(values) });
|
|
177
194
|
}
|
|
178
195
|
return typeof number === 'number' ? boundOf('value', op, number) : Unconstrained;
|
|
179
196
|
}
|
|
180
197
|
function ofCheck(call, formal, facts) {
|
|
181
198
|
const name = guard_term_1.GuardTerm.bareName(call.fn);
|
|
182
|
-
if (name ===
|
|
199
|
+
if (name === guard_term_1.GuardFn.UseMethod) {
|
|
183
200
|
const [{ value: generic }, { value: object }] = call.args;
|
|
184
|
-
return isFormal(object, formal) && generic.kind === 'constant' ? {
|
|
201
|
+
return isFormal(object, formal) && generic.kind === 'constant' ? constrained({ resolves: new Map([[`${generic.lexeme}.class(${formal})`, { expression: `paste0(${generic.lexeme}, ".", class(${formal}))`, prefix: `${String(generic.value)}.`, suffix: '' }]]) }) : Unconstrained;
|
|
185
202
|
}
|
|
186
203
|
if ((0, guard_knowledge_1.appliesFormal)(facts(name)) && isFormal(call.args[0]?.value, formal)) {
|
|
187
|
-
return {
|
|
204
|
+
return constrained({ callable: true });
|
|
188
205
|
}
|
|
189
206
|
const check = facts(name)?.check;
|
|
190
207
|
if (check === undefined || !isFormal(call.args[0]?.value, formal)) {
|
|
@@ -203,7 +220,7 @@ function ofCheck(call, formal, facts) {
|
|
|
203
220
|
const choices = check.choices === undefined ? undefined : call.args.find((a, i) => a.name === check.choices || (a.name === undefined && i === 1))?.value;
|
|
204
221
|
const values = choices === undefined ? undefined : valuesOf(guard_term_1.GuardTerm.constantsOf(choices) ?? []);
|
|
205
222
|
const claim = { ...ofTypes(types, check.classed), values: ofValues(values), partial: values !== undefined && check.partial === true };
|
|
206
|
-
return check.scalar && !loosened ? both(claim, ofBound(
|
|
223
|
+
return check.scalar && !loosened ? both(claim, ofBound(guard_term_1.GuardFn.Length, 1, 1)) : claim;
|
|
207
224
|
}
|
|
208
225
|
/** What surrounds the formal in the `paste0`, `paste`, or `sprintf` that spells out a name, if that is all there is to it. */
|
|
209
226
|
function surroundings(term, formal) {
|
|
@@ -211,13 +228,13 @@ function surroundings(term, formal) {
|
|
|
211
228
|
return {};
|
|
212
229
|
}
|
|
213
230
|
const texts = term.args.filter(a => a.name === undefined).map(a => a.value);
|
|
214
|
-
if (term.fn ===
|
|
231
|
+
if (term.fn === guard_term_1.GuardFn.Sprintf) {
|
|
215
232
|
const [format, ...rest] = texts;
|
|
216
233
|
const parts = format?.kind === 'constant' && typeof format.value === 'string' ? format.value.split('%s') : [];
|
|
217
234
|
return parts.length === 2 && rest.length === 1 && isFormal(rest[0], formal) ? { prefix: parts[0], suffix: parts[1] } : {};
|
|
218
235
|
}
|
|
219
236
|
const separator = term.args.find(a => a.name === 'sep')?.value;
|
|
220
|
-
const glue = term.fn ===
|
|
237
|
+
const glue = term.fn === guard_term_1.GuardFn.Paste0 ? '' : separator === undefined ? ' ' : separator.kind === 'constant' && typeof separator.value === 'string' ? separator.value : undefined;
|
|
221
238
|
const at = texts.findIndex(t => isFormal(t, formal));
|
|
222
239
|
const strings = texts.map(t => t.kind === 'constant' && typeof t.value === 'string' ? t.value : undefined);
|
|
223
240
|
if (glue === undefined || at < 0 || strings.some((t, i) => i !== at && t === undefined) || term.args.some(a => a.name === 'collapse')) {
|
|
@@ -228,22 +245,22 @@ function surroundings(term, formal) {
|
|
|
228
245
|
}
|
|
229
246
|
function resolving(named, formal) {
|
|
230
247
|
const expression = guard_term_1.GuardTerm.render(named);
|
|
231
|
-
return {
|
|
248
|
+
return constrained({ resolves: new Map([[expression, { expression, ...surroundings(named, formal) }]]) });
|
|
232
249
|
}
|
|
233
250
|
function ofExists(call, formal) {
|
|
234
251
|
const [{ value: named }] = call.args;
|
|
235
252
|
const isFunctionMode = call.args.some(a => a.name === 'mode' && a.value.kind === 'constant' && a.value.value === 'function');
|
|
236
253
|
if (named.kind === 'constant' && named.value === formal) {
|
|
237
|
-
return {
|
|
254
|
+
return constrained({ callable: isFunctionMode });
|
|
238
255
|
}
|
|
239
256
|
if (!guard_term_1.GuardTerm.formalsOf(named).has(formal)) {
|
|
240
257
|
return Unconstrained;
|
|
241
258
|
}
|
|
242
|
-
return isFormal(named, formal) ? {
|
|
259
|
+
return isFormal(named, formal) ? constrained({ callable: isFunctionMode }) : resolving(named, formal);
|
|
243
260
|
}
|
|
244
261
|
/** What `all` lets through unbounded: of no number at all, each one holds. */
|
|
245
262
|
function withoutNullable(abstract, facts) {
|
|
246
|
-
return { ...abstract, bounds: new Map(
|
|
263
|
+
return { ...abstract, bounds: new Map(abstract.bounds.entries().filter(([measure]) => facts(measure)?.measures !== 'nullable')) };
|
|
247
264
|
}
|
|
248
265
|
function abstractOf(term, formal, facts) {
|
|
249
266
|
if (!guard_term_1.GuardTerm.isCall(term) || !term.known) {
|
|
@@ -252,28 +269,28 @@ function abstractOf(term, formal, facts) {
|
|
|
252
269
|
const operands = term.args.map(a => a.value);
|
|
253
270
|
const [first, second] = operands;
|
|
254
271
|
switch (term.fn) {
|
|
255
|
-
case
|
|
256
|
-
case
|
|
272
|
+
case guard_term_1.GuardFn.And:
|
|
273
|
+
case guard_term_1.GuardFn.ElementAnd:
|
|
257
274
|
return both(abstractOf(first, formal, facts), abstractOf(second, formal, facts));
|
|
258
|
-
case
|
|
259
|
-
case
|
|
275
|
+
case guard_term_1.GuardFn.Or:
|
|
276
|
+
case guard_term_1.GuardFn.ElementOr:
|
|
260
277
|
return either(abstractOf(first, formal, facts), abstractOf(second, formal, facts));
|
|
261
|
-
case
|
|
278
|
+
case guard_term_1.GuardFn.All:
|
|
262
279
|
return operands.length === 1 ? withoutNullable(abstractOf(first, formal, facts), facts) : Unconstrained;
|
|
263
|
-
case
|
|
280
|
+
case guard_term_1.GuardFn.Not:
|
|
264
281
|
return guard_term_1.GuardTerm.isCall(first) && first.known ? ofPredicate(first, formal, false, facts) : Unconstrained;
|
|
265
|
-
case
|
|
282
|
+
case guard_term_1.GuardFn.Succeeds:
|
|
266
283
|
return guard_term_1.GuardTerm.isCall(first) ? ofCheck(first, formal, facts) : Unconstrained;
|
|
267
|
-
case
|
|
284
|
+
case guard_term_1.GuardFn.Exists:
|
|
268
285
|
return ofExists(term, formal);
|
|
269
286
|
case 'is.element':
|
|
270
|
-
case
|
|
271
|
-
return operands.length === 2 ? ofComparison(first, term.fn ===
|
|
272
|
-
case
|
|
273
|
-
return ofComparison(first,
|
|
287
|
+
case guard_term_1.GuardFn.Identical:
|
|
288
|
+
return operands.length === 2 ? ofComparison(first, term.fn === guard_term_1.GuardFn.Identical ? guard_term_1.GuardFn.Equal : guard_term_1.GuardFn.In, second, formal, facts) : Unconstrained;
|
|
289
|
+
case guard_term_1.GuardFn.In:
|
|
290
|
+
return ofComparison(first, guard_term_1.GuardFn.In, second, formal, facts);
|
|
274
291
|
default:
|
|
275
|
-
if (term.fn ===
|
|
276
|
-
return {
|
|
292
|
+
if (term.fn === guard_term_1.GuardFn.Equal && operands.length === 2 && isWholeTest(first, second, formal)) {
|
|
293
|
+
return constrained({ whole: true });
|
|
277
294
|
}
|
|
278
295
|
if (Swapped[term.fn] !== undefined && operands.length === 2) {
|
|
279
296
|
return first.kind === 'constant' ? ofComparison(second, Swapped[term.fn], first, formal, facts) : ofComparison(first, term.fn, second, formal, facts);
|
|
@@ -283,7 +300,7 @@ function abstractOf(term, formal, facts) {
|
|
|
283
300
|
}
|
|
284
301
|
/** A bound the way {@link FormalClaim.bounds} states it, without one that is not known. */
|
|
285
302
|
function boundsOf(bounds) {
|
|
286
|
-
const kept =
|
|
303
|
+
const kept = bounds.entries().filter(([, domain]) => domain.isValue() && (Number.isFinite(domain.lower) || Number.isFinite(domain.upper))).toArray();
|
|
287
304
|
return kept.length === 0 ? undefined : Object.fromEntries(kept.map(([measure, { lower, upper }]) => {
|
|
288
305
|
const [low, high] = [lower, upper];
|
|
289
306
|
return [measure, [Number.isFinite(low) ? low : null, Number.isFinite(high) ? high : null]];
|
|
@@ -292,26 +309,27 @@ function boundsOf(bounds) {
|
|
|
292
309
|
const Numbers = guard_facts_1.RValueType.Integer | guard_facts_1.RValueType.Double;
|
|
293
310
|
/** Whether `==` tells the values apart for every value without a class, as R turns `TRUE == 1` and `"1" == 1` true, which only a string claim survives. */
|
|
294
311
|
function comparesExactly(plain, values) {
|
|
295
|
-
const kinds = new Set(values.isValue() ?
|
|
312
|
+
const kinds = new Set(values.isValue() ? values.value.values().map(v => typeof v) : []);
|
|
296
313
|
return kinds.size === 1 && (kinds.has('string') || plain.leq(typeSet(kinds.has('number') ? Numbers : guard_facts_1.RValueType.Logical)));
|
|
297
314
|
}
|
|
298
315
|
function toClaim(abstract) {
|
|
299
316
|
const { types, plain, partial, classes, notNA, callable, resolves } = abstract;
|
|
300
317
|
const values = comparesExactly(plain, abstract.values) ? abstract.values.value : undefined;
|
|
301
318
|
/* `"a" > 5` holds in R, so a bound on the value says something only of a number */
|
|
302
|
-
const bounds = plain.leq(typeSet(Numbers | guard_facts_1.RValueType.Logical)) ? abstract.bounds : new Map(
|
|
303
|
-
const
|
|
304
|
-
return {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
const bounds = plain.leq(typeSet(Numbers | guard_facts_1.RValueType.Logical)) ? abstract.bounds : new Map(abstract.bounds.entries().filter(([measure]) => measure !== 'value'));
|
|
320
|
+
const listed = values === undefined || values.size === 0 ? undefined : values.values().toArray();
|
|
321
|
+
return (0, objects_1.compactRecord)({
|
|
322
|
+
types: types.isTop() ? undefined : (0, guard_knowledge_1.typeNames)(typeBits(types)),
|
|
323
|
+
unclassedTypes: plain.equals(types) || plain.isTop() ? undefined : (0, guard_knowledge_1.typeNames)(typeBits(plain)),
|
|
324
|
+
values: listed,
|
|
325
|
+
partial: listed !== undefined && partial ? partial : undefined,
|
|
326
|
+
classes: classes?.values().toArray(),
|
|
327
|
+
bounds: boundsOf(bounds),
|
|
328
|
+
notNA: notNA || undefined,
|
|
329
|
+
callable: callable || undefined,
|
|
330
|
+
whole: abstract.whole || undefined,
|
|
331
|
+
resolves: resolves.size === 0 ? undefined : resolves.values().toArray()
|
|
332
|
+
});
|
|
315
333
|
}
|
|
316
334
|
/** What `claim` says beyond `known`, each part `known` already makes sure of left out, so a case does not repeat its condition or what always holds. */
|
|
317
335
|
function claimBeyond(claim, known) {
|
|
@@ -320,30 +338,32 @@ function claimBeyond(claim, known) {
|
|
|
320
338
|
const bounds = Object.entries(claim.bounds ?? {}).filter(([measure, range]) => known.bounds?.[measure] === undefined || !narrower(known.bounds[measure], range));
|
|
321
339
|
const resolves = (claim.resolves ?? []).filter(r => !known.resolves?.some(k => k.expression === r.expression));
|
|
322
340
|
const { types, unclassedTypes, values, partial, classes, notNA, callable, whole, cases } = claim;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
341
|
+
const newValues = values !== undefined && !(within(known.values, values) && (partial === true || known.partial !== true));
|
|
342
|
+
return (0, objects_1.compactRecord)({
|
|
343
|
+
types: types === undefined || within(known.types, types) ? undefined : types,
|
|
344
|
+
unclassedTypes: unclassedTypes === undefined || within(known.unclassedTypes ?? known.types, unclassedTypes) ? undefined : unclassedTypes,
|
|
345
|
+
values: newValues ? values : undefined,
|
|
346
|
+
partial: newValues && partial ? partial : undefined,
|
|
347
|
+
classes: classes === undefined || within(known.classes, classes) ? undefined : classes,
|
|
348
|
+
bounds: bounds.length === 0 ? undefined : Object.fromEntries(bounds),
|
|
349
|
+
notNA: notNA && !known.notNA ? notNA : undefined,
|
|
350
|
+
callable: callable && !known.callable ? callable : undefined,
|
|
351
|
+
whole: whole && !known.whole ? whole : undefined,
|
|
352
|
+
resolves: (0, objects_1.nonEmpty)(resolves),
|
|
353
|
+
cases
|
|
354
|
+
});
|
|
335
355
|
}
|
|
336
356
|
/** The functions that drop the fraction of a number, so `trunc(x) == x` holds only for a whole `x`. */
|
|
337
357
|
const Rounding = new Set(['trunc', 'round', 'floor', 'ceiling', 'as.integer']);
|
|
338
358
|
/** Whether `a == b` asks the formal to be a whole number: `trunc(x) == x` either way around, or `x %% 1 == 0`. */
|
|
339
359
|
function isWholeTest(a, b, formal) {
|
|
340
360
|
const rounds = (r, x) => guard_term_1.GuardTerm.isCall(r) && r.known === true && Rounding.has(r.fn) && r.args.length === 1 && isFormal(r.args[0].value, formal) && isFormal(x, formal);
|
|
341
|
-
const modulo = (m, zero) => guard_term_1.GuardTerm.isCall(m,
|
|
361
|
+
const modulo = (m, zero) => guard_term_1.GuardTerm.isCall(m, guard_term_1.GuardFn.Modulo) && m.known === true && isFormal(m.args[0]?.value, formal) && m.args[1]?.value.kind === 'constant' && m.args[1].value.value === 1 && zero.kind === 'constant' && zero.value === 0;
|
|
342
362
|
return rounds(a, b) || rounds(b, a) || modulo(a, b) || modulo(b, a);
|
|
343
363
|
}
|
|
344
364
|
/** The comparison within `term`, also within the `all` that `stopifnot` spells a vector of them with, `undefined` if it is none. */
|
|
345
365
|
function comparisonOf(term) {
|
|
346
|
-
const inner = guard_term_1.GuardTerm.isCall(term,
|
|
366
|
+
const inner = guard_term_1.GuardTerm.isCall(term, guard_term_1.GuardFn.All) && term.known && term.args.length === 1 ? term.args[0].value : term;
|
|
347
367
|
return guard_term_1.GuardTerm.isCall(inner) && inner.known && Swapped[inner.fn] !== undefined && inner.args.length === 2 ? inner : undefined;
|
|
348
368
|
}
|
|
349
369
|
/** The relations between formals the given conditions state, each one a comparison of two sides that read different formals. */
|
|
@@ -359,15 +379,16 @@ function relationsOf(conditions, facts) {
|
|
|
359
379
|
}
|
|
360
380
|
const [relation] = relating;
|
|
361
381
|
const others = alternatives.filter(alternative => alternative !== relation);
|
|
362
|
-
const unless = guard_term_1.GuardTerm.
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
|
|
382
|
+
const unless = guard_term_1.GuardTerm.anyOf(others);
|
|
383
|
+
const mentioned = guard_term_1.GuardTerm.formalsOf(unless);
|
|
384
|
+
const [only] = mentioned;
|
|
385
|
+
const unlessClaim = mentioned.size !== 1 ? undefined : toClaim(abstractOf(unless, only, facts));
|
|
386
|
+
return [(0, objects_1.compactRecord)({
|
|
366
387
|
holds: guard_term_1.GuardTerm.render(relation),
|
|
367
|
-
formals:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}];
|
|
388
|
+
formals: guard_term_1.GuardTerm.formalsOf(relation).values().toArray(),
|
|
389
|
+
unless: others.length === 0 ? undefined : guard_term_1.GuardTerm.render(unless),
|
|
390
|
+
unlessClaim: unlessClaim === undefined || Object.keys(unlessClaim).length === 0 ? undefined : { formal: only, claim: unlessClaim }
|
|
391
|
+
})];
|
|
371
392
|
});
|
|
372
393
|
}
|
|
373
394
|
/** A condition split into what it says of `formal` alone and the rest, `undefined` if some alternative mixes both. */
|
|
@@ -378,20 +399,20 @@ function splitAbout(condition, formal) {
|
|
|
378
399
|
return about.length + others.length === alternatives.length ? { about, others } : undefined;
|
|
379
400
|
}
|
|
380
401
|
/**
|
|
381
|
-
*
|
|
402
|
+
* What two of the conditions say of a formal together: `a || p` and `a || q` where `p` and `q` cannot both fail say `a`
|
|
382
403
|
* outright (`p && !p` is never true), which neither says alone. The two stay, the claim they give together joins them.
|
|
383
404
|
*/
|
|
384
|
-
function
|
|
385
|
-
const out = [
|
|
405
|
+
function resolventsOf(conditions, formals) {
|
|
406
|
+
const out = [];
|
|
386
407
|
for (const formal of formals) {
|
|
387
408
|
const split = conditions.map(c => splitAbout(c, formal)).filter(s => s !== undefined && s.about.length > 0 && s.others.length > 0);
|
|
388
409
|
for (let i = 0; i < split.length; i++) {
|
|
389
410
|
for (let j = i + 1; j < split.length; j++) {
|
|
390
411
|
const [a, b] = [split[i], split[j]];
|
|
391
|
-
const
|
|
412
|
+
const about = guard_term_1.GuardTerm.anyOf(a.about);
|
|
392
413
|
/* neither way through can hold when the other one does not */
|
|
393
|
-
if (
|
|
394
|
-
out.push(
|
|
414
|
+
if (guard_term_1.GuardTerm.render(about) === guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.anyOf(b.about)) && guard_term_1.GuardTerm.isFalse(guard_term_1.GuardTerm.any(guard_term_1.GuardTerm.all(guard_term_1.GuardTerm.anyOf(a.others), guard_term_1.GuardTerm.anyOf(b.others))))) {
|
|
415
|
+
out.push(about);
|
|
395
416
|
}
|
|
396
417
|
}
|
|
397
418
|
}
|
|
@@ -401,26 +422,26 @@ function withResolvents(conditions, formals) {
|
|
|
401
422
|
/** The claims the given conditions make on a formal unless something not about that formal holds, see {@link ConditionalClaim}. */
|
|
402
423
|
function conditionalClaimsOf(conditions, formals, facts) {
|
|
403
424
|
/* what holds outright needs no way through */
|
|
404
|
-
const outright = new Set(
|
|
425
|
+
const outright = new Set(resolventsOf(conditions, formals).map(t => guard_term_1.GuardTerm.render(t)));
|
|
405
426
|
return conditions.flatMap(condition => {
|
|
406
427
|
const alternatives = guard_term_1.GuardTerm.disjuncts(condition);
|
|
407
428
|
return formals.flatMap(formal => {
|
|
408
429
|
const about = alternatives.filter(a => (0, set_1.setEquals)(guard_term_1.GuardTerm.formalsOf(a), new Set([formal])));
|
|
409
430
|
const others = alternatives.filter(a => !guard_term_1.GuardTerm.formalsOf(a).has(formal));
|
|
410
|
-
if (about.length === 0 || others.length === 0 || about.length + others.length !== alternatives.length || outright.has(guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.
|
|
431
|
+
if (about.length === 0 || others.length === 0 || about.length + others.length !== alternatives.length || outright.has(guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.anyOf(about)))) {
|
|
411
432
|
return [];
|
|
412
433
|
}
|
|
413
434
|
const claim = toClaim(about.map(a => abstractOf(a, formal, facts)).reduce(either));
|
|
414
435
|
/* that a formal has to have a class unless another one passes is all dispatching leaves, not a claim */
|
|
415
436
|
const onlyClassed = Object.keys(claim).length === 1 && claim.unclassedTypes?.length === 0;
|
|
416
|
-
return Object.keys(claim).length === 0 || onlyClassed ? [] : [{ formal, claim, unless: guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.
|
|
437
|
+
return Object.keys(claim).length === 0 || onlyClassed ? [] : [{ formal, claim, unless: guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.anyOf(others)) }];
|
|
417
438
|
});
|
|
418
439
|
});
|
|
419
440
|
}
|
|
420
441
|
/** The conditions that hold in the case `when`: a clause offering what the case rules out loses that alternative, one offering the case itself asks nothing. */
|
|
421
442
|
function inCase(clauses, when, otherwise) {
|
|
422
443
|
const [yes, no] = [guard_term_1.GuardTerm.render(when), new Set(guard_term_1.GuardTerm.disjuncts(otherwise).map(d => guard_term_1.GuardTerm.render(d)))];
|
|
423
|
-
const all =
|
|
444
|
+
const all = guard_term_1.GuardTerm.conjuncts(when).slice();
|
|
424
445
|
const own = [];
|
|
425
446
|
for (const { requires } of clauses) {
|
|
426
447
|
const alternatives = guard_term_1.GuardTerm.disjuncts(requires);
|
|
@@ -428,10 +449,11 @@ function inCase(clauses, when, otherwise) {
|
|
|
428
449
|
continue;
|
|
429
450
|
}
|
|
430
451
|
const kept = alternatives.filter(a => !no.has(guard_term_1.GuardTerm.render(a)));
|
|
452
|
+
const remaining = guard_term_1.GuardTerm.anyOf(kept);
|
|
431
453
|
if (kept.length + no.size === alternatives.length) {
|
|
432
|
-
own.push(
|
|
454
|
+
own.push(remaining);
|
|
433
455
|
}
|
|
434
|
-
all.push(
|
|
456
|
+
all.push(remaining);
|
|
435
457
|
}
|
|
436
458
|
return { all, own };
|
|
437
459
|
}
|
|
@@ -441,7 +463,7 @@ function inCase(clauses, when, otherwise) {
|
|
|
441
463
|
*/
|
|
442
464
|
function casesOf(clauses, formals, facts) {
|
|
443
465
|
const cases = {};
|
|
444
|
-
const branches =
|
|
466
|
+
const branches = new Map(clauses.flatMap(c => c.under ?? []).map(term => [guard_term_1.GuardTerm.render(term), term])).values().toArray();
|
|
445
467
|
for (const formal of formals) {
|
|
446
468
|
for (const when of branches.filter(b => (0, set_1.setEquals)(guard_term_1.GuardTerm.formalsOf(b), new Set([formal])))) {
|
|
447
469
|
const otherwise = guard_term_1.GuardTerm.truth(when, false, facts);
|
|
@@ -452,7 +474,7 @@ function casesOf(clauses, formals, facts) {
|
|
|
452
474
|
cases[formal] = split.map(([term, { all }]) => {
|
|
453
475
|
const relations = relationsOf(all, facts).filter(r => r.formals.includes(formal));
|
|
454
476
|
const claim = claimBeyond(toClaim(abstractOfAll(all, formal, facts)), toClaim(abstractOfAll(guard_term_1.GuardTerm.conjuncts(term), formal, facts)));
|
|
455
|
-
return { when: guard_term_1.GuardTerm.render(term), claim,
|
|
477
|
+
return (0, objects_1.compactRecord)({ when: guard_term_1.GuardTerm.render(term), claim, relations: (0, objects_1.nonEmpty)(relations) });
|
|
456
478
|
});
|
|
457
479
|
break;
|
|
458
480
|
}
|
|
@@ -480,7 +502,7 @@ function abstractOfAll(conditions, formal, facts) {
|
|
|
480
502
|
/** What the given conditions, all of which hold on a normal return, claim about each of the given formals; a formal without any claim is left out. */
|
|
481
503
|
function claimsOf(conditions, formals, facts) {
|
|
482
504
|
const claims = {};
|
|
483
|
-
const all =
|
|
505
|
+
const all = conditions.concat(resolventsOf(conditions, formals));
|
|
484
506
|
for (const formal of formals) {
|
|
485
507
|
const claim = toClaim(abstractOfAll(all, formal, facts));
|
|
486
508
|
if (Object.keys(claim).length > 0) {
|
|
@@ -564,7 +586,7 @@ function ofConstants(constants) {
|
|
|
564
586
|
/** What the value of the term is, `conditions` holding of the formals. */
|
|
565
587
|
function ofValue(term, conditions, facts) {
|
|
566
588
|
if (term?.kind === 'formal') {
|
|
567
|
-
return conditions
|
|
589
|
+
return abstractOfAll(conditions, term.name, facts);
|
|
568
590
|
}
|
|
569
591
|
const constants = guard_term_1.GuardTerm.constantsOf(term);
|
|
570
592
|
if (constants !== undefined && (!guard_term_1.GuardTerm.isCall(term) || term.args.every(a => a.name === undefined))) {
|
|
@@ -587,7 +609,7 @@ function ofValue(term, conditions, facts) {
|
|
|
587
609
|
}
|
|
588
610
|
/** What holds of the value of every normal return, given what holds of the formals on every one of them, `undefined` if that is nothing. */
|
|
589
611
|
function returnsOf(returned, conditions, facts) {
|
|
590
|
-
const claim = returned.length === 0 ? {} : toClaim(returned.map(r => ofValue(r.value,
|
|
612
|
+
const claim = returned.length === 0 ? {} : toClaim(returned.map(r => ofValue(r.value, conditions.concat(r.holds), facts)).reduce(either));
|
|
591
613
|
return Object.keys(claim).length === 0 ? undefined : claim;
|
|
592
614
|
}
|
|
593
615
|
/** The formal the term hands back as it is. */
|
|
@@ -599,15 +621,15 @@ function passedOn(term, facts) {
|
|
|
599
621
|
}
|
|
600
622
|
/** The formal every normal return hands back unchanged, if there is one. */
|
|
601
623
|
function returnedFormalOf(returned, facts) {
|
|
602
|
-
const
|
|
603
|
-
return
|
|
624
|
+
const passed = returned.map(r => passedOn(r.value, facts));
|
|
625
|
+
return passed.every(f => f === passed[0]) ? passed[0] : undefined;
|
|
604
626
|
}
|
|
605
627
|
/** `succeeds(f(x, ...))` in words: what the check `f` states of `x`, or that the call runs without an error. */
|
|
606
628
|
function succeedsInWords(call, facts) {
|
|
607
629
|
const checked = call.args[0]?.value;
|
|
608
630
|
const claim = checked?.kind === 'formal' && facts(guard_term_1.GuardTerm.bareName(call.fn))?.check !== undefined ? toClaim(ofCheck(call, checked.name, facts)) : undefined;
|
|
609
631
|
/* the choices say what the type adds for anyone reading it */
|
|
610
|
-
const said = claim === undefined || checked?.kind !== 'formal' ? [] : claimConditions(String(checked.name), claim.values === undefined ? claim : { values: claim.values,
|
|
632
|
+
const said = claim === undefined || checked?.kind !== 'formal' ? [] : claimConditions(String(checked.name), claim.values === undefined ? claim : (0, objects_1.compactRecord)({ values: claim.values, partial: claim.partial || undefined }));
|
|
611
633
|
return said.length > 0 ? said.join(' && ') : `${guard_term_1.GuardTerm.render(call)} runs without an error`;
|
|
612
634
|
}
|
|
613
635
|
/**
|
|
@@ -618,10 +640,10 @@ function succeedsInWords(call, facts) {
|
|
|
618
640
|
function readingOf(condition, facts, group) {
|
|
619
641
|
const alternatives = guard_term_1.GuardTerm.disjuncts(condition);
|
|
620
642
|
function read(term) {
|
|
621
|
-
if (guard_term_1.GuardTerm.isCall(term,
|
|
643
|
+
if (guard_term_1.GuardTerm.isCall(term, guard_term_1.GuardFn.Succeeds) && term.known && guard_term_1.GuardTerm.isCall(term.args[0]?.value)) {
|
|
622
644
|
return succeedsInWords(term.args[0].value, facts);
|
|
623
645
|
}
|
|
624
|
-
const [of] = guard_term_1.GuardTerm.isCall(term,
|
|
646
|
+
const [of] = guard_term_1.GuardTerm.isCall(term, guard_term_1.GuardFn.IsObject) && term.known ? term.args : [];
|
|
625
647
|
return group !== undefined && of !== undefined ? `${guard_term_1.GuardTerm.render(of.value)} may have a ${group} method` : undefined;
|
|
626
648
|
}
|
|
627
649
|
const readings = alternatives.map(read);
|
|
@@ -666,19 +688,19 @@ function claimConditions(formal, { types, unclassedTypes, values, partial, class
|
|
|
666
688
|
function range(measure, [lower, upper]) {
|
|
667
689
|
const of = measure === 'value' ? formal : `${measure}(${formal})`;
|
|
668
690
|
return lower !== null && lower === upper ? [`${of} == ${lower}`]
|
|
669
|
-
: [
|
|
691
|
+
: [lower === null ? '' : `${of} >= ${lower}`, upper === null ? '' : `${of} <= ${upper}`];
|
|
670
692
|
}
|
|
671
693
|
return [
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
694
|
+
types === undefined ? '' : ofTypes(types, false),
|
|
695
|
+
unclassedTypes === undefined ? '' : ofTypes(unclassedTypes, true),
|
|
696
|
+
values === undefined ? '' : `${formal} ${partial ? 'pmatches' : 'in'} ${setOf(values.map(v => JSON.stringify(v)))}`,
|
|
697
|
+
classes === undefined ? '' : classes.length === 1 ? `inherits(${formal}, ${JSON.stringify(classes[0])})` : `inherits(${formal}, c(${classes.map(c => JSON.stringify(c)).join(', ')}))`,
|
|
676
698
|
...Object.entries(bounds ?? {}).filter(([measure]) => !onlyNull || measure !== 'length').flatMap(([measure, bound]) => range(measure, bound)),
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
699
|
+
notNA && !onlyNull ? `!anyNA(${formal})` : '',
|
|
700
|
+
callable ? `is.function(match.fun(${formal}))` : '',
|
|
701
|
+
whole ? `trunc(${formal}) == ${formal}` : '',
|
|
680
702
|
...(resolves ?? []).map(r => `exists(${r.expression})`)
|
|
681
|
-
];
|
|
703
|
+
].filter(c => c !== '');
|
|
682
704
|
}
|
|
683
705
|
/** Reads a claim in a few words each, as a page or a terminal shows it. */
|
|
684
706
|
function claimWords(claim) {
|
|
@@ -696,7 +718,7 @@ function claimWords(claim) {
|
|
|
696
718
|
callable ? 'callable' : '',
|
|
697
719
|
whole ? 'whole number' : '',
|
|
698
720
|
...(resolves ?? []).map(r => `${r.expression} exists`),
|
|
699
|
-
...shownCases(claim).map(([when, said, relations]) => `if ${when}: ${
|
|
721
|
+
...shownCases(claim).map(([when, said, relations]) => `if ${when}: ${claimWords(said).concat(relations).join(', ')}`)
|
|
700
722
|
].filter(w => w !== '');
|
|
701
723
|
}
|
|
702
724
|
/** The cases of a claim with what each adds to the claim itself, a relation already stated elsewhere left out, and no case that adds nothing. */
|
|
@@ -706,14 +728,16 @@ function shownCases({ cases, ...always }, stated = []) {
|
|
|
706
728
|
}
|
|
707
729
|
/** Each case of a claim as its condition and what holds in it, see {@link claimConditions}; `stated` are the relations said of the formals on their own. */
|
|
708
730
|
function caseConditions(formal, claim, stated = []) {
|
|
709
|
-
return shownCases(claim, stated).map(([when, said, relations]) => `if (${when}): ${(0, condition_grouping_1.allOf)(
|
|
731
|
+
return shownCases(claim, stated).map(([when, said, relations]) => `if (${when}): ${(0, condition_grouping_1.allOf)(claimConditions(formal, said).concat(relations))}`);
|
|
710
732
|
}
|
|
711
733
|
/** What a call returns in a few words, see {@link claimWords}: what holds of it, and the formal it hands back. */
|
|
712
734
|
function returnWords(returns, passes) {
|
|
713
|
-
|
|
735
|
+
const words = claimWords(returns ?? {});
|
|
736
|
+
return passes === undefined ? words : [`the value of ${passes}`].concat(words);
|
|
714
737
|
}
|
|
715
738
|
/** The same as {@link claimConditions}, of the value a call returns, named `result`. */
|
|
716
739
|
function returnConditions(returns, passes) {
|
|
717
|
-
|
|
740
|
+
const conditions = claimConditions('result', returns ?? {});
|
|
741
|
+
return passes === undefined ? conditions : [`identical(result, ${passes})`].concat(conditions);
|
|
718
742
|
}
|
|
719
743
|
//# sourceMappingURL=guard-claims.js.map
|