@eagleoutice/flowr 2.13.2 → 2.13.4

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 (146) hide show
  1. package/README.md +45 -43
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/access-mapper.js +1 -0
  4. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  5. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +1 -1
  6. package/abstract-interpretation/data-frame/mappers/function-mapper.js +3 -0
  7. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  8. package/abstract-interpretation/domains/state-domain-like.d.ts +1 -1
  9. package/abstract-interpretation/unsupported-functions.js +1 -1
  10. package/config.d.ts +8 -0
  11. package/config.js +9 -1
  12. package/control-flow/cfg-dead-code.js +72 -11
  13. package/control-flow/control-flow-graph.js +2 -1
  14. package/control-flow/extract-cfg.js +85 -8
  15. package/control-flow/semantic-cfg-guided-visitor.d.ts +1 -1
  16. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  17. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +1 -1
  18. package/dataflow/environments/append.d.ts +1 -1
  19. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  20. package/dataflow/environments/built-in-proc-name.js +4 -0
  21. package/dataflow/environments/built-in.d.ts +5 -1
  22. package/dataflow/environments/built-in.js +5 -1
  23. package/dataflow/environments/clone.d.ts +1 -1
  24. package/dataflow/environments/default-builtin-config.d.ts +59 -4
  25. package/dataflow/environments/default-builtin-config.js +23 -11
  26. package/dataflow/environments/environment.d.ts +28 -4
  27. package/dataflow/environments/environment.js +66 -11
  28. package/dataflow/environments/identifier.d.ts +1 -0
  29. package/dataflow/environments/overwrite.d.ts +1 -1
  30. package/dataflow/eval/resolve/alias-tracking.d.ts +3 -1
  31. package/dataflow/eval/resolve/alias-tracking.js +8 -1
  32. package/dataflow/eval/resolve/resolve.d.ts +14 -0
  33. package/dataflow/eval/resolve/resolve.js +47 -0
  34. package/dataflow/fn/higher-order-function.js +3 -3
  35. package/dataflow/fn/recursive-function.js +1 -1
  36. package/dataflow/graph/dataflowgraph-builder.d.ts +1 -1
  37. package/dataflow/graph/df-helper.js +1 -1
  38. package/dataflow/graph/vertex.d.ts +32 -25
  39. package/dataflow/graph/vertex.js +40 -36
  40. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  42. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  44. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -1
  45. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  46. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +1 -1
  47. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  48. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  49. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +14 -1
  50. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +80 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +63 -3
  53. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +1 -1
  54. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  55. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  56. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +5 -2
  57. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +15 -9
  58. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +4 -0
  59. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  60. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  61. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +1 -1
  62. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  63. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +1 -1
  64. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-dispatch.d.ts +1 -1
  65. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +55 -2
  67. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -1
  68. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +5 -3
  69. package/dataflow/internal/process/functions/call/built-in/built-in-vector.d.ts +1 -1
  70. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  71. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  72. package/documentation/doc-readme.js +14 -12
  73. package/documentation/doc-util/doc-normalized-ast.d.ts +1 -1
  74. package/documentation/wiki-dataflow-graph.js +4 -24
  75. package/documentation/wiki-query.js +47 -0
  76. package/documentation/wiki-signature-database.js +3 -2
  77. package/linter/rules/absolute-path.js +1 -1
  78. package/linter/rules/dataframe-access-validation.d.ts +1 -1
  79. package/linter/rules/function-finder-util.js +1 -1
  80. package/linter/rules/no-leaked-credentials.js +1 -1
  81. package/linter/rules/undefined-symbol-util.js +3 -1
  82. package/linter/rules/undefined-symbol.js +4 -5
  83. package/linter/rules/unused-definition.js +15 -10
  84. package/linter/rules/useless-loop.js +1 -1
  85. package/package.json +21 -9
  86. package/project/context/flowr-analyzer-context.d.ts +4 -4
  87. package/project/context/flowr-analyzer-context.js +3 -3
  88. package/project/context/flowr-analyzer-dependencies-context.d.ts +11 -5
  89. package/project/context/flowr-analyzer-dependencies-context.js +8 -3
  90. package/project/context/flowr-analyzer-meta-context.d.ts +1 -0
  91. package/project/dependency-version-space.d.ts +118 -26
  92. package/project/dependency-version-space.js +343 -87
  93. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +4 -0
  94. package/project/plugins/file-plugins/files/flowr-description-file.js +8 -1
  95. package/project/plugins/file-plugins/files/flowr-rda-file.js +27 -25
  96. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +1 -1
  97. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +1 -1
  98. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -1
  99. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -1
  100. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -4
  101. package/project/plugins/package-version-plugins/package.d.ts +27 -10
  102. package/project/plugins/package-version-plugins/package.js +50 -25
  103. package/project/sigdb/reader.d.ts +26 -16
  104. package/project/sigdb/reader.js +52 -21
  105. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  106. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  107. package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
  108. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +2 -2
  109. package/queries/catalog/dependencies-query/dependencies-query-format.js +2 -2
  110. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  111. package/queries/catalog/dependencies-query/function-info/write-functions.js +23 -24
  112. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -1
  113. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +39 -77
  114. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +12 -0
  115. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +53 -23
  116. package/queries/catalog/input-sources-query/input-source-functions.d.ts +14 -0
  117. package/queries/catalog/input-sources-query/input-source-functions.js +109 -20
  118. package/queries/catalog/input-sources-query/input-sources-query-executor.js +45 -4
  119. package/queries/catalog/input-sources-query/input-sources-query-format.js +22 -3
  120. package/queries/catalog/input-sources-query/input-types.d.ts +58 -0
  121. package/queries/catalog/input-sources-query/input-types.js +64 -0
  122. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +76 -53
  123. package/queries/catalog/input-sources-query/simple-input-classifier.js +358 -101
  124. package/queries/catalog/project-query/project-query-executor.js +1 -1
  125. package/queries/catalog/signature-query/signature-query-executor.d.ts +7 -1
  126. package/queries/catalog/signature-query/signature-query-executor.js +112 -39
  127. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -1
  128. package/queries/catalog/signature-query/signature-query-format.js +1 -1
  129. package/queries/catalog/signature-query/signature-query-render.js +8 -3
  130. package/r-bridge/data/data.d.ts +2 -2
  131. package/r-bridge/data/data.js +2 -2
  132. package/r-bridge/lang-4.x/ast/parser/json/format.js +1 -1
  133. package/r-bridge/retriever.d.ts +1 -1
  134. package/reconstruct/inline/source-inline-map.js +1 -1
  135. package/search/flowr-search-printer.js +10 -8
  136. package/slicing/static/static-slicer.d.ts +2 -2
  137. package/util/mermaid/dfg.js +1 -1
  138. package/util/objects.js +6 -4
  139. package/util/r-base-packages.d.ts +2 -0
  140. package/util/r-base-packages.js +3 -0
  141. package/util/r-license.js +1 -4
  142. package/util/r-version.d.ts +12 -0
  143. package/util/r-version.js +16 -0
  144. package/util/range.d.ts +6 -2
  145. package/util/range.js +33 -15
  146. package/util/version.js +1 -1
