@eagleoutice/flowr 2.17.5 → 2.17.6

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 (357) hide show
  1. package/README.md +13 -51
  2. package/abstract-interpretation/absint-inference.d.ts +4 -4
  3. package/abstract-interpretation/absint-inference.js +11 -11
  4. package/abstract-interpretation/abstract-semantics.d.ts +2 -1
  5. package/abstract-interpretation/branch-paths-interpreter.d.ts +1 -0
  6. package/abstract-interpretation/branch-paths-interpreter.js +60 -0
  7. package/abstract-interpretation/branch-paths.d.ts +60 -0
  8. package/abstract-interpretation/branch-paths.js +120 -0
  9. package/abstract-interpretation/data-frame/dataframe-semantics.d.ts +6 -1
  10. package/abstract-interpretation/data-frame/dataframe-semantics.js +60 -1
  11. package/abstract-interpretation/data-frame/semantics.js +4 -10
  12. package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -1
  13. package/cli/repl/core.js +51 -0
  14. package/control-flow/cfg-dead-code.js +12 -7
  15. package/data/packed.d.ts +10 -0
  16. package/data/packed.js +33 -0
  17. package/data/r-base-guards.generated.d.ts +7 -0
  18. package/data/r-base-guards.generated.js +12 -0
  19. package/data/r-datasets.generated.d.ts +4 -0
  20. package/data/r-datasets.generated.js +10 -0
  21. package/data/r-formals.generated.d.ts +4 -0
  22. package/data/r-formals.generated.js +10 -0
  23. package/data/r-group-method-guards.generated.d.ts +3 -0
  24. package/data/r-group-method-guards.generated.js +8 -0
  25. package/dataflow/environments/ambient-effect.d.ts +1000 -0
  26. package/dataflow/environments/ambient-effect.js +234 -0
  27. package/dataflow/environments/ambient-state-name.d.ts +45 -2
  28. package/dataflow/environments/ambient-state-name.js +61 -3
  29. package/dataflow/environments/apply-kill.js +11 -4
  30. package/dataflow/environments/built-in-kinds.d.ts +4 -46
  31. package/dataflow/environments/built-in-kinds.js +6 -2
  32. package/dataflow/environments/built-in-props.d.ts +16 -4
  33. package/dataflow/environments/built-in-props.js +11 -3
  34. package/dataflow/environments/built-in.d.ts +6 -1
  35. package/dataflow/environments/built-in.js +13 -36
  36. package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
  37. package/dataflow/environments/default-builtin-config/base-functions.js +110 -52
  38. package/dataflow/environments/default-builtin-config/base-language.d.ts +1 -1
  39. package/dataflow/environments/default-builtin-config/base-language.js +11 -8
  40. package/dataflow/environments/default-builtin-config/dev-tooling.js +1 -1
  41. package/dataflow/environments/default-builtin-config/file-io.js +6 -4
  42. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +1 -1
  43. package/dataflow/environments/default-builtin-config/graphics-devices.js +24 -14
  44. package/dataflow/environments/default-builtin-config/guard-builders.d.ts +16 -0
  45. package/dataflow/environments/default-builtin-config/guard-builders.js +29 -0
  46. package/dataflow/environments/default-builtin-config/guards-primitive-lang.d.ts +15 -0
  47. package/dataflow/environments/default-builtin-config/guards-primitive-lang.js +228 -0
  48. package/dataflow/environments/default-builtin-config/guards-primitive-ops.d.ts +11 -0
  49. package/dataflow/environments/default-builtin-config/guards-primitive-ops.js +154 -0
  50. package/dataflow/environments/default-builtin-config/guards.d.ts +9 -0
  51. package/dataflow/environments/default-builtin-config/guards.js +211 -0
  52. package/dataflow/environments/default-builtin-config/index.d.ts +3 -3
  53. package/dataflow/environments/default-builtin-config/index.js +22 -7
  54. package/dataflow/environments/default-builtin-config/media-formats.js +4 -4
  55. package/dataflow/environments/default-builtin-config/package-spatial.js +2 -1
  56. package/dataflow/environments/default-builtin-config/package-tidyverse.js +3 -2
  57. package/dataflow/environments/default-builtin-config/package-utils.d.ts +1 -1
  58. package/dataflow/environments/default-builtin-config/package-utils.js +5 -2
  59. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
  60. package/dataflow/environments/default-builtin-config/parallel-execution.js +3 -1
  61. package/dataflow/environments/default-builtin-config/r-formals.d.ts +13 -0
  62. package/dataflow/environments/default-builtin-config/r-formals.js +110 -0
  63. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +138 -77
  64. package/dataflow/environments/default-builtin-config/shared-configs.js +52 -88
  65. package/dataflow/environments/default-builtin-config/statistics.d.ts +1 -1
  66. package/dataflow/environments/default-builtin-config/statistics.js +4 -1
  67. package/dataflow/environments/diff.js +5 -2
  68. package/dataflow/environments/environment.d.ts +20 -0
  69. package/dataflow/environments/environment.js +39 -4
  70. package/dataflow/environments/group-generics.d.ts +5 -1
  71. package/dataflow/environments/group-generics.js +13 -3
  72. package/dataflow/environments/guard-facts.d.ts +169 -0
  73. package/dataflow/environments/guard-facts.js +26 -0
  74. package/dataflow/environments/identifier.d.ts +9 -1
  75. package/dataflow/environments/identifier.js +5 -0
  76. package/dataflow/environments/pkg-name.d.ts +1 -0
  77. package/dataflow/environments/query-fn-props.d.ts +3 -5
  78. package/dataflow/environments/query-fn-props.js +44 -21
  79. package/dataflow/environments/removal-marker.d.ts +2 -0
  80. package/dataflow/environments/removal-marker.js +5 -0
  81. package/dataflow/eval/resolve/resolve-strings.d.ts +2 -5
  82. package/dataflow/eval/resolve/resolve-strings.js +2 -2
  83. package/dataflow/extractor.js +24 -15
  84. package/dataflow/fn/condition-handlers.d.ts +2 -0
  85. package/dataflow/fn/condition-handlers.js +3 -1
  86. package/dataflow/fn/frame-reflection.d.ts +4 -2
  87. package/dataflow/fn/frame-reflection.js +16 -0
  88. package/dataflow/fn/function-props.js +15 -22
  89. package/dataflow/fn/function-semantics.d.ts +31 -1
  90. package/dataflow/fn/function-semantics.js +15 -0
  91. package/dataflow/fn/guards/built-in-guards.d.ts +112 -0
  92. package/dataflow/fn/guards/built-in-guards.js +199 -0
  93. package/dataflow/fn/guards/call-contracts.d.ts +97 -0
  94. package/dataflow/fn/guards/call-contracts.js +331 -0
  95. package/dataflow/fn/guards/condition-grouping.d.ts +20 -0
  96. package/dataflow/fn/guards/condition-grouping.js +135 -0
  97. package/dataflow/fn/guards/function-guards.d.ts +112 -0
  98. package/dataflow/fn/guards/function-guards.js +1549 -0
  99. package/dataflow/fn/guards/group-method-guards.d.ts +28 -0
  100. package/dataflow/fn/guards/group-method-guards.js +56 -0
  101. package/dataflow/fn/guards/guard-claims.d.ts +125 -0
  102. package/dataflow/fn/guards/guard-claims.js +678 -0
  103. package/dataflow/fn/guards/guard-knowledge.d.ts +41 -0
  104. package/dataflow/fn/guards/guard-knowledge.js +180 -0
  105. package/dataflow/fn/guards/guard-term-syntax.d.ts +9 -0
  106. package/dataflow/fn/guards/guard-term-syntax.js +210 -0
  107. package/dataflow/fn/guards/guard-term.d.ts +136 -0
  108. package/dataflow/fn/guards/guard-term.js +550 -0
  109. package/dataflow/fn/guards/stated-guards.d.ts +13 -0
  110. package/dataflow/fn/guards/stated-guards.js +35 -0
  111. package/dataflow/fn/higher-order-function.d.ts +2 -0
  112. package/dataflow/fn/higher-order-function.js +1 -0
  113. package/dataflow/fn/strict-function.d.ts +4 -0
  114. package/dataflow/fn/strict-function.js +66 -17
  115. package/dataflow/graph/ambient-access.d.ts +4 -1
  116. package/dataflow/graph/ambient-access.js +8 -2
  117. package/dataflow/graph/closure-frames.js +1 -1
  118. package/dataflow/graph/dataflowgraph-builder.d.ts +1 -1
  119. package/dataflow/graph/dataflowgraph-builder.js +2 -2
  120. package/dataflow/graph/df-helper.d.ts +6 -0
  121. package/dataflow/graph/df-helper.js +15 -0
  122. package/dataflow/graph/graph.d.ts +12 -6
  123. package/dataflow/graph/graph.js +21 -28
  124. package/dataflow/info.d.ts +2 -1
  125. package/dataflow/info.js +3 -1
  126. package/dataflow/internal/dispatch-linking.d.ts +3 -1
  127. package/dataflow/internal/dispatch-linking.js +1 -0
  128. package/dataflow/internal/linker.d.ts +2 -0
  129. package/dataflow/internal/linker.js +115 -6
  130. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -1
  131. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +5 -2
  132. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +2 -1
  133. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +19 -57
  134. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +471 -295
  135. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +13 -1
  136. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -0
  137. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +106 -19
  138. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
  139. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +24 -3
  140. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +1 -1
  141. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +33 -11
  142. package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +4 -0
  143. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +4 -4
  144. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +23 -7
  145. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  146. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +19 -2
  147. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +347 -46
  148. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
  149. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +5 -0
  150. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +110 -16
  151. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +2 -0
  152. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +9 -2
  153. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
  154. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -2
  155. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +5 -0
  156. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +28 -0
  157. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +16 -6
  158. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +6 -1
  159. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +37 -2
  160. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +4 -0
  161. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +19 -1
  162. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -1
  163. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +55 -11
  164. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -2
  165. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +11 -10
  166. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +3 -1
  167. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +8 -0
  168. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +64 -7
  169. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +1 -1
  170. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +160 -20
  171. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +5 -3
  172. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +6 -0
  173. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +142 -4
  174. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  175. package/dataflow/internal/process/functions/call/quoted.js +23 -4
  176. package/dataflow/processor.d.ts +2 -0
  177. package/documentation/data/dfg/doc-ambient.d.ts +4 -0
  178. package/documentation/data/dfg/doc-ambient.js +74 -0
  179. package/documentation/wiki-dataflow-graph.js +10 -4
  180. package/documentation/wiki-linter.js +12 -0
  181. package/documentation/wiki-query.js +112 -1
  182. package/linter/linter-rules.d.ts +41 -1
  183. package/linter/linter-rules.js +5 -1
  184. package/linter/rules/call-contracts.d.ts +40 -0
  185. package/linter/rules/call-contracts.js +56 -0
  186. package/linter/rules/cmd-check/bogus-return.js +1 -1
  187. package/linter/rules/cmd-check/call-arguments.js +5 -6
  188. package/linter/rules/cmd-check/cmd-check-util.d.ts +0 -6
  189. package/linter/rules/cmd-check/cmd-check-util.js +0 -28
  190. package/linter/rules/cmd-check/package-hooks.js +2 -1
  191. package/linter/rules/cmd-check/s-three-method-consistency.js +1 -1
  192. package/linter/rules/interactive-functions.d.ts +30 -0
  193. package/linter/rules/interactive-functions.js +87 -0
  194. package/linter/rules/process-state-in-session.js +1 -1
  195. package/linter/rules/undefined-symbol-util.d.ts +1 -1
  196. package/linter/rules/undefined-symbol-util.js +8 -2
  197. package/linter/rules/undefined-symbol.js +18 -7
  198. package/linter/rules/useless-loop.d.ts +1 -1
  199. package/package.json +1 -1
  200. package/project/context/flowr-analyzer-dependencies-context.js +2 -1
  201. package/project/flowr-analyzer.d.ts +1 -0
  202. package/project/flowr-analyzer.js +5 -5
  203. package/project/sigdb/build.js +14 -4
  204. package/project/sigdb/decode.d.ts +3 -0
  205. package/project/sigdb/decode.js +10 -1
  206. package/project/sigdb/guarded-source.d.ts +6 -0
  207. package/project/sigdb/guarded-source.js +29 -0
  208. package/project/sigdb/reader.d.ts +5 -0
  209. package/project/sigdb/reader.js +27 -1
  210. package/project/sigdb/schema.d.ts +24 -2
  211. package/queries/catalog/absint-query/absint-query-format.d.ts +6 -3
  212. package/queries/catalog/absint-query/absint-query-format.js +57 -2
  213. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +6 -2
  214. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +48 -3
  215. package/queries/catalog/cluster-query/cluster-query-format.d.ts +5 -2
  216. package/queries/catalog/cluster-query/cluster-query-format.js +19 -2
  217. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +5 -2
  218. package/queries/catalog/code-clones-query/code-clones-query-format.js +34 -2
  219. package/queries/catalog/config-query/config-query-format.d.ts +5 -2
  220. package/queries/catalog/config-query/config-query-format.js +41 -2
  221. package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +5 -2
  222. package/queries/catalog/control-flow-query/control-flow-query-format.js +19 -2
  223. package/queries/catalog/data-columns-query/data-columns-query-format.d.ts +72 -0
  224. package/queries/catalog/data-columns-query/data-columns-query-format.js +215 -0
  225. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +5 -2
  226. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +38 -2
  227. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +5 -2
  228. package/queries/catalog/dataflow-query/dataflow-query-format.js +18 -2
  229. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -1
  230. package/queries/catalog/dependencies-query/dependencies-query-format.js +8 -3
  231. package/queries/catalog/dependencies-query/function-info/other-path-functions.js +1 -1
  232. package/queries/catalog/dependencies-query/function-info/tagged-functions.d.ts +11 -0
  233. package/queries/catalog/dependencies-query/function-info/tagged-functions.js +18 -0
  234. package/queries/catalog/dice-query/dice-query-format.d.ts +7 -2
  235. package/queries/catalog/dice-query/dice-query-format.js +34 -2
  236. package/queries/catalog/does-call-query/does-call-query-format.d.ts +7 -4
  237. package/queries/catalog/does-call-query/does-call-query-format.js +114 -2
  238. package/queries/catalog/files-query/files-query-format.d.ts +5 -2
  239. package/queries/catalog/files-query/files-query-format.js +45 -2
  240. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +6 -3
  241. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +303 -2
  242. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +8 -4
  243. package/queries/catalog/happens-before-query/happens-before-query-format.js +37 -2
  244. package/queries/catalog/id-map-query/id-map-query-format.d.ts +5 -2
  245. package/queries/catalog/id-map-query/id-map-query-format.js +18 -2
  246. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +5 -2
  247. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +29 -2
  248. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +37 -0
  249. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +125 -0
  250. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -2
  251. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +54 -2
  252. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +6 -2
  253. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +23 -2
  254. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +6 -2
  255. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +15 -2
  256. package/queries/catalog/linter-query/linter-query-format.d.ts +8 -2
  257. package/queries/catalog/linter-query/linter-query-format.js +69 -4
  258. package/queries/catalog/location-map-query/location-map-query-format.d.ts +7 -3
  259. package/queries/catalog/location-map-query/location-map-query-format.js +70 -2
  260. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +5 -2
  261. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +18 -2
  262. package/queries/catalog/origin-query/origin-query-format.d.ts +6 -3
  263. package/queries/catalog/origin-query/origin-query-format.js +29 -2
  264. package/queries/catalog/project-query/project-query-format.d.ts +6 -3
  265. package/queries/catalog/project-query/project-query-format.js +98 -2
  266. package/queries/catalog/provenance-query/provenance-query-format.d.ts +6 -3
  267. package/queries/catalog/provenance-query/provenance-query-format.js +30 -2
  268. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +9 -2
  269. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +38 -2
  270. package/queries/catalog/search-query/search-query-format.d.ts +5 -2
  271. package/queries/catalog/search-query/search-query-format.js +23 -2
  272. package/queries/catalog/signature-query/signature-query-executor.js +3 -1
  273. package/queries/catalog/signature-query/signature-query-format.d.ts +3 -0
  274. package/queries/catalog/signature-query/signature-query-render.js +23 -0
  275. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +13 -2
  276. package/queries/catalog/static-slice-query/static-slice-query-format.js +55 -2
  277. package/queries/catalog/taint-query/taint-query-format.d.ts +6 -3
  278. package/queries/catalog/taint-query/taint-query-format.js +28 -2
  279. package/queries/query.d.ts +48 -27
  280. package/queries/query.js +6 -4
  281. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +2 -0
  282. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +4 -0
  283. package/r-bridge/shell.js +7 -2
  284. package/reconstruct/reconstruct.js +18 -3
  285. package/slicing/static/removal-slice.js +4 -3
  286. package/slicing/static/slice-call.d.ts +11 -0
  287. package/slicing/static/slice-call.js +43 -2
  288. package/slicing/static/static-slicer.d.ts +2 -0
  289. package/slicing/static/static-slicer.js +137 -21
  290. package/slicing/static/visiting-queue.d.ts +2 -0
  291. package/slicing/static/visiting-queue.js +4 -0
  292. package/util/flowr-version.d.ts +1 -1
  293. package/util/flowr-version.js +2 -2
  294. package/util/objects.d.ts +2 -0
  295. package/util/objects.js +5 -0
  296. package/util/r-datasets.d.ts +27 -0
  297. package/util/r-datasets.js +45 -0
  298. package/util/text/playground-link.d.ts +2 -0
  299. package/util/text/playground-link.js +2 -0
  300. package/queries/catalog/absint-query/absint-query-executor.d.ts +0 -6
  301. package/queries/catalog/absint-query/absint-query-executor.js +0 -61
  302. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +0 -6
  303. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +0 -50
  304. package/queries/catalog/cluster-query/cluster-query-executor.d.ts +0 -6
  305. package/queries/catalog/cluster-query/cluster-query-executor.js +0 -21
  306. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +0 -6
  307. package/queries/catalog/code-clones-query/code-clones-query-executor.js +0 -38
  308. package/queries/catalog/config-query/config-query-executor.d.ts +0 -6
  309. package/queries/catalog/config-query/config-query-executor.js +0 -45
  310. package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +0 -6
  311. package/queries/catalog/control-flow-query/control-flow-query-executor.js +0 -21
  312. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.d.ts +0 -6
  313. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +0 -40
  314. package/queries/catalog/dataflow-query/dataflow-query-executor.d.ts +0 -6
  315. package/queries/catalog/dataflow-query/dataflow-query-executor.js +0 -20
  316. package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +0 -9
  317. package/queries/catalog/dependencies-query/function-info/statistics-functions.js +0 -18
  318. package/queries/catalog/dice-query/dice-query-executor.d.ts +0 -8
  319. package/queries/catalog/dice-query/dice-query-executor.js +0 -37
  320. package/queries/catalog/does-call-query/does-call-query-executor.d.ts +0 -6
  321. package/queries/catalog/does-call-query/does-call-query-executor.js +0 -116
  322. package/queries/catalog/files-query/files-query-executor.d.ts +0 -6
  323. package/queries/catalog/files-query/files-query-executor.js +0 -47
  324. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.d.ts +0 -6
  325. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +0 -307
  326. package/queries/catalog/happens-before-query/happens-before-query-executor.d.ts +0 -7
  327. package/queries/catalog/happens-before-query/happens-before-query-executor.js +0 -40
  328. package/queries/catalog/id-map-query/id-map-query-executor.d.ts +0 -6
  329. package/queries/catalog/id-map-query/id-map-query-executor.js +0 -20
  330. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -6
  331. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +0 -31
  332. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.d.ts +0 -4
  333. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +0 -58
  334. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.d.ts +0 -7
  335. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +0 -25
  336. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.d.ts +0 -7
  337. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +0 -17
  338. package/queries/catalog/linter-query/linter-query-executor.d.ts +0 -9
  339. package/queries/catalog/linter-query/linter-query-executor.js +0 -62
  340. package/queries/catalog/location-map-query/location-map-query-executor.d.ts +0 -7
  341. package/queries/catalog/location-map-query/location-map-query-executor.js +0 -73
  342. package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.d.ts +0 -6
  343. package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.js +0 -20
  344. package/queries/catalog/origin-query/origin-query-executor.d.ts +0 -6
  345. package/queries/catalog/origin-query/origin-query-executor.js +0 -31
  346. package/queries/catalog/project-query/project-query-executor.d.ts +0 -6
  347. package/queries/catalog/project-query/project-query-executor.js +0 -103
  348. package/queries/catalog/provenance-query/provenance-query-executor.d.ts +0 -6
  349. package/queries/catalog/provenance-query/provenance-query-executor.js +0 -33
  350. package/queries/catalog/resolve-value-query/resolve-value-query-executor.d.ts +0 -10
  351. package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +0 -40
  352. package/queries/catalog/search-query/search-query-executor.d.ts +0 -6
  353. package/queries/catalog/search-query/search-query-executor.js +0 -25
  354. package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +0 -14
  355. package/queries/catalog/static-slice-query/static-slice-query-executor.js +0 -59
  356. package/queries/catalog/taint-query/taint-query-executor.d.ts +0 -7
  357. package/queries/catalog/taint-query/taint-query-executor.js +0 -30
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrintingOptions = void 0;
3
+ exports.PrintWrites = exports.PrintingOptions = void 0;
4
4
  exports.hidesBody = hidesBody;
