@eagleoutice/flowr 2.13.14 → 2.13.15

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.
Files changed (131) hide show
  1. package/README.md +23 -23
  2. package/abstract-interpretation/data-frame/resolve-args.js +11 -12
  3. package/benchmark/summarizer/second-phase/graph.d.ts +23 -0
  4. package/benchmark/summarizer/second-phase/graph.js +47 -14
  5. package/cli/repl/commands/repl-cfg.js +2 -42
  6. package/cli/repl/commands/repl-clipboard.d.ts +7 -0
  7. package/cli/repl/commands/repl-clipboard.js +53 -0
  8. package/cli/repl/commands/repl-dataflow.js +5 -70
  9. package/cli/repl/commands/repl-normalize.js +3 -51
  10. package/control-flow/cfg-dead-code.js +5 -29
  11. package/control-flow/diff-cfg.js +2 -56
  12. package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
  13. package/control-flow/semantic-cfg-guided-visitor.js +14 -0
  14. package/control-flow/useless-loop.js +4 -26
  15. package/core/steps/all/core/10-normalize.d.ts +8 -0
  16. package/core/steps/all/core/10-normalize.js +10 -8
  17. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +5 -7
  18. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -9
  19. package/data/r-base-packages.generated.d.ts +1 -0
  20. package/data/r-base-packages.generated.js +5 -3
  21. package/dataflow/environments/built-in-config.d.ts +9 -1
  22. package/dataflow/environments/built-in-proc-name.d.ts +2 -0
  23. package/dataflow/environments/built-in-proc-name.js +2 -0
  24. package/dataflow/environments/built-in-props.d.ts +4 -0
  25. package/dataflow/environments/built-in-props.js +3 -3
  26. package/dataflow/environments/built-in.d.ts +4 -2
  27. package/dataflow/environments/built-in.js +53 -3
  28. package/dataflow/environments/data-masking-functions.d.ts +3 -4
  29. package/dataflow/environments/data-masking-functions.js +7 -8
  30. package/dataflow/environments/default-builtin-config.d.ts +92 -12
  31. package/dataflow/environments/default-builtin-config.js +86 -43
  32. package/dataflow/environments/environment.d.ts +5 -0
  33. package/dataflow/environments/environment.js +17 -12
  34. package/dataflow/environments/identifier.d.ts +3 -0
  35. package/dataflow/eval/resolve/alias-tracking.js +4 -7
  36. package/dataflow/eval/resolve/node-value.d.ts +51 -0
  37. package/dataflow/eval/resolve/node-value.js +71 -0
  38. package/dataflow/eval/resolve/resolve-argument.js +10 -7
  39. package/dataflow/eval/resolve/resolve-operators.js +1 -2
  40. package/dataflow/eval/values/general.d.ts +4 -0
  41. package/dataflow/eval/values/general.js +11 -0
  42. package/dataflow/eval/values/r-value.d.ts +15 -0
  43. package/dataflow/eval/values/r-value.js +27 -1
  44. package/dataflow/extractor.js +2 -0
  45. package/dataflow/fn/higher-order-function.js +2 -3
  46. package/dataflow/graph/diff-dataflow-graph.js +3 -55
  47. package/dataflow/graph/graph.d.ts +5 -0
  48. package/dataflow/graph/graph.js +27 -0
  49. package/dataflow/internal/linker.d.ts +23 -0
  50. package/dataflow/internal/linker.js +70 -1
  51. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +4 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +2 -0
  53. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -29
  54. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +39 -6
  55. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +10 -22
  56. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +29 -53
  57. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -5
  58. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -7
  59. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -3
  60. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +19 -12
  61. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +2 -1
  62. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +3 -0
  63. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +69 -52
  64. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  65. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +2 -8
  66. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -8
  67. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -2
  69. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -0
  70. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +23 -3
  71. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +5 -4
  72. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +7 -10
  73. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +6 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +20 -3
  75. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -8
  76. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +25 -0
  77. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +105 -0
  78. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -27
  79. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  80. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +1 -1
  81. package/dataflow/internal/process/functions/call/deferred.d.ts +41 -0
  82. package/dataflow/internal/process/functions/call/deferred.js +127 -0
  83. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +13 -12
  84. package/dataflow/internal/process/functions/call/known-call-handling.js +35 -35
  85. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
  87. package/dataflow/internal/process/functions/call/nse.d.ts +28 -0
  88. package/dataflow/internal/process/functions/call/nse.js +87 -0
  89. package/dataflow/internal/process/functions/call/quoted.d.ts +29 -0
  90. package/dataflow/internal/process/functions/call/quoted.js +188 -0
  91. package/documentation/doc-util/doc-types.js +15 -9
  92. package/linter/rules/deprecated-functions.js +9 -3
  93. package/linter/rules/seeded-randomness.js +2 -3
  94. package/linter/rules/undefined-symbol.js +10 -1
  95. package/package.json +1 -1
  96. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +6 -0
  97. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +17 -1
  98. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +2 -11
  99. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +3 -15
  100. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +16 -0
  101. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +26 -0
  102. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -11
  103. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +3 -15
  104. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +4 -10
  105. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -9
  106. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -9
  107. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +1 -1
  108. package/project/sigdb/reader.d.ts +9 -0
  109. package/project/sigdb/reader.js +30 -0
  110. package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -1
  111. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -12
  112. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -37
  113. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -23
  114. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  115. package/queries/query-function-filter.d.ts +21 -0
  116. package/queries/query-function-filter.js +48 -0
  117. package/r-bridge/data/data.d.ts +13 -3
  118. package/r-bridge/data/data.js +15 -3
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +2 -0
  120. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +4 -0
  121. package/search/flowr-search-filters.d.ts +5 -1
  122. package/search/flowr-search-filters.js +31 -21
  123. package/search/search-executor/search-enrichers.d.ts +24 -4
  124. package/search/search-executor/search-enrichers.js +22 -9
  125. package/search/search-executor/search-transformer.js +1 -1
  126. package/util/diff-graph.d.ts +13 -0
  127. package/util/diff-graph.js +64 -1
  128. package/util/files.js +9 -8
  129. package/util/r-base-packages.d.ts +2 -0
  130. package/util/r-base-packages.js +3 -1
  131. package/util/version.js +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bottom = exports.Top = void 0;
