@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.
Files changed (112) hide show
  1. package/README.md +34 -25
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/benchmark/slicer.d.ts +0 -1
  5. package/benchmark/slicer.js +1 -2
  6. package/cli/repl/commands/repl-signature.js +12 -3
  7. package/config.d.ts +5 -1
  8. package/control-flow/cfg-properties.js +0 -22
  9. package/control-flow/happens-before.d.ts +2 -2
  10. package/control-flow/happens-before.js +29 -19
  11. package/dataflow/environments/apply-kill.js +6 -2
  12. package/dataflow/environments/built-in-config.d.ts +2 -0
  13. package/dataflow/environments/built-in-props.d.ts +7 -1
  14. package/dataflow/environments/built-in-props.js +8 -1
  15. package/dataflow/environments/built-in.d.ts +7 -2
  16. package/dataflow/environments/built-in.js +11 -5
  17. package/dataflow/environments/default-builtin-config.d.ts +386 -8
  18. package/dataflow/environments/default-builtin-config.js +84 -22
  19. package/dataflow/environments/define.d.ts +3 -2
  20. package/dataflow/environments/define.js +4 -3
  21. package/dataflow/environments/deprecation-info.d.ts +45 -0
  22. package/dataflow/environments/deprecation-info.js +13 -0
  23. package/dataflow/environments/environment.d.ts +1 -1
  24. package/dataflow/environments/environment.js +5 -4
  25. package/dataflow/environments/identifier.d.ts +2 -0
  26. package/dataflow/extractor.js +6 -1
  27. package/dataflow/fn/class-declaration.d.ts +0 -11
  28. package/dataflow/fn/class-declaration.js +0 -20
  29. package/dataflow/fn/higher-order-function.d.ts +9 -1
  30. package/dataflow/fn/higher-order-function.js +14 -7
  31. package/dataflow/fn/strict-function.js +8 -3
  32. package/dataflow/graph/graph.d.ts +7 -0
  33. package/dataflow/graph/graph.js +17 -0
  34. package/dataflow/graph/vertex.d.ts +1 -1
  35. package/dataflow/internal/linker.d.ts +3 -0
  36. package/dataflow/internal/linker.js +67 -6
  37. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +113 -0
  38. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +506 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +9 -0
  40. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +22 -19
  42. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  43. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  44. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  45. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -2
  46. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +4 -3
  48. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +19 -3
  49. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +7 -3
  50. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +4 -2
  52. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +3 -5
  53. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -1
  54. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +8 -0
  55. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -0
  56. package/dataflow/internal/process/functions/call/common.d.ts +3 -1
  57. package/dataflow/internal/process/functions/call/common.js +22 -4
  58. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -0
  59. package/dataflow/internal/process/functions/call/deferred.js +33 -12
  60. package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
  61. package/dataflow/internal/process/functions/call/named-call-handling.js +15 -0
  62. package/dataflow/internal/process/functions/call/quoted.js +137 -24
  63. package/dataflow/internal/process/process-symbol.js +6 -2
  64. package/documentation/data/faq/faqs.js +3 -3
  65. package/documentation/data/interface/doc-writing-code.js +1 -2
  66. package/documentation/data/server/doc-data-server-messages.js +7 -7
  67. package/documentation/doc-capabilities.js +80 -34
  68. package/documentation/doc-util/doc-query.d.ts +0 -3
  69. package/documentation/doc-util/doc-query.js +4 -3
  70. package/documentation/wiki-analyzer.js +1 -1
  71. package/documentation/wiki-cfg.js +5 -6
  72. package/documentation/wiki-core.js +8 -8
  73. package/documentation/wiki-dataflow-graph.js +10 -11
  74. package/documentation/wiki-interface.js +2 -2
  75. package/documentation/wiki-linting-and-testing.js +3 -3
  76. package/documentation/wiki-overview.js +6 -6
  77. package/documentation/wiki-query.js +9 -101
  78. package/documentation/wiki-signature-database.js +1 -1
  79. package/linter/linter-rules.d.ts +1 -1
  80. package/linter/rules/deprecated-functions.d.ts +1 -45
  81. package/linter/rules/deprecated-functions.js +24 -33
  82. package/package.json +1 -1
  83. package/project/flowr-analyzer.d.ts +2 -0
  84. package/project/flowr-analyzer.js +24 -1
  85. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  86. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  87. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  88. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +6 -4
  89. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  90. package/project/sigdb/build.js +4 -0
  91. package/project/sigdb/manifest.d.ts +2 -0
  92. package/project/sigdb/manifest.js +10 -1
  93. package/project/sigdb/reader.js +23 -61
  94. package/project/sigdb/sigdb-download.d.ts +29 -6
  95. package/project/sigdb/sigdb-download.js +212 -64
  96. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  97. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  98. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  99. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  100. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  101. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  102. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  103. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  104. package/queries/query.d.ts +1 -1
  105. package/r-bridge/data/data.d.ts +21 -14
  106. package/r-bridge/data/data.js +28 -20
  107. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  108. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  109. package/util/files.d.ts +2 -0
  110. package/util/files.js +3 -1
  111. package/util/mermaid/mermaid.js +6 -2
  112. package/util/version.js +2 -2
@@ -9,8 +9,8 @@ const retriever_1 = require("../../../../../r-bridge/retriever");
9
9
  const edge_1 = require("../../../../graph/edge");
10
10
  const vertex_1 = require("../../../../graph/vertex");
