@eagleoutice/flowr 2.13.9 → 2.13.11

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 (181) hide show
  1. package/README.md +40 -40
  2. package/config.d.ts +50 -2
  3. package/config.js +37 -6
  4. package/dataflow/environments/apply-kill.js +4 -4
  5. package/dataflow/environments/built-in-props.d.ts +28 -4
  6. package/dataflow/environments/built-in-props.js +31 -8
  7. package/dataflow/environments/built-in.d.ts +7 -2
  8. package/dataflow/environments/built-in.js +10 -12
  9. package/dataflow/environments/default-builtin-config.d.ts +46 -6
  10. package/dataflow/environments/default-builtin-config.js +30 -16
  11. package/dataflow/environments/environment.d.ts +16 -0
  12. package/dataflow/environments/environment.js +114 -26
  13. package/dataflow/environments/identifier.d.ts +6 -0
  14. package/dataflow/environments/identifier.js +18 -5
  15. package/dataflow/environments/query-fn-props.js +34 -2
  16. package/dataflow/environments/reference-to-maybe.js +1 -1
  17. package/dataflow/environments/resolve-by-name.js +16 -6
  18. package/dataflow/environments/resolve-helper.d.ts +43 -0
  19. package/dataflow/environments/resolve-helper.js +47 -0
  20. package/dataflow/eval/resolve/alias-tracking.js +45 -1
  21. package/dataflow/eval/resolve/resolve-argument.js +25 -17
  22. package/dataflow/eval/resolve/resolve-strings.d.ts +17 -0
  23. package/dataflow/eval/resolve/resolve-strings.js +16 -9
  24. package/dataflow/eval/resolve/resolve.js +3 -1
  25. package/dataflow/graph/call-graph.d.ts +7 -0
  26. package/dataflow/graph/call-graph.js +103 -0
  27. package/dataflow/graph/df-helper.d.ts +50 -1
  28. package/dataflow/graph/df-helper.js +63 -0
  29. package/dataflow/graph/graph.d.ts +5 -8
  30. package/dataflow/graph/graph.js +24 -13
  31. package/dataflow/internal/linker.d.ts +5 -5
  32. package/dataflow/internal/linker.js +31 -92
  33. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -2
  34. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +3 -9
  35. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +4 -30
  36. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
  37. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -1
  39. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +3 -3
  40. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.d.ts +1 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +5 -1
  42. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +2 -2
  43. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +5 -6
  44. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +32 -14
  45. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +16 -4
  46. package/dataflow/internal/process/functions/call/known-call-handling.js +29 -8
  47. package/documentation/data/faq/faqs.js +1 -1
  48. package/documentation/data/faq/wiki-faq-store.js +3 -2
  49. package/documentation/data/server/doc-data-server-messages.js +1 -1
  50. package/documentation/doc-readme.js +1 -1
  51. package/documentation/doc-util/doc-files.d.ts +5 -0
  52. package/documentation/doc-util/doc-files.js +13 -3
  53. package/documentation/doc-util/doc-sigdb.d.ts +9 -0
  54. package/documentation/doc-util/doc-sigdb.js +32 -0
  55. package/documentation/wiki-analyzer.js +10 -10
  56. package/documentation/wiki-core.js +1 -1
  57. package/documentation/wiki-dataflow-graph.js +3 -3
  58. package/documentation/wiki-interface.js +13 -2
  59. package/documentation/wiki-linting-and-testing.js +13 -13
  60. package/documentation/wiki-mk/doc-context.d.ts +1 -1
  61. package/documentation/wiki-mk/doc-context.js +9 -5
  62. package/documentation/wiki-normalized-ast.js +1 -1
  63. package/documentation/wiki-overview.js +2 -2
  64. package/documentation/wiki-query.js +4 -1
  65. package/documentation/wiki-setup.js +3 -3
  66. package/documentation/wiki-signature-database.js +2 -5
  67. package/gas.d.ts +6 -0
  68. package/gas.js +7 -1
  69. package/linter/linter-rules.d.ts +1 -1
  70. package/linter/rules/syntactically-valid.d.ts +12 -1
  71. package/linter/rules/syntactically-valid.js +88 -17
  72. package/package.json +7 -8
  73. package/project/attached-packages.d.ts +13 -0
  74. package/project/attached-packages.js +30 -0
  75. package/project/context/flowr-analyzer-context.d.ts +15 -0
  76. package/project/context/flowr-analyzer-context.js +14 -3
  77. package/project/context/flowr-analyzer-files-context.d.ts +11 -0
  78. package/project/context/flowr-analyzer-files-context.js +3 -0
  79. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +4 -0
  80. package/project/context/flowr-analyzer-incremental-analysis-context.js +69 -0
  81. package/project/context/flowr-analyzer-loading-order-context.d.ts +8 -0
  82. package/project/context/flowr-analyzer-loading-order-context.js +23 -2
  83. package/project/dependency-version-space.d.ts +33 -11
  84. package/project/dependency-version-space.js +58 -32
  85. package/project/plugins/file-plugins/files/flowr-namespace-file.js +52 -24
  86. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.d.ts +22 -0
  87. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +101 -0
  88. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +30 -11
  89. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +79 -37
  90. package/project/plugins/plugin-registry.d.ts +2 -1
  91. package/project/plugins/plugin-registry.js +2 -0
  92. package/project/sigdb/manifest.js +9 -5
  93. package/project/sigdb/reader.d.ts +20 -0
  94. package/project/sigdb/reader.js +93 -10
  95. package/project/sigdb/signature-match.d.ts +5 -18
  96. package/project/sigdb/signature-match.js +5 -18
  97. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  98. package/queries/catalog/call-graph-query/call-graph-query-executor.js +3 -1
  99. package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +4 -0
  100. package/queries/catalog/call-graph-query/call-graph-query-format.js +4 -0
  101. package/queries/catalog/dependencies-query/dependencies-query-executor.js +11 -3
  102. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +25 -1
  103. package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -2
  104. package/queries/catalog/dependencies-query/function-info/library-functions.js +7 -1
  105. package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -5
  106. package/queries/catalog/dependencies-query/function-info/remote-functions.d.ts +18 -0
  107. package/queries/catalog/dependencies-query/function-info/remote-functions.js +46 -0
  108. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +52 -2
  109. package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -4
  110. package/queries/catalog/dependencies-query/link-devices.d.ts +16 -0
  111. package/queries/catalog/dependencies-query/link-devices.js +104 -0
  112. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -0
  113. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +25 -6
  114. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +37 -6
  115. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +17 -4
  116. package/queries/catalog/happens-before-query/happens-before-query-executor.js +2 -1
  117. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +14 -0
  118. package/queries/catalog/happens-before-query/happens-before-query-format.js +18 -2
  119. package/queries/catalog/input-sources-query/input-sources-query-format.js +4 -0
  120. package/queries/catalog/input-sources-query/input-types.d.ts +10 -0
  121. package/queries/catalog/input-sources-query/input-types.js +10 -0
  122. package/queries/catalog/location-map-query/location-map-query-executor.js +16 -6
  123. package/queries/catalog/location-map-query/location-map-query-format.d.ts +15 -1
  124. package/queries/catalog/location-map-query/location-map-query-format.js +22 -5
  125. package/queries/catalog/signature-query/signature-query-executor.js +3 -0
  126. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -0
  127. package/queries/catalog/slice-query-options.d.ts +11 -1
  128. package/queries/catalog/slice-query-options.js +8 -4
  129. package/queries/catalog/static-slice-query/static-slice-query-executor.js +4 -1
  130. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +5 -1
  131. package/queries/query.d.ts +1 -1
  132. package/r-bridge/lang-4.x/ast/model/model.d.ts +23 -2
  133. package/r-bridge/lang-4.x/ast/model/model.js +44 -0
  134. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -0
  135. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  136. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -0
  137. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -0
  138. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +3 -0
  139. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -0
  140. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +3 -0
  141. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +8 -8
  142. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +9 -46
  143. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +3 -0
  144. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +3 -0
  145. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -0
  146. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -0
  147. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -0
  148. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -0
  149. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +3 -0
  150. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -0
  151. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +3 -0
  152. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -0
  153. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -0
  154. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -0
  155. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +3 -0
  156. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +0 -5
  157. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +6 -3
  158. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +1 -1
  159. package/reconstruct/reconstruct.d.ts +9 -0
  160. package/reconstruct/reconstruct.js +1 -0
  161. package/search/flowr-search-filters.d.ts +25 -1
  162. package/search/flowr-search-filters.js +42 -7
  163. package/search/search-executor/search-generators.js +7 -2
  164. package/search/search-executor/search-transformer.js +4 -1
  165. package/slicing/criterion/parse.d.ts +5 -25
  166. package/slicing/criterion/parse.js +15 -20
  167. package/slicing/static/fingerprint.js +18 -6
  168. package/slicing/static/slice-call.js +2 -2
  169. package/slicing/static/slicer-types.d.ts +10 -0
  170. package/slicing/static/static-slicer.d.ts +1 -1
  171. package/slicing/static/static-slicer.js +29 -6
  172. package/slicing/static/visiting-queue.d.ts +12 -2
  173. package/slicing/static/visiting-queue.js +28 -3
  174. package/util/arg-matching.d.ts +18 -0
  175. package/util/arg-matching.js +70 -0
  176. package/util/collections/bimap.d.ts +21 -1
  177. package/util/collections/bimap.js +43 -7
  178. package/util/r-regex.js +19 -1
  179. package/util/range.d.ts +7 -8
  180. package/util/range.js +10 -11
  181. package/util/version.js +1 -1