3
+ exports.RValue = exports.Bottom = exports.Top = void 0;
4
4
  exports.typeOfValue = typeOfValue;
5
5
  exports.isTop = isTop;
6
6
  exports.isBottom = isBottom;
@@ -103,4 +103,30 @@ function stringifyValue(value) {
103
103
  }
104
104
  });
105
105
  }
106
+ /**
107
+ * Reads the plain TS value a {@link Value} stands for, `undefined` whenever it stands for more than one, for
108
+ * none, or for another kind. Prefer these over reaching into a value's shape by hand.
109
+ *
110
+ * This is the constant-folding view: it answers "is this one known constant" and nothing else. It runs no
111
+ * fixpoint, knows no control flow, and widens nothing. For an abstract state that does, use the dedicated
112
+ * abstract interpretation in `src/abstract-interpretation/`.
113
+ */
114
+ exports.RValue = {
115
+ name: 'RValue',
116
+ /** The number the value stands for, collapsing an interval that admits a single one. */
117
+ numberOf(value) {
118
+ if (value.type === 'number') {
119
+ return isValue(value.value) && !value.value.complexNumber ? value.value.num : undefined;
120
+ }
121
+ else if (value.type === 'interval' && value.startInclusive && value.endInclusive) {
122
+ const start = exports.RValue.numberOf(value.start);
123
+ return start !== undefined && start === exports.RValue.numberOf(value.end) ? start : undefined;
124
+ }
125
+ return undefined;
126
+ },
127
+ /** The string the value stands for. */
128
+ stringOf(value) {
129
+ return value.type === 'string' && isValue(value.value) ? value.value.str : undefined;
130
+ }
131
+ };
106
132
  //# sourceMappingURL=r-value.js.map
@@ -25,6 +25,7 @@ const flowr_file_1 = require("../project/context/flowr-file");
25
25
  /** Round cap for the transitive-side-effect fixpoint. */
26
26
  const transitiveSideEffectRounds = 32;
27
27
  const identifier_1 = require("./environments/identifier");
28
+ const quoted_1 = require("./internal/process/functions/call/quoted");
28
29
  const range_1 = require("../util/range");
29
30
  const logger_1 = require("./logger");
30
31
  const gas_1 = require("../gas");
@@ -171,6 +172,7 @@ function produceDataFlowGraph(parser, completeAst, ctx) {
171
172
  }
172
173
  // link on-demand-materialized package exports back to their `library()` loaders
173
174
  (0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
175
+ quoted_1.Quoted.finalize(df.graph, completeAst.idMap, () => (0, extract_cfg_1.extractCfgQuick)(completeAst).graph);
174
176
  df.cfgQuick = resolveLinkToSideEffects(completeAst, df.graph, ctx);
175
177
  // performance optimization: return cfgQuick as part of the result to avoid recomputation
176
178
  return df;
@@ -4,10 +4,9 @@ exports.isFunctionHigherOrder = isFunctionHigherOrder;
4
4
  const vertex_1 = require("../graph/vertex");
5
5
  const assert_1 = require("../../util/assert");
6
6
  const edge_1 = require("../graph/edge");
7
- const alias_tracking_1 = require("../eval/resolve/alias-tracking");
7
+ const node_value_1 = require("../eval/resolve/node-value");
8
8
  const config_1 = require("../../config");
9
9
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
10
- const general_1 = require("../eval/values/general");
11
10
  function isAnyReturnAFunction(def, graph) {
12
11
  const workingQueue = def.exitPoints.map(d => graph.getVertex(d.nodeId)).filter(assert_1.isNotUndefined);
13
12
  const seen = new Set();
@@ -46,7 +45,7 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
46
45
  if (arg === r_function_call_1.EmptyArgument) {
47
46
  continue;
48
47
  }
49
- const value = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.nodeId, { graph, idMap: graph.idMap, resolve: config_1.VariableResolve.Alias, full: true, ctx }));
48
+ const value = node_value_1.NodeValue.inGraph.setOf(arg.nodeId, graph, ctx, { resolve: config_1.VariableResolve.Alias });
50
49
  if (value?.elements.some(e => e.type === 'function-definition')) {
51
50
  return true;
52
51
  }