11
11
  const happens_before_1 = require("../../../../../control-flow/happens-before");
12
- const logic_1 = require("../../../../../util/logic");
13
12
  const r_symbol_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
13
+ const linker_1 = require("../../../linker");
14
14
  /** Drops the read of `target` from `use`, for a binding another write has replaced. */
15
15
  function dropRead(graph, use, target) {
16
16
  graph.removeEdgeType(use, target, edge_1.EdgeType.Reads);
@@ -35,6 +35,10 @@ function namesWithin(expr, graph, idMap) {
35
35
  model_1.RNode.visitAst(node, inner => {
36
36
  if (r_function_call_1.RFunctionCall.isNamed(inner)) {
37
37
  callees.add(inner.functionName.info.id);
38
+ /* a call reads the function it names, so `evalq(f())` needs the definition of `f` */
39
+ if (vertex_1.DfgVertex.isFunctionCall(graph.getVertex(inner.info.id))) {
40
+ names.push([inner.info.id, identifier_1.Identifier.getName(inner.functionName.content), false]);
41
+ }
38
42
  return false;
39
43
  }
40
44
  else if (!r_symbol_1.RSymbol.is(inner) || callees.has(inner.info.id)) {
@@ -86,9 +90,8 @@ exports.Deferred = {
86
90
  if (reads.length < 2) {
87
91
  return reads;
88
92
  }
89
- /* `Always` implies reachable, so only the reads met walking back need the exact check */
90
93
  const readSet = new Set(reads);
91
- return reads.filter(r => !(0, happens_before_1.someReachableTo)(cfg, r, previous => readSet.has(previous) && (0, happens_before_1.happensBefore)(cfg, previous, r) === logic_1.Ternary.Always));
94
+ return reads.filter(r => !(0, happens_before_1.someAlwaysBefore)(cfg, readSet, r));
92
95
  },
93
96
  /**
94
97
  * Links the writes an expression performs to the uses that may observe them, for a call evaluating the
@@ -124,14 +127,25 @@ exports.Deferred = {
124
127
  const within = namesWithin(expr, graph, idMap);
125
128
  const own = new Set(within.map(([id]) => id));
126
129
  /* one walk per direction answers every candidate, so the sets are built once and only when asked for */
127
- let before;
128
- let after;
130
+ const reach = forces?.reach ?? {};
129
131
  /* a binding matters only if some force can see it, and a use only if some force can reach it */
130
132
  const seenByAForce = (definition) => forces === undefined
131
- || (before ??= (0, happens_before_1.reachableTo)(forces.cfg, forces.sites)).has(definition);
133
+ || (reach.before ??= (0, happens_before_1.reachableTo)(forces.cfg, forces.sites)).has(definition);
132
134
  /* the forcing read yields the promise's value, so only reads after it observe what the promise wrote */
133
135
  const reachedByAForce = (use) => forces === undefined
134
- || (!forces.sites.includes(use) && (after ??= (0, happens_before_1.reachableFrom)(forces.cfg, forces.sites)).has(use));
136
+ || (!forces.sites.includes(use) && (reach.after ??= (0, happens_before_1.reachableFrom)(forces.cfg, forces.sites)).has(use));
137
+ /* whether some force always happens before `use`, asked again by every write of the bound name */
138
+ let sites;
139
+ const alwaysAfterAForce = (use) => {
140
+ const known = (reach.always ??= new Map()).get(use);
141
+ if (known !== undefined || forces === undefined) {
142
+ return known ?? false;
143
+ }
144
+ /* one walk back from the use answers it for all sites, a use is never a site itself (see `reachedByAForce`) */
145
+ const always = (0, happens_before_1.someAlwaysBefore)(forces.cfg, sites ??= new Set(forces.sites), use);
146
+ reach.always.set(use, always);
147
+ return always;
148
+ };
135
149
  /* `delayedAssign` names its variable with a string literal, so the recovered name still carries quotes */
136
150
  const bindingName = forces === undefined ? undefined : (0, retriever_1.removeRQuotes)(node_id_1.NodeId.recoverName(forces.binding, idMap) ?? '');
137
151
  for (const [node, name, writes] of within) {
@@ -141,17 +155,24 @@ exports.Deferred = {
141
155
  for (const use of index.uses.get(name) ?? []) {
142
156
  if (!own.has(use) && reachedByAForce(use)) {
143
157
  graph.addEdge(use, node, edge_1.EdgeType.Reads);
144
- if (shadows && forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, site, use) === logic_1.Ternary.Always)) {
158
+ /* the write only happens because a force runs it */
159
+ for (const site of forces?.sites ?? []) {
160
+ graph.addEdge(node, site, edge_1.EdgeType.Reads);
161
+ }
162
+ if (shadows && alwaysAfterAForce(use)) {
145
163
  dropRead(graph, use, forces.binding);
146
164
  }
147
165
  }
148
166
  }
149
167
  }
150
168
  else {
151
- for (const definition of index.definitions.get(name) ?? []) {
152
- if (seenByAForce(definition)) {
153
- graph.addEdge(node, definition, edge_1.EdgeType.Reads);
154
- }
169
+ const seen = (index.definitions.get(name) ?? []).filter(seenByAForce);
170
+ for (const definition of seen) {
171
+ graph.addEdge(node, definition, edge_1.EdgeType.Reads);
172
+ }
173
+ if (forces !== undefined) {
174
+ /* a deferred call runs what its name holds at the force, which may be defined after the call was written */
175
+ (0, linker_1.linkCallToDefinitions)(graph, node, seen, idMap);
155
176
  }
156
177
  }
157
178
  }
@@ -100,7 +100,7 @@ function processKnownFunctionCall({ name, args, rootId, data, reverseOrder = fal
100
100
  const functionCallName = name.content;
101
101
  const processArgs = reverseOrder ? args.toReversed() : args;
102
102
  const forced = function_semantics_1.FunctionSemantics.call.signature.forced(sig, processArgs.length);
103
- const { finalEnv, callArgs, remainingReadInArgs, processedArguments } = (0, common_1.processAllArguments)({ functionName, args: processArgs, data, finalGraph, functionRootId: rootId, patchData, forced, nonFunction });
103
+ const { finalEnv, callArgs, remainingReadInArgs, processedArguments } = (0, common_1.processAllArguments)({ functionName, args: processArgs, data, finalGraph, functionRootId: rootId, patchData, forced, nonFunction, alternativesFrom: reverseOrder ? undefined : alternativeArgsFrom });
104
104
  markArgumentsAsNonStandardEvaluation(finalGraph, rootId, processedArguments, markAsNSE, { kind: NseKind.Reevaluated });
105
105
  const onlyBuiltin = data.builtInNoEnv === rootId;
106
106
  finalGraph.addVertex({
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.markAsOnlyBuiltIn = markAsOnlyBuiltIn;
4
4
  exports.processNamedCall = processNamedCall;
5
+ const built_in_ambient_state_1 = require("./built-in/built-in-ambient-state");
5
6
  const function_semantics_1 = require("../../../../fn/function-semantics");
6
7
  const info_1 = require("../../../../info");
7
8
  const known_call_handling_1 = require("./known-call-handling");
@@ -86,6 +87,9 @@ function processNamedCall(name, callArguments, rootId, data) {
86
87
  let builtIn = false;
87
88
  /* a set, because an export and the built-in behind it are two ways to the same definition */
88
89
  const toRun = new Set();
90
+ /* within a function, a call may still resolve to a user function where the function is called, so only the top
91
+ level knows an unresolved call goes to a function we cannot see */
92
+ let unknownBody = resolved.length === 0 && data.environment.level === 0;
89
93
  for (const resolvedFunction of resolved) {
90
94
  const isBuiltIn = resolvedFunction.type === identifier_1.ReferenceType.BuiltInFunction && typeof resolvedFunction.processor === 'function';
91
95
  /* the call goes through the attached export, so it is not built-in only, but flowR's own
@@ -93,13 +97,20 @@ function processNamedCall(name, callArguments, rootId, data) {
93
97
  const own = isBuiltIn ? resolvedFunction : builtInBehindExport(data, resolvedFunction);
94
98
  if (own === undefined) {
95
99
  defaultProcessor = true;
100
+ /* a user function's body states what it reads itself */
101
+ unknownBody ||= (0, built_in_ambient_state_1.hidesBody)(resolvedFunction);
96
102
  continue;
97
103
  }
98
104
  builtIn ||= isBuiltIn && own.config?.libFn !== true;
99
105
  toRun.add(own);
100
106
  }
107
+ /* flowR models what a package function does with its arguments, but not which of its options it reads */
108
+ let packageFn = false;
101
109
  for (const own of toRun) {
102
110
  information = mergeInformation(information, own.processor(name, args, rootId, data));
111
+ const pkg = own.name === undefined ? undefined : identifier_1.Identifier.getNamespace(own.name);
112
+ /* unless flowR states how it accesses the state, as for `withr::with_options` */
113
+ packageFn ||= pkg !== undefined && !(own.config !== undefined && ('ambient' in own.config || 'scope' in own.config)) && !(0, r_base_packages_1.isBaseRPackage)(String(pkg));
103
114
  }
104
115
  if (defaultProcessor) {
105
116
  /* if we do not know where we land, we force! reuse `resolved`, data.environment did not change above */
@@ -110,6 +121,10 @@ function processNamedCall(name, callArguments, rootId, data) {
110
121
  // mark the function call as built in only
111
122
  markAsOnlyBuiltIn(information.graph, rootId, keepEnvironment);
112
123
  }
124
+ /* a function whose body we do not see may read any option or draw on the device */
125
+ if (information !== undefined && (unknownBody || packageFn)) {
126
+ information = (0, built_in_ambient_state_1.readsAllAmbientState)(information, rootId, data, unknownBody);
127
+ }
113
128
  // on demand: materialize the built-in vertex for any package export this call resolves to and, when we
114
129
  // already know the loading call here, link to it (a function-local export is invisible to the later
115
130
  // top-level linkMaterializedExportsToLoaders pass, so we must catch it at the call site)
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Quoted = void 0;
4
4
  const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
5
+ const match_args_1 = require("../../../../graph/match-args");
5
6
  const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
6
7
  const identifier_1 = require("../../../../environments/identifier");
8
+ const resolve_helper_1 = require("../../../../environments/resolve-helper");
9
+ const r_symbol_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
7
10
  const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
8
11
  const edge_1 = require("../../../../graph/edge");
9
12
  const df_helper_1 = require("../../../../graph/df-helper");
@@ -15,7 +18,6 @@ const deferred_1 = require("./deferred");
15
18
  const r_argument_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
16
19
  const retriever_1 = require("../../../../../r-bridge/retriever");
17
20
  const happens_before_1 = require("../../../../../control-flow/happens-before");
18
- const logic_1 = require("../../../../../util/logic");
19
21
  const query_fn_props_1 = require("../../../../environments/query-fn-props");
20
22
  const built_in_props_1 = require("../../../../environments/built-in-props");
21
23
  /** Calls capturing a language object. */
@@ -24,6 +26,7 @@ const CapturingProcessors = [built_in_proc_name_1.BuiltInProcName.Quote];
24
26
  const CapturingCalls = new Set(['expression']);
25
27
  /** Calls capturing an expression as a promise, forced at some later read of the variable they bind. */
26
28
  const DelayingCalls = new Set(['delayedAssign']);
29
+ const DelayedAssignFormals = ['x', 'value', 'eval.env', 'assign.env'];
27
30
  /** Calls evaluating one. */
28
31
  const EvaluatingProcessors = [built_in_proc_name_1.BuiltInProcName.Eval];
29
32
  /** Calls evaluating their own unevaluated argument, in a frame of their own. */
@@ -80,6 +83,8 @@ exports.Quoted = {
80
83
  * forced against, and a masked name the caller binds after all loses its mark.
81
84
  */
82
85
  finalize(graph, environment, idMap, controlFlow) {
86
+ /* lets the forces of a parameter be reused without counting its reads again while nothing touched them (see `forcesOf`) */
87
+ graph.trackIncomingReads(true);
83
88
  let names = undefined;
84
89
  let bindings = undefined;
85
90
  let cfg = null;
@@ -88,6 +93,20 @@ exports.Quoted = {
88
93
  let sideEffects = undefined;
89
94
  const sideEffectsOnce = () => sideEffects ??= callsWithSideEffects(graph);
90
95
  let installers = undefined;
96
+ /* every call of a function forces its parameters at the same sites, so this pass works them out once */
97
+ const forcing = new Map();
98
+ /* evaluations within one function and forces of one parameter share their sites, and with them what reaches them */
99
+ const reaches = new Map();
100
+ let enclosing;
101
+ const reachOf = (sites) => {
102
+ const key = sites.join('\0');
103
+ let reach = reaches.get(key);
104
+ if (reach === undefined) {
105
+ reach = {};
106
+ reaches.set(key, reach);
107
+ }
108
+ return reach;
109
+ };
91
110
  const installersOnce = () => installers ??= languageInstallersOf(graph, environment);
92
111
  for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
93
112
  const masks = nse_1.Nse.dropResolvedMask(graph, id, vertex.name);
@@ -106,16 +125,25 @@ exports.Quoted = {
106
125
  names ??= deferred_1.Deferred.indexOf(graph, idMap);
107
126
  const flow = binding === undefined ? undefined : cfgOnce();
108
127
  const sites = flow === undefined || binding === undefined ? undefined : deferred_1.Deferred.forcedAt(graph, binding, flow);
109
- deferred_1.Deferred.link(graph, promise, names, idMap, flow !== undefined && sites?.length && binding !== undefined ? { cfg: flow, sites, binding } : undefined);
128
+ /* the promise runs in `eval.env`, so whatever that environment holds may be what it reads */
129
+ const call = idMap.get(id);
130
+ const evalEnv = r_function_call_1.RFunctionCall.is(call) ? match_args_1.MatchArgs.toNames(call.arguments, DelayedAssignFormals).get('eval.env')?.value : undefined;
131
+ const tracked = trackedEnvOf(vertex, evalEnv);
132
+ /* a tracked `eval.env` that binds every name the promise reads leaves no other binding in play, its writes still reach later reads */
133
+ const bound = tracked !== undefined && exports.Quoted.evaluateIn(graph, promise, tracked, idMap).length === 0;
134
+ deferred_1.Deferred.link(graph, promise, bound ? { definitions: new Map(), uses: names.uses } : names, idMap, flow !== undefined && sites?.length && binding !== undefined ? { cfg: flow, sites, binding } : undefined);
110
135
  if (binding !== undefined) {
111
136
  linkForcesToPromise(graph, binding, promise);
112
137
  }
138
+ if (evalEnv !== undefined) {
139
+ graph.addEdge(promise, evalEnv.info.id, edge_1.EdgeType.Reads);
140
+ }
113
141
  }
114
142
  }
115
143
  else if (hasOrigin(vertex, EvaluatingProcessors) || EvaluatingElsewhereCalls.has(identifier_1.Identifier.getName(vertex.name))) {
116
144
  names ??= deferred_1.Deferred.indexOf(graph, idMap);
117
145
  bindings ??= bindingsOf(graph, idMap);
118
- resolveEvaluation(graph, vertex, idMap, names, bindings, cfgOnce());
146
+ resolveEvaluation(graph, vertex, idMap, names, bindings, cfgOnce(), reachOf, enclosing ??= enclosingDefinitions(graph));
119
147
  }
120
148
  else {
121
149
  for (const escaped of escapingArguments(graph, id)) {
@@ -127,19 +155,43 @@ exports.Quoted = {
127
155
  if (flow !== undefined) {
128
156
  for (const [argument, parameter] of forcedParameters(graph, id)) {
129
157
  names ??= deferred_1.Deferred.indexOf(graph, idMap);
130
- const sites = deferred_1.Deferred.forcedAt(graph, parameter, flow);
131
- if (sites.length > 0) {
132
- deferred_1.Deferred.link(graph, argument, names, idMap, { cfg: flow, sites, binding: parameter });
158
+ const forces = forcesOf(graph, parameter, flow, forcing, reachOf);
159
+ if (forces !== undefined) {
160
+ deferred_1.Deferred.link(graph, argument, names, idMap, forces);
133
161
  }
134
162
  }
135
163
  }
136
164
  }
137
165
  }
138
166
  }
167
+ graph.trackIncomingReads(false);
139
168
  /* only once every mark has settled: the read a column gets makes it look bound from here on */
140
169
  nse_1.Nse.linkMasksToData(graph, masking);
141
170
  }
142
171
  };
172
+ /** Where `parameter` is forced, shared by all calls handing it an argument; only reused while its reads are unchanged. */
173
+ function forcesOf(graph, parameter, cfg, forcing, reachOf) {
174
+ const version = graph.incomingReadsVersion(parameter);
175
+ const known = forcing.get(parameter);
176
+ if (known?.version === version) {
177
+ return known.forces;
178
+ }
179
+ /* counting is only needed once something touched the reads, and the same count still means the same forces */
180
+ let reads = 0;
181
+ for (const [, edge] of graph.edgesTo(parameter)) {
182
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
183
+ reads++;
184
+ }
185
+ }
186
+ if (known?.reads === reads) {
187
+ forcing.set(parameter, { ...known, version });
188
+ return known.forces;
189
+ }
190
+ const sites = deferred_1.Deferred.forcedAt(graph, parameter, cfg);
191
+ const forces = sites.length > 0 ? { cfg, sites, binding: parameter, reach: reachOf(sites) } : undefined;
192
+ forcing.set(parameter, { version, reads, forces });
193
+ return forces;
194
+ }
143
195
  /** The name a delaying call binds, which is the definition its reads have to go through. */
144
196
  function boundBy(graph, id) {
145
197
  for (const [target, edge] of graph.edgesTo(id)) {
@@ -157,6 +209,12 @@ function linkForcesToPromise(graph, binding, promise) {
157
209
  }
158
210
  }
159
211
  }
212
+ /** The tracked custom environment `evalEnv` names, if it is a single one. */
213
+ function trackedEnvOf(call, evalEnv) {
214
+ const defs = r_symbol_1.RSymbol.is(evalEnv) && call.environment !== undefined ? resolve_helper_1.Resolve.byNameAndType(evalEnv.content, call.environment, identifier_1.ReferenceType.Variable) : undefined;
215
+ const env = defs?.length === 1 && (0, identifier_1.hasEnvState)(defs[0]) ? defs[0].envState : undefined;
216
+ return env?.current.globalEnv || env?.current.builtInEnv ? undefined : env;
217
+ }
160
218
  function* installedLanguageOf(graph, id, installers) {
161
219
  for (const [definition, edge] of graph.edgesFrom(id)) {
162
220
  if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) || !vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(definition))) {
@@ -185,7 +243,7 @@ function languageInstallersOf(graph, environment) {
185
243
  const installers = new Set();
186
244
  for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
187
245
  if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Replacement)
188
- && (((0, query_fn_props_1.callFnProps)(id, { graph, environment })?.props ?? 0) & built_in_props_1.CallProp.Lang) !== 0) {
246
+ && built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.CallProp.Lang)) {
189
247
  installers.add(id);
190
248
  }
191
249
  }
@@ -227,40 +285,56 @@ function bindingsOf(graph, idMap) {
227
285
  * Where the evaluation happens: the call itself, or, for one inside a closure, every call of that closure (those
228
286
  * are the points whose bindings the evaluation sees). `undefined` if a nesting closure is never seen called.
229
287
  */
230
- function evaluationSites(graph, id) {
288
+ function evaluationSites(graph, id, enclosing) {
231
289
  const sites = [];
232
- let nested = false;
233
- for (const [definition, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
234
- if (!vertex.subflow.graph.has(id)) {
235
- continue;
236
- }
237
- nested = true;
290
+ const definitions = enclosing.get(id) ?? [];
291
+ for (const definition of definitions) {
238
292
  for (const [caller, edge] of graph.edgesTo(definition)) {
239
293
  if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
240
294
  sites.push(caller);
241
295
  }
242
296
  }
243
297
  }
244
- if (!nested) {
298
+ if (definitions.length === 0) {
245
299
  return [id];
246
300
  }
247
301
  return sites.length > 0 ? sites : undefined;
248
302
  }
249
- /** Whether some point the evaluation may run at can be reached with `definition` in effect. */
250
- function mayReach(sites, definition, cfg) {
251
- return cfg === undefined || sites === undefined || sites.some(site => (0, happens_before_1.happensBefore)(cfg, definition, site) !== logic_1.Ternary.Never);
303
+ /** the function definitions each vertex sits in, built once per pass instead of searching them for every evaluation */
304
+ function enclosingDefinitions(graph) {
305
+ const enclosing = new Map();
306
+ for (const [definition, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
307
+ for (const id of vertex.subflow.graph) {
308
+ const known = enclosing.get(id);
309
+ if (known === undefined) {
310
+ enclosing.set(id, [definition]);
311
+ }
312
+ else {
313
+ known.push(definition);
314
+ }
315
+ }
316
+ }
317
+ return enclosing;
318
+ }
319
+ /** Whether some point the evaluation may run at is reached with a definition in effect; the same for every definition, so walked once. */
320
+ function mayReachFrom(sites, cfg, reach) {
321
+ if (cfg === undefined || sites === undefined) {
322
+ return () => true;
323
+ }
324
+ return definition => (reach.before ??= (0, happens_before_1.reachableTo)(cfg, sites)).has(definition);
252
325
  }
253
326
  /**
254
327
  * The names the frames we know do not bind: a capture forced inside a closure may see bindings the caller made
255
328
  * after the closure was written, so every reachable definition of the name stays a candidate.
256
329
  */
257
- function linkAgainstAnyBinding(graph, open, bindings, sites, cfg) {
330
+ function linkAgainstAnyBinding(graph, open, bindings, sites, cfg, reach) {
331
+ const mayReach = mayReachFrom(sites, cfg, reach);
258
332
  for (const reference of open) {
259
333
  if (reference.name === undefined) {
260
334
  continue;
261
335
  }
262
336
  for (const definition of bindings.get(identifier_1.Identifier.getName(reference.name)) ?? []) {
263
- if (definition !== reference.nodeId && mayReach(sites, definition, cfg)) {
337
+ if (definition !== reference.nodeId && mayReach(definition)) {
264
338
  graph.addEdge(reference.nodeId, definition, edge_1.EdgeType.Reads);
265
339
  }
266
340
  }
@@ -287,17 +361,18 @@ function* forcedParameters(graph, id) {
287
361
  }
288
362
  }
289
363
  /** Links a capture handed to an evaluating call, in that call's scope. */
290
- function resolveEvaluation(graph, call, idMap, names, bindings, cfg) {
364
+ function resolveEvaluation(graph, call, idMap, names, bindings, cfg, reachOf, enclosing) {
291
365
  const id = call.id;
292
366
  const own = EvaluatingElsewhereCalls.has(identifier_1.Identifier.getName(call.name));
293
367
  const sources = own ? capturedArgumentsOf(graph, id, true).map(expr => ({ expr, at: id })) : sourcesHandedTo(graph, call, idMap);
294
368
  const environment = call.environment;
295
369
  /* a frame of its own says nothing about the bindings here, so every one of them stays possible */
296
370
  const elsewhere = own || environment === undefined || evaluatesElsewhere(idMap.get(id));
297
- const sites = sources.length > 0 ? evaluationSites(graph, id) : undefined;
371
+ const sites = sources.length > 0 ? evaluationSites(graph, id, enclosing) : undefined;
372
+ const reach = sites === undefined ? {} : reachOf(sites);
298
373
  for (const { expr, at } of sources) {
299
374
  if (elsewhere) {
300
- const forces = cfg === undefined || sites === undefined ? undefined : { cfg, sites, binding: id };
375
+ const forces = cfg === undefined || sites === undefined ? undefined : { cfg, sites, binding: id, reach };
301
376
  deferred_1.Deferred.link(graph, expr, { definitions: bindings, uses: names.uses }, idMap, forces);
302
377
  deferred_1.Deferred.publish(graph, expr, names, idMap, id, undefined);
303
378
  }
@@ -306,10 +381,12 @@ function resolveEvaluation(graph, call, idMap, names, bindings, cfg) {
306
381
  /* R falls through to the enclosing scope for names the evaluating frame does not bind */
307
382
  const enclosing = open.length > 0 ? graph.getVertex(at)?.environment : undefined;
308
383
  const unbound = enclosing === undefined ? open : (0, linker_1.linkInputs)(open, enclosing, [], graph, false);
309
- linkAgainstAnyBinding(graph, unbound, bindings, sites, cfg);
384
+ linkAgainstAnyBinding(graph, unbound, bindings, sites, cfg, reach);
310
385
  deferred_1.Deferred.publish(graph, expr, names, idMap, id, cfg);
311
386
  }
312
387
  graph.addEdge(id, expr, edge_1.EdgeType.Returns);
388
+ /* the captured code only runs because this call evaluates it */
389
+ graph.addEdge(expr, id, edge_1.EdgeType.Reads);
313
390
  if (!elsewhere) {
314
391
  /* the capture said "not evaluated here", and being handed to `eval` settles that it is */
315
392
  nse_1.Nse.unmark(graph, at);
@@ -318,6 +395,42 @@ function resolveEvaluation(graph, call, idMap, names, bindings, cfg) {
318
395
  if (sources.length > 0 && !elsewhere) {
319
396
  forgetUnknownSideEffect(graph, id);
320
397
  }
398
+ if (sources.length > 0 && environment !== undefined && !sources.some(({ expr }) => mayConfigure(graph, expr, environment))) {
399
+ forgetStateWrites(graph, id);
400
+ }
401
+ }
402
+ /** Whether evaluating `expr` may change the options or graphics state: a call states {@link CallProp.Configures} or is opaque. */
403
+ function mayConfigure(graph, expr, environment) {
404
+ const seen = new Set();
405
+ const todo = [expr];
406
+ while (todo.length > 0) {
407
+ const id = todo.pop();
408
+ if (seen.has(id) || node_id_1.NodeId.isBuiltIn(id)) {
409
+ continue;
410
+ }
411
+ seen.add(id);
412
+ const vertex = graph.getVertex(id);
413
+ if (vertex_1.DfgVertex.isFunctionCall(vertex)) {
414
+ const builtIn = Array.isArray(vertex.origin) && vertex.origin.every(o => String(o).startsWith('builtin:') && o !== built_in_proc_name_1.BuiltInProcName.Function && o !== built_in_proc_name_1.BuiltInProcName.Eval);
415
+ if (!builtIn || built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.CallProp.Configures)) {
416
+ return true;
417
+ }
418
+ }
419
+ for (const [target, edge] of graph.edgesFrom(id)) {
420
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument | edge_1.EdgeType.Returns) || (vertex_1.DfgVertex.isUse(vertex) && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads))) {
421
+ todo.push(target);
422
+ }
423
+ }
424
+ }
425
+ return false;
426
+ }
427
+ /** An evaluation is assumed to write the options and graphics state until we know what it evaluates (see `evaluatesCapturedCode`); a captured call then no longer needs the evaluation either, `eval(quote(x <- 1))` slices to `x <- 1`. */
428
+ function forgetStateWrites(graph, id) {
429
+ for (const [from, edge] of graph.edgesTo(id)) {
430
+ if (edge_1.DfEdge.isOnlyType(edge, edge_1.EdgeType.Reads) && vertex_1.DfgVertex.isFunctionCall(graph.getVertex(from))) {
431
+ graph.removeEdgeType(from, id, edge_1.EdgeType.Reads);
432
+ }
433
+ }
321
434
  }
322
435
  /** The captures the first argument of an evaluating call may carry. */
323
436
  function sourcesHandedTo(graph, call, idMap) {
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSymbol = processSymbol;
4
+ const identifier_1 = require("../../environments/identifier");
4
5
  const process_value_1 = require("./process-value");
5
6
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
6
7
  const graph_1 = require("../../graph/graph");
7
8
  const vertex_1 = require("../../graph/vertex");
8
- const identifier_1 = require("../../environments/identifier");
9
+ const built_in_ambient_state_1 = require("./functions/call/built-in/built-in-ambient-state");
9
10
  /**
10
11
  * Process a symbol node in the AST for dataflow analysis.
11
12
  * If the symbol is `NULL` or `NA`, it is processed as a value.
@@ -16,8 +17,11 @@ function processSymbol(symbol, data) {
16
17
  return (0, process_value_1.processValue)(symbol, data);
17
18
  }
18
19
  const sid = symbol.info.id;
20
+ const read = { nodeId: sid, name: symbol.content, cds: data.cds, type: identifier_1.ReferenceType.Unknown };
19
21
  return {
20
- unknownReferences: [{ nodeId: sid, name: symbol.content, cds: data.cds, type: identifier_1.ReferenceType.Unknown }],
22
+ unknownReferences: identifier_1.Identifier.getName(symbol.content) === '.Options'
23
+ ? [read, ...(0, built_in_ambient_state_1.readsOfOptionsVariable)(symbol, data)]
24
+ : [read],
21
25
  in: [],
22
26
  out: [],
23
27
  environment: data.environment,
@@ -79,7 +79,7 @@ To add a new linting rule, see ${ctx.linkPage('wiki/Create Linting Rules')}.
79
79
  .addFaq('Where do I find *all the helper objects*?', `
80
80
  flowR stores its data as plain values and puts the behavior beside it in a helper object named after the
81
81
  thing it is about (${ctx.link({ name: 'SourceLocation' }, undefined, { type: 'variable' })},
82
- ${ctx.link({ name: 'Vertex' }, undefined, { type: 'variable' })},
82
+ ${ctx.link({ name: 'DfgVertex' }, undefined, { type: 'variable' })},
83
83
  ${ctx.link({ name: 'Identifier' }, undefined, { type: 'variable' })}, ...).
84
84
  The ${ctx.linkPage('wiki/Helper Objects', 'Helper Objects')} wiki page lists every one of them, grouped by what
85
85
  it is about, so you can find the one that answers your question without knowing where it lives.
@@ -120,12 +120,12 @@ sections in the output of \`sessionInfo()\`.
120
120
  .addFaq('How to get *documentation* for a function or package?', `
121
121
  There are a couple of ways to get documentation for a function or package.
122
122
 
123
- 🖥️ Firstly, if you have already installed the package the function originated from you can simply run \`?<package name>::<function name>\` in an R session to print the
123
+ 🖥️ Firstly, if you have already installed the package the function originated from you can run \`?<package name>::<function name>\` in an R session to print the
124
124
  relevant documentation. If you don't know the origin of the package, you can use
125
125
  \`??<function name>\` in an R shell to fuzzy find all documentations containing
126
126
  \`<function name>\` or something similar.
127
127
 
128
- 🌐 Secondly, if you don't have or don't want to install the package you can simply google the fully qualified name of the function. Good sources include [rdrr.io](https://rdrr.io/)
128
+ 🌐 Secondly, if you don't have or don't want to install the package you can google the fully qualified name of the function. Good sources include [rdrr.io](https://rdrr.io/)
129
129
  or [rdocumentation.org](https://rdocumentation.org/). Additionally, the package documentation PDF can also
130
130
  be downloaded directly from [cran](https://cran.r-project.org/).
131
131
  `)
@@ -20,7 +20,6 @@ async function staticSliceExample() {
20
20
  criteria: ['3@x']
21
21
  }
22
22
  ]);
23
- //console.log(result['static-slice']);
24
23
  return result;
25
24
  }
26
25
  /**
@@ -86,7 +85,7 @@ Each ${ctx.link(shell_1.RShell)} controls a new instance of the R&nbsp;interpret
86
85
  make sure to call ${(0, doc_code_1.codeInline)(ctx.linkM(shell_1.RShell, 'close', { codeFont: false, realNameWrapper: 'i' }) + '()')} when you are done.`
87
86
  })}
88
87
 
89
- You can start a new "session" simply by constructing a new object with ${(0, doc_code_1.codeInline)('new ' + ctx.link(shell_1.RShell, { codeFont: false }) + '()')}.
88
+ You can start a new "session" by constructing a new object with ${(0, doc_code_1.codeInline)('new ' + ctx.link(shell_1.RShell, { codeFont: false }) + '()')}.
90
89
 
91
90
  However, there are several options that may be of interest
92
91
  (e.g., to automatically revive the shell in case of errors or to control the name location of the R process on the system).
@@ -35,7 +35,7 @@ function documentAllServerMessages(ctx) {
35
35
  text: async (shell) => {
36
36
  return `
37
37
 
38
- After launching _flowR_, for example, with <code>docker run -it --rm ${doc_docker_1.DockerName} ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'server', false, false)}</code>&nbsp;(🐳️), simply connecting should present you with a \`${message_hello_1.helloMessageDefinition.type}\` message, that amongst others should reveal the versions of&nbsp;_flowR_ and&nbsp;R, using the [semver 2.0](https://semver.org/spec/v2.0.0.html) versioning scheme.
38
+ After launching _flowR_, for example, with <code>docker run -it --rm ${doc_docker_1.DockerName} ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'server', false, false)}</code>&nbsp;(🐳️), connecting should present you with a \`${message_hello_1.helloMessageDefinition.type}\` message, that amongst others should reveal the versions of&nbsp;_flowR_ and&nbsp;R, using the [semver 2.0](https://semver.org/spec/v2.0.0.html) versioning scheme.
39
39
  The message looks like this:
40
40
 
41
41
  ${(0, doc_code_1.codeBlock)('json', await (0, doc_server_message_1.inServerContext)(shell, socket => {
@@ -203,7 +203,7 @@ ${await (0, doc_server_message_1.documentServerMessageResponse)({
203
203
  type: 'response',
204
204
  expectedType: 'response-file-analysis',
205
205
  description: `
206
- Please note, that the base message format is still JSON. Only the individual results get converted.
206
+ The base message format is still JSON, only the individual results get converted.
207
207
  While the context is derived from the \`filename\`, we currently offer no way to customize other parts of the quads
208
208
  (please open a [new issue](${doc_issue_1.NewIssueUrl}) if you require this).
209
209
 
@@ -214,7 +214,7 @@ While the context is derived from the \`filename\`, we currently offer no way to
214
214
  <a id="analysis-format-compact"></a>
215
215
  **Retrieve the Output in a Compacted Form**
216
216
 
217
- The default response is formatted as JSON. But this can get very big quickly.
217
+ The default JSON response can get very big quickly.
218
218
  By specifying \`format: "compact"\`, you can retrieve the results heavily compacted (using [lz-string](https://www.npmjs.com/package/lz-string)).
219
219
  This works with and without the control flow graph as described [above](#analysis-include-cfg).
220
220
 
@@ -236,7 +236,7 @@ ${await (0, doc_server_message_1.documentServerMessageResponse)({
236
236
  type: 'response',
237
237
  expectedType: 'response-file-analysis',
238
238
  description: `
239
- Please note, that the base message format is still JSON. Only the individual results are printed as binary objects.
239
+ The base message format is still JSON, only the individual results are printed as binary objects.
240
240
  `
241
241
  }]
242
242
  })}
@@ -267,7 +267,7 @@ Please note, that the base message format is still JSON. Only the individual res
267
267
 
268
268
  To slice, you have to send a file analysis request first. The \`filetoken\` you assign is of use here as you can re-use it to repeatedly slice the same file.
269
269
  Besides that, you only need to add an array of slicing criteria, using one of the formats described on the [terminology wiki page](${doc_files_1.FlowrWikiBaseRef}/Terminology#slicing-criterion)
270
- (however, instead of using \`;\`, you can simply pass separate array elements).
270
+ (however, instead of using \`;\`, you can pass separate array elements).
271
271
  See the implementation of the request-slice message for more information.
272
272
 
273
273
  Additionally, you may pass \`"noMagicComments": true\` to disable the automatic selection of elements based on magic comments (see below).
@@ -292,7 +292,7 @@ See [above](#message-request-file-analysis) for the general structure of the res
292
292
  `
293
293
  }, {
294
294
  type: 'request',
295
- description: 'Of course, the second slice criterion `2:1` is redundant for the input, as they refer to the same variable. It is only for demonstration purposes.',
295
+ description: 'The second slice criterion `2:1` is redundant for the input, as they refer to the same variable. It is only for demonstration purposes.',
296
296
  message: {
297
297
  type: 'request-slice',
298
298
  id: '2',
@@ -368,7 +368,7 @@ Furthermore, you can set the \`ansi\` field to \`true\` if you are interested in
368
368
  We strongly recommend you to make use of the \`id\` field to link answers with requests as you can theoretically request the execution of multiple scripts at the same time, which then happens in parallel.
369
369
 
370
370
  > [!WARNING]
371
- > There is currently no automatic sandboxing or safeguarding against such requests. They simply execute the respective&nbsp;R code on your machine.
371
+ > There is currently no automatic sandboxing or safeguarding against such requests. They execute the respective&nbsp;R code on your machine.
372
372
  > Please be very careful (and do not use ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'r-session-access')} if you are unsure).
373
373
 
374
374