@eagleoutice/flowr 2.15.9 → 2.15.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/README.md +34 -25
- package/abstract-interpretation/absint-inference.d.ts +2 -2
- package/abstract-interpretation/absint-inference.js +32 -79
- package/benchmark/slicer.d.ts +0 -1
- package/benchmark/slicer.js +1 -2
- package/cli/repl/commands/repl-signature.js +12 -3
- package/config.d.ts +5 -1
- package/control-flow/cfg-properties.js +0 -22
- package/control-flow/happens-before.d.ts +2 -2
- package/control-flow/happens-before.js +29 -19
- package/dataflow/environments/apply-kill.js +6 -2
- package/dataflow/environments/built-in-config.d.ts +2 -0
- package/dataflow/environments/built-in-props.d.ts +7 -1
- package/dataflow/environments/built-in-props.js +8 -1
- package/dataflow/environments/built-in.d.ts +7 -2
- package/dataflow/environments/built-in.js +11 -5
- package/dataflow/environments/default-builtin-config.d.ts +386 -8
- package/dataflow/environments/default-builtin-config.js +84 -22
- package/dataflow/environments/define.d.ts +3 -2
- package/dataflow/environments/define.js +4 -3
- package/dataflow/environments/deprecation-info.d.ts +45 -0
- package/dataflow/environments/deprecation-info.js +13 -0
- package/dataflow/environments/environment.d.ts +1 -1
- package/dataflow/environments/environment.js +5 -4
- package/dataflow/environments/identifier.d.ts +2 -0
- package/dataflow/extractor.js +6 -1
- package/dataflow/fn/class-declaration.d.ts +0 -11
- package/dataflow/fn/class-declaration.js +0 -20
- package/dataflow/fn/higher-order-function.d.ts +9 -1
- package/dataflow/fn/higher-order-function.js +14 -7
- package/dataflow/fn/strict-function.js +8 -3
- package/dataflow/graph/graph.d.ts +7 -0
- package/dataflow/graph/graph.js +17 -0
- package/dataflow/graph/vertex.d.ts +1 -1
- package/dataflow/internal/linker.d.ts +3 -0
- package/dataflow/internal/linker.js +67 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +113 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +506 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +22 -19
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +4 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +19 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +3 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -0
- package/dataflow/internal/process/functions/call/common.d.ts +3 -1
- package/dataflow/internal/process/functions/call/common.js +22 -4
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -0
- package/dataflow/internal/process/functions/call/deferred.js +33 -12
- package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +15 -0
- package/dataflow/internal/process/functions/call/quoted.js +137 -24
- package/dataflow/internal/process/process-symbol.js +6 -2
- package/documentation/data/faq/faqs.js +3 -3
- package/documentation/data/interface/doc-writing-code.js +1 -2
- package/documentation/data/server/doc-data-server-messages.js +7 -7
- package/documentation/doc-capabilities.js +80 -34
- package/documentation/doc-util/doc-query.d.ts +0 -3
- package/documentation/doc-util/doc-query.js +4 -3
- package/documentation/wiki-analyzer.js +1 -1
- package/documentation/wiki-cfg.js +5 -6
- package/documentation/wiki-core.js +8 -8
- package/documentation/wiki-dataflow-graph.js +10 -11
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linting-and-testing.js +3 -3
- package/documentation/wiki-overview.js +6 -6
- package/documentation/wiki-query.js +9 -101
- package/documentation/wiki-signature-database.js +1 -1
- package/linter/linter-rules.d.ts +1 -1
- package/linter/rules/deprecated-functions.d.ts +1 -45
- package/linter/rules/deprecated-functions.js +24 -33
- package/package.json +1 -1
- package/project/flowr-analyzer.d.ts +2 -0
- package/project/flowr-analyzer.js +24 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
- package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +6 -4
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/build.js +4 -0
- package/project/sigdb/manifest.d.ts +2 -0
- package/project/sigdb/manifest.js +10 -1
- package/project/sigdb/reader.js +23 -61
- package/project/sigdb/sigdb-download.d.ts +29 -6
- package/project/sigdb/sigdb-download.js +212 -64
- package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
- package/queries/catalog/call-context-query/cascade-action.js +2 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
- package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
- package/queries/catalog/origin-query/origin-query-executor.js +2 -2
- package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
- package/queries/catalog/origin-query/origin-query-format.js +1 -1
- package/queries/query.d.ts +1 -1
- package/r-bridge/data/data.d.ts +21 -14
- package/r-bridge/data/data.js +28 -20
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
- package/util/files.d.ts +2 -0
- package/util/files.js +3 -1
- package/util/mermaid/mermaid.js +6 -2
- package/util/version.js +2 -2
|
@@ -5,13 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.argForImpl = argForImpl;
|
|
8
|
-
exports.argFor = argFor;
|
|
9
8
|
exports.classDeclarationOfImpl = classDeclarationOfImpl;
|
|
10
9
|
exports.declaredClassesImpl = declaredClassesImpl;
|
|
11
|
-
exports.declaredClasses = declaredClasses;
|
|
12
10
|
exports.superClassesOfImpl = superClassesOfImpl;
|
|
13
11
|
exports.toSigClassesImpl = toSigClassesImpl;
|
|
14
|
-
exports.toSigClasses = toSigClasses;
|
|
15
12
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
16
13
|
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
17
14
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
@@ -48,15 +45,6 @@ function argForImpl(args, ref) {
|
|
|
48
45
|
}
|
|
49
46
|
return undefined;
|
|
50
47
|
}
|
|
51
|
-
/**
|
|
52
|
-
* The argument `ref` names, by name when the call gives one and by position among the unnamed ones otherwise.
|
|
53
|
-
* Exported so `built-in-s-four.ts` can drop its own copy of this instead of hand-rolling it again; that file
|
|
54
|
-
* already imports {@link ClassArgRef} from here, so the reverse import would cycle.
|
|
55
|
-
* @deprecated use {@link argForImpl} instead
|
|
56
|
-
*/
|
|
57
|
-
function argFor(args, ref) {
|
|
58
|
-
return argForImpl(args, ref);
|
|
59
|
-
}
|
|
60
48
|
/** The string a node states literally, `undefined` for anything that is not a literal (a variable, a call, ...). */
|
|
61
49
|
function literal(node) {
|
|
62
50
|
return node !== undefined && r_string_1.RString.is(node) ? node.content.str : undefined;
|
|
@@ -209,10 +197,6 @@ function declaredClassesImpl(graph) {
|
|
|
209
197
|
}
|
|
210
198
|
return classes;
|
|
211
199
|
}
|
|
212
|
-
/** @deprecated use {@link declaredClassesImpl} instead */
|
|
213
|
-
function declaredClasses(graph) {
|
|
214
|
-
return declaredClassesImpl(graph);
|
|
215
|
-
}
|
|
216
200
|
/** Variable name to the class its generator declares, for the `Cls <- R6Class(...)`/`Cls <- new_class(...)` bindings. */
|
|
217
201
|
function generatorVariables(graph, classes) {
|
|
218
202
|
const byName = new Map();
|
|
@@ -285,8 +269,4 @@ function toSigClassesImpl(classes, ownerOf) {
|
|
|
285
269
|
}
|
|
286
270
|
return records;
|
|
287
271
|
}
|
|
288
|
-
/** @deprecated use {@link toSigClassesImpl} instead */
|
|
289
|
-
function toSigClasses(classes, ownerOf) {
|
|
290
|
-
return toSigClassesImpl(classes, ownerOf);
|
|
291
|
-
}
|
|
292
272
|
//# sourceMappingURL=class-declaration.js.map
|
|
@@ -6,16 +6,24 @@
|
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
7
|
import type { DataflowGraph } from '../graph/graph';
|
|
8
8
|
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
9
|
+
/** What an argument is, which no definition it is looked at for changes. */
|
|
10
|
+
export interface ArgumentFacts {
|
|
11
|
+
readonly behind: ReadonlySet<NodeId>;
|
|
12
|
+
/** whether it hands over a function, only worked out once something asks */
|
|
13
|
+
carriesFunction?: boolean;
|
|
14
|
+
}
|
|
9
15
|
/** What to ask for beyond the definition itself, see {@link isHigherOrder}. */
|
|
10
16
|
export interface HigherOrderFunctionsOptions {
|
|
11
17
|
/** how to ask what a built-in states, and to resolve the value an argument carries */
|
|
12
18
|
readonly ctx: ReadOnlyFlowrAnalyzerContext;
|
|
13
19
|
/** the graph with edges reversed, to speed up repeat queries over the same call sites */
|
|
14
20
|
readonly invertedGraph?: DataflowGraph;
|
|
21
|
+
/** what is known about the arguments, to share between the definitions asked about in one go; a call site reaching several of them resolves its arguments once */
|
|
22
|
+
readonly argumentFacts?: Map<NodeId, ArgumentFacts>;
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
25
|
* Whether the function is higher-order: it takes a function argument, may return one, or calls one of its own
|
|
18
26
|
* formals as a function. `function(x) x` alone is not higher-order.
|
|
19
27
|
* @useInstead {@link FunctionSemantics.isHigherOrder}
|
|
20
28
|
*/
|
|
21
|
-
export declare function isHigherOrder(this: void, id: NodeId, graph: DataflowGraph, { ctx, invertedGraph }: HigherOrderFunctionsOptions): boolean;
|
|
29
|
+
export declare function isHigherOrder(this: void, id: NodeId, graph: DataflowGraph, { ctx, invertedGraph, argumentFacts }: HigherOrderFunctionsOptions): boolean;
|
|
@@ -83,7 +83,7 @@ function definitionsBehind(id, graph) {
|
|
|
83
83
|
}
|
|
84
84
|
return found;
|
|
85
85
|
}
|
|
86
|
-
function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
|
|
86
|
+
function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph, facts) {
|
|
87
87
|
const callSites = invertedGraph?.outgoingEdges(def.id) ?? graph.ingoingEdges(def.id);
|
|
88
88
|
for (const [callerId, e] of callSites ?? []) {
|
|
89
89
|
if (!edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls)) {
|
|
@@ -98,12 +98,19 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
|
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
/* an apply-family call carries the callback among its arguments, which says nothing about the callback itself */
|
|
101
|
-
|
|
102
|
-
if (
|
|
101
|
+
let known = facts?.get(arg.nodeId);
|
|
102
|
+
if (known === undefined) {
|
|
103
|
+
known = { behind: definitionsBehind(arg.nodeId, graph) };
|
|
104
|
+
facts?.set(arg.nodeId, known);
|
|
105
|
+
}
|
|
106
|
+
if (known.behind.size === 1 && known.behind.has(def.id)) {
|
|
103
107
|
continue;
|
|
104
108
|
}
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
if (known.carriesFunction === undefined) {
|
|
110
|
+
const value = node_value_1.NodeValue.setOf(arg.nodeId, resolve_helper_1.Resolve.info(graph, ctx), { resolve: config_1.VariableResolve.Alias });
|
|
111
|
+
known.carriesFunction = value?.elements.some(e => e.type === 'function-definition') || readsBuiltInFunction(arg.nodeId, graph, ctx);
|
|
112
|
+
}
|
|
113
|
+
if (known.carriesFunction) {
|
|
107
114
|
return true;
|
|
108
115
|
}
|
|
109
116
|
}
|
|
@@ -120,11 +127,11 @@ function callsAFormal(id, graph, ctx) {
|
|
|
120
127
|
* formals as a function. `function(x) x` alone is not higher-order.
|
|
121
128
|
* @useInstead {@link FunctionSemantics.isHigherOrder}
|
|
122
129
|
*/
|
|
123
|
-
function isHigherOrder(id, graph, { ctx, invertedGraph }) {
|
|
130
|
+
function isHigherOrder(id, graph, { ctx, invertedGraph, argumentFacts }) {
|
|
124
131
|
const vert = graph.getVertex(id);
|
|
125
132
|
if (!vert || !vertex_1.DfgVertex.isFunctionDefinition(vert)) {
|
|
126
133
|
return false;
|
|
127
134
|
}
|
|
128
|
-
return isAnyReturnAFunction(vert, graph) || callsAFormal(id, graph, ctx) || inspectCallSitesArgumentsFns(vert, graph, ctx, invertedGraph);
|
|
135
|
+
return isAnyReturnAFunction(vert, graph) || callsAFormal(id, graph, ctx) || inspectCallSitesArgumentsFns(vert, graph, ctx, invertedGraph, argumentFacts);
|
|
129
136
|
}
|
|
130
137
|
//# sourceMappingURL=higher-order-function.js.map
|
|
@@ -99,7 +99,7 @@ function makeState(graph, ctx) {
|
|
|
99
99
|
dispatch.set(within, { named, certain, next });
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
return { graph, idMap, owner, dispatch, fnInfo, sigs: new Map(), props: name => fnInfo(name)?.sig, known: new Map(), asking: new Set(), assumed: false };
|
|
102
|
+
return { graph, idMap, owner, dispatch, fnInfo, sigs: new Map(), props: name => fnInfo(name)?.sig, known: new Map(), provisional: new Map(), asking: new Set(), assumed: false };
|
|
103
103
|
}
|
|
104
104
|
/** What is certain becomes a possibility once something may intervene. */
|
|
105
105
|
function weaken(value) {
|
|
@@ -240,7 +240,8 @@ function forces(read, definition, state) {
|
|
|
240
240
|
function strictnessOfParameter(param, definition, state) {
|
|
241
241
|
const reads = [];
|
|
242
242
|
for (const [read, edge] of state.graph.edgesTo(param)) {
|
|
243
|
-
|
|
243
|
+
/* a `NextMethod` hands the parameter on unforced, the methods it reaches decide below */
|
|
244
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !vertex_1.DfgVertex.hasOrigin(state.graph.getVertex(read), built_in_proc_name_1.BuiltInProcName.S3DispatchNext)) {
|
|
244
245
|
reads.push(forces(read, definition, state));
|
|
245
246
|
}
|
|
246
247
|
}
|
|
@@ -270,7 +271,7 @@ function parameterIds(definition, idMap) {
|
|
|
270
271
|
return r_function_definition_1.RFunctionDefinition.is(node) ? node.parameters.map(p => p.name.info.id) : [];
|
|
271
272
|
}
|
|
272
273
|
function strictnessOf(id, state) {
|
|
273
|
-
const known = state.known.get(id);
|
|
274
|
+
const known = state.known.get(id) ?? state.provisional.get(id);
|
|
274
275
|
if (known !== undefined) {
|
|
275
276
|
return known;
|
|
276
277
|
}
|
|
@@ -312,6 +313,10 @@ function strictnessOf(id, state) {
|
|
|
312
313
|
}
|
|
313
314
|
else if (state.asking.size === 0) {
|
|
314
315
|
state.assumed = false;
|
|
316
|
+
state.provisional.clear();
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
state.provisional.set(id, result);
|
|
315
320
|
}
|
|
316
321
|
return result;
|
|
317
322
|
}
|
|
@@ -230,6 +230,13 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
230
230
|
/** Returns true if the root level of the graph contains a node with the given id. */
|
|
231
231
|
isRoot(id: NodeId): boolean;
|
|
232
232
|
rootIds(): ReadonlySet<NodeId>;
|
|
233
|
+
/** while tracked (see {@link trackIncomingReads}), how often a read arriving at a vertex was added or removed */
|
|
234
|
+
private readsInto;
|
|
235
|
+
/** Starts (or stops) counting the reads added to or removed from each vertex, see {@link incomingReadsVersion}. */
|
|
236
|
+
trackIncomingReads(on: boolean): void;
|
|
237
|
+
/** How often a read arriving at `id` was added or removed since tracking started; an equal number means the reads are unchanged. */
|
|
238
|
+
incomingReadsVersion(id: NodeId): number;
|
|
239
|
+
private countRead;
|
|
233
240
|
/**
|
|
234
241
|
* Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
|
|
235
242
|
* An edge with no type is no edge: every removal has to go through here so none is left behind.
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -364,6 +364,21 @@ class DataflowGraph {
|
|
|
364
364
|
rootIds() {
|
|
365
365
|
return this.rootVertices;
|
|
366
366
|
}
|
|
367
|
+
/** while tracked (see {@link trackIncomingReads}), how often a read arriving at a vertex was added or removed */
|
|
368
|
+
readsInto;
|
|
369
|
+
/** Starts (or stops) counting the reads added to or removed from each vertex, see {@link incomingReadsVersion}. */
|
|
370
|
+
trackIncomingReads(on) {
|
|
371
|
+
this.readsInto = on ? new Map() : undefined;
|
|
372
|
+
}
|
|
373
|
+
/** How often a read arriving at `id` was added or removed since tracking started; an equal number means the reads are unchanged. */
|
|
374
|
+
incomingReadsVersion(id) {
|
|
375
|
+
return this.readsInto?.get(id) ?? 0;
|
|
376
|
+
}
|
|
377
|
+
countRead(to, type) {
|
|
378
|
+
if (this.readsInto !== undefined && (type & edge_1.EdgeType.Reads) !== 0) {
|
|
379
|
+
this.readsInto.set(to, (this.readsInto.get(to) ?? 0) + 1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
367
382
|
/**
|
|
368
383
|
* Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
|
|
369
384
|
* An edge with no type is no edge: every removal has to go through here so none is left behind.
|
|
@@ -376,6 +391,7 @@ class DataflowGraph {
|
|
|
376
391
|
return this;
|
|
377
392
|
}
|
|
378
393
|
this.dropQualifications();
|
|
394
|
+
this.countRead(to, type);
|
|
379
395
|
edge.types &= ~type;
|
|
380
396
|
if (edge_1.DfEdge.hasAnyType(edge)) {
|
|
381
397
|
/* the reverse index holds this very object, so a narrowed type is already visible through it */
|
|
@@ -435,6 +451,7 @@ class DataflowGraph {
|
|
|
435
451
|
return this;
|
|
436
452
|
}
|
|
437
453
|
this.dropQualifications();
|
|
454
|
+
this.countRead(toId, type);
|
|
438
455
|
const fromEdges = this.edgeInformation.get(fromId);
|
|
439
456
|
const existing = fromEdges?.get(toId);
|
|
440
457
|
if (existing !== undefined) {
|
|
@@ -118,7 +118,7 @@ export interface DataflowGraphVertexFunctionCall extends DataflowGraphVertexBase
|
|
|
118
118
|
* For a class-declaring call (`setClass`, `setClassUnion`, `setIs`, `setValidity`, `setRefClass`,
|
|
119
119
|
* `S7::new_class`, `R6::R6Class`): what the declaration states -- its name, superclasses, members, and
|
|
120
120
|
* whether it can be instantiated. Filled from the {@link ClassDeclarationConfig} the built-in declares,
|
|
121
|
-
* so no argument's meaning is guessed. See {@link
|
|
121
|
+
* so no argument's meaning is guessed. See {@link declaredClassesImpl} to collect these across a graph.
|
|
122
122
|
*/
|
|
123
123
|
classDecl?: ClassDeclaration;
|
|
124
124
|
}
|
|
@@ -38,6 +38,7 @@ alsoCalls?: readonly NodeId[]): {
|
|
|
38
38
|
functionCall: NodeId;
|
|
39
39
|
called: readonly DataflowGraphVertexInfo[];
|
|
40
40
|
propagateExitPoints: readonly ExitPoint[];
|
|
41
|
+
calledBuiltIns?: readonly NodeId[];
|
|
41
42
|
}[];
|
|
42
43
|
/**
|
|
43
44
|
* convenience function returning all known call targets, as well as the name source which defines them
|
|
@@ -54,6 +55,8 @@ export declare function getAllLinkedFunctionDefinitions(functionDefinitionReadId
|
|
|
54
55
|
* @useInstead {@link FunctionSemantics.call.quoted.evaluateIn}
|
|
55
56
|
*/
|
|
56
57
|
export declare function linkExpressionIn<Info>(this: void, graph: DataflowGraph, expr: NodeId, environment: REnvironmentInformation, idMap: AstIdMap<Info & ParentInformation>): readonly IdentifierReference[];
|
|
58
|
+
/** Links the call `callId` to the functions the given definitions bind, which it did not know of when it was processed. */
|
|
59
|
+
export declare function linkCallToDefinitions(graph: DataflowGraph, callId: NodeId, definitions: readonly NodeId[], idMap: AstIdMap): void;
|
|
57
60
|
/**
|
|
58
61
|
* Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked is
|
|
59
62
|
* added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
|
|
@@ -9,6 +9,7 @@ exports.linkFunctionCalls = linkFunctionCalls;
|
|
|
9
9
|
exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
|
|
10
10
|
exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
|
|
11
11
|
exports.linkExpressionIn = linkExpressionIn;
|
|
12
|
+
exports.linkCallToDefinitions = linkCallToDefinitions;
|
|
12
13
|
exports.linkInputs = linkInputs;
|
|
13
14
|
exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
|
|
14
15
|
exports.reapplyLoopExitPoints = reapplyLoopExitPoints;
|
|
@@ -37,6 +38,7 @@ const built_in_proc_name_1 = require("../environments/built-in-proc-name");
|
|
|
37
38
|
const vertex_2 = require("../graph/vertex");
|
|
38
39
|
const resolve_helper_1 = require("../environments/resolve-helper");
|
|
39
40
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
41
|
+
const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
40
42
|
const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
41
43
|
/**
|
|
42
44
|
* Find all reads within the graph that do not reference a local definition in the graph.
|
|
@@ -122,6 +124,19 @@ function environmentsOfCallee(info) {
|
|
|
122
124
|
}
|
|
123
125
|
return (resolve_helper_1.Resolve.byName(info.name, info.environment) ?? []).filter(identifier_1.hasEnvState).map(d => d.envState);
|
|
124
126
|
}
|
|
127
|
+
const AliasFlowBits = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
|
|
128
|
+
/** `start` and everything that takes over what it reads: aliases and nested uses of an environment all share it. */
|
|
129
|
+
function aliasReadsOf(graph, start) {
|
|
130
|
+
const found = new Set([start]);
|
|
131
|
+
for (const id of found) {
|
|
132
|
+
for (const [from, edge] of graph.edgesTo(id)) {
|
|
133
|
+
if (edge_1.DfEdge.includesType(edge, AliasFlowBits)) {
|
|
134
|
+
found.add(from);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return found;
|
|
139
|
+
}
|
|
125
140
|
/**
|
|
126
141
|
* Links a function call with a single target function definition.
|
|
127
142
|
*/
|
|
@@ -153,8 +168,20 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
153
168
|
if (!fnSubflow.graph.has(nodeId) && !node_id_1.NodeId.isBuiltIn(nodeId)) {
|
|
154
169
|
graph.addEdge(ingoing.nodeId, nodeId, edge_1.EdgeType.DefinedByOnCall);
|
|
155
170
|
graph.addEdge(id, nodeId, edge_1.EdgeType.DefinesOnCall);
|
|
156
|
-
|
|
157
|
-
bindAccessedField(graph,
|
|
171
|
+
for (const read of envState === undefined ? [] : aliasReadsOf(graph, ingoing.nodeId)) {
|
|
172
|
+
bindAccessedField(graph, read, envState, idMap);
|
|
173
|
+
const write = fieldAssignmentOf(read, idMap);
|
|
174
|
+
if (write !== undefined) {
|
|
175
|
+
graph.addEdge(id, write, edge_1.EdgeType.Reads);
|
|
176
|
+
graph.addEdge(nodeId, id, edge_1.EdgeType.SideEffectOnCall);
|
|
177
|
+
/* a write in a nested function only runs when that function is called */
|
|
178
|
+
const within = model_1.RNode.findEnclosing(write, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
179
|
+
for (const [caller, edge] of within === undefined || within === fnId ? [] : graph.edgesTo(within)) {
|
|
180
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
|
|
181
|
+
graph.addEdge(write, caller, edge_1.EdgeType.Reads);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
158
185
|
}
|
|
159
186
|
if (definedAt !== undefined && definedAt !== nodeId && !node_id_1.NodeId.isBuiltIn(definedAt)
|
|
160
187
|
&& graph.hasVertex(definedAt) && !vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(nodeId))) {
|
|
@@ -198,6 +225,10 @@ function applyForForcedArgs(graph, callId, readParams, maps) {
|
|
|
198
225
|
for (const [arg, param] of maps.entries()) {
|
|
199
226
|
if (readParams[String(param)]) {
|
|
200
227
|
graph.addEdge(callId, arg, edge_1.EdgeType.Reads);
|
|
228
|
+
/* a call in the argument only runs when the call forces it, so its side effects depend on the call */
|
|
229
|
+
if (vertex_2.DfgVertex.isFunctionCall(graph.getVertex(arg))) {
|
|
230
|
+
graph.addEdge(arg, callId, edge_1.EdgeType.Reads);
|
|
231
|
+
}
|
|
201
232
|
}
|
|
202
233
|
}
|
|
203
234
|
}
|
|
@@ -214,7 +245,7 @@ function linkFunctionCall(graph, id, info, idMap, thisGraph, calledFunctionDefin
|
|
|
214
245
|
functionDefinitionReadIds.add(t);
|
|
215
246
|
}
|
|
216
247
|
}
|
|
217
|
-
const [functionDefs] = getAllLinkedFunctionDefinitions(functionDefinitionReadIds, graph);
|
|
248
|
+
const [functionDefs, builtIns] = getAllLinkedFunctionDefinitions(functionDefinitionReadIds, graph);
|
|
218
249
|
const propagateExitPoints = [];
|
|
219
250
|
for (const def of functionDefs.values()) {
|
|
220
251
|
// we can skip this if we already linked it
|
|
@@ -226,8 +257,9 @@ function linkFunctionCall(graph, id, info, idMap, thisGraph, calledFunctionDefin
|
|
|
226
257
|
propagateExitPoints.push(ep);
|
|
227
258
|
}
|
|
228
259
|
}
|
|
229
|
-
if (thisGraph.isRoot(id) && functionDefs.size > 0) {
|
|
230
|
-
|
|
260
|
+
if (thisGraph.isRoot(id) && (functionDefs.size > 0 || builtIns.size > 0)) {
|
|
261
|
+
/* a built-in reached through a variable (`p <- par; p(...)`) was not processed as that built-in */
|
|
262
|
+
calledFunctionDefinitions.push({ functionCall: id, called: functionDefs.values().toArray(), propagateExitPoints, calledBuiltIns: builtIns.size > 0 ? [...builtIns] : undefined });
|
|
231
263
|
}
|
|
232
264
|
}
|
|
233
265
|
/**
|
|
@@ -369,7 +401,8 @@ function linkExpressionIn(graph, expr, environment, idMap) {
|
|
|
369
401
|
model_1.RNode.visitAst(node, inner => {
|
|
370
402
|
if (r_function_call_1.RFunctionCall.isNamed(inner)) {
|
|
371
403
|
callees.add(inner.functionName.info.id);
|
|
372
|
-
|
|
404
|
+
/* the call vertex carries the call's id, its name symbol has no vertex of its own */
|
|
405
|
+
references.push({ nodeId: inner.info.id, name: inner.functionName.content, cds: undefined, type: identifier_1.ReferenceType.Function });
|
|
373
406
|
}
|
|
374
407
|
else if (r_symbol_1.RSymbol.is(inner) && !callees.has(inner.info.id)) {
|
|
375
408
|
references.push({ nodeId: inner.info.id, name: inner.content, cds: undefined, type: identifier_1.ReferenceType.Variable });
|
|
@@ -378,8 +411,23 @@ function linkExpressionIn(graph, expr, environment, idMap) {
|
|
|
378
411
|
});
|
|
379
412
|
const unresolved = [];
|
|
380
413
|
linkInputs(references, environment, unresolved, graph, false);
|
|
414
|
+
for (const call of references.filter(r => r.type === identifier_1.ReferenceType.Function)) {
|
|
415
|
+
linkCallToDefinitions(graph, call.nodeId, resolve_helper_1.Resolve.byNameAndType(call.name, environment, identifier_1.ReferenceType.Function)?.map(d => d.nodeId) ?? [], idMap);
|
|
416
|
+
}
|
|
381
417
|
return unresolved;
|
|
382
418
|
}
|
|
419
|
+
/** Links the call `callId` to the functions the given definitions bind, which it did not know of when it was processed. */
|
|
420
|
+
function linkCallToDefinitions(graph, callId, definitions, idMap) {
|
|
421
|
+
const call = graph.getVertex(callId);
|
|
422
|
+
if (definitions.length === 0 || !vertex_2.DfgVertex.isFunctionCall(call)) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
for (const fn of getAllLinkedFunctionDefinitions(new Set(definitions), graph)[0]) {
|
|
426
|
+
if (!edge_1.DfEdge.includesType(graph.outgoingEdges(callId)?.get(fn.id) ?? { types: 0 }, edge_1.EdgeType.Calls)) {
|
|
427
|
+
linkFunctionCallWithSingleTarget(graph, fn, call, idMap);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
383
431
|
/**
|
|
384
432
|
* Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked is
|
|
385
433
|
* added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
|
|
@@ -548,6 +596,19 @@ function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
|
|
|
548
596
|
}
|
|
549
597
|
}
|
|
550
598
|
}
|
|
599
|
+
/** The call writing a field into the environment the symbol `readId` holds: `x$f <- v` (its replacement call) or `assign("f", v, envir = x)`. */
|
|
600
|
+
function fieldAssignmentOf(readId, idMap) {
|
|
601
|
+
const read = idMap.get(readId);
|
|
602
|
+
const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
|
|
603
|
+
/* `assign("f", v, envir = x)` writes into `x` as well */
|
|
604
|
+
const call = access === undefined ? undefined : model_1.RNode.directParent(access, idMap);
|
|
605
|
+
if (r_function_call_1.RFunctionCall.isNamed(call) && identifier_1.Identifier.getName(call.functionName.content) === 'assign' && call.arguments.indexOf(access) >= 2) {
|
|
606
|
+
return call.info.id;
|
|
607
|
+
}
|
|
608
|
+
const assign = r_access_1.RAccess.is(access) && access.accessed.info.id === readId ? call : undefined;
|
|
609
|
+
/* the replacement call `$<-` carries the id of the access it writes through */
|
|
610
|
+
return r_binary_op_1.RBinaryOp.is(assign) && assign.lhs.info.id === access?.info.id && /^(<<?-|=)$/.test(assign.operator) ? access.info.id : undefined;
|
|
611
|
+
}
|
|
551
612
|
/**
|
|
552
613
|
* An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is
|
|
553
614
|
* known, so binding the read at `readId` to a definition holding `envState` links the access to that field.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
2
|
+
import { DataflowInformation } from '../../../../../info';
|
|
3
|
+
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
+
import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
|
+
import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
6
|
+
import { Identifier, type IdentifierDefinition, type IdentifierReference } from '../../../../../environments/identifier';
|
|
7
|
+
import type { REnvironmentInformation } from '../../../../../environments/environment';
|
|
8
|
+
import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
|
|
9
|
+
import type { LinkTo } from '../../../../../../queries/catalog/call-context-query/call-context-query-format';
|
|
10
|
+
import type { DataflowGraph } from '../../../../../graph/graph';
|
|
11
|
+
import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
12
|
+
/**
|
|
13
|
+
* Graphics parameters and options, tracked as global pseudo variables (`#...`) so readers link to the calls that set them.
|
|
14
|
+
* Accumulating states only grow: `par(mar = ...)` keeps an earlier `par(mfrow = ...)`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AmbientStateName: {
|
|
17
|
+
/** the graphics state (`par`, `layout`, ...) of the active device, which a new device starts afresh */
|
|
18
|
+
readonly graphics: "#graphics";
|
|
19
|
+
/** the graphics states of the other open devices, the active one returns to one of them once it closes */
|
|
20
|
+
readonly otherDevices: "#graphics:other";
|
|
21
|
+
/** the call that opened the active device, and those of the other open devices */
|
|
22
|
+
readonly device: "#device";
|
|
23
|
+
readonly otherDevicesOpenedBy: "#device:other";
|
|
24
|
+
/** the color palette, which, other than the graphics parameters, all devices share */
|
|
25
|
+
readonly palette: "#palette";
|
|
26
|
+
/** every option write, for readers that may read any option (`getOption(k)` with an unknown `k`, library functions) */
|
|
27
|
+
readonly allOptions: "#options";
|
|
28
|
+
/** written by an `options(...)` call whose keys we cannot name, like the common `options(op)` restore */
|
|
29
|
+
readonly unknownOption: "#option:*";
|
|
30
|
+
/** the pseudo variable holding the option `key`; setting the option replaces it */
|
|
31
|
+
readonly option: (this: void, key: string) => string;
|
|
32
|
+
/** whether `name` is one of these pseudo variables */
|
|
33
|
+
readonly is: (this: void, name: Identifier | undefined) => name is string;
|
|
34
|
+
};
|
|
35
|
+
/** Whether calling `definition` runs a body flowR cannot see: a library function's, or whatever a parameter is bound to. */
|
|
36
|
+
export declare function hidesBody(definition: IdentifierDefinition): boolean;
|
|
37
|
+
/** A call into code flowR cannot see may read any option and draw on the device. */
|
|
38
|
+
export declare function readsAllAmbientState<OtherInfo>(res: DataflowInformation, rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, graphics: boolean): DataflowInformation;
|
|
39
|
+
/** `.Options$digits` (or `.Options[["digits"]]`) reads that option, anything else done with `.Options` reads all of them. */
|
|
40
|
+
export declare function readsOfOptionsVariable<OtherInfo>(symbol: RSymbol<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): IdentifierReference[];
|
|
41
|
+
/** Options that affect how values are printed and formatted (read by `print`, `format`, and `cat`). */
|
|
42
|
+
export declare const PrintingOptions: readonly string[];
|
|
43
|
+
/** How a call accesses the {@link AmbientStateName|ambient state}. */
|
|
44
|
+
export declare const enum AmbientStateAccessType {
|
|
45
|
+
/** `options(...)`: named arguments set options, unnamed strings query them, anything else sets unknown options */
|
|
46
|
+
SetOptions = "set-options",
|
|
47
|
+
/** `getOption(x)`: reads the option named by the first argument */
|
|
48
|
+
GetOption = "get-option",
|
|
49
|
+
/** reads the given options, like `cat` reads `digits` (see {@link AmbientStateAccess#dispatchOn} for `print`) */
|
|
50
|
+
ReadOptions = "read-options",
|
|
51
|
+
/** writes the graphics state, unless all arguments are unnamed strings (see {@link AmbientStateAccess#queryOnUnnamedStrings}) */
|
|
52
|
+
SetGraphics = "set-graphics",
|
|
53
|
+
/** writes the palette, which all devices share; without arguments it only reads it */
|
|
54
|
+
SetPalette = "set-palette",
|
|
55
|
+
/** reads the graphics state and the palette, like every plot does */
|
|
56
|
+
ReadGraphics = "read-graphics",
|
|
57
|
+
/** opens a device, which starts with a fresh graphics state */
|
|
58
|
+
OpenDevice = "open-device",
|
|
59
|
+
/** closes a device (or all of them), returning to the state of another open device */
|
|
60
|
+
CloseDevice = "close-device",
|
|
61
|
+
/** makes another open device the active one */
|
|
62
|
+
SwitchDevice = "switch-device",
|
|
63
|
+
/** evaluates its unevaluated argument, like `evalq`, see {@link evaluatesCapturedCode} */
|
|
64
|
+
EvaluateQuoted = "evaluate-quoted"
|
|
65
|
+
}
|
|
66
|
+
export type AmbientStateAccess = {
|
|
67
|
+
readonly type: AmbientStateAccessType.SetOptions | AmbientStateAccessType.GetOption | AmbientStateAccessType.ReadGraphics | AmbientStateAccessType.SetPalette | AmbientStateAccessType.OpenDevice | AmbientStateAccessType.SwitchDevice;
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: AmbientStateAccessType.ReadOptions;
|
|
70
|
+
readonly keys: readonly string[];
|
|
71
|
+
/** the argument `print(x)` dispatches on: a package method may read any option unless the value is plain */
|
|
72
|
+
readonly dispatchOn?: number;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: AmbientStateAccessType.EvaluateQuoted;
|
|
75
|
+
} | {
|
|
76
|
+
readonly type: AmbientStateAccessType.CloseDevice;
|
|
77
|
+
/** `graphics.off()` closes every device */
|
|
78
|
+
readonly all?: boolean;
|
|
79
|
+
} | {
|
|
80
|
+
readonly type: AmbientStateAccessType.SetGraphics;
|
|
81
|
+
/** `par()` and `par("mar")` only query the state */
|
|
82
|
+
readonly queryOnUnnamedStrings?: boolean;
|
|
83
|
+
/** a query also reads what the last plot left behind (`par("usr")`), linked like an unknown side effect */
|
|
84
|
+
readonly queryLinksTo?: LinkTo<RegExp | string>;
|
|
85
|
+
};
|
|
86
|
+
/** Wires the {@link AmbientStateAccess} of a call into its dataflow information: reads become unknown references, writes define the pseudo variable globally. */
|
|
87
|
+
export declare function applyAmbientStateAccess<OtherInfo>(res: DataflowInformation, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[] | UnknownArguments, rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, access: AmbientStateAccess): DataflowInformation;
|
|
88
|
+
/** The arguments of a call made on our behalf, like `do.call(par, args)`, which we cannot see. */
|
|
89
|
+
declare const UnknownArguments: unique symbol;
|
|
90
|
+
type UnknownArguments = typeof UnknownArguments;
|
|
91
|
+
/** A call to `fn` made on our behalf (`do.call(fn, args)`, `sapply(x, fn)`): it accesses the state as `fn` does, or reads all of it if `fn` is opaque. */
|
|
92
|
+
export declare function applyAmbientStateOfCallee<OtherInfo>(res: DataflowInformation, callId: NodeId, fn: Identifier, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
93
|
+
/** Links state reads in a loop body to the body's own writes of a later iteration; the loops' circular linking only sees uses. */
|
|
94
|
+
export declare function linkAmbientStateWithinLoop(graph: DataflowGraph, reads: readonly IdentifierReference[], body: DataflowInformation): void;
|
|
95
|
+
/** A scoped state change (`withr`, `rlang`): `with_*` undoes it after its code, `local_*` when the calling function returns. */
|
|
96
|
+
export interface AmbientScope {
|
|
97
|
+
readonly state: 'options' | 'graphics' | 'device';
|
|
98
|
+
/** the formals in order, used to bind the arguments */
|
|
99
|
+
readonly params: readonly string[];
|
|
100
|
+
/** the formal evaluated with the change in effect, absent for the `local_*` variants */
|
|
101
|
+
readonly code?: string;
|
|
102
|
+
/** the formal holding a list of the new values (`list(digits = 3)`), other named arguments are values too */
|
|
103
|
+
readonly new?: string;
|
|
104
|
+
}
|
|
105
|
+
/** The processor for an {@link AmbientScope}. */
|
|
106
|
+
export declare function processAmbientScope<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, scope: AmbientScope): DataflowInformation;
|
|
107
|
+
/** Evaluating captured code may access any state; `Quoted.finalize` drops the writes again once the code is known to change none. */
|
|
108
|
+
export declare function evaluatesCapturedCode<OtherInfo>(res: DataflowInformation, rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
109
|
+
/** R prints every visible top-level value, which reads the printing options like `print` does. */
|
|
110
|
+
export declare function readsOfAutoPrint<OtherInfo>(processed: DataflowInformation, expression: RNode<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
111
|
+
/** A call through a variable bound to a built-in (`p <- par; p(...)`), only revealed when linking the statement's calls. */
|
|
112
|
+
export declare function applyAmbientStateOfCalledBuiltIns<OtherInfo>(res: DataflowInformation, callId: NodeId, builtIns: readonly NodeId[], before: REnvironmentInformation, graph: DataflowGraph, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
113
|
+
export {};
|