@eagleoutice/flowr 2.15.10 → 2.16.1

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 (213) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/cli/flowr-main-options.d.ts +15 -0
  4. package/cli/flowr-main-options.js +18 -0
  5. package/cli/flowr.d.ts +18 -0
  6. package/cli/flowr.js +13 -2
  7. package/cli/repl/commands/repl-clipboard.js +2 -1
  8. package/cli/repl/commands/repl-commands.js +2 -0
  9. package/cli/repl/commands/repl-main.d.ts +5 -0
  10. package/cli/repl/commands/repl-signature.js +2 -0
  11. package/cli/repl/core.d.ts +7 -1
  12. package/cli/repl/core.js +17 -8
  13. package/cli/repl/execute.js +2 -0
  14. package/cli/repl/server/connection.js +2 -1
  15. package/cli/repl/server/net.d.ts +10 -0
  16. package/cli/repl/server/net.js +34 -1
  17. package/cli/slicer-app.js +2 -1
  18. package/config.d.ts +12 -2
  19. package/config.js +91 -14
  20. package/control-flow/happens-before.d.ts +5 -0
  21. package/control-flow/happens-before.js +48 -34
  22. package/control-flow/useless-loop.d.ts +1 -1
  23. package/control-flow/useless-loop.js +29 -42
  24. package/dataflow/environments/built-in-props.d.ts +9 -0
  25. package/dataflow/environments/built-in-props.js +25 -19
  26. package/dataflow/environments/built-in.d.ts +2 -2
  27. package/dataflow/environments/built-in.js +41 -77
  28. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  29. package/dataflow/environments/default-builtin-config.js +38 -24
  30. package/dataflow/environments/environment.d.ts +6 -4
  31. package/dataflow/environments/environment.js +54 -121
  32. package/dataflow/environments/identifier.d.ts +4 -2
  33. package/dataflow/environments/identifier.js +23 -69
  34. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  35. package/dataflow/environments/reference-to-maybe.js +23 -51
  36. package/dataflow/environments/resolve-by-name.js +37 -76
  37. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  38. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  39. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  40. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  41. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  42. package/dataflow/eval/resolve/resolve.js +23 -14
  43. package/dataflow/extractor.js +185 -59
  44. package/dataflow/fn/class-declaration.d.ts +8 -2
  45. package/dataflow/fn/class-declaration.js +96 -97
  46. package/dataflow/fn/exceptions-of-function.js +68 -37
  47. package/dataflow/fn/frame-reflection.d.ts +12 -4
  48. package/dataflow/fn/frame-reflection.js +64 -42
  49. package/dataflow/fn/function-props.js +15 -33
  50. package/dataflow/fn/function-semantics.d.ts +11 -3
  51. package/dataflow/fn/function-semantics.js +6 -0
  52. package/dataflow/fn/higher-order-function.js +13 -17
  53. package/dataflow/fn/strict-function.d.ts +13 -0
  54. package/dataflow/fn/strict-function.js +285 -122
  55. package/dataflow/graph/call-graph.d.ts +7 -6
  56. package/dataflow/graph/call-graph.js +35 -46
  57. package/dataflow/graph/graph.d.ts +6 -1
  58. package/dataflow/graph/graph.js +57 -66
  59. package/dataflow/info.d.ts +8 -1
  60. package/dataflow/info.js +24 -30
  61. package/dataflow/internal/control-flow.d.ts +42 -4
  62. package/dataflow/internal/control-flow.js +76 -39
  63. package/dataflow/internal/linker.d.ts +15 -9
  64. package/dataflow/internal/linker.js +253 -241
  65. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  66. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +441 -79
  67. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  68. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  69. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  70. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  71. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  72. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  74. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  75. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +290 -252
  76. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  78. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  80. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  82. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  84. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  85. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  91. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  93. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  94. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  95. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  97. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  99. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +120 -93
  101. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  102. package/dataflow/internal/process/functions/call/common.js +36 -76
  103. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  104. package/dataflow/internal/process/functions/call/deferred.js +60 -58
  105. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  106. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  107. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  108. package/dataflow/internal/process/functions/call/named-call-handling.js +44 -21
  109. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  110. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  111. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  112. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  113. package/dataflow/internal/process/process-symbol.js +3 -6
  114. package/dataflow/internal/program-order.d.ts +26 -0
  115. package/dataflow/internal/program-order.js +49 -0
  116. package/documentation/doc-capabilities.js +4 -1
  117. package/documentation/wiki-interface.js +4 -0
  118. package/documentation/wiki-setup.js +23 -0
  119. package/engines.js +11 -3
  120. package/linter/linter-executor.js +19 -1
  121. package/linter/linter-rules.d.ts +17 -8
  122. package/linter/rules/absolute-path.js +63 -87
  123. package/linter/rules/file-path-validity.d.ts +4 -2
  124. package/linter/rules/file-path-validity.js +117 -80
  125. package/linter/rules/namespace-access.js +21 -33
  126. package/linter/rules/naming-convention.d.ts +1 -1
  127. package/linter/rules/naming-convention.js +60 -48
  128. package/linter/rules/network-functions.js +11 -7
  129. package/linter/rules/no-leaked-credentials.js +15 -18
  130. package/linter/rules/problematic-inputs.d.ts +2 -1
  131. package/linter/rules/problematic-inputs.js +39 -59
  132. package/linter/rules/roxygen-arguments.d.ts +9 -4
  133. package/linter/rules/roxygen-arguments.js +29 -48
  134. package/linter/rules/seeded-randomness.d.ts +7 -4
  135. package/linter/rules/seeded-randomness.js +130 -89
  136. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  137. package/linter/rules/stop-with-call-arg.js +25 -22
  138. package/linter/rules/unclosed-connection.js +31 -24
  139. package/linter/rules/undefined-symbol.d.ts +4 -6
  140. package/linter/rules/undefined-symbol.js +58 -75
  141. package/linter/rules/unescaped-arguments.js +18 -44
  142. package/linter/rules/unused-definition.d.ts +6 -0
  143. package/linter/rules/unused-definition.js +105 -145
  144. package/linter/rules/unused-import.d.ts +3 -0
  145. package/linter/rules/unused-import.js +25 -43
  146. package/package.json +5 -2
  147. package/project/flowr-analyzer.js +6 -2
  148. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  149. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  150. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
  151. package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
  152. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  153. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  154. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +18 -42
  155. package/project/sigdb/decompress.js +3 -1
  156. package/project/sigdb/sigdb-download.js +9 -6
  157. package/queries/base-query-format.js +1 -2
  158. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  159. package/queries/catalog/config-query/config-query-executor.js +9 -2
  160. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  161. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  162. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  163. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  164. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  165. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  166. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  167. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  168. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  169. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  170. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  171. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  172. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  173. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  174. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  175. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  176. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  177. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  178. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  179. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  180. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  181. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  182. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  183. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  184. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  185. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  186. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  187. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  188. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  189. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  190. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  191. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  192. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  193. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  194. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  195. package/r-bridge/shell-executor.js +2 -0
  196. package/r-bridge/shell.js +8 -0
  197. package/search/search-executor/search-enrichers.js +25 -37
  198. package/slicing/static/slice-call.d.ts +4 -3
  199. package/slicing/static/slice-call.js +56 -88
  200. package/slicing/static/static-slicer.js +120 -79
  201. package/slicing/static/visiting-queue.d.ts +4 -6
  202. package/slicing/static/visiting-queue.js +9 -13
  203. package/util/files.d.ts +6 -0
  204. package/util/files.js +12 -0
  205. package/util/parallel.js +2 -0
  206. package/util/proc.js +2 -1
  207. package/util/r-base-packages.d.ts +2 -0
  208. package/util/r-base-packages.js +23 -13
  209. package/util/secure-mode.d.ts +42 -0
  210. package/util/secure-mode.js +70 -0
  211. package/util/text/playground-link.d.ts +12 -3
  212. package/util/text/playground-link.js +18 -27
  213. package/util/version.js +4 -10
