@eagleoutice/flowr 2.17.8 → 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 +11 -1
- package/config.js +45 -8
- 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 +5 -3
- package/project/plugins/plugin-registry.js +7 -2
- 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
|
@@ -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
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -227,12 +227,16 @@ class DataflowGraph {
|
|
|
227
227
|
}
|
|
228
228
|
/** 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). */
|
|
229
229
|
isQuoted(id, withOutgoing = false) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
for (const [source, e] of this.edgesTo(id)) {
|
|
231
|
+
if (this.quotes(source, e)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
234
|
}
|
|
235
|
-
return withOutgoing && this.edgesFrom(id).values().some(e => quotes(id, e));
|
|
235
|
+
return withOutgoing && this.edgesFrom(id).values().some(e => this.quotes(id, e));
|
|
236
|
+
}
|
|
237
|
+
/** an nse edge quotes iff it does not originate from a loop marking its body */
|
|
238
|
+
quotes(source, e) {
|
|
239
|
+
return edge_1.DfEdge.includesType(e, edge_1.EdgeType.NonStandardEvaluation) && !model_1.RLoopConstructs.is(this._idMap?.get(source));
|
|
236
240
|
}
|
|
237
241
|
/**
|
|
238
242
|
* The cached `pkg::fn` name of the call `id`, asking `resolve` only for a call the cache does not know yet.
|
|
@@ -67,6 +67,12 @@ export declare function s3ClassOfMethod(fn: NodeId, prefixes: readonly BrandedId
|
|
|
67
67
|
export declare function linkedFunctionIds(ids: ReadonlySet<NodeId>, graph: DataflowGraph): NodeId[];
|
|
68
68
|
/** The methods `environment` binds for the generics a built-in dispatches to on its own (see `dispatches` of a built-in): every `<generic>.<class>` and every function `setMethod` registers for one, whatever the class, as it may be that of a part. */
|
|
69
69
|
export declare function internalGenericMethods(generics: readonly string[], environment: REnvironmentInformation, graph: DataflowGraph): IdentifierDefinition[];
|
|
70
|
+
/**
|
|
71
|
+
* {@link internalGenericMethods} per generic for the environments the calls of a program see. These differ in the few frames of the code but share
|
|
72
|
+
* the many attached packages below them, so what the packages bind for a generic is resolved once for all of them, and the frames are only walked
|
|
73
|
+
* where they bind the generic or a method of it.
|
|
74
|
+
*/
|
|
75
|
+
export declare function internalGenericMethodsPerEnvironment(graph: DataflowGraph): (environment: REnvironmentInformation) => (generic: string) => readonly IdentifierDefinition[];
|
|
70
76
|
/** Per target, the edges from `call` only its link to the method definitions `excluded` needs: the call and the returns of them, the reads of the definitions registering only them, and what only their bodies read on the call. */
|
|
71
77
|
export declare function methodOnlyEdges(graph: DataflowGraph, call: NodeId, excluded: ReadonlySet<NodeId>): Map<NodeId, EdgeType>;
|
|
72
78
|
/** Removes what linking `call` to the method definitions `excluded` added: the edges {@link methodOnlyEdges} names and the arguments bound to the parameters of the methods. */
|
|
@@ -7,6 +7,7 @@ exports.runsOnlyAfter = runsOnlyAfter;
|
|
|
7
7
|
exports.s3ClassOfMethod = s3ClassOfMethod;
|
|
8
8
|
exports.linkedFunctionIds = linkedFunctionIds;
|
|
9
9
|
exports.internalGenericMethods = internalGenericMethods;
|
|
10
|
+
exports.internalGenericMethodsPerEnvironment = internalGenericMethodsPerEnvironment;
|
|
10
11
|
exports.methodOnlyEdges = methodOnlyEdges;
|
|
11
12
|
exports.unlinkExcludedMethods = unlinkExcludedMethods;
|
|
12
13
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
@@ -26,6 +27,8 @@ const built_in_proc_name_1 = require("../environments/built-in-proc-name");
|
|
|
26
27
|
const function_semantics_1 = require("../fn/function-semantics");
|
|
27
28
|
const dispatch_1 = require("../fn/dispatch");
|
|
28
29
|
const linker_1 = require("./linker");
|
|
30
|
+
const group_generics_1 = require("../environments/group-generics");
|
|
31
|
+
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
29
32
|
const identifier_1 = require("../environments/identifier");
|
|
30
33
|
const resolve_helper_1 = require("../environments/resolve-helper");
|
|
31
34
|
/** how many contexts of calls a dispatch is decided for on its own, beyond that all of them share one decision */
|
|
@@ -276,6 +279,28 @@ function internalGenericMethods(generics, environment, graph) {
|
|
|
276
279
|
}) ?? []
|
|
277
280
|
]).filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId));
|
|
278
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* {@link internalGenericMethods} per generic for the environments the calls of a program see. These differ in the few frames of the code but share
|
|
284
|
+
* the many attached packages below them, so what the packages bind for a generic is resolved once for all of them, and the frames are only walked
|
|
285
|
+
* where they bind the generic or a method of it.
|
|
286
|
+
*/
|
|
287
|
+
function internalGenericMethodsPerEnvironment(graph) {
|
|
288
|
+
const inPackages = (0, defaultmap_1.memoize)((packages) => (0, defaultmap_1.memoize)((generic) => internalGenericMethods([generic], { current: packages, level: 0 }, graph)));
|
|
289
|
+
return (0, defaultmap_1.memoize)((environment) => {
|
|
290
|
+
const frames = [];
|
|
291
|
+
const withMethods = new Set();
|
|
292
|
+
let packages = environment.current;
|
|
293
|
+
for (; packages.t === undefined && !packages.builtInEnv; packages = packages.parent) {
|
|
294
|
+
frames.push(packages);
|
|
295
|
+
for (const name of packages.memory.keys()) {
|
|
296
|
+
(0, group_generics_1.addS3GenericsOfMethod)(name, withMethods);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const below = inPackages(packages);
|
|
300
|
+
const within = (0, defaultmap_1.memoize)((generic) => internalGenericMethods([generic], environment, graph));
|
|
301
|
+
return generic => withMethods.has(generic) || frames.some(f => f.memory.has(generic)) ? within(generic) : below(generic);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
279
304
|
/** the edges by which a call reaches a definition registering a method, by name or as what a generic hands on */
|
|
280
305
|
const RegistrationEdges = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Calls;
|
|
281
306
|
/** Per target, the edges from `call` only its link to the method definitions `excluded` needs: the call and the returns of them, the reads of the definitions registering only them, and what only their bodies read on the call. */
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { type DataflowInformation } from '../../../../../info';
|
|
1
|
+
import { type ControlDependency, type DataflowCfgInformation, type DataflowInformation, type ExitPoint, type KillReference } from '../../../../../info';
|
|
2
2
|
import { type DataflowProcessorInformation } from '../../../../../processor';
|
|
3
3
|
import { linkFunctionCalls } from '../../../../linker';
|
|
4
4
|
import { type REnvironmentInformation } from '../../../../../environments/environment';
|
|
5
5
|
import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
6
6
|
import { DataflowGraph } from '../../../../../graph/graph';
|
|
7
|
-
import { Identifier } from '../../../../../environments/identifier';
|
|
7
|
+
import { type BrandedIdentifier, Identifier, type IdentifierReference } from '../../../../../environments/identifier';
|
|
8
8
|
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
9
9
|
import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
10
10
|
import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
11
11
|
import type { ReadOnlyFlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
|
|
12
12
|
import { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
|
|
13
|
+
import { DefaultMap } from '../../../../../../util/collections/defaultmap';
|
|
13
14
|
import { type ClassFlowInfo } from '../../../../../fn/dispatch';
|
|
14
15
|
/** Printing a visible top-level value (or one `capture.output` captures) dispatches to the `print` methods in scope, so the expression calls them: those for the classes the value may have, and what their `NextMethod()` may run, every one if the classes are not known. */
|
|
15
16
|
export declare function printMethodsOf(id: NodeId, environment: REnvironmentInformation, graph: DataflowGraph, info: ClassFlowInfo): ReturnType<typeof linkFunctionCalls>;
|
|
@@ -21,5 +22,34 @@ export declare function noteUnknownMethods(environment: REnvironmentInformation,
|
|
|
21
22
|
export declare function bindsUnknownNames(graph: DataflowGraph, environment: REnvironmentInformation, id: NodeId, value?: RNode<ParentInformation>, ctx?: ReadOnlyFlowrAnalyzerContext, elements?: boolean): void;
|
|
22
23
|
/** Whether the value of `node` (or with `elements` each of its elements) surely is no function: a constant, a call of a built-in stated to return no function, or a symbol bound only to such values. */
|
|
23
24
|
export declare function cannotBeFunction(node: RNode<ParentInformation> | undefined, environment: REnvironmentInformation, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext | undefined, elements?: boolean, depth?: number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Everything {@link processExpressionList} carries from one top-level statement of a file to the next,
|
|
27
|
+
* so that an incremental analysis can continue the list after the first {@link ExpressionListState#count|count} statements.
|
|
28
|
+
*/
|
|
29
|
+
export interface ExpressionListState {
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly environment: REnvironmentInformation;
|
|
32
|
+
readonly listEnvironments: Set<NodeId>;
|
|
33
|
+
readonly remainingRead: DefaultMap<BrandedIdentifier | undefined, IdentifierReference[]>;
|
|
34
|
+
readonly graph: DataflowGraph;
|
|
35
|
+
readonly out: IdentifierReference[];
|
|
36
|
+
readonly killed: KillReference[] | undefined;
|
|
37
|
+
readonly exitPoints: ExitPoint[];
|
|
38
|
+
readonly invertExitCds: ControlDependency[];
|
|
39
|
+
readonly processed: (DataflowCfgInformation | undefined)[];
|
|
40
|
+
readonly defaultReturn: DataflowCfgInformation | undefined;
|
|
41
|
+
readonly initialState: Set<IdentifierReference> | undefined;
|
|
42
|
+
readonly hooks: DataflowInformation['hooks'];
|
|
43
|
+
readonly exited: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Where {@link processExpressionList} records and resumes the {@link ExpressionListState} of a file's top-level statements. */
|
|
46
|
+
export interface ExpressionListCheckpoints {
|
|
47
|
+
/** The state to continue the list of the file at `fileIndex` with, restoring what the state of `data` held at that point. */
|
|
48
|
+
resume<OtherInfo>(fileIndex: number, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): ExpressionListState | undefined;
|
|
49
|
+
/** Whether to record the state after `count` of the `total` statements. */
|
|
50
|
+
wants(count: number, total: number): boolean;
|
|
51
|
+
/** Records the state of the list of the file at `fileIndex`, which is updated in place afterward. */
|
|
52
|
+
record<OtherInfo>(fileIndex: number, state: ExpressionListState, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): void;
|
|
53
|
+
}
|
|
24
54
|
/** Processes a list of expressions joining their dataflow graphs accordingly. */
|
|
25
55
|
export declare function processExpressionList<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
@@ -568,29 +568,47 @@ function updateSideEffectsForCalledFunctions(calledEnvs, inputEnvironment, nextG
|
|
|
568
568
|
}
|
|
569
569
|
return inputEnvironment;
|
|
570
570
|
}
|
|
571
|
+
/** The statements following one that always exits are never analyzed, walks over the AST skip them. */
|
|
572
|
+
function markUnreachable(dead, data) {
|
|
573
|
+
for (const arg of dead) {
|
|
574
|
+
const id = r_argument_1.RArgument.unnamedValueOf(arg)?.info.id;
|
|
575
|
+
if (id !== undefined) {
|
|
576
|
+
data.unreachable?.add(id);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
571
580
|
/** Processes a list of expressions joining their dataflow graphs accordingly. */
|
|
572
581
|
function processExpressionList(name, args, rootId, data) {
|
|
573
|
-
|
|
582
|
+
const fileIndex = data.completeAst.ast.files.findIndex(f => f.root.info.id === rootId);
|
|
583
|
+
const fileRoot = fileIndex >= 0;
|
|
584
|
+
const checkpoints = fileRoot ? data.checkpoints : undefined;
|
|
585
|
+
/* an incremental analysis continues the list where an earlier one of the same statements left off */
|
|
586
|
+
const resumed = checkpoints?.resume(fileIndex, data);
|
|
587
|
+
let environment = resumed?.environment ?? data.environment;
|
|
574
588
|
const idMap = data.completeAst.idMap;
|
|
575
589
|
/* the writes of this list, to detect whether a read sees one of them */
|
|
576
|
-
const listEnvironments = new Set();
|
|
577
|
-
const remainingRead = new defaultmap_1.DefaultMap(() => []);
|
|
578
|
-
const nextGraph = new graph_1.DataflowGraph(idMap);
|
|
579
|
-
const out = [];
|
|
590
|
+
const listEnvironments = resumed?.listEnvironments ?? new Set();
|
|
591
|
+
const remainingRead = resumed?.remainingRead ?? new defaultmap_1.DefaultMap(() => []);
|
|
592
|
+
const nextGraph = resumed?.graph ?? new graph_1.DataflowGraph(idMap);
|
|
593
|
+
const out = resumed?.out ?? [];
|
|
580
594
|
/* lazily created - `rm` is rare, so rm-free lists never allocate this */
|
|
581
|
-
let killed;
|
|
582
|
-
const exitPoints = [];
|
|
595
|
+
let killed = resumed?.killed;
|
|
596
|
+
const exitPoints = resumed?.exitPoints ?? [];
|
|
583
597
|
/* what the list stands under as a whole, copied since the vertices share and extend that array */
|
|
584
598
|
const context = data.cds?.slice();
|
|
585
|
-
const invertExitCds = [];
|
|
586
|
-
const processedExpressions = [];
|
|
587
|
-
let defaultReturnExpr;
|
|
588
|
-
const fileRoot = data.completeAst.ast.files.some(f => f.root.info.id === rootId);
|
|
599
|
+
const invertExitCds = resumed?.invertExitCds ?? [];
|
|
600
|
+
const processedExpressions = resumed?.processed ?? [];
|
|
601
|
+
let defaultReturnExpr = resumed?.defaultReturn;
|
|
589
602
|
/* R prints what the top level of the analyzed script leaves visible, but not what a sourced file does */
|
|
590
603
|
const autoPrint = (0, built_in_ambient_state_1.autoPrintsStatementsOf)(rootId, data);
|
|
591
|
-
let initialState;
|
|
592
|
-
const hooks = [];
|
|
593
|
-
|
|
604
|
+
let initialState = resumed?.initialState;
|
|
605
|
+
const hooks = resumed?.hooks ?? [];
|
|
606
|
+
let exited = resumed?.exited ?? false;
|
|
607
|
+
if (exited) {
|
|
608
|
+
markUnreachable(args.slice(resumed?.count), data);
|
|
609
|
+
}
|
|
610
|
+
for (let index = resumed?.count ?? 0; !exited && index < args.length; index++) {
|
|
611
|
+
const arg = args[index];
|
|
594
612
|
const expression = r_argument_1.RArgument.unnamedValueOf(arg);
|
|
595
613
|
if (expression === undefined) {
|
|
596
614
|
processedExpressions.push(undefined);
|
|
@@ -677,13 +695,26 @@ function processExpressionList(name, args, rootId, data) {
|
|
|
677
695
|
if (control_flow_1.ControlFlow.alwaysExits(processed, context)) {
|
|
678
696
|
/* if there is an always-exit expression, there is no default return active anymore */
|
|
679
697
|
defaultReturnExpr = undefined;
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
698
|
+
markUnreachable(args.slice(index + 1), data);
|
|
699
|
+
exited = true;
|
|
700
|
+
}
|
|
701
|
+
if (checkpoints?.wants(index + 1, args.length)) {
|
|
702
|
+
checkpoints.record(fileIndex, {
|
|
703
|
+
count: index + 1,
|
|
704
|
+
environment,
|
|
705
|
+
listEnvironments,
|
|
706
|
+
remainingRead,
|
|
707
|
+
graph: nextGraph,
|
|
708
|
+
out,
|
|
709
|
+
killed,
|
|
710
|
+
exitPoints,
|
|
711
|
+
invertExitCds,
|
|
712
|
+
processed: processedExpressions,
|
|
713
|
+
defaultReturn: defaultReturnExpr,
|
|
714
|
+
initialState,
|
|
715
|
+
hooks,
|
|
716
|
+
exited
|
|
717
|
+
}, data);
|
|
687
718
|
}
|
|
688
719
|
}
|
|
689
720
|
if (defaultReturnExpr) {
|
|
@@ -427,12 +427,6 @@ function* superAssignedTargets(graph, nodes) {
|
|
|
427
427
|
function namesShadowingBuiltIns(environment, graph) {
|
|
428
428
|
const shadowing = new Set();
|
|
429
429
|
const generics = new Set();
|
|
430
|
-
/* `as.character.zz` may be a method of `as` or of `as.character`, so every prefix is a candidate */
|
|
431
|
-
function methodOf(name) {
|
|
432
|
-
for (let dot = name.indexOf('.', 1); dot > 0; dot = name.indexOf('.', dot + 1)) {
|
|
433
|
-
generics.add(name.slice(0, dot));
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
430
|
for (const env of environment_1.REnvironment.frames(environment.current)) {
|
|
437
431
|
/* an attached package may shadow a built-in a function body bound to before it was attached; its keys suffice, building the definitions of every export would be costly */
|
|
438
432
|
if (env.t === environment_1.EnvType.Namespace) {
|
|
@@ -444,7 +438,7 @@ function namesShadowingBuiltIns(environment, graph) {
|
|
|
444
438
|
for (const [identifier, definitions] of env.memory) {
|
|
445
439
|
if (!definitions.every(d => node_id_1.NodeId.isBuiltIn(d.nodeId))) {
|
|
446
440
|
shadowing.add(identifier_1.Identifier.getName(identifier));
|
|
447
|
-
|
|
441
|
+
(0, group_generics_1.addS3GenericsOfMethod)(identifier_1.Identifier.getName(identifier), generics);
|
|
448
442
|
}
|
|
449
443
|
}
|
|
450
444
|
}
|
|
@@ -452,7 +446,7 @@ function namesShadowingBuiltIns(environment, graph) {
|
|
|
452
446
|
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
453
447
|
const name = graph.isRoot(id) ? undefined : node_id_1.NodeId.recoverBareName(id, graph.idMap);
|
|
454
448
|
if (name !== undefined) {
|
|
455
|
-
|
|
449
|
+
(0, group_generics_1.addS3GenericsOfMethod)(name, generics);
|
|
456
450
|
}
|
|
457
451
|
}
|
|
458
452
|
return { shadowing, generics };
|
|
@@ -646,6 +640,8 @@ function nextMethodsPerCall(next, owner, dispatch, contexts, collected, graph) {
|
|
|
646
640
|
const RunsPlainCode = new Set([built_in_proc_name_1.BuiltInProcName.Default, built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs, built_in_proc_name_1.BuiltInProcName.Apply]);
|
|
647
641
|
/** The internal generics and the S3 groups, which R code may dispatch to on whatever it is handed, without naming them as a call the signature database records (`x[i]`). */
|
|
648
642
|
const DispatchedInternally = [...default_builtin_config_1.InternalGenerics, ...group_generics_1.S3Groups];
|
|
643
|
+
/** every generic {@link genericsRunWithin} may name for a built-in the configuration states nothing for */
|
|
644
|
+
const RunWithinUnstated = new Set([...default_builtin_config_1.RGenerics, ...group_generics_1.S3Groups]);
|
|
649
645
|
/** Whether the `call` may hand on an object a method may get: a constant (`structure(1, class = "a")`) has no class. */
|
|
650
646
|
function handsObjects(call, idMap) {
|
|
651
647
|
return call.args.some(a => a !== r_function_call_1.EmptyArgument && !model_1.RConstant.is(r_argument_1.RArgument.valueOf(idMap?.get(a.nodeId))));
|
|
@@ -655,16 +651,20 @@ function handsObjects(call, idMap) {
|
|
|
655
651
|
* (`nrow(x)` asks `dim(x)`), else for a function of R code (`median`, `head`) every internal one as well as those its code
|
|
656
652
|
* calls (as the signature database knows), also through the default method of a generic it calls.
|
|
657
653
|
*/
|
|
658
|
-
function genericsRunWithin(name, ctx) {
|
|
654
|
+
function genericsRunWithin(name, ctx, callees) {
|
|
659
655
|
const builtIn = ctx.env.builtInFunctionOf(name);
|
|
660
656
|
const stated = builtIn?.config?.dispatches;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (stated !== undefined || (builtIn !== undefined && !RunsPlainCode.has(builtIn.processorName)) || r_primitives_generated_1.RPrimitives.has(String(identifier_1.Identifier.getName(name))) || (called === undefined && builtIn === undefined)) {
|
|
657
|
+
/* what the configuration states it dispatches to is all, a processor of its own models what the call does (`setMethod`), and a primitive runs no R code */
|
|
658
|
+
if (stated !== undefined || (builtIn !== undefined && !RunsPlainCode.has(builtIn.processorName)) || r_primitives_generated_1.RPrimitives.has(String(identifier_1.Identifier.getName(name)))) {
|
|
664
659
|
return stated ?? [];
|
|
665
660
|
}
|
|
661
|
+
const called = callees(name)?.filter(c => default_builtin_config_1.RGenerics.has(c));
|
|
662
|
+
/* a name flowR knows nothing of is no built-in */
|
|
663
|
+
if (called === undefined && builtIn === undefined) {
|
|
664
|
+
return [];
|
|
665
|
+
}
|
|
666
666
|
const generic = default_builtin_config_1.RGenerics.has(identifier_1.Identifier.getName(name)) ? [identifier_1.Identifier.getName(name)] : [];
|
|
667
|
-
const viaDefaults = [...generic, ...called ?? []].flatMap(g =>
|
|
667
|
+
const viaDefaults = [...generic, ...called ?? []].flatMap(g => callees(identifier_1.Identifier.make(`${g}.default`))?.filter(c => default_builtin_config_1.RGenerics.has(c)) ?? []);
|
|
668
668
|
return (0, arrays_1.uniqueArray)([...DispatchedInternally, ...called ?? [], ...viaDefaults].map(String));
|
|
669
669
|
}
|
|
670
670
|
/** What the R code of the package function `name` calls, `undefined` if the signature database knows no code for it. */
|
|
@@ -690,14 +690,23 @@ function linkNestedFunctionCalls(graph, outEnvironment, ctx) {
|
|
|
690
690
|
const handingOnDots = [];
|
|
691
691
|
const enclosingOf = (0, defaultmap_1.memoize)((id) => graph.idMap === undefined ? undefined : model_1.RNode.strictlyEnclosingFunction(id, graph.idMap));
|
|
692
692
|
const runsOnceAt = (0, defaultmap_1.memoize)((id) => program_order_1.ProgramOrder.runsOnceAt(id, graph));
|
|
693
|
-
const databaseInfoOf =
|
|
693
|
+
const databaseInfoOf = identifier_1.Identifier.memoize(name => ctx.functionInfo(name));
|
|
694
694
|
/* the generics a built-in dispatches to on its own whose methods the code binds */
|
|
695
|
-
const
|
|
696
|
-
const
|
|
695
|
+
const callees = identifier_1.Identifier.memoize(name => calleesOf(name, ctx));
|
|
696
|
+
const runWithin = identifier_1.Identifier.memoize(name => genericsRunWithin(name, ctx, callees));
|
|
697
|
+
const bound = (g) => generics.has(g) || shadowing.has(g);
|
|
698
|
+
/* unless the code binds one of the generics a built-in runs on its own, only what the configuration states is left to ask, which spares the signature database */
|
|
699
|
+
const bindsRunWithin = RunWithinUnstated.values().some(bound);
|
|
700
|
+
const internalOf = identifier_1.Identifier.memoize(name => (bindsRunWithin ? runWithin(name) : ctx.env.builtInFunctionOf(name)?.config?.dispatches ?? []).filter(bound));
|
|
697
701
|
const environmentAt = (0, defaultmap_1.memoize)((id) => {
|
|
698
702
|
const environment = graph.getVertex(id).environment;
|
|
699
703
|
return environment ? environment_1.REnvironment.overwrite(outEnvironment, environment) : outEnvironment;
|
|
700
704
|
});
|
|
705
|
+
const frameEnvironmentOf = (0, defaultmap_1.memoize)((fn) => {
|
|
706
|
+
const frame = graph.getVertex(fn);
|
|
707
|
+
return vertex_1.DfgVertex.isFunctionDefinition(frame) ? environment_1.REnvironment.overwrite(outEnvironment, frame.subflow.environment) : undefined;
|
|
708
|
+
});
|
|
709
|
+
const methodsIn = (0, dispatch_linking_1.internalGenericMethodsPerEnvironment)(graph);
|
|
701
710
|
const narrower = new dispatch_linking_1.DispatchNarrower(graph, ctx);
|
|
702
711
|
/* the bindings of names we cannot tell that run, i.e. those at the top or in a function the code calls */
|
|
703
712
|
const unknownMethodsAt = (environment_1.REnvironment.findBuiltIn(outEnvironment.current).unknownMethodsAt ?? []).filter(at => {
|
|
@@ -804,8 +813,8 @@ function linkNestedFunctionCalls(graph, outEnvironment, ctx) {
|
|
|
804
813
|
let s3Objects = object === undefined ? undefined : [object];
|
|
805
814
|
/* a built-in keeps no environment, but the frame of the function it is in may bind methods */
|
|
806
815
|
function methodEnvironment() {
|
|
807
|
-
const
|
|
808
|
-
return
|
|
816
|
+
const fn = vertex.environment === undefined ? enclosingOf(id) : undefined;
|
|
817
|
+
return (fn === undefined ? undefined : frameEnvironmentOf(fn)) ?? effectiveEnvironment;
|
|
809
818
|
}
|
|
810
819
|
if (mayDispatch && !treatAsS3 && dispatchesOnClass(name, effectiveEnvironment, databaseInfoOf)) {
|
|
811
820
|
const own = linkOwnS3Methods(vertex, name, graph, methodEnvironment(), runsOnceAt(id), ctx, databaseInfoOf);
|
|
@@ -813,7 +822,7 @@ function linkNestedFunctionCalls(graph, outEnvironment, ctx) {
|
|
|
813
822
|
s3Objects = own.objects;
|
|
814
823
|
treatAsS3 = true;
|
|
815
824
|
}
|
|
816
|
-
for (const method of internal.length === 0 ? [] :
|
|
825
|
+
for (const method of internal.length === 0 ? [] : internal.flatMap(methodsIn(methodEnvironment())).filter(m => !definedLater(m.nodeId))) {
|
|
817
826
|
graph.addEdge(id, method.nodeId, edge_1.EdgeType.Reads);
|
|
818
827
|
for (const target of (0, dispatch_linking_1.linkedFunctionIds)(new Set([method.nodeId]), graph)) {
|
|
819
828
|
targets.add(target);
|
|
@@ -7,6 +7,7 @@ const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
|
7
7
|
const info_1 = require("../../../../../info");
|
|
8
8
|
const known_call_handling_1 = require("../known-call-handling");
|
|
9
9
|
const nse_kind_1 = require("../nse-kind");
|
|
10
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
10
11
|
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
11
12
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
12
13
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
@@ -18,6 +19,7 @@ const edge_1 = require("../../../../../graph/edge");
|
|
|
18
19
|
const control_flow_1 = require("../../../../control-flow");
|
|
19
20
|
const linker_1 = require("../../../../linker");
|
|
20
21
|
const environment_1 = require("../../../../../environments/environment");
|
|
22
|
+
const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
|
|
21
23
|
/** Fallback formal parameter names for `with(data, expr, ...)` / `within(data, expr, ...)` when the signature database has no `base::with`. */
|
|
22
24
|
const withParamsFallback = ['data', 'expr'];
|
|
23
25
|
/** Normal call analysis, marking the data-masked arguments (columns of the data) as NSE; `expr` runs in a frame of its own built from the data. */
|
|
@@ -58,6 +60,10 @@ function processWithEnv(name, args, rootId, data) {
|
|
|
58
60
|
if (dataArg?.value === undefined || exprArg?.value === undefined) {
|
|
59
61
|
return markAsMaskedFallback(name, args, rootId, data);
|
|
60
62
|
}
|
|
63
|
+
const literal = literalListElements(dataArg.value, data);
|
|
64
|
+
if (literal !== undefined && !(0, common_1.isPipedArgument)(dataArg, rootId, data)) {
|
|
65
|
+
return processWithLiteralList(name, rootId, data, dataArg.value, exprArg.value, literal);
|
|
66
|
+
}
|
|
61
67
|
const envirRouting = (0, built_in_envir_utils_1.resolveArgToEnvirOrAmbiguous)(dataArg, data);
|
|
62
68
|
const envirResolution = (0, built_in_envir_utils_1.envirOf)(envirRouting);
|
|
63
69
|
if (!envirResolution) {
|
|
@@ -113,6 +119,75 @@ function processWithEnv(name, args, rootId, data) {
|
|
|
113
119
|
};
|
|
114
120
|
return callsOpaque(dfExpr.graph, rootId) ? mayWriteInto(dataArg.value, result, rootId, data) : result;
|
|
115
121
|
}
|
|
122
|
+
/** The named elements of a `list(a = ..., b = ...)` written as the data, `undefined` if the data is no such call or the names it binds are unknown (a `...`). */
|
|
123
|
+
function literalListElements(dataNode, data) {
|
|
124
|
+
if (!r_function_call_1.RFunctionCall.isNamed(dataNode, 'list') || !resolve_helper_1.Resolve.isBuiltIn(dataNode.functionName.content, data.environment, identifier_1.ReferenceType.Function)) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const elements = [];
|
|
128
|
+
for (const arg of dataNode.arguments) {
|
|
129
|
+
if (r_argument_1.RArgument.isEmpty(arg) || arg.value === undefined) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
else if (arg.name === undefined) {
|
|
133
|
+
if (r_symbol_1.RSymbol.is(arg.value) && arg.value.content === identifier_1.Identifier.dotdotdot()) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
elements.push([identifier_1.Identifier.getName(arg.name.content), arg.value]);
|
|
139
|
+
}
|
|
140
|
+
return elements;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* `with(list(f = system, x = readline()), f(x))` evaluates `expr` in a frame holding the named elements of the
|
|
144
|
+
* list, whose parent is the calling environment: `f` is `system` there and `x` the value of `readline()`.
|
|
145
|
+
* Neither `with` nor `within` changes a variable of the caller.
|
|
146
|
+
*/
|
|
147
|
+
function processWithLiteralList(name, rootId, data, dataNode, expr, elements) {
|
|
148
|
+
const dfDataArg = (0, processor_1.processDataflowFor)(dataNode, data);
|
|
149
|
+
let frame = environment_1.REnvironment.pushLocal(data.environment);
|
|
150
|
+
for (const [element, value] of elements) {
|
|
151
|
+
const vertex = dfDataArg.graph.getVertex(value.info.id);
|
|
152
|
+
frame = environment_1.REnvironment.define({
|
|
153
|
+
nodeId: value.info.id,
|
|
154
|
+
name: element,
|
|
155
|
+
type: vertex_1.DfgVertex.isFunctionDefinition(vertex) ? identifier_1.ReferenceType.Function : vertex_1.DfgVertex.isValue(vertex) ? identifier_1.ReferenceType.Variable : identifier_1.ReferenceType.Unknown,
|
|
156
|
+
definedAt: value.info.id,
|
|
157
|
+
cds: data.cds,
|
|
158
|
+
/* like `f <- system`, the element holds what its value aliases */
|
|
159
|
+
value: (0, alias_tracking_1.getAliases)([value.info.id], dfDataArg.graph, data.environment)
|
|
160
|
+
}, false, frame);
|
|
161
|
+
}
|
|
162
|
+
const dfExpr = (0, processor_1.processDataflowFor)(expr, { ...data, environment: frame });
|
|
163
|
+
const remainingFromExpr = [];
|
|
164
|
+
(0, linker_1.linkInputs)(dfExpr.unknownReferences, frame, remainingFromExpr, dfExpr.graph, false);
|
|
165
|
+
(0, common_1.patchFunctionCall)({
|
|
166
|
+
nextGraph: dfDataArg.graph,
|
|
167
|
+
rootId,
|
|
168
|
+
name,
|
|
169
|
+
data,
|
|
170
|
+
argumentProcessResult: [dfDataArg, dfExpr],
|
|
171
|
+
origin: built_in_proc_name_1.BuiltInProcName.With
|
|
172
|
+
});
|
|
173
|
+
const merged = dfDataArg.graph.mergeWith(dfExpr.graph);
|
|
174
|
+
const cfgEntry = control_flow_1.ControlFlow.inSequence(merged, [dfDataArg, dfExpr], rootId);
|
|
175
|
+
/* the expression only runs because the call evaluates it, and the frame of the data is gone afterwards */
|
|
176
|
+
keepCallFor(dfExpr.out, merged, rootId);
|
|
177
|
+
return {
|
|
178
|
+
hooks: dfDataArg.hooks.concat(dfExpr.hooks),
|
|
179
|
+
/* only what `<<-` writes beyond the frame stays */
|
|
180
|
+
environment: environment_1.REnvironment.popLocal(dfExpr.environment),
|
|
181
|
+
exitPoints: dfDataArg.exitPoints.concat(dfExpr.exitPoints),
|
|
182
|
+
graph: merged,
|
|
183
|
+
entryPoint: rootId,
|
|
184
|
+
cfgEntry,
|
|
185
|
+
cfgExit: rootId,
|
|
186
|
+
in: dfDataArg.in.concat(dfExpr.in, dfDataArg.unknownReferences, remainingFromExpr, [{ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function }]),
|
|
187
|
+
out: [],
|
|
188
|
+
unknownReferences: []
|
|
189
|
+
};
|
|
190
|
+
}
|
|
116
191
|
/** whether `graph` holds a call other than `rootId` that may run a closure of the data, like `with(e, inc())` */
|
|
117
192
|
function callsOpaque(graph, rootId) {
|
|
118
193
|
return graph.verticesOfType(vertex_1.VertexType.FunctionCall).some(([id, vertex]) => id !== rootId && !vertex.onlyBuiltin);
|
|
@@ -90,6 +90,8 @@ function linkPromisesToWritesOfCall(graph, ctx) {
|
|
|
90
90
|
let forcing;
|
|
91
91
|
let order;
|
|
92
92
|
let functions;
|
|
93
|
+
/* a script calls the same few package functions over and over, and decoding a signature costs */
|
|
94
|
+
const signatureOf = identifier_1.Identifier.memoize(name => packageSignatureOf(name, ctx));
|
|
93
95
|
/* the global state a closure changes while it runs, which a promise it forces may see */
|
|
94
96
|
function changedBy(fns) {
|
|
95
97
|
functions ??= ambientAccessOfFunctions(graph);
|
|
@@ -98,7 +100,7 @@ function linkPromisesToWritesOfCall(graph, ctx) {
|
|
|
98
100
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
99
101
|
/* a function of a package flowR has no body for forces its arguments as its signature states, see `keptPromisesOfPackageCall` */
|
|
100
102
|
const kept = df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)))
|
|
101
|
-
? undefined : keptPromisesOfPackageCall(graph, vertex,
|
|
103
|
+
? undefined : keptPromisesOfPackageCall(graph, vertex, signatureOf);
|
|
102
104
|
if (kept === false) {
|
|
103
105
|
continue;
|
|
104
106
|
}
|
|
@@ -507,17 +509,29 @@ class PromiseOrder {
|
|
|
507
509
|
}
|
|
508
510
|
}
|
|
509
511
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
|
|
512
|
+
function packageSignatureOf(name, ctx) {
|
|
513
|
+
/* the package alone rules out most names, which spares decoding the signature and everything it calls */
|
|
514
|
+
const named = (0, query_fn_props_1.packageOfFunction)(name, ctx);
|
|
515
|
+
if (named === undefined || (0, r_base_packages_1.isBaseRPackage)(named)) {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
const info = (0, query_fn_props_1.fnSignature)(name, ctx);
|
|
519
|
+
const pkg = info?.package ?? identifier_1.Identifier.getNamespace(name);
|
|
514
520
|
if (pkg === undefined || (0, r_base_packages_1.isBaseRPackage)(pkg)) {
|
|
515
521
|
return false;
|
|
516
522
|
}
|
|
523
|
+
return { sig: info?.sig };
|
|
524
|
+
}
|
|
525
|
+
/** For a call of a package function flowR has no body for, see {@link PackageSignature}: `false` if it is none, else the arguments whose promises may be forced after the call returned. */
|
|
526
|
+
function keptPromisesOfPackageCall(graph, call, signatureOf) {
|
|
527
|
+
const signature = call.name === undefined ? false : signatureOf(call.name);
|
|
528
|
+
if (signature === false) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
517
531
|
if (!handsBackCalledValue(graph, call.id)) {
|
|
518
532
|
return new Set();
|
|
519
533
|
}
|
|
520
|
-
const layout =
|
|
534
|
+
const layout = signature.sig === undefined ? undefined : built_in_props_1.FnSig.layout(signature.sig);
|
|
521
535
|
const args = call.args.filter(graph_1.FunctionArgument.isNotEmpty);
|
|
522
536
|
const slots = layout === undefined ? undefined : built_in_props_1.FnSig.slots(layout, args.map(graph_1.FunctionArgument.getName));
|
|
523
537
|
return new Set(args.filter((_, i) => {
|
package/dataflow/processor.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { RArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-argument'
|
|
|
7
7
|
import type { KnownParserType, Parser } from '../r-bridge/parser';
|
|
8
8
|
import type { FlowrAnalyzerContext } from '../project/context/flowr-analyzer-context';
|
|
9
9
|
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
10
|
+
import type { ExpressionListCheckpoints } from './internal/process/functions/call/built-in/built-in-expression-list';
|
|
10
11
|
export interface DataflowProcessorInformation<OtherInfo> {
|
|
11
12
|
readonly parser: Parser<KnownParserType>;
|
|
12
13
|
/** Initial and frozen ast-information */
|
|
@@ -60,6 +61,8 @@ export interface DataflowProcessorInformation<OtherInfo> {
|
|
|
60
61
|
readonly statementOrder?: Map<NodeId, [start: number, end: number]>;
|
|
61
62
|
/** The statements left unanalyzed as they follow one that always exits, so walks over the AST can skip what never runs */
|
|
62
63
|
readonly unreachable?: Set<NodeId>;
|
|
64
|
+
/** Records and resumes the top-level statements of the files for an incremental analysis, see {@link ExpressionListCheckpoints} */
|
|
65
|
+
readonly checkpoints?: ExpressionListCheckpoints;
|
|
63
66
|
}
|
|
64
67
|
export type DataflowProcessor<OtherInfo, NodeType extends RNodeWithParent<OtherInfo>> = (node: NodeType, data: DataflowProcessorInformation<OtherInfo>) => DataflowInformation;
|
|
65
68
|
type NodeWithKey<OtherInfo, Key> = RNode<OtherInfo & ParentInformation> & {
|
|
@@ -86,6 +86,10 @@ ${(0, doc_code_1.codeBlock)('shell', 'npm run test:verbose')}
|
|
|
86
86
|
Alternatively, set the \`FLOWR_VERBOSE\` environment variable directly:
|
|
87
87
|
${(0, doc_code_1.codeBlock)('shell', 'FLOWR_VERBOSE=true npm run test')}
|
|
88
88
|
Both forms accept the usual vitest filters (e.g. \`npm run test:verbose -- cli/server\`).
|
|
89
|
+
`)
|
|
90
|
+
.addFaq('What to do if the *linter fails*?', `
|
|
91
|
+
Read the description of the failing rule and fix what it points at, \`npm run lint-local -- --fix\` fixes the formatting.
|
|
92
|
+
See the ${ctx.linkPage('wiki/Linting and Testing', 'linting wiki section', 'oh-no-the-linter-fails')} for the rule sets, and open an issue if you think the linter is wrong.
|
|
89
93
|
`)
|
|
90
94
|
.addFaq('How to add a *linting rule*?', `
|
|
91
95
|
To add a new linting rule, see ${ctx.linkPage('wiki/Create Linting Rules')}.
|