@@ -15,6 +15,7 @@ const identifier_1 = require("../environments/identifier");
15
15
  const diff_2 = require("../environments/diff");
16
16
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
17
17
  const info_1 = require("../info");
18
+ const diff_graph_1 = require("../../util/diff-graph");
18
19
  /**
19
20
  * This is the underlying function to calculate the difference based on a given context.
20
21
  * Use {@link Dataflow.diff} to calculate the diff of two graphs.
@@ -22,39 +23,7 @@ const info_1 = require("../info");
22
23
  function diffDataflowGraph(ctx) {
23
24
  diffRootVertices(ctx);
24
25
  diffVertices(ctx);
25
- diffOutgoingEdges(ctx);
26
- }
27
- function diffOutgoingEdges(ctx) {
28
- const lEdges = new Map(ctx.left.edges());
29
- const rEdges = new Map(ctx.right.edges());
30
- if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
31
- ctx.report.addComment(`Detected different number of edges! ${ctx.leftname} has ${lEdges.size} (${JSON.stringify(lEdges, json_1.jsonReplacer)}). ${ctx.rightname} has ${rEdges.size} ${JSON.stringify(rEdges, json_1.jsonReplacer)}`);
32
- }
33
- for (const [id, edge] of lEdges) {
34
- /* This has nothing to do with the subset relation as we verify this in the same graph.
35
- * Yet we still do the check as a subgraph may not have to have all source vertices for edges.
36
- */
37
- if (!ctx.left.hasVertex(id)) {
38
- if (!ctx.config.leftIsSubgraph) {
39
- ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.leftname}. This means that the graph contains an edge but not the corresponding vertex.`);
40
- continue;
41
- }
42
- }
43
- diffEdges(ctx, id, edge, rEdges.get(id));
44
- }
45
- // just to make it both ways in case the length differs
46
- for (const [id, edge] of rEdges) {
47
- if (!ctx.right.hasVertex(id)) {
48
- if (!ctx.config.rightIsSubgraph) {
49
- ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.rightname}. This means that the graph contains an edge but not the corresponding vertex.`);
50
- continue;
51
- }
52
- }
53
- if (!ctx.config.leftIsSubgraph && !lEdges.has(id)) {
54
- diffEdges(ctx, id, undefined, edge);
55
- }
56
- /* otherwise, we already cover the edge above */
57
- }
26
+ diff_graph_1.GraphDiff.outgoingEdges(ctx, diffEdges);
58
27
  }