5
5
  exports.reachesBuiltInLate = reachesBuiltInLate;
6
6
  exports.readsAllAmbientState = readsAllAmbientState;
@@ -9,10 +9,13 @@ exports.ambientWritesOfRelease = ambientWritesOfRelease;
9
9
  exports.makeAmbientWritesMaybe = makeAmbientWritesMaybe;
10
10
  exports.ambientWritesBetween = ambientWritesBetween;
11
11
  exports.markForcing = markForcing;
12
+ exports.markLocking = markLocking;
13
+ exports.mayLock = mayLock;
12
14
  exports.mayForce = mayForce;
13
15
  exports.ambientAccessOfSymbol = ambientAccessOfSymbol;
16
+ exports.holds = holds;
14
17
  exports.drawingWritesDevice = drawingWritesDevice;
15
- exports.applyAmbientStateAccess = applyAmbientStateAccess;
18
+ exports.applyAmbientEffects = applyAmbientEffects;
16
19
  exports.applyAmbientStateOfCallee = applyAmbientStateOfCallee;
17
20
  exports.hiddenSideEffects = hiddenSideEffects;
18
21
  exports.writesOfHiddenBuiltIn = writesOfHiddenBuiltIn;
@@ -23,11 +26,13 @@ exports.processAmbientScope = processAmbientScope;
23
26
  exports.evaluatesCapturedCode = evaluatesCapturedCode;
24
27
  exports.autoPrintReads = autoPrintReads;
25
28
  exports.readsOfAutoPrint = readsOfAutoPrint;
29
+ exports.autoPrintsStatementsOf = autoPrintsStatementsOf;
26
30
  exports.autoPrints = autoPrints;
27
31
  exports.applyAmbientStateOfCalledBuiltIns = applyAmbientStateOfCalledBuiltIns;
28
32
  exports.errorsOfWarnings = errorsOfWarnings;
29
33
  exports.signalSites = signalSites;
30
34
  exports.maySignal = maySignal;
35
+ exports.testsValue = testsValue;
31
36
  const info_1 = require("../../../../../info");
32
37
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
33
38
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
@@ -36,6 +41,8 @@ const built_in_props_1 = require("../../../../../environments/built-in-props");
36
41
  const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
37
42
  const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
38
43
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
44
+ const r_logical_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
45
+ const query_fn_props_1 = require("../../../../../environments/query-fn-props");
39
46
  const identifier_1 = require("../../../../../environments/identifier");
40
47
  const environment_1 = require("../../../../../environments/environment");
41
48
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
@@ -46,6 +53,7 @@ const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast
46
53
  const r_value_1 = require("../../../../../eval/values/r-value");
47
54
  const match_args_1 = require("../../../../../graph/match-args");
48
55
  const known_call_handling_1 = require("../known-call-handling");
56
+ const built_in_expression_list_1 = require("./built-in-expression-list");
49
57
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
50
58
  const node_value_1 = require("../../../../../eval/resolve/node-value");
51
59
  const applied_arguments_1 = require("../../../../../graph/applied-arguments");
@@ -62,16 +70,22 @@ const arrays_1 = require("../../../../../../util/collections/arrays");
62
70
  const ambient_access_1 = require("../../../../../graph/ambient-access");
63
71
  const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
64
72
  const built_in_ambient_keys_1 = require("./built-in-ambient-keys");
73
+ const logic_1 = require("../../../../../../util/logic");
65
74
  const base_operators_1 = require("../../../../../environments/default-builtin-config/base-operators");
66
75
  const r_while_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-while-loop");
67
76
  const r_for_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
68
77
  const built_in_kinds_1 = require("../../../../../environments/built-in-kinds");
78
+ const ambient_effect_1 = require("../../../../../environments/ambient-effect");
69
79
  var built_in_kinds_2 = require("../../../../../environments/built-in-kinds");
70
80
  Object.defineProperty(exports, "PrintingOptions", { enumerable: true, get: function () { return built_in_kinds_2.PrintingOptions; } });
71
81
  const ListConstructors = new Set(['list', 'c']);
72
- const DeviceStates = [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.otherDevices, ambient_state_name_1.AmbientStateName.device, ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy];
82
+ /** the states of the active instance of a family */
83
+ function activeStates(family) {
84
+ return family.states.map(([active]) => active);
85
+ }
86
+ const DeviceStates = ambient_state_name_1.GraphicsDevices.states.flat();
73
87
  const Accumulating = new Set([
74
- ...DeviceStates, ambient_state_name_1.AmbientStateName.canvas, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.unknownOption,
88
+ ...DeviceStates, ...ambient_state_name_1.OutputSinks.states.flat(), ...ambient_state_name_1.MessageSinks.states.flat(), ambient_state_name_1.AmbientStateName.canvas, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.unknownOption,
75
89
  ambient_state_name_1.AmbientStateName.warnsAsErrors, ambient_state_name_1.AmbientStateName.files, ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.finalizers, ...ambient_state_name_1.KeyedAccumulators
76
90
  ]);