@@ -40,6 +40,8 @@ class Environment {
40
40
  memory;
41
41
  cache;
42
42
  builtInEnv;
43
+ /** {@link memory} is shared with a clone; writing needs {@link writableMemory} to unshare it first */
44
+ sharedMemory;
43
45
  /** marks the global environment (`.GlobalEnv`); attached packages (see {@link EnvType}) live below it */
44
46
  globalEnv;
45
47
  constructor(parent, isBuiltInDefault = undefined) {
@@ -70,8 +72,24 @@ class Environment {
70
72
  get closure() {
71
73
  return this.c;
72
74
  }
75
+ /**
76
+ * This environment's {@link memory}, ready to be written to. Every in-place write must go through this
77
+ * rather than through {@link memory} directly, as {@link clone} hands the map itself to the clone and only
78
+ * the first writer of either side copies it (copy-on-write).
79
+ */
80
+ get writableMemory() {
81
+ if (this.sharedMemory) {
82
+ this.memory = new Map(this.memory);
83
+ this.sharedMemory = undefined;
84
+ }
85
+ return this.memory;
86
+ }
73
87
  /**
74
88
  * Create a clone of this environment.
89
+ *
90
+ * The clone shares this environment's {@link memory} until either side writes to it (see
91
+ * {@link writableMemory}); cloning a frame is therefore independent of how many definitions it holds, which
92
+ * matters because attached packages contribute frames with thousands of them.
75
93
  * @param recurseParents - Whether to also clone parent environments
76
94
  */
77
95
  clone(recurseParents) {
@@ -84,7 +102,8 @@ class Environment {
84
102
  clone.n = this.n;
85
103
  clone.t = this.t;
86
104
  clone.globalEnv = this.globalEnv;
87
- clone.memory = new Map(this.memory);
105
+ clone.memory = this.memory;
106
+ clone.sharedMemory = this.sharedMemory = true;
88
107
  return clone;
89
108
  }
90
109
  /**
@@ -125,21 +144,21 @@ class Environment {
125
144
  }
126
145
  // When there are defined indices, merge the definitions
127
146
  if (definition.cds === undefined) {
128
- this.memory.set(name, [definition]);
147
+ this.writableMemory.set(name, [definition]);
129
148
  }
130
149
  else {
131
150
  const existing = this.memory.get(name);
132
151
  const inGraphDefinition = definition;
133
152
  if (existing !== undefined &&
134
153
  inGraphDefinition.cds === undefined) {
135
- this.memory.set(name, [inGraphDefinition]);
154
+ this.writableMemory.set(name, [inGraphDefinition]);
136
155
  }
137
156
  else if (existing === undefined || definition.cds === undefined) {
138
- this.memory.set(name, [definition]);
157
+ this.writableMemory.set(name, [definition]);
139
158
  }
140
159
  else {
141
160
  /* the array may be shared with clones, so replace instead of push */
142
- this.memory.set(name, [...existing, definition]);
161
+ this.writableMemory.set(name, [...existing, definition]);
143
162
  }
144
163
  }
145
164
  }
@@ -150,9 +169,13 @@ class Environment {
150
169
  // navigate to parent until either before built-in or matching namespace
151
170
  const newEnvironment = this.clone(false);
152
171
  let current = newEnvironment;
153
- do {
172
+ /* the match has to be re-checked after every step: a post-condition on `current.n` would end the loop on
173
+ * the very layer it was looking for, before the body could define anything in it */
174
+ for (;;) {
154
175
  if (current.n === ns) {
155
- current.define(definition);
176
+ /* every layer walked here is a fresh clone, and `apply` copies the shared memory on write,
177
+ * so this adds to the layer in place -- `define` would clone and the definition would be lost */
178
+ current.apply(identifier_1.Identifier.getName(definition.name), definition);
156
179
  return newEnvironment;
157
180
  }
158
181
  else if (current.parent && !current.parent.builtInEnv) {
@@ -163,7 +186,7 @@ class Environment {
163
186
  else {
164
187
  break;
165
188
  }
166
- } while (current.n !== ns);
189
+ }
167
190
  // we did not find the namespace, so we inject a new environment here
168
191
  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).`);
169
192
  const env = new Environment(current.parent);
@@ -187,13 +210,13 @@ class Environment {
187
210
  let found = false;
188
211
  do {
189
212
  if (current.memory.has(name)) {
190
- current.memory.set(name, [definition]);
213
+ current.writableMemory.set(name, [definition]);
191
214
  found = true;
192
215
  break;
193
216
  }
194
217
  // `<<-` falls back to the global env, never an attached package below it
195
218
  if (current.globalEnv) {
196
- current.memory.set(name, [definition]);
219
+ current.writableMemory.set(name, [definition]);
197
220
  found = true;
198
221
  break;
199
222
  }
@@ -203,7 +226,7 @@ class Environment {
203
226
  } while (!current.builtInEnv);
204
227
  if (!found) {
205
228
  (0, assert_1.guard)(last !== undefined, () => `Could not find global scope for ${name}`);
206
- last.memory.set(name, [definition]);
229
+ last.writableMemory.set(name, [definition]);
207
230
  }
208
231
  return newEnvironment;
209
232
  }
@@ -298,30 +321,53 @@ class Environment {
298
321
  mergePackageBlocks(other) {
299
322
  const [thisLayers, thisBase] = splitLibraryLayers(this);
300
323
  const [otherLayers, otherBase] = splitLibraryLayers(other);
301
- // `other` first so its packages end up nearest global (most recently attached is nearest, cf. R `search()`)
324
+ /*
325
+ * One block is the other plus the packages attached since (blocks grow at the front), so their union is
326
+ * the longer one and it is already in R's order: the most recently attached package is searched first,
327
+ * `library(a); library(b)` resolves `b` before `a`. This is the overwhelmingly common case, since every
328
+ * statement after a `library` call merges two environments that still hold its layers.
329
+ */
330
+ const keep = layersEndWith(thisLayers, otherLayers) ? thisLayers
331
+ : layersEndWith(otherLayers, thisLayers) ? otherLayers : undefined;
332
+ if (keep !== undefined) {
333
+ const base = thisBase.append(otherBase);
334
+ if (keep === thisLayers && base === thisBase) {
335
+ return this;
336
+ }
337
+ return relinkLayers(keep.map(l => l.clone(false)), base);
338
+ }
339
+ /*
340
+ * Neither block is recognizably an extension of the other, so union them. The longer attach history goes
341
+ * first so its order survives and the other block only contributes what it alone saw: R searches the most
342
+ * recently attached package first, and only the longer block still records that order.
343
+ * Keyed by type and then by name, rather than by a `t:n` string built for every layer of every merge.
344
+ */
345
+ const order = [];
302
346
  const merged = new Map();
303
- for (const layers of [otherLayers, thisLayers]) {
347
+ for (const layers of thisLayers.length > otherLayers.length ? [thisLayers, otherLayers] : [otherLayers, thisLayers]) {
304
348
  for (const layer of layers) {
305
- const key = `${layer.t}:${layer.n}`;
306
- const existing = merged.get(key);
349
+ let byName = merged.get(layer.t);
350
+ if (byName === undefined) {
351
+ byName = new Map();
352
+ merged.set(layer.t, byName);
353
+ }
354
+ const existing = byName.get(layer.n);
307
355
  if (existing === undefined) {
308
- merged.set(key, layer.clone(false));
356
+ const cloned = layer.clone(false);
357
+ byName.set(layer.n, cloned);
358
+ order.push(cloned);
309
359
  }
310
- else {
360
+ else if (existing.memory !== layer.memory) {
311
361
  for (const [name, value] of layer.memory) {
312
362
  const old = existing.memory.get(name);
313
- existing.memory.set(name, old ? (0, append_1.uniqueMergeValuesInDefinitions)(old, value) : value);
363
+ if (old !== value) {
364
+ existing.writableMemory.set(name, old ? (0, append_1.uniqueMergeValuesInDefinitions)(old, value) : value);
365
+ }
314
366
  }
315
367
  }
316
368
  }
317
369
  }
318
- const uniqueLayers = Array.from(merged.values());
319
- let current = thisBase.append(otherBase);
320
- for (let i = uniqueLayers.length - 1; i >= 0; i--) {
321
- uniqueLayers[i].parent = current;
322
- current = uniqueLayers[i];
323
- }
324
- return current;
370
+ return relinkLayers(order, thisBase.append(otherBase));
325
371
  }
326
372
  remove(id) {
327
373
  if (this.builtInEnv) {
@@ -335,7 +381,7 @@ class Environment {
335
381
  const definition = this.memory.get(name);
336
382
  let cont = true;
337
383
  if (definition !== undefined) {
338
- this.memory.delete(name);
384
+ this.writableMemory.delete(name);
339
385
  this.cache?.delete(name);
340
386
  cont = !definition.every(d => (0, info_1.happensInEveryBranch)(d.cds));
341
387
  }
@@ -381,6 +427,14 @@ function findGlobalEnvironment(env) {
381
427
  }
382
428
  return current;
383
429
  }
430
+ /** Walks up to the built-in environment. */
431
+ function findBuiltInEnvironment(env) {
432
+ let current = env;
433
+ while (!current.builtInEnv) {
434
+ current = current.parent;
435
+ }
436
+ return current;
437
+ }
384
438
  /** The `search()` position directly below the global environment; where R attaches by default. */
385
439
  exports.DefaultAttachPosition = 2;
386
440
  /** Prefix of a package's entry in R's `search()` list. */
@@ -453,6 +507,8 @@ exports.REnvironment = {
453
507
  name: 'REnvironment',
454
508
  /** Walks up to the global environment (`.GlobalEnv`); see {@link findGlobalEnvironment}. */
455
509
  findGlobal: findGlobalEnvironment,
510
+ /** Walks up to the built-in environment; see {@link findBuiltInEnvironment}. */
511
+ findBuiltIn: findBuiltInEnvironment,
456
512
  /** Attaches a package block at a `search()` position, below the global by default; see {@link attachPackageAt}. */
457
513
  attachAt: attachPackageAt,
458
514
  /** The `search()` position of a named entry; see {@link searchPositionOf}. */
@@ -460,6 +516,38 @@ exports.REnvironment = {
460
516
  /** The packages on the search path; see {@link attachedPackagesOf}. */
461
517
  attachedPackages: attachedPackagesOf,
462
518
  };
519
+ /**
520
+ * Whether the package block `layers` ends with `tail`, i.e. `tail` is `layers` without some of the attachments
521
+ * made since. A block grows at the front ({@link attachPackageAt} inserts at `search()` position 2), so this is
522
+ * the shape two branches take when one of them attached more packages than the other. Equal blocks qualify.
523
+ *
524
+ * Frames cloned from one another keep the same {@link Environment#memory} map until one of them is written to
525
+ * (see {@link Environment#clone}), so comparing the maps by identity recognizes untouched blocks without
526
+ * scanning them; blocks that only happen to hold equal definitions are treated as different, which merely costs
527
+ * the general union below.
528
+ */
529
+ function layersEndWith(layers, tail) {
530
+ const offset = layers.length - tail.length;
531
+ if (offset < 0) {
532
+ return false;
533
+ }
534
+ for (let i = 0; i < tail.length; i++) {
535
+ const l = layers[offset + i], t = tail[i];
536
+ if (l !== t && (l.t !== t.t || l.n !== t.n || l.memory !== t.memory)) {
537
+ return false;
538
+ }
539
+ }
540
+ return true;
541
+ }
542
+ /** Stacks `layers` (top first) on top of `base`, returning the new top of the chain. The layers must not be shared. */
543
+ function relinkLayers(layers, base) {
544
+ let current = base;
545
+ for (let i = layers.length - 1; i >= 0; i--) {
546
+ layers[i].parent = current;
547
+ current = layers[i];
548
+ }
549
+ return current;
550
+ }
463
551
  /** Splits a package block (a contiguous run of attached-package layers, see {@link EnvType}) into its layers and the env below them. */
464
552
  function splitLibraryLayers(env) {
465
553
  const layers = [];
@@ -160,6 +160,7 @@ export declare const enum PkgName {
160
160
  Fs = "fs",
161
161
  Functools = "functools",
162
162
  GgPlot2 = "ggplot2",
163
+ Here = "here",
163
164
  Hmisc = "Hmisc",
164
165
  Import = "import",
165
166
  Inferference = "inferference",
@@ -304,6 +305,11 @@ export interface InGraphIdentifierDefinition extends IdentifierReference {
304
305
  * that the function returns (best-effort: only set when statically detectable).
305
306
  */
306
307
  readonly returnsEnvState?: REnvironmentInformation;
308
+ /**
309
+ * Whether {@link value} names the sequence this identifier iterates over rather than what it holds, as a
310
+ * `for` loop's variable does: it takes one element of that sequence at a time.
311
+ */
312
+ readonly iterated?: boolean;
307
313
  }
308
314
  /**
309
315
  * A narrowed variant of {@link InGraphIdentifierDefinition} that is guaranteed to have a non-undefined `name`.
@@ -85,12 +85,12 @@ exports.Identifier = {
85
85
  * In this scenario, see {@link Identifier.make} instead.
86
86
  */
87
87
  parse(str) {
88
- const internal = str.includes(':::');
89
- const parts = str.split(internal ? ':::' : '::');
90
- if (parts.length === 2) {
91
- return [parts[1], parts[0], internal];
88
+ const at = namespaceSeparatorAt(str);
89
+ if (at < 0) {
90
+ return str;
92
91
  }
93
- return parts[0];
92
+ const internal = str[at + 2] === ':';
93
+ return [str.slice(at + (internal ? 3 : 2)), str.slice(0, at), internal];
94
94
  },
95
95
  /**
96
96
  * Get the name part of the identifier
@@ -257,6 +257,19 @@ exports.Identifier = {
257
257
  return undefined;
258
258
  }
259
259
  };
260
+ /** The index of the `::` separating namespace from name, skipping backtick-quoted spans; `-1` if there is none. */
261
+ function namespaceSeparatorAt(str) {
262
+ let quoted = false;
263
+ for (let i = 0; i < str.length; i++) {
264
+ if (str[i] === '`') {
265
+ quoted = !quoted;
266
+ }
267
+ else if (!quoted && str[i] === ':' && str[i + 1] === ':') {
268
+ return i;
269
+ }
270
+ }
271
+ return -1;
272
+ }
260
273
  /**
261
274
  * Each reference has exactly one reference type, stored as the respective number.
262
275
  * However, when checking, we may want to allow for one of several types,
@@ -6,8 +6,39 @@ exports.inferFnProps = inferFnProps;
6
6
  exports.builtInNames = builtInNames;
7
7
  const built_in_props_1 = require("./built-in-props");
8
8
  const default_builtin_config_1 = require("./default-builtin-config");
9
+ const environment_1 = require("./environment");
9
10
  const identifier_1 = require("./identifier");
11
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
12
  const resolve_by_name_1 = require("./resolve-by-name");
13
+ /**
14
+ * What flowR states about the package export `definition` binds, `undefined` if it binds none or if flowR
15
+ * states nothing about it. `library(pkg)` binds every export itself, and that binding hides the built-in layer.
16
+ */
17
+ function statedBuiltIn(definition, environment) {
18
+ const pkgFn = definition.type === identifier_1.ReferenceType.Function ? node_id_1.NodeId.toPkgFn(definition.nodeId) : undefined;
19
+ if (pkgFn === undefined) {
20
+ return undefined;
21
+ }
22
+ const [pkg, fn] = pkgFn;
23
+ const known = environment_1.REnvironment.findBuiltIn(environment.current).memory.get(fn)
24
+ ?.filter(d => d.type === identifier_1.ReferenceType.BuiltInFunction && identifier_1.Identifier.getNamespace(d.name ?? '') === pkg);
25
+ return known?.length ? known : undefined;
26
+ }
27
+ /** `definitions` with every package export replaced by what flowR states about it, the array itself if none is one. */
28
+ function withStatedBuiltIns(definitions, environment) {
29
+ let replaced;
30
+ for (const [at, definition] of definitions.entries()) {
31
+ const stated = statedBuiltIn(definition, environment);
32
+ if (stated === undefined) {
33
+ replaced?.push(definition);
34
+ }
35
+ else {
36
+ replaced ??= definitions.slice(0, at);
37
+ replaced.push(...stated);
38
+ }
39
+ }
40
+ return replaced ?? definitions;
41
+ }
11
42
  function ofDefinitions(definitions) {
12
43
  let sig, props;
13
44
  for (const d of definitions ?? []) {
@@ -30,10 +61,11 @@ function queryFnProps(name, { environment, builtIns, signatures, version }) {
30
61
  let info;
31
62
  if (environment !== undefined) {
32
63
  const resolved = (0, resolve_by_name_1.resolveByName)(name, environment, identifier_1.ReferenceType.Function);
33
- if (resolved?.some(d => d.type !== identifier_1.ReferenceType.BuiltInFunction)) {
64
+ const stated = resolved === undefined ? undefined : withStatedBuiltIns(resolved, environment);
65
+ if (stated?.some(d => d.type !== identifier_1.ReferenceType.BuiltInFunction)) {
34
66
  return undefined;
35
67
  }
36
- info = ofDefinitions(resolved);
68
+ info = ofDefinitions(stated);
37
69
  }
38
70
  else if (builtIns !== undefined) {
39
71
  info = ofDefinitions(builtIns.builtInMemory.get(identifier_1.Identifier.getName(name)));
@@ -55,7 +55,7 @@ function withAppliedCds(definition, defaultCd) {
55
55
  function replaceDefinitions(env, key, toUpdate, defaultCd) {
56
56
  const defs = env.memory.get(key);
57
57
  if (defs?.some(d => toUpdate.has(d))) {
58
- env.memory.set(key, defs.map(d => toUpdate.has(d) ? withAppliedCds(d, defaultCd) : d));
58
+ env.writableMemory.set(key, defs.map(d => toUpdate.has(d) ? withAppliedCds(d, defaultCd) : d));
59
59
  }
60
60
  env.cache?.delete(key);
61
61
  }
@@ -20,6 +20,8 @@ const VariableTargetTypes = identifier_1.ReferenceType.Variable | identifier_1.R
20
20
  const ConstantTargetTypes = identifier_1.ReferenceType.Constant | identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.Unknown;
21
21
  const BuiltInConstantTargetTypes = identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.Unknown;
22
22
  const BuiltInFunctionTargetTypes = identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.Unknown;
23
+ const inEveryBranch = (d) => (0, info_1.happensInEveryBranch)(d.cds);
24
+ const notAParameter = (d) => d.type !== identifier_1.ReferenceType.Parameter;
23
25
  const TargetTypePredicate = {
24
26
  [identifier_1.ReferenceType.Unknown]: () => true,
25
27
  [identifier_1.ReferenceType.Function]: ({ type }) => (0, identifier_1.isReferenceType)(type, FunctionTargetTypes),
@@ -45,7 +47,10 @@ function resolveByName(id, environment, target) {
45
47
  if (target === identifier_1.ReferenceType.Unknown) {
46
48
  return resolveByNameAnyType(id, environment);
47
49
  }
48
- const [name, ns, internal] = identifier_1.Identifier.toArray(id);
50
+ /* read piecewise, `Identifier.toArray` would allocate a tuple per resolution */
51
+ const name = identifier_1.Identifier.getName(id);
52
+ const ns = identifier_1.Identifier.getNamespace(id);
53
+ const internal = identifier_1.Identifier.accessesInternal(id);
49
54
  let current = environment.current;
50
55
  /* `current` can already be the built-in environment itself (e.g. `get(x, envir=baseenv())`);
51
56
  * it has no parent to walk to, so resolve directly instead of entering the loop below. */
@@ -75,11 +80,14 @@ function resolveByName(id, environment, target) {
75
80
  }
76
81
  }
77
82
  if (definition !== undefined && definition.length > 0) {
78
- const filtered = definition.filter(wantedType);
79
- if (filtered.length === definition.length && (target !== identifier_1.ReferenceType.Function || definition.every(d => d.type !== identifier_1.ReferenceType.Parameter)) && definition.every(d => (0, info_1.happensInEveryBranch)(d.cds))) {
83
+ /* ask before filtering: the common case wants all of them and needs no copy */
84
+ const allWanted = definition.every(wantedType);
85
+ if (allWanted && (target !== identifier_1.ReferenceType.Function || definition.every(notAParameter)) && definition.every(inEveryBranch)) {
80
86
  return definition;
81
87
  }
82
- else if (filtered.length > 0) {
88
+ /* never alias the environment's own array, it is appended to below */
89
+ const filtered = allWanted ? definition.slice() : definition.filter(wantedType);
90
+ if (filtered.length > 0) {
83
91
  if (definitions) {
84
92
  definitions.push(...filtered);
85
93
  }
@@ -111,7 +119,9 @@ function resolveByNameAnyType(id, environment) {
111
119
  return g;
112
120
  }
113
121
  }
114
- const [name, ns, internal] = identifier_1.Identifier.toArray(id);
122
+ const name = identifier_1.Identifier.getName(id);
123
+ const ns = identifier_1.Identifier.getNamespace(id);
124
+ const internal = identifier_1.Identifier.accessesInternal(id);
115
125
  /* `current` can already be the built-in environment itself */
116
126
  if (current.builtInEnv) {
117
127
  const ret = current.memory.get(name);
@@ -132,7 +142,7 @@ function resolveByNameAnyType(id, environment) {
132
142
  if (internal === false) {
133
143
  definition = definition.filter(({ name }) => name === undefined || !identifier_1.Identifier.accessesInternal(name));
134
144
  }
135
- if (definition.every(d => (0, info_1.happensInEveryBranch)(d.cds))) {
145
+ if (definition.every(inEveryBranch)) {
136
146
  if (cacheable) {
137
147
  environment.current.cache ??= new Map();
138
148
  environment.current.cache.set(id, definition);
@@ -0,0 +1,43 @@
1
+ import { resolveByName, resolveByNameAnyType, resolvesToBuiltInConstant } from './resolve-by-name';
2
+ import { resolveIdToValue, resolveIdToSingleString, resolveToConstants } from '../eval/resolve/alias-tracking';
3
+ import { resolveIdToArgName, resolveIdToArgStringVector, resolveIdToArgValue, resolveIdToArgValueSymbolName, resolveIdToArgVectorLength } from '../../abstract-interpretation/data-frame/resolve-args';
4
+ /**
5
+ * The helper object for resolution: from a name to the definitions it may refer to, and from a node to the
6
+ * value(s) it may hold. Reachable as {@link Dataflow.resolve} as well.
7
+ *
8
+ * Take the narrowest entry point that answers your question, they differ a lot in cost:
9
+ *
10
+ * - {@link Resolve.byName} walks the environment layers once and answers repeat questions from the layer's own
11
+ * lookup cache. Use it whenever the {@link ReferenceType} does not matter.
12
+ * - {@link Resolve.byNameAndType} additionally filters and merges the definitions of every layer it passes.
13
+ * Given the unknown reference type it only forwards to {@link Resolve.byName}, so ask that one directly instead.
14
+ * - {@link Resolve.toValue} and the {@link Resolve.argument} family run the evaluator on top of a resolution.
15
+ */
16
+ export declare const Resolve: {
17
+ readonly name: "Resolve";
18
+ /** Every definition the identifier may refer to, whatever its type. */
19
+ readonly byName: typeof resolveByNameAnyType;
20
+ /** The definitions the identifier may refer to that fit the wanted {@link ReferenceType}. */
21
+ readonly byNameAndType: typeof resolveByName;
22
+ /** Whether the name always, never, or maybe refers to a built-in constant of the given value. */
23
+ readonly toBuiltIn: typeof resolvesToBuiltInConstant;
24
+ /** The constant values the name resolves to. */
25
+ readonly toConstants: typeof resolveToConstants;
26
+ /** The value(s) the node may hold, tracking aliases as the configuration allows. */
27
+ readonly toValue: typeof resolveIdToValue;
28
+ /** The single string the node resolves to, or `undefined` if it is not exactly one. */
29
+ readonly toSingleString: typeof resolveIdToSingleString;
30
+ /** The same, for the arguments of a call. */
31
+ readonly argument: {
32
+ /** The argument's name. */
33
+ readonly name: typeof resolveIdToArgName;
34
+ /** The argument's value. */
35
+ readonly value: typeof resolveIdToArgValue;
36
+ /** The argument's value as a vector of strings. */
37
+ readonly stringVector: typeof resolveIdToArgStringVector;
38
+ /** The argument's value as the name of the symbol it holds. */
39
+ readonly symbolName: typeof resolveIdToArgValueSymbolName;
40
+ /** The length of the vector the argument holds. */
41
+ readonly vectorLength: typeof resolveIdToArgVectorLength;
42
+ };
43
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Resolve = void 0;
4
+ const resolve_by_name_1 = require("./resolve-by-name");
5
+ const alias_tracking_1 = require("../eval/resolve/alias-tracking");
6
+ const resolve_args_1 = require("../../abstract-interpretation/data-frame/resolve-args");
7
+ /**
8
+ * The helper object for resolution: from a name to the definitions it may refer to, and from a node to the
9
+ * value(s) it may hold. Reachable as {@link Dataflow.resolve} as well.
10
+ *
11
+ * Take the narrowest entry point that answers your question, they differ a lot in cost:
12
+ *
13
+ * - {@link Resolve.byName} walks the environment layers once and answers repeat questions from the layer's own
14
+ * lookup cache. Use it whenever the {@link ReferenceType} does not matter.
15
+ * - {@link Resolve.byNameAndType} additionally filters and merges the definitions of every layer it passes.
16
+ * Given the unknown reference type it only forwards to {@link Resolve.byName}, so ask that one directly instead.
17
+ * - {@link Resolve.toValue} and the {@link Resolve.argument} family run the evaluator on top of a resolution.
18
+ */
19
+ exports.Resolve = {
20
+ name: 'Resolve',
21
+ /** Every definition the identifier may refer to, whatever its type. */
22
+ byName: resolve_by_name_1.resolveByNameAnyType,
23
+ /** The definitions the identifier may refer to that fit the wanted {@link ReferenceType}. */
24
+ byNameAndType: resolve_by_name_1.resolveByName,
25
+ /** Whether the name always, never, or maybe refers to a built-in constant of the given value. */
26
+ toBuiltIn: resolve_by_name_1.resolvesToBuiltInConstant,
27
+ /** The constant values the name resolves to. */
28
+ toConstants: alias_tracking_1.resolveToConstants,
29
+ /** The value(s) the node may hold, tracking aliases as the configuration allows. */
30
+ toValue: alias_tracking_1.resolveIdToValue,
31
+ /** The single string the node resolves to, or `undefined` if it is not exactly one. */
32
+ toSingleString: alias_tracking_1.resolveIdToSingleString,
33
+ /** The same, for the arguments of a call. */
34
+ argument: {
35
+ /** The argument's name. */
36
+ name: resolve_args_1.resolveIdToArgName,
37
+ /** The argument's value. */
38
+ value: resolve_args_1.resolveIdToArgValue,
39
+ /** The argument's value as a vector of strings. */
40
+ stringVector: resolve_args_1.resolveIdToArgStringVector,
41
+ /** The argument's value as the name of the symbol it holds. */
42
+ symbolName: resolve_args_1.resolveIdToArgValueSymbolName,
43
+ /** The length of the vector the argument holds. */
44
+ vectorLength: resolve_args_1.resolveIdToArgVectorLength
45
+ }
46
+ };
47
+ //# sourceMappingURL=resolve-helper.js.map
@@ -14,6 +14,7 @@ const assert_1 = require("../../../util/assert");
14
14
  const identifier_1 = require("../../environments/identifier");
15
15
  const resolve_by_name_1 = require("../../environments/resolve-by-name");
16
16
  const edge_1 = require("../../graph/edge");
17
+ const r_for_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
17
18
  const unknown_replacement_1 = require("../../graph/unknown-replacement");
18
19
  const unknown_side_effect_1 = require("../../graph/unknown-side-effect");
19
20
  const vertex_1 = require("../../graph/vertex");
@@ -173,6 +174,16 @@ function resolveIdToSingleString(id, info) {
173
174
  const element = resolved?.elements.length === 1 ? resolved.elements[0] : undefined;
174
175
  return element?.type === 'string' && (0, r_value_1.isValue)(element.value) ? element.value.str : undefined;
175
176
  }
177
+ /** the values one element of a sequence may take: a vector contributes its elements, a set what its members do */
178
+ function iteratedElements(value) {
179
+ if (value.type === 'vector' && (0, r_value_1.isValue)(value.elements)) {
180
+ return value.elements.flatMap(iteratedElements);
181
+ }
182
+ else if (value.type === 'set' && (0, r_value_1.isValue)(value.elements)) {
183
+ return value.elements.flatMap(iteratedElements);
184
+ }
185
+ return [value];
186
+ }
176
187
  /**
177
188
  * Please use {@link resolveIdToValue}
178
189
  *
@@ -219,7 +230,13 @@ function trackAliasInEnvironments(identifier, environment, { blocked, idMap, res
219
230
  if ((0, r_value_1.isTop)(value)) {
220
231
  return r_value_1.Top;
221
232
  }
222
- values.add(value);
233
+ /* the sequence is what it runs over, so what the name holds is one of its elements */
234
+ if (def.iterated) {
235
+ iteratedElements(value).forEach(e => values.add(e));
236
+ }
237
+ else {
238
+ values.add(value);
239
+ }
223
240
  }
224
241
  }
225
242
  }
@@ -271,6 +288,27 @@ function isParameterDefault(node, idMap) {
271
288
  return node !== undefined && (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */
272
289
  || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */));
273
290
  }
291
+ /**
292
+ * The sequence a use of a `for` loop's variable runs over, `undefined` when `id` is no such use. Every
293
+ * definition it reads has to be that variable: once anything else writes the name (`i <- i + 1` in the body),
294
+ * the sequence no longer states what the name holds.
295
+ */
296
+ function iteratedSequence(id, graph, idMap) {
297
+ let sequence;
298
+ for (const [target, edge] of graph.outgoingEdges(id) ?? []) {
299
+ if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
300
+ continue;
301
+ }
302
+ const definition = idMap.get(target);
303
+ const loop = definition?.info.parent === undefined ? undefined : idMap.get(definition.info.parent);
304
+ if (!r_for_loop_1.RForLoop.is(loop) || loop.variable.info.id !== definition?.info.id
305
+ || (sequence !== undefined && sequence.info.id !== loop.vector.info.id)) {
306
+ return undefined;
307
+ }
308
+ sequence = loop.vector;
309
+ }
310
+ return sequence;
311
+ }
274
312
  /**
275
313
  * Please use {@link resolveIdToValue}
276
314
  *
@@ -288,6 +326,12 @@ function trackAliasesInGraph(id, graph, ctx, idMap, blocked) {
288
326
  }
289
327
  idMap ??= graph.idMap;
290
328
  (0, assert_1.guard)(idMap !== undefined, 'The ID map is required to get the lineage of a node');
329
+ /* a loop makes the walk below give up, yet the variable of a `for` is precisely its sequence, elementwise */
330
+ const sequence = iteratedSequence(id, graph, idMap);
331
+ if (sequence !== undefined) {
332
+ const value = resolveIdToValue(sequence.info.id, { graph, idMap, ctx, blocked });
333
+ return (0, r_value_1.isTop)(value) ? r_value_1.Top : (0, set_constants_1.setFrom)(...iteratedElements(value));
334
+ }
291
335
  const queue = new visiting_queue_1.VisitingQueue(10);
292
336
  const clean = ctx.env.makeCleanEnv();
293
337
  const cleanFingerprint = ctx.env.getCleanEnvFingerprint();
@@ -92,27 +92,35 @@ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environm
92
92
  if (resolved) {
93
93
  const values = [];
94
94
  for (const value of resolved.elements) {
95
- if (!(0, r_value_1.isValue)(value)) {
96
- return undefined;
97
- }
98
- else if (value.type === 'string' && (0, r_value_1.isValue)(value.value)) {
99
- values.push(value.value.str);
100
- }
101
- else if (value.type === 'logical' && (0, r_value_1.isValue)(value.value)) {
102
- values.push(value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse);
103
- }
104
- else if (value.type === 'vector' && (0, r_value_1.isValue)(value.elements)) {
105
- const elements = (0, string_constants_1.collectStrings)(value.elements, !full);
106
- if (elements === undefined) {
107
- return undefined;
108
- }
109
- values.push(...elements);
110
- }
111
- else {
95
+ const strings = (0, r_value_1.isValue)(value) ? stringsOfValue(value, full) : undefined;
96
+ if (strings === undefined) {
112
97
  return undefined;
113
98
  }
99
+ values.push(...strings);
114
100
  }
115
101
  return values;
116
102
  }
117
103
  }
104
+ /**
105
+ * The strings a resolved value stands for. A value that is no string is data given inline and hence reported as
106
+ * {@link Constant}, so that a consumer can tell it apart from a value we failed to resolve ({@link Unknown}).
107
+ */
108
+ function stringsOfValue(value, full) {
109
+ switch (value.type) {
110
+ case 'string':
111
+ return (0, r_value_1.isValue)(value.value) ? [value.value.str] : undefined;
112
+ case 'logical':
113
+ return (0, r_value_1.isValue)(value.value) ? [value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse] : undefined;
114
+ case 'vector':
115
+ return (0, r_value_1.isValue)(value.elements)
116
+ ? (0, string_constants_1.collectStrings)(value.elements, !full) ?? (value.elements.every(r_value_1.isValue) ? [dependencies_query_format_1.Constant] : undefined)
117
+ : undefined;
118
+ case 'number':
119
+ case 'interval':
120
+ case 'null':
121
+ return [dependencies_query_format_1.Constant];
122
+ default:
123
+ return undefined;
124
+ }
125
+ }
118
126
  //# sourceMappingURL=resolve-argument.js.map