59
28
  function diffRootVertices(ctx) {
60
29
  (0, diff_1.setDifference)(ctx.left.rootIds(), ctx.right.rootIds(), { ...ctx, position: `${ctx.position}Root vertices differ in graphs. ` });
@@ -319,27 +288,6 @@ function diffEdge(edge, otherEdge, ctx, id, target) {
319
288
  * Compares two sets of outgoing edges and reports differences.
320
289
  */
321
290
  function diffEdges(ctx, id, lEdges, rEdges) {
322
- if (lEdges === undefined || rEdges === undefined) {
323
- if ((lEdges === undefined && !ctx.config.leftIsSubgraph)
324
- || (rEdges === undefined && !ctx.config.rightIsSubgraph)) {
325
- ctx.report.addComment(`Vertex ${id} has undefined outgoing edges. ${ctx.leftname}: ${JSON.stringify(lEdges, json_1.jsonReplacer)} vs ${ctx.rightname}: ${JSON.stringify(rEdges, json_1.jsonReplacer)}`, { tag: 'vertex', id });
326
- }
327
- return;
328
- }
329
- if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph
330
- || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
331
- ctx.report.addComment(`Vertex ${id} differs in number of outgoing edges. ${ctx.leftname}: [${[...lEdges.keys()].join(',')}] vs ${ctx.rightname}: [${[...rEdges.keys()].join(',')}] `, { tag: 'vertex', id });
332
- }
333
- // order independent compare
334
- for (const [target, edge] of lEdges) {
335
- const otherEdge = rEdges.get(target);
336
- if (otherEdge === undefined) {
337
- if (!ctx.config.rightIsSubgraph) {
338
- ctx.report.addComment(`Target of ${id}->${target} in ${ctx.leftname} is not present in ${ctx.rightname}`, { tag: 'edge', from: id, to: target });
339
- }
340
- continue;
341
- }
342
- diffEdge(edge, otherEdge, ctx, id, target);
343
- }
291
+ diff_graph_1.GraphDiff.edges(ctx, id, lEdges, rEdges, diffEdge);
344
292
  }
345
293
  //# sourceMappingURL=diff-dataflow-graph.js.map
@@ -277,6 +277,11 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
277
277
  */
278
278
  isRoot(id: NodeId): boolean;
279
279
  rootIds(): ReadonlySet<NodeId>;
280
+ /**
281
+ * Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
282
+ * An edge with no type is no edge: every removal has to go through here so none is left behind.
283
+ */
284
+ removeEdgeType(fromId: NodeId, toId: NodeId, type: EdgeType | number): this;
280
285
  /**
281
286
  * Adds a new vertex to the graph, for ease of use, some arguments are optional and filled automatically.
282
287
  * @param vertex - The vertex to add
@@ -328,6 +328,33 @@ class DataflowGraph {
328
328
  rootIds() {
329
329
  return this.rootVertices;
330
330
  }
331
+ /**
332
+ * Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
333
+ * An edge with no type is no edge: every removal has to go through here so none is left behind.
334
+ */
335
+ removeEdgeType(fromId, toId, type) {
336
+ const from = node_id_1.NodeId.normalize(fromId), to = node_id_1.NodeId.normalize(toId);
337
+ const targets = this.edgeInformation.get(from);
338
+ const edge = targets?.get(to);
339
+ if (edge === undefined || targets === undefined) {
340
+ return this;
341
+ }
342
+ edge.types &= ~type;
343
+ if (edge.types !== 0) {
344
+ /* the reverse index holds this very object, so a narrowed type is already visible through it */
345
+ return this;
346
+ }
347
+ targets.delete(to);
348
+ if (targets.size === 0) {
349
+ this.edgeInformation.delete(from);
350
+ }
351
+ const into = this.incomingIndex?.get(to);
352
+ into?.delete(from);
353
+ if (into?.size === 0) {
354
+ this.incomingIndex?.delete(to);
355
+ }
356
+ return this;
357
+ }
331
358
  /**
332
359
  * Adds a new vertex to the graph, for ease of use, some arguments are optional and filled automatically.
333
360
  * @param vertex - The vertex to add
@@ -81,6 +81,20 @@ export declare function getAllFunctionCallTargets(call: NodeId, graph: DataflowG
81
81
  * To know what fdefs the definition of `x` in the first line links to, you can use {@link getAllLinkedFunctionDefinitions|this function}.
82
82
  */
83
83
  export declare function getAllLinkedFunctionDefinitions(functionDefinitionReadIds: ReadonlySet<NodeId>, dataflowGraph: DataflowGraph): [Set<Required<DataflowGraphVertexFunctionDefinition>>, Set<BuiltIn>];
84
+ /**
85
+ * This method links a set of read variables to definitions in an environment.
86
+ * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
87
+ * @param environmentInformation - The environment information to link against
88
+ * @param givenInputs - The existing list of inputs that might be extended
89
+ * @param graph - The graph to enter the found links
90
+ * @param maybeForRemaining - Each input that can not be linked, will be added to `givenInputs`. If this flag is `true`, it will be marked as `maybe`.
91
+ * @returns the given inputs, possibly extended with the remaining inputs (those of `referencesToLinkAgainstEnvironment` that could not be linked against the environment)
92
+ */
93
+ /**
94
+ * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
95
+ * hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
96
+ */
97
+ export declare function linkExpressionIn<Info>(this: void, graph: DataflowGraph, expr: NodeId, environment: REnvironmentInformation, idMap: AstIdMap<Info & ParentInformation>): readonly IdentifierReference[];
84
98
  /**
85
99
  * This method links a set of read variables to definitions in an environment.
86
100
  * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
@@ -110,3 +124,12 @@ export declare function linkCircularRedefinitionsWithinALoop(graph: DataflowGrap
110
124
  * Reapplies the loop exit points' control dependencies to the given identifier references.
111
125
  */
112
126
  export declare function reapplyLoopExitPoints(exits: readonly ExitPoint[], references: readonly IdentifierReference[], graph: DataflowGraph): void;
127
+ /** The open references a function definition still carries into its closure. */
128
+ export declare const ClosureRefs: {
129
+ readonly name: "ClosureRefs";
130
+ /**
131
+ * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
132
+ * links what resolves, and leaves only the references that stay open.
133
+ */
134
+ readonly resolveOpenIngoing: (this: void, graph: DataflowGraph, callId: NodeId, definition: DataflowGraphVertexFunctionDefinition, environment: REnvironmentInformation) => void;
135
+ };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClosureRefs = void 0;
3
4
  exports.findNonLocalReads = findNonLocalReads;
4
5
  exports.produceNameSharedIdMap = produceNameSharedIdMap;
5
6
  exports.linkArgumentsOnCall = linkArgumentsOnCall;
@@ -8,17 +9,19 @@ exports.linkFunctionCallWithSingleTarget = linkFunctionCallWithSingleTarget;
8
9
  exports.linkFunctionCalls = linkFunctionCalls;
9
10
  exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
10
11
  exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
12
+ exports.linkExpressionIn = linkExpressionIn;
11
13
  exports.linkInputs = linkInputs;
12
14
  exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
13
15
  exports.reapplyLoopExitPoints = reapplyLoopExitPoints;
14
16
  const defaultmap_1 = require("../../util/collections/defaultmap");
17
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
18
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
15
19
  const assert_1 = require("../../util/assert");
16
20
  const log_1 = require("../../util/log");
17
21
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
18
22
  const identifier_1 = require("../environments/identifier");
19
23
  const graph_1 = require("../graph/graph");
20
24
  const logger_1 = require("../logger");
21
- const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
22
25
  const edge_1 = require("../graph/edge");
23
26
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
24
27
  const vertex_1 = require("../graph/vertex");
@@ -366,6 +369,40 @@ function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGrap
366
369
  }