77
91
  /** What a call does to the graphics devices. */
@@ -80,7 +94,9 @@ var DeviceAccess;
80
94
  DeviceAccess["Open"] = "open";
81
95
  DeviceAccess["Close"] = "close";
82
96
  DeviceAccess["CloseAll"] = "close-all";
83
- /** closes one that is not known to be the active one, or makes another one active */
97
+ /** closes one that is not known to be the active one, which writes what any of them holds */
98
+ DeviceAccess["CloseSome"] = "close-some";
99
+ /** makes another one active */
84
100
  DeviceAccess["Switch"] = "switch";
85
101
  })(DeviceAccess || (DeviceAccess = {}));
86
102
  /** How a write differs from the default, see {@link AmbientWrite}. */
@@ -101,21 +117,33 @@ function maybe(name) {
101
117
  function optionReads(keys) {
102
118
  return keys === undefined ? [ambient_state_name_1.AmbientStateName.allOptions] : [...keys.map(ambient_state_name_1.AmbientStateName.option), ambient_state_name_1.AmbientStateName.unknownOption];
103
119
  }
104
- /** Links `getOption(key)` to the values the calls it surely reads the option from set it to (`options(cb = function() 4)`), so it hands them back like a call hands back its result. */
105
- function linkOptionValue(res, rootId, keys, data) {
106
- if (keys?.length !== 1 || resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.unknownOption, data.environment)?.some(d => !node_id_1.NodeId.isBuiltIn(d.nodeId))) {
120
+ /**
121
+ * Links a call handing back the entry `key` of a keyed state (`getOption("digits")`, `Sys.getenv("A")`, `par("mfrow")`) to the values the calls that may have set it last gave it,
122
+ * so value resolution sees them like the result of a call. It links only if these calls cover every path and named the entry, as anything else (`options(op)`, `layout(m)`, a new device) may set it to a value we do not know.
123
+ */
124
+ function linkEntryValue(res, rootId, state, keys, data) {
125
+ const [key] = keys;
126
+ if (keys.length !== 1 || key === ambient_state_name_1.UnknownKey || resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.keyed(state, ambient_state_name_1.UnknownKey), data.environment)?.some(d => !node_id_1.NodeId.isBuiltIn(d.nodeId))) {
107
127
  return;
108
128
  }
109
- const defs = resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.option(keys[0]), data.environment) ?? [];
110
- if (!defs.some(d => (0, info_1.happensInEveryBranch)(d.cds))) {
129
+ const defs = resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.keyed(state, key), data.environment) ?? [];
130
+ const whole = new Set((resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.allOf(state), data.environment) ?? []).map(d => d.nodeId));
131
+ const own = new Set(defs.map(d => d.nodeId));
132
+ /* a write of the whole state that names no entry, like `layout(m)`, may change this one as well */
133
+ const namesEntries = (id) => {
134
+ const setter = data.completeAst.idMap.get(id);
135
+ return node_id_1.NodeId.isBuiltIn(id) || (r_function_call_1.RFunctionCall.is(setter) && setter.arguments.every(a => a === r_function_call_1.EmptyArgument || a.name !== undefined));
136
+ };
137
+ if (defs.length === 0 || [...whole].some(id => !own.has(id) && !namesEntries(id)) || !(defs.some(d => (0, info_1.happensInEveryBranch)(d.cds)) || (0, info_1.happensInEveryBranch)(defs.flatMap(d => d.cds ?? [])))) {
111
138
  return;
112
139
  }
113
140
  const values = [];
114
141
  for (const { nodeId } of defs) {
115
142
  const setter = data.completeAst.idMap.get(nodeId);
116
- const named = r_function_call_1.RFunctionCall.is(setter) ? setter.arguments.filter(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) === keys[0]) : [];
143
+ const named = r_function_call_1.RFunctionCall.is(setter) && whole.has(nodeId) ? setter.arguments.filter(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) === key) : [];
117
144
  const value = named.length === 1 ? r_argument_1.RArgument.valueOf(named[0]) : undefined;
