@eagleoutice/flowr 2.17.9 → 2.17.10
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/cli/repl/core.js +4 -0
- package/config.d.ts +10 -0
- package/config.js +8 -1
- package/control-flow/control-flow-graph.js +11 -1
- package/dataflow/environments/default-builtin-config/guards-primitive-lang.js +1 -1
- package/dataflow/environments/default-builtin-config/guards.js +6 -1
- package/dataflow/environments/default-builtin-config/index.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/network-access.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/network-access.js +2 -0
- package/dataflow/environments/environment.d.ts +2 -0
- package/dataflow/environments/environment.js +5 -0
- package/dataflow/environments/frame-memory.d.ts +9 -0
- package/dataflow/environments/frame-memory.js +37 -0
- package/dataflow/environments/group-generics.d.ts +2 -0
- package/dataflow/environments/group-generics.js +7 -0
- package/dataflow/environments/identifier.d.ts +2 -0
- package/dataflow/environments/identifier.js +16 -0
- package/dataflow/environments/pkg-name.d.ts +1 -0
- package/dataflow/environments/query-fn-props.d.ts +4 -0
- package/dataflow/environments/query-fn-props.js +21 -4
- package/dataflow/environments/resolve-by-name.js +5 -3
- package/dataflow/extractor.js +26 -4
- package/dataflow/fn/guards/call-contracts.js +8 -4
- package/dataflow/fn/guards/function-guards.d.ts +13 -4
- package/dataflow/fn/guards/function-guards.js +147 -52
- package/dataflow/fn/guards/guard-term.d.ts +6 -3
- package/dataflow/fn/guards/guard-term.js +12 -6
- package/dataflow/graph/graph.d.ts +2 -0
- package/dataflow/graph/graph.js +9 -5
- package/dataflow/internal/dispatch-linking.d.ts +6 -0
- package/dataflow/internal/dispatch-linking.js +25 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +32 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +52 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +28 -19
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +75 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +20 -6
- package/dataflow/processor.d.ts +3 -0
- package/documentation/data/faq/faqs.js +4 -0
- package/documentation/wiki-analyzer.js +13 -2
- package/documentation/wiki-interface.js +1 -0
- package/documentation/wiki-linter.js +3 -0
- package/linter/linter-executor.js +4 -1
- package/linter/linter-format.d.ts +5 -5
- package/linter/linter-rules.d.ts +47 -13
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-file-paths.js +1 -1
- package/linter/rules/autoload-files.d.ts +33 -0
- package/linter/rules/autoload-files.js +94 -0
- package/linter/rules/cmd-check/description-metadata.d.ts +2 -2
- package/linter/rules/cmd-check/description-metadata.js +1 -1
- package/linter/rules/cmd-check/documentation-mismatch.d.ts +2 -2
- package/linter/rules/cmd-check/documentation-mismatch.js +1 -1
- package/linter/rules/cmd-check/file-checks.d.ts +6 -11
- package/linter/rules/cmd-check/file-checks.js +8 -3
- package/linter/rules/cmd-check/package-data.d.ts +2 -2
- package/linter/rules/cmd-check/package-data.js +1 -1
- package/linter/rules/cmd-check/package-metafiles.js +1 -1
- package/linter/rules/cmd-check/package-structure.d.ts +2 -2
- package/linter/rules/cmd-check/package-structure.js +1 -1
- package/linter/rules/cmd-check/rd-files.js +1 -1
- package/linter/rules/naming-convention.d.ts +9 -2
- package/linter/rules/process-state-in-session.js +4 -1
- package/linter/rules/software-has-license.d.ts +2 -2
- package/linter/rules/software-has-license.js +1 -2
- package/linter/rules/stop-call.d.ts +8 -3
- package/linter/rules/useless-loop.d.ts +1 -1
- package/package.json +1 -1
- package/project/cache/flowr-analyzer-cache.d.ts +3 -0
- package/project/cache/flowr-analyzer-cache.js +9 -0
- package/project/context/flowr-analyzer-context.d.ts +4 -3
- package/project/context/flowr-analyzer-context.js +18 -6
- package/project/context/flowr-analyzer-dependencies-context.d.ts +9 -0
- package/project/context/flowr-analyzer-dependencies-context.js +35 -6
- package/project/context/flowr-analyzer-environment-context.d.ts +1 -0
- package/project/context/flowr-analyzer-environment-context.js +1 -0
- package/project/context/flowr-analyzer-files-context.d.ts +4 -0
- package/project/context/flowr-analyzer-files-context.js +24 -0
- package/project/context/flowr-analyzer-functions-context.d.ts +1 -0
- package/project/context/flowr-analyzer-functions-context.js +6 -0
- package/project/context/flowr-analyzer-gas-context.d.ts +1 -0
- package/project/context/flowr-analyzer-gas-context.js +1 -0
- package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +24 -0
- package/project/context/flowr-analyzer-incremental-analysis-context.js +54 -0
- package/project/context/flowr-analyzer-loading-order-context.d.ts +1 -0
- package/project/context/flowr-analyzer-loading-order-context.js +14 -0
- package/project/context/flowr-analyzer-meta-context.d.ts +1 -0
- package/project/context/flowr-analyzer-meta-context.js +11 -0
- package/project/context/flowr-file.d.ts +2 -1
- package/project/context/flowr-file.js +5 -2
- package/project/flowr-analyzer.d.ts +22 -3
- package/project/flowr-analyzer.js +36 -0
- package/project/incremental/incremental-dataflow/incremental-dataflow.d.ts +142 -0
- package/project/incremental/incremental-dataflow/incremental-dataflow.js +330 -0
- package/project/plugins/flowr-analyzer-plugin.d.ts +22 -2
- package/project/plugins/flowr-analyzer-plugin.js +16 -1
- package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-heuristic-plugin.d.ts +52 -0
- package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-heuristic-plugin.js +50 -0
- package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-update-type-plugin.d.ts +77 -0
- package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-update-type-plugin.js +151 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +4 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +3 -0
- package/project/plugins/plugin-registry.d.ts +3 -1
- package/project/plugins/plugin-registry.js +6 -1
- package/project/sigdb/decode.js +4 -1
- package/project/sigdb/dict.d.ts +7 -4
- package/project/sigdb/dict.js +20 -6
- package/project/sigdb/guarded-source.js +10 -0
- package/project/sigdb/reader.d.ts +8 -2
- package/project/sigdb/reader.js +44 -30
- package/queries/catalog/input-sources-query/simple-input-classifier.js +84 -10
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/objects.d.ts +14 -0
- package/util/objects.js +100 -0
package/dataflow/extractor.js
CHANGED
|
@@ -68,6 +68,7 @@ const happens_before_1 = require("../control-flow/happens-before");
|
|
|
68
68
|
const assert_1 = require("../util/assert");
|
|
69
69
|
const node_value_1 = require("./eval/resolve/node-value");
|
|
70
70
|
const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
71
|
+
const incremental_dataflow_1 = require("../project/incremental/incremental-dataflow/incremental-dataflow");
|
|
71
72
|
/** The best friend of {@link produceDataFlowGraph} and {@link processDataflowFor}. Maps every {@link RType} in the normalized AST to a processor. */
|
|
72
73
|
exports.processors = {
|
|
73
74
|
[type_1.RType.Number]: process_value_1.processValue,
|
|
@@ -814,28 +815,49 @@ function produceDataFlowGraph(parser, completeAst, ctx, budget = ctx.gas.budget(
|
|
|
814
815
|
function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
815
816
|
// we freeze the files here to avoid endless modifications during processing
|
|
816
817
|
const files = completeAst.ast.files.slice();
|
|
818
|
+
/* the project kind depends on the files considered, so a repeated analysis must not start from what the last one found */
|
|
819
|
+
ctx.files.forgetConsideredFiles();
|
|
817
820
|
ctx.files.addConsideredFile(files[0].filePath ? files[0].filePath : flowr_file_1.FlowrFile.INLINE_PATH);
|
|
821
|
+
const base = {
|
|
822
|
+
parser,
|
|
823
|
+
completeAst,
|
|
824
|
+
processors: ctx.config.solver.instrument.dataflowExtractors?.(exports.processors, ctx) ?? exports.processors,
|
|
825
|
+
ctx
|
|
826
|
+
};
|
|
827
|
+
const session = incremental_dataflow_1.IncrementalDataflow.begin(completeAst, ctx);
|
|
828
|
+
const reused = session?.reuseFinalized();
|
|
829
|
+
if (reused !== undefined) {
|
|
830
|
+
return reused;
|
|
831
|
+
}
|
|
832
|
+
const result = session?.reuse(base) ?? runFullDataflow(files, base, session);
|
|
833
|
+
session?.end(result);
|
|
834
|
+
const df = finalizeDataflow(result.df, result.dfData, completeAst, ctx);
|
|
835
|
+
return session?.finalized(df) ?? df;
|
|
836
|
+
}
|
|
837
|
+
function runFullDataflow(files, base, checkpoints) {
|
|
838
|
+
const ctx = base.ctx;
|
|
818
839
|
const env = ctx.env.makeCleanEnv();
|
|
819
840
|
/* what an earlier program noted on the built-in environment all programs share does not hold for this one */
|
|
820
841
|
environment_1.REnvironment.findBuiltIn(env.current).forgetProgramMarks();
|
|
821
842
|
env.current.n = ctx.meta.getNamespace();
|
|
822
843
|
const environment = (0, built_in_library_1.attachProject)(env, ctx);
|
|
823
844
|
const dfData = {
|
|
824
|
-
|
|
825
|
-
completeAst,
|
|
845
|
+
...base,
|
|
826
846
|
environment,
|
|
827
|
-
processors: ctx.config.solver.instrument.dataflowExtractors?.(exports.processors, ctx) ?? exports.processors,
|
|
828
847
|
cds: undefined,
|
|
829
848
|
referenceChain: [files[0].filePath],
|
|
830
849
|
statementOrder: new Map(),
|
|
831
850
|
unreachable: new Set(),
|
|
832
|
-
|
|
851
|
+
checkpoints
|
|
833
852
|
};
|
|
834
853
|
let df = (0, assert_1.guardNesting)('Dataflow analysis', files[0].filePath, () => (0, processor_1.processDataflowFor)(files[0].root, dfData));
|
|
835
854
|
for (let i = 1; i < files.length; i++) {
|
|
836
855
|
/* source requests register automatically */
|
|
837
856
|
df = (0, built_in_source_1.standaloneSourceFile)(i, files[i], dfData, df);
|
|
838
857
|
}
|
|
858
|
+
return { df, dfData: dfData };
|
|
859
|
+
}
|
|
860
|
+
function finalizeDataflow(df, dfData, completeAst, ctx) {
|
|
839
861
|
// resolve linkages and propagate transitive side effects across calls to a fixpoint
|
|
840
862
|
callActiveBindings(df.graph);
|
|
841
863
|
(0, built_in_s_four_1.linkInstantiations)(df.graph);
|
|
@@ -259,10 +259,14 @@ function breaches(call, contract, scope) {
|
|
|
259
259
|
const given = match_args_1.MatchArgs.toSpec(vertex.args, Object.fromEntries(contract.formals.map(f => [f, f])));
|
|
260
260
|
const result = match_args_1.MatchArgs.handsOnDots(vertex.args, graph) ? [] : contract.required.filter(f => f !== '...' && (given.get(f)?.length ?? 0) === 0).map(formal => ({ kind: 'missing', formal }));
|
|
261
261
|
const args = new Map();
|
|
262
|
-
const binding = (0, function_guards_1.callBinding)(vertex, contract.formals, graph,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
const binding = (0, function_guards_1.callBinding)(vertex, contract.formals, graph, {
|
|
263
|
+
value: node => {
|
|
264
|
+
const placeholder = `#${String(node.info.id)}`;
|
|
265
|
+
args.set(placeholder, { node });
|
|
266
|
+
return guard_term_1.GuardTerm.formal(placeholder);
|
|
267
|
+
},
|
|
268
|
+
/* a name may be that of a formal the function around the call was not given */
|
|
269
|
+
missing: name => (0, function_guards_1.readsViaParameter)(df_helper_1.Dataflow.origin(graph, name.info.id) ?? [], graph) ? undefined : guard_term_1.GuardTerm.False
|
|
266
270
|
});
|
|
267
271
|
const literalsAt = (placeholder) => {
|
|
268
272
|
const argument = args.get(placeholder);
|
|
@@ -74,15 +74,24 @@ export declare function isParameter(this: void, id: NodeId, idMap: AstIdMap): bo
|
|
|
74
74
|
export declare function readsViaParameter(this: void, origins: readonly Origin[], graph: DataflowGraph): boolean;
|
|
75
75
|
/** What the caller states the value of an argument as, `undefined` if it cannot. */
|
|
76
76
|
export type ArgumentTerm = (value: RNodeWithParent) => GuardTerm | undefined;
|
|
77
|
-
/**
|
|
78
|
-
|
|
77
|
+
/** How the caller states the arguments of a call. */
|
|
78
|
+
export interface ArgumentTerms {
|
|
79
|
+
readonly value: ArgumentTerm;
|
|
80
|
+
/** what `missing` is of a formal handed an argument that is but a name, the only kind R looks through to a formal of the caller */
|
|
81
|
+
readonly missing: ArgumentTerm;
|
|
82
|
+
}
|
|
83
|
+
/** What the given arguments of the call bind the formals `names` of the callee to, seen from the caller, with what `missing` is of them where the call tells, and whether that leaves no formal unbound. */
|
|
84
|
+
declare function bindingOfArguments(this: void, vertex: DataflowGraphVertexFunctionCall, args: DataflowGraphVertexFunctionCall['args'], names: readonly BrandedIdentifier[], graph: DataflowGraph, terms: ArgumentTerms): {
|
|
79
85
|
readonly binding: GuardBinding;
|
|
86
|
+
readonly absent: GuardBinding;
|
|
80
87
|
readonly complete: boolean;
|
|
81
88
|
};
|
|
82
89
|
/** What a call binds the formals of its callee to, see {@link callBinding}. */
|
|
83
90
|
export interface CallBinding {
|
|
84
91
|
/** what the formals stand for for sure */
|
|
85
92
|
readonly binding: GuardBinding;
|
|
93
|
+
/** what `missing` is of each formal, where the call tells */
|
|
94
|
+
readonly absent?: GuardBinding;
|
|
86
95
|
/** if the call hands on dots, what they stand for if the dots name nothing */
|
|
87
96
|
readonly besides?: ReturnType<typeof bindingOfArguments>;
|
|
88
97
|
/** the call leaves the dots of the callee without a name */
|
|
@@ -90,9 +99,9 @@ export interface CallBinding {
|
|
|
90
99
|
}
|
|
91
100
|
/**
|
|
92
101
|
* What the call binds the formals `names` of its callee to, by R's argument matching, the way the contract of a callee is inherited:
|
|
93
|
-
* `
|
|
102
|
+
* `terms` state the arguments in the words of the caller.
|
|
94
103
|
*/
|
|
95
|
-
export declare function callBinding(this: void, vertex: DataflowGraphVertexFunctionCall, names: readonly BrandedIdentifier[], graph: DataflowGraph,
|
|
104
|
+
export declare function callBinding(this: void, vertex: DataflowGraphVertexFunctionCall, names: readonly BrandedIdentifier[], graph: DataflowGraph, terms: ArgumentTerms): CallBinding;
|
|
96
105
|
/**
|
|
97
106
|
* A condition of a callee in the words of a caller binding its formals by `call`, see {@link callBinding}, with `outer` stating what the callee reads from outside:
|
|
98
107
|
* `requires` holds for sure, and `unlessNamed`, if the call hands on dots, holds as long as they name nothing.
|
|
@@ -51,6 +51,7 @@ const dispatch_1 = require("../dispatch");
|
|
|
51
51
|
const dispatch_linking_1 = require("../../internal/dispatch-linking");
|
|
52
52
|
const r_base_packages_1 = require("../../../util/r-base-packages");
|
|
53
53
|
const r_base_guards_generated_1 = require("../../../data/r-base-guards.generated");
|
|
54
|
+
const r_primitives_generated_1 = require("../../../data/r-primitives.generated");
|
|
54
55
|
const branch_paths_1 = require("../../../abstract-interpretation/branch-paths");
|
|
55
56
|
const control_flow_graph_1 = require("../../../control-flow/control-flow-graph");
|
|
56
57
|
const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
@@ -64,7 +65,7 @@ const happens_before_1 = require("../../../control-flow/happens-before");
|
|
|
64
65
|
const guard_claims_1 = require("./guard-claims");
|
|
65
66
|
/** Nothing is known about why the code was reached, as with a loop body. */
|
|
66
67
|
const UnknownStep = { holds: guard_term_1.GuardTerm.True, fails: guard_term_1.GuardTerm.True };
|
|
67
|
-
const NoContract = { clauses: [], required: [], effects: true, opens: false, returned: [], reach: 0, called: false };
|
|
68
|
+
const NoContract = { clauses: [], required: [], forced: [], effects: true, opens: false, returned: [], reach: 0, called: false };
|
|
68
69
|
/** {@link Dataflow.origin} of the node, worked out once per node and guard state. */
|
|
69
70
|
function originsOf(state, id) {
|
|
70
71
|
state.origins ??= (0, defaultmap_1.memoize)(n => df_helper_1.Dataflow.origin(state.graph, n));
|
|
@@ -272,31 +273,38 @@ function formalNamesOf({ definition }) {
|
|
|
272
273
|
function namesFormal(argument, names) {
|
|
273
274
|
return graph_1.FunctionArgument.isNamed(argument) && names.includes(argument.name);
|
|
274
275
|
}
|
|
275
|
-
/** What the given arguments of the call bind the formals `names` of the callee to, seen from the caller, with whether that leaves no formal unbound. */
|
|
276
|
-
function bindingOfArguments(vertex, args, names, graph,
|
|
276
|
+
/** What the given arguments of the call bind the formals `names` of the callee to, seen from the caller, with what `missing` is of them where the call tells, and whether that leaves no formal unbound. */
|
|
277
|
+
function bindingOfArguments(vertex, args, names, graph, terms) {
|
|
277
278
|
const binding = new Map();
|
|
279
|
+
const absent = new Map();
|
|
278
280
|
const matched = match_args_1.MatchArgs.toSpec(args, Object.fromEntries(names.map(n => [n, n])));
|
|
281
|
+
const given = (formal) => (matched.get(formal)?.length ?? 0) > 0;
|
|
282
|
+
const set = (to, formal, term) => term === undefined ? to : to.set(formal, term);
|
|
279
283
|
for (const [formal, ids] of matched) {
|
|
280
284
|
const value = formal === '...' || ids.length !== 1 ? undefined : valueOfArgument(ids[0], vertex, graph);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
285
|
+
if (value !== undefined) {
|
|
286
|
+
set(binding, formal, terms.value(value));
|
|
287
|
+
set(absent, formal, r_symbol_1.RSymbol.is(value) ? terms.missing(value) : guard_term_1.GuardTerm.False);
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
|
-
|
|
290
|
+
/* what the dots hand on may fill any formal the call leaves out */
|
|
291
|
+
if (!match_args_1.MatchArgs.handsOnDots(vertex.args, graph)) {
|
|
292
|
+
names.filter(n => n !== '...' && !given(n)).forEach(n => absent.set(n, guard_term_1.GuardTerm.True));
|
|
293
|
+
}
|
|
294
|
+
return { binding, absent, complete: names.every(n => n !== '...' && given(n)) };
|
|
287
295
|
}
|
|
288
296
|
/** What the arguments of the call bind the formals of the callee to for sure: what the dots hand on may name any formal, which moves the arguments given by position, so only the ones given by their full name stay. */
|
|
289
|
-
function bindingOf(vertex, names, graph,
|
|
297
|
+
function bindingOf(vertex, names, graph, terms) {
|
|
290
298
|
const args = match_args_1.MatchArgs.handsOnDots(vertex.args, graph) ? vertex.args.filter(a => namesFormal(a, names)) : vertex.args;
|
|
291
|
-
return bindingOfArguments(vertex, args, names, graph,
|
|
299
|
+
return bindingOfArguments(vertex, args, names, graph, terms);
|
|
292
300
|
}
|
|
293
301
|
/** What the arguments of a call handing on dots bind if the dots name nothing, which only keeps the arguments in front of the dots in place. */
|
|
294
|
-
function bindingBesidesDots(vertex, names, graph,
|
|
302
|
+
function bindingBesidesDots(vertex, names, graph, terms) {
|
|
295
303
|
const dots = vertex.args.findIndex(a => match_args_1.MatchArgs.handsOnDots([a], graph));
|
|
296
304
|
if (dots < 0) {
|
|
297
305
|
return undefined;
|
|
298
306
|
}
|
|
299
|
-
return bindingOfArguments(vertex, vertex.args.filter((a, at) => at < dots || namesFormal(a, names)), names, graph,
|
|
307
|
+
return bindingOfArguments(vertex, vertex.args.filter((a, at) => at < dots || namesFormal(a, names)), names, graph, terms);
|
|
300
308
|
}
|
|
301
309
|
/** Whether something the dots hand on bears a name, which only the function holding the dots can tell. */
|
|
302
310
|
const DotsBearNames = guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('is.null', guard_term_1.GuardTerm.known('...names')));
|
|
@@ -307,13 +315,13 @@ function leavesDotsUnnamed(vertex, names, graph) {
|
|
|
307
315
|
}
|
|
308
316
|
/**
|
|
309
317
|
* What the call binds the formals `names` of its callee to, by R's argument matching, the way the contract of a callee is inherited:
|
|
310
|
-
* `
|
|
318
|
+
* `terms` state the arguments in the words of the caller.
|
|
311
319
|
*/
|
|
312
|
-
function callBinding(vertex, names, graph,
|
|
313
|
-
const besides = bindingBesidesDots(vertex, names, graph,
|
|
320
|
+
function callBinding(vertex, names, graph, terms) {
|
|
321
|
+
const besides = bindingBesidesDots(vertex, names, graph, terms);
|
|
314
322
|
/* with every formal bound and no dots to take more, anything further the dots hand on is an error, so nothing can move */
|
|
315
|
-
const binding = besides?.complete ? besides
|
|
316
|
-
return { binding, ...(besides === undefined ? {} : { besides }), dotsUnnamed: leavesDotsUnnamed(vertex, names, graph) };
|
|
323
|
+
const { binding, absent } = besides?.complete ? besides : bindingOf(vertex, names, graph, terms);
|
|
324
|
+
return { binding, absent, ...(besides === undefined ? {} : { besides }), dotsUnnamed: leavesDotsUnnamed(vertex, names, graph) };
|
|
317
325
|
}
|
|
318
326
|
/**
|
|
319
327
|
* A condition of a callee in the words of a caller binding its formals by `call`, see {@link callBinding}, with `outer` stating what the callee reads from outside:
|
|
@@ -321,13 +329,37 @@ function callBinding(vertex, names, graph, termOfArgument) {
|
|
|
321
329
|
*/
|
|
322
330
|
function atCall(condition, call, outer, facts) {
|
|
323
331
|
const asked = call.dotsUnnamed ? guard_term_1.GuardTerm.any(...guard_term_1.GuardTerm.disjuncts(condition).filter(d => guard_term_1.GuardTerm.render(d) !== DotsBearNamesText)) : condition;
|
|
324
|
-
const requires = guard_term_1.GuardTerm.substituteCondition(asked, call.binding, outer, facts);
|
|
332
|
+
const requires = guard_term_1.GuardTerm.substituteCondition(asked, call.binding, outer, facts, call.absent);
|
|
325
333
|
if (call.besides === undefined || call.besides.complete) {
|
|
326
334
|
return { requires };
|
|
327
335
|
}
|
|
328
|
-
const unlessNamed = guard_term_1.GuardTerm.substituteCondition(asked, call.besides.binding, outer, facts);
|
|
336
|
+
const unlessNamed = guard_term_1.GuardTerm.substituteCondition(asked, call.besides.binding, outer, facts, call.besides.absent);
|
|
329
337
|
return guard_term_1.GuardTerm.render(unlessNamed) === guard_term_1.GuardTerm.render(requires) ? { requires } : { requires, unlessNamed: guard_term_1.GuardTerm.any(DotsBearNames, unlessNamed) };
|
|
330
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* The arguments of a call as the function calling states them. A callee finds a formal missing that was handed the name of a formal the call
|
|
341
|
+
* of the caller left out, unless that has a default (R then only looks through a default that is a name again, which is not followed).
|
|
342
|
+
*/
|
|
343
|
+
function statedBy(scope, state, depth = 0) {
|
|
344
|
+
const value = (node) => termOf(node, scope, state, depth);
|
|
345
|
+
return {
|
|
346
|
+
value,
|
|
347
|
+
missing: name => {
|
|
348
|
+
const term = value(name);
|
|
349
|
+
if (term?.kind !== 'formal') {
|
|
350
|
+
return term === undefined ? undefined : guard_term_1.GuardTerm.False;
|
|
351
|
+
}
|
|
352
|
+
const own = scope.definition.parameters.find(p => p.name.content === term.name);
|
|
353
|
+
return own === undefined || own.defaultValue !== undefined || name.lexeme !== term.name ? undefined : guard_term_1.GuardTerm.known('missing', term);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/** Nothing of the arguments stated, as the callee decides which of them R evaluates first, so one binding a name changes what the others read. */
|
|
358
|
+
const Unstated = { value: () => undefined, missing: () => undefined };
|
|
359
|
+
/** Whether the code binds a name itself, as `g(x, x <- 1)` does. */
|
|
360
|
+
function bindsWithin(node, state) {
|
|
361
|
+
return node !== undefined && model_1.RNode.collectAllIdsWithStop(node, n => r_function_definition_1.RFunctionDefinition.is(n)).values().some(id => vertex_1.DfgVertex.isVariableDefinition(state.graph.getVertex(id)));
|
|
362
|
+
}
|
|
331
363
|
/** The node of the value of an argument, a named argument being bound by the node that names it. */
|
|
332
364
|
function valueOfArgument(argument, vertex, graph) {
|
|
333
365
|
const named = vertex.args.find(a => graph_1.FunctionArgument.isNamed(a) && a.nodeId === argument);
|
|
@@ -344,7 +376,11 @@ function inlined(id, vertex, scope, state, depth) {
|
|
|
344
376
|
/* a generic hands over to whichever method it dispatches to, what it says itself is no value of the call */
|
|
345
377
|
const body = single !== undefined && r_function_call_1.RFunctionCall.isNamed(single) && identifier_1.Identifier.getName(single.functionName.content) === 'UseMethod' ? undefined : single;
|
|
346
378
|
const term = callee === undefined || body === undefined ? undefined : termOf(body, callee, state, depth + 1);
|
|
347
|
-
|
|
379
|
+
if (term === undefined || callee === undefined) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
const { binding, absent } = bindingOf(vertex, formalNamesOf(callee), state.graph, statedBy(scope, state, depth + 1));
|
|
383
|
+
return guard_term_1.GuardTerm.substitute(term, binding, undefined, absent);
|
|
348
384
|
}
|
|
349
385
|
function callTerm(id, fn, args, state) {
|
|
350
386
|
const vertex = callVertexOf(id, state);
|
|
@@ -435,7 +471,9 @@ function termOfUncached(node, scope, state, depth) {
|
|
|
435
471
|
if (args === undefined) {
|
|
436
472
|
return undefined;
|
|
437
473
|
}
|
|
438
|
-
|
|
474
|
+
const call = callTerm(node.info.id, identifier_1.Identifier.toString(node.functionName.content), args, state);
|
|
475
|
+
/* a formal that got a value in the body is not missing anymore */
|
|
476
|
+
return guard_term_1.GuardTerm.isCall(call, 'missing') && call.known && (args[0]?.value.kind === 'constant' || guard_term_1.GuardTerm.isCall(args[0]?.value)) ? guard_term_1.GuardTerm.False : call;
|
|
439
477
|
}
|
|
440
478
|
default:
|
|
441
479
|
return undefined;
|
|
@@ -466,6 +504,10 @@ function addClause(run, path, condition, at, extra) {
|
|
|
466
504
|
}
|
|
467
505
|
}
|
|
468
506
|
}
|
|
507
|
+
/** Whether the node of a call is but the name of the function, which an applier like `do.call` runs. */
|
|
508
|
+
function isHandedOver(node) {
|
|
509
|
+
return r_symbol_1.RSymbol.is(node) || r_string_1.RString.is(node);
|
|
510
|
+
}
|
|
469
511
|
/**
|
|
470
512
|
* What may write to the frame of the function without that showing up as a definition once it runs or is defined: `e <- environment()`, `rm(x)`, or a closure with `x <<- v`.
|
|
471
513
|
* A `<<-` right in the frame writes to the frames around it instead.
|
|
@@ -486,6 +528,10 @@ function frameOpeners(definition, state) {
|
|
|
486
528
|
openers.add(id);
|
|
487
529
|
}
|
|
488
530
|
}
|
|
531
|
+
/* what an applier runs binds without a definition the dataflow sees, as `do.call("<-", .)` does */
|
|
532
|
+
if (vertex !== undefined && isHandedOver(node) && built_in_props_1.CallProps.hasAny(state.info(vertex.name), built_in_props_1.CallProp.Scope)) {
|
|
533
|
+
openers.add(id);
|
|
534
|
+
}
|
|
489
535
|
});
|
|
490
536
|
return openers;
|
|
491
537
|
}
|
|
@@ -570,22 +616,24 @@ function boundArguments(vertex, sig, state) {
|
|
|
570
616
|
return bound;
|
|
571
617
|
}
|
|
572
618
|
/**
|
|
573
|
-
* The formals of a function
|
|
574
|
-
*
|
|
575
|
-
*
|
|
619
|
+
* The formals of a function written in R, not C, a missing formal of the caller may be handed to: R hands on a promise, and that only fails once
|
|
620
|
+
* the function evaluates it (`matpoints(x, y)` hands a missing `y` to `matplot`, which asks `missing(y)`). So all of them but the ones the function
|
|
621
|
+
* is known to evaluate: what `asks` something of its value whatever else was given, what the contract of a function of base R requires, or,
|
|
622
|
+
* without one, what it dispatches on as a generic.
|
|
576
623
|
*/
|
|
577
|
-
function closureMissingOk(name, formals) {
|
|
578
|
-
|
|
579
|
-
if (owner === undefined || (0, r_base_packages_1.isBasePrimitive)(name)) {
|
|
624
|
+
function closureMissingOk(name, formals, facts) {
|
|
625
|
+
if (r_primitives_generated_1.RPrimitives.has(String(name))) {
|
|
580
626
|
return [];
|
|
581
627
|
}
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
628
|
+
const owner = (0, r_base_packages_1.baseRExportOwner)(name);
|
|
629
|
+
const stored = owner === undefined ? undefined : (0, r_base_guards_generated_1.RBaseGuards)()[String(owner)]?.[String(name)];
|
|
630
|
+
/* a function of base R without a contract of its own evaluates what flowR's model of it says */
|
|
631
|
+
if (owner !== undefined && stored === undefined) {
|
|
585
632
|
return [];
|
|
586
633
|
}
|
|
587
|
-
const
|
|
588
|
-
|
|
634
|
+
const asked = Object.entries(facts?.asks ?? {}).filter(([, failures]) => failures.some(f => f.when === undefined)).map(([formal]) => formal);
|
|
635
|
+
const evaluated = new Set([...asked, ...stored?.required ?? [], ...stored?.dispatches === undefined ? [] : [String(stored.dispatches)]]);
|
|
636
|
+
return formals.filter(f => !evaluated.has(String(f)));
|
|
589
637
|
}
|
|
590
638
|
/** The arguments handed over which R evaluates for sure, in the order they are written, and those it may not. */
|
|
591
639
|
function evaluatedAndNot(vertex, state) {
|
|
@@ -597,7 +645,8 @@ function evaluatedAndNot(vertex, state) {
|
|
|
597
645
|
const bound = boundArguments(vertex, sig, state);
|
|
598
646
|
/* a special primitive matching its arguments itself takes a missing formal handed to some of its own as not given */
|
|
599
647
|
const name = identifier_1.Identifier.getName(vertex.name);
|
|
600
|
-
const
|
|
648
|
+
const facts = state.facts(name);
|
|
649
|
+
const missingOk = [...facts?.missingOk ?? [], ...closureMissingOk(name, sig.map(([formal]) => formal), facts)];
|
|
601
650
|
const forcedIds = new Set(sig.filter(([, props]) => (props & built_in_props_1.ArgProp.Forced) !== 0).flatMap(([formal]) => (bound.get(formal) ?? []).filter(v => !missingOk.includes(formal) || !r_symbol_1.RSymbol.is(v))));
|
|
602
651
|
return { forced: values.filter(v => forcedIds.has(v)), lazy: values.filter(v => !forcedIds.has(v)) };
|
|
603
652
|
}
|
|
@@ -775,10 +824,23 @@ function getRequirement(node, path, run) {
|
|
|
775
824
|
addClause(run, path, (0, guard_knowledge_1.getAsExists)({ ...term, fn: 'get' }), node.info.id, { kind: 'implicit' });
|
|
776
825
|
}
|
|
777
826
|
}
|
|
827
|
+
/** A check that only fails for an argument that was not given asks `missing` of what it is handed, as any callee does, see {@link statedBy}. */
|
|
828
|
+
function presenceRequirement(vertex, path, run) {
|
|
829
|
+
const { state, scope } = run;
|
|
830
|
+
const [given] = vertex.args.filter(graph_1.FunctionArgument.isNotEmpty).map(a => valueOfArgument(a.nodeId, vertex, state.graph));
|
|
831
|
+
const gone = r_symbol_1.RSymbol.is(given) ? statedBy(scope, state).missing(given) : undefined;
|
|
832
|
+
if (gone !== undefined) {
|
|
833
|
+
addClause(run, path, guard_term_1.GuardTerm.truth(gone, false, state.facts), vertex.id, { kind: 'explicit' });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
778
836
|
/** A call flowR knows the failing of: `succeeds(check(x))`, with the choices `match.arg` takes from the default of the formal spelled out. */
|
|
779
837
|
function checkRequirement(name, node, vertex, path, run) {
|
|
780
838
|
const term = termOf(node, run.scope, run.state);
|
|
781
839
|
const check = run.state.facts(name)?.check;
|
|
840
|
+
if (check?.present) {
|
|
841
|
+
presenceRequirement(vertex, path, run);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
782
844
|
if (check === undefined || !guard_term_1.GuardTerm.isCall(term) || check.defers?.some(d => term.args.some(a => a.name === d))) {
|
|
783
845
|
return;
|
|
784
846
|
}
|
|
@@ -807,7 +869,7 @@ function inherit(target, vertex, path, run) {
|
|
|
807
869
|
run.effects = true;
|
|
808
870
|
return;
|
|
809
871
|
}
|
|
810
|
-
const call = callBinding(vertex, formalNamesOf(callee), state.graph,
|
|
872
|
+
const call = callBinding(vertex, formalNamesOf(callee), state.graph, bindsWithin(nodeOf(vertex.id, state), state) ? Unstated : statedBy(scope, state));
|
|
811
873
|
/* a closure reads the formals of the function it is called from as well */
|
|
812
874
|
function outer(origin) {
|
|
813
875
|
const name = scope.formals.get(origin);
|
|
@@ -823,11 +885,11 @@ function inherit(target, vertex, path, run) {
|
|
|
823
885
|
addClause(run, path, unlessNamed, clause.at, inherited);
|
|
824
886
|
}
|
|
825
887
|
}
|
|
826
|
-
if (path.length === 0) {
|
|
827
|
-
for (const formal of contract.
|
|
888
|
+
if (path.length === 0 && !scope.frameIsOpen) {
|
|
889
|
+
for (const formal of contract.forced) {
|
|
828
890
|
const bound = call.binding.get(formal);
|
|
829
891
|
if (bound?.kind === 'formal') {
|
|
830
|
-
run.
|
|
892
|
+
run.forced.add(bound.name);
|
|
831
893
|
}
|
|
832
894
|
}
|
|
833
895
|
}
|
|
@@ -995,7 +1057,7 @@ function operatorMethods(name, vertex, path, run) {
|
|
|
995
1057
|
return;
|
|
996
1058
|
}
|
|
997
1059
|
const terms = operands;
|
|
998
|
-
const bound = (callee) => bindingOf(vertex, formalNamesOf(callee), state.graph,
|
|
1060
|
+
const bound = (callee) => bindingOf(vertex, formalNamesOf(callee), state.graph, statedBy(scope, state)).binding;
|
|
999
1061
|
const unclassed = (others) => others.filter(o => o.kind !== 'constant').map(o => guard_term_1.GuardTerm.known('is.object', o));
|
|
1000
1062
|
const classes = new Set([...state.methodClasses(name), ...state.methodClasses(group)]);
|
|
1001
1063
|
if (s4.length === 0) {
|
|
@@ -1072,6 +1134,21 @@ function inLoopOf(node, { state, scope }) {
|
|
|
1072
1134
|
return (r_for_loop_1.RForLoop.is(parent) || r_while_loop_1.RWhileLoop.is(parent) || r_repeat_loop_1.RRepeatLoop.is(parent)) && parent.body === n && within(parent, scope.definition.body, state);
|
|
1073
1135
|
});
|
|
1074
1136
|
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Whether only blocks and the branches of `if`s lie between the node and the body, which the paths to what comes after tell apart:
|
|
1139
|
+
* a loop, an operand, or an argument around a `return` joins the way through it with the ways around.
|
|
1140
|
+
*/
|
|
1141
|
+
function inBranchesOnly(node, { state, scope }) {
|
|
1142
|
+
const idMap = state.graph.idMap;
|
|
1143
|
+
for (let at = node; at !== scope.definition.body;) {
|
|
1144
|
+
const parent = model_1.RNode.directParent(at, idMap);
|
|
1145
|
+
if (!r_expression_list_1.RExpressionList.is(parent) && !(r_if_then_else_1.RIfThenElse.is(parent) && parent.condition !== at)) {
|
|
1146
|
+
return false;
|
|
1147
|
+
}
|
|
1148
|
+
at = parent;
|
|
1149
|
+
}
|
|
1150
|
+
return true;
|
|
1151
|
+
}
|
|
1075
1152
|
/** Whether the code ends in a `stop`, so it never completes. */
|
|
1076
1153
|
function alwaysFails(node, state) {
|
|
1077
1154
|
let last = node;
|
|
@@ -1175,9 +1252,15 @@ function pathsAt(node, run) {
|
|
|
1175
1252
|
const { scope } = run;
|
|
1176
1253
|
const order = run.order;
|
|
1177
1254
|
/* what holds of the formals is gone once the frame may have been written behind the back of the dataflow */
|
|
1178
|
-
|
|
1255
|
+
/* one within the node may run before the rest of it, as an argument R evaluates once the callee asks for it */
|
|
1256
|
+
scope.frameIsOpen = order.openers.size > 0 && (model_1.RNode.collectAllIds(node).values().some(id => order.openers.has(id)) || order.before(order.openers, node.info.id).length > 0);
|
|
1179
1257
|
run.effects = order.effectfulDefaults || order.before(order.effects, node.info.id).length > 0;
|
|
1180
1258
|
const exits = order.before(order.exits, node.info.id).map(order.exitStep);
|
|
1259
|
+
/* the control flow ends at a `return`, so what is written after one comes after it as well */
|
|
1260
|
+
const at = positionOf(node.info.id, run.state);
|
|
1261
|
+
if (order.unsureExits.size > 0 && (order.before(order.unsureExits, node.info.id).length > 0 || order.unsureExits.values().some(exit => positionOf(exit, run.state) < at))) {
|
|
1262
|
+
exits.push(UnknownStep);
|
|
1263
|
+
}
|
|
1181
1264
|
return stepsTo(node, run)?.map(({ path, skips }) => ({ path: [...path, ...exits], skips }));
|
|
1182
1265
|
}
|
|
1183
1266
|
/**
|
|
@@ -1216,12 +1299,22 @@ function orderOf(run) {
|
|
|
1216
1299
|
const effects = new Set();
|
|
1217
1300
|
const openers = new Set(run.openers);
|
|
1218
1301
|
const exits = [];
|
|
1302
|
+
const unsureExits = new Set();
|
|
1219
1303
|
const inUseMethod = new Set();
|
|
1220
1304
|
for (const id of model_1.RNode.collectAllIdsWithStop(scope.definition.body, n => r_function_definition_1.RFunctionDefinition.is(n))) {
|
|
1221
1305
|
const vertex = callVertexOf(id, state);
|
|
1222
1306
|
const node = nodeOf(id, state);
|
|
1223
|
-
if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Return) &&
|
|
1224
|
-
|
|
1307
|
+
if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Return) && node !== undefined && !r_symbol_1.RSymbol.is(node)) {
|
|
1308
|
+
if (!runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Return)) {
|
|
1309
|
+
exits.push(id);
|
|
1310
|
+
}
|
|
1311
|
+
else if (!inBranchesOnly(node, run)) {
|
|
1312
|
+
unsureExits.add(id);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
else if (vertex !== undefined && isHandedOver(node) && knownNameOf(id, vertex, state) === 'return') {
|
|
1316
|
+
/* `do.call(return, .)` */
|
|
1317
|
+
unsureExits.add(id);
|
|
1225
1318
|
}
|
|
1226
1319
|
/* what names the generic of a `UseMethod` is no call of its own, whatever the dataflow turns it into */
|
|
1227
1320
|
if (vertex !== undefined && knownNameOf(id, vertex, state) === 'UseMethod' && r_function_call_1.RFunctionCall.is(node)) {
|
|
@@ -1246,7 +1339,7 @@ function orderOf(run) {
|
|
|
1246
1339
|
return vertex !== undefined && !r_symbol_1.RSymbol.is(nodeOf(id, state)) && !onlyComputes(id, vertex, state);
|
|
1247
1340
|
}));
|
|
1248
1341
|
const cfg = branchPathsOf(state).controlFlow.graph;
|
|
1249
|
-
return { effects, openers, effectfulDefaults, exits: new Set(exits), exitStep: (0, defaultmap_1.memoize)((exit) => exitStep(exit, run)), before: (candidates, node) => [...(0, happens_before_1.happensBeforeEach)(cfg, candidates, node).keys()].filter(c => c !== node) };
|
|
1342
|
+
return { effects, openers, effectfulDefaults, exits: new Set(exits), unsureExits, exitStep: (0, defaultmap_1.memoize)((exit) => exitStep(exit, run)), before: (candidates, node) => [...(0, happens_before_1.happensBeforeEach)(cfg, candidates, node).keys()].filter(c => c !== node) };
|
|
1250
1343
|
}
|
|
1251
1344
|
/** Each path to the node, with what flowR cannot tell how the node is reached left without any. */
|
|
1252
1345
|
function eachPath(node, run, fn) {
|
|
@@ -1365,6 +1458,7 @@ function guardVisitor() {
|
|
|
1365
1458
|
const vertex = callVertexOf(id, this.run.state);
|
|
1366
1459
|
if (vertex !== undefined && !r_symbol_1.RSymbol.is(nodeOf(id, this.run.state)) && (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Return) || identifier_1.Identifier.getName(vertex.name) === 'return_from')) {
|
|
1367
1460
|
eachPath(nodeOf(id, this.run.state), this.run, path => returnsValue(undefined, path, this.run));
|
|
1461
|
+
this.run.order?.unsureExits.add(id);
|
|
1368
1462
|
}
|
|
1369
1463
|
}
|
|
1370
1464
|
visitDataflowNode(node) {
|
|
@@ -1380,7 +1474,7 @@ function guardVisitor() {
|
|
|
1380
1474
|
if (node !== undefined && paths?.length === 1 && paths[0].path.length === 0) {
|
|
1381
1475
|
const read = termOf(node, this.run.scope, this.run.state);
|
|
1382
1476
|
if (read?.kind === 'formal') {
|
|
1383
|
-
this.run.
|
|
1477
|
+
this.run.forced.add(read.name);
|
|
1384
1478
|
}
|
|
1385
1479
|
}
|
|
1386
1480
|
}
|
|
@@ -1515,12 +1609,9 @@ function withoutImplied(clauses, scope, facts) {
|
|
|
1515
1609
|
return clauses.filter(c => c.kind === 'explicit' || !(0, guard_claims_1.impliedBy)(c.requires, explicit, formals, facts));
|
|
1516
1610
|
}
|
|
1517
1611
|
/** The formals the condition asks to be there, as `!missing(x)` does, whether or not they come with a default. */
|
|
1518
|
-
function demandsPresenceOf(condition
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
}
|
|
1522
|
-
const [{ value: inner }] = condition.args;
|
|
1523
|
-
const asked = guard_term_1.GuardTerm.isCall(inner) && (condition.fn === '!' ? inner.fn === 'missing' : facts(guard_term_1.GuardTerm.bareName(inner.fn))?.check?.present) ? inner.args[0]?.value : undefined;
|
|
1612
|
+
function demandsPresenceOf(condition) {
|
|
1613
|
+
const inner = guard_term_1.GuardTerm.isCall(condition, '!') && condition.known ? condition.args[0].value : undefined;
|
|
1614
|
+
const asked = guard_term_1.GuardTerm.isCall(inner, 'missing') ? inner.args[0]?.value : undefined;
|
|
1524
1615
|
return asked?.kind === 'formal' ? [asked.name] : [];
|
|
1525
1616
|
}
|
|
1526
1617
|
/** What the given definition asks of its calls, for the calls `via` that run it if a dispatch within decides more for them, the innermost first. */
|
|
@@ -1537,7 +1628,8 @@ function contractOf(id, state, via = []) {
|
|
|
1537
1628
|
return known;
|
|
1538
1629
|
}
|
|
1539
1630
|
const scope = state.depth > MaxCalleeDepth ? undefined : scopeOf(id, state);
|
|
1540
|
-
|
|
1631
|
+
/* a default returning from the function, as `y = return(1)`, does so wherever the formal is first read */
|
|
1632
|
+
if (scope === undefined || mayReturnOnExit(scope.definition) || scope.definition.parameters.some(p => p.defaultValue !== undefined && hasSymbol(p.defaultValue, 'return'))) {
|
|
1541
1633
|
return NoContract;
|
|
1542
1634
|
}
|
|
1543
1635
|
/* a recursive call counts for nothing, which only ever leaves out what the recursion could have added */
|
|
@@ -1545,15 +1637,18 @@ function contractOf(id, state, via = []) {
|
|
|
1545
1637
|
state.depth++;
|
|
1546
1638
|
const tails = new Map();
|
|
1547
1639
|
markTails(scope.definition.body, state, tails);
|
|
1548
|
-
const run = { scope, state, clauses: new Map(),
|
|
1640
|
+
const run = { scope, state, clauses: new Map(), forced: new Set(), openers: frameOpeners(scope.definition, state), tails, returned: [], via: via.slice(0, reach), reach: 0, called: false, effects: false };
|
|
1549
1641
|
const order = run.order = orderOf(run);
|
|
1550
1642
|
new (guardVisitor())(run).walk();
|
|
1551
1643
|
tailReturns(run);
|
|
1552
1644
|
state.depth--;
|
|
1553
|
-
const demanded = new Set([...run.clauses.values()].flatMap(c => demandsPresenceOf(c.requires
|
|
1645
|
+
const demanded = new Set([...run.clauses.values()].flatMap(c => demandsPresenceOf(c.requires)));
|
|
1646
|
+
/* a default that only fails, as `x = stop("x is needed")`, is as good as none */
|
|
1647
|
+
const failsForced = ({ defaultValue }) => defaultValue === undefined || alwaysFails(defaultValue, state);
|
|
1554
1648
|
const contract = {
|
|
1555
1649
|
clauses: withoutImplied(guard_term_1.GuardTerm.resolved(withUnitsApplied([...run.clauses.values()], state.facts), c => c.requires, mergeClauses), scope, state.facts),
|
|
1556
|
-
required: scope.definition.parameters.filter(p => demanded.has(p.name.content) || (
|
|
1650
|
+
required: scope.definition.parameters.filter(p => demanded.has(p.name.content) || (run.forced.has(p.name.content) && failsForced(p))).map(p => p.name.content),
|
|
1651
|
+
forced: [...run.forced],
|
|
1557
1652
|
effects: order.effects.size > 0 || order.effectfulDefaults,
|
|
1558
1653
|
opens: order.openers.size > 0,
|
|
1559
1654
|
returned: run.returned,
|
|
@@ -79,8 +79,11 @@ declare function readsFree(this: void, term: GuardTerm): boolean;
|
|
|
79
79
|
export type GuardBinding = ReadonlyMap<BrandedIdentifier, GuardTerm>;
|
|
80
80
|
/** What a name from outside of the callee is to its caller, given where it was bound. */
|
|
81
81
|
export type GuardOuter = (origin: NodeId) => GuardTerm | undefined;
|
|
82
|
-
/**
|
|
83
|
-
|
|
82
|
+
/**
|
|
83
|
+
* The `term` of a callee as its caller sees it, `undefined` if it reads anything the caller cannot state.
|
|
84
|
+
* `absent` states what `missing` is of the formals where a call tells, without it a formal is missing with the formal it is bound to, as a dispatch hands it on.
|
|
85
|
+
*/
|
|
86
|
+
declare function substitute(this: void, term: GuardTerm, binding: GuardBinding, outer?: GuardOuter, absent?: GuardBinding): GuardTerm | undefined;
|
|
84
87
|
/** The constants of a literal vector like `c("a", "b")` or of a single constant, `undefined` for anything else. */
|
|
85
88
|
declare function constantsOf(this: void, term: GuardTerm | undefined): readonly GuardConstant[] | undefined;
|
|
86
89
|
/**
|
|
@@ -90,7 +93,7 @@ declare function constantsOf(this: void, term: GuardTerm | undefined): readonly
|
|
|
90
93
|
*/
|
|
91
94
|
declare function decided(this: void, term: GuardTerm, facts: GuardFactsLookup): GuardTerm;
|
|
92
95
|
/** {@link substitute} for a condition in negation normal form, where anything not statable can weaken into {@link True}, while the rest still holds. */
|
|
93
|
-
declare function substituteCondition(this: void, term: GuardTerm, binding: GuardBinding, outer?: GuardOuter, facts?: GuardFactsLookup): GuardTerm;
|
|
96
|
+
declare function substituteCondition(this: void, term: GuardTerm, binding: GuardBinding, outer?: GuardOuter, facts?: GuardFactsLookup, absent?: GuardBinding): GuardTerm;
|
|
94
97
|
/**
|
|
95
98
|
* Terms state what a guard asks for, see {@link GuardTerm}.
|
|
96
99
|
* @helper dataflow
|
|
@@ -257,8 +257,11 @@ function formalsOf(term, found = new Set()) {
|
|
|
257
257
|
function readsFree(term) {
|
|
258
258
|
return term.kind === 'free' || (isCall(term) && term.args.some(a => readsFree(a.value)));
|
|
259
259
|
}
|
|
260
|
-
/**
|
|
261
|
-
|
|
260
|
+
/**
|
|
261
|
+
* The `term` of a callee as its caller sees it, `undefined` if it reads anything the caller cannot state.
|
|
262
|
+
* `absent` states what `missing` is of the formals where a call tells, without it a formal is missing with the formal it is bound to, as a dispatch hands it on.
|
|
263
|
+
*/
|
|
264
|
+
function substitute(term, binding, outer, absent) {
|
|
262
265
|
switch (term.kind) {
|
|
263
266
|
case 'formal':
|
|
264
267
|
return binding.get(term.name);
|
|
@@ -273,12 +276,15 @@ function substitute(term, binding, outer) {
|
|
|
273
276
|
}
|
|
274
277
|
else if (term.fn === 'missing' && term.known) {
|
|
275
278
|
const [{ value: formal }] = term.args;
|
|
279
|
+
if (absent !== undefined) {
|
|
280
|
+
return formal.kind === 'formal' ? absent.get(formal.name) : undefined;
|
|
281
|
+
}
|
|
276
282
|
const bound = formal.kind === 'formal' ? binding.get(formal.name) : undefined;
|
|
277
283
|
return bound === undefined ? True : bound.kind === 'formal' ? { ...term, args: [{ value: bound }] } : False;
|
|
278
284
|
}
|
|
279
285
|
const args = [];
|
|
280
286
|
for (const arg of term.args) {
|
|
281
|
-
const value = substitute(arg.value, binding, outer);
|
|
287
|
+
const value = substitute(arg.value, binding, outer, absent);
|
|
282
288
|
if (value === undefined) {
|
|
283
289
|
return undefined;
|
|
284
290
|
}
|
|
@@ -470,12 +476,12 @@ function predicateDecided(term, facts) {
|
|
|
470
476
|
return predicate.exact || (predicate.plain && shape.type !== guard_facts_1.RValueType.Null) ? True : term;
|
|
471
477
|
}
|
|
472
478
|
/** {@link substitute} for a condition in negation normal form, where anything not statable can weaken into {@link True}, while the rest still holds. */
|
|
473
|
-
function substituteCondition(term, binding, outer, facts) {
|
|
479
|
+
function substituteCondition(term, binding, outer, facts, absent) {
|
|
474
480
|
if (isCall(term) && term.known && (term.fn === '&&' || term.fn === '||')) {
|
|
475
|
-
const operands = term.args.map(a => substituteCondition(a.value, binding, outer, facts));
|
|
481
|
+
const operands = term.args.map(a => substituteCondition(a.value, binding, outer, facts, absent));
|
|
476
482
|
return term.fn === '&&' ? all(...operands) : any(...operands);
|
|
477
483
|
}
|
|
478
|
-
const substituted = substitute(term, binding, outer) ?? True;
|
|
484
|
+
const substituted = substitute(term, binding, outer, absent) ?? True;
|
|
479
485
|
return facts === undefined ? substituted : decided(substituted, facts);
|
|
480
486
|
}
|
|
481
487
|
/** Whether the conjunction cannot hold as written: one of its parts is a disjunction of what its other parts rule out, `p && q && (!p || !q)`. */
|
|
@@ -153,6 +153,8 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
153
153
|
ingoingEdges(id: NodeId): ReadonlyIngoingEdges | undefined;
|
|
154
154
|
/** Whether `id` is quoted, i.e. affected by a {@link EdgeType.NonStandardEvaluation} edge that keeps it from being evaluated (a loop's own NSE-marked body still is evaluated, so that does not count). */
|
|
155
155
|
isQuoted(id: NodeId, withOutgoing?: boolean): boolean;
|
|
156
|
+
/** an nse edge quotes iff it does not originate from a loop marking its body */
|
|
157
|
+
private quotes;
|
|
156
158
|
/**
|
|
157
159
|
* The cached `pkg::fn` name of the call `id`, asking `resolve` only for a call the cache does not know yet.
|
|
158
160
|
* @useInstead {@link Dataflow.qualify} - which passes the resolution
|