367
370
  return [result, builtIns];
368
371
  }
372
+ /**
373
+ * This method links a set of read variables to definitions in an environment.
374
+ * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
375
+ * @param environmentInformation - The environment information to link against
376
+ * @param givenInputs - The existing list of inputs that might be extended
377
+ * @param graph - The graph to enter the found links
378
+ * @param maybeForRemaining - Each input that can not be linked, will be added to `givenInputs`. If this flag is `true`, it will be marked as `maybe`.
379
+ * @returns the given inputs, possibly extended with the remaining inputs (those of `referencesToLinkAgainstEnvironment` that could not be linked against the environment)
380
+ */
381
+ /**
382
+ * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
383
+ * hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
384
+ */
385
+ function linkExpressionIn(graph, expr, environment, idMap) {
386
+ const node = idMap.get(expr);
387
+ if (node === undefined) {
388
+ return [];
389
+ }
390
+ const references = [];
391
+ const callees = new Set();
392
+ model_1.RNode.visitAst(node, inner => {
393
+ if (r_function_call_1.RFunctionCall.isNamed(inner)) {
394
+ callees.add(inner.functionName.info.id);
395
+ references.push({ nodeId: inner.functionName.info.id, name: inner.functionName.content, cds: undefined, type: identifier_1.ReferenceType.Function });
396
+ }
397
+ else if (inner.type === type_1.RType.Symbol && !callees.has(inner.info.id)) {
398
+ references.push({ nodeId: inner.info.id, name: inner.content, cds: undefined, type: identifier_1.ReferenceType.Variable });
399
+ }
400
+ return false;
401
+ });
402
+ const unresolved = [];
403
+ linkInputs(references, environment, unresolved, graph, false);
404
+ return unresolved;
405
+ }
369
406
  /**
370
407
  * This method links a set of read variables to definitions in an environment.
371
408
  * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
@@ -494,4 +531,36 @@ function reapplyLoopExitPoints(exits, references, graph) {
494
531
  }
495
532
  }
496
533
  }
534
+ /** The open references a function definition still carries into its closure. */
535
+ exports.ClosureRefs = {
536
+ name: 'ClosureRefs',
537
+ /**
538
+ * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
539
+ * links what resolves, and leaves only the references that stay open.
540
+ */
541
+ resolveOpenIngoing(graph, callId, definition, environment) {
542
+ const remainingIn = [];
543
+ for (const ingoing of definition.subflow.in) {
544
+ const resolved = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, environment, ingoing.type) : undefined;
545
+ if (resolved === undefined) {
546
+ remainingIn.push(ingoing);
547
+ continue;
548
+ }
549
+ (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Found ${resolved.length} references to open ref ${ingoing.nodeId} in closure of function definition ${callId}`);
550
+ let allBuiltIn = true;
551
+ const inId = ingoing.nodeId;
552
+ for (const { nodeId, type } of resolved) {
553
+ graph.addEdge(inId, nodeId, edge_1.EdgeType.Reads);
554
+ graph.addEdge(callId, nodeId, edge_1.EdgeType.Reads); // because the def. is the anonymous call
555
+ if (!(0, identifier_1.isReferenceType)(type, identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.BuiltInFunction)) {
556
+ allBuiltIn = false;
557
+ }
558
+ }
559
+ if (allBuiltIn) {
560
+ remainingIn.push(ingoing);
561
+ }
562
+ }
563
+ definition.subflow.in = remainingIn;
564
+ }
565
+ };
497
566
  //# sourceMappingURL=linker.js.map
@@ -15,6 +15,7 @@ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-
15
15
  const unpack_argument_1 = require("../argument/unpack-argument");
16
16
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
17
17
  const built_in_stack_env_1 = require("./built-in-stack-env");
18
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
18
19
  function tableAssignmentProcessor(name, args, rootId, data, outInfo) {
19
20
  outInfo.definitionRootNodes.push(rootId);
20
21
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.TableAssignment }).information;
@@ -69,7 +70,9 @@ function processAccess(name, args, rootId, data, config) {
69
70
  if (envState) {
70
71
  const fieldNode = (0, unpack_argument_1.unpackArg)(args[1]);
71
72
  const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : (config.treatIndicesAsString ? fieldNode?.lexeme : undefined);
72
- const fieldDefs = fieldName ? envState.current.memory.get(fieldName) : undefined;
73
+ const fieldDefs = fieldName
74
+ ? ((0, built_in_stack_env_1.stackEnvInheritsFields)(head.value) ? (0, resolve_by_name_1.resolveByName)(fieldName, envState, identifier_1.ReferenceType.Unknown) : envState.current.memory.get(fieldName))
75
+ : undefined;
73
76
  for (const fd of fieldDefs ?? []) {
74
77
  info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Reads);
75
78
  if (stackEnvState === undefined && fd.type === identifier_1.ReferenceType.Function) {
@@ -30,6 +30,8 @@ export interface BuiltInApplyConfiguration extends MergeableRecord {
30
30
  readonly resolveInEnvironment?: 'global' | 'local';
31
31
  /** Should the value of the function be resolved? */
32
32
  readonly resolveValue?: boolean;
33
+ /** the call reaches beyond what we can see even when the callee resolves, like `rlang::exec` */
34
+ readonly hasUnknownSideEffects?: boolean;
33
35
  }
34
36
  /**
35
37
  * Process an apply call like `vapply` or `mapply`.
@@ -10,10 +10,9 @@ const vertex_1 = require("../../../../../graph/vertex");
10
10
  const edge_1 = require("../../../../../graph/edge");
11
11
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
- const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
14
13
  const unnamed_call_handling_1 = require("../unnamed-call-handling");
15
- const log_1 = require("../../../../../../util/log");
16
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
14
+ const linker_1 = require("../../../../linker");
15
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
17
16
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
18
17
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
19
18
  /** Resolve the function an argument stands for: a string literal, a symbol, or an inline definition; `undefined` if none. */
@@ -28,7 +27,7 @@ function resolveFunctionArgument(val, data, opts) {
28
27
  return undefined;
29
28
  }
30
29
  const functionName = opts.resolveValue
31
- ? (0, alias_tracking_1.resolveIdToSingleString)(val.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx })
30
+ ? node_value_1.NodeValue.singleStringOf(val.info.id, data)
32
31
  : val.content;
33
32
  return functionName === undefined ? undefined : { functionId: val.info.id, functionName, anonymous: false, asString: false };
34
33
  }
@@ -36,7 +35,7 @@ function resolveFunctionArgument(val, data, opts) {
36
35
  * Process an apply call like `vapply` or `mapply`.
37
36
  */
38
37
  function processApply(name, args, rootId, data, config) {
39
- const { indexOfFunction = 1, nameOfFunctionArgument, unquoteFunction, resolveInEnvironment, resolveValue } = config;
38
+ const { indexOfFunction = 1, nameOfFunctionArgument, unquoteFunction, resolveInEnvironment, resolveValue, hasUnknownSideEffects } = config;
40
39
  /* as the length is one-based and the argument filter mapping is zero-based, we do not have to subtract 1 */
41
40
  const forceArgsMask = new Array(indexOfFunction).fill(false);
42
41
  forceArgsMask.push(true);
@@ -44,6 +43,9 @@ function processApply(name, args, rootId, data, config) {
44
43
  name, args, rootId, data, forceArgs: forceArgsMask, origin: built_in_proc_name_1.BuiltInProcName.Apply
45
44
  });
46
45
  let information = resFn.information;
46
+ if (hasUnknownSideEffects) {
47
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
48
+ }
47
49
  const processedArguments = resFn.processedArguments;
48
50
  let index = indexOfFunction;
49
51
  /* search, if one of the arguments actually contains the argument name if given in the config */
@@ -132,30 +134,7 @@ function processApply(name, args, rootId, data, config) {
132
134
  };
133
135
  const dfVert = information.graph.getVertex(rootId);
134
136
  if (dfVert && dfVert.tag === vertex_1.VertexType.FunctionDefinition) {
135
- // resolve all ingoings against the environment
136
- const ingoingRefs = dfVert.subflow.in;
137
- const remainingIn = [];
138
- for (const ingoing of ingoingRefs) {
139
- const resolved = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, data.environment, ingoing.type) : undefined;
140
- if (resolved === undefined) {
141
- remainingIn.push(ingoing);
142
- continue;
143
- }
144
- (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Found ${resolved.length} references to open ref ${ingoing.nodeId} in closure of function definition ${rootId}`);
145
- let allBuiltIn = true;
146
- const inId = ingoing.nodeId;
147
- for (const { nodeId, type } of resolved) {
148
- information.graph.addEdge(inId, nodeId, edge_1.EdgeType.Reads);
149
- information.graph.addEdge(rootId, nodeId, edge_1.EdgeType.Reads); // because the def. is the anonymous call
150
- if (!(0, identifier_1.isReferenceType)(type, identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.BuiltInFunction)) {
151
- allBuiltIn = false;
152
- }
153
- }
154
- if (allBuiltIn) {
155
- remainingIn.push(ingoing);
156
- }
157
- }
158
- dfVert.subflow.in = remainingIn;
137
+ linker_1.ClosureRefs.resolveOpenIngoing(information.graph, rootId, dfVert, data.environment);
159
138
  }
