@eagleoutice/flowr 2.17.4 → 2.17.5

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 (544) hide show
  1. package/README.md +13 -52
  2. package/abstract-interpretation/absint-inference.js +1 -2
  3. package/abstract-interpretation/data-frame/arguments.d.ts +14 -3
  4. package/abstract-interpretation/data-frame/arguments.js +34 -0
  5. package/abstract-interpretation/data-frame/dataframe-semantics.js +7 -15
  6. package/abstract-interpretation/data-frame/resolve-args.d.ts +2 -2
  7. package/abstract-interpretation/data-frame/semantics.d.ts +8 -1
  8. package/abstract-interpretation/data-frame/semantics.js +14 -6
  9. package/abstract-interpretation/domains/state-abstract-domain.js +28 -18
  10. package/abstract-interpretation/domains/state-map.d.ts +43 -0
  11. package/abstract-interpretation/domains/state-map.js +147 -0
  12. package/benchmark/slicer.d.ts +1 -1
  13. package/benchmark/slicer.js +8 -7
  14. package/cli/repl/commands/repl-dataflow.js +5 -5
  15. package/cli/repl/commands/repl-execute.js +3 -2
  16. package/cli/repl/commands/repl-parse.js +2 -1
  17. package/cli/repl/print-version.d.ts +1 -1
  18. package/cli/repl/print-version.js +2 -1
  19. package/cli/repl/server/connection.d.ts +1 -1
  20. package/cli/repl/server/connection.js +7 -9
  21. package/cli/slicer-app.js +2 -1
  22. package/clones/algorithms/baxter-ast.d.ts +33 -0
  23. package/clones/algorithms/baxter-ast.js +70 -0
  24. package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
  25. package/clones/algorithms/greedy-string-tiling.js +56 -0
  26. package/clones/algorithms/winnowing.d.ts +27 -0
  27. package/clones/algorithms/winnowing.js +66 -0
  28. package/clones/clone-ast.d.ts +75 -0
  29. package/clones/clone-ast.js +174 -0
  30. package/clones/clone-dataflow.d.ts +11 -0
  31. package/clones/clone-dataflow.js +83 -0
  32. package/clones/clone-detector.d.ts +116 -0
  33. package/clones/clone-detector.js +200 -0
  34. package/clones/clone-index.d.ts +54 -0
  35. package/clones/clone-index.js +56 -0
  36. package/config.d.ts +21 -2
  37. package/config.js +7 -1
  38. package/control-flow/basic-cfg-guided-visitor.js +1 -2
  39. package/control-flow/happens-before.d.ts +2 -0
  40. package/control-flow/happens-before.js +15 -9
  41. package/control-flow/simple-visitor.js +2 -4
  42. package/core/steps/all/core/00-parse.js +2 -1
  43. package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
  44. package/core/steps/all/core/10-normalize.js +2 -1
  45. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
  46. package/core/steps/all/static-slicing/00-slice.js +2 -1
  47. package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
  48. package/core/steps/pipeline/create-pipeline.js +1 -2
  49. package/core/steps/pipeline/default-pipelines.d.ts +1 -1
  50. package/core/steps/pipeline/default-pipelines.js +5 -4
  51. package/core/steps/pipeline-step.d.ts +3 -1
  52. package/core/steps/pipeline-step.js +5 -0
  53. package/data/r-base-primitives.generated.d.ts +2 -1
  54. package/dataflow/cluster.js +1 -2
  55. package/dataflow/environments/ambient-state-name.d.ts +14 -22
  56. package/dataflow/environments/ambient-state-name.js +4 -18
  57. package/dataflow/environments/apply-kill.d.ts +9 -20
  58. package/dataflow/environments/apply-kill.js +51 -25
  59. package/dataflow/environments/built-in-config.d.ts +7 -15
  60. package/dataflow/environments/built-in-config.js +15 -16
  61. package/dataflow/environments/built-in-eval-name.d.ts +5 -6
  62. package/dataflow/environments/built-in-eval-name.js +4 -5
  63. package/dataflow/environments/built-in-kinds.d.ts +111 -0
  64. package/dataflow/environments/built-in-kinds.js +35 -0
  65. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  66. package/dataflow/environments/built-in-proc-name.js +11 -0
  67. package/dataflow/environments/built-in-props.d.ts +62 -175
  68. package/dataflow/environments/built-in-props.js +42 -154
  69. package/dataflow/environments/built-in.d.ts +37 -73
  70. package/dataflow/environments/built-in.js +41 -62
  71. package/dataflow/environments/data-masking-functions.d.ts +2 -2
  72. package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
  73. package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
  74. package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
  75. package/dataflow/environments/default-builtin-config/base-language.js +66 -0
  76. package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
  77. package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
  78. package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
  79. package/dataflow/environments/default-builtin-config/database-access.js +16 -0
  80. package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
  81. package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
  82. package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
  83. package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
  84. package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
  85. package/dataflow/environments/default-builtin-config/file-io.js +81 -0
  86. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
  87. package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
  88. package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
  89. package/dataflow/environments/default-builtin-config/index.js +114 -0
  90. package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
  91. package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
  92. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
  93. package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
  94. package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
  95. package/dataflow/environments/default-builtin-config/network-access.js +47 -0
  96. package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
  97. package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
  98. package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
  99. package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
  100. package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
  101. package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
  102. package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
  103. package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
  104. package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
  105. package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
  106. package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
  107. package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
  108. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
  109. package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
  110. package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
  111. package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
  112. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
  113. package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
  114. package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
  115. package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
  116. package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
  117. package/dataflow/environments/default-builtin-config/statistics.js +32 -0
  118. package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
  119. package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
  120. package/dataflow/environments/environment.d.ts +28 -52
  121. package/dataflow/environments/environment.js +24 -71
  122. package/dataflow/environments/group-generics.d.ts +12 -19
  123. package/dataflow/environments/group-generics.js +17 -14
  124. package/dataflow/environments/identifier.d.ts +72 -427
  125. package/dataflow/environments/identifier.js +34 -145
  126. package/dataflow/environments/pkg-name.d.ts +197 -0
  127. package/dataflow/environments/pkg-name.js +3 -0
  128. package/dataflow/environments/query-fn-props.d.ts +27 -76
  129. package/dataflow/environments/query-fn-props.js +34 -95
  130. package/dataflow/environments/resolve-by-name.d.ts +6 -16
  131. package/dataflow/environments/resolve-by-name.js +23 -35
  132. package/dataflow/environments/scoping.d.ts +5 -5
  133. package/dataflow/environments/scoping.js +13 -5
  134. package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
  135. package/dataflow/eval/resolve/alias-tracking.js +611 -126
  136. package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
  137. package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
  138. package/dataflow/eval/resolve/resolve-argument.js +25 -30
  139. package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
  140. package/dataflow/eval/resolve/resolve-field.js +127 -0
  141. package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
  142. package/dataflow/eval/resolve/resolve-replacement.js +80 -0
  143. package/dataflow/eval/resolve/resolve-strings.d.ts +2 -2
  144. package/dataflow/eval/resolve/resolve.d.ts +13 -10
  145. package/dataflow/eval/resolve/resolve.js +81 -32
  146. package/dataflow/eval/values/general.d.ts +6 -24
  147. package/dataflow/eval/values/general.js +12 -29
  148. package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
  149. package/dataflow/eval/values/lists/list-constants.js +65 -0
  150. package/dataflow/eval/values/r-value.d.ts +20 -23
  151. package/dataflow/eval/values/r-value.js +22 -17
  152. package/dataflow/extractor.d.ts +2 -10
  153. package/dataflow/extractor.js +100 -46
  154. package/dataflow/fn/argument-roles.d.ts +2 -4
  155. package/dataflow/fn/argument-roles.js +49 -23
  156. package/dataflow/fn/class-declaration.d.ts +36 -52
  157. package/dataflow/fn/class-declaration.js +22 -56
  158. package/dataflow/fn/condition-handlers.d.ts +2 -1
  159. package/dataflow/fn/dispatch.d.ts +70 -0
  160. package/dataflow/fn/dispatch.js +434 -0
  161. package/dataflow/fn/exceptions-of-function.d.ts +1 -2
  162. package/dataflow/fn/exceptions-of-function.js +36 -106
  163. package/dataflow/fn/frame-reflection.d.ts +1 -3
  164. package/dataflow/fn/frame-reflection.js +8 -16
  165. package/dataflow/fn/function-props.d.ts +2 -5
  166. package/dataflow/fn/function-props.js +27 -36
  167. package/dataflow/fn/function-semantics.d.ts +14 -26
  168. package/dataflow/fn/function-semantics.js +4 -18
  169. package/dataflow/fn/higher-order-function.js +2 -4
  170. package/dataflow/fn/strict-function.d.ts +10 -35
  171. package/dataflow/fn/strict-function.js +126 -138
  172. package/dataflow/graph/ambient-access.d.ts +51 -0
  173. package/dataflow/graph/ambient-access.js +80 -0
  174. package/dataflow/graph/call-graph.d.ts +9 -29
  175. package/dataflow/graph/call-graph.js +17 -41
  176. package/dataflow/graph/closure-frames.d.ts +46 -0
  177. package/dataflow/graph/closure-frames.js +225 -0
  178. package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
  179. package/dataflow/graph/dataflowgraph-builder.js +29 -97
  180. package/dataflow/graph/df-helper.d.ts +48 -188
  181. package/dataflow/graph/df-helper.js +107 -208
  182. package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
  183. package/dataflow/graph/diff-dataflow-graph.js +25 -25
  184. package/dataflow/graph/edge.js +1 -1
  185. package/dataflow/graph/graph-helper.d.ts +10 -46
  186. package/dataflow/graph/graph-helper.js +16 -50
  187. package/dataflow/graph/graph.d.ts +44 -97
  188. package/dataflow/graph/graph.js +83 -79
  189. package/dataflow/graph/match-args.d.ts +21 -88
  190. package/dataflow/graph/match-args.js +284 -97
  191. package/dataflow/graph/vertex.d.ts +101 -128
  192. package/dataflow/graph/vertex.js +23 -20
  193. package/dataflow/hooks.d.ts +7 -14
  194. package/dataflow/hooks.js +15 -13
  195. package/dataflow/info.d.ts +2 -17
  196. package/dataflow/internal/dispatch-linking.d.ts +71 -0
  197. package/dataflow/internal/dispatch-linking.js +332 -0
  198. package/dataflow/internal/linker.d.ts +48 -50
  199. package/dataflow/internal/linker.js +457 -155
  200. package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
  201. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
  202. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
  203. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
  204. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
  205. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +23 -75
  206. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +263 -97
  207. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
  208. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
  209. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
  210. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +82 -62
  211. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
  212. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
  213. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
  214. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
  215. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
  216. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
  217. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
  218. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
  219. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
  220. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
  221. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
  222. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
  223. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
  224. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
  225. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
  226. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
  227. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
  228. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
  229. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
  230. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
  231. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
  232. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
  233. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  234. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
  235. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
  236. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
  237. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
  238. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
  239. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
  240. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
  241. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
  242. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
  243. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
  244. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
  245. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
  246. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -3
  247. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
  248. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +8 -4
  249. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
  250. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -25
  251. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +31 -35
  252. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
  253. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +13 -19
  254. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
  255. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
  256. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
  257. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +38 -30
  258. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +584 -114
  259. package/dataflow/internal/process/functions/call/common.d.ts +8 -24
  260. package/dataflow/internal/process/functions/call/common.js +24 -24
  261. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
  262. package/dataflow/internal/process/functions/call/deferred.js +6 -27
  263. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +6 -26
  264. package/dataflow/internal/process/functions/call/known-call-handling.js +6 -16
  265. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
  266. package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
  267. package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
  268. package/dataflow/internal/process/functions/call/nse.js +6 -13
  269. package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
  270. package/dataflow/internal/process/functions/call/quoted.js +26 -62
  271. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
  272. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
  273. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  274. package/dataflow/internal/program-order.d.ts +3 -10
  275. package/dataflow/internal/program-order.js +19 -10
  276. package/dataflow/origin/dfg-get-origin.js +2 -1
  277. package/documentation/data/faq/faqs.js +16 -1
  278. package/documentation/data/interface/doc-writing-code.js +5 -7
  279. package/documentation/doc-capabilities.js +3 -3
  280. package/documentation/doc-readme.js +1 -1
  281. package/documentation/doc-util/doc-code.d.ts +0 -5
  282. package/documentation/doc-util/doc-code.js +2 -22
  283. package/documentation/doc-util/doc-query.d.ts +1 -2
  284. package/documentation/doc-util/doc-query.js +4 -5
  285. package/documentation/doc-util/doc-search.js +1 -1
  286. package/documentation/wiki-analyzer.js +4 -3
  287. package/documentation/wiki-core.js +5 -5
  288. package/documentation/wiki-dataflow-graph.js +6 -0
  289. package/documentation/wiki-interface.js +2 -1
  290. package/documentation/wiki-linter.js +15 -3
  291. package/documentation/wiki-linting-and-testing.js +15 -2
  292. package/documentation/wiki-query.js +111 -29
  293. package/index.d.ts +3 -1
  294. package/index.js +6 -3
  295. package/linter/linter-executor.js +1 -1
  296. package/linter/linter-rules.d.ts +37 -8
  297. package/linter/linter-rules.js +8 -1
  298. package/linter/linter-util.d.ts +3 -3
  299. package/linter/linter-util.js +1 -1
  300. package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
  301. package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
  302. package/linter/rules/cmd-check/call-arguments.js +5 -5
  303. package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
  304. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
  305. package/linter/rules/cmd-check/dependency-declaration.js +1 -1
  306. package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
  307. package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
  308. package/linter/rules/cmd-check/file-checks.d.ts +2 -2
  309. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
  310. package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
  311. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
  312. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  313. package/linter/rules/cmd-check/package-files.d.ts +2 -2
  314. package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
  315. package/linter/rules/cmd-check/package-runtime.js +2 -2
  316. package/linter/rules/cmd-check/rd-files.js +2 -1
  317. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
  318. package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
  319. package/linter/rules/code-clones.d.ts +57 -0
  320. package/linter/rules/code-clones.js +53 -0
  321. package/linter/rules/deprecated-functions.js +3 -6
  322. package/linter/rules/file-path-validity.js +6 -4
  323. package/linter/rules/function-finder-util.d.ts +4 -2
  324. package/linter/rules/naming-convention.d.ts +6 -5
  325. package/linter/rules/naming-convention.js +2 -3
  326. package/linter/rules/no-leaked-credentials.d.ts +2 -1
  327. package/linter/rules/no-leaked-credentials.js +1 -1
  328. package/linter/rules/overwritten-file.d.ts +2 -1
  329. package/linter/rules/problematic-inputs.d.ts +2 -1
  330. package/linter/rules/problematic-inputs.js +3 -3
  331. package/linter/rules/process-state-in-session.d.ts +7 -6
  332. package/linter/rules/process-state-in-session.js +1 -1
  333. package/linter/rules/roxygen-arguments.d.ts +1 -1
  334. package/linter/rules/secret-exfiltration.js +1 -1
  335. package/linter/rules/seeded-randomness.d.ts +3 -3
  336. package/linter/rules/unclosed-connection.js +1 -2
  337. package/linter/rules/undefined-symbol-util.d.ts +3 -2
  338. package/linter/rules/undefined-symbol.d.ts +3 -2
  339. package/linter/rules/unescaped-arguments.d.ts +1 -1
  340. package/linter/rules/unescaped-arguments.js +6 -8
  341. package/linter/rules/unused-definition.d.ts +4 -3
  342. package/linter/rules/unused-definition.js +10 -12
  343. package/linter/rules/unused-import.d.ts +6 -5
  344. package/package.json +1 -1
  345. package/project/attached-packages.d.ts +5 -4
  346. package/project/cache/flowr-analyzer-cache.d.ts +14 -1
  347. package/project/cache/flowr-analyzer-cache.js +40 -3
  348. package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
  349. package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
  350. package/project/context/flowr-analyzer-environment-context.js +3 -3
  351. package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
  352. package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
  353. package/project/context/flowr-analyzer-gas-context.js +34 -4
  354. package/project/dependency-version-space.d.ts +30 -29
  355. package/project/dependency-version-space.js +1 -2
  356. package/project/flowr-analyzer-builder.d.ts +2 -3
  357. package/project/flowr-analyzer.d.ts +35 -3
  358. package/project/flowr-analyzer.js +11 -5
  359. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -14
  360. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
  361. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
  362. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
  363. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
  364. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
  365. package/project/plugins/package-version-plugins/package.d.ts +6 -5
  366. package/project/sigdb/build.js +1 -1
  367. package/project/sigdb/decode.d.ts +8 -7
  368. package/project/sigdb/decode.js +1 -2
  369. package/project/sigdb/dict.d.ts +2 -1
  370. package/project/sigdb/dict.js +2 -2
  371. package/project/sigdb/index-format.d.ts +2 -1
  372. package/project/sigdb/manifest.d.ts +1 -1
  373. package/project/sigdb/memory-source.d.ts +18 -17
  374. package/project/sigdb/on-demand/package-sources.d.ts +4 -3
  375. package/project/sigdb/on-demand/recoverer.d.ts +2 -1
  376. package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
  377. package/project/sigdb/reader.d.ts +85 -80
  378. package/project/sigdb/reader.js +0 -4
  379. package/project/sigdb/schema.d.ts +9 -8
  380. package/project/sigdb/signature-db.d.ts +6 -6
  381. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
  382. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
  383. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
  384. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
  385. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
  386. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  387. package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
  388. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
  389. package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
  390. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
  391. package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
  392. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
  393. package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
  394. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
  395. package/queries/catalog/dependencies-query/dependencies-query-executor.js +5 -5
  396. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -2
  397. package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
  398. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
  399. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  400. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -0
  401. package/queries/catalog/dice-query/dice-query-format.js +1 -0
  402. package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
  403. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
  404. package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
  405. package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
  406. package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
  407. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
  408. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
  409. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
  410. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
  411. package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
  412. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
  413. package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
  414. package/queries/catalog/linter-query/linter-query-executor.js +4 -1
  415. package/queries/catalog/linter-query/linter-query-format.js +3 -2
  416. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
  417. package/queries/catalog/origin-query/origin-query-format.js +1 -0
  418. package/queries/catalog/project-query/project-query-format.d.ts +2 -1
  419. package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
  420. package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
  421. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
  422. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
  423. package/queries/catalog/signature-query/signature-query-executor.d.ts +9 -6
  424. package/queries/catalog/signature-query/signature-query-executor.js +14 -15
  425. package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
  426. package/queries/catalog/signature-query/signature-query-render.js +1 -1
  427. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  428. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
  429. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  430. package/queries/query-function-filter.d.ts +1 -1
  431. package/queries/query.d.ts +59 -8
  432. package/queries/query.js +59 -37
  433. package/r-bridge/data/data.d.ts +39 -28
  434. package/r-bridge/data/data.js +37 -28
  435. package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
  436. package/r-bridge/lang-4.x/ast/model/model.js +30 -0
  437. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
  438. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
  439. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  440. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
  441. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
  442. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  443. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  444. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  445. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  446. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
  447. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  448. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  449. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  450. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  451. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  452. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  453. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  454. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  455. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  456. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
  457. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
  458. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  459. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
  460. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
  461. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  462. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
  463. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
  464. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
  465. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
  466. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
  467. package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
  468. package/r-bridge/lang-4.x/ast/model/type.js +1 -1
  469. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
  470. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
  471. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  472. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
  473. package/r-bridge/parser.d.ts +8 -2
  474. package/r-bridge/parser.js +6 -0
  475. package/r-bridge/shell-executor.d.ts +2 -2
  476. package/r-bridge/shell-executor.js +3 -2
  477. package/r-bridge/shell.d.ts +2 -2
  478. package/r-bridge/shell.js +3 -2
  479. package/reconstruct/auto-select/magic-comments.js +1 -1
  480. package/reconstruct/reconstruct.d.ts +0 -5
  481. package/reconstruct/reconstruct.js +6 -5
  482. package/search/flowr-search-builder.d.ts +14 -0
  483. package/search/flowr-search-builder.js +7 -0
  484. package/search/flowr-search-executor.js +2 -2
  485. package/search/flowr-search-filters.js +8 -9
  486. package/search/flowr-search.js +1 -1
  487. package/search/search-executor/search-enrichers.d.ts +2 -0
  488. package/search/search-executor/search-enrichers.js +6 -1
  489. package/search/search-executor/search-generators.d.ts +2 -2
  490. package/search/search-executor/search-generators.js +13 -8
  491. package/search/search-executor/search-mappers.js +1 -1
  492. package/search/search-executor/search-transformer.d.ts +2 -2
  493. package/search/search-executor/search-transformer.js +6 -6
  494. package/slicing/criterion/parse.d.ts +2 -1
  495. package/slicing/criterion/parse.js +2 -1
  496. package/slicing/static/removal-slice.js +2 -1
  497. package/slicing/static/slice-call.d.ts +30 -4
  498. package/slicing/static/slice-call.js +74 -9
  499. package/slicing/static/slicer-types.d.ts +2 -1
  500. package/slicing/static/static-slicer.js +66 -11
  501. package/slicing/static/visiting-queue.d.ts +2 -0
  502. package/slicing/static/visiting-queue.js +4 -0
  503. package/taint-analysis/builder/report-template.d.ts +3 -3
  504. package/util/arg-matching.d.ts +1 -1
  505. package/util/collections/relation.d.ts +23 -0
  506. package/util/collections/relation.js +63 -0
  507. package/util/fixpoint.d.ts +65 -0
  508. package/util/fixpoint.js +216 -0
  509. package/util/flowr-version.d.ts +1 -1
  510. package/util/flowr-version.js +2 -2
  511. package/util/json.d.ts +4 -0
  512. package/util/json.js +12 -3
  513. package/util/mermaid/cfg.js +1 -2
  514. package/util/mermaid/dfg.d.ts +1 -1
  515. package/util/mermaid/dfg.js +1 -1
  516. package/util/mermaid/mermaid.d.ts +2 -1
  517. package/util/monoid.d.ts +26 -0
  518. package/util/monoid.js +31 -0
  519. package/util/prefix.d.ts +1 -1
  520. package/util/r-base-packages.d.ts +10 -7
  521. package/util/r-base-packages.js +11 -6
  522. package/util/r-package-urls.d.ts +10 -9
  523. package/util/r-value.js +2 -1
  524. package/util/r-version-order.d.ts +2 -0
  525. package/util/r-version-order.js +19 -0
  526. package/util/r-version.d.ts +2 -1
  527. package/util/r-version.js +2 -14
  528. package/util/range.d.ts +38 -29
  529. package/util/range.js +10 -5
  530. package/util/simple-df/dfg-ascii.js +2 -2
  531. package/util/text/ansi.d.ts +13 -9
  532. package/util/text/ansi.js +4 -6
  533. package/util/text/strings.d.ts +10 -3
  534. package/util/text/strings.js +10 -1
  535. package/util/version.d.ts +1 -1
  536. package/util/version.js +2 -1
  537. package/dataflow/environments/default-builtin-config.d.ts +0 -8874
  538. package/dataflow/environments/default-builtin-config.js +0 -1737
  539. package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
  540. package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
  541. package/taint-analysis/eval/eval.d.ts +0 -1
  542. package/taint-analysis/eval/eval.js +0 -124
  543. package/taint-analysis/eval/instrumentation.d.ts +0 -59
  544. package/taint-analysis/eval/instrumentation.js +0 -124
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processFunctionDefinition = processFunctionDefinition;
4
4
  exports.retrieveActiveEnvironment = retrieveActiveEnvironment;