@@ -42,6 +42,7 @@ function processFunctionDefinition(name, args, rootId, data) {
42
42
  data = prepareFunctionEnvironment(data, rootId);
43
43
  const subgraph = new graph_1.DataflowGraph(data.completeAst.idMap);
44
44
  let readInParameters = [];
45
+ const allParameterReads = [];
45
46
  const paramIds = [];
46
47
  for (const param of parameters) {
47
48
  (0, assert_1.guard)(param !== r_function_call_1.EmptyArgument, () => `Empty param arg in function definition ${identifier_1.Identifier.toString(name.content)}, ${JSON.stringify(args)}`);
@@ -51,6 +52,7 @@ function processFunctionDefinition(name, args, rootId, data) {
51
52
  }
52
53
  subgraph.mergeWith(processed.graph);
53
54
  const read = processed.in.concat(processed.unknownReferences);
55
+ allParameterReads.push(...read);
54
56
  (0, linker_1.linkInputs)(read, data.environment, readInParameters, subgraph, false);
55
57
  data.environment = (0, overwrite_1.overwriteEnvironment)(data.environment, processed.environment);
56
58
  }
@@ -95,7 +97,15 @@ function processFunctionDefinition(name, args, rootId, data) {
95
97
  // As we know, parameters cannot technically duplicate (i.e., their names are unique), we overwrite their environments.
96
98
  // This is the correct behavior, even if someone uses non-`=` arguments in functions.
97
99
  const bodyEnvironment = body.environment;
98
- readInParameters = findPromiseLinkagesForParameters(subgraph, readInParameters, paramsEnvironments, body);
100
+ // a default read (e.g. `function(x, y = x)`) may also see a later body reassignment, as the default is a promise
101
+ const writesByName = groupBodyWrites(body.out);
102
+ const unresolvedParamReads = new Set(readInParameters);
103
+ for (const read of allParameterReads) {
104
+ if (read.name && !unresolvedParamReads.has(read)) {
105
+ linkParameterReadToBodyWrites(subgraph, read, writesByName);
106
+ }
107
+ }
108
+ readInParameters = findPromiseLinkagesForParameters(subgraph, readInParameters, paramsEnvironments, writesByName);
99
109
  const readInBody = body.in.concat(body.unknownReferences);
100
110
  // there is no uncertainty regarding the arguments, as if a function header is executed, so is its body
101
111
  const remainingRead = (0, linker_1.linkInputs)(readInBody, paramsEnvironments, readInParameters.slice(), body.graph, true /* functions do not have to be called */);
@@ -115,7 +125,7 @@ function processFunctionDefinition(name, args, rootId, data) {
115
125
  (0, linker_1.linkCircularRedefinitionsWithinALoop)(body.graph, nameIdShares, globalBodyOut);
116
126
  }
117
127
  subgraph.mergeWith(body.graph);
118
- const outEnvironment = (0, overwrite_1.overwriteEnvironment)(paramsEnvironments, bodyEnvironment);
128
+ let outEnvironment = (0, overwrite_1.overwriteEnvironment)(paramsEnvironments, bodyEnvironment);
119
129
  for (const read of remainingRead) {
120
130
  if (read.name) {
121
131
  subgraph.addVertex({
@@ -128,6 +138,18 @@ function processFunctionDefinition(name, args, rootId, data) {
128
138
  }
129
139
  const compactedHooks = (0, hooks_1.compactHookStates)(body.hooks);
130
140
  const exitHooks = (0, hooks_1.getHookInformation)(compactedHooks, hooks_1.KnownHooks.OnFnExit);
141
+ // an on.exit hook's `<<-` escapes like a body `<<-`; fold its escaping writes into this function's subflow
142
+ for (const hook of exitHooks) {
143
+ const vert = subgraph.getVertex(hook.id);
144
+ if (vert?.tag !== vertex_1.VertexType.FunctionDefinition) {
145
+ continue;
146
+ }
147
+ let hookEnvironment = vert.subflow.environment;
148
+ while (hookEnvironment.level > outEnvironment.level) {
149
+ hookEnvironment = (0, scoping_1.popLocalEnvironment)(hookEnvironment);
150
+ }
151
+ outEnvironment = (0, overwrite_1.overwriteEnvironment)(outEnvironment, hookEnvironment);
152
+ }
131
153
  const flow = {
132
154
  unknownReferences: [],
133
155
  in: remainingRead,
@@ -175,7 +197,7 @@ function processFunctionDefinition(name, args, rootId, data) {
175
197
  if (data.ctx.config.solver.trackEnvironments) {
176
198
  for (const ep of afterHookExitPoints) {
177
199
  const epVertex = subgraph.getVertex(ep.nodeId);
178
- if ((0, vertex_1.isFunctionCallVertex)(epVertex) && epVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv)) {
200
+ if (vertex_1.FunctionCallVertex.is(epVertex) && epVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv)) {
179
201
  returnEnvState = (0, built_in_new_env_1.createFreshEnvState)(data, { graph: subgraph, entryPoint: ep.nodeId });
180
202
  break;
181
203
  }
@@ -445,7 +467,43 @@ function prepareFunctionEnvironment(data, rootId) {
445
467
  * <p>
446
468
  * <b>Currently we may be unable to narrow down every definition within the body as we have not implemented ways to track what covers the first definitions precisely</b>
447
469
  */
448
- function findPromiseLinkagesForParameters(parameters, readInParameters, parameterEnvs, body) {
470
+ /** Links a parameter default read to the body writes of the same name (may), returning whether any was linked. */
471
+ /** Groups body writes by name, each list sorted by descending id (so the lowest id is last), for `linkParameterReadToBodyWrites`. */
472
+ function groupBodyWrites(out) {
473
+ const byName = new Map();
474
+ for (const o of out) {
475
+ if (o.name === undefined) {
476
+ continue;
477
+ }
478
+ const writes = byName.get(o.name);
479
+ if (writes === undefined) {
480
+ byName.set(o.name, [o]);
481
+ }
482
+ else {
483
+ writes.push(o);
484
+ }
485
+ }
486
+ for (const writes of byName.values()) {
487
+ writes.sort((a, b) => String(a.nodeId) < String(b.nodeId) ? 1 : -1);
488
+ }
489
+ return byName;
490
+ }
491
+ function linkParameterReadToBodyWrites(graph, read, writesByName) {
492
+ const writingOuts = read.name === undefined ? undefined : writesByName.get(read.name);
493
+ if (writingOuts === undefined) {
494
+ return false;
495
+ }
496
+ if (writingOuts[0].cds === undefined) {
497
+ graph.addEdge(read.nodeId, writingOuts[0].nodeId, edge_1.EdgeType.Reads);
498
+ }
499
+ else {
500
+ for (const { nodeId } of writingOuts) {
501
+ graph.addEdge(read.nodeId, nodeId, edge_1.EdgeType.Reads);
502
+ }
503
+ }
504
+ return true;
505
+ }
506
+ function findPromiseLinkagesForParameters(parameters, readInParameters, parameterEnvs, writesByName) {
449
507
  // first, we try to bind again within parameters - if we have it, fine
450
508
  const remainingRead = [];
451
509
  for (const read of readInParameters) {
@@ -458,19 +516,8 @@ function findPromiseLinkagesForParameters(parameters, readInParameters, paramete
458
516
  continue;
459
517
  }
460
518
  // If not resolved, link all outs within the body as potential reads.
461
- // Regarding the sort, we can ignore equality as nodeIds are unique.
462
- // We sort to get the lowest id - if it is an 'always' flag, we can safely use it instead of all of them.
463
- const writingOuts = body.out.filter(o => o.name === read.name).sort((a, b) => String(a.nodeId) < String(b.nodeId) ? 1 : -1);
464
- if (writingOuts.length === 0) {
519
+ if (!linkParameterReadToBodyWrites(parameters, read, writesByName)) {
465
520
  remainingRead.push(read);
466
- continue;
467
- }
468
- if (writingOuts[0].cds === undefined) {
469
- parameters.addEdge(rid, writingOuts[0].nodeId, edge_1.EdgeType.Reads);
470
- continue;
471
- }
472
- for (const { nodeId } of writingOuts) {
473
- parameters.addEdge(rid, nodeId, edge_1.EdgeType.Reads);
474
521
  }
475
522
  }
476
523
  return remainingRead;
@@ -12,6 +12,7 @@ const edge_1 = require("../../../../../graph/edge");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
13
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
14
14
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
15
+ const range_1 = require("../../../../../../util/range");
15
16
  /**
16
17
  * Processes a built-in 'get' function call.
17
18
  *
@@ -28,17 +29,36 @@ function processGet(name, args, rootId, data) {
28
29
  const retrieve = firstArg !== undefined && firstArg !== r_function_call_1.EmptyArgument
29
30
  ? (0, unpack_argument_1.unpackNonameArg)(firstArg)
30
31
  : undefined;
31
- if (retrieve === undefined || retrieve.type !== type_1.RType.String) {
32
+ let treatTargetAsSymbol = undefined;
33
+ if (retrieve !== undefined && retrieve.type === type_1.RType.String) {
34
+ treatTargetAsSymbol = {
35
+ type: type_1.RType.Symbol,
36
+ info: retrieve.info,
37
+ content: (0, retriever_1.removeRQuotes)(retrieve.lexeme),
38
+ lexeme: retrieve.lexeme,
39
+ location: retrieve.location
40
+ };
41
+ }
42
+ else if (retrieve !== undefined) {
43
+ const resolvedName = (0, built_in_envir_utils_1.resolveConstantString)(retrieve, data);
44
+ if (resolvedName !== undefined) {
45
+ const synthId = rootId + '-get-name';
46
+ const synthSymbol = {
47
+ type: type_1.RType.Symbol,
48
+ info: { ...retrieve.info, id: synthId },
49
+ content: resolvedName,
50
+ lexeme: resolvedName,
51
+ location: retrieve.location ?? name.location ?? range_1.SourceRange.invalid()
52
+ };
53
+ data.completeAst.idMap.set(synthId, synthSymbol);
54
+ treatTargetAsSymbol = synthSymbol;
55
+ }
56
+ }
57
+ if (treatTargetAsSymbol === undefined) {
32
58
  logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has not 1 string argument, skipping`);
33
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
59
+ // dynamic, unresolvable name: reached-but-unknown rather than dropped
60
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', hasUnknownSideEffect: true }).information;
34
61
  }
35
- const treatTargetAsSymbol = {
36
- type: type_1.RType.Symbol,
37
- info: retrieve.info,
38
- content: (0, retriever_1.removeRQuotes)(retrieve.lexeme),
39
- lexeme: retrieve.lexeme,
40
- location: retrieve.location
41
- };
42
62
  /* resolve in the custom environment if one was found, else the global one.
43
63
  * Pass remaining original args (e.g. envir=e) so they appear as Use vertices in the graph. */
44
64
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
@@ -1,4 +1,4 @@
1
- import { type DataflowProcessorInformation } from '../../../../../processor';
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import type { DataflowInformation, ControlDependency } from '../../../../../info';
3
3
  import type { DataflowGraph } from '../../../../../graph/graph';
4
4
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
@@ -28,6 +28,8 @@ interface AttachSpec {
28
28
  readonly exclude?: ReadonlySet<string>;
29
29
  /** attach every export (`import::from` `.all`, `box::use(pkg[...])`) */
30
30
  readonly all?: boolean;
31
+ /** `library(pkg, pos = 3)`: the `search()` position to attach at, {@link DefaultAttachPosition} if unset */
32
+ readonly pos?: number;
31
33
  }
32
34
  /**
33
35
  * Process a library call like `library` or `require`
@@ -41,7 +43,8 @@ export declare function attachExportVertex(graph: DataflowGraph, builtInId: Node
41
43
  */
42
44
  export declare function loadNodesForNamespace(env: REnvironmentInformation, pack: string): NodeId[];
43
45
  /**
44
- * Attaches `dependency`'s exports below the global environment (see {@link attachPackageBelowGlobal}) and returns the
46
+ * Attaches `dependency`'s exports at `spec`'s {@link AttachSpec#pos|search position} (below the global environment by
47
+ * default, see {@link REnvironment.attachAt|attachPackageAt}) and returns the
45
48
  * enriched environment (the graph is untouched). Used by `library()`, `import::from`, `box::use`, `requireNamespace`,
46
49
  * and the transitive side-effect propagation.
47
50
  */
@@ -30,6 +30,7 @@ const common_1 = require("../common");
30
30
  const linker_1 = require("../../../../linker");
31
31
  const vertex_1 = require("../../../../../graph/vertex");
32
32
  const r_base_packages_1 = require("../../../../../../util/r-base-packages");
33
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
33
34
  /**
34
35
  * Process a library call like `library` or `require`
35
36
  */
@@ -42,15 +43,19 @@ function processLibrary(name, args, rootId, data, config = {}) {
42
43
  return processUse(name, args, rootId, data);
43
44
  }
44
45
  /* parse the import selection before the library flow rewrites `args` below */
45
- const spec = config.fromImports ? parseFromSpec(args) : { namespaceOnly: config.namespaceOnly };
46
+ const parsedSpec = config.fromImports ? parseFromSpec(args) : { namespaceOnly: config.namespaceOnly };
46
47
  const params = {
47
48
  'package': 'pkg',
48
- 'character.only': 'char'
49
+ 'character.only': 'char',
50
+ /* last, so the positional fallback keeps its previous order */
51
+ 'pos': 'pos'
49
52
  };
50
53
  const resolveArgs = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx };
51
54
  const argMaps = (0, linker_1.pMatch)((0, common_1.convertFnArguments)(args), params);
52
55
  const packageId = Array.from(new Set(argMaps.get('pkg')));
53
56
  const charId = Array.from(new Set(argMaps.get('char')));
57
+ /* `import::from` has no `pos`; its extra arguments name exports */
58
+ const spec = { ...parsedSpec, pos: config.fromImports ? undefined : (0, built_in_envir_utils_1.resolveAttachPosition)(argMaps.get('pos')?.[0], data) };
54
59
  let namesToLoad = packageId.map(v => r_argument_1.RArgument.getValue(args, v));
55
60
  //check if library name provided
56
61
  namesToLoad = namesToLoad.filter(v => v !== undefined && (v.type === type_1.RType.Symbol || v.type === type_1.RType.String));
@@ -160,7 +165,7 @@ function processLibrary(name, args, rootId, data, config = {}) {
160
165
  // `p::fn` can still link back to this call. requireNamespace/loadNamespace are recorded too, since
161
166
  // they equally make `p::fn` valid.
162
167
  if (info.environment.level >= 0) {
163
- info.environment = recordUnresolvedLibraryLoad(info.environment, p, rootId, data.cds);
168
+ info.environment = recordUnresolvedLibraryLoad(info.environment, p, rootId, spec.pos, data.cds);
164
169
  }
165
170
  }
166
171
  }
@@ -311,7 +316,7 @@ const libraryLoadMarker = ' library-load';
311
316
  * `definedAt` is the load call. This lets an explicit `pack::fn` link back via {@link loadNodesForNamespace}
312
317
  * even without a signature database.
313
318
  */
314
- function recordUnresolvedLibraryLoad(envInfo, pack, rootId, cds) {
319
+ function recordUnresolvedLibraryLoad(envInfo, pack, rootId, pos, cds) {
315
320
  const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, environment_1.EnvType.LoadedNamespace).define({
316
321
  name: identifier_1.Identifier.make(libraryLoadMarker, pack),
317
322
  type: identifier_1.ReferenceType.Function,
@@ -319,7 +324,7 @@ function recordUnresolvedLibraryLoad(envInfo, pack, rootId, cds) {
319
324
  definedAt: rootId,
320
325
  cds: cds?.slice()
321
326
  });
322
- return { level: envInfo.level, current: environment_1.REnvironment.attachBelowGlobal(envInfo.current, layer, layer) };
327
+ return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, pos) };
323
328
  }
324
329
  /**
325
330
  * The load calls (`library()`/`require()`) that brought package `pack` into scope without a database, collected from
@@ -382,7 +387,8 @@ function isSubsetAttach(spec) {
382
387
  return spec.include !== undefined && !spec.all;
383
388
  }
384
389
  /**
385
- * Attaches `dependency`'s exports below the global environment (see {@link attachPackageBelowGlobal}) and returns the
390
+ * Attaches `dependency`'s exports at `spec`'s {@link AttachSpec#pos|search position} (below the global environment by
391
+ * default, see {@link REnvironment.attachAt|attachPackageAt}) and returns the
386
392
  * enriched environment (the graph is untouched). Used by `library()`, `import::from`, `box::use`, `requireNamespace`,
387
393
  * and the transitive side-effect propagation.
388
394
  */
@@ -396,14 +402,14 @@ function attachDependencyToEnvironment(dependency, envInfo, ctx, spec = {}, defi
396
402
  const layerType = spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace;
397
403
  const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, layerType)
398
404
  .defineAll(exports.map(exp => exportDefinition(pack, exp, definedAt)));
399
- return { level: envInfo.level, current: environment_1.REnvironment.attachBelowGlobal(envInfo.current, layer, layer) };
405
+ return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, spec.pos) };
400
406
  }
401
407
  // full attach: imports layer at the bottom, namespace (exports) layer on top
402
408
  let importsEnv = new environment_1.Environment(envInfo.current).asLibrary(pack, environment_1.EnvType.Imports);
403
409
  importsEnv = recImports(importsEnv, dependency.namespaceInfo, ctx, new Set());
404
410
  const namespaceEnv = new environment_1.Environment(importsEnv).asLibrary(pack, environment_1.EnvType.Namespace)
405
411
  .defineAll(exports.map(exp => exportDefinition(pack, exp, definedAt)));
406
- return { level: envInfo.level, current: environment_1.REnvironment.attachBelowGlobal(envInfo.current, namespaceEnv, importsEnv) };
412
+ return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, namespaceEnv, importsEnv, spec.pos) };
407
413
  }
408
414
  /** A namespace-only load is subsumed by any layer for `pack`; a full attach ignores a mere {@link EnvType.LoadedNamespace}. */
409
415
  function blocksAttach(layer, namespaceOnly) {
@@ -513,7 +519,7 @@ function attachProjectImports(env, ctx) {
513
519
  return env;
514
520
  }
515
521
  const layer = new environment_1.Environment(env.current).asLibrary(layerNamespace, environment_1.EnvType.Imports).defineAll(toDefine);
516
- return { level: env.level, current: environment_1.REnvironment.attachBelowGlobal(env.current, layer, layer) };
522
+ return { level: env.level, current: environment_1.REnvironment.attachAt(env.current, layer, layer) };
517
523
  }
518
524
  /** attach every project-level environment layer in order: base R namespaces, the project's own `importFrom` symbols, then its declared dependencies */
519
525
  function attachProject(env, ctx) {
@@ -1,9 +1,11 @@
1
1
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2
2
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
3
+ import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
3
4
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
5
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
5
6
  import type { DataflowInformation } from '../../../../../info';
6
7
  import type { DataflowProcessorInformation } from '../../../../../processor';
8
+ import type { REnvironmentInformation } from '../../../../../environments/environment';
7
9
  /**
8
10
  * Process a list call.
9
11
  *
@@ -13,3 +15,5 @@ import type { DataflowProcessorInformation } from '../../../../../processor';
13
15
  * ```
14
16
  */
15
17
  export declare function processList<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
18
+ /** Records a `list(...)`'s named function entries as a resolvable pseudo-env, so `d$foo(...)`/`d[["foo"]](...)` link to them; `undefined` if none. */
19
+ export declare function resolveListToEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processList = processList;
4
+ exports.resolveListToEnvState = resolveListToEnvState;
5
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
4
7
  const known_call_handling_1 = require("../known-call-handling");
5
8
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
9
+ const identifier_1 = require("../../../../../environments/identifier");
10
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
11
+ const define_1 = require("../../../../../environments/define");
12
+ const scoping_1 = require("../../../../../environments/scoping");
6
13
  /**
7
14
  * Process a list call.
8
15
  *
@@ -14,4 +21,32 @@ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-
14
21
  function processList(name, args, rootId, data) {
15
22
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.List }).information;
16
23
  }
24
+ /** Records a `list(...)`'s named function entries as a resolvable pseudo-env, so `d$foo(...)`/`d[["foo"]](...)` link to them; `undefined` if none. */
25
+ function resolveListToEnvState(source, data) {
26
+ if (!r_function_call_1.RFunctionCall.isNamed(source)) {
27
+ return undefined;
28
+ }
29
+ let envState = (0, scoping_1.pushLocalEnvironment)(data.environment);
30
+ let found = false;
31
+ for (const arg of source.arguments) {
32
+ if (arg === r_function_call_1.EmptyArgument || arg.name === undefined || arg.value === undefined) {
33
+ continue;
34
+ }
35
+ const value = arg.value;
36
+ const isFn = value.type === type_1.RType.FunctionDefinition
37
+ || (value.type === type_1.RType.Symbol && ((0, resolve_by_name_1.resolveByName)(value.content, data.environment, identifier_1.ReferenceType.Function)?.length ?? 0) > 0);
38
+ if (!isFn) {
39
+ continue;
40
+ }
41
+ envState = (0, define_1.define)({
42
+ type: identifier_1.ReferenceType.Function,
43
+ name: arg.name.content,
44
+ nodeId: value.info.id,
45
+ definedAt: value.info.id,
46
+ cds: undefined
47
+ }, false, envState);
48
+ found = true;
49
+ }
50
+ return found ? envState : undefined;
51
+ }
17
52
  //# sourceMappingURL=built-in-list.js.map
@@ -28,7 +28,7 @@ function processNewEnv(name, args, rootId, data) {
28
28
  if (data.ctx.config.solver.trackEnvironments) {
29
29
  const parentState = resolveNewEnvParentArg(args, data);
30
30
  const vertex = result.graph.getVertex(rootId);
31
- if (parentState !== undefined && (0, vertex_1.isFunctionCallVertex)(vertex)) {
31
+ if (parentState !== undefined && vertex_1.FunctionCallVertex.is(vertex)) {
32
32
  vertex.newEnvParent = parentState;
33
33
  }
34
34
  }
@@ -85,7 +85,7 @@ function createIsolatedEnvState(data) {
85
85
  function createFreshEnvState(data, sourceInfo) {
86
86
  if (sourceInfo !== undefined) {
87
87
  const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
88
- if ((0, vertex_1.isFunctionCallVertex)(vertex) && vertex.newEnvParent !== undefined) {
88
+ if (vertex_1.FunctionCallVertex.is(vertex) && vertex.newEnvParent !== undefined) {
89
89
  return {
90
90
  current: new environment_1.Environment(vertex.newEnvParent.current),
91
91
  level: vertex.newEnvParent.level + 1
@@ -1,4 +1,4 @@
1
- import { type DataflowProcessorInformation } from '../../../../../processor';
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import type { DataflowInformation } from '../../../../../info';
3
3
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
4
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
@@ -47,7 +47,7 @@ function processRecall(name, args, rootId, data, config) {
47
47
  information.graph.addEdge(rootId, closure, edge_1.EdgeType.Calls);
48
48
  // also kill the name of the recall function
49
49
  const r = information.graph.getVertex(rootId);
50
- if ((0, vertex_1.isFunctionCallVertex)(r)) {
50
+ if (vertex_1.FunctionCallVertex.is(r)) {
51
51
  r.name = unnamed_call_handling_1.UnnamedFunctionCallPrefix + rootId + '-' + identifier_1.Identifier.toString(r.name);
52
52
  r.environment = information.environment;
53
53
  }
@@ -1,4 +1,4 @@
1
- import { type DataflowProcessorInformation } from '../../../../../processor';
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import type { DataflowInformation } from '../../../../../info';
3
3
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
4
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
@@ -1,7 +1,7 @@
1
1
  import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import type { DataflowInformation } from '../../../../../info';
3
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';
4
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  /** Used to separate S7 dispatch info in identifiers */
@@ -1,7 +1,7 @@
1
1
  import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import type { DataflowInformation } from '../../../../../info';
3
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';
4
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  /** e.g. new_generic(name, dispatch_args, fun=NULL) */
@@ -24,5 +24,13 @@ export declare function processS7NewGeneric<OtherInfo>(name: RSymbol<OtherInfo &
24
24
  */
25
25
  export declare function processMakeConstructor<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config?: {
26
26
  readonly mode?: readonly ('s7' | 's3' | 's4')[];
27
+ readonly wrapIndex?: number;
28
+ readonly wrapName?: string;
27
29
  }): DataflowInformation;
30
+ /**
31
+ * Node-id suffix of the `fun = function(...) S7_dispatch()` argument flowR synthesizes for S7 calls that do not
32
+ * carry one (`new_class`, `new_generic`, ...). It stands for no argument in the source, so consumers that reason
33
+ * about how the *code* calls a function (e.g. matching a call against a package's signature history) must skip it.
34
+ */
35
+ export declare const S7SyntheticFunArgSuffix = "-s7-new-generic-fun-arg";
28
36
  export {};
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.S7SyntheticFunArgSuffix = void 0;
3
4
  exports.processS7NewGeneric = processS7NewGeneric;
4
5
  exports.processMakeConstructor = processMakeConstructor;
5
6
  const known_call_handling_1 = require("../known-call-handling");
7
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
+ const built_in_apply_1 = require("./built-in-apply");
6
9
  const logger_1 = require("../../../../../logger");
7
10
  const linker_1 = require("../../../../linker");
8
11
  const common_1 = require("../common");
@@ -86,8 +89,58 @@ function processMakeConstructor(name, args, rootId, data, config) {
86
89
  if (fArg?.tag === vertex_1.VertexType.FunctionDefinition && config?.mode) {
87
90
  fArg.mode ??= config.mode.slice(); // copy: mode is mutated in place later, config.mode is shared
88
91
  }
92
+ if (config?.wrapIndex !== undefined) {
93
+ linkWrappedFunction(info, args, config.wrapIndex, config.wrapName, data);
94
+ }
89
95
  return info;
90
96
  }
97
+ /** Mark the wrapped function of an eager higher-order wrapper (`Negate`/`Vectorize`/`partial`) as called. */
98
+ function linkWrappedFunction(info, args, wrapIndex, wrapName, data) {
99
+ let wrapped = undefined;
100
+ if (wrapName !== undefined) {
101
+ wrapped = args.find(a => a !== r_function_call_1.EmptyArgument && a.name?.content === wrapName);
102
+ }
103
+ if (wrapped === undefined) {
104
+ let pos = 0;
105
+ for (const a of args) {
106
+ if (a === r_function_call_1.EmptyArgument || a.name) {
107
+ continue;
108
+ }
109
+ if (pos === wrapIndex) {
110
+ wrapped = a;
111
+ break;
112
+ }
113
+ pos++;
114
+ }
115
+ }
116
+ if (wrapped === undefined || wrapped === r_function_call_1.EmptyArgument || !wrapped.value) {
117
+ return;
118
+ }
119
+ const resolved = (0, built_in_apply_1.resolveFunctionArgument)(wrapped.value, data, {});
120
+ if (resolved === undefined || resolved.anonymous) {
121
+ return;
122
+ }
123
+ const vertex = info.graph.getVertex(resolved.functionId);
124
+ if (vertex?.tag !== vertex_1.VertexType.Use) {
125
+ return;
126
+ }
127
+ info.graph.updateToFunctionCall({
128
+ tag: vertex_1.VertexType.FunctionCall,
129
+ id: resolved.functionId,
130
+ name: resolved.functionName,
131
+ args: [],
132
+ environment: data.environment,
133
+ onlyBuiltin: false,
134
+ cds: data.cds,
135
+ origin: [built_in_proc_name_1.BuiltInProcName.Function]
136
+ });
137
+ }
138
+ /**
139
+ * Node-id suffix of the `fun = function(...) S7_dispatch()` argument flowR synthesizes for S7 calls that do not
140
+ * carry one (`new_class`, `new_generic`, ...). It stands for no argument in the source, so consumers that reason
141
+ * about how the *code* calls a function (e.g. matching a call against a package's signature history) must skip it.
142
+ */
143
+ exports.S7SyntheticFunArgSuffix = '-s7-new-generic-fun-arg';
91
144
  // 'function([dispatch_args],...) S7_dispatch()'; returns the value id
92
145
  function makeS7DispatchFDef(name, names, rootId, args, idMap) {
93
146
  const argNameId = rootId + '-s7-new-generic-fun-arg-name';
@@ -124,7 +177,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
124
177
  index: 0
125
178
  },
126
179
  location: r,
127
- content: identifier_1.Identifier.make('S7_dispatch', 's7'),
180
+ content: identifier_1.Identifier.make('S7_dispatch', 'S7'),
128
181
  };
129
182
  const funcBody = {
130
183
  type: type_1.RType.FunctionCall,
@@ -205,7 +258,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
205
258
  idMap.set(funcNameId, funcName);
206
259
  idMap.set(funcBody.info.id, funcBody);
207
260
  idMap.set(fdefId, argValue);
208
- const argId = rootId + '-s7-new-generic-fun-arg';
261
+ const argId = rootId + exports.S7SyntheticFunArgSuffix;
209
262
  const argument = {
210
263
  type: type_1.RType.Argument,
211
264
  lexeme: 'fun',
@@ -1,7 +1,7 @@
1
1
  import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import { DataflowInformation } from '../../../../../info';
3
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';
4
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  /** e.g. UseMethod(generic, object) */
@@ -57,6 +57,8 @@ function resolveNodeToStackEnv(node, data) {
57
57
  case default_builtin_config_1.StackEnvKind.Base:
58
58
  case default_builtin_config_1.StackEnvKind.Empty:
59
59
  return fixedStackEnv(kind, data);
60
+ case default_builtin_config_1.StackEnvKind.CallerFrame: // parent.frame(): the caller's frame, over-approximated to global (exact at a top-level call)
61
+ return fixedStackEnv(default_builtin_config_1.StackEnvKind.Global, data);
60
62
  case default_builtin_config_1.StackEnvKind.Current: // environment() with no argument is the current environment
61
63
  return firstArg === undefined ? { current: data.environment.current, level: data.environment.level } : undefined;
62
64
  case default_builtin_config_1.StackEnvKind.Parent: {
@@ -73,8 +75,8 @@ function asSearchPathEnv(name, data) {
73
75
  if (fixed !== undefined) {
74
76
  return fixed;
75
77
  }
76
- if (name.startsWith('package:')) {
77
- const pkg = name.slice('package:'.length);
78
+ if (name.startsWith(environment_1.SearchPathPackagePrefix)) {
79
+ const pkg = name.slice(environment_1.SearchPathPackagePrefix.length);
78
80
  for (let env = environment_1.REnvironment.findGlobal(data.environment.current).parent; env !== undefined && !env.builtInEnv; env = env.parent) {
79
81
  if (env.n === pkg && env.t === environment_1.EnvType.Namespace) {
80
82
  return { current: env, level: 0 };
@@ -86,7 +88,7 @@ function asSearchPathEnv(name, data) {
86
88
  /** If `sourceInfo`'s entry is a {@link BuiltInProcName.StackEnv} call, the stack environment it refers to; else `undefined`. */
87
89
  function stackEnvStateFromSource(sourceInfo, data) {
88
90
  const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
89
- if (!(0, vertex_1.isFunctionCallVertex)(vertex) || vertex.name === undefined || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
91
+ if (!vertex_1.FunctionCallVertex.is(vertex) || vertex.name === undefined || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
90
92
  return undefined;
91
93
  }
92
94
  return fixedStackEnv(stackEnvKind(String(vertex.name)), data);
@@ -1,4 +1,4 @@
1
- import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
1
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2
2
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
3
3
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
4
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
@@ -7,12 +7,32 @@ const common_1 = require("./common");
7
7
  const linker_1 = require("../../../linker");
8
8
  const edge_1 = require("../../../../graph/edge");
9
9
  const graph_1 = require("../../../../graph/graph");
10
+ const unknown_side_effect_1 = require("../../../../graph/unknown-side-effect");
10
11
  const vertex_1 = require("../../../../graph/vertex");
11
12
  const type_1 = require("../../../../../r-bridge/lang-4.x/ast/model/type");
12
13
  const logger_1 = require("../../../../logger");
13
14
  const identifier_1 = require("../../../../environments/identifier");
14
15
  const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
16
+ const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
15
17
  exports.UnnamedFunctionCallPrefix = 'unnamed-fc-';
18
+ /**
19
+ * Whether a `$`/`[[` access callee resolved a field to a stored function: a resolved dispatch (`dispatch$foo()`)
20
+ * carries a `Returns` edge from the access node to the field target (in addition to the base `Returns` to `accessedId`),
21
+ * while an opaque object (`g$greet()` on an untracked `g`) only carries the base `Returns`.
22
+ */
23
+ function accessResolvesToField(graph, accessId, accessedId) {
24
+ const outgoing = graph.outgoingEdges(accessId);
25
+ if (outgoing === undefined) {
26
+ return false;
27
+ }
28
+ const base = node_id_1.NodeId.normalize(accessedId);
29
+ for (const [target, edge] of outgoing) {
30
+ if (node_id_1.NodeId.normalize(target) !== base && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
31
+ return true;
32
+ }
33
+ }
34
+ return false;
35
+ }
16
36
  /**
17
37
  * Processes an unnamed function call.
18
38
  * For example `(function(x) { x + 1 })(5)`
@@ -53,6 +73,10 @@ function processUnnamedFunctionCall(functionCall, data) {
53
73
  if (functionCall.calledFunction.type === type_1.RType.FunctionDefinition) {
54
74
  (0, linker_1.linkArgumentsOnCall)(callArgs, functionCall.calledFunction.parameters, finalGraph);
55
75
  }
76
+ else if (functionCall.calledFunction.type === type_1.RType.Access && !accessResolvesToField(finalGraph, calledRootId, functionCall.calledFunction.accessed.info.id)) {
77
+ // `obj$method()` whose callee did not resolve to a stored function: reached-but-unknown rather than dropped
78
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(finalGraph, data.environment, functionRootId);
79
+ }
56
80
  // push the called function to the ids:
57
81
  inIds = inIds.concat(calledFunction.in, calledFunction.unknownReferences);
58
82
  return {