160
139
  }
161
140
  else {
@@ -5,6 +5,9 @@ exports.processAssignment = processAssignment;
5
5
  exports.processDefineArgument = processDefineArgument;
6
6
  exports.markAsAssignment = markAsAssignment;
7
7
  const known_call_handling_1 = require("../known-call-handling");
8
+ const nse_1 = require("../nse");
9
+ const data_masking_functions_1 = require("../../../../../environments/data-masking-functions");
10
+ const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
8
11
  const log_1 = require("../../../../../../util/log");
9
12
  const unpack_argument_1 = require("../argument/unpack-argument");
10
13
  const process_named_call_1 = require("../../../process-named-call");
@@ -95,6 +98,37 @@ args, rootId, data, config) {
95
98
  }
96
99
  return processAssignment(name, args, rootId, data, { ...config, mayHaveMoreArgs: true });
97
100
  }
101
+ /** Within a data-masking call `a := b` is rlang's name-value pair, not data.table's assignment. */
102
+ function isMaskedNamePair(name, rootId, data) {
103
+ if (identifier_1.Identifier.getName(name.content) !== ':=') {
104
+ return false;
105
+ }
106
+ const idMap = data.completeAst.idMap;
107
+ let parent = idMap.get(rootId)?.info.parent;
108
+ while (parent !== undefined) {
109
+ const node = idMap.get(parent);
110
+ if (node === undefined) {
111
+ return false;
112
+ }
113
+ else if (r_argument_1.RArgument.is(node)) {
114
+ parent = node.info.parent;
115
+ }
116
+ else {
117
+ return r_function_call_1.RFunctionCall.isNamed(node) && data_masking_functions_1.DataMaskingFunctionNames.has(identifier_1.Identifier.getName(node.functionName.content));
118
+ }
119
+ }
120
+ return false;
121
+ }
122
+ /** Analyzes `a := b` as the named argument it is. */
123
+ function processMaskedNamePair(name, args, rootId, data) {
124
+ const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' });
125
+ const target = args[0];
126
+ (0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.First, {
127
+ kind: known_call_handling_1.NseKind.DataMasked,
128
+ evaluated: nse_1.Nse.unquoted(target === r_function_call_1.EmptyArgument ? undefined : target?.value, nse_1.Unquote.Rlang)
129
+ });
130
+ return information;
131
+ }
98
132
  /**
99
133
  * Processes an assignment, i.e., `<target> <- <source>`.
100
134
  * Handling it as a function call \`&lt;-\` `(<target>, <source>)`.
@@ -103,6 +137,9 @@ args, rootId, data, config) {
103
137
  function processAssignment(name,
104
138
  /* we expect them to be ordered in the sense that we have (source, target): `<source> <- <target>` */
