@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
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveFunctionArgument = resolveFunctionArgument;
3
4
  exports.processApply = processApply;
4
5
  const known_call_handling_1 = require("../known-call-handling");
5
6
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
@@ -7,15 +8,30 @@ const logger_1 = require("../../../../../logger");
7
8
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
8
9
  const vertex_1 = require("../../../../../graph/vertex");
9
10
  const edge_1 = require("../../../../../graph/edge");
11
+ const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
10
12
  const identifier_1 = require("../../../../../environments/identifier");
11
13
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
12
14
  const unnamed_call_handling_1 = require("../unnamed-call-handling");
13
- const general_1 = require("../../../../../eval/values/general");
14
- const r_value_1 = require("../../../../../eval/values/r-value");
15
15
  const log_1 = require("../../../../../../util/log");
16
16
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
17
17
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
18
18
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
19
+ /** Resolve the function an argument stands for: a string literal, a symbol, or an inline definition; `undefined` if none. */
20
+ function resolveFunctionArgument(val, data, opts) {
21
+ if (opts.unquoteFunction && r_string_1.RString.is(val)) {
22
+ return { functionId: val.info.id, functionName: val.content.str, anonymous: false, asString: true };
23
+ }
24
+ if (val.type === type_1.RType.FunctionDefinition) {
25
+ return { functionId: val.info.id, functionName: `${unnamed_call_handling_1.UnnamedFunctionCallPrefix}${val.info.id}`, anonymous: true, asString: false };
26
+ }
27
+ if (val.type !== type_1.RType.Symbol) {
28
+ return undefined;
29
+ }
30
+ const functionName = opts.resolveValue
31
+ ? (0, alias_tracking_1.resolveIdToSingleString)(val.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx })
32
+ : val.content;
33
+ return functionName === undefined ? undefined : { functionId: val.info.id, functionName, anonymous: false, asString: false };
34
+ }
19
35
  /**
20
36
  * Process an apply call like `vapply` or `mapply`.
21
37
  */
