@eagleoutice/flowr 2.15.9 → 2.16.0

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 (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -12,22 +12,26 @@ const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/node
12
12
  const log_1 = require("../../../../../../util/log");
13
13
  const unpack_argument_1 = require("../argument/unpack-argument");
14
14
  const make_argument_1 = require("../argument/make-argument");
15
+ const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
15
16
  const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
16
17
  const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
17
18
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
18
19
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
19
20
  const logger_1 = require("../../../../../logger");
20
21
  const identifier_1 = require("../../../../../environments/identifier");
22
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
21
23
  const overwrite_1 = require("../../../../../environments/overwrite");
22
24
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
23
25
  const retriever_1 = require("../../../../../../r-bridge/retriever");
24
26
  const vertex_1 = require("../../../../../graph/vertex");
25
- const linker_1 = require("../../../../linker");
26
27
  const define_1 = require("../../../../../environments/define");
27
28
  const edge_1 = require("../../../../../graph/edge");
28
29
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
29
30
  const named_call_handling_1 = require("../named-call-handling");
30
31
  const built_in_1 = require("../../../../../environments/built-in");
32
+ const built_in_props_1 = require("../../../../../environments/built-in-props");
33
+ const arg_matching_1 = require("../../../../../../util/arg-matching");
34
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
31
35
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
32
36
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
33
37
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
@@ -49,15 +53,8 @@ function toReplacementSymbol(target, prefix, superAssignment) {
49
53
  function getEffectiveOrder(config, args) {
50
54
  return config.swapSourceAndTarget ? [args[1], args[0]] : args;
51
55
  }
52
- function findRootAccess(node) {
53
- let current = node;
54
- while (r_access_1.RAccess.is(current)) {
55
- current = current.accessed;
56
- }
57
- if (r_symbol_1.RSymbol.is(current)) {
58
- return current;
59
- }
60
- return undefined;
56
+ function originOf(config) {
57
+ return config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment;
61
58
  }
62
59
  const EnvironmentProducers = [built_in_proc_name_1.BuiltInProcName.NewEnv, built_in_proc_name_1.BuiltInProcName.StackEnv, built_in_proc_name_1.BuiltInProcName.ListToEnv];
63
60
  function yieldsEnvironment(node, graph, data) {
@@ -75,23 +72,12 @@ function tryReplacement(rootId, functionName, data, superAssignment, args, befor
75
72
  /* every replacement function rebinds its target, no matter whether we ship a built-in for it or the user wrote
76
73
  * it; a user-defined one is only ever bound under its `<-` name, the `<<-` form stays in the configuration */
77
74
  const name = builtIn ? functionName.content : identifier_1.Identifier.mapName(functionName.content, n => superAssignment ? n.slice(0, -'<<-'.length) + '<-' : n);
78
- const info = built_in_1.BuiltInProcessorMapper[built_in_proc_name_1.BuiltInProcName.Replacement]({
79
- type: type_1.RType.Symbol,
80
- info: functionName.info,
81
- content: name,
82
- lexeme: functionName.lexeme,
83
- location: functionName.location
84
- }, (0, make_argument_1.wrapArgumentsUnnamed)(args, data.completeAst.idMap), functionName.info.id, data, builtIn ? {
85
- ...builtIn.config,
86
- assignRootId: rootId,
87
- beforeDefine
88
- } : {
75
+ const replacementConfig = builtIn ? builtIn.config : {
89
76
  readIndices: true,
90
77
  makeMaybe: true,
91
- assignmentOperator: superAssignment ? '<<-' : '<-',
92
- assignRootId: rootId,
93
- beforeDefine
94
- });
78
+ assignmentOperator: superAssignment ? '<<-' : '<-'
79
+ };
80
+ const info = built_in_1.BuiltInProcessorMapper[built_in_proc_name_1.BuiltInProcName.Replacement]({ ...functionName, content: name }, (0, make_argument_1.wrapArgumentsUnnamed)(args, data.completeAst.idMap), functionName.info.id, data, { ...replacementConfig, assignRootId: rootId, beforeDefine });
95
81
  if (builtIn) {
96
82
  (0, named_call_handling_1.markAsOnlyBuiltIn)(info.graph, functionName.info.id);
97
83
  return info;
@@ -120,27 +106,16 @@ args, rootId, data, config) {
120
106
  }
121
107
  const source = argsWithNames.get(config.source.name) ?? (config.source.idx === undefined ? undefined : argsWithoutNames[config.source.idx]);
122
108
  const target = argsWithNames.get(config.target.name) ?? (config.target.idx === undefined ? undefined : argsWithoutNames[config.target.idx]);
123
- if (source && target) {
124
- args = [target, source];
125
- }
126
- return processAssignment(name, args, rootId, data, { ...config, mayHaveMoreArgs: true });
109
+ const normalizedArgs = source && target ? [target, source] : args;
110
+ return processAssignment(name, normalizedArgs, rootId, data, { ...config, mayHaveMoreArgs: true });
127
111
  }
128
112
  /** Within a data-masking call `a := b` is rlang's name-value pair, not data.table's assignment. */
129
113
  function isMaskedNamePair(name, rootId, data) {
130
114
  if (identifier_1.Identifier.getName(name.content) !== ':=') {
131
115
  return false;
132
116
  }
133
- const idMap = data.completeAst.idMap;
134
- let parent = idMap.get(rootId)?.info.parent;
135
- while (parent !== undefined) {
136
- const node = idMap.get(parent);
137
- if (node === undefined) {
138
- return false;
139
- }
140
- else if (r_argument_1.RArgument.is(node)) {
141
- parent = node.info.parent;
142
- }
143
- else {
117
+ for (const node of model_1.RNode.iterateParents(data.completeAst.idMap.get(rootId), data.completeAst.idMap)) {
118
+ if (!r_argument_1.RArgument.is(node)) {
144
119
  return r_function_call_1.RFunctionCall.isNamed(node) && data_masking_functions_1.DataMaskingFunctionNames.has(identifier_1.Identifier.getName(node.functionName.content));
145
120
  }
146
121
  }
@@ -164,20 +139,15 @@ function processAssignment(name,
164
139
  /* we expect them to be ordered in the sense that we have (source, target): `<source> <- <target>` */
165
140
  args, rootId, data, config) {
166
141
  const information = processAssignmentTarget(name, args, rootId, data, config);
167
- if (config.callsSource) {
168
- linkSourceAsCalled(args, rootId, data, config, information);
169
- }
170
- return information;
171
- }
172
- function linkSourceAsCalled(args, rootId, data, config, information) {
173
- const source = (0, unpack_argument_1.unpackArg)(args[config.swapSourceAndTarget ? 0 : 1]);
142
+ const source = config.callsSource ? (0, unpack_argument_1.unpackArg)(args[config.swapSourceAndTarget ? 0 : 1]) : undefined;
174
143
  const vertex = source ? information.graph.getVertex(source.info.id) : undefined;
175
- if (vertex && vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
176
- linker_1.ClosureRefs.resolveOpenIngoing(information.graph, rootId, vertex, data.environment);
144
+ /* the function runs when the name is read, so what it reads is resolved there and not where it is bound */
145
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
177
146
  for (const written of information.out) {
178
147
  information.graph.addEdge(written.nodeId, vertex.id, edge_1.EdgeType.Calls);
179
148
  }
180
149
  }
150
+ return information;
181
151
  }
182
152
  function processAssignmentTarget(name, args, rootId, data, config) {
183
153
  if (isMaskedNamePair(name, rootId, data)) {
@@ -202,27 +172,31 @@ function processAssignmentTarget(name, args, rootId, data, config) {
202
172
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
203
173
  }
204
174
  const { type, named } = target;
205
- /** the target is a plain name, so the assignment defines it directly (with `targetName` set whenever the name had to be resolved first) */
206
- const assignToSymbol = (targetName) => {
175
+ /** the call (with `callArgs`) defines the plain name at `targetId` (with `targetName` set whenever the name had to be resolved first) */
176
+ const toSymbol = (callArgs, targetId, targetName) => {
207
177
  const res = (0, known_call_handling_1.processKnownFunctionCall)({
208
178
  name,
209
- args,
179
+ args: callArgs,
210
180
  rootId,
211
181
  data,
212
182
  reverseOrder: !config.swapSourceAndTarget,
213
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
183
+ origin: originOf(config)
214
184
  });
215
- const info = processAssignmentToSymbol({
185
+ return processAssignmentToSymbol({
216
186
  ...config,
217
187
  nameOfAssignmentFunction: name.content,
218
188
  source,
219
- targetId: target.info.id,
189
+ targetId,
220
190
  targetName,
221
191
  args: getEffectiveOrder(config, res.processedArguments),
222
192
  rootId,
223
193
  data,
224
194
  information: res.information,
225
195
  });
196
+ };
197
+ /** the target is a plain name, so the assignment defines it directly */
198
+ const assignToSymbol = (targetName) => {
199
+ const info = toSymbol(args, target.info.id, targetName);
226
200
  if (config.readTarget && r_symbol_1.RSymbol.is(target)) {
227
201
  /* just like a replacement function, the call works on the old value of its target */
228
202
  info.graph.addEdge(target.info.id, rootId, edge_1.EdgeType.Reads);
@@ -234,7 +208,8 @@ function processAssignmentTarget(name, args, rootId, data, config) {
234
208
  return assignToSymbol();
235
209
  }
236
210
  else if (config.targetVariable && (type === type_1.RType.Symbol || type === type_1.RType.FunctionCall)) {
237
- // 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
211
+ /* the target expression (`assign(x, v)` / `assign(paste0("cfg_", k), v)`) resolving to a constant name defines that name, keeping
212
+ * the reads that produced it; a dynamic name falls through to the unknown-target handling below */
238
213
  const resolvedName = (0, built_in_envir_utils_1.resolveConstantString)(target, data);
239
214
  if (resolvedName !== undefined) {
240
215
  return assignToSymbol(resolvedName);
@@ -260,88 +235,42 @@ function processAssignmentTarget(name, args, rootId, data, config) {
260
235
  return replaced;
261
236
  }
262
237
  else if (type === type_1.RType.Access) {
263
- const rootArg = findRootAccess(target);
264
- if (rootArg) {
265
- const res = (0, known_call_handling_1.processKnownFunctionCall)({
266
- name,
267
- args: [rootArg, source],
268
- rootId,
269
- data,
270
- reverseOrder: !config.swapSourceAndTarget,
271
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
272
- });
273
- return processAssignmentToSymbol({
274
- ...config,
275
- nameOfAssignmentFunction: name.content,
276
- source,
277
- targetId: rootArg.info.id,
278
- args: getEffectiveOrder(config, res.processedArguments),
279
- rootId,
280
- data,
281
- information: res.information,
282
- });
238
+ let rootArg = target;
239
+ while (r_access_1.RAccess.is(rootArg)) {
240
+ rootArg = rootArg.accessed;
241
+ }
242
+ if (r_symbol_1.RSymbol.is(rootArg)) {
243
+ return toSymbol([rootArg, source], rootArg.info.id);
283
244
  }
284
245
  }
285
246
  else if (type === type_1.RType.String) {
286
- return processAssignmentToString(target, args, name, rootId, data, config, source);
247
+ const symbol = {
248
+ type: type_1.RType.Symbol,
249
+ info: target.info,
250
+ content: (0, retriever_1.removeRQuotes)(target.lexeme) + (config.targetSuffix ?? ''),
251
+ lexeme: target.lexeme,
252
+ location: target.location,
253
+ };
254
+ /* treat the target argument as a symbol; keep extra args (e.g. envir=) so they get graph vertices */
255
+ const targetIdx = config.swapSourceAndTarget ? 1 : 0;
256
+ const mappedArgs = args.map((a, i) => i === targetIdx ? { ...a, value: symbol } : a);
257
+ return toSymbol(mappedArgs, symbol.info.id);
287
258
  }
288
259
  logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has an unknown target type ${target.type} => unknown impact`);
289
- const info = (0, known_call_handling_1.processKnownFunctionCall)({
290
- name, args: effectiveArgs, rootId, data,
291
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
292
- }).information;
260
+ const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args: effectiveArgs, rootId, data, origin: originOf(config) }).information;
293
261
  (0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
294
262
  return info;
295
263
  }
296
264
  /** Promotes the ingoing/unknown references of target (an assignment) to definitions. */
297
265
  function produceWrittenNodes(rootId, target, referenceType, data, makeMaybe, value) {
298
- const written = [];
299
- for (const refs of [target.in, target.unknownReferences]) {
300
- for (const ref of refs) {
301
- written.push({
302
- nodeId: ref.nodeId,
303
- name: ref.name,
304
- type: referenceType,
305
- definedAt: rootId,
306
- cds: data.cds ?? (makeMaybe ? [] : undefined),
307
- value
308
- });
309
- }
310
- }
311
- return written;
312
- }
313
- function processAssignmentToString(target, args, name, rootId, data, config, source) {
314
- const symbol = {
315
- type: type_1.RType.Symbol,
316
- info: target.info,
317
- content: (0, retriever_1.removeRQuotes)(target.lexeme),
318
- lexeme: target.lexeme,
319
- location: target.location,
320
- };
321
- // treat first argument to Symbol; include extra args (e.g. envir=) so they get graph vertices
322
- const extraArgs = config.mayHaveMoreArgs ? Array.from(args).slice(2) : [];
323
- const mappedArgs = config.swapSourceAndTarget ? [args[0], {
324
- ...args[1],
325
- value: symbol
326
- }, ...extraArgs] : [{ ...args[0], value: symbol }, args[1], ...extraArgs];
327
- const res = (0, known_call_handling_1.processKnownFunctionCall)({
328
- name,
329
- args: mappedArgs,
330
- rootId,
331
- data,
332
- reverseOrder: !config.swapSourceAndTarget,
333
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
334
- });
335
- return processAssignmentToSymbol({
336
- ...config,
337
- nameOfAssignmentFunction: name.content,
338
- source,
339
- targetId: symbol.info.id,
340
- args: getEffectiveOrder(config, res.processedArguments),
341
- rootId,
342
- data,
343
- information: res.information
344
- });
266
+ return [...target.in, ...target.unknownReferences].filter(ref => !built_in_ambient_state_1.AmbientStateName.is(ref.name)).map(ref => ({
267
+ nodeId: ref.nodeId,
268
+ name: ref.name,
269
+ type: referenceType,
270
+ definedAt: rootId,
271
+ cds: data.cds ?? (makeMaybe ? [] : undefined),
272
+ value
273
+ }));
345
274
  }
346
275
  function checkTargetReferenceType(sourceInfo, fnModes) {
347
276
  const vert = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
@@ -410,9 +339,8 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
410
339
  }
411
340
  const fieldName = (r_string_1.RString.is(fieldNode) ? fieldNode.content.str : fieldNode.lexeme);
412
341
  const normalResult = tryReplacement(rootId, replacement, data, config.superAssignment ?? false, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source], config.beforeDefine);
413
- const isFunction = (0, built_in_list_1.holdsFunction)(source, data.environment);
414
342
  const fieldDef = {
415
- type: isFunction ? identifier_1.ReferenceType.Function : identifier_1.ReferenceType.Variable,
343
+ type: (0, built_in_list_1.holdsFunction)(source, data.environment) ? identifier_1.ReferenceType.Function : identifier_1.ReferenceType.Variable,
416
344
  name: fieldName,
417
345
  nodeId: source.info.id,
418
346
  definedAt: normalResult.entryPoint,
@@ -421,6 +349,7 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
421
349
  const newEnvState = (0, define_1.define)(fieldDef, false, envirResolution.envDef.envState);
422
350
  const updatedEnvDef = {
423
351
  ...envirResolution.envDef,
352
+ nodeId: target.accessed.info.id,
424
353
  definedAt: rootId,
425
354
  envState: newEnvState
426
355
  };
@@ -429,7 +358,11 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
429
358
  level: normalResult.environment.level
430
359
  };
431
360
  normalResult.graph.addEdge(normalResult.entryPoint, target.accessed.info.id, edge_1.EdgeType.Reads);
432
- return { ...normalResult, environment: (0, define_1.define)(updatedEnvDef, false, strippedEnv) };
361
+ const environment = (0, define_1.define)(updatedEnvDef, false, strippedEnv);
362
+ if (updatedEnvDef.envId === undefined) {
363
+ return { ...normalResult, environment };
364
+ }
365
+ return { ...normalResult, environment: (0, built_in_envir_utils_1.rebindHolders)(environment, updatedEnvDef, newEnvState, rootId) };
433
366
  }
434
367
  /**
435
368
  * When `config.environmentArg` (e.g. `'envir'` for `assign`) resolves to a variable with a tracked
@@ -441,32 +374,25 @@ function tryRouteToCustomEnv(name, args, rootId, data, config) {
441
374
  const envirRouting = (0, built_in_envir_utils_1.resolveEnvirArgOrAmbiguous)(args, data, config.sig, config.environmentArg)
442
375
  ?? (0, built_in_envir_utils_1.resolveFirstEnvirArg)(args, data, config.sig, built_in_envir_utils_1.EnvirPositionFormals);
443
376
  if (envirRouting === 'ambiguous' || (!envirRouting && (0, built_in_envir_utils_1.suppliesArg)(args, config.sig, built_in_envir_utils_1.EnvirPositionFormals))) {
444
- const info = (0, known_call_handling_1.processKnownFunctionCall)({
445
- name, args, rootId, data,
446
- origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
447
- }).information;
377
+ const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: originOf(config) }).information;
448
378
  (0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
449
379
  return info;
450
380
  }
451
381
  if (!envirRouting) {
452
- return undefined;
453
- }
454
- if (envirRouting.stack === 'global') {
455
- const globalResult = processAssignment(name, args, rootId, data, {
456
- ...config,
457
- environmentArg: undefined, // prevent re-entry
458
- superAssignment: true
459
- });
460
- globalResult.graph.addEdge(rootId, envirRouting.envirNodeId, edge_1.EdgeType.Reads);
461
- return globalResult;
382
+ if (!data.ctx.config.solver.trackEnvironments || config.environmentArg === undefined || !(0, built_in_envir_utils_1.suppliesArg)(args, config.sig, [config.environmentArg])) {
383
+ return undefined;
384
+ }
385
+ /* an environment we cannot name (`sys.frame(-1)`) may be any frame, so the write stays here and is kept as well */
386
+ const info = processAssignment(name, args, rootId, data, { ...config, environmentArg: undefined });
387
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
388
+ return info;
462
389
  }
463
- /* run the normal assignment path to get the correct graph structure */
464
- const normalResult = processAssignment(name, args, rootId, data, {
465
- ...config,
466
- environmentArg: undefined // prevent re-entry
467
- });
390
+ /* run the normal assignment path to get the correct graph structure, the call reads the environment it writes into */
391
+ const global = envirRouting.stack === 'global';
392
+ const normalResult = processAssignment(name, args, rootId, data, { ...config, environmentArg: undefined, superAssignment: global || config.superAssignment });
393
+ normalResult.graph.addEdge(rootId, envirRouting.envirNodeId, edge_1.EdgeType.Reads);
468
394
  /* pass rootId as definedAt so only defs made at this call site are routed */
469
- return (0, built_in_envir_utils_1.routeWrittenToEnvir)(normalResult, envirRouting, rootId, data.environment, rootId);
395
+ return global ? normalResult : (0, built_in_envir_utils_1.routeWrittenToEnvir)(normalResult, envirRouting, rootId, data.environment, rootId);
470
396
  }
471
397
  /**
472
398
  * Models a call like `Hmisc::getHdata(x)` that loads a dataset into the variable it is *given*: `x` is both
@@ -475,12 +401,34 @@ function tryRouteToCustomEnv(name, args, rootId, data, config) {
475
401
  function processDefineArgument(name, args, rootId, data, config) {
476
402
  const res = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.DefineArgument });
477
403
  const info = res.information;
478
- const targetArg = res.processedArguments[0]; // the read argument, e.g. `prostate`
479
- if (targetArg !== undefined) {
480
- for (const node of produceWrittenNodes(rootId, targetArg, identifier_1.ReferenceType.Variable, data, false, undefined)) {
481
- info.environment = (0, define_1.define)(node, config.superAssignment, info.environment);
404
+ const formals = config.sig ?? [];
405
+ const bound = (0, arg_matching_1.matchArgumentsToParameters)(args.map(a => r_argument_1.RArgument.isEmpty(a) ? undefined : a.name?.content), formals.map(([f]) => f));
406
+ const defineByCall = (node) => {
407
+ info.environment = (0, define_1.define)(node, config.superAssignment, info.environment);
408
+ /* defined by the call; the read edge is left intact */
409
+ if (node.nodeId !== rootId) {
482
410
  info.graph.setDefinitionOfVertex(node, [rootId]);
483
- info.graph.addEdge(node.nodeId, rootId, edge_1.EdgeType.DefinedBy); // defined by the call; the read edge is left intact
411
+ info.graph.addEdge(node.nodeId, rootId, edge_1.EdgeType.DefinedBy);
412
+ }
413
+ };
414
+ for (let i = 0; i < args.length; i++) {
415
+ const arg = args[i], targetArg = res.processedArguments[i], param = bound[i];
416
+ if (r_argument_1.RArgument.isEmpty(arg) || targetArg === undefined || param === undefined) {
417
+ continue;
418
+ }
419
+ if (param === 0 && r_symbol_1.RSymbol.is(arg.value)) {
420
+ for (const node of produceWrittenNodes(rootId, targetArg, identifier_1.ReferenceType.Variable, data, false, undefined)) {
421
+ defineByCall(node);
422
+ }
423
+ }
424
+ else if (param === 0 || (formals[param][1] & built_in_props_1.ArgProp.Value) !== 0) {
425
+ /* a name given as a string literal is defined at it, any other at the call */
426
+ const at = r_string_1.RString.is(arg.value) ? arg.value.info.id : rootId;
427
+ for (const named of node_value_1.NodeValue.knownStringsOf(arg.value, data)) {
428
+ const node = { nodeId: at, name: named, type: identifier_1.ReferenceType.Variable, definedAt: rootId, cds: data.cds };
429
+ info.out = [...info.out, node];
430
+ defineByCall(node);
431
+ }
484
432
  }
485
433
  }
486
434
  return info;
@@ -488,6 +436,7 @@ function processDefineArgument(name, args, rootId, data, config) {
488
436
  /** Define `nodeToDefine` in the environment and wire the `DefinedBy` edges from it to its sources and the assignment root (dropping the child-added read edges). */
489
437
  function markAsAssignment(information, nodeToDefine, sourceIds, rootIdOfAssignment, data, assignmentConfig) {
490
438
  information.environment = (0, define_1.define)(nodeToDefine, assignmentConfig?.superAssignment, information.environment);
439
+ information.environment = (0, built_in_ambient_state_1.ambientWritesOfAssignment)(information.environment, nodeToDefine.name, rootIdOfAssignment, data.cds ? [...data.cds] : undefined, assignmentConfig?.superAssignment === true || data.environment.level === 0);
491
440
  information.graph.setDefinitionOfVertex(nodeToDefine, sourceIds);
492
441
  const nid = nodeToDefine.nodeId;
493
442
  if (!assignmentConfig?.quoteSource) {
@@ -497,8 +446,8 @@ function markAsAssignment(information, nodeToDefine, sourceIds, rootIdOfAssignme
497
446
  }
498
447
  information.graph.addEdge(nid, rootIdOfAssignment, edge_1.EdgeType.DefinedBy);
499
448
  // kinda dirty, but we have to remove existing read edges for the symbol, added by the child
500
- for (const [id] of information.graph.edgesFrom(nodeToDefine.nodeId)) {
501
- information.graph.removeEdgeType(nodeToDefine.nodeId, id, edge_1.EdgeType.Reads);
449
+ for (const [id] of information.graph.edgesFrom(nid)) {
450
+ information.graph.removeEdgeType(nid, id, edge_1.EdgeType.Reads);
502
451
  }
503
452
  }
504
453
  /** Helper for when the _target_ of an assignment is known to be a (single) symbol (i.e. `x <- ...`, not `names(x) <- ...`). */
@@ -508,7 +457,7 @@ function processAssignmentToSymbol(config) {
508
457
  const referenceType = config.replacement && kindOfValue === identifier_1.ReferenceType.Variable ? identifier_1.ReferenceType.Unknown : kindOfValue;
509
458
  const useSourceIds = [sourceArg.graph.hasVertex(source.info.id) ? source.info.id : sourceArg.entryPoint];
510
459
  const aliases = (0, alias_tracking_1.getAliases)(useSourceIds, information.graph, information.environment);
511
- const writeNodes = targetName ? [{
460
+ const written = targetName ? [{
512
461
  nodeId: targetId,
513
462
  name: targetName,
514
463
  type: referenceType,
@@ -517,9 +466,11 @@ function processAssignmentToSymbol(config) {
517
466
  value: aliases
518
467
  }]
519
468
  : produceWrittenNodes(rootId, targetArg, referenceType, data, makeMaybe ?? false, aliases);
469
+ let copied;
470
+ let envState;
471
+ let envId;
472
+ let returnsEnvState;
520
473
  if (data.ctx.config.solver.trackEnvironments) {
521
- let envState;
522
- let returnsEnvState;
523
474
  const valueEntry = valueEntryPointOf(sourceArg);
524
475
  const stackEnv = (0, built_in_stack_env_1.stackEnvStateFromSource)(sourceArg, data, valueEntry);
525
476
  if (isEnvCreatorSource(sourceArg, valueEntry)) {
@@ -531,8 +482,10 @@ function processAssignmentToSymbol(config) {
531
482
  }
532
483
  else if (r_symbol_1.RSymbol.is(source)) {
533
484
  const defs = resolve_helper_1.Resolve.byNameAndType(source.content, data.environment, identifier_1.ReferenceType.Variable);
534
- envState = defs?.find(identifier_1.hasEnvState)?.envState
535
- ?? (0, built_in_envir_utils_1.findReturnsEnvState)(defs);
485
+ copied = defs?.find(identifier_1.hasEnvState);
486
+ envState = copied?.envState ?? (0, built_in_envir_utils_1.findReturnsEnvState)(defs);
487
+ /* only a copied environment needs an identity, its holders are rebound on every field write */
488
+ envId = copied === undefined ? undefined : copied.envId ?? copied.nodeId;
536
489
  }
537
490
  else {
538
491
  const entryVertex = sourceArg.graph.getVertex(sourceArg.entryPoint);
@@ -550,54 +503,38 @@ function processAssignmentToSymbol(config) {
550
503
  }
551
504
  envState ??= (0, built_in_class_generator_1.resolveConstructorInstanceEnvState)(source, data);
552
505
  }
553
- if (envState) {
554
- for (let i = 0; i < writeNodes.length; i++) {
555
- writeNodes[i] = { ...writeNodes[i], envState };
556
- }
557
- }
558
- else if (returnsEnvState) {
559
- for (let i = 0; i < writeNodes.length; i++) {
560
- writeNodes[i] = { ...writeNodes[i], returnsEnvState };
561
- }
562
- }
563
506
  }
507
+ const forces = quoteSource ? (0, built_in_ambient_state_1.ambientWritesBetween)(sourceArg.environment, data.environment) : [];
508
+ if (forces.length > 0) {
509
+ (0, built_in_ambient_state_1.markForcing)(data.environment);
510
+ }
511
+ const tracked = envState ? { envState, envId } : returnsEnvState ? { returnsEnvState } : {};
512
+ const writeNodes = written.map(w => ({ ...w, ...tracked, ...forces.length > 0 ? { forces } : {} }));
564
513
  if (writeNodes.length !== 1 && log_1.log.settings.minLevel >= 4 /* LogLevel.Warn */) {
565
514
  log_1.log.warn(`Unexpected write number in assignment: ${JSON.stringify(writeNodes)}`);
566
515
  }
567
- // we drop the first arg which we use to pass along arguments :D
516
+ /* we drop the first arg which we use to pass along arguments */
568
517
  const readFromSourceWritten = sourceArg.out.slice(1);
569
518
  const readTargets = [
570
- { nodeId: rootId, name: nameOfAssignmentFunction, cds: data.cds, type: identifier_1.ReferenceType.Function }
519
+ { nodeId: rootId, name: nameOfAssignmentFunction, cds: data.cds, type: identifier_1.ReferenceType.Function },
520
+ ...sourceArg.unknownReferences,
521
+ ...sourceArg.in,
522
+ ...targetName ? targetArg.in : targetArg.in.filter(i => i.nodeId !== targetId),
523
+ ...readFromSourceWritten
571
524
  ];
572
- readTargets.push(...sourceArg.unknownReferences);
573
- readTargets.push(...sourceArg.in);
574
- if (targetName) {
575
- readTargets.push(...targetArg.in);
576
- }
577
- else {
578
- for (const i of targetArg.in) {
579
- if (i.nodeId !== targetId) {
580
- readTargets.push(i);
581
- }
582
- }
583
- }
584
- readTargets.push(...readFromSourceWritten);
585
- information.environment = (0, overwrite_1.overwriteEnvironment)(sourceArg.environment, targetArg.environment);
525
+ /* a quoted source (`delayedAssign`) writes nothing yet, its writes happen where it is forced (see `Deferred`) */
526
+ information.environment = quoteSource ? data.environment : (0, overwrite_1.overwriteEnvironment)(sourceArg.environment, targetArg.environment);
586
527
  if (config.beforeDefine) {
587
528
  information.environment = config.beforeDefine(information);
588
529
  }
589
- // install assigned variables in environment
590
530
  for (const write of writeNodes) {
591
531
  markAsAssignment(information, write, useSourceIds, rootId, data, config);
592
532
  }
593
- information.graph.addEdge(rootId, targetArg.entryPoint, edge_1.EdgeType.Returns);
594
- if (quoteSource) {
595
- information.graph.addEdge(rootId, source.info.id, edge_1.EdgeType.NonStandardEvaluation);
596
- }
597
- else {
598
- // we read the source
599
- information.graph.addEdge(rootId, source.info.id, edge_1.EdgeType.Reads);
533
+ if (copied?.name !== undefined && copied.envId === undefined && information.environment.current.lookup(identifier_1.Identifier.getName(copied.name))?.includes(copied)) {
534
+ information.environment = (0, define_1.define)({ ...copied, name: copied.name, envId: copied.nodeId }, false, information.environment);
600
535
  }
536
+ information.graph.addEdge(rootId, targetArg.entryPoint, edge_1.EdgeType.Returns);
537
+ information.graph.addEdge(rootId, source.info.id, quoteSource ? edge_1.EdgeType.NonStandardEvaluation : edge_1.EdgeType.Reads);
601
538
  return {
602
539
  environment: information.environment,
603
540
  graph: information.graph,
@@ -607,7 +544,7 @@ function processAssignmentToSymbol(config) {
607
544
  entryPoint: rootId,
608
545
  cfgEntry: information.cfgEntry,
609
546
  in: readTargets,
610
- out: writeNodes.concat(readFromSourceWritten),
547
+ out: [...writeNodes, ...readFromSourceWritten],
611
548
  };
612
549
  }
613
550
  //# sourceMappingURL=built-in-assignment.js.map
@@ -16,6 +16,7 @@ const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/node
16
16
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
17
17
  const r_function_call_2 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
18
18
  const built_in_s_seven_new_generic_1 = require("./built-in-s-seven-new-generic");
19
+ const built_in_s_four_1 = require("./built-in-s-four");
19
20
  /** R6's `public` / Reference Class's `methods` argument carrying the class generator's methods. */
20
21
  const MethodListArguments = ['public', 'methods'];
21
22
  const FieldListArguments = ['fields', 'private'];
@@ -23,6 +24,7 @@ const FieldListArguments = ['fields', 'private'];
23
24
  function processClassGenerator(name, args, rootId, data, config) {
24
25
  const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.ClassGenerator }).information;
25
26
  (0, built_in_s_seven_new_generic_1.attachClassDeclaration)(info, rootId, args, config?.classDecl);
27
+ (0, built_in_s_four_1.linkS4Declaration)(info, rootId, data);
26
28
  return info;
27
29
  }
28
30
  /** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
@@ -32,10 +34,9 @@ function resolveClassMethodsToEnvState(source, data) {
32
34
  }
33
35
  let envState;
34
36
  for (const [names, values] of [[MethodListArguments, false], [FieldListArguments, true]]) {
35
- const list = source.arguments.find(arg => arg !== r_function_call_2.EmptyArgument && arg.name !== undefined && names.includes(arg.name.content));
36
- const resolved = list && list !== r_function_call_2.EmptyArgument && list.value !== undefined
37
- ? (0, built_in_list_1.resolveListToEnvState)(list.value, envState ? { environment: envState } : data, values)
38
- : undefined;
37
+ const listArg = source.arguments.find(arg => arg !== r_function_call_2.EmptyArgument && arg.name !== undefined && names.includes(arg.name.content));
38
+ const list = r_argument_1.RArgument.valueOf(listArg);
39
+ const resolved = list === undefined ? undefined : (0, built_in_list_1.resolveListToEnvState)(list, envState ? { environment: envState } : data, values);
39
40
  envState = resolved ?? envState;
40
41
  }
41
42
  return envState;
@@ -43,14 +44,11 @@ function resolveClassMethodsToEnvState(source, data) {
43
44
  const ConstructorField = 'new';
44
45
  /** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
45
46
  function resolveConstructorInstanceEnvState(source, data) {
46
- if (!r_function_call_1.RFunctionCall.is(source) || source.named) {
47
- return undefined;
48
- }
49
- const callee = source.calledFunction;
47
+ const callee = r_function_call_1.RFunctionCall.isUnnamed(source) ? source.calledFunction : undefined;
50
48
  if (!r_access_1.RAccess.is(callee) || (callee.operator !== '$' && callee.operator !== '[[') || !r_symbol_1.RSymbol.is(callee.accessed)) {
51
49
  return undefined;
52
50
  }
53
- const field = r_argument_1.RArgument.isEmpty(callee.access[0]) ? undefined : callee.access[0]?.value;
51
+ const field = r_argument_1.RArgument.valueOf(callee.access[0]);
54
52
  const fieldName = r_string_1.RString.is(field) ? field.content.str : field?.lexeme;
55
53
  if (fieldName !== ConstructorField) {
56
54
  return undefined;
@@ -5,7 +5,7 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
5
5
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
6
6
  import { RFunctionCall } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
7
7
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
8
- import type { IdentifierDefinition, NamedInGraphIdentifierDefinition, Identifier } from '../../../../../environments/identifier';
8
+ import { Identifier, type IdentifierDefinition, type NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
9
9
  import type { REnvironmentInformation } from '../../../../../environments/environment';
10
10
  import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
11
11
  import { FnSig } from '../../../../../environments/built-in-props';
@@ -75,6 +75,10 @@ export declare function resolveFirstEnvirArg<OtherInfo>(args: readonly Potential
75
75
  export declare function unknownIfAmbiguous<OtherInfo>(routing: EnvirArgRouting<OtherInfo>, result: DataflowInformation, rootId: NodeId): boolean;
76
76
  /** Resolves a symbol by name to an {@link EnvirResolution} when it holds a tracked environment. */
77
77
  export declare function resolveSymbolToEnvir<OtherInfo>(symbolName: Identifier, nodeId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
78
+ /** Binds every variable holding the environment of `envDef` to its new state, where that variable is bound. */
79
+ export declare function rebindHolders(environment: REnvironmentInformation, envDef: NamedInGraphIdentifierDefinition & {
80
+ envState: REnvironmentInformation;
81
+ }, envState: REnvironmentInformation, definedAt?: NodeId): REnvironmentInformation;
78
82
  /**
79
83
  * Routes writes into a real stack env's frame chain, the same way `<<-` reaches an outer scope.
80
84
  * Each write also gets a `Reads` edge back to `rootId`, so slicing does not drop the call that made it.