118
- if (value === undefined) {
145
+ /* setting an option to NULL removes it, so reading it hands back the default instead */
146
+ if (value === undefined || (r_symbol_1.RSymbol.is(value) && identifier_1.Identifier.getName(value.content) === 'NULL')) {
119
147
  return;
120
148
  }
121
149
  values.push(value.info.id);
@@ -142,15 +170,15 @@ function readsAllAmbientState(res, rootId, data, graphics, draws = true) {
142
170
  return withAccess(res, rootId, data, reads, draws ? [{ ...maybe(ambient_state_name_1.AmbientStateName.rng), assumed: true }] : []);
143
171
  }
144
172
  /** Adds the reads and writes of the ambient state to what a call does, see {@link AmbientStateName}. */
145
- function withAccess(res, rootId, data, reads, writes = []) {
146
- if (reads.length === 0 && writes.length === 0) {
173
+ function withAccess(res, rootId, data, reads, writes = [], kills = []) {
174
+ if (reads.length === 0 && writes.length === 0 && kills.length === 0) {
147
175
  return res;
148
176
  }
149
177
  const cds = data.cds ? [...data.cds] : undefined;
150
178
  const maybeWritten = writes.flatMap(w => typeof w === 'object' && w.mode === AmbientWriteMode.Maybe ? [w.name] : []);
151
179
  const read = (0, arrays_1.uniqueArrayMerge)(reads, maybeWritten);
152
180
  const readRefs = read.map(name => ({ nodeId: rootId, name, type: identifier_1.ReferenceType.Variable, cds }));
153
- recordAmbient(res.graph, rootId, res.environment, read, writes);
181
+ recordAmbient(res.graph, rootId, res.environment, read, writes, kills);
154
182
  /* the writes stay out of `out`: an assignment reads whatever else its source writes (`x <- y <- 3`) */
155
183
  return {
156
184
  ...res,
@@ -162,9 +190,9 @@ function withAccess(res, rootId, data, reads, writes = []) {
162
190
  function writesLocally(environment, name, mode) {
163
191
  return mode === AmbientWriteMode.Local || (environment.level > 0 && environment.current.memory.has(name));
164
192
  }
165
- /** Notes in `graph` what the call `rootId` reads and writes, see {@link DataflowGraph#recordAmbientAccess}; `environment` is the one the writes apply to. */
166
- function recordAmbient(graph, rootId, environment, reads, writes) {
167
- if (reads.length === 0 && writes.length === 0) {
193
+ /** Notes in `graph` what the call `rootId` reads, writes, and ends (`kills`), see {@link DataflowGraph#recordAmbientAccess}; `environment` is the one the writes apply to. */
194
+ function recordAmbient(graph, rootId, environment, reads, writes, kills = []) {
195
+ if (reads.length === 0 && writes.length === 0 && kills.length === 0) {
168
196
  return;
169
197
  }
170
198
  const global = [];
@@ -174,7 +202,7 @@ function recordAmbient(graph, rootId, environment, reads, writes) {
174
202
  const { name, mode, assumed: isAssumed } = typeof write === 'string' ? { name: write, mode: undefined, assumed: undefined } : write;
175
203
  (writesLocally(environment, name, mode) ? local : isAssumed ? assumed : global).push(name);
176
204
  }
177
- graph.recordAmbientAccess(rootId, { reads, writes: global, assumed, local });
205
+ graph.recordAmbientAccess(rootId, { reads, writes: global, assumed, local, kills });
178
206
  }
179
207
  /** Whether the code itself binds a variable of the same name, by quoting it in backticks, which a write of the state must not replace, as they only share the name. */
180
208
  function boundByCode(environment, name) {
@@ -256,6 +284,14 @@ function ambientWritesBetween(after, before) {
256
284
  function markForcing(environment) {
257
285
  environment_1.REnvironment.findBuiltIn(environment.current).forcing = true;
258
286
  }
287
+ /** Notes that a call may lock a binding or an environment (`lockBinding`), after which binding a name may fail. */
288
+ function markLocking(environment) {
289
+ environment_1.REnvironment.findBuiltIn(environment.current).locking = true;
290
+ }
291
+ /** Whether a call seen so far may lock a binding, see {@link markLocking}. */
292
+ function mayLock(environment) {
293
+ return environment_1.REnvironment.findBuiltIn(environment.current).locking === true;
294
+ }
259
295
  /** Whether a definition seen so far binds a promise or a text connection, see {@link markForcing}. */
260
296
  function mayForce(environment) {
261
297
  return environment_1.REnvironment.findBuiltIn(environment.current).forcing === true;
@@ -264,8 +300,17 @@ function mayForce(environment) {
264
300
  function ambientAccessOfSymbol(res, symbol, data) {
265
301
  const forcing = mayForce(data.environment);
266
302
  const definitions = forcing ? resolve_helper_1.Resolve.byName(symbol.content, data.environment) ?? [] : [];
267
- const forces = definitions.filter(identifier_1.isInGraphDefinition).flatMap(d => d.forces ?? []);
268
- return withAccess(res, symbol.info.id, data, ambientReadsOfSymbol(symbol, data, forcing), forces.map(maybe));
303
+ const promises = definitions.filter(identifier_1.isInGraphDefinition);
304
+ const reads = (0, arrays_1.uniqueArrayMerge)(ambientReadsOfSymbol(symbol, data, forcing), promises.flatMap(d => d.forcedReads ?? []));
305
+ const accessed = withAccess(res, symbol.info.id, data, reads, promises.flatMap(d => d.forces ?? []).map(maybe));
306
+ /* a read may be the one forcing the promise, so what its code binds may be bound from here on (the first read forces it, so only maybe) */
307
+ let environment = accessed.environment;
308
+ for (const write of promises.flatMap(d => d.forcedWrites ?? [])) {
309
+ environment = environment_1.REnvironment.define(write, false, environment, true);
310
+ }
311
+ /* a read reached either forces the promise or comes after a forcing that left already, so it leaves as the promise does */
312
+ const exits = promises.flatMap(d => d.forcedExits ?? []).map(e => ({ ...e, nodeId: symbol.info.id, cds: e.cds ?? data.cds }));
313
+ return environment === accessed.environment && exits.length === 0 ? accessed : { ...accessed, environment, exitPoints: [...accessed.exitPoints, ...exits] };
269
314
  }
270
315
  /** Binds `name` (globally) to the given definitions, in addition to what it holds with `keep`, so `#graphics` can become what another state holds. */
271
316
  function setAmbient(environment, name, definitions, keep = false) {
@@ -320,147 +365,263 @@ const GlobalEffectEnv = /^(TZ|LANG|LANGUAGE|LC_\w+|R_\w+|TMPDIR|TEMP|TMP|HOME|PA
320
365
  function keyedReads(state, keys) {
321
366
  return keys.length === 0 || keys.includes(ambient_state_name_1.UnknownKey) ? [ambient_state_name_1.AmbientStateName.allOf(state)] : [...keys.map(k => ambient_state_name_1.AmbientStateName.keyed(state, k)), ambient_state_name_1.AmbientStateName.keyed(state, ambient_state_name_1.UnknownKey)];
322
367
  }
368
+ const Families = {
369
+ [ambient_effect_1.AmbientPart.Device]: { state: ambient_state_name_1.AmbientStateName.device, instances: ambient_state_name_1.GraphicsDevices },
370
+ [ambient_effect_1.AmbientPart.Sink]: { state: ambient_state_name_1.AmbientStateName.sink, instances: ambient_state_name_1.OutputSinks },
371
+ [ambient_effect_1.AmbientPart.MessageSink]: { state: ambient_state_name_1.MessageSinks.switched, instances: ambient_state_name_1.MessageSinks },
372
+ [ambient_effect_1.AmbientPart.Plot]: { state: ambient_state_name_1.AmbientStateName.plot, of: ambient_state_name_1.GraphicsDevices },
373
+ [ambient_state_name_1.KeyedState.Par]: { state: ambient_state_name_1.AmbientStateName.graphics, keyed: ambient_state_name_1.KeyedState.Par, of: ambient_state_name_1.GraphicsDevices },
374
+ [ambient_effect_1.AmbientPart.Palette]: { state: ambient_state_name_1.AmbientStateName.palette },
375
+ [ambient_effect_1.AmbientPart.LastPlot]: { state: ambient_state_name_1.AmbientStateName.lastPlot },
376
+ [ambient_state_name_1.KeyedState.Option]: { state: ambient_state_name_1.AmbientStateName.allOptions, keyed: ambient_state_name_1.KeyedState.Option },
377
+ [ambient_state_name_1.KeyedState.Env]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.Env), keyed: ambient_state_name_1.KeyedState.Env },
378
+ [ambient_state_name_1.KeyedState.Locale]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.Locale), keyed: ambient_state_name_1.KeyedState.Locale },
379
+ [ambient_state_name_1.KeyedState.SearchPath]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.SearchPath), keyed: ambient_state_name_1.KeyedState.SearchPath },
380
+ [ambient_effect_1.AmbientPart.Rng]: { state: ambient_state_name_1.AmbientStateName.rng },
381
+ [ambient_effect_1.AmbientPart.RngKind]: { state: ambient_state_name_1.AmbientStateName.rngKind },
382
+ [ambient_effect_1.AmbientPart.WorkingDirectory]: { state: ambient_state_name_1.AmbientStateName.workingDirectory },
383
+ [ambient_effect_1.AmbientPart.Directories]: { state: ambient_state_name_1.AmbientStateName.directories },
384
+ [ambient_effect_1.AmbientPart.Files]: { state: ambient_state_name_1.AmbientStateName.files },
385
+ [ambient_effect_1.AmbientPart.ProjectRoot]: { state: ambient_state_name_1.AmbientStateName.projectRoot },
386
+ [ambient_effect_1.AmbientPart.LibPaths]: { state: ambient_state_name_1.AmbientStateName.libPaths },
387
+ [ambient_effect_1.AmbientPart.Umask]: { state: ambient_state_name_1.AmbientStateName.umask },
388
+ [ambient_effect_1.AmbientPart.Finalizers]: { state: ambient_state_name_1.AmbientStateName.finalizers },
389
+ [ambient_effect_1.AmbientPart.TextConnection]: { state: ambient_state_name_1.AmbientStateName.anyFile },
390
+ [ambient_effect_1.AmbientPart.ErrorMessage]: { state: ambient_state_name_1.AmbientStateName.errorMessage }
391
+ };
392
+ /** Whether an effect changes the state, so a call whose only changes are off only queries it. */
393
+ function changes(effect) {
394
+ return effect.access !== ambient_effect_1.AmbientVerb.Reads && effect.access !== ambient_effect_1.AmbientVerb.Builds;
395
+ }
396
+ /** Whether the `condition` holds for the arguments `args`, what values are known decided with `data`. */
397
+ function holds(condition, args, data) {
398
+ if (condition === 'no-arguments') {
399
+ return args.length === 0 ? logic_1.Ternary.Always : logic_1.Ternary.Never;
400
+ }
401
+ else if (condition === 'query') {
402
+ return isQuery(args) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
403
+ }
404
+ else if ('flag' in condition) {
405
+ const flag = args.find(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) === condition.flag);
406
+ return flag === undefined || flag === r_function_call_1.EmptyArgument ? logic_1.Ternary.Never : r_logical_1.RLogical.is(flag.value) ? flag.value.content ? logic_1.Ternary.Always : logic_1.Ternary.Never : data === undefined ? logic_1.Ternary.Maybe : (0, built_in_ambient_keys_1.flagValue)(flag.value, data);
407
+ }
408
+ else if ('calls' in condition) {
409
+ return argumentCalls(match_args_1.MatchArgs.toNames(args, condition.formals).get(condition.arg), condition.calls, data);
410
+ }
411
+ else if ('arg' in condition) {
412
+ return argumentIs(match_args_1.MatchArgs.toNames(args, condition.formals).get(condition.arg), condition.is, data);
413
+ }
414
+ return args.some((a, i) => a !== r_function_call_1.EmptyArgument && (a.name === undefined ? i >= condition.besides.length : !condition.besides.includes(identifier_1.Identifier.getName(a.name.content)))) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
415
+ }
416
+ /** Whether the argument is one of the strings `is`, `null` standing for a missing or `NULL` argument. */
417
+ function argumentIs(arg, is, data) {
418
+ const value = r_argument_1.RArgument.valueOf(arg);
419
+ if (value === undefined || (r_symbol_1.RSymbol.is(value) && value.content === convert_values_1.RNull)) {
420
+ return is.includes(null) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
421
+ }
422
+ /* an argument given is taken for a value, `NULL` only if written so */
423
+ const strings = r_string_1.RString.is(value) ? [value.content.str] : data === undefined ? undefined : (0, built_in_ambient_keys_1.stringValuesOf)(value, data);
424
+ if (!is.some(v => v !== null)) {
425
+ return logic_1.Ternary.Never;
426
+ }
427
+ else if (strings === undefined) {
428
+ return logic_1.Ternary.Maybe;
429
+ }
430
+ const known = strings.map(v => is.includes(v));
431
+ return known.every(Boolean) ? logic_1.Ternary.Always : known.some(Boolean) ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
432
+ }
433
+ /** Whether the argument is a call of one of the functions `calls`, or a variable bound to one. */
434
+ function argumentCalls(arg, calls, data) {
435
+ if (arg === undefined) {
436
+ return logic_1.Ternary.Never;
437
+ }
438
+ const values = data === undefined ? [r_argument_1.RArgument.valueOf(arg)].filter(assert_1.isNotUndefined) : boundValues(arg.info.id, data);
439
+ const known = values.map(v => r_function_call_1.RFunctionCall.isNamed(v, new Set(calls)));
440
+ return known.length === 0 ? logic_1.Ternary.Maybe : known.every(Boolean) ? logic_1.Ternary.Always : known.some(Boolean) ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
441
+ }
442
+ /** Whether the effect happens for the arguments `args`, see {@link AmbientEffect#when}. */
443
+ function applies(effect, args, data) {
444
+ return logic_1.TernaryLogic.and(effect.when === undefined ? logic_1.Ternary.Always : holds(effect.when, args, data), effect.unless === undefined ? logic_1.Ternary.Always : logic_1.TernaryLogic.negate(holds(effect.unless, args, data)));
445
+ }
446
+ /**
447
+ * What the effect on a part without instances does to its state, for the entries `keys` (all of them if `undefined`).
448
+ * A part of the active instance of a family opens one on the fly, a drawing on the plot writes the canvas with `drawing`.
449
+ * With `maybe` the arguments are unknown, so a reset only adds and an entry is not known to be removed.
450
+ */
451
+ function stateAccess(effect, keys, maybe, drawing) {
452
+ const { state, keyed, of } = Families[effect.family];
453
+ const { access } = effect;
454
+ if (access === ambient_effect_1.AmbientVerb.Builds) {
455
+ return { reads: [], writes: [], kills: [] };
456
+ }
457
+ const read = keyed === undefined ? [state] : keyedReads(keyed, keys ?? []);
458
+ const written = keyed === undefined ? [state] : keys === undefined ? [ambient_state_name_1.AmbientStateName.allOf(keyed)] : (0, built_in_ambient_keys_1.keyedWrites)(keyed, keys);
459
+ const writes = [
460
+ ...of === undefined ? [] : [of.used],
461
+ ...drawing && effect.family === ambient_effect_1.AmbientPart.Plot && (access === ambient_effect_1.AmbientVerb.Adds || access === ambient_effect_1.AmbientVerb.Resets) ? [ambient_state_name_1.AmbientStateName.canvas] : [],
462
+ ...access === ambient_effect_1.AmbientVerb.Reads ? [] : access === ambient_effect_1.AmbientVerb.Resets && !maybe ? written.map(name => ({ name, mode: AmbientWriteMode.Reset })) : written
463
+ ];
464
+ return {
465
+ /* with unknown arguments, a reset may add to what is there (`plot(f, add = TRUE)`) */
466
+ reads: access === ambient_effect_1.AmbientVerb.Reads || access === ambient_effect_1.AmbientVerb.Adds || (maybe && access === ambient_effect_1.AmbientVerb.Resets) ? read : [],
467
+ writes,
468
+ kills: access === ambient_effect_1.AmbientVerb.Kills && !maybe ? written.filter(n => keyed === undefined || n !== ambient_state_name_1.AmbientStateName.allOf(keyed)) : []
469
+ };
470
+ }
323
471
  /** Whether a call drawing on a device writes its canvas, see `semantics.ambient.drawingWritesDevice`. */
324
472
  function drawingWritesDevice(config) {
325
473
  return config.semantics.ambient?.drawingWritesDevice === true;
326
474
  }
327
- /** Wires the {@link AmbientStateAccess} of a call into its dataflow information: reads become unknown references, writes define the pseudo variable globally. */
328
- function applyAmbientStateAccess(res, args, rootId, data, access) {
329
- if (!('type' in access)) {
330
- return access.reduce((r, a) => applyAmbientStateAccess(r, args, rootId, data, a), res);
331
- }
332
- else if (args === UnknownArguments) {
333
- return applyWithUnknownArguments(res, rootId, data, access);
334
- }
335
- const reads = [];
336
- const writes = [];
337
- switch (access.type) {
338
- case "read-graphics" /* AmbientStateAccessType.ReadGraphics */:
339
- reads.push(ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette);
340
- if (drawingWritesDevice(data.ctx.config)) {
341
- writes.push(ambient_state_name_1.AmbientStateName.canvas);
342
- }
343
- break;
344
- case "set-graphics" /* AmbientStateAccessType.SetGraphics */:
345
- /* the call returns the previous state */
346
- reads.push(ambient_state_name_1.AmbientStateName.graphics);
347
- if (onlyQueries(access, args)) {
348
- if (access.queryLinksTo) {
349
- (0, unknown_side_effect_1.handleUnknownSideEffect)(res.graph, res.environment, rootId, access.queryLinksTo);
350
- }
351
- }
352
- else {
353
- writes.push(ambient_state_name_1.AmbientStateName.graphics, ...access.keys === undefined ? [] : (0, built_in_ambient_keys_1.keyedWrites)(ambient_state_name_1.KeyedState.Par, (0, built_in_ambient_keys_1.keysOf)(access.keys, args, data)));
354
- }
355
- break;
356
- case "set-palette" /* AmbientStateAccessType.SetPalette */:
357
- reads.push(ambient_state_name_1.AmbientStateName.palette);
358
- if (!onlyQueries(access, args)) {
359
- writes.push(ambient_state_name_1.AmbientStateName.palette);
360
- }
361
- break;
362
- case "read-options" /* AmbientStateAccessType.ReadOptions */: {
363
- const dispatched = access.dispatchOn === undefined ? undefined : r_argument_1.RArgument.valueOf(args[access.dispatchOn]);
364
- reads.push(...printingReads(dispatched, access.dispatchOn !== undefined, access.keys, data));
365
- break;
366
- }
367
- case "get-option" /* AmbientStateAccessType.GetOption */: {
368
- const first = args.find(a => a !== r_function_call_1.EmptyArgument && (a.name === undefined || identifier_1.Identifier.getName(a.name.content) === 'x'));
369
- const keys = (0, built_in_ambient_keys_1.stringValuesOf)(r_argument_1.RArgument.valueOf(first), data);
370
- reads.push(...optionReads(keys));
371
- if (args.length === 1) {
372
- linkOptionValue(res, rootId, keys, data);
373
- }
374
- break;
475
+ /** Wires the {@link AmbientEffect}s of a call into its dataflow information: reads become unknown references, writes define the pseudo variable globally. */
476
+ function applyAmbientEffects(res, args, rootId, data, effects) {
477
+ for (const effect of ambient_effect_1.Ambient.list(effects)) {
478
+ if (args === UnknownArguments) {
479
+ res = applyWithUnknownArguments(res, rootId, data, effect);
375
480
  }
376
- case "set-options" /* AmbientStateAccessType.SetOptions */:
377
- return setOptions(res, args, rootId, data);
378
- case "set-keyed" /* AmbientStateAccessType.SetKeyed */: {
379
- const keys = (0, built_in_ambient_keys_1.keysOf)(access.keys, args, data);
380
- /* a variable R or a child process reads by itself is read by calls we cannot name */
381
- if (access.state === ambient_state_name_1.KeyedState.Env && keys.some(k => k === ambient_state_name_1.UnknownKey || GlobalEffectEnv.test(k))) {
382
- res.graph.markIdForUnknownSideEffects(rootId);
481
+ else {
482
+ const happens = applies(effect, args, data);
483
+ if (happens !== logic_1.Ternary.Never) {
484
+ res = applyEffect(res, args, rootId, data, effect, happens === logic_1.Ternary.Maybe);
383
485
  }
384
- writes.push(...(0, built_in_ambient_keys_1.keyedWrites)(access.state, keys));
385
- break;
386
486
  }
387
- case "read-keyed" /* AmbientStateAccessType.ReadKeyed */:
388
- reads.push(...keyedReads(access.state, (0, built_in_ambient_keys_1.keysOf)(access.keys, args, data)));
389
- break;
390
- case "set-state" /* AmbientStateAccessType.SetState */:
391
- if (!onlyQueries(access, args)) {
392
- writes.push(access.state);
393
- }
394
- break;
395
- case "read-state" /* AmbientStateAccessType.ReadState */:
396
- reads.push(access.state);
397
- break;
398
- case "open-device" /* AmbientStateAccessType.OpenDevice */:
399
- return deviceAccess(res, rootId, data, DeviceAccess.Open);
400
- case "close-device" /* AmbientStateAccessType.CloseDevice */:
401
- /* `dev.off(which)` may close a device other than the active one, which keeps its state then */
402
- return deviceAccess(res, rootId, data, access.all ? DeviceAccess.CloseAll : args.length > 0 ? DeviceAccess.Switch : DeviceAccess.Close);
403
- case "switch-device" /* AmbientStateAccessType.SwitchDevice */:
404
- return deviceAccess(res, rootId, data, DeviceAccess.Switch);
405
- case "set-rng" /* AmbientStateAccessType.SetRng */: {
406
- const kindFrom = access.kindFrom ?? 1;
407
- reads.push(ambient_state_name_1.AmbientStateName.rngKind);
408
- if (kindFrom > 0) {
409
- writes.push(ambient_state_name_1.AmbientStateName.rng);
410
- }
411
- /* a new kind reseeds the generator from its current state, so it changes the stream as well */
412
- if (args.some((a, i) => a !== r_function_call_1.EmptyArgument && (a.name === undefined ? i >= kindFrom : identifier_1.Identifier.getName(a.name.content) !== 'seed'))) {
413
- reads.push(ambient_state_name_1.AmbientStateName.rng);
414
- writes.push(ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.rng);
487
+ }
488
+ return res;
489
+ }
490
+ /** Applies the effect, which only `maybe` happens. */
491
+ function applyEffect(res, args, rootId, data, effect, maybe = false) {
492
+ const { instances, keyed } = Families[effect.family];
493
+ if (instances !== undefined) {
494
+ return instanceAccess(res, rootId, data, effect, instances, args.length > 0);
495
+ }
496
+ const keys = effect.member === undefined || effect.member === 'every' ? undefined : (0, built_in_ambient_keys_1.keysOf)(effect.member, args, data);
497
+ switch (effect.family) {
498
+ case ambient_state_name_1.KeyedState.Option:
499
+ return effect.access === ambient_effect_1.AmbientVerb.Reads ? readOptions(res, args, rootId, data, effect, keys) : setOptions(res, args, rootId, data);
500
+ case ambient_effect_1.AmbientPart.Files:
501
+ return fileAccess(res, rootId, data, effect);
502
+ case ambient_effect_1.AmbientPart.TextConnection:
503
+ return openTextConnection(res, args, rootId, data);
504
+ case ambient_effect_1.AmbientPart.Finalizers:
505
+ return effect.access === ambient_effect_1.AmbientVerb.Reads ? runFinalizers(res, rootId, data) : registerFinalizer(res, args, rootId, data);
506
+ case ambient_effect_1.AmbientPart.LastPlot:
507
+ if (changes(effect)) {
508
+ /* the plot object is what the outermost `+` the call is part of builds */
509
+ recordAmbient(res.graph, rootId, res.environment, [], [ambient_state_name_1.AmbientStateName.lastPlot]);
510
+ return { ...res, environment: defineAmbient(res.environment, outermostPlus(rootId, data.completeAst.idMap), data.cds ? [...data.cds] : undefined, [ambient_state_name_1.AmbientStateName.lastPlot]) };
415
511
  }
416
512
  break;
417
- }
418
- case "draw-rng" /* AmbientStateAccessType.DrawRng */:
419
- reads.push(ambient_state_name_1.AmbientStateName.rng);
420
- writes.push(ambient_state_name_1.AmbientStateName.rng);
421
- break;
422
- case "read-files" /* AmbientStateAccessType.ReadFiles */: {
423
- const stems = fileStems(res, rootId, data, access);
424
- if (stems?.length === 0) {
425
- break;
513
+ case ambient_state_name_1.KeyedState.Env:
514
+ case ambient_state_name_1.KeyedState.Par:
515
+ if (effect.handsBack && keys !== undefined && keyed !== undefined) {
516
+ linkEntryValue(res, rootId, keyed, keys, data);
426
517
  }
427
- reads.push(ambient_state_name_1.AmbientStateName.workingDirectory, ...stems === undefined ? [ambient_state_name_1.AmbientStateName.files] : [...stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.anyFile]);
428
- /* a read through a connection the program holds moves its position, so the next read depends on this one */
429
- if (readsThroughHandle(res, rootId, data, access.sig)) {
430
- writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] : stems.map(ambient_state_name_1.AmbientStateName.file));
431
- }
432
- break;
433
- }
434
- case "write-files" /* AmbientStateAccessType.WriteFiles */: {
435
- const stems = fileStems(res, rootId, data, access);
436
- if (stems?.length === 0) {
437
- break;
518
+ /* a variable R or a child process reads by itself is read by calls we cannot name */
519
+ if (effect.family === ambient_state_name_1.KeyedState.Env && changes(effect) && keys?.some(k => k === ambient_state_name_1.UnknownKey || GlobalEffectEnv.test(k))) {
520
+ res.graph.markIdForUnknownSideEffects(rootId);
438
521
  }
439
- reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
440
- writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files);
441
522
  break;
442
- }
443
- case "set-working-directory" /* AmbientStateAccessType.SetWorkingDirectory */:
444
- /* a relative `dir` resolves against the current one, which the call also returns */
445
- reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
446
- writes.push(ambient_state_name_1.AmbientStateName.workingDirectory);
447
- break;
448
- case "get-working-directory" /* AmbientStateAccessType.GetWorkingDirectory */:
449
- reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
450
- break;
451
- case "open-text-connection" /* AmbientStateAccessType.OpenTextConnection */:
452
- return openTextConnection(res, args, rootId, data);
453
- case "register-finalizer" /* AmbientStateAccessType.RegisterFinalizer */:
454
- return registerFinalizer(res, args, rootId, data);
455
- case "run-finalizers" /* AmbientStateAccessType.RunFinalizers */: {
456
- const registered = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.finalizers, data.environment) ?? []).filter(identifier_1.isInGraphDefinition);
457
- for (const fn of registered.flatMap(d => d.value ?? [])) {
458
- res.graph.addEdge(rootId, fn, edge_1.EdgeType.Calls);
459
- }
460
- return withAccess(res, rootId, data, [ambient_state_name_1.AmbientStateName.finalizers], registered.flatMap(d => d.writes ?? []).map(maybe));
523
+ }
524
+ const { reads, writes, kills } = stateAccess(effect, keyed === undefined ? undefined : keys, maybe, drawingWritesDevice(data.ctx.config));
525
+ return withAccess(res, rootId, data, reads, (0, arrays_1.uniqueArray)(writes), kills);
526
+ }
527
+ /** What the effect on an instance family does: opening, closing, and switching move the states of the instances, see {@link deviceAccess}. */
528
+ function instanceAccess(res, rootId, data, effect, family, named) {
529
+ const { state } = Families[effect.family];
530
+ switch (effect.access) {
531
+ case ambient_effect_1.AmbientVerb.Opens:
532
+ return deviceAccess(res, rootId, data, DeviceAccess.Open, family);
533
+ case ambient_effect_1.AmbientVerb.Switches:
534
+ return deviceAccess(res, rootId, data, DeviceAccess.Switch, family);
535
+ case ambient_effect_1.AmbientVerb.Closes:
536
+ /* `dev.off(which)` may close an instance other than the active one, which keeps its state then */
537
+ return deviceAccess(res, rootId, data, effect.member === 'every' ? DeviceAccess.CloseAll : named ? DeviceAccess.CloseSome : DeviceAccess.Close, family);
538
+ default: {
539
+ const { reads, writes } = instanceStateAccess(effect, state, family);
540
+ return withAccess(res, rootId, data, reads, writes);
461
541
  }
462
542
  }
463
- return withAccess(res, rootId, data, reads, (0, arrays_1.uniqueArray)(writes));
543
+ }
544
+ /** What reading or using an instance does, `every` one with {@link AmbientEffect#member}: using it adds to what its closing links to. */
545
+ function instanceStateAccess(effect, state, family) {
546
+ const others = family.states.find(([active]) => active === state)?.[1];
547
+ return {
548
+ reads: effect.access === ambient_effect_1.AmbientVerb.Builds ? [] : [state, ...effect.member === 'every' && others !== undefined ? [others] : []],
549
+ writes: changes(effect) ? [family.used] : []
550
+ };
551
+ }
552
+ /** What reading options does: the entries `keys` names, all options if a method may print the value `print(x)` dispatches on, which draws a plot object. */
553
+ function readOptions(res, args, rootId, data, effect, keys) {
554
+ if (effect.dispatchOn !== undefined) {
555
+ const dispatched = r_argument_1.RArgument.valueOf(args[effect.dispatchOn]);
556
+ return withAccess(res, rootId, data, printingReads(dispatched, true, keys ?? [], data), mayHoldPlot(dispatched, data) ? DrawsNewPlot : []);
557
+ }
558
+ if (effect.handsBack) {
559
+ linkEntryValue(res, rootId, ambient_state_name_1.KeyedState.Option, keys ?? [], data);
560
+ }
561
+ return withAccess(res, rootId, data, keyedReads(ambient_state_name_1.KeyedState.Option, keys ?? []));
562
+ }
563
+ /** what every access of a file reads to find it: the working directory a relative path starts from and the directories the path leads through */
564
+ const FileSystemReads = [ambient_state_name_1.AmbientStateName.workingDirectory, ambient_state_name_1.AmbientStateName.directories];
565
+ /** What reading or writing the files the call names does, see {@link fileStems}. */
566
+ function fileAccess(res, rootId, data, effect) {
567
+ const stems = fileStems(res, rootId, data, effect);
568
+ if (stems?.length === 0) {
569
+ return res;
570
+ }
571
+ if (effect.access === ambient_effect_1.AmbientVerb.Reads) {
572
+ /* a read through a connection the program holds moves its position, so the next read depends on this one */
573
+ const moves = readsThroughHandle(res, rootId, data, effect.sig) ? stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] : stems.map(ambient_state_name_1.AmbientStateName.file) : [];
574
+ return withAccess(res, rootId, data, [...FileSystemReads, ...stems === undefined ? [ambient_state_name_1.AmbientStateName.files] : [...stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.anyFile]], moves);
575
+ }
576
+ return withAccess(res, rootId, data, FileSystemReads, [...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files]);
577
+ }
578
+ /** `gc()` may run every registered finalizer whose object is released. */
579
+ function runFinalizers(res, rootId, data) {
580
+ const registered = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.finalizers, data.environment) ?? []).filter(identifier_1.isInGraphDefinition);
581
+ for (const fn of registered.flatMap(d => d.value ?? [])) {
582
+ res.graph.addEdge(rootId, fn, edge_1.EdgeType.Calls);
583
+ }
584
+ return withAccess(res, rootId, data, [ambient_state_name_1.AmbientStateName.finalizers], registered.flatMap(d => d.writes ?? []).map(maybe));
585
+ }
586
+ /** drawing a new plot adds to the device, which opens one if none is open, and replaces its plot */
587
+ const DrawsNewPlot = [ambient_state_name_1.AmbientStateName.device, { name: ambient_state_name_1.AmbientStateName.plot, mode: AmbientWriteMode.Reset }];
588
+ /**
589
+ * Whether the value of `node` may be a plot object, which printing draws: a call building one ({@link AmbientVerb.Builds}, as `ggplot` does),
590
+ * a `+` adding to one, or a variable bound to either.
591
+ */
592
+ function mayHoldPlot(node, data, seen = new Set()) {
593
+ if (node === undefined || seen.has(node.info.id)) {
594
+ return false;
595
+ }
596
+ seen.add(node.info.id);
597
+ if (r_function_call_1.RFunctionCall.isNamed(node)) {
598
+ return ((0, query_fn_props_1.statedFunctions)(node.functionName.content, data.environment) ?? [])
599
+ .some(t => hiddenAccess(t).some(a => a.family === ambient_effect_1.AmbientPart.Plot && a.access === ambient_effect_1.AmbientVerb.Builds));
600
+ }
601
+ else if (r_binary_op_1.RBinaryOp.is(node)) {
602
+ return node.operator === '+' && (mayHoldPlot(node.lhs, data, seen) || mayHoldPlot(node.rhs, data, seen));
603
+ }
604
+ else if (r_if_then_else_1.RIfThenElse.is(node)) {
605
+ return mayHoldPlot(node.then, data, seen) || mayHoldPlot(node.otherwise, data, seen);
606
+ }
607
+ else if (r_expression_list_1.RExpressionList.is(node)) {
608
+ return mayHoldPlot(node.children.at(-1), data, seen);
609
+ }
610
+ else if (!r_symbol_1.RSymbol.is(node)) {
611
+ return false;
612
+ }
613
+ return (resolve_helper_1.Resolve.byName(node.content, data.environment) ?? []).filter(identifier_1.isInGraphDefinition).some(d => {
614
+ const source = data.completeAst.idMap.get(d.definedAt);
615
+ return r_binary_op_1.RBinaryOp.is(source) && mayHoldPlot(source.lhs.info.id === d.nodeId ? source.rhs : source.lhs, data, seen);
616
+ });
617
+ }
618
+ /** the outermost `+` chain holding `id`, `id` itself if it is part of none */
619
+ function outermostPlus(id, idMap) {
620
+ let at = idMap.get(id);
621
+ for (let parent = at === undefined ? undefined : model_1.RNode.directParent(at, idMap); r_binary_op_1.RBinaryOp.is(parent) && parent.operator === '+'; parent = model_1.RNode.directParent(parent, idMap)) {
622
+ at = parent;
623
+ }
624
+ return at?.info.id ?? id;
464
625
  }
465
626
  /** `reg.finalizer(e, f)` keeps the functions `f` may be, and the name holding `e`, whose release lets `gc()` run them. */
466
627
  function registerFinalizer(res, args, rootId, data) {
@@ -581,133 +742,120 @@ function isPlainValue(node, data) {
581
742
  }
582
743
  /** The arguments of a call made on our behalf, like `do.call(par, args)`, which we cannot see. */
583
744
  const UnknownArguments = Symbol('unknown-arguments');
584
- function applyWithUnknownArguments(res, rootId, data, access) {
585
- switch (access.type) {
586
- case "close-device" /* AmbientStateAccessType.CloseDevice */:
587
- return deviceAccess(res, rootId, data, access.all ? DeviceAccess.CloseAll : DeviceAccess.Switch);
745
+ function applyWithUnknownArguments(res, rootId, data, effect) {
746
+ const { instances } = Families[effect.family];
747
+ if (instances !== undefined && effect.access !== ambient_effect_1.AmbientVerb.Reads && effect.access !== ambient_effect_1.AmbientVerb.Adds) {
748
+ /* we cannot tell which instance a close closes */
749
+ return instanceAccess(res, rootId, data, effect, instances, true);
750
+ }
751
+ else if (effect.family === ambient_effect_1.AmbientPart.Files) {
588
752
  /* the arguments handed on (`do.call(readLines, list("a.txt"))`, `lapply(files, readLines)`) may still name the files */
589
- case "open-device" /* AmbientStateAccessType.OpenDevice */:
590
- case "switch-device" /* AmbientStateAccessType.SwitchDevice */:
591
- case "read-files" /* AmbientStateAccessType.ReadFiles */:
592
- case "write-files" /* AmbientStateAccessType.WriteFiles */:
593
- return applyAmbientStateAccess(res, [], rootId, data, access);
594
- case "set-options" /* AmbientStateAccessType.SetOptions */:
595
- /* like `options(op)`: it may set anything */
596
- res.graph.markIdForUnknownSideEffects(rootId);
597
- }
598
- const { reads, writes } = unknownArgumentAccess(access, drawingWritesDevice(data.ctx.config));
753
+ return applyEffect(res, [], rootId, data, effect);
754
+ }
755
+ else if (effect.family === ambient_state_name_1.KeyedState.Option && changes(effect)) {
756
+ /* like `options(op)`: it may set anything */
757
+ res.graph.markIdForUnknownSideEffects(rootId);
758
+ }
759
+ const { reads, writes } = unknownArgumentAccess(effect, drawingWritesDevice(data.ctx.config));
599
760
  return withAccess(res, rootId, data, reads, writes);
600
761
  }
601
- const Devices = { reads: [], writes: [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device] };
602
762
  /* evaluated code may attach a package as well, which every call nothing else resolves reads */
603
763
  const Quoted = { reads: [ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette], writes: [ambient_state_name_1.AmbientStateName.unknownOption, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.SearchPath)] };
604
- /** What a call of the given kind may read and write when its arguments are unknown, as when only linking reveals it. */
605
- const UnknownArgumentAccess = {
606
- ["set-options" /* AmbientStateAccessType.SetOptions */]: { reads: [ambient_state_name_1.AmbientStateName.allOptions], writes: [ambient_state_name_1.AmbientStateName.unknownOption, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.warnsAsErrors] },
607
- ["get-option" /* AmbientStateAccessType.GetOption */]: { reads: [ambient_state_name_1.AmbientStateName.allOptions], writes: [] },
608
- ["set-graphics" /* AmbientStateAccessType.SetGraphics */]: { reads: [ambient_state_name_1.AmbientStateName.graphics], writes: [ambient_state_name_1.AmbientStateName.graphics] },
609
- ["read-graphics" /* AmbientStateAccessType.ReadGraphics */]: { reads: [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette], writes: [] },
610
- ["set-palette" /* AmbientStateAccessType.SetPalette */]: { reads: [ambient_state_name_1.AmbientStateName.palette], writes: [ambient_state_name_1.AmbientStateName.palette] },
611
- ["open-device" /* AmbientStateAccessType.OpenDevice */]: Devices,
612
- ["close-device" /* AmbientStateAccessType.CloseDevice */]: Devices,
613
- ["switch-device" /* AmbientStateAccessType.SwitchDevice */]: Devices,
614
- ["set-rng" /* AmbientStateAccessType.SetRng */]: { reads: [ambient_state_name_1.AmbientStateName.rngKind], writes: [ambient_state_name_1.AmbientStateName.rng, ambient_state_name_1.AmbientStateName.rngKind] },
615
- ["draw-rng" /* AmbientStateAccessType.DrawRng */]: { reads: [ambient_state_name_1.AmbientStateName.rng], writes: [ambient_state_name_1.AmbientStateName.rng] },
616
- ["read-files" /* AmbientStateAccessType.ReadFiles */]: { reads: [ambient_state_name_1.AmbientStateName.workingDirectory, ambient_state_name_1.AmbientStateName.files], writes: [] },
617
- ["write-files" /* AmbientStateAccessType.WriteFiles */]: { reads: [ambient_state_name_1.AmbientStateName.workingDirectory], writes: [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] },
618
- ["set-working-directory" /* AmbientStateAccessType.SetWorkingDirectory */]: { reads: [ambient_state_name_1.AmbientStateName.workingDirectory], writes: [ambient_state_name_1.AmbientStateName.workingDirectory] },
619
- ["get-working-directory" /* AmbientStateAccessType.GetWorkingDirectory */]: { reads: [ambient_state_name_1.AmbientStateName.workingDirectory], writes: [] },
620
- ["open-text-connection" /* AmbientStateAccessType.OpenTextConnection */]: { reads: [], writes: [] },
621
- ["register-finalizer" /* AmbientStateAccessType.RegisterFinalizer */]: { reads: [], writes: [ambient_state_name_1.AmbientStateName.finalizers] },
622
- ["run-finalizers" /* AmbientStateAccessType.RunFinalizers */]: { reads: [ambient_state_name_1.AmbientStateName.finalizers], writes: [] }
623
- };
624
- function unknownArgumentAccess(access, drawing) {
625
- switch (access.type) {
626
- case "read-options" /* AmbientStateAccessType.ReadOptions */:
627
- return { reads: optionReads(access.dispatchOn === undefined ? access.keys : undefined), writes: [] };
628
- case "set-keyed" /* AmbientStateAccessType.SetKeyed */:
629
- return { reads: [], writes: (0, built_in_ambient_keys_1.keyedWrites)(access.state, [ambient_state_name_1.UnknownKey]) };
630
- case "read-keyed" /* AmbientStateAccessType.ReadKeyed */:
631
- return { reads: [ambient_state_name_1.AmbientStateName.allOf(access.state)], writes: [] };
632
- case "set-state" /* AmbientStateAccessType.SetState */:
633
- return { reads: [], writes: [access.state] };
634
- case "read-state" /* AmbientStateAccessType.ReadState */:
635
- return { reads: [access.state], writes: [] };
636
- case "read-graphics" /* AmbientStateAccessType.ReadGraphics */:
637
- return { reads: UnknownArgumentAccess[access.type].reads, writes: drawing ? [ambient_state_name_1.AmbientStateName.canvas] : [] };
638
- default:
639
- return UnknownArgumentAccess[access.type];
640
- }
641
- }
642
- /** Graphics parameters are per device; within a function the open devices are unknown, so a device call only adds. */
643
- function deviceAccess(res, rootId, data, kind) {
644
- /* only a switch reads the state; what a closed device holds reaches its file through the plots on it (see LinkToLastPlot) */
645
- const reads = kind === DeviceAccess.Switch ? [ambient_state_name_1.AmbientStateName.graphics] : [];
764
+ /** What the effect may read and write when the arguments of the call are unknown, as when only linking reveals it: any condition may hold, and any entry be named but stated ones. */
765
+ function unknownArgumentAccess(effect, drawing) {
766
+ const { state, instances } = Families[effect.family];
767
+ if (instances !== undefined) {
768
+ return effect.access === ambient_effect_1.AmbientVerb.Reads || effect.access === ambient_effect_1.AmbientVerb.Adds ? instanceStateAccess(effect, state, instances) : { reads: [], writes: activeStates(instances) };
769
+ }
770
+ switch (effect.family) {
771
+ case ambient_state_name_1.KeyedState.Option:
772
+ if (changes(effect)) {
773
+ return { reads: [ambient_state_name_1.AmbientStateName.allOptions], writes: [ambient_state_name_1.AmbientStateName.unknownOption, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.warnsAsErrors] };
774
+ }
775
+ break;
776
+ case ambient_effect_1.AmbientPart.Files:
777
+ return effect.access === ambient_effect_1.AmbientVerb.Reads ? { reads: [...FileSystemReads, ambient_state_name_1.AmbientStateName.files], writes: [] }
778
+ : { reads: FileSystemReads, writes: [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] };
779
+ case ambient_effect_1.AmbientPart.TextConnection:
780
+ return { reads: [], writes: [] };
781
+ case ambient_effect_1.AmbientPart.Finalizers:
782
+ return effect.access === ambient_effect_1.AmbientVerb.Reads ? { reads: [state], writes: [] } : { reads: [], writes: [state] };
783
+ }
784
+ const member = effect.member;
785
+ const keys = typeof member === 'object' && member.from === 'constant' && effect.dispatchOn === undefined ? member.keys : [ambient_state_name_1.UnknownKey];
786
+ const { reads, writes } = stateAccess(effect, Families[effect.family].keyed === undefined ? undefined : keys, true, drawing);
787
+ return { reads, writes: writes.map(w => typeof w === 'string' ? w : w.name) };
788
+ }
789
+ /**
790
+ * Opens, closes, or switches an instance of the `family` (a graphics device), each of whose states is per instance.
791
+ * A close reads the calls that opened and used the closed instance, the explicit opening reads the close in turn, so keeping it keeps the close.
792
+ * Within a function the open instances are unknown, so a call only adds.
793
+ */
794
+ function deviceAccess(res, rootId, data, kind, family = ambient_state_name_1.GraphicsDevices) {
795
+ const otherOf = (state) => family.states.find(([active]) => active === state)?.[1] ?? state;
796
+ const actives = activeStates(family);
797
+ /* `x <- dev.off()` is the device that is active afterward, one of the others */
798
+ const closing = kind === DeviceAccess.Close ? [family.used, ...resultIsUsed(rootId, data) ? [otherOf(family.used)] : []] : [];
799
+ const all = [family.used, otherOf(family.used)];
800
+ const reads = kind === DeviceAccess.Switch ? [family.switched] : kind === DeviceAccess.CloseSome ? [family.switched, ...all] : kind === DeviceAccess.CloseAll ? all : closing;
646
801
  /* closing writes the file of the device, which its opening names unless we do not know the device closed */
647
802
  const unnamedFile = kind === DeviceAccess.Open ? [] : [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files];
648
803
  const cds = data.cds ? [...data.cds] : undefined;
649
804
  if (data.environment.level > 0) {
650
805
  /* a device the body opened itself is the one a later close in the same body closes: `f <- function() { pdf("a.pdf"); plot(1); dev.off() }` writes `a.pdf` and no other file */
651
- const here = kind === DeviceAccess.Close ? res.environment.current.memory.get(ambient_state_name_1.AmbientStateName.deviceOpenedHere) ?? [] : [];
806
+ const here = kind === DeviceAccess.Close ? res.environment.current.memory.get(family.openedHere) ?? [] : [];
652
807
  for (const open of here) {
653
808
  res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
654
809
  }
655
- let environment = { ...res.environment, current: res.environment.current.removeAll([{ name: ambient_state_name_1.AmbientStateName.deviceOpenedHere }]) };
810
+ let environment = { ...res.environment, current: res.environment.current.removeAll([{ name: family.openedHere }]) };
656
811
  if (kind === DeviceAccess.Open) {
657
- environment = defineAmbient(environment, rootId, cds, [{ name: ambient_state_name_1.AmbientStateName.deviceOpenedHere, mode: AmbientWriteMode.Local }]);
812
+ environment = defineAmbient(environment, rootId, cds, [{ name: family.openedHere, mode: AmbientWriteMode.Local }]);
658
813
  }
659
- return withAccess({ ...res, environment }, rootId, data, reads, [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device, ...here.length > 0 ? [] : unnamedFile]);
814
+ recordAmbient(res.graph, rootId, environment, [], [], kind === DeviceAccess.Close || kind === DeviceAccess.CloseAll ? actives : []);
815
+ return withAccess({ ...res, environment }, rootId, data, reads, [...actives, ...here.length > 0 ? [] : unnamedFile]);
660
816
  }
661
817
  const lookup = (name) => resolve_helper_1.Resolve.byName(name, res.environment) ?? [];
662
- const current = lookup(ambient_state_name_1.AmbientStateName.graphics);
663
- const others = lookup(ambient_state_name_1.AmbientStateName.otherDevices);
664
- const opener = lookup(ambient_state_name_1.AmbientStateName.device);
665
- const otherOpeners = lookup(ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy);
666
- let environment = res.environment;
667
- const reset = (name) => defineAmbient(environment, rootId, cds, [{ name, mode: AmbientWriteMode.Reset }]);
668
- /* a later plot depends on neither the close nor the closed device's state; a device only depends on its close so it does not catch later plots */
669
- const closes = (openers) => {
670
- for (const open of openers) {
671
- res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
672
- }
673
- };
818
+ /* a use opening the device on the fly (`plot` without one) names no file and needs no close */
819
+ const closed = kind === DeviceAccess.Close ? lookup(family.opened) : kind === DeviceAccess.CloseAll ? [...lookup(family.opened), ...lookup(otherOf(family.opened))] : [];
820
+ for (const open of closed) {
821
+ res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
822
+ }
674
823
  /* in a loop, an earlier round may have opened a device this one leaves behind, or a close may leave one open */
675
824
  const repeats = model_1.RLoopConstructs.encloses(rootId, data.completeAst.idMap);
676
- const earlierRound = repeats ? [{ nodeId: rootId, name: ambient_state_name_1.AmbientStateName.device, type: identifier_1.ReferenceType.Variable, definedAt: rootId, cds: cds ?? [] }] : [];
677
- switch (kind) {
678
- case DeviceAccess.Open:
679
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevices, [...others, ...current, ...earlierRound]);
680
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy, [...otherOpeners, ...opener, ...earlierRound]);
681
- environment = reset(ambient_state_name_1.AmbientStateName.graphics);
682
- environment = reset(ambient_state_name_1.AmbientStateName.device);
683
- break;
684
- case DeviceAccess.Close:
685
- closes(opener);
686
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.graphics, repeats ? [...others, ...current] : others);
687
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.device, repeats ? [...otherOpeners, ...opener] : otherOpeners);
688
- break;
689
- case DeviceAccess.CloseAll:
690
- closes([...opener, ...otherOpeners]);
691
- for (const name of DeviceStates) {
692
- environment = setAmbient(environment, name, []);
693
- }
694
- break;
695
- case DeviceAccess.Switch:
696
- environment = defineAmbient(environment, rootId, cds, [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device]);
697
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.graphics, others, true);
698
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevices, current, true);
699
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.device, otherOpeners, true);
700
- environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy, opener, true);
701
- break;
825
+ const earlierRound = repeats ? [{ nodeId: rootId, name: family.used, type: identifier_1.ReferenceType.Variable, definedAt: rootId, cds: cds ?? [] }] : [];
826
+ let environment = res.environment;
827
+ if (kind === DeviceAccess.Switch || kind === DeviceAccess.CloseSome) {
828
+ environment = defineAmbient(environment, rootId, cds, actives);
829
+ }
830
+ for (const [active, others] of family.states) {
831
+ const current = lookup(active);
832
+ const other = lookup(others);
833
+ switch (kind) {
834
+ case DeviceAccess.Open:
835
+ environment = setAmbient(environment, others, [...other, ...current, ...earlierRound]);
836
+ environment = defineAmbient(environment, rootId, cds, [{ name: active, mode: AmbientWriteMode.Reset }]);
837
+ break;
838
+ case DeviceAccess.Close:
839
+ environment = setAmbient(environment, active, repeats ? [...other, ...current] : other);
840
+ break;
841
+ case DeviceAccess.CloseAll:
842
+ environment = setAmbient(setAmbient(environment, active, []), others, []);
843
+ break;
844
+ case DeviceAccess.Switch:
845
+ case DeviceAccess.CloseSome:
846
+ environment = setAmbient(setAmbient(environment, active, other, true), others, current, true);
847
+ break;
848
+ }
702
849
  }
703
- recordAmbient(res.graph, rootId, res.environment, [], kind === DeviceAccess.CloseAll ? DeviceStates : [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device]);
704
- const known = kind === DeviceAccess.Close ? opener.length > 0 : kind === DeviceAccess.CloseAll && opener.length + otherOpeners.length > 0;
705
- return withAccess({ ...res, environment }, rootId, data, reads, kind === DeviceAccess.Open || known ? [] : unnamedFile);
850
+ /* a close ends the state of the device it closes, all of them for every device */
851
+ const kills = kind === DeviceAccess.Close ? actives : kind === DeviceAccess.CloseAll ? family.states.flat() : [];
852
+ recordAmbient(res.graph, rootId, res.environment, [], kind === DeviceAccess.CloseAll ? family.states.flat() : actives, kills);
853
+ return withAccess({ ...res, environment }, rootId, data, reads, kind === DeviceAccess.Open || closed.length > 0 ? [] : unnamedFile);
706
854
  }
707
855
  /** A call to `fn` made on our behalf (`do.call(fn, args)`, `sapply(x, fn)`): it accesses the state as `fn` does, or reads all of it if `fn` is opaque. */
708
856
  function applyAmbientStateOfCallee(res, callId, fn, data) {
709
857
  const targets = resolve_helper_1.Resolve.byNameAndType(fn, data.environment, identifier_1.ReferenceType.Function) ?? [];
710
- res = applyAmbientStateAccess(res, UnknownArguments, callId, data, targets.flatMap(hiddenAccess));
858
+ res = applyAmbientEffects(res, UnknownArguments, callId, data, targets.flatMap(hiddenAccess));
711
859
  hiddenSideEffects(res.graph, res.environment, callId, targets);
712
860
  const unknown = (targets.length === 0 && data.environment.level === 0) || targets.some(t => t.type !== identifier_1.ReferenceType.BuiltInFunction && hidesBody(t));
713
861
  return unknown ? readsAllAmbientState(res, callId, data, true) : res;
@@ -735,8 +883,7 @@ function hiddenSideEffects(graph, environment, callId, targets) {
735
883
  }
736
884
  }
737
885
  function hiddenAccess(target) {
738
- const access = target.type === identifier_1.ReferenceType.BuiltInFunction ? target.config?.ambient : undefined;
739
- return [access ?? []].flat();
886
+ return ambient_effect_1.Ambient.list(target.type === identifier_1.ReferenceType.BuiltInFunction ? target.config?.ambient : undefined);
740
887
  }
741
888
  /** The (maybe) writes of the call `callId` to the built-in `target` through a parameter, like `g <- function(f, ...) f(...); g(options, digits = 3)`. */
742
889
  function writesOfHiddenBuiltIn(target, callId, drawing = false) {
@@ -798,40 +945,34 @@ function setOptions(res, args, rootId, data) {
798
945
  /** Whether the call to `fn` only queries the state it may set, as `par("mar")`, `options("digits")` and `palette()` do, which hand that state back visibly where setting it returns the previous one invisibly. */
799
946
  function callOnlyQueries(fn, args, environment) {
800
947
  const targets = resolve_helper_1.Resolve.byNameAndType(fn, environment, identifier_1.ReferenceType.Function) ?? [];
801
- return targets.length > 0 && targets.every(t => hiddenAccess(t).some(a => onlyQueries(a, args)));
802
- }
803
- function onlyQueries(access, args) {
804
- switch (access.type) {
805
- case "set-graphics" /* AmbientStateAccessType.SetGraphics */:
806
- return args.length === 0 || (access.queryOnUnnamedStrings === true && isQuery(args));
807
- case "set-options" /* AmbientStateAccessType.SetOptions */:
808
- return isQuery(args);
809
- case "set-palette" /* AmbientStateAccessType.SetPalette */:
810
- return args.length === 0;
811
- case "set-state" /* AmbientStateAccessType.SetState */:
812
- return access.queryWithoutArguments === true && args.length === 0;
813
- default:
814
- return false;
815
- }
948
+ return targets.length > 0 && targets.every(t => onlyQueries(hiddenAccess(t), args));
949
+ }
950
+ /** Whether a call with the `effects` only queries: a change is off for the arguments `args`, and no other one happens. */
951
+ function onlyQueries(effects, args) {
952
+ const changing = effects.filter(changes);
953
+ return changing.some(e => e.unless !== undefined && holds(e.unless, args) === logic_1.Ternary.Always) && changing.every(e => applies(e, args) === logic_1.Ternary.Never);
816
954
  }
817
955
  /** `par()`, `par("mar", "usr")`, and `par(no.readonly = TRUE)` only query the graphics state */
818
956
  function isQuery(args) {
819
957
  return args.every(a => a === r_function_call_1.EmptyArgument
820
958
  || (a.name === undefined ? r_string_1.RString.is(a.value) : identifier_1.Identifier.getName(a.name.content) === 'no.readonly'));
821
959
  }
822
- /** Whether the call's value may be used: anything but a non-final statement or the script's last statement (the last of a block is its value). */
823
- function resultIsUsed(rootId, data) {
960
+ /** Whether the call's value may be used: anything but a non-final statement or, unless it is `printed` there, a top-level statement of the script (the last of a block is its value). */
961
+ function resultIsUsed(rootId, data, printed) {
824
962
  const node = data.completeAst.idMap.get(rootId);
825
963
  const parent = node === undefined ? undefined : model_1.RNode.directParent(node, data.completeAst.idMap);
964
+ /* R prints the value a top-level statement leaves visible */
965
+ printed ??= !(r_function_call_1.RFunctionCall.isNamed(node) && returnsInvisibly(node.functionName.content, data.environment));
826
966
  if (parent === undefined) {
827
967
  return false;
828
968
  }
829
969
  else if (r_expression_list_1.RExpressionList.is(parent)) {
830
970
  /* a block yields its last value, which is used where the block's is */
831
- return parent.children.at(-1)?.info.id === rootId && !data.completeAst.ast.files.some(f => f.root.info.id === parent.info.id) && resultIsUsed(parent.info.id, data);
971
+ return data.completeAst.ast.files.some(f => f.root.info.id === parent.info.id) ? printed && autoPrintsStatementsOf(parent.info.id, data)
972
+ : parent.children.at(-1)?.info.id === rootId && resultIsUsed(parent.info.id, data, printed);
832
973
  }
833
974
  else if (r_if_then_else_1.RIfThenElse.is(parent)) {
834
- return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data);
975
+ return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data, printed);
835
976
  }
836
977
  /* a loop discards what its body yields */
837
978
  return !(model_1.RLoopConstructs.is(parent) && parent.body.info.id === rootId);
@@ -852,22 +993,34 @@ function linkAmbientStateWithinLoop(graph, reads, body) {
852
993
  function processAmbientScope(name, args, rootId, data, scope) {
853
994
  const bound = match_args_1.MatchArgs.toNames(args, scope.params);
854
995
  const code = scope.code === undefined ? undefined : bound.get(scope.code);
855
- const codeIndex = code === undefined ? -1 : args.findIndex(a => a !== r_function_call_1.EmptyArgument && a.info.id === code.info.id);
996
+ /* the code may be several arguments, all that fall to `...` (`capture.output(print(1), print(2))`) */
997
+ const formals = new Set([...bound.entries()].filter(([param]) => param !== '...').map(([, arg]) => arg.info.id));
998
+ const isCode = (arg) => arg !== undefined && arg !== r_function_call_1.EmptyArgument
999
+ && (scope.code === '...' ? !formals.has(arg.info.id) : arg.info.id === code?.info.id);
1000
+ const family = scopedFamily(scope.state);
856
1001
  const local = code === undefined && data.environment.level > 0;
857
1002
  const { writes, unknown } = scope.preserve ? { writes: local ? [{ name: singleStateOf(built_in_kinds_1.AmbientSingleState.Rng), mode: AmbientWriteMode.Local }] : [], unknown: false } : scopedWrites(scope, args, bound, local);
858
1003
  const cds = data.cds ? [...data.cds] : undefined;
859
- const apply = (environment) => scope.state === built_in_kinds_1.AmbientSingleState.Device ? deviceAccess({ ...info_1.DataflowInformation.initialize(rootId, data), environment }, rootId, data, local ? DeviceAccess.Switch : DeviceAccess.Open).environment
1004
+ const apply = (environment) => family !== undefined ? deviceAccess({ ...info_1.DataflowInformation.initialize(rootId, data), environment }, rootId, data, local ? DeviceAccess.Switch : DeviceAccess.Open, family).environment
860
1005
  : defineAmbient(environment, rootId, cds, writes);
861
- const { information } = (0, known_call_handling_1.processKnownFunctionCall)({
1006
+ let { information } = (0, known_call_handling_1.processKnownFunctionCall)({
862
1007
  name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Default,
863
- patchData: (d, i) => i === codeIndex ? { ...d, environment: apply(d.environment) } : d
1008
+ patchData: (d, i) => isCode(args[i]) ? { ...d, environment: apply(d.environment) } : d
864
1009
  });
1010
+ /* `capture.output` prints every visible value of its code into the diversion, as the top level does */
1011
+ for (const value of family === ambient_state_name_1.OutputSinks ? args.filter(isCode).map(r_argument_1.RArgument.valueOf) : []) {
1012
+ if (value !== undefined && autoPrints(value, information, data)) {
1013
+ const environment = information.environment;
1014
+ information = readsOfAutoPrint(information, value, { ...data, environment });
1015
+ (0, built_in_expression_list_1.printMethodsOf)(value.info.id, environment, information.graph, { graph: information.graph, idMap: data.completeAst.idMap, ctx: data.ctx, environment });
1016
+ }
1017
+ }
865
1018
  if (unknown) {
866
1019
  information.graph.markIdForUnknownSideEffects(rootId);
867
1020
  }
868
1021
  /* the state a scope changes around its code is back afterward */
869
- const changed = scope.state === built_in_kinds_1.AmbientSingleState.Device ? [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device] : writes;
870
- recordAmbient(information.graph, rootId, information.environment, [], code === undefined && !(scope.state === built_in_kinds_1.AmbientSingleState.Device && local) ? changed : changed.map(w => ({ name: typeof w === 'string' ? w : w.name, mode: AmbientWriteMode.Local })));
1022
+ const changed = family !== undefined ? activeStates(family) : writes;
1023
+ recordAmbient(information.graph, rootId, information.environment, [], code === undefined && !(family !== undefined && local) ? changed : changed.map(w => ({ name: typeof w === 'string' ? w : w.name, mode: AmbientWriteMode.Local })));
871
1024
  if (code === undefined) {
872
1025
  const applied = { ...information, environment: apply(information.environment) };
873
1026
  /* the frame starts out with the state as it was */
@@ -876,13 +1029,13 @@ function processAmbientScope(name, args, rootId, data, scope) {
876
1029
  /* afterward, what the scope changed is back to what it was before */
877
1030
  let environment = information.environment;
878
1031
  const keyed = keyedStateOf(scope);
879
- const restored = scope.state === built_in_kinds_1.AmbientSingleState.Device ? DeviceStates
1032
+ const restored = family !== undefined ? family.states.flat()
880
1033
  : scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory ? [singleStateOf(scope.state)]
881
1034
  : writes.map(w => typeof w === 'string' ? w : w.name).filter(n => keyed !== undefined && n.startsWith(ambient_state_name_1.AmbientStateName.keyed(keyed, '')) && n !== ambient_state_name_1.AmbientStateName.keyed(keyed, ambient_state_name_1.UnknownKey));
882
1035
  for (const state of restored) {
883
1036
  const before = resolve_helper_1.Resolve.byName(state, data.environment);
884
1037
  /* an entry nothing set before keeps the scope's definition, we cannot tell R's default apart */
885
- if ((before !== undefined && before.length > 0) || ((scope.state === built_in_kinds_1.AmbientSingleState.Device || scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory) && data.environment.level === 0)) {
1038
+ if ((before !== undefined && before.length > 0) || ((family !== undefined || scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory) && data.environment.level === 0)) {
886
1039
  environment = setAmbient(environment, state, before ?? []);
887
1040
  }
888
1041
  }
@@ -893,6 +1046,10 @@ function processAmbientScope(name, args, rootId, data, scope) {
893
1046
  }
894
1047
  return { ...information, environment };
895
1048
  }
1049
+ /** The family of instances a scope opens one of for its code, `with_png` a device and `capture.output` a diversion of the output. */
1050
+ function scopedFamily(state) {
1051
+ return state === built_in_kinds_1.AmbientSingleState.Device ? ambient_state_name_1.GraphicsDevices : state === built_in_kinds_1.AmbientSingleState.Sink ? ambient_state_name_1.OutputSinks : undefined;
1052
+ }
896
1053
  /** The keyed state an {@link AmbientScope} changes the entries of, `undefined` for a state without entries. */
897
1054
  function keyedStateOf(scope) {
898
1055
  return scope.state === ambient_state_name_1.KeyedState.Option || scope.state === ambient_state_name_1.KeyedState.Env || scope.state === ambient_state_name_1.KeyedState.Locale ? scope.state : undefined;
@@ -961,22 +1118,28 @@ function evaluatesCapturedCode(res, rootId, data) {
961
1118
  }
962
1119
  /** What the implicit `print` of a top-level value reads (see {@link readsOfAutoPrint}): every option if a method may print it (`dispatched`). */
963
1120
  function autoPrintReads(dispatched) {
964
- return optionReads(dispatched ? undefined : built_in_kinds_1.PrintingOptions);
1121
+ return [...optionReads(dispatched ? undefined : built_in_kinds_1.PrintingOptions), ambient_state_name_1.AmbientStateName.sink];
965
1122
  }
966
- /** R prints every visible top-level value (see {@link autoPrints}) by an implicit `print`, which reads the options the configured `print` reads for that value. */
1123
+ /** what printing writes: it is part of the diversion of the output, see {@link OutputSinks} */
1124
+ exports.PrintWrites = [ambient_state_name_1.AmbientStateName.sinkOutput];
1125
+ /** R prints every visible top-level value (see {@link autoPrints}) by an implicit `print`, which reads the options the configured `print` reads for that value, and draws a plot object. */
967
1126
  function readsOfAutoPrint(processed, expression, data) {
968
1127
  const print = resolve_helper_1.Resolve.byNameAndType('print', { current: environment_1.REnvironment.findBuiltIn(data.environment.current), level: 0 }, identifier_1.ReferenceType.Function)?.slice(0, 1) ?? [];
969
- const reads = print.flatMap(hiddenAccess).flatMap(access => access.type === "read-options" /* AmbientStateAccessType.ReadOptions */
970
- ? printingReads(expression, access.dispatchOn !== undefined, access.keys, data) : []);
971
- return withAccess(processed, expression.info.id, data, reads, []);
1128
+ const reads = print.flatMap(hiddenAccess).flatMap(effect => effect.family === ambient_state_name_1.KeyedState.Option && effect.access === ambient_effect_1.AmbientVerb.Reads
1129
+ ? printingReads(expression, effect.dispatchOn !== undefined, typeof effect.member === 'object' && effect.member.from === 'constant' ? effect.member.keys : [], data) : []);
1130
+ return withAccess(processed, expression.info.id, data, [...reads, ambient_state_name_1.AmbientStateName.sink], [...exports.PrintWrites, ...mayHoldPlot(expression, data) ? DrawsNewPlot : []]);
972
1131
  }
973
1132
  /** the processors whose calls return invisibly, although their configuration states no {@link CallProp.Invisible} */
974
1133
  const InvisibleProcessors = new Set([built_in_proc_name_1.BuiltInProcName.ForLoop, built_in_proc_name_1.BuiltInProcName.WhileLoop, built_in_proc_name_1.BuiltInProcName.RepeatLoop,
975
1134
  built_in_proc_name_1.BuiltInProcName.Assignment, built_in_proc_name_1.BuiltInProcName.SuperAssignment, built_in_proc_name_1.BuiltInProcName.FunctionDefinition]);
1135
+ /** Whether R prints the visible values of the statements of the expression list `list`: those of the top level of the analyzed script, not of a sourced file. */
1136
+ function autoPrintsStatementsOf(list, data) {
1137
+ return data.referenceChain.length <= 1 && data.environment.level === 0 && data.completeAst.ast.files.some(f => f.root.info.id === list);
1138
+ }
976
1139
  /** whether the value of the top-level `expression` is visible, so that R prints it, decided on its vertex */
977
1140
  function autoPrints(expression, processed, data) {
978
1141
  const vertex = processed.graph.getVertex(expression.info.id);
979
- if (vertex === undefined || vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
1142
+ if (vertex === undefined) {
980
1143
  return false;
981
1144
  }
982
1145
  else if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
@@ -985,9 +1148,16 @@ function autoPrints(expression, processed, data) {
985
1148
  else if (Array.isArray(vertex.origin) && vertex.origin.some(o => InvisibleProcessors.has(o))) {
986
1149
  return false;
987
1150
  }
988
- /* `invisible`, `library`, ...: everything this resolves to returns invisibly */
989
- const targets = resolve_helper_1.Resolve.byNameAndType(vertex.name, data.environment, identifier_1.ReferenceType.Function);
990
- return targets === undefined || targets.length === 0 || !targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && built_in_props_1.CallProps.hasAny(t.config, built_in_props_1.CallProp.Invisible));
1151
+ else if (r_expression_list_1.RExpressionList.is(expression) && expression.grouping?.[0].lexeme === '{' && vertex.onlyBuiltin && expression.children.length > 0) {
1152
+ /* a block hands on its last value, visible or not */
1153
+ return autoPrints(expression.children[expression.children.length - 1], processed, data);
1154
+ }
1155
+ return !returnsInvisibly(vertex.name, data.environment);
1156
+ }
1157
+ /** `invisible`, `library`, ...: whether everything `name` resolves to returns invisibly */
1158
+ function returnsInvisibly(name, environment) {
1159
+ const targets = resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Function);
1160
+ return targets !== undefined && targets.length > 0 && targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && built_in_props_1.CallProps.hasAny(t.config, built_in_props_1.CallProp.Invisible));
991
1161
  }
992
1162
  /** A call through a variable bound to a built-in (`p <- par; p(...)`), only revealed when linking the statement's calls. */
993
1163
  function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph, data) {
@@ -998,7 +1168,7 @@ function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph,
998
1168
  const known = res.unknownReferences.length;
999
1169
  for (const builtIn of builtIns) {
1000
1170
  const targets = node_id_1.NodeId.isBuiltIn(builtIn) ? resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(builtIn), before, identifier_1.ReferenceType.Function) ?? [] : [];
1001
- res = applyAmbientStateAccess(res, call.arguments, callId, data, targets.flatMap(hiddenAccess));
1171
+ res = applyAmbientEffects(res, call.arguments, callId, data, targets.flatMap(hiddenAccess));
1002
1172
  hiddenSideEffects(graph, before, callId, targets);
1003
1173
  }
1004
1174
  const access = res.graph.ambientAccessOf(callId);
@@ -1088,12 +1258,16 @@ function rejectsArguments(definition, call) {
1088
1258
  const given = call.arguments.filter(a => a !== r_function_call_1.EmptyArgument);
1089
1259
  return given.length > names.length || given.some(a => a.name !== undefined && !names.some(n => n.startsWith(identifier_1.Identifier.getName(a.name?.content ?? ''))));
1090
1260
  }
1261
+ /** Whether `id` follows a statement that always exits, so it never runs and has no vertex. */
1262
+ function unanalyzed(id, graph, data) {
1263
+ return data.unreachable?.has(id) === true && !graph.hasVertex(id);
1264
+ }
1091
1265
  /** what may warn when `root` runs, see {@link WarningSiteMode}, `bodies` holds what may in the bodies of the closures seen so far */
1092
1266
  function warningSites(root, graph, data, bodies, mode) {
1093
1267
  const sites = [];
1094
1268
  const { signal } = mode;
1095
1269
  model_1.RNode.visitAst(root, node => {
1096
- if (r_function_definition_1.RFunctionDefinition.is(node)) {
1270
+ if (r_function_definition_1.RFunctionDefinition.is(node) || unanalyzed(node.info.id, graph, data)) {
1097
1271
  return true;
1098
1272
  }
1099
1273
  else if (r_binary_op_1.RBinaryOp.is(node) ? r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs !== base_operators_1.OperatorUsedAs.Assignment : r_unary_op_1.RUnaryOp.is(node) || r_access_1.RAccess.is(node)) {
@@ -1111,7 +1285,7 @@ function warningSites(root, graph, data, bodies, mode) {
1111
1285
  }
1112
1286
  return false;
1113
1287
  }
1114
- if (mode.muffled && r_function_call_1.RFunctionCall.isNamed(node, 'suppressWarnings') && targets.every(t => node_id_1.NodeId.isBuiltIn(t.nodeId))) {
1288
+ if (mode.muffled && targets.length > 0 && targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && t.config?.muffles?.includes('warning') === true)) {
1115
1289
  return true;
1116
1290
  }
1117
1291
  const handlers = mode.muffled ? muffledHandlers(node, graph, data) : undefined;
@@ -1146,10 +1320,12 @@ function warningSites(root, graph, data, bodies, mode) {
1146
1320
  });
1147
1321
  return sites;
1148
1322
  }
1149
- /** Whether `node` branches or loops on a value that is not a constant, which R may reject (`if(NA)`). */
1323
+ /** Whether `node` branches or loops on a value R may reject: a condition that is not `TRUE` or `FALSE` (`if(NA)`, `if(logical(0))`) or a vector that is not a constant. */
1150
1324
  function testsValue(node) {
1151
- const tested = r_if_then_else_1.RIfThenElse.is(node) || r_while_loop_1.RWhileLoop.is(node) ? node.condition : r_for_loop_1.RForLoop.is(node) ? node.vector : undefined;
1152
- return tested !== undefined && !model_1.RConstant.is(tested);
1325
+ if (r_if_then_else_1.RIfThenElse.is(node) || r_while_loop_1.RWhileLoop.is(node)) {
1326
+ return !r_logical_1.RLogical.is(node.condition);
1327
+ }
1328
+ return r_for_loop_1.RForLoop.is(node) && !model_1.RConstant.is(node.vector);
1153
1329
  }
1154
1330
  /** The handlers of a `withCallingHandlers` whose first handler muffles every `warning` of its `expr`, `undefined` otherwise. */
1155
1331
  function muffledHandlers(call, graph, data) {