5
5
  exports.updateNestedFunctionClosures = updateNestedFunctionClosures;
6
+ exports.callBoundInScope = callBoundInScope;
6
7
  exports.updateNestedFunctionCalls = updateNestedFunctionCalls;
7
8
  const processor_1 = require("../../../../../processor");
8
9
  const function_semantics_1 = require("../../../../../fn/function-semantics");
10
+ const common_1 = require("../common");
9
11
  const control_flow_1 = require("../../../../control-flow");
10
12
  const info_1 = require("../../../../../info");
11
13
  const linker_1 = require("../../../../linker");
14
+ const built_in_deferred_env_ops_1 = require("./built-in-deferred-env-ops");
12
15
  const known_call_handling_1 = require("../known-call-handling");
13
16
  const assert_1 = require("../../../../../../util/assert");
14
17
  const logger_1 = require("../../../../../logger");
@@ -22,11 +25,15 @@ const program_order_1 = require("../../../../program-order");
22
25
  const graph_1 = require("../../../../../graph/graph");
23
26
  const identifier_1 = require("../../../../../environments/identifier");
24
27
  const vertex_1 = require("../../../../../graph/vertex");
28
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
29
+ const dispatch_1 = require("../../../../../fn/dispatch");
25
30
  const class_declaration_1 = require("../../../../../fn/class-declaration");