@@ -60,39 +76,22 @@ function processApply(name, args, rootId, data, config) {
60
76
  const arg = args[index];
61
77
  if (arg === r_function_call_1.EmptyArgument || !arg.value || (!unquoteFunction && arg.value.type !== type_1.RType.Symbol && arg.value.type !== type_1.RType.FunctionDefinition)) {
62
78
  logger_1.dataflowLogger.warn(`Expected symbol as argument at index ${index}, but got ${JSON.stringify(arg)} instead.`);
79
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
63
80
  return information;
64
81
  }
65
- let functionId = undefined;
66
- let functionName = undefined;
67
- let anonymous = false;
68
82
  const val = arg.value;
69
- if (unquoteFunction && r_string_1.RString.is(val)) {
70
- functionId = val.info.id;
71
- functionName = val.content.str;
72
- information.in = [...information.in, { type: identifier_1.ReferenceType.Function, name: functionName, cds: data.cds, nodeId: functionId }];
73
- }
74
- else if (val.type === type_1.RType.Symbol) {
75
- functionId = val.info.id;
76
- if (resolveValue) {
77
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(val.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
78
- if (resolved?.elements.length === 1 && resolved.elements[0].type === 'string') {
79
- const r = resolved.elements[0];
80
- functionName = (0, r_value_1.isValue)(r.value) ? r.value.str : undefined;
81
- }
82
- }
83
- else {
84
- functionName = val.content;
85
- }
86
- }
87
- else if (val.type === type_1.RType.FunctionDefinition) {
88
- anonymous = true;
89
- functionId = val.info.id;
90
- functionName = `${unnamed_call_handling_1.UnnamedFunctionCallPrefix}${functionId}`;
91
- }
92
- if (functionName === undefined || functionId === undefined) {
83
+ const resolvedFn = resolveFunctionArgument(val, data, { unquoteFunction, resolveValue });
84
+ if (resolvedFn === undefined) {
93
85
  logger_1.dataflowLogger.warn(`Expected symbol or string as function argument at index ${index}, but got ${JSON.stringify(val)} instead.`);
86
+ // the called function is dynamic and unresolvable: reached-but-unknown rather than dropped
87
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
94
88
  return information;
95
89
  }
90
+ const { functionName, anonymous, asString } = resolvedFn;
91
+ let functionId = resolvedFn.functionId;
92
+ if (asString) {
93
+ information.in = [...information.in, { type: identifier_1.ReferenceType.Function, name: functionName, cds: data.cds, nodeId: functionId }];
94
+ }
96
95
  const allOtherArguments = processedArguments.map((arg, i) => {
97
96
  const counterpart = args[i];
98
97
  if (arg && counterpart !== r_function_call_1.EmptyArgument) {
@@ -4,7 +4,7 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
4
4
  import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
7
- import { type NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
+ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
8
8
  import { Identifier, type InGraphIdentifierDefinition } from '../../../../../environments/identifier';
9
9
  import type { DataflowGraphVertexFunctionDefinition } from '../../../../../graph/vertex';
10
10
  import type { ForceArguments } from '../common';
@@ -24,9 +24,10 @@ const named_call_handling_1 = require("../named-call-handling");
24
24
  const built_in_1 = require("../../../../../environments/built-in");
25
25
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
26
26
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
27
- const r_value_1 = require("../../../../../eval/values/r-value");
28
27
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
29
28
  const built_in_new_env_1 = require("./built-in-new-env");
29
+ const built_in_list_1 = require("./built-in-list");
30
+ const built_in_class_generator_1 = require("./built-in-class-generator");
30
31
  const built_in_stack_env_1 = require("./built-in-stack-env");
31
32
  function toReplacementSymbol(target, prefix, superAssignment) {
32
33
  return {
@@ -120,8 +121,31 @@ args, rootId, data, config) {
120
121
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: 'default' }).information;
121
122
  }
122
123
  const { type, named } = target;
123
- if (type === type_1.RType.Symbol) {
124
- if (!config.targetVariable) {
124
+ if (type === type_1.RType.Symbol && !config.targetVariable) {
125
+ const res = (0, known_call_handling_1.processKnownFunctionCall)({
126
+ name,
127
+ args,
128
+ rootId,
129
+ data,
130
+ reverseOrder: !config.swapSourceAndTarget,
131
+ forceArgs: config.forceArgs,
132
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
133
+ });
134
+ return processAssignmentToSymbol({
135
+ ...config,
136
+ nameOfAssignmentFunction: name.content,
137
+ source,
138
+ targetId: target.info.id,
139
+ args: getEffectiveOrder(config, res.processedArguments),
140
+ rootId,
141
+ data,
142
+ information: res.information,
143
+ });
144
+ }
145
+ else if (config.targetVariable && (type === type_1.RType.Symbol || type === type_1.RType.FunctionCall)) {
146
+ // the target expression (`assign(x, v)` / `assign(paste0("cfg_", k), v)`) resolving to a constant name defines that name, keeping the reads that produced it; a dynamic name falls through to the unknown-target handling below
147
+ const resolvedName = (0, built_in_envir_utils_1.resolveConstantString)(target, data);
148
+ if (resolvedName !== undefined) {
125
149
  const res = (0, known_call_handling_1.processKnownFunctionCall)({
126
150
  name,
127
151
  args,
@@ -136,41 +160,13 @@ args, rootId, data, config) {
136
160
  nameOfAssignmentFunction: name.content,
137
161
  source,
138
162
  targetId: target.info.id,
163
+ targetName: resolvedName,
139
164
  args: getEffectiveOrder(config, res.processedArguments),
140
165
  rootId,
141
166
  data,
142
167
  information: res.information,
143
168
  });
144
169
  }
145
- else {
146
- // try to resolve the variable first
147
- const n = (0, alias_tracking_1.resolveIdToValue)(target.info.id, { environment: data.environment, resolve: data.ctx.config.solver.variables, idMap: data.completeAst.idMap, full: true, ctx: data.ctx });
148
- if (n.type === 'set' && n.elements.length === 1 && n.elements[0].type === 'string') {
149
- const val = n.elements[0].value;
150
- if ((0, r_value_1.isValue)(val)) {
151
- const res = (0, known_call_handling_1.processKnownFunctionCall)({
152
- name,
153
- args,
154
- rootId,
155
- data,
156
- reverseOrder: !config.swapSourceAndTarget,
157
- forceArgs: config.forceArgs,
158
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
159
- });
160
- return processAssignmentToSymbol({
161
- ...config,
162
- nameOfAssignmentFunction: name.content,
163
- source,
164
- targetId: target.info.id,
165
- targetName: val.str,
166
- args: getEffectiveOrder(config, res.processedArguments),
167
- rootId,
168
- data,
169
- information: res.information,
170
- });
171
- }
172
- }
173
- }
174
170
  }
175
171
  else if (config.canBeReplacement && type === type_1.RType.FunctionCall && named) {
176
172
  /* as replacement functions take precedence over the lhs fn-call (i.e., `names(x) <- ...` is independent from the definition of `names`), we do not have to process the call */
@@ -306,7 +302,7 @@ function checkTargetReferenceType(sourceInfo, fnModes) {
306
302
  */
307
303
  function isEnvCreatorSource(sourceInfo) {
308
304
  const vert = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
309
- return (0, vertex_1.isFunctionCallVertex)(vert) && vert.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv);
305
+ return vertex_1.FunctionCallVertex.hasOrigin(vert, built_in_proc_name_1.BuiltInProcName.NewEnv);
310
306
  }
311
307
  /**
312
308
  * When `e$x <- val` and `e` holds a tracked {@link InGraphIdentifierDefinition#envState},
@@ -458,27 +454,24 @@ function processAssignmentToSymbol(config) {
458
454
  }
459
455
  else if (source.type === type_1.RType.Symbol) {
460
456
  const defs = (0, resolve_by_name_1.resolveByName)(source.content, data.environment, identifier_1.ReferenceType.Variable);
461
- const def = defs?.find((d) => d.envState !== undefined);
462
- envState = def?.envState;
463
- if (!envState) {
464
- const fnDef = defs?.find((d) => d.returnsEnvState !== undefined);
465
- if (fnDef?.returnsEnvState) {
466
- envState = fnDef.returnsEnvState;
467
- }
468
- }
457
+ envState = defs?.find((d) => d.envState !== undefined)?.envState
458
+ ?? (0, built_in_envir_utils_1.findReturnsEnvState)(defs);
469
459
  }
470
460
  else {
471
461
  const entryVertex = sourceArg.graph.getVertex(sourceArg.entryPoint);
472
- if ((0, vertex_1.isFunctionDefinitionVertex)(entryVertex) && entryVertex.returnEnvState !== undefined) {
462
+ if (vertex_1.FunctionCallVertex.hasOrigin(entryVertex, built_in_proc_name_1.BuiltInProcName.List)) {
463
+ envState = (0, built_in_list_1.resolveListToEnvState)(source, data);
464
+ }
465
+ else if (vertex_1.FunctionCallVertex.hasOrigin(entryVertex, built_in_proc_name_1.BuiltInProcName.ClassGenerator)) {
466
+ returnsEnvState = (0, built_in_class_generator_1.resolveClassMethodsToEnvState)(source, data);
467
+ }
468
+ else if (vertex_1.FunctionDefinitionVertex.is(entryVertex) && entryVertex.returnEnvState !== undefined) {
473
469
  returnsEnvState = entryVertex.returnEnvState;
474
470
  }
475
- else if ((0, vertex_1.isFunctionCallVertex)(entryVertex) && entryVertex.name) {
476
- const fnDefs = (0, resolve_by_name_1.resolveByName)(entryVertex.name, data.environment, identifier_1.ReferenceType.Function);
477
- const fnDef = fnDefs?.find((d) => d.returnsEnvState !== undefined);
478
- if (fnDef?.returnsEnvState) {
479
- envState = fnDef.returnsEnvState;
480
- }
471
+ else if (vertex_1.FunctionCallVertex.is(entryVertex) && entryVertex.name) {
472
+ envState = (0, built_in_envir_utils_1.findReturnsEnvState)((0, resolve_by_name_1.resolveByName)(entryVertex.name, data.environment, identifier_1.ReferenceType.Function));
481
473
  }
474
+ envState ??= (0, built_in_class_generator_1.resolveConstructorInstanceEnvState)(source, data);
482
475
  }
483
476
  if (envState) {
484
477
  for (let i = 0; i < writeNodes.length; i++) {
@@ -41,7 +41,7 @@ function processAttach(name, args, rootId, data) {
41
41
  const attachedLayer = new environment_1.Environment(result.environment.current).defineAll(injected);
42
42
  /* R attaches below `.GlobalEnv`, so existing global bindings shadow the attached ones */
43
43
  return { ...result, environment: {
44
- current: environment_1.REnvironment.attachBelowGlobal(result.environment.current, attachedLayer, attachedLayer),
44
+ current: environment_1.REnvironment.attachAt(result.environment.current, attachedLayer, attachedLayer),
45
45
  level: result.environment.level
46
46
  } };
47
47
  }
@@ -0,0 +1,14 @@
1
+ import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
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';
4
+ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
+ import type { DataflowInformation } from '../../../../../info';
7
+ import type { DataflowProcessorInformation } from '../../../../../processor';
8
+ import type { REnvironmentInformation } from '../../../../../environments/environment';
9
+ /** Processes an `R6Class`/`setRefClass` generator call, tagging it so the assignment layer can record its method list. */
10
+ export declare function processClassGenerator<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
11
+ /** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
12
+ export declare function resolveClassMethodsToEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
13
+ /** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
14
+ export declare function resolveConstructorInstanceEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processClassGenerator = processClassGenerator;
4
+ exports.resolveClassMethodsToEnvState = resolveClassMethodsToEnvState;
5
+ exports.resolveConstructorInstanceEnvState = resolveConstructorInstanceEnvState;
6
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
+ const known_call_handling_1 = require("../known-call-handling");
8
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
9
+ const built_in_list_1 = require("./built-in-list");
10
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
11
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
12
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
13
+ const identifier_1 = require("../../../../../environments/identifier");
14
+ /** R6's `public` / Reference Class's `methods` argument carrying the class generator's methods. */
15
+ const MethodListArguments = ['public', 'methods'];
16
+ /** Processes an `R6Class`/`setRefClass` generator call, tagging it so the assignment layer can record its method list. */
17
+ function processClassGenerator(name, args, rootId, data) {
18
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.ClassGenerator }).information;
19
+ }
20
+ /** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
21
+ function resolveClassMethodsToEnvState(source, data) {
22
+ if (!r_function_call_1.RFunctionCall.isNamed(source)) {
23
+ return undefined;
24
+ }
25
+ const methodList = source.arguments.find(arg => arg !== r_function_call_1.EmptyArgument && arg.name !== undefined && MethodListArguments.includes(arg.name.content));
26
+ return methodList && methodList !== r_function_call_1.EmptyArgument && methodList.value !== undefined ? (0, built_in_list_1.resolveListToEnvState)(methodList.value, data) : undefined;
27
+ }
28
+ const ConstructorField = 'new';
29
+ /** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
30
+ function resolveConstructorInstanceEnvState(source, data) {
31
+ if (source.type !== type_1.RType.FunctionCall || source.named) {
32
+ return undefined;
33
+ }
34
+ const callee = source.calledFunction;
35
+ if (callee.type !== type_1.RType.Access || (callee.operator !== '$' && callee.operator !== '[[') || callee.accessed.type !== type_1.RType.Symbol) {
36
+ return undefined;
37
+ }
38
+ const field = callee.access[0] === r_function_call_1.EmptyArgument ? undefined : callee.access[0]?.value;
39
+ const fieldName = field?.type === type_1.RType.String ? field.content.str : field?.lexeme;
40
+ if (fieldName !== ConstructorField) {
41
+ return undefined;
42
+ }
43
+ return (0, built_in_envir_utils_1.findReturnsEnvState)((0, resolve_by_name_1.resolveByName)(callee.accessed.content, data.environment, identifier_1.ReferenceType.Variable));
44
+ }
45
+ //# sourceMappingURL=built-in-class-generator.js.map
@@ -4,8 +4,10 @@ import type { DataflowInformation } from '../../../../../info';
4
4
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
5
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
- import type { Identifier, NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
7
+ import type { IdentifierDefinition, NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
8
+ import { Identifier } from '../../../../../environments/identifier';
8
9
  import type { REnvironmentInformation } from '../../../../../environments/environment';
10
+ import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
9
11
  /** Result type for a successful envir-argument resolution. */
10
12
  export interface EnvirResolution<OtherInfo> {
11
13
  /** `data` with its `environment` replaced by the resolved `envState` for in-env lookups. */
@@ -32,6 +34,10 @@ export declare function bindArgs<OtherInfo>(args: readonly PotentiallyEmptyRArgu
32
34
  * instead of a hardcoded formal list, while staying correct -- and graph-invariant -- when no signature is available.
33
35
  */
34
36
  export declare function signatureParamNames<OtherInfo>(data: DataflowProcessorInformation<OtherInfo & ParentInformation>, id: Identifier, fallback: readonly string[]): readonly string[];
37
+ /** The constant string a name-position node denotes at construction time (string literal, aliased variable, or `paste`/`paste0` of such); `undefined` if any part is dynamic or the paste builtin is user-shadowed. */
38
+ export declare function resolveConstantString<OtherInfo>(node: RNode<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): string | undefined;
39
+ /** The `returnsEnvState` of the first reaching definition that carries one, else `undefined`. */
40
+ export declare function findReturnsEnvState(defs: readonly IdentifierDefinition[] | undefined): REnvironmentInformation | undefined;
35
41
  /** Resolves a single already-found argument (e.g. from {@link bindArgs}) to an {@link EnvirResolution} when it is a symbol holding a tracked envState. */
36
42
  export declare function resolveArgToEnvir<OtherInfo>(arg: PotentiallyEmptyRArgument<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
37
43
  /** Resolves the `argName` argument (default `'envir'`, pmatch against `allParamNames`), falling back to `positionalFallbackIndex`, to an {@link EnvirResolution}. */
@@ -42,3 +48,10 @@ export declare function resolveSymbolToEnvir<OtherInfo>(symbolName: Identifier,
42
48
  export declare function routeWrittenToCustomEnv(result: DataflowInformation, envDef: NamedInGraphIdentifierDefinition & {
43
49
  envState: REnvironmentInformation;
44
50
  }, newDefAt: NodeId, definedAt?: NodeId): DataflowInformation;
51
+ /**
52
+ * The `search()` position the `pos` argument of a `library()` call requests, either given as a number or as the name of
53
+ * an existing entry (`pos = "package:base"`). Returns `undefined` when there is no such argument, its value is unknown
54
+ * or ambiguous, or it names an entry that is not on the search path; callers then attach at {@link DefaultAttachPosition}
55
+ * (as R does, which warns in the last case).
56
+ */
57
+ export declare function resolveAttachPosition<OtherInfo>(posId: NodeId | undefined, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): number | undefined;
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bindArgs = bindArgs;
4
4
  exports.signatureParamNames = signatureParamNames;
5
+ exports.resolveConstantString = resolveConstantString;
6
+ exports.findReturnsEnvState = findReturnsEnvState;
5
7
  exports.resolveArgToEnvir = resolveArgToEnvir;
6
8
  exports.resolveEnvirArg = resolveEnvirArg;
7
9
  exports.resolveSymbolToEnvir = resolveSymbolToEnvir;
8
10
  exports.routeWrittenToCustomEnv = routeWrittenToCustomEnv;
11
+ exports.resolveAttachPosition = resolveAttachPosition;
9
12
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
10
13
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
11
14
  const unpack_argument_1 = require("../argument/unpack-argument");
@@ -13,8 +16,13 @@ const decode_1 = require("../../../../../../project/sigdb/decode");
13
16
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
14
17
  const identifier_1 = require("../../../../../environments/identifier");
15
18
  const define_1 = require("../../../../../environments/define");
19
+ const environment_1 = require("../../../../../environments/environment");
16
20
  const prefix_1 = require("../../../../../../util/prefix");
17
21
  const built_in_stack_env_1 = require("./built-in-stack-env");
22
+ const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
23
+ const resolve_1 = require("../../../../../eval/resolve/resolve");
24
+ const general_1 = require("../../../../../eval/values/general");
25
+ const logger_1 = require("../../../../../logger");
18
26
  /** A tracked env is a real stack environment (not a private custom env) when its current layer is the global or the built-in/base env. */
19
27
  function isStackEnvState(envState) {
20
28
  return envState.current.globalEnv === true || envState.current.builtInEnv === true;
@@ -72,6 +80,32 @@ function signatureParamNames(data, id, fallback) {
72
80
  const names = sig ? (0, decode_1.signatureParameterNames)(sig) : [];
73
81
  return names.length > 0 ? names : fallback;
74
82
  }
83
+ /** The constant string a name-position node denotes at construction time (string literal, aliased variable, or `paste`/`paste0` of such); `undefined` if any part is dynamic or the paste builtin is user-shadowed. */
84
+ function resolveConstantString(node, data) {
85
+ const info = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx, full: true };
86
+ const unshadowed = new Map();
87
+ const fold = (n) => {
88
+ if (!r_function_call_1.RFunctionCall.isNamed(n)) {
89
+ return (0, alias_tracking_1.resolveIdToSingleString)(n.info.id, info);
90
+ }
91
+ const fnName = identifier_1.Identifier.getName(n.functionName.content);
92
+ if (fnName !== 'paste0' && fnName !== 'paste') {
93
+ return undefined;
94
+ }
95
+ let ok = unshadowed.get(fnName);
96
+ if (ok === undefined) {
97
+ const defs = (0, resolve_by_name_1.resolveByName)(n.functionName.content, data.environment, identifier_1.ReferenceType.Function);
98
+ ok = defs === undefined || defs.every(d => (0, identifier_1.isReferenceType)(d.type, identifier_1.ReferenceType.BuiltInFunction));
99
+ unshadowed.set(fnName, ok);
100
+ }
101
+ return ok ? (0, resolve_1.foldPasteCall)(n, fold) : undefined;
102
+ };
103
+ return fold(node);
104
+ }
105
+ /** The `returnsEnvState` of the first reaching definition that carries one, else `undefined`. */
106
+ function findReturnsEnvState(defs) {
107
+ return defs?.find((d) => d.returnsEnvState !== undefined)?.returnsEnvState;
108
+ }
75
109
  /** Resolves a single already-found argument (e.g. from {@link bindArgs}) to an {@link EnvirResolution} when it is a symbol holding a tracked envState. */
76
110
  function resolveArgToEnvir(arg, data) {
77
111
  if (arg === r_function_call_1.EmptyArgument) {
@@ -142,4 +176,50 @@ function routeWrittenToCustomEnv(result, envDef, newDefAt, definedAt) {
142
176
  const newEnvironment = (0, define_1.define)({ ...envDef, definedAt: newDefAt, envState: newEnvState }, false, { current: result.environment.current.removeAll(namesToRemove), level: result.environment.level });
143
177
  return { ...result, environment: newEnvironment };
144
178
  }
179
+ /** A `search()` position must be an integer and may never displace the global environment (R rejects `pos = 1`). */
180
+ function clampAttachPosition(pos) {
181
+ return Number.isFinite(pos) ? Math.max(environment_1.DefaultAttachPosition, Math.trunc(pos)) : undefined;
182
+ }
183
+ /** The number a value denotes, directly or as the single point of an interval (how a numeric literal resolves). */
184
+ function scalarNumber(value) {
185
+ if (value.type === 'number') {
186
+ return 'num' in value.value ? value.value.num : undefined;
187
+ }
188
+ if (value.type === 'interval' && value.startInclusive && value.endInclusive
189
+ && value.start.type === 'number' && 'num' in value.start.value
190
+ && value.end.type === 'number' && 'num' in value.end.value
191
+ && value.start.value.num === value.end.value.num) {
192
+ return value.start.value.num;
193
+ }
194
+ return undefined;
195
+ }
196
+ /**
197
+ * The `search()` position the `pos` argument of a `library()` call requests, either given as a number or as the name of
198
+ * an existing entry (`pos = "package:base"`). Returns `undefined` when there is no such argument, its value is unknown
199
+ * or ambiguous, or it names an entry that is not on the search path; callers then attach at {@link DefaultAttachPosition}
200
+ * (as R does, which warns in the last case).
201
+ */
202
+ function resolveAttachPosition(posId, data) {
203
+ if (posId === undefined) {
204
+ return undefined;
205
+ }
206
+ const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(posId, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
207
+ if (values?.type !== 'set' || values.elements.length !== 1) {
208
+ return undefined;
209
+ }
210
+ const element = values.elements[0];
211
+ const asNumber = scalarNumber(element);
212
+ if (asNumber !== undefined) {
213
+ return clampAttachPosition(asNumber);
214
+ }
215
+ if (element.type === 'string' && 'str' in element.value) {
216
+ const found = environment_1.REnvironment.searchPosition(data.environment.current, element.value.str);
217
+ if (found === undefined) {
218
+ logger_1.dataflowLogger.warn(`search-path entry '${element.value.str}' does not exist, attaching at the default position`);
219
+ return undefined;
220
+ }
221
+ return clampAttachPosition(found);
222
+ }
223
+ return undefined;
224
+ }
145
225
  //# sourceMappingURL=built-in-envir-utils.js.map
@@ -1,4 +1,4 @@
1
- import { type DataflowProcessorInformation } from '../../../../../processor';
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
4
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
@@ -57,18 +57,78 @@ function linkReadNameToWriteIfPossible(read, environments, listEnvironments, rem
57
57
  tag: vertex_1.VertexType.Value,
58
58
  id: tid,
59
59
  cds: undefined,
60
- value: (0, general_1.valueFromTsValue)(target.value)
60
+ value: (0, general_1.valueFromTsValue)((target).value)
61
61
  }, environments, false);
62
62
  }
63
63
  }
64
64
  }
65
+ /**
66
+ * Expands the directly-called function definitions (`direct`) with those they transitively call (resolved by name in
67
+ * `resolveEnv`). A sibling/outer callee is invisible inside its caller's (clean) body, so its escaped globals never fold
68
+ * into the caller's subflow; pulling them here lets a super-assignment escaping through several call levels reach the
69
+ * outer read. Escapes are folded popped to the fold level, so a write binding an intermediate frame stops there.
70
+ * Package attachments keep their own (lazy) propagation, so transitive callees only contribute their `<<-` escapes.
71
+ */
72
+ function* transitivelyCalledDefinitions(initial, graph, resolveEnv) {
73
+ const seen = new Set();
74
+ const stack = initial.map(fn => ({ fn, direct: true }));
75
+ while (stack.length > 0) {
76
+ const { fn, direct } = stack.pop();
77
+ if (fn.tag !== vertex_1.VertexType.FunctionDefinition || seen.has(fn.id)) {
78
+ continue;
79
+ }
80
+ seen.add(fn.id);
81
+ yield { fn, direct };
82
+ for (const nodeId of fn.subflow.graph) {
83
+ const call = graph.getVertex(nodeId);
84
+ if (call?.tag !== vertex_1.VertexType.FunctionCall || call.onlyBuiltin || call.name === undefined) {
85
+ continue;
86
+ }
87
+ const resolved = (0, resolve_by_name_1.resolveByName)(call.name, resolveEnv, identifier_1.ReferenceType.Function);
88
+ if (resolved === undefined) {
89
+ continue;
90
+ }
91
+ const [targets] = (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(resolved.map(r => r.nodeId)), graph);
92
+ for (const target of targets) {
93
+ if (!seen.has(target.id)) {
94
+ stack.push({ fn: target, direct: false });
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ /** Rebuilds `env` without its attached-package/namespace layers (`t !== undefined`), keeping only the lexical frames a `<<-` can bind. */
101
+ function withoutPackageLayers(env) {
102
+ let builtIn = env.current;
103
+ const core = [];
104
+ let hasPackage = false;
105
+ while (!builtIn.builtInEnv) {
106
+ if (builtIn.t === undefined) {
107
+ core.push(builtIn);
108
+ }
109
+ else {
110
+ hasPackage = true;
111
+ }
112
+ builtIn = builtIn.parent;
113
+ }
114
+ if (!hasPackage) {
115
+ return env;
116
+ }
117
+ let parent = builtIn;
118
+ for (let i = core.length - 1; i >= 0; i--) {
119
+ const cloned = core[i].clone(false);
120
+ cloned.parent = parent;
121
+ parent = cloned;
122
+ }
123
+ return { current: parent, level: env.level };
124
+ }
65
125
  function updateSideEffectsForCalledFunctions(calledEnvs, inputEnvironment, nextGraph, localDefs) {
66
126
  for (const { functionCall, called } of calledEnvs) {
67
127
  let callDependencies = null;
68
- for (const calledFn of called) {
128
+ for (const { fn: calledFn, direct } of transitivelyCalledDefinitions(called, nextGraph, inputEnvironment)) {
69
129
  (0, assert_1.guard)(calledFn.tag === vertex_1.VertexType.FunctionDefinition, 'called function must be a function definition');
70
130
  // only merge the environments they have in common
71
- let environment = calledFn.subflow.environment;
131
+ let environment = direct ? calledFn.subflow.environment : withoutPackageLayers(calledFn.subflow.environment);
72
132
  while (environment.level > inputEnvironment.level) {
73
133
  environment = (0, scoping_1.popLocalEnvironment)(environment);
74
134
  }
@@ -5,7 +5,7 @@ import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/node
5
5
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
6
6
  import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import { DataflowGraph } from '../../../../../graph/graph';
8
- import { type REnvironmentInformation } from '../../../../../environments/environment';
8
+ import type { REnvironmentInformation } from '../../../../../environments/environment';
9
9
  import type { ReadOnlyFlowrAnalyzerContext, FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
10
10
  /**
11
11
  * Process a function definition, i.e., `function(a, b) { ... }`