@@ -10,11 +10,11 @@ exports.builtInEnvJsonReplacer = builtInEnvJsonReplacer;
10
10
  const json_1 = require("../../util/json");
11
11
  const removal_marker_1 = require("./removal-marker");
12
12
  const identifier_1 = require("./identifier");
13
- const assert_1 = require("../../util/assert");
14
13
  const info_1 = require("../info");
15
14
  const append_1 = require("./append");
16
15
  const frame_memory_1 = require("./frame-memory");
17
16
  const log_1 = require("../../util/log");
17
+ const defaultmap_1 = require("../../util/collections/defaultmap");
18
18
  var EnvType;
19
19
  (function (EnvType) {
20
20
  EnvType["Namespace"] = "ns";
@@ -45,6 +45,8 @@ class Environment {
45
45
  /** what a resolution found below this frame, by target and name; only frames nothing writes keep one */
46
46
  tailCache;
47
47
  builtInEnv;
48
+ /** set on the built-in environment once a definition below binds a promise or a text connection, which reads then look for */
49
+ forcing;
48
50
  /** {@link memory} is shared with a clone; writing needs {@link writableMemory} to unshare it first */
49
51
  sharedMemory;
50
52
  /** {@link parent} is shared with the environment this was cloned from; writing through it needs {@link writableParent} */
@@ -126,12 +128,6 @@ class Environment {
126
128
  this.sharedMemory = shared ? true : undefined;
127
129
  this.tailCache = undefined;
128
130
  }
129
- /** What a merge writes its result into: {@link Frame.forWrite} overlays a big frame instead of copying it, so the cost follows what the merge changes, not what it keeps. */
130
- mergedFrame() {
131
- /* the result may keep this frame as its base, so a later write here has to fork */
132
- this.sharedMemory = true;
133
- return this.frame.forWrite();
134
- }
135
131
  /** {@link memory} ready to be written to. Every write goes through here, since {@link clone} shares the frame. */
136
132
  get writableMemory() {
137
133
  this.tailCache = undefined;
@@ -146,18 +142,22 @@ class Environment {
146
142
  if (this.builtInEnv) {
147
143
  return this; // do not clone the built-in environment
148
144
  }
149
- const clone = new Environment(this.parent, this.builtInEnv, this.frame);
150
- clone.c = this.c;
151
- clone.n = this.n;
152
- clone.t = this.t;
153
- clone.globalEnv = this.globalEnv;
154
- clone.superMemory = this.superMemory;
145
+ const clone = this.derive(this.parent, this.frame);
155
146
  clone.sharedMemory = this.sharedMemory = true;
156
147
  if (recurseParents && !this.parent.builtInEnv) {
157
148
  clone.sharedParent = true;
158
149
  }
159
150
  return clone;
160
151
  }
152
+ derive(parent, frame) {
153
+ const env = new Environment(parent, undefined, frame);
154
+ env.c = this.c;
155
+ env.n = this.n;
156
+ env.t = this.t;
157
+ env.globalEnv = this.globalEnv;
158
+ env.superMemory = this.superMemory;
159
+ return env;
160
+ }
161
161
  /** Define a new identifier definition within this environment. */
162
162
  define(definition) {
163
163
  const [name, ns] = identifier_1.Identifier.toArray(definition.name);
@@ -193,31 +193,14 @@ class Environment {
193
193
  if (definition.cds !== undefined) {
194
194
  definition = { ...definition, cds: definition.cds.slice() };
195
195
  }
196
- // When there are defined indices, merge the definitions
197
- if (definition.cds === undefined) {
198
- this.writableMemory.set(name, [definition]);
199
- }
200
- else {
201
- const existing = this.lookup(name);
202
- const inGraphDefinition = definition;
203
- if (existing !== undefined &&
204
- inGraphDefinition.cds === undefined) {
205
- this.writableMemory.set(name, [inGraphDefinition]);
206
- }
207
- else if (existing === undefined || definition.cds === undefined) {
208
- this.writableMemory.set(name, [definition]);
209
- }
210
- else {
211
- /* the array may be shared with clones, so replace instead of push */
212
- this.writableMemory.set(name, [...existing, definition]);
213
- }
214
- }
196
+ /* a maybe definition joins the existing ones; the array may be shared with clones, so replace instead of push */
197
+ const existing = definition.cds === undefined ? undefined : this.lookup(name);
198
+ this.writableMemory.set(name, existing === undefined ? [definition] : [...existing, definition]);
215
199
  }
216
200
  defineInNamespace(definition, ns) {
217
201
  if (this.n === ns) {
218
202
  return this.define(definition);
219
203
  }
220
- // navigate to parent until either before built-in or matching namespace
221
204
  const newEnvironment = this.clone(false);
222
205
  let current = newEnvironment;
223
206
  /* the match has to be re-checked after every step: a post-condition on `current.n` would end the loop on
@@ -230,7 +213,6 @@ class Environment {
230
213
  return newEnvironment;
231
214
  }
232
215
  else if (current.parent && !current.parent.builtInEnv) {
233
- // clone parent
234
216
  current.parent = current.parent.clone(false);
235
217
  current = current.parent;
236
218
  }
@@ -238,7 +220,6 @@ class Environment {
238
220
  break;
239
221
  }
240
222
  }
241
- // we did not find the namespace, so we inject a new environment here
242
223
  log_1.log.warn(`Defining ${identifier_1.Identifier.getName(definition.name)} in namespace ${ns}, which did not exist yet in the environment chain => create (r should fail or we miss attachment).`);
243
224
  const env = new Environment(current.parent);
244
225
  env.n = ns;
@@ -256,36 +237,32 @@ class Environment {
256
237
  newEnvironment.parent = newEnvironment.parent.defineInNamespace(definition, ns);
257
238
  return newEnvironment;
258
239
  }
259
- const bind = (env) => env.writableMemory.set(name, append ? [...env.lookup(name) ?? [], definition] : [definition]);
240
+ /* `<<-` binds in the closest enclosing frame that holds the name, which for an emptied frame is what
241
+ * it stood in for when the closure was created (see {@link superMemory}) */
242
+ const holdsName = (env) => env.lookup(name) !== undefined || env.superMemory?.has(name) === true;
260
243
  let current = newEnvironment;
261
- let last = undefined;
262
- let found = false;
263
- do {
264
- /* `<<-` binds in the closest enclosing frame that holds the name, which for an emptied frame is what
265
- * it stood in for when the closure was created (see {@link superMemory}) */
266
- if (current.lookup(name) !== undefined || current.superMemory?.has(name)) {
267
- bind(current);
268
- found = true;
269
- break;
270
- }
271
- // `<<-` falls back to the global env, never an attached package below it
272
- if (current.globalEnv) {
273
- bind(current);
274
- found = true;
275
- break;
276
- }
277
- last = current;
244
+ // `<<-` falls back to the global env, never an attached package below it
245
+ while (!holdsName(current) && !current.globalEnv) {
246
+ const last = current;
278
247
  current.parent = current.parent.clone(false);
279
248
  current = current.parent;
280
- } while (!current.builtInEnv);
281
- if (!found) {
282
- (0, assert_1.guard)(last !== undefined, () => `Could not find global scope for ${name}`);
283
- bind(last);
249
+ if (current.builtInEnv) {
250
+ current = last;
251
+ break;
252
+ }
284
253
  }
254
+ current.writableMemory.set(name, append ? [...current.lookup(name) ?? [], definition] : [definition]);
285
255
  return newEnvironment;
286
256
  }
287
257
  /** Definitions within `other` replace those here by name; if all of `other`'s are maybe, they are appended instead (turning existing ones maybe too). Always recurses parents. */
288
258
  overwrite(other, applyCds) {
259
+ return this.merge(other, false, applyCds);
260
+ }
261
+ /** Adds all writes of `other` to this environment (`other`'s operations *might* happen). Always recurses parents. */
262
+ append(other) {
263
+ return this.merge(other, true);
264
+ }
265
+ merge(other, append, applyCds) {
289
266
  if (!other || this === other) {
290
267
  return this;
291
268
  }
@@ -295,79 +272,39 @@ class Environment {
295
272
  }
296
273
  /* nothing on the other side leaves these bindings as the result, so they are shared rather than merged */
297
274
  const keep = other.memory.size === 0;
298
- const frame = keep ? this.frame : this.mergedFrame();
299
- if (keep) {
300
- this.sharedMemory = true;
301
- }
275
+ const frame = keep ? this.frame : this.frame.forWrite();
276
+ /* the result may keep this frame as its base, so a later write here has to fork */
277
+ this.sharedMemory = true;
302
278
  for (const [key, values] of other.memory) {
303
- const hasMaybe = applyCds === undefined ? values.length === 0 || values.some(v => v.cds !== undefined) : true;
304
- if (hasMaybe) {
305
- const old = frame.get(key);
306
- if (!old && applyCds === undefined) {
307
- frame.set(key, values);
308
- continue;
309
- }
279
+ /* an overwrite by definite definitions replaces the old ones, so they are not even looked up */
280
+ const hasMaybe = values.length === 0 || values.some(v => v.cds !== undefined);
281
+ const joinsOld = append || applyCds !== undefined || hasMaybe;
282
+ const old = joinsOld ? frame.get(key) : undefined;
283
+ if (old === undefined && applyCds === undefined) {
284
+ frame.set(key, values);
285
+ }
286
+ else if (append) {
287
+ frame.set(key, (0, append_1.uniqueMergeValuesInDefinitions)(old ?? [], values));
288
+ }
289
+ else {
310
290
  // we need to make a copy to avoid side effects for old reference in other environments
311
291
  const updated = old?.slice() ?? [];
312
292
  for (const v of values) {
313
- const { nodeId, definedAt } = v;
314
- if (updated.some(o => o.nodeId === nodeId && o.definedAt === definedAt)) {
293
+ if (updated.some(o => o.nodeId === v.nodeId && o.definedAt === v.definedAt)) {
315
294
  continue;
316
295
  }
317
296
  if (applyCds === undefined) {
318
297
  updated.push(v);
319
298
  }
320
299
  else {
321
- updated.push({
322
- ...v,
323
- cds: v.cds ? applyCds.concat(v.cds) : applyCds.slice()
324
- });
300
+ updated.push({ ...v, cds: v.cds ? applyCds.concat(v.cds) : applyCds.slice() });
325
301
  }
326
302
  }
327
303
  frame.set(key, updated);
328
304
  }
329
- else {
330
- frame.set(key, values);
331
- }
332
- }
333
- const out = new Environment(this.parent.overwrite(other.parent, applyCds));
334
- out.c = this.c;
335
- out.n = this.n;
336
- out.t = this.t;
337
- out.globalEnv = this.globalEnv;
338
- out.superMemory = this.superMemory ?? other.superMemory;
339
- out.adoptFrame(frame, keep);
340
- return out;
341
- }
342
- /** Adds all writes of `other` to this environment (`other`'s operations *might* happen). Always recurses parents. */
343
- append(other) {
344
- if (!other || this === other) {
345
- return this;
346
- }
347
- const shortcut = this.mergeShortcut(other);
348
- if (shortcut !== undefined) {
349
- return shortcut;
350
- }
351
- const keep = other.memory.size === 0;
352
- const frame = keep ? this.frame : this.mergedFrame();
353
- if (keep) {
354
- this.sharedMemory = true;
355
- }
356
- for (const [key, value] of other.memory) {
357
- const old = frame.get(key);
358
- if (old) {
359
- frame.set(key, (0, append_1.uniqueMergeValuesInDefinitions)(old, value));
360
- }
361
- else {
362
- frame.set(key, value);
363
- }
364
305
  }
365
- const out = new Environment(this.parent.append(other.parent));
366
- out.c = this.c;
367
- out.n = this.n;
368
- out.t = this.t;
369
- out.globalEnv = this.globalEnv;
370
- out.superMemory = this.superMemory ?? other.superMemory;
306
+ const out = this.derive(append ? this.parent.append(other.parent) : this.parent.overwrite(other.parent, applyCds));
307
+ out.superMemory ??= other.superMemory;
371
308
  out.adoptFrame(frame, keep);
372
309
  return out;
373
310
  }
@@ -407,14 +344,10 @@ class Environment {
407
344
  * Keyed by type and then by name, rather than by a `t:n` string built for every layer of every merge.
408
345
  */
409
346
  const order = [];
410
- const merged = new Map();
347
+ const merged = new defaultmap_1.DefaultMap(() => new Map());
411
348
  for (const layers of thisLayers.length > otherLayers.length ? [thisLayers, otherLayers] : [otherLayers, thisLayers]) {
412
349
  for (const layer of layers) {
413
- let byName = merged.get(layer.t);
414
- if (byName === undefined) {
415
- byName = new Map();
416
- merged.set(layer.t, byName);
417
- }
350
+ const byName = merged.get(layer.t);
418
351
  const existing = byName.get(layer.n);
419
352
  if (existing === undefined) {
420
353
  const cloned = layer.clone(false);
@@ -178,9 +178,9 @@ export declare const Identifier: {
178
178
  * ```
179
179
  */
180
180
  export declare class IdentifierView {
181
- /** The underlying identifier; use it whenever you need the plain representation back. */
182
181
  readonly raw: Identifier;
183
- constructor(id: Identifier);
182
+ /** @param raw - the underlying identifier; use it whenever you need the plain representation back */
183
+ constructor(raw: Identifier);
184
184
  /** the name part, so the `fn` of a `pkg::fn` */
185
185
  get name(): BrandedIdentifier;
186
186
  /** the namespace part, `undefined` for a name written without one */
@@ -339,6 +339,7 @@ export declare const enum PkgName {
339
339
  Soda = "SoDA",
340
340
  Sourcetools = "sourcetools",
341
341
  Sqldf = "sqldf",
342
+ Stargazer = "stargazer",
342
343
  Stars = "stars",
343
344
  Stringmagic = "stringmagic",
344
345
  Stringr = "stringr",
@@ -347,6 +348,7 @@ export declare const enum PkgName {
347
348
  Sys = "sys",
348
349
  Tcltk = "tcltk",
349
350
  Terra = "terra",
351
+ Texreg = "texreg",
350
352
  Testthat = "testthat",
351
353
  Tibble = "tibble",
352
354
  TidyR = "tidyr",
@@ -31,12 +31,7 @@ exports.Identifier = {
31
31
  if ((0, strings_1.startAndEndsWith)(name, '`')) {
32
32
  name = name.slice(1, -1);
33
33
  }
34
- if (namespace) {
35
- return [name, namespace, internal];
36
- }
37
- else {
38
- return name;
39
- }
34
+ return namespace ? [name, namespace, internal] : name;
40
35
  },
41
36
  /**
42
37
  * Fast-path factory: returns the tuple as-is with no allocation or runtime checks.
@@ -74,13 +69,7 @@ exports.Identifier = {
74
69
  * ```
75
70
  */
76
71
  fromAllIn(namespaces, names) {
77
- const ids = [];
78
- for (const namespace of namespaces) {
79
- for (const name of names) {
80
- ids.push([name, namespace]);
81
- }
82
- }
83
- return ids;
72
+ return namespaces.flatMap(namespace => names.map((name) => [name, namespace]));
84
73
  },
85
74
  /**
86
75
  * Verify whether an unknown element has a valid identifier shape!
@@ -89,15 +78,10 @@ exports.Identifier = {
89
78
  if (typeof id === 'string') {
90
79
  return true;
91
80
  }
92
- if (Array.isArray(id)) {
93
- if (id.length === 2) {
94
- return typeof id[0] === 'string' && typeof id[1] === 'string';
95
- }
96
- else if (id.length === 3) {
97
- return typeof id[0] === 'string' && typeof id[1] === 'string' && typeof id[2] === 'boolean';
98
- }
81
+ if (!Array.isArray(id) || typeof id[0] !== 'string' || typeof id[1] !== 'string') {
82
+ return false;
99
83
  }
100
- return false;
84
+ return id.length === 2 || (id.length === 3 && typeof id[2] === 'boolean');
101
85
  },
102
86
  /**
103
87
  * Parse an identifier from its string representation,
@@ -143,17 +127,9 @@ exports.Identifier = {
143
127
  return undefined;
144
128
  }
145
129
  else if (Array.isArray(id)) {
146
- if (id[1].includes('::')) {
147
- return `${JSON.stringify(id[1])}${id[2] ? ':::' : '::'}${id[0]}`;
148
- }
149
- return `${id[1]}${id[2] ? ':::' : '::'}${id[0]}`;
150
- }
151
- else {
152
- if (id.includes('::')) {
153
- return JSON.stringify(id);
154
- }
155
- return id;
130
+ return `${id[1].includes('::') ? JSON.stringify(id[1]) : id[1]}${id[2] ? ':::' : '::'}${id[0]}`;
156
131
  }
132
+ return id.includes('::') ? JSON.stringify(id) : id;
157
133
  }),
158
134
  /**
159
135
  * Check if two identifiers match.
@@ -166,22 +142,20 @@ exports.Identifier = {
166
142
  const idName = exports.Identifier.getName(id);
167
143
  const targetName = exports.Identifier.getName(target);
168
144
  if (idName !== targetName) {
169
- return s3 ? targetName.startsWith(idName + '.') : false;
145
+ return s3 && targetName.startsWith(idName + '.');
170
146
  }
171
147
  const idNs = exports.Identifier.getNamespace(id);
172
148
  if (idNs === undefined) {
173
149
  return true;
174
150
  }
175
- const targetNs = exports.Identifier.getNamespace(target);
176
- if (idNs !== targetNs) {
151
+ if (idNs !== exports.Identifier.getNamespace(target)) {
177
152
  return false;
178
153
  }
179
- const idInternal = exports.Identifier.accessesInternal(id);
180
- if (idInternal === true) {
154
+ if (exports.Identifier.accessesInternal(id) === true) {
181
155
  return true;
182
156
  }
183
157
  /* an omitted flag is the same as an explicit `false`, `pkg::fn` written either way is one identifier */
184
- return (idInternal ?? false) === (exports.Identifier.accessesInternal(target) ?? false);
158
+ return exports.Identifier.accessesInternal(target) !== true;
185
159
  },
186
160
  /** The text as a regex matches it literally: `[`, `$` and `.` name functions in R, they are not pattern syntax. */
187
161
  quote(text) {
@@ -212,34 +186,19 @@ exports.Identifier = {
212
186
  * Functor over the name of the identifier
213
187
  */
214
188
  mapName(id, fn) {
215
- if (Array.isArray(id)) {
216
- return [fn(id[0]), id[1], id[2]];
217
- }
218
- else {
219
- return fn(id);
220
- }
189
+ return Array.isArray(id) ? [fn(id[0]), id[1], id[2]] : fn(id);
221
190
  },
222
191
  /**
223
192
  * Functor over the namespace of the identifier
224
193
  */
225
194
  mapNamespace(id, fn) {
226
- if (Array.isArray(id)) {
227
- return [id[0], fn(id[1]), id[2]];
228
- }
229
- else {
230
- return id;
231
- }
195
+ return Array.isArray(id) ? [id[0], fn(id[1]), id[2]] : id;
232
196
  },
233
197
  /**
234
198
  * Convert the identifier to its array representation
235
199
  */
236
200
  toArray(id) {
237
- if (Array.isArray(id)) {
238
- return [id[0], id[1], id[2]];
239
- }
240
- else {
241
- return [id, undefined, undefined];
242
- }
201
+ return Array.isArray(id) ? [id[0], id[1], id[2]] : [id, undefined, undefined];
243
202
  },
244
203
  /**
245
204
  * The package-qualified identifier of a call, resolved in order of decreasing certainty:
@@ -272,20 +231,15 @@ exports.Identifier = {
272
231
  sawUserDefinition = true;
273
232
  }
274
233
  }
275
- if (name === undefined) {
276
- return undefined;
277
- }
278
- if (exports.Identifier.getNamespace(name) !== undefined) {
234
+ if (name === undefined || exports.Identifier.getNamespace(name) !== undefined) {
279
235
  return name;
280
236
  }
281
- if (qualifyBaseR && !sawUserDefinition) {
282
- const bare = exports.Identifier.getName(name);
283
- const owner = (0, r_base_packages_1.baseRExportOwner)(bare);
284
- if (owner !== undefined) {
285
- return exports.Identifier.make(bare, owner);
286
- }
237
+ if (!qualifyBaseR || sawUserDefinition) {
238
+ return undefined;
287
239
  }
288
- return undefined;
240
+ const bare = exports.Identifier.getName(name);
241
+ const owner = (0, r_base_packages_1.baseRExportOwner)(bare);
242
+ return owner === undefined ? undefined : exports.Identifier.make(bare, owner);
289
243
  },
290
244
  /**
291
245
  * Wraps the identifier in an {@link IdentifierView|view} offering property access (`id.name`, `id.namespace`)
@@ -309,10 +263,10 @@ exports.Identifier = {
309
263
  * ```
310
264
  */
311
265
  class IdentifierView {
312
- /** The underlying identifier; use it whenever you need the plain representation back. */
313
266
  raw;
314
- constructor(id) {
315
- this.raw = id;
267
+ /** @param raw - the underlying identifier; use it whenever you need the plain representation back */
268
+ constructor(raw) {
269
+ this.raw = raw;
316
270
  }
317
271
  /** the name part, so the `fn` of a `pkg::fn` */
318
272
  get name() {
@@ -1,9 +1,18 @@
1
1
  import type { IdentifierDefinition, IdentifierReference } from './identifier';
2
+ import { Identifier, ReferenceType } from './identifier';
2
3
  import type { DataflowGraph } from '../graph/graph';
4
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
3
5
  import type { ControlDependency } from '../info';
4
6
  import type { REnvironmentInformation } from './environment';
5
7
  /** copy of the definition with the given cds attached, marking it as maybe */
6
8
  export declare function withAppliedCds(definition: IdentifierDefinition, defaultCd: readonly ControlDependency[] | undefined): IdentifierDefinition;
9
+ /**
10
+ * Attaches the given control dependencies to the definition made by `nodeId` within the environment chain.
11
+ * Definitions of the same name made elsewhere survive whenever the conditional definition does not happen.
12
+ * Copy-on-write: definitions are replaced, never mutated in place, so previously cloned
13
+ * environments (e.g., snapshots stored in the dataflow graph) keep their state.
14
+ */
15
+ export declare function applyCdsToDefinitions(environments: REnvironmentInformation, name: Identifier, type: ReferenceType, definitions: readonly IdentifierDefinition[], nodeId: NodeId, defaultCd: readonly ControlDependency[] | undefined): void;
7
16
  /**
8
17
  * Marks the reference as maybe (i.e., as controlled by a set of {@link IdentifierReference#cds|control dependencies}).
9
18
  * With `includeDefs`, the cds are also attached (copy-on-write) to the definition the reference
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withAppliedCds = withAppliedCds;
4
+ exports.applyCdsToDefinitions = applyCdsToDefinitions;
4
5
  exports.makeReferenceMaybe = makeReferenceMaybe;
5
6
  exports.makeAllMaybe = makeAllMaybe;
6
7
  exports.applyCdsToAllInGraphButConstants = applyCdsToAllInGraphButConstants;
@@ -29,22 +30,16 @@ function replaceDefinitions(env, key, toUpdate, defaultCd) {
29
30
  * environments (e.g., snapshots stored in the dataflow graph) keep their state.
30
31
  */
31
32
  function applyCdsToDefinitions(environments, name, type, definitions, nodeId, defaultCd) {
32
- const toUpdate = new Set();
33
- for (const definition of definitions) {
34
- if (definition.nodeId === nodeId
35
- && definition.type !== identifier_1.ReferenceType.BuiltInFunction && definition.type !== identifier_1.ReferenceType.BuiltInConstant
36
- && (defaultCd !== undefined || definition.cds === undefined)) {
37
- toUpdate.add(definition);
38
- }
39
- }
33
+ const toUpdate = new Set(definitions.filter(definition => definition.nodeId === nodeId
34
+ && definition.type !== identifier_1.ReferenceType.BuiltInFunction && definition.type !== identifier_1.ReferenceType.BuiltInConstant
35
+ && (defaultCd !== undefined || definition.cds === undefined)));
40
36
  if (toUpdate.size === 0) {
41
37
  return;
42
38
  }
43
39
  const [plainName] = identifier_1.Identifier.toArray(name);
44
40
  const prefix = type === identifier_1.ReferenceType.S3MethodPrefix ? plainName + '.'
45
41
  : type === identifier_1.ReferenceType.S7MethodPrefix ? plainName + built_in_s_seven_dispatch_1.S7DispatchSeparator : undefined;
46
- let current = environments.current;
47
- while (!current.builtInEnv) {
42
+ for (let current = environments.current; !current.builtInEnv; current = current.parent) {
48
43
  if (prefix === undefined) {
49
44
  replaceDefinitions(current, plainName, toUpdate, defaultCd);
50
45
  }
@@ -55,7 +50,14 @@ function applyCdsToDefinitions(environments, name, type, definitions, nodeId, de
55
50
  }
56
51
  }
57
52
  }
58
- current = current.parent;
53
+ }
54
+ }
55
+ function addCds(target, cds) {
56
+ if (target.cds) {
57
+ (0, info_1.appendCds)(target.cds, cds);
58
+ }
59
+ else {
60
+ target.cds = cds ? Array.from(cds) : [];
59
61
  }
60
62
  }
61
63
  /**
@@ -72,70 +74,40 @@ function makeReferenceMaybe(ref, graph, environments, includeDefs, defaultCd = u
72
74
  }
73
75
  const node = graph.getVertex(ref.nodeId);
74
76
  if (node) {
75
- if (node.cds) {
76
- (0, info_1.appendCds)(node.cds, defaultCd);
77
- }
78
- else {
79
- node.cds = defaultCd ? Array.from(defaultCd) : [];
80
- }
77
+ addCds(node, defaultCd);
81
78
  }
82
- if (ref.cds) {
83
- if (defaultCd) {
84
- return { ...ref, cds: (0, info_1.withCds)(ref.cds, defaultCd) };
85
- }
86
- }
87
- else {
79
+ if (ref.cds === undefined) {
88
80
  return { ...ref, cds: defaultCd ? Array.from(defaultCd) : [] };
89
81
  }
90
- return ref;
82
+ return defaultCd ? { ...ref, cds: (0, info_1.withCds)(ref.cds, defaultCd) } : ref;
91
83
  }
92
84
  /**
93
85
  * Marks all references as maybe (i.e., as controlled by a set of {@link IdentifierReference#cds|control dependencies}).
94
86
  * @see {@link makeReferenceMaybe}
95
87
  */
96
88
  function makeAllMaybe(references, graph, environments, includeDefs, applyCds = undefined) {
97
- if (references === undefined || references.length === 0) {
98
- return [];
99
- }
100
- return references.map(ref => makeReferenceMaybe(ref, graph, environments, includeDefs, applyCds));
89
+ return references?.map(ref => makeReferenceMaybe(ref, graph, environments, includeDefs, applyCds)) ?? [];
101
90
  }
102
91
  /**
103
92
  * apply the given cds to all elements in the graph and also transform the given references similar to {@link makeAllMaybe}.
104
93
  */
105
94
  function applyCdsToAllInGraphButConstants(graph, references, cds) {
106
95
  for (const [, v] of graph.vertices(true)) {
107
- if (vertex_1.DfgVertex.isValue(v)) {
108
- continue;
109
- }
110
- if (v.cds) {
111
- (0, info_1.appendCds)(v.cds, cds);
112
- }
113
- else {
114
- v.cds = Array.from(cds);
96
+ if (!vertex_1.DfgVertex.isValue(v)) {
97
+ addCds(v, cds);
115
98
  }
116
99
  }
117
100
  for (const ref of references) {
118
- if (ref.cds) {
119
- (0, info_1.appendCds)(ref.cds, cds);
120
- }
121
- else {
122
- ref.cds = Array.from(cds);
123
- }
101
+ addCds(ref, cds);
124
102
  }
125
103
  }
126
104
  /**
127
105
  * apply the given cds to all given references, but not to the graph. This is useful if we want to mark the references as maybe without marking all other nodes in the graph as maybe.
128
106
  */
129
107
  function applyCdToReferences(references, cds) {
130
- if (cds.length === 0) {
131
- return;
132
- }
133
- for (const ref of references) {
134
- if (ref.cds) {
135
- (0, info_1.appendCds)(ref.cds, cds);
136
- }
137
- else {
138
- ref.cds = Array.from(cds);
108
+ if (cds.length > 0) {
109
+ for (const ref of references) {
110
+ addCds(ref, cds);
139
111
  }
140
112
  }
141
113
  }