105
139
  args, rootId, data, config) {
140
+ if (isMaskedNamePair(name, rootId, data)) {
141
+ return processMaskedNamePair(name, args, rootId, data);
142
+ }
106
143
  if (!config.mayHaveMoreArgs && args.length !== 2) {
107
144
  logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has something else than 2 arguments, skipping`);
108
145
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: 'default' }).information;
@@ -416,12 +453,8 @@ function markAsAssignment(information, nodeToDefine, sourceIds, rootIdOfAssignme
416
453
  }
417
454
  information.graph.addEdge(nid, rootIdOfAssignment, edge_1.EdgeType.DefinedBy);
418
455
  // kinda dirty, but we have to remove existing read edges for the symbol, added by the child
419
- const out = information.graph.outgoingEdges(nodeToDefine.nodeId);
420
- for (const [id, edge] of (out ?? [])) {
421
- edge.types &= ~edge_1.EdgeType.Reads;
422
- if (edge.types === 0) {
423
- out?.delete(id);
424
- }
456
+ for (const [id] of [...information.graph.outgoingEdges(nodeToDefine.nodeId) ?? []]) {
457
+ information.graph.removeEdgeType(nodeToDefine.nodeId, id, edge_1.EdgeType.Reads);
425
458
  }
426
459
  }
427
460
  /**
@@ -8,6 +8,7 @@ exports.resolveEnvirArg = resolveEnvirArg;
8
8
  exports.resolveSymbolToEnvir = resolveSymbolToEnvir;
9
9
  exports.routeWrittenToCustomEnv = routeWrittenToCustomEnv;
10
10
  exports.resolveAttachPosition = resolveAttachPosition;
11
+ const r_value_1 = require("../../../../../eval/values/r-value");
11
12
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
12
13
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
13
14
  const unpack_argument_1 = require("../argument/unpack-argument");
@@ -19,8 +20,8 @@ const environment_1 = require("../../../../../environments/environment");
19
20
  const prefix_1 = require("../../../../../../util/prefix");
20
21
  const built_in_stack_env_1 = require("./built-in-stack-env");
21
22
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
23
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
22
24
  const resolve_strings_1 = require("../../../../../eval/resolve/resolve-strings");
23
- const general_1 = require("../../../../../eval/values/general");
24
25
  const logger_1 = require("../../../../../logger");
25
26
  /** A tracked env is a real stack environment (not a private custom env) when its current layer is the global or the built-in/base env. */
26
27
  function isStackEnvState(envState) {
@@ -73,7 +74,7 @@ function signatureParamNames(data, id, fallback) {
73
74
  }
74
75
  /** The constant string a name-position node denotes at construction time (string literal, aliased variable, or a paste-like join of such); `undefined` if any part is dynamic or the paste builtin is user-shadowed. */
75
76
  function resolveConstantString(node, data) {
76
- const info = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx, full: true };
77
+ const info = node_value_1.NodeValue.infoOf(data);
77
78
  const unshadowed = new Map();
78
79
  const fold = (n) => {
79
80
  if (!r_function_call_1.RFunctionCall.isNamed(n)) {
@@ -155,19 +156,6 @@ function routeWrittenToCustomEnv(result, envDef, newDefAt, definedAt) {
155
156
  function clampAttachPosition(pos) {
156
157
  return Number.isFinite(pos) ? Math.max(environment_1.DefaultAttachPosition, Math.trunc(pos)) : undefined;
157
158
  }
158
- /** The number a value denotes, directly or as the single point of an interval (how a numeric literal resolves). */
159
- function scalarNumber(value) {
160
- if (value.type === 'number') {
161
- return 'num' in value.value ? value.value.num : undefined;
162
- }
163
- if (value.type === 'interval' && value.startInclusive && value.endInclusive
164
- && value.start.type === 'number' && 'num' in value.start.value
165
- && value.end.type === 'number' && 'num' in value.end.value
166
- && value.start.value.num === value.end.value.num) {
167
- return value.start.value.num;
168
- }
169
- return undefined;
170
- }
171
159
  /**
172
160
  * The `search()` position the `pos` argument of a `library()` call requests, either given as a number or as the name of
173
161
  * an existing entry (`pos = "package:base"`). Returns `undefined` when there is no such argument, its value is unknown
@@ -178,19 +166,19 @@ function resolveAttachPosition(posId, data) {
178
166
  if (posId === undefined) {
179
167
  return undefined;
180
168
  }
181
- const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(posId, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
182
- if (values?.type !== 'set' || values.elements.length !== 1) {
169
+ const element = node_value_1.NodeValue.soleOf(posId, data);
170
+ if (element === undefined) {
183
171
  return undefined;
184
172
  }
185
- const element = values.elements[0];
186
- const asNumber = scalarNumber(element);
173
+ const asNumber = r_value_1.RValue.numberOf(element);
187
174
  if (asNumber !== undefined) {
188
175
  return clampAttachPosition(asNumber);
189
176
  }
190
- if (element.type === 'string' && 'str' in element.value) {
191
- const found = environment_1.REnvironment.searchPosition(data.environment.current, element.value.str);
177
+ const asString = r_value_1.RValue.stringOf(element);
178
+ if (asString !== undefined) {
179
+ const found = environment_1.REnvironment.searchPosition(data.environment.current, asString);
192
180
  if (found === undefined) {
193
- logger_1.dataflowLogger.warn(`search-path entry '${element.value.str}' does not exist, attaching at the default position`);
181
+ logger_1.dataflowLogger.warn(`search-path entry '${asString}' does not exist, attaching at the default position`);
194
182
  return undefined;
195
183
  }
196
184
  return clampAttachPosition(found);