31
+ const dispatch_linking_1 = require("../../../../dispatch-linking");
26
32
  const built_in_new_env_1 = require("./built-in-new-env");
27
33
  const environment_1 = require("../../../../../environments/environment");
28
34
  const edge_1 = require("../../../../../graph/edge");
29
35
  const built_in_library_1 = require("./built-in-library");
36
+ const built_in_get_1 = require("./built-in-get");
30
37
  const r_number_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-number");
31
38
  const hooks_1 = require("../../../../../hooks");
32
39
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
@@ -34,6 +41,7 @@ const resolve_helper_1 = require("../../../../../environments/resolve-helper");
34
41
  const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
35
42
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
36
43
  const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
44
+ const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
37
45
  const r_parameter_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
38
46
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
39
47
  const query_fn_props_1 = require("../../../../../environments/query-fn-props");
@@ -43,9 +51,7 @@ const group_generics_1 = require("../../../../../environments/group-generics");
43
51
  const arg_matching_1 = require("../../../../../../util/arg-matching");
44
52
  const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
45
53
  const df_helper_1 = require("../../../../../graph/df-helper");
46
- /**
47
- * Process a function definition, i.e., `function(a, b) { ... }`
48
- */
54
+ /** Process a function definition, i.e., `function(a, b) { ... }` */
49
55
  function processFunctionDefinition(name, args, rootId, data) {
50
56
  if (args.length < 1) {
51
57
  logger_1.dataflowLogger.warn(`Function Definition ${identifier_1.Identifier.toString(name.content)} does not have an argument, skipping`);
@@ -146,7 +152,7 @@ function processFunctionDefinition(name, args, rootId, data) {
146
152
  }, data.ctx.env.cleanEnv);
147
153
  }
148
154
  }
149
- const compactedHooks = (0, hooks_1.compactHookStates)(body.hooks);
155
+ const compactedHooks = (0, hooks_1.compactHookStates)(body.hooks).filter(h => vertex_1.DfgVertex.isFunctionDefinition(subgraph.getVertex(h.id)));
150
156
  /* a jump in a default leaves the function from where the parameter is first used */
151
157
  const exitPoints = body.exitPoints.concat(processedParameters.flatMap(p => p.exitPoints.filter(e => e.type !== 0 /* ExitPointType.Default */)));
152
158
  let afterHookExitPoints = exitPoints.filter(e => e.type === 1 /* ExitPointType.Return */ || e.type === 0 /* ExitPointType.Default */ || e.type === 4 /* ExitPointType.Error */);
@@ -170,7 +176,8 @@ function processFunctionDefinition(name, args, rootId, data) {
170
176
  while (hookEnvironment.level > outEnvironment.level) {
171
177
  hookEnvironment = environment_1.REnvironment.popLocal(hookEnvironment);
172
178
  }
173
- outEnvironment = environment_1.REnvironment.overwrite(outEnvironment, hookEnvironment);
179
+ /* a hook registered under a condition may not run, so its writes join what the body leaves behind */
180
+ outEnvironment = environment_1.REnvironment.overwrite(outEnvironment, hookEnvironment, (0, info_1.happensInEveryBranch)(hook.cds) ? undefined : hook.cds);
174
181
  /* the jumps and errors of an exit hook overrule the exit points of the body */
175
182
  subgraph.addEdge(rootId, hook.id, edge_1.EdgeType.Calls);
176
183
  const hookExitPoints = vert.exitPoints.filter(e => e.type === 1 /* ExitPointType.Return */ || e.type === 4 /* ExitPointType.Error */);
@@ -211,6 +218,7 @@ function processFunctionDefinition(name, args, rootId, data) {
211
218
  const returnEnvState = data.ctx.config.solver.trackEnvironments
212
219
  ? afterHookExitPoints.values().map(({ nodeId }) => envStateReturnedAt(nodeId, subgraph, outEnvironment, data)).find(assert_1.isNotUndefined)
213
220
  : undefined;
221
+ const envOps = (0, built_in_deferred_env_ops_1.deferredEnvOps)(flow.graph, subgraph, data);
214
222
  const graph = new graph_1.DataflowGraph(idMap).mergeWith(subgraph, false, true);
215
223
  graph.addVertex({
216
224
  tag: vertex_1.VertexType.FunctionDefinition,
@@ -220,7 +228,8 @@ function processFunctionDefinition(name, args, rootId, data) {
220
228
  params: readParams,
221
229
  subflow: flow,
222
230
  exitPoints: afterHookExitPoints,
223
- returnEnvState
231
+ returnEnvState,
232
+ ...envOps === undefined ? {} : { envOps }
224
233
  }, data.ctx.env.cleanEnv);
225
234
  return {
226
235
  unknownReferences: [],
@@ -246,15 +255,9 @@ function envStateReturnedAt(nodeId, graph, outEnvironment, data) {
246
255
  return undefined;
247
256
  }
248
257
  const environment = { environment: outEnvironment };
249
- const fromList = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? (0, built_in_list_1.resolveListToEnvState)(node, environment) : undefined;
250
- if (fromList) {
251
- return fromList;
252
- }
253
- const fromClass = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.ClassGenerator) ? (0, built_in_class_generator_1.resolveClassMethodsToEnvState)(node, environment) : undefined;
254
- if (fromClass) {
255
- return fromClass;
256
- }
257
- return r_symbol_1.RSymbol.is(node) ? resolve_helper_1.Resolve.byNameAndType(node.content, outEnvironment, identifier_1.ReferenceType.Variable)?.find(identifier_1.hasEnvState)?.envState : undefined;
258
+ return (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? (0, built_in_list_1.resolveListToEnvState)(node, environment) : undefined)
259
+ ?? (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.ClassGenerator) ? (0, built_in_class_generator_1.resolveClassMethodsToEnvState)(node, environment) : undefined)
260
+ ?? (r_symbol_1.RSymbol.is(node) ? resolve_helper_1.Resolve.byNameAndType(node.content, outEnvironment, identifier_1.ReferenceType.Variable)?.find(identifier_1.hasEnvState)?.envState : undefined);
258
261
  }
259
262
  /** Retrieve the active environment when entering a function definition or call. */
260
263
  function retrieveActiveEnvironment(callerEnvironment, baseEnvironment, ctx) {
@@ -267,10 +270,7 @@ function retrieveActiveEnvironment(callerEnvironment, baseEnvironment, ctx) {
267
270
  }
268
271
  return environment_1.REnvironment.overwrite(baseEnvironment, callerEnvironment);
269
272
  }
270
- /**
271
- * Whether the dispatch takes its object from the first formal, which is what R does unless the call names
272
- * the object itself (`UseMethod("f", y)`), in which case that argument carries the read already.
273
- */
273
+ /** Whether the dispatch takes its object from the first formal, which is what R does unless the call names the object itself (`UseMethod("f", y)`), in which case that argument carries the read already. */
274
274
  function dispatchesOnFirstParameter(id, idMap) {
275
275
  const enclosing = model_1.RNode.findEnclosing(id, idMap, r_function_call_1.RFunctionCall.is);
276
276
  const call = enclosing === undefined ? undefined : idMap.get(enclosing);
@@ -294,24 +294,24 @@ function updateDispatches(graph, myArgs, idMap) {
294
294
  }
295
295
  }
296
296
  }
297
- /**
298
- * Resolves `refs` (open reads of a nested definition or call) against `environment`;
299
- * `onResolved` handles each resolved reference and says whether it should stay in the returned "still open" list.
300
- */
301
- function resolveIngoingRefs(refs, environment, onResolved) {
297
+ /** Resolves `refs` (open reads of a nested definition or call) against `environment`; `onResolved` handles each resolved reference and says whether it should stay in the returned "still open" list. */
298
+ function resolveIngoingRefs(refs, environment, onResolved, method) {
299
+ let instance = null;
302
300
  return refs.filter(ingoing => {
303
- const resolved = ingoing.name ? resolve_helper_1.Resolve.byNameAndType(ingoing.name, environment, ingoing.type) : undefined;
301
+ instance ??= method?.graph.idMap === undefined ? undefined : (0, class_declaration_1.instanceBindingsOfMethod)(method.fn, method.graph, method.graph.idMap);
302
+ if (instance !== undefined && ingoing.name !== undefined && instance.includes(identifier_1.Identifier.getName(ingoing.name))) {
303
+ return true;
304
+ }
305
+ const resolved = ingoing.name ? resolve_helper_1.Resolve.byNameAndType(identifier_1.Identifier.boundAs(ingoing.name), environment, ingoing.type) : undefined;
304
306
  return resolved === undefined || onResolved(ingoing, resolved);
305
307
  });
306
308
  }
307
- /**
308
- * Links the free variables of the functions defined in `graph` to their definitions in `outEnvironment`, the scope
309
- * the functions were defined in. Call it before that scope is popped, at the end of a function body or of `local`.
310
- * Reads that `outEnvironment` does not define are added to `openReads`.
311
- */
309
+ /** Links the free variables of the functions defined in `graph` to their definitions in `outEnvironment`, the scope the functions were defined in. */
312
310
  function updateNestedFunctionClosures(graph, outEnvironment, openReads) {
313
311
  const open = new Set(openReads.map(r => r.nodeId));
314
312
  const settled = new Set();
313
+ /* reads the scope binds before their closure exists, so they never reach past the scope */
314
+ const bound = new Set();
315
315
  const superWrites = new defaultmap_1.DefaultMap(() => []);
316
316
  for (const [, { subflow }] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
317
317
  for (const [target, name] of superAssignedTargets(graph, subflow.graph)) {
@@ -319,7 +319,7 @@ function updateNestedFunctionClosures(graph, outEnvironment, openReads) {
319
319
  }
320
320
  }
321
321
  // track *all* function definitions, including those nested within, resolving their 'in' via the lowest scope (popped after this definition)
322
- for (const [, { subflow }] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
322
+ for (const [fn, { subflow }] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
323
323
  subflow.in = resolveIngoingRefs(subflow.in, outEnvironment, (ingoing, resolved) => {
324
324
  const writes = superWrites.get(ingoing.name);
325
325
  for (const ref of resolved) {
@@ -335,11 +335,14 @@ function updateNestedFunctionClosures(graph, outEnvironment, openReads) {
335
335
  if (allBuiltIn && resolved.length > 0 && !allClosureWrites) {
336
336
  settled.add(ingoing.nodeId);
337
337
  }
338
+ else if (!ambient_state_name_1.AmbientStateName.is(ingoing.name) && resolved.some(ref => boundBeforeClosure(ref.nodeId, ingoing.nodeId, graph))) {
339
+ bound.add(ingoing.nodeId);
340
+ }
338
341
  /* the state of the session (options, files, the working directory) is what it is where the function is called, so it stays open for its calls */
339
342
  return allBuiltIn || allClosureWrites || ambient_state_name_1.AmbientStateName.is(ingoing.name);
340
- });
343
+ }, { fn, graph });
341
344
  for (const ref of subflow.in) {
342
- if (ref.name !== undefined && !settled.has(ref.nodeId) && !open.has(ref.nodeId)) {
345
+ if (ref.name !== undefined && !settled.has(ref.nodeId) && !bound.has(ref.nodeId) && !open.has(ref.nodeId)) {
343
346
  open.add(ref.nodeId);
344
347
  openReads.push(ref);
345
348
  }
@@ -352,10 +355,33 @@ function updateNestedFunctionClosures(graph, outEnvironment, openReads) {
352
355
  }
353
356
  }
354
357
  }
358
+ if (bound.size > 0) {
359
+ const kept = openReads.filter(r => !bound.has(r.nodeId));
360
+ openReads.length = 0;
361
+ openReads.push(...kept);
362
+ }
363
+ }
364
+ /** Whether an enclosing scope binds the name of a call within a closure before the closure exists, see {@link boundBeforeClosure}: then the call reaches only what its reads do, and never looks further out, whatever the end of the script binds there. */
365
+ function callBoundInScope(call, graph) {
366
+ return !graph.isRoot(call) && df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Reads).some(r => boundBeforeClosure(r, call, graph));
367
+ }
368
+ /** Whether the local definition `def` is made before the closure holding the read `read` is created, on every way there: `h <- function() 2; g <- function() h()` binds `h` in the scope before `g` exists, so no call of `g` looks past the scope for it. */
369
+ function boundBeforeClosure(def, read, graph) {
370
+ const idMap = graph.idMap;
371
+ const node = idMap?.get(def);
372
+ const assignment = node?.info.parent === undefined ? undefined : idMap?.get(node.info.parent);
373
+ const block = assignment?.info.parent === undefined ? undefined : idMap?.get(assignment.info.parent);
374
+ if (idMap === undefined || assignment === undefined || !r_expression_list_1.RExpressionList.is(block)
375
+ || !vertex_1.DfgVertex.hasOrigin(graph.getVertex(assignment.info.id), built_in_proc_name_1.BuiltInProcName.Assignment)) {
376
+ return false;
377
+ }
378
+ const statement = [idMap.get(read), ...model_1.RNode.iterateParents(idMap.get(read), idMap)].find(p => p?.info.parent === block.info.id);
379
+ return statement !== undefined && statement.info.index > assignment.info.index
380
+ && model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is) !== model_1.RNode.findEnclosing(statement.info.id, idMap, r_function_definition_1.RFunctionDefinition.is);
355
381
  }
356
382
  function* superAssignedTargets(graph, nodes) {
357
383
  for (const nodeId of nodes) {
358
- if (!vertex_1.DfgVertex.hasOrigin(graph.getVertex(nodeId), built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
384
+ if (!df_helper_1.Dataflow.superAssigns(graph, nodeId)) {
359
385
  continue;
360
386
  }
361
387
  for (const target of df_helper_1.Dataflow.targetsOf(graph, nodeId, edge_1.EdgeType.Returns)) {
@@ -366,16 +392,18 @@ function* superAssignedTargets(graph, nodes) {
366
392
  }
367
393
  }
368
394
  }
369
- /**
370
- * The names the analyzed code binds that a built-in also goes by, so a call that resolved to only that built-in
371
- * may still land on one of them: a body looks its callee up when it runs, not when it is written.
372
- */
373
- function namesShadowingBuiltIns(environment) {
395
+ /** The names the analyzed code binds that a built-in also goes by, so a call that resolved to only that built-in may still land on one of them: a body looks its callee up when it runs, not when it is written. */
396
+ function namesShadowingBuiltIns(environment, graph) {
374
397
  const shadowing = new Set();
375
398
  const generics = new Set();
399
+ /* `as.character.zz` may be a method of `as` or of `as.character`, so every prefix is a candidate */
400
+ const methodOf = (name) => {
401
+ for (let dot = name.indexOf('.', 1); dot > 0; dot = name.indexOf('.', dot + 1)) {
402
+ generics.add(name.slice(0, dot));
403
+ }
404
+ };
376
405
  for (const env of environment_1.REnvironment.frames(environment.current)) {
377
- /* an attached package may shadow a built-in a function body bound to before it was attached; its keys
378
- * suffice, building the definitions of every export would be costly */
406
+ /* an attached package may shadow a built-in a function body bound to before it was attached; its keys suffice, building the definitions of every export would be costly */
379
407
  if (env.t === environment_1.EnvType.Namespace) {
380
408
  for (const identifier of env.memory.keys()) {
381
409
  shadowing.add(identifier_1.Identifier.getName(identifier));
@@ -383,17 +411,19 @@ function namesShadowingBuiltIns(environment) {
383
411
  continue;
384
412
  }
385
413
  for (const [identifier, definitions] of env.memory) {
386
- if (definitions.every(d => node_id_1.NodeId.isBuiltIn(d.nodeId))) {
387
- continue;
388
- }
389
- const name = identifier_1.Identifier.getName(identifier);
390
- shadowing.add(name);
391
- /* `as.character.zz` may be a method of `as` or of `as.character`, so every prefix is a candidate */
392
- for (let dot = name.indexOf('.', 1); dot > 0; dot = name.indexOf('.', dot + 1)) {
393
- generics.add(name.slice(0, dot));
414
+ if (!definitions.every(d => node_id_1.NodeId.isBuiltIn(d.nodeId))) {
415
+ shadowing.add(identifier_1.Identifier.getName(identifier));
416
+ methodOf(identifier_1.Identifier.getName(identifier));
394
417
  }
395
418
  }
396
419
  }
420
+ /* a method a function binds in its own frame is seen by the dispatches within it */
421
+ for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
422
+ const name = graph.isRoot(id) ? undefined : node_id_1.NodeId.recoverBareName(id, graph.idMap);
423
+ if (name !== undefined) {
424
+ methodOf(name);
425
+ }
426
+ }
397
427
  return { shadowing, generics };
398
428
  }
399
429
  function fnPropsOf(name, environment, infoOf) {
@@ -405,35 +435,36 @@ function dispatchesOnClass(name, environment, infoOf) {
405
435
  const props = fnPropsOf(name, environment, infoOf);
406
436
  return props === undefined ? resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Function) === undefined : built_in_props_1.CallProps.hasAny(props, built_in_props_1.CallProp.Generic);
407
437
  }
408
- /**
409
- * Links `call` to the S3 methods the analyzed code binds as `<name>.<class>`, returning their definition vertices.
410
- * Unless {@link dispatchedS3Methods} knows the class, every such method counts, same as the {@link BuiltInProcName.S3Dispatch} path.
411
- */
438
+ /** Links `call` to the S3 methods the analyzed code binds as `<name>.<class>`, returning their definition vertices and the dispatched objects. */
412
439
  function linkOwnS3Methods(call, name, graph, environment, statement, ctx, infoOf) {
413
- const defs = resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.S3MethodPrefix)
414
- ?.filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId) && !program_order_1.ProgramOrder.definedLater(d.nodeId, statement, graph));
415
- if (defs === undefined || defs.length === 0) {
416
- return [];
440
+ const defs = s3MethodPrefixesOf(name).flatMap(prefix => resolve_helper_1.Resolve.byNameAndType(prefix, environment, identifier_1.ReferenceType.S3MethodPrefix) ?? [])
441
+ .filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId) && !program_order_1.ProgramOrder.definedLater(d.nodeId, statement, graph));
442
+ if (defs.length === 0) {
443
+ return { methods: [] };
417
444
  }
418
- const dispatched = dispatchedS3Methods(call, name, defs, graph, environment, statement, ctx, infoOf) ?? defs;
419
- for (const def of dispatched) {
445
+ const dispatched = dispatchedS3Methods(call, name, defs, graph, environment, statement, ctx, infoOf);
446
+ const chosen = dispatched?.methods ?? defs;
447
+ for (const def of chosen) {
420
448
  /* the dispatch looks the method up by name, just like a call written out would */
421
449
  graph.addEdge(call.id, def.nodeId, edge_1.EdgeType.Reads);
422
450
  }
423
- return linkedFunctionIds(dispatched, graph);
451
+ return { methods: (0, dispatch_linking_1.linkedFunctionIds)(new Set(chosen.map(d => d.nodeId)), graph), objects: dispatched?.objects };
424
452
  }
425
- function linkedFunctionIds(defs, graph) {
426
- return (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(defs.map(d => d.nodeId)), graph)[0].values().map(d => d.id).toArray();
453
+ /** The names whose `<name>.<class>` methods a call of `name` may dispatch to: its own and that of the S3 group generic it is a member of. */
454
+ function s3MethodPrefixesOf(name) {
455
+ const plain = identifier_1.Identifier.getName(name);
456
+ const group = (0, group_generics_1.s3GroupGenericOf)(plain);
457
+ return group === undefined ? [plain] : [plain, group];
427
458
  }
428
- /**
429
- * The `methods` a call dispatches to per known class of its dispatch object (then `default`), stopping for a top-level call at one surely bound before it;
430
- * `undefined` if the class is unknown or a method may `NextMethod()`.
431
- */
432
- function dispatchedS3Methods(call, name, methods, graph, environment, statement, ctx, infoOf) {
433
- const generic = identifier_1.Identifier.getName(name);
434
- const node = graph.idMap?.get(call.id);
435
- const first = call.args[0];
436
- if (graph.idMap === undefined || !r_function_call_1.RFunctionCall.is(node) || first === r_function_call_1.EmptyArgument || first === undefined || (call.args.length > 1 && (0, group_generics_1.groupGenericOf)(generic) !== undefined)) {
459
+ /** The arguments the S3 dispatch of a call of a built-in generic looks at the class of, `undefined` if they are not clear. */
460
+ function dispatchedArgumentsOf(call, node, name, graph, environment, ctx, infoOf) {
461
+ const args = call.args.filter(a => a !== r_function_call_1.EmptyArgument);
462
+ if ((0, group_generics_1.groupGenericOf)(identifier_1.Identifier.getName(name)) !== undefined && call.args.length > 1) {
463
+ /* a group generic of two operands dispatches on the class of either */
464
+ return call.args.length === 2 && args.length === 2 ? args.map(a => a.nodeId) : undefined;
465
+ }
466
+ const first = args[0];
467
+ if (!r_function_call_1.RFunctionCall.is(node)) {
437
468
  return undefined;
438
469
  }
439
470
  const formals = function_semantics_1.FunctionSemantics.call.match.formalsOf(node, graph, ctx);
@@ -444,82 +475,293 @@ function dispatchedS3Methods(call, name, methods, graph, environment, statement,
444
475
  /* a closure dispatches on what binds its first formal, a primitive (or anything else) may on the first argument given */
445
476
  const props = fnPropsOf(name, environment, infoOf);
446
477
  const closure = bound !== undefined && props !== undefined && !built_in_props_1.CallProps.hasAny(props, built_in_props_1.CallProp.Primitive);
447
- const classes = new Set(closure ? bound : [first.nodeId, ...bound ?? []]).values().map(a => (0, class_declaration_1.s3DispatchClassesOf)(a, { graph, idMap: graph.idMap, ctx })).toArray();
448
- if (!classes.every(assert_1.isNotUndefined)) {
478
+ return (0, arrays_1.uniqueArray)(closure ? bound : [first.nodeId, ...bound ?? []]);
479
+ }
480
+ /** The `methods` a call dispatches to per known class of its dispatch object (then `default`), stopping for a top-level call at one surely bound before it unless a method may `NextMethod()`, with the objects dispatched on; without methods if a class is unknown, `undefined` if the objects are. */
481
+ function dispatchedS3Methods(call, name, methods, graph, environment, statement, ctx, infoOf) {
482
+ const node = graph.idMap?.get(call.id);
483
+ const first = call.args[0];
484
+ if (graph.idMap === undefined || first === r_function_call_1.EmptyArgument || first === undefined) {
449
485
  return undefined;
450
486
  }
451
- const picked = new Set();
452
- for (const cls of classes.flat()) {
453
- for (const c of [...cls, 'default']) {
454
- const found = methods.filter(m => m.name === undefined || identifier_1.Identifier.getName(m.name) === `${generic}.${c}`);
455
- found.forEach(m => picked.add(m));
456
- if (statement !== undefined && found.some(m => m.name !== undefined && m.cds === undefined && program_order_1.ProgramOrder.offset(m.nodeId, statement, graph) < 0)) {
457
- break;
487
+ const dispatched = dispatchedArgumentsOf(call, node, name, graph, environment, ctx, infoOf);
488
+ if (dispatched === undefined) {
489
+ return undefined;
490
+ }
491
+ const perArgument = dispatched.map(a => (0, dispatch_1.s3DispatchClassesOf)(a, { graph, idMap: graph.idMap, ctx }));
492
+ if (!perArgument.every(assert_1.isNotUndefined)) {
493
+ return { objects: dispatched };
494
+ }
495
+ const classes = perArgument.flat();
496
+ const prefixes = s3MethodPrefixesOf(name);
497
+ const pick = (stopAt) => {
498
+ const picked = new Set();
499
+ for (const cls of classes) {
500
+ for (const c of [...cls, 'default']) {
501
+ const found = methods.filter(m => m.name === undefined || prefixes.some(p => identifier_1.Identifier.getName(m.name) === `${p}.${c}`));
502
+ found.forEach(m => picked.add(m));
503
+ if (stopAt !== undefined && found.some(m => m.name !== undefined && m.cds === undefined && program_order_1.ProgramOrder.offset(m.nodeId, stopAt, graph) < 0)) {
504
+ break;
505
+ }
458
506
  }
459
507
  }
508
+ return picked;
509
+ };
510
+ const picked = pick(statement);
511
+ const callsNext = (0, dispatch_linking_1.linkedFunctionIds)(new Set([...picked].map(d => d.nodeId)), graph).some(d => (0, dispatch_linking_1.callsNextMethod)(d, graph));
512
+ /* a next method continues along the class vector past where the dispatch stops */
513
+ return { methods: [...callsNext ? pick(undefined) : picked], objects: dispatched };
514
+ }
515
+ /** The definitions `ingoing` resolves to, without those binding only methods the dispatch reading them rules out. */
516
+ function withoutExcludedMethods(ingoing, resolved, graph) {
517
+ const excludes = graph.getVertex(ingoing.nodeId)?.ruledOut;
518
+ if (excludes === undefined) {
519
+ return resolved;
460
520
  }
461
- const callsNext = linkedFunctionIds([...picked], graph).some(d => {
462
- const v = graph.getVertex(d);
463
- return vertex_1.DfgVertex.isFunctionDefinition(v) && df_helper_1.Dataflow.callsIn(v, graph).some(([, c]) => vertex_1.DfgVertex.hasOrigin(c, built_in_proc_name_1.BuiltInProcName.S3DispatchNext));
521
+ return resolved.filter(d => {
522
+ const methods = (0, dispatch_linking_1.linkedFunctionIds)(new Set([d.nodeId]), graph);
523
+ return methods.length === 0 || methods.some(m => !excludes.includes(m));
464
524
  });
465
- return callsNext ? undefined : [...picked];
525
+ }
526
+ const NextMethodId = node_id_1.NodeId.toBuiltIn('NextMethod');
527
+ /** The object an S3 dispatch of a generic's body reads: the one `UseMethod("f", y)` names, else the first argument the generic is handed. */
528
+ function dispatchedObjectOf(vertex, graph) {
529
+ const call = graph.idMap === undefined ? undefined : graph.idMap.get(model_1.RNode.findEnclosing(vertex.id, graph.idMap, r_function_call_1.RFunctionCall.is) ?? '');
530
+ /* `UseMethod("f", y)` dispatches on `y`, while `NextMethod` dispatches on the class vector of the method it is in */
531
+ if (r_function_call_1.RFunctionCall.is(call) && call.arguments.length > 1 && df_helper_1.Dataflow.targetsOf(graph, call.info.id, edge_1.EdgeType.Calls).includes(node_id_1.NodeId.toBuiltIn('UseMethod'))) {
532
+ const object = function_semantics_1.FunctionSemantics.call.match.toSpec((0, common_1.convertFnArguments)(call.arguments), { generic: 'generic', object: 'object' }).get('object');
533
+ return object?.length === 1 ? object[0] : undefined;
534
+ }
535
+ const first = vertex.args[0];
536
+ if (first === undefined || first === r_function_call_1.EmptyArgument || !df_helper_1.Dataflow.hasEdge(graph, vertex.id, first.nodeId, edge_1.EdgeType.Reads)) {
537
+ return undefined;
538
+ }
539
+ /* the dispatch sees the value the parameter holds then, which a body binding it anew (`class(x) <- "b"`) changes */
540
+ const fn = graph.getVertex(graph.idMap === undefined ? '' : model_1.RNode.strictlyEnclosingFunction(vertex.id, graph.idMap) ?? '');
541
+ const name = node_id_1.NodeId.recoverBareName(first.nodeId, graph.idMap);
542
+ const rebound = vertex_1.DfgVertex.isFunctionDefinition(fn) && fn.subflow.graph.values().some(id => id !== first.nodeId && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(id)) && node_id_1.NodeId.recoverBareName(id, graph.idMap) === name);
543
+ return rebound ? undefined : first.nodeId;
544
+ }
545
+ /** What the dispatch of `vertex` among `targets` rules out, S3 on the objects `s3Objects` and S4 on the classes of its arguments. */
546
+ function narrowedDispatchOf(narrower, vertex, s3Objects, targets, definedLater, info) {
547
+ const name = identifier_1.Identifier.getName(vertex.name);
548
+ const s3 = s3Objects === undefined ? undefined : narrower.s3(s3Objects, s3MethodPrefixesOf(vertex.name), targets, info);
549
+ const s4 = narrower.reachesS4Method(targets) ? narrower.s4(vertex, name, targets, definedLater, info) : undefined;
550
+ if (s3 === undefined || s4 === undefined) {
551
+ return s3 ?? s4;
552
+ }
553
+ return { excluded: new Set([...s3.excluded, ...s4.excluded]), next: new Map([...s3.next, ...s4.next]), reads: s4.reads };
554
+ }
555
+ /** Links each next-method call to what it may run: the methods `next` names for the method it is in, and the methods those run in turn, or else every target of the dispatching call. */
556
+ function linkNextMethods(graph, collected, targets, next) {
557
+ const todo = [...collected];
558
+ const visited = new Set(collected.values());
559
+ for (let item = todo.pop(); item !== undefined; item = todo.pop()) {
560
+ const [call, owner] = item;
561
+ const runs = next?.get(owner);
562
+ if (runs === undefined) {
563
+ for (const target of targets) {
564
+ const targetVertex = graph.getVertex(target);
565
+ if (vertex_1.DfgVertex.isUse(targetVertex)) {
566
+ graph.addEdge(call, target, edge_1.EdgeType.Reads);
567
+ }
568
+ else if (vertex_1.DfgVertex.isFunctionDefinition(targetVertex)) {
569
+ graph.addEdge(call, target, edge_1.EdgeType.Calls);
570
+ }
571
+ }
572
+ continue;
573
+ }
574
+ for (const method of runs) {
575
+ const vertex = graph.getVertex(method);
576
+ if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
577
+ continue;
578
+ }
579
+ graph.addEdge(call, method, edge_1.EdgeType.Calls);
580
+ if (!visited.has(method)) {
581
+ visited.add(method);
582
+ for (const [inner, v] of df_helper_1.Dataflow.callsIn(vertex, graph)) {
583
+ if (vertex_1.DfgVertex.hasOrigin(v, built_in_proc_name_1.BuiltInProcName.S3DispatchNext)) {
584
+ todo.push([inner, method]);
585
+ }
586
+ }
587
+ }
588
+ }
589
+ }
590
+ }
591
+ /** A function called directly rather than by a dispatch has no dispatch to continue, so a `NextMethod("f")` within it dispatches the generic it names on the class of the first argument, running the methods after its own. */
592
+ function linkNamedNextMethods(graph, fn, nextCalls, environment, narrower, ctx) {
593
+ const definition = graph.idMap?.get(fn);
594
+ const first = r_function_definition_1.RFunctionDefinition.is(definition) ? definition.parameters[0]?.name.info.id : undefined;
595
+ for (const next of nextCalls) {
596
+ const node = graph.idMap?.get(next);
597
+ if (!r_function_call_1.RFunctionCall.is(node)) {
598
+ continue;
599
+ }
600
+ const generic = function_semantics_1.FunctionSemantics.call.match.toSpec((0, common_1.convertFnArguments)(node.arguments), { generic: 'generic', object: 'object', '...': '...' }).get('generic')?.[0];
601
+ const names = generic === undefined ? [] : node_value_1.NodeValue.knownStringsOf(generic, { graph, idMap: graph.idMap, environment, ctx });
602
+ const methods = names.flatMap(n => resolve_helper_1.Resolve.byNameAndType(n, environment, identifier_1.ReferenceType.S3MethodPrefix) ?? []).filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId));
603
+ const targets = new Set((0, dispatch_linking_1.linkedFunctionIds)(new Set(methods.map(m => m.nodeId)), graph));
604
+ const narrowed = first === undefined || targets.size === 0 ? undefined : narrower.s3([first], names, targets);
605
+ linkNextMethods(graph, new Map([[next, fn]]), targets, narrowed?.next);
606
+ }
607
+ }
608
+ /** Per context of the dispatch `dispatch` running the method `owner`, the methods the next-method call `next` within it reaches that it cannot run there: those not after `owner` in the class vectors of that context. */
609
+ function nextMethodsPerCall(next, owner, dispatch, contexts, collected, graph) {
610
+ const reached = df_helper_1.Dataflow.targetsOf(graph, next, edge_1.EdgeType.Calls).filter(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
611
+ const within = (0, dispatch_linking_1.ruledOutPerCall)(contexts, narrowed => {
612
+ const runs = narrowed?.next.get(owner);
613
+ return runs === undefined ? [] : reached.filter(r => !runs.includes(r));
614
+ });
615
+ const runsOf = (method, seen) => [{ call: dispatch, methods: [], within },
616
+ ...collected.entries().filter(([n, m]) => !seen.has(m) && df_helper_1.Dataflow.hasEdge(graph, n, method, edge_1.EdgeType.Calls))
617
+ .map(([n, m]) => ({ call: n, methods: [], within: runsOf(m, new Set([...seen, m])) }))];
618
+ return within === undefined ? undefined : runsOf(owner, new Set([owner]));
466
619
  }
467
620
  /**
468
621
  * Update the closure links of all nested function calls, done once at the end of the script.
469
622
  * @lintIgnore vertex-has-origin
470
623
  */
471
624
  function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
472
- const { shadowing, generics } = namesShadowingBuiltIns(outEnvironment);
625
+ const { shadowing, generics } = namesShadowingBuiltIns(outEnvironment, graph);
473
626
  let rootDefinitions;
474
627
  const calls = graph.verticesOfType(vertex_1.VertexType.FunctionCall).toArray();
475
- const deferred = new Set();
628
+ /* the calls that wait for the parameters they call through to be bound, and whether a call was linked since they began to */
629
+ let waiting = [];
630
+ let linked = false;
476
631
  const lifted = [];
632
+ const handingOnDots = [];
477
633
  const enclosingOf = (0, defaultmap_1.memoize)((id) => graph.idMap === undefined ? undefined : model_1.RNode.strictlyEnclosingFunction(id, graph.idMap));
478
634
  const runsOnceAt = (0, defaultmap_1.memoize)((id) => program_order_1.ProgramOrder.runsOnceAt(id, graph));
479
635
  const databaseInfoOf = (0, defaultmap_1.memoize)((name) => ctx.functionInfo(name));
636
+ /* the generics a built-in dispatches to on its own whose methods the code binds */
637
+ const internalOf = (0, defaultmap_1.memoize)((name) => ctx.env.builtInFunctionOf(name)?.config?.dispatches?.filter(g => generics.has(g) || shadowing.has(g)) ?? []);
480
638
  const environmentAt = (0, defaultmap_1.memoize)((id) => {
481
639
  const environment = graph.getVertex(id).environment;
482
640
  return environment ? environment_1.REnvironment.overwrite(outEnvironment, environment) : outEnvironment;
483
641
  });
484
- for (let i = 0; i < calls.length; i++) {
642
+ const narrower = new dispatch_linking_1.DispatchNarrower(graph, ctx);
643
+ /* per function, the `NextMethod` calls of its body */
644
+ const namedNextCalls = new Map();
645
+ for (const [id, vertex] of calls) {
646
+ const fn = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.S3DispatchNext) && df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).includes(NextMethodId) ? enclosingOf(id) : undefined;
647
+ if (fn !== undefined) {
648
+ namedNextCalls.set(fn, [...namedNextCalls.get(fn) ?? [], id]);
649
+ }
650
+ }
651
+ /* the dispatches, decided once the calls they may reach are linked */
652
+ const deferred = new Set();
653
+ let dispatching = [];
654
+ /* per next-method call, what it rules out per context of the dispatches running the method it is in */
655
+ const nextRuledOut = new Map();
656
+ for (let i = 0;; i++) {
657
+ if (i === calls.length) {
658
+ /* a call linked since binds parameters, which may be what a waiting call calls, so they try again until nothing changes */
659
+ if (linked && waiting.length > 0) {
660
+ calls.push(...waiting);
661
+ waiting = [];
662
+ }
663
+ else if (dispatching.length > 0) {
664
+ calls.push(...dispatching);
665
+ dispatching = [];
666
+ }
667
+ else {
668
+ break;
669
+ }
670
+ linked = false;
671
+ }
485
672
  const [id, vertex] = calls[i];
486
673
  const { onlyBuiltin, name, args, origin } = vertex;
487
674
  if (name === undefined) {
488
675
  continue;
489
676
  }
677
+ if ((0, built_in_get_1.isComputedLookup)(vertex, graph)) {
678
+ /* the parameters the name reads are bound only once the calls handing them down are linked */
679
+ if ((0, built_in_get_1.linkComputedLookup)(graph, vertex, environmentAt(id), ctx, runsOnceAt(id))) {
680
+ linked = true;
681
+ }
682
+ else {
683
+ waiting.push(calls[i]);
684
+ }
685
+ continue;
686
+ }
490
687
  /* the code writes a `<name>.<class>`, so a built-in `name` that dispatches may reach it */
491
- const mayDispatch = generics.has(identifier_1.Identifier.getName(name));
492
- if (onlyBuiltin && !mayDispatch && !(!graph.isRoot(id) && shadowing.has(identifier_1.Identifier.getName(name)))) {
688
+ const mayDispatch = s3MethodPrefixesOf(name).some(p => generics.has(p));
689
+ /* a `setMethod("Arith", ...)` claims every member of the S4 group, so a built-in member may reach its methods */
690
+ const s4Groups = (0, group_generics_1.s4GroupGenericsOf)(identifier_1.Identifier.getName(name)).filter(g => shadowing.has(g));
691
+ const internal = internalOf(name);
692
+ if (onlyBuiltin && !mayDispatch && s4Groups.length === 0 && internal.length === 0 && !(!graph.isRoot(id) && shadowing.has(identifier_1.Identifier.getName(name)))) {
493
693
  continue;
494
694
  }
495
695
  const effectiveEnvironment = environmentAt(id);
496
696
  /* a call the program runs once, at the top and outside any loop, cannot see what is defined after it */
497
697
  const definedLater = (definition) => program_order_1.ProgramOrder.definedLater(definition, runsOnceAt(id), graph);
498
- const targets = new Set(df_helper_1.Dataflow.callTargetsOf(id, graph, effectiveEnvironment));
499
- /* a call of a parameter sees what it is bound to only once the calls handing it down are linked */
500
- if (!deferred.has(id) && targets.size > 0 && targets.values().every(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(t)))) {
698
+ /* the dispatch is decided anew, from every method the name may reach */
699
+ delete vertex.ruledOut;
700
+ delete vertex.ruledOutAt;
701
+ const targets = new Set(callBoundInScope(id, graph) ? (0, dispatch_linking_1.linkedFunctionIds)(new Set(df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Reads)), graph) : df_helper_1.Dataflow.callTargetsOf(id, graph, effectiveEnvironment));
702
+ /* a dispatch depends on the classes of its arguments, so it waits for the value flow to be linked */
703
+ const dispatches = origin.includes(built_in_proc_name_1.BuiltInProcName.S3Dispatch) || narrower.reachesS4Method(targets) || mayDispatch && dispatchesOnClass(name, effectiveEnvironment, databaseInfoOf);
704
+ if (dispatches && !deferred.has(id)) {
501
705
  deferred.add(id);
502
- calls.push(calls[i]);
706
+ dispatching.push(calls[i]);
503
707
  continue;
504
708
  }
505
- const collectedNextMethods = new Set();
709
+ /* a call of a parameter sees what it is bound to only once the calls handing it down are linked */
710
+ if (targets.size > 0 && targets.values().every(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(t)))) {
711
+ waiting.push(calls[i]);
712
+ continue;
713
+ }
714
+ /* per next-method call, the method it is in */
715
+ const collectedNextMethods = new Map();
506
716
  let treatAsS3 = origin.includes(built_in_proc_name_1.BuiltInProcName.S3Dispatch);
507
717
  if (treatAsS3 && !graph.isRoot(id)) {
508
- /* a body dispatches where it is called, which may see a method the end of the script has replaced */
718
+ /* a body dispatches where it is called, which may see a method the end of the script has replaced, or one a function calling it defines in its own frame, which only the lookup by name reaches */
509
719
  rootDefinitions ??= df_helper_1.Dataflow.definitionsByName(graph);
510
720
  const prefix = identifier_1.Identifier.getName(name) + '.';
511
721
  for (const [defined, ids] of rootDefinitions.entries()) {
512
722
  if (defined.startsWith(prefix)) {
513
- (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(ids.filter(d => graph.isRoot(d))), graph)[0].forEach(t => targets.add(t.id));
723
+ (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(ids), graph)[0].forEach(t => targets.add(t.id));
724
+ ids.filter(d => !graph.isRoot(d)).forEach(d => graph.addEdge(id, d, edge_1.EdgeType.Reads));
514
725
  }
515
726
  }
516
727
  }
517
- if (mayDispatch && !treatAsS3 && dispatchesOnClass(name, effectiveEnvironment, databaseInfoOf)) {
518
- for (const method of linkOwnS3Methods(vertex, name, graph, effectiveEnvironment, runsOnceAt(id), ctx, databaseInfoOf)) {
519
- targets.add(method);
728
+ for (const group of s4Groups) {
729
+ const methods = resolve_helper_1.Resolve.byNameAndType(group, effectiveEnvironment, identifier_1.ReferenceType.Function)?.filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId) && !definedLater(d.nodeId)) ?? [];
730
+ for (const method of methods) {
731
+ graph.addEdge(id, method.nodeId, edge_1.EdgeType.Reads);
520
732
  }
733
+ (0, dispatch_linking_1.linkedFunctionIds)(new Set(methods.map(m => m.nodeId)), graph).forEach(t => targets.add(t));
734
+ }
735
+ const object = treatAsS3 ? dispatchedObjectOf(vertex, graph) : undefined;
736
+ let s3Objects = object === undefined ? undefined : [object];
737
+ /* a built-in keeps no environment, but the frame of the function it is in may bind methods */
738
+ const methodEnvironment = () => {
739
+ const frame = vertex.environment === undefined ? graph.getVertex(enclosingOf(id) ?? '') : undefined;
740
+ return vertex_1.DfgVertex.isFunctionDefinition(frame) ? environment_1.REnvironment.overwrite(outEnvironment, frame.subflow.environment) : effectiveEnvironment;
741
+ };
742
+ if (mayDispatch && !treatAsS3 && dispatchesOnClass(name, effectiveEnvironment, databaseInfoOf)) {
743
+ const own = linkOwnS3Methods(vertex, name, graph, methodEnvironment(), runsOnceAt(id), ctx, databaseInfoOf);
744
+ own.methods.forEach(m => targets.add(m));
745
+ s3Objects = own.objects;
521
746
  treatAsS3 = true;
522
747
  }
748
+ for (const method of internal.length === 0 ? [] : (0, dispatch_linking_1.internalGenericMethods)(internal, methodEnvironment(), graph).filter(m => !definedLater(m.nodeId))) {
749
+ graph.addEdge(id, method.nodeId, edge_1.EdgeType.Reads);
750
+ (0, dispatch_linking_1.linkedFunctionIds)(new Set([method.nodeId]), graph).forEach(t => targets.add(t));
751
+ }
752
+ const decide = (info) => {
753
+ const decided = narrowedDispatchOf(narrower, vertex, s3Objects, targets, definedLater, info);
754
+ /* the call depends on the registrations a decision relies on */
755
+ for (const registration of decided?.reads ?? []) {
756
+ graph.addEdge(id, registration, edge_1.EdgeType.Reads);
757
+ }
758
+ return decided;
759
+ };
760
+ const narrowed = decide();
761
+ /* a dispatch on what the calls of its function hand it is decided per call as well */
762
+ const contexts = narrower.perCall(id, targets, narrowed, decide);
763
+ const perCall = contexts === undefined ? undefined : (0, dispatch_linking_1.ruledOutPerCall)(contexts, n => [...n?.excluded ?? []], narrowed?.excluded);
764
+ narrowed?.excluded.forEach(e => targets.delete(e));
523
765
  const enclosing = graph.isRoot(id) ? undefined : enclosingOf(id);
524
766
  for (const target of targets) {
525
767
  if (node_id_1.NodeId.isBuiltIn(target)) {
@@ -542,23 +784,38 @@ function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
542
784
  graph.addEdge(id, target, edge_1.EdgeType.Calls);
543
785
  /* the call reaches user code, so everything downstream has to stop treating it as built-in only */
544
786
  vertex.onlyBuiltin = false;
787
+ linked = true;
788
+ if (enclosing !== undefined) {
789
+ (0, built_in_deferred_env_ops_1.linkCallerFrameWrites)(id, targetVertex, graph, ctx);
790
+ }
545
791
  for (const exitPoint of targetVertex.exitPoints) {
546
792
  graph.addEdge(id, exitPoint.nodeId, edge_1.EdgeType.Returns);
547
793
  }
548
- if (treatAsS3) {
794
+ const named = treatAsS3 ? undefined : namedNextCalls.get(target);
795
+ if (named !== undefined) {
796
+ linkNamedNextMethods(graph, target, named, effectiveEnvironment, narrower, ctx);
797
+ }
798
+ if (treatAsS3 || targetVertex.mode?.includes(vertex_1.FunctionDispatch.S4)) {
549
799
  targetVertex.mode ??= [];
550
- if (!targetVertex.mode.includes('s3')) {
551
- targetVertex.mode.push('s3');
800
+ if (treatAsS3 && !targetVertex.mode.includes(vertex_1.FunctionDispatch.S3)) {
801
+ targetVertex.mode.push(vertex_1.FunctionDispatch.S3);
552
802
  }
553
- // collect all next method calls to link them to the same targets!
554
803
  for (const [next, v] of df_helper_1.Dataflow.callsIn(targetVertex, graph)) {
555
804
  if (vertex_1.DfgVertex.hasOrigin(v, built_in_proc_name_1.BuiltInProcName.S3DispatchNext)) {
556
- collectedNextMethods.add(next);
805
+ collectedNextMethods.set(next, target);
557
806
  }
558
807
  }
559
808
  }
560
809
  const global = enclosingOf(target) === undefined;
561
- targetVertex.subflow.in = resolveIngoingRefs(targetVertex.subflow.in, effectiveEnvironment, (ingoing, resolved) => {
810
+ if (graph.idMap !== undefined) {
811
+ (0, linker_1.linkInstanceReads)(graph, vertex, targetVertex, effectiveEnvironment, graph.idMap);
812
+ }
813
+ const readWhereCalled = graph.idMap === undefined ? undefined : (0, linker_1.readsOfUncalledClosures)(target, targetVertex.subflow, graph, graph.idMap);
814
+ targetVertex.subflow.in = resolveIngoingRefs(targetVertex.subflow.in, effectiveEnvironment, (ingoing, found) => {
815
+ if (readWhereCalled?.(ingoing.nodeId)) {
816
+ return false;
817
+ }
818
+ const resolved = withoutExcludedMethods(ingoing, found, graph);
562
819
  /* the state of the session (options, files, the working directory) is what it is at this very call, and what it was before the calls of the enclosing function */
563
820
  if (ambient_state_name_1.AmbientStateName.is(ingoing.name)) {
564
821
  for (const { nodeId } of (vertex.environment && resolve_helper_1.Resolve.byNameAndType(ingoing.name, vertex.environment, ingoing.type)) ?? []) {
@@ -588,31 +845,50 @@ function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
588
845
  graph.addEdge(ingoing.nodeId, nodeId, edge_1.EdgeType.DefinedByOnCall);
589
846
  graph.addEdge(id, nodeId, edge_1.EdgeType.DefinesOnCall);
590
847
  if (envState !== undefined && graph.idMap !== undefined) {
591
- (0, linker_1.bindAccessedField)(graph, ingoing.nodeId, envState, graph.idMap);
848
+ (0, linker_1.bindAccessedField)(graph, ingoing.nodeId, envState, graph.idMap, id);
592
849
  }
593
850
  }
594
851
  }
595
852
  return false;
596
- });
853
+ }, { fn: target, graph });
597
854
  const linkedParameters = graph.idMap?.get(target);
598
855
  if (r_function_definition_1.RFunctionDefinition.is(linkedParameters)) {
599
856
  function_semantics_1.FunctionSemantics.call.match.onCallAndLink(args, linkedParameters.parameters, graph);
600
- }
601
- }
602
- for (const nextMethodId of collectedNextMethods) {
603
- for (const target of targets) {
604
- const targetVertex = graph.getVertex(target);
605
- if (vertex_1.DfgVertex.isUse(targetVertex)) {
606
- graph.addEdge(nextMethodId, target, edge_1.EdgeType.Reads);
607
- }
608
- else if (vertex_1.DfgVertex.isFunctionDefinition(targetVertex)) {
609
- graph.addEdge(nextMethodId, target, edge_1.EdgeType.Calls);
857
+ if (function_semantics_1.FunctionSemantics.call.match.handsOnDots(args, graph)) {
858
+ handingOnDots.push([args, linkedParameters.parameters]);
610
859
  }
611
860
  }
612
861
  }
862
+ if (narrowed !== undefined && narrowed.excluded.size > 0) {
863
+ (0, dispatch_linking_1.unlinkExcludedMethods)(graph, vertex, narrowed.excluded);
864
+ vertex.ruledOut = [...narrowed.excluded];
865
+ }
866
+ if (perCall !== undefined) {
867
+ vertex.ruledOutAt = perCall;
868
+ }
869
+ linkNextMethods(graph, collectedNextMethods, targets, narrowed?.next);
870
+ for (const [next, owner] of collectedNextMethods) {
871
+ const ruledOut = contexts === undefined ? undefined : nextMethodsPerCall(next, owner, id, contexts, collectedNextMethods, graph);
872
+ nextRuledOut.set(next, [...nextRuledOut.get(next) ?? [], ...ruledOut ?? []]);
873
+ }
874
+ }
875
+ for (const [next, ruledOut] of nextRuledOut) {
876
+ const vertex = graph.getVertex(next);
877
+ if (ruledOut.length > 0) {
878
+ vertex.ruledOutAt = ruledOut;
879
+ }
880
+ else {
881
+ delete vertex.ruledOutAt;
882
+ }
613
883
  }
884
+ /* the dots a call hands on stand for what the calls of the function around hand over, all of them linked by now */
885
+ for (const [args, parameters] of handingOnDots) {
886
+ function_semantics_1.FunctionSemantics.call.match.onCallAndLink(args, parameters, graph);
887
+ }
888
+ function_semantics_1.FunctionSemantics.call.match.unforceUnreadDots(graph);
614
889
  linkLiftedReads(graph, lifted, enclosingOf, environmentAt, runsOnceAt);
615
- const called = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionCall).flatMap(([id]) => df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)));
890
+ /* a method only a next-method call reaches is linked by no call that resolves what it reads */
891
+ const called = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionCall).filter(([, v]) => !vertex_1.DfgVertex.hasOrigin(v, built_in_proc_name_1.BuiltInProcName.S3DispatchNext)).flatMap(([id]) => df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)));
616
892
  for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
617
893
  if (called.has(id)) {
618
894
  continue;
@@ -624,31 +900,54 @@ function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
624
900
  }
625
901
  }
626
902
  return true;
627
- });
903
+ }, { fn: id, graph });
628
904
  }
629
905
  }
630
906
  /** Resolves each global read of a nested call where the enclosing function is called. */
631
907
  function linkLiftedReads(graph, lifted, enclosingOf, environmentAt, runsOnceAt) {
908
+ /* the top-level calls that run a definition, through the calls of the functions that enclose its calls */
909
+ const topLevelCallsOf = (0, defaultmap_1.memoize)((start) => {
910
+ const calls = new Set();
911
+ const definitions = new Set([start]);
912
+ for (const definition of definitions) {
913
+ for (const call of df_helper_1.Dataflow.sourcesOf(graph, definition, edge_1.EdgeType.Calls)) {
914
+ if (!vertex_1.DfgVertex.isFunctionCall(graph.getVertex(call))) {
915
+ continue;
916
+ }
917
+ const outer = graph.isRoot(call) ? undefined : enclosingOf(call);
918
+ if (outer === undefined) {
919
+ calls.add(call);
920
+ }
921
+ else {
922
+ definitions.add(outer);
923
+ }
924
+ }
925
+ }
926
+ return calls;
927
+ });
632
928
  /* a call reads several states under its own id (`#wd`, `#file:f`), so a read is told apart by its name as well */
633
- const seen = new defaultmap_1.DefaultMap(() => new Set());
634
- while (lifted.length > 0) {
635
- const [definition, read, holder] = lifted.pop();
636
- const known = seen.get(definition);
637
- const key = `${String(read.nodeId)}|${read.name === undefined ? '' : identifier_1.Identifier.toString(read.name)}`;
638
- if (known.has(key) || read.name === undefined) {
929
+ const seen = new defaultmap_1.DefaultMap(() => new defaultmap_1.DefaultMap(() => new Set()));
930
+ for (let next = lifted.pop(); next !== undefined; next = lifted.pop()) {
931
+ const [definition, read, holder] = next;
932
+ if (read.name === undefined) {
639
933
  continue;
640
934
  }
641
- known.add(key);
642
- for (const call of df_helper_1.Dataflow.sourcesOf(graph, definition, edge_1.EdgeType.Calls)) {
643
- if (!vertex_1.DfgVertex.isFunctionCall(graph.getVertex(call))) {
644
- continue;
645
- }
646
- const outer = graph.isRoot(call) ? undefined : enclosingOf(call);
647
- if (outer !== undefined) {
648
- lifted.push([outer, read, holder]);
649
- continue;
935
+ const known = seen.get(definition).get(read.nodeId);
936
+ const name = identifier_1.Identifier.toString(read.name);
937
+ if (known.has(name)) {
938
+ continue;
939
+ }
940
+ known.add(name);
941
+ /* the function the read is lifted to may write the variable itself before its call runs (`k <<- 2; g()`) */
942
+ const fn = graph.getVertex(definition);
943
+ for (const write of vertex_1.DfgVertex.isFunctionDefinition(fn) ? fn.subflow.graph : []) {
944
+ if (vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(write)) && df_helper_1.Dataflow.definedBySuperAssignment(graph, write) && node_id_1.NodeId.recoverBareName(write, graph.idMap) === identifier_1.Identifier.getName(read.name)) {
945
+ graph.addEdge(read.nodeId, write, edge_1.EdgeType.Reads);
650
946
  }
651
- const resolved = resolve_helper_1.Resolve.byNameAndType(read.name, environmentAt(call), read.type);
947
+ }
948
+ for (const call of topLevelCallsOf(definition)) {
949
+ const found = resolve_helper_1.Resolve.byNameAndType(read.name, environmentAt(call), read.type);
950
+ const resolved = found && withoutExcludedMethods(read, found, graph);
652
951
  const target = graph.getVertex(holder);
653
952
  if (resolved === undefined && vertex_1.DfgVertex.isFunctionDefinition(target) && !target.subflow.in.some(r => r.nodeId === read.nodeId)) {
654
953
  target.subflow.in = [...target.subflow.in, read];
@@ -713,16 +1012,13 @@ function groupBodyWrites(out) {
713
1012
  }
714
1013
  return byName;
715
1014
  }
716
- /**
717
- * Links a parameter default read (e.g. `function(a=b)`) to the body write(s) of the same name it could see as a promise,
718
- * e.g. in `f <- function(a=b) { b <- 1; a; b <- 5 }`, `a` links to `b <- 1`; may not narrow this down precisely in every case.
719
- */
1015
+ /** Links a parameter default read (e.g. `function(a=b)`) to the body writes of the same name it could see as a promise: the default is evaluated where the parameter is first forced, after any of them. */
720
1016
  function linkParameterReadToBodyWrites(graph, read, writesByName) {
721
1017
  const writes = read.name === undefined ? undefined : writesByName.get(read.name);
722
1018
  if (writes === undefined) {
723
1019
  return false;
724
1020
  }
725
- for (const { nodeId } of writes[0].cds === undefined ? writes.slice(0, 1) : writes) {
1021
+ for (const { nodeId } of writes) {
726
1022
  graph.addEdge(read.nodeId, nodeId, edge_1.EdgeType.Reads);
727
1023
  }
728
1024
  return true;