@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
@@ -14,10 +14,7 @@ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id"
14
14
  const TailCacheCap = 4096;
15
15
  /** A namespaced lookup only sees its matching layer; a bare lookup skips loaded-but-unattached namespaces (`requireNamespace`). */
16
16
  function layerSkipped(layer, ns) {
17
- if (ns !== undefined) {
18
- return layer.n !== ns;
19
- }
20
- return layer.t === environment_1.EnvType.LoadedNamespace;
17
+ return ns !== undefined ? layer.n !== ns : layer.t === environment_1.EnvType.LoadedNamespace;
21
18
  }
22
19
  /**
23
20
  * What the built-in environment states about `pkg::name` for a package nothing attached: `pkg::fn` reaches its
@@ -34,7 +31,6 @@ const BuiltInFunctionTargetTypes = identifier_1.ReferenceType.BuiltInFunction |
34
31
  const NonFunctionTargetTypes = identifier_1.ReferenceType.Variable | identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Unknown
35
32
  | identifier_1.ReferenceType.Constant | identifier_1.ReferenceType.BuiltInConstant;
36
33
  const inEveryBranch = (d) => (0, info_1.happensInEveryBranch)(d.cds);
37
- const notAParameter = (d) => d.type !== identifier_1.ReferenceType.Parameter;
38
34
  const TargetTypePredicate = {
39
35
  [identifier_1.ReferenceType.Unknown]: () => true,
40
36
  [identifier_1.ReferenceType.Function]: ({ type }) => (0, identifier_1.isReferenceType)(type, FunctionTargetTypes),
@@ -77,6 +73,14 @@ function resolveByName(id, environment, target) {
77
73
  const found = resolveByTargetType(id, environment, target);
78
74
  return found === undefined && target === identifier_1.ReferenceType.NonFunction ? ownDefinitions(id, environment) : found;
79
75
  }
76
+ function tailCacheOf(env, target) {
77
+ env.tailCache ??= new Map();
78
+ let memo = env.tailCache.get(target);
79
+ if (memo === undefined) {
80
+ env.tailCache.set(target, memo = new Map());
81
+ }
82
+ return memo;
83
+ }
80
84
  /** {@link resolveByName} without its two special targets, i.e. the plain walk up the environments. */
81
85
  function resolveByTargetType(id, environment, target) {
82
86
  /* read piecewise, `Identifier.toArray` would allocate a tuple per resolution */
@@ -95,12 +99,12 @@ function resolveByTargetType(id, environment, target) {
95
99
  * walk through them is done once per name and target instead of once per resolution */
96
100
  const flatten = ns === undefined && internal !== false && typeof id === 'string'
97
101
  && target !== identifier_1.ReferenceType.S3MethodPrefix && target !== identifier_1.ReferenceType.S7MethodPrefix;
98
- const key = flatten ? `${target}\u0000${name}` : '';
99
102
  let flattenAt;
100
103
  do {
101
104
  if (flatten && flattenAt === undefined && definitions === undefined && (current.t !== undefined || current.builtInEnv)) {
102
- const cached = current.tailCache?.get(key);
103
- if (cached !== undefined || current.tailCache?.has(key)) {
105
+ const memo = current.tailCache?.get(target);
106
+ const cached = memo?.get(name);
107
+ if (cached !== undefined || memo?.has(name)) {
104
108
  return cached;
105
109
  }
106
110
  flattenAt = current;
@@ -113,13 +117,7 @@ function resolveByTargetType(id, environment, target) {
113
117
  if (target === identifier_1.ReferenceType.S3MethodPrefix || target === identifier_1.ReferenceType.S7MethodPrefix) {
114
118
  // S3 method prefixes only resolve to functions, S3s must not match the exported criteria!
115
119
  const prefix = name + (target === identifier_1.ReferenceType.S3MethodPrefix ? '.' : built_in_s_seven_dispatch_1.S7DispatchSeparator);
116
- const hits = [];
117
- for (const defName of current.memory.keys()) {
118
- if (defName.startsWith(prefix)) {
119
- hits.push(...current.memory.get(defName) ?? []);
120
- }
121
- }
122
- definition = hits;
120
+ definition = current.memory.entries().filter(([defName]) => defName.startsWith(prefix)).flatMap(([, defs]) => defs).toArray();
123
121
  }
124
122
  else {
125
123
  definition = current.lookup(name);
@@ -138,25 +136,19 @@ function resolveByTargetType(id, environment, target) {
138
136
  allOk = false;
139
137
  break;
140
138
  }
141
- if (allOk && ((checkParameters && !notAParameter(def)) || !inEveryBranch(def))) {
139
+ if (allOk && ((checkParameters && def.type === identifier_1.ReferenceType.Parameter) || !inEveryBranch(def))) {
142
140
  allOk = false;
143
141
  }
144
142
  }
145
143
  if (allOk) {
146
144
  if (flattenAt !== undefined) {
147
- (flattenAt.tailCache ??= new Map()).set(key, definition);
145
+ tailCacheOf(flattenAt, target).set(name, definition);
148
146
  }
149
147
  return definition;
150
148
  }
151
- /* never alias the environment's own array, it is appended to below */
152
- const filtered = allWanted ? definition.slice() : definition.filter(wantedType);
149
+ const filtered = allWanted ? definition : definition.filter(wantedType);
153
150
  if (filtered.length > 0) {
154
- if (definitions) {
155
- definitions.push(...filtered);
156
- }
157
- else {
158
- definitions = filtered;
159
- }
151
+ (definitions ??= []).push(...filtered);
160
152
  }
161
153
  }
162
154
  current = current.parent;
@@ -169,11 +161,11 @@ function resolveByTargetType(id, environment, target) {
169
161
  ? (builtIns === undefined || builtIns.length === 0 ? definitions : definitions.concat(builtIns))
170
162
  : (builtIns === undefined || builtIns.length > 0 ? builtIns : undefined);
171
163
  if (flattenAt !== undefined) {
172
- const memo = flattenAt.tailCache ??= new Map();
164
+ const memo = tailCacheOf(flattenAt, target);
173
165
  if (memo.size >= TailCacheCap) {
174
166
  memo.clear();
175
167
  }
176
- memo.set(key, result);
168
+ memo.set(name, result);
177
169
  }
178
170
  return result;
179
171
  }
@@ -184,25 +176,19 @@ function resolveByTargetType(id, environment, target) {
184
176
  function resolveByNameAnyType(id, environment) {
185
177
  let current = environment.current;
186
178
  /* only cache plain names: namespaced ids are arrays (no stable map key) and must not answer plain lookups */
187
- const cacheable = typeof id === 'string';
188
- if (cacheable) {
179
+ if (typeof id === 'string') {
189
180
  const g = current.cache?.get(id);
190
181
  if (g !== undefined) {
191
182
  return g;
192
183
  }
193
184
  }
194
185
  const name = identifier_1.Identifier.getName(id);
195
- const ns = identifier_1.Identifier.getNamespace(id);
196
- const internal = identifier_1.Identifier.accessesInternal(id);
197
186
  /* `current` can already be the built-in environment itself */
198
187
  if (current.builtInEnv) {
199
- const ret = current.lookup(name);
200
- if (ret && cacheable) {
201
- current.cache ??= new Map();
202
- current.cache.set(id, ret);
203
- }
204
- return ret;
188
+ return remember(environment, id, current.lookup(name));
205
189
  }
190
+ const ns = identifier_1.Identifier.getNamespace(id);
191
+ const internal = identifier_1.Identifier.accessesInternal(id);
206
192
  let definitions = undefined;
207
193
  do {
208
194
  if (layerSkipped(current, ns)) {
@@ -215,36 +201,25 @@ function resolveByNameAnyType(id, environment) {
215
201
  definition = definition.filter(({ name }) => name === undefined || !identifier_1.Identifier.accessesInternal(name));
216
202
  }
217
203
  if (definition.every(inEveryBranch)) {
218
- if (cacheable) {
219
- environment.current.cache ??= new Map();
220
- environment.current.cache.set(id, definition);
221
- }
222
- return definition;
204
+ return remember(environment, id, definition);
223
205
  }
224
206
  else if (definition.length > 0) {
225
- if (definitions) {
226
- definitions = definitions.concat(definition);
227
- }
228
- else {
229
- definitions = definition;
230
- }
207
+ definitions = definitions ? definitions.concat(definition) : definition;
231
208
  }
232
209
  }
233
210
  current = current.parent;
234
211
  } while (!current.builtInEnv);
235
212
  const builtIns = statedIn(current, name, ns) ?? current.lookup(name);
236
- let ret;
237
- if (definitions) {
238
- ret = builtIns === undefined ? definitions : definitions.concat(builtIns);
213
+ if (definitions === undefined) {
214
+ return remember(environment, id, builtIns);
239
215
  }
240
- else {
241
- ret = builtIns;
242
- }
243
- if (ret && cacheable) {
244
- environment.current.cache ??= new Map();
245
- environment.current.cache.set(id, ret);
216
+ return remember(environment, id, builtIns === undefined ? definitions : definitions.concat(builtIns));
217
+ }
218
+ function remember(environment, id, definitions) {
219
+ if (definitions !== undefined && typeof id === 'string') {
220
+ (environment.current.cache ??= new Map()).set(id, definitions);
246
221
  }
247
- return ret;
222
+ return definitions;
248
223
  }
249
224
  /**
250
225
  * Whether every definition `name` may refer to is the built-in one (or there is none), i.e., the name is not
@@ -266,28 +241,14 @@ function resolvesToBuiltIn(name, environment, target) {
266
241
  * @useInstead {@link Resolve.toBuiltIn}
267
242
  */
268
243
  function resolvesToBuiltInConstant(name, environment, wantedValue) {
269
- if (name === undefined) {
270
- return logic_1.Ternary.Never;
271
- }
272
- const definition = resolveByName(name, environment, identifier_1.ReferenceType.Constant);
244
+ const definition = name === undefined ? undefined : resolveByName(name, environment, identifier_1.ReferenceType.Constant);
273
245
  if (definition === undefined) {
274
246
  return logic_1.Ternary.Never;
275
247
  }
276
- let all = true;
277
- let some = false;
278
- for (const def of definition) {
279
- if (def.type === identifier_1.ReferenceType.BuiltInConstant && def.value === wantedValue) {
280
- some = true;
281
- }
282
- else {
283
- all = false;
284
- }
285
- }
286
- if (all) {
248
+ const isWanted = (def) => def.type === identifier_1.ReferenceType.BuiltInConstant && def.value === wantedValue;
249
+ if (definition.every(isWanted)) {
287
250
  return logic_1.Ternary.Always;
288
251
  }
289
- else {
290
- return some ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
291
- }
252
+ return definition.some(isWanted) ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
292
253
  }
293
254
  //# sourceMappingURL=resolve-by-name.js.map
@@ -3,7 +3,9 @@ import type { DataflowGraphVertexFunctionCall } from '../../graph/vertex';
3
3
  import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
4
  import type { VariableResolve } from '../../../config';
5
5
  import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
6
+ /** The index of the argument of `vertex` that binds the formal `argumentName`, R's matching when the formals are known and the `argumentIndex`-th unnamed argument otherwise. */
7
+ export declare function boundArgumentIndex<Idx extends number | 'unnamed' | undefined>(graph: DataflowGraph, vertex: DataflowGraphVertexFunctionCall, argumentIndex: Idx, argumentName: string, ctx: ReadOnlyFlowrAnalyzerContext): Idx | number;
6
8
  /**
7
- * Get the values of all arguments matching the criteria.
9
+ * Get the values of all arguments matching the criteria, keyed by the id of the argument.
8
10
  */
9
11
  export declare function getArgumentStringValue(variableResolve: VariableResolve, graph: DataflowGraph, vertex: DataflowGraphVertexFunctionCall, argumentIndex: number | 'unnamed' | undefined, argumentName: string | undefined, resolveValue: boolean | 'library' | undefined, ctx: ReadOnlyFlowrAnalyzerContext): Map<NodeId, Set<string | undefined>> | undefined;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.boundArgumentIndex = boundArgumentIndex;
3
4
  exports.getArgumentStringValue = getArgumentStringValue;
4
5
  const graph_1 = require("../../graph/graph");
5
6
  const r_value_1 = require("../values/r-value");
6
7
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
+ const match_args_1 = require("../../graph/match-args");
7
9
  const assert_1 = require("../../../util/assert");
8
10
  const vertex_1 = require("../../graph/vertex");
9
11
  const edge_1 = require("../../graph/edge");
@@ -19,51 +21,65 @@ const string_constants_1 = require("../values/string/string-constants");
19
21
  const resolve_helper_1 = require("../../environments/resolve-helper");
20
22
  const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
21
23
  const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
24
+ /** The index of the argument of `vertex` that binds the formal `argumentName`, R's matching when the formals are known and the `argumentIndex`-th unnamed argument otherwise. */
25
+ function boundArgumentIndex(graph, vertex, argumentIndex, argumentName, ctx) {
26
+ const call = graph.idMap?.get(vertex.id);
27
+ const formals = r_function_call_1.RFunctionCall.is(call) ? match_args_1.MatchArgs.formalsOf(call, graph, ctx) : undefined;
28
+ if (formals?.includes(argumentName)) {
29
+ const bound = match_args_1.MatchArgs.toSpec(vertex.args, Object.fromEntries(formals.map(f => [f, f]))).get(argumentName)?.[0];
30
+ return bound === undefined ? vertex.args.length : vertex.args.findIndex(a => a !== r_function_call_1.EmptyArgument && a.nodeId === bound);
31
+ }
32
+ const arg = vertex.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && arg.name === argumentName);
33
+ if (arg >= 0) {
34
+ return arg;
35
+ }
36
+ else if (typeof argumentIndex === 'number') {
37
+ /* a named argument takes no position, so the parameter binds the matching unnamed one */
38
+ const unnamed = vertex.args.flatMap((a, i) => a === r_function_call_1.EmptyArgument || !a.name ? [i] : []);
39
+ return unnamed[argumentIndex] ?? vertex.args.length;
40
+ }
41
+ return argumentIndex;
42
+ }
22
43
  /**
23
- * Get the values of all arguments matching the criteria.
44
+ * Get the values of all arguments matching the criteria, keyed by the id of the argument.
24
45
  */
25
46
  function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, argumentName, resolveValue, ctx) {
26
- if (argumentName) {
27
- const arg = vertex?.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && arg.name === argumentName);
28
- if (arg >= 0) {
29
- argumentIndex = arg;
30
- }
47
+ if (argumentName && argumentIndex !== 'unnamed') {
48
+ argumentIndex = boundArgumentIndex(graph, vertex, argumentIndex, argumentName, ctx);
31
49
  }
32
- if (!vertex || argumentIndex === undefined) {
50
+ if (argumentIndex === undefined) {
33
51
  return undefined;
34
52
  }
35
53
  if (argumentIndex === 'unnamed') {
36
- // return all unnamed arguments
37
- const references = vertex.args.filter(arg => arg !== r_function_call_1.EmptyArgument && !arg.name).map(graph_1.FunctionArgument.getReference).filter(assert_1.isNotUndefined);
38
54
  const map = new Map();
39
- for (const ref of references) {
40
- let valueNode = graph.idMap?.get(ref);
41
- if (r_argument_1.RArgument.is(valueNode)) {
42
- valueNode = valueNode.value;
55
+ /* all unnamed arguments, and the one named `argumentName`, which is evaluated rather than taken as a name */
56
+ for (const arg of vertex.args) {
57
+ if (arg === r_function_call_1.EmptyArgument || (arg.name && arg.name !== argumentName)) {
58
+ continue;
43
59
  }
44
- if (valueNode) {
45
- // this should be evaluated in the callee-context
46
- const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue, ctx) ?? openedResourceOf(variableResolve, graph, valueNode.info.id, ctx) ?? [dependencies_query_format_1.Unknown];
47
- map.set(ref, new Set(values));
60
+ const ref = graph_1.FunctionArgument.getReference(arg);
61
+ const resolveAs = graph_1.FunctionArgument.isNamed(arg) && resolveValue === 'library' ? true : resolveValue;
62
+ const values = argumentValues(variableResolve, graph, vertex, ref, resolveAs, ctx);
63
+ if (ref !== undefined && values !== undefined) {
64
+ map.set(ref, values);
48
65
  }
49
66
  }
50
67
  return map;
51
68
  }
52
- if (argumentIndex < vertex.args.length) {
53
- const arg = graph_1.FunctionArgument.getReference(vertex.args[argumentIndex]);
54
- if (!arg) {
55
- return undefined;
56
- }
57
- let valueNode = graph.idMap?.get(arg);
58
- if (r_argument_1.RArgument.is(valueNode)) {
59
- valueNode = valueNode.value;
60
- }
61
- if (valueNode) {
62
- const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue, ctx) ?? openedResourceOf(variableResolve, graph, valueNode.info.id, ctx) ?? [dependencies_query_format_1.Unknown];
63
- return new Map([[arg, new Set(values)]]);
64
- }
69
+ const ref = argumentIndex < vertex.args.length ? graph_1.FunctionArgument.getReference(vertex.args[argumentIndex]) : undefined;
70
+ const values = argumentValues(variableResolve, graph, vertex, ref, resolveValue, ctx);
71
+ return ref === undefined || values === undefined ? undefined : new Map([[ref, values]]);
72
+ }
73
+ /** The values of the argument `ref` passes to `vertex`, falling back to the resource a call it reads from opens, and to {@link Unknown}. */
74
+ function argumentValues(variableResolve, graph, vertex, ref, resolveValue, ctx) {
75
+ const valueNode = ref === undefined ? undefined : r_argument_1.RArgument.valueOf(graph.idMap?.get(ref));
76
+ if (valueNode === undefined) {
77
+ return undefined;
65
78
  }
66
- return undefined;
79
+ const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, resolveValue, ctx)
80
+ ?? openedResourceOf(variableResolve, graph, valueNode.info.id, ctx)
81
+ ?? [dependencies_query_format_1.Unknown];
82
+ return new Set(values);
67
83
  }
68
84
  function openedResourceOf(variableResolve, graph, argument, ctx) {
69
85
  for (const id of df_helper_1.Dataflow.provenance(argument, graph, undefined, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall)) {
@@ -78,8 +94,8 @@ function openedResourceOf(variableResolve, graph, argument, ctx) {
78
94
  }
79
95
  return undefined;
80
96
  }
81
- function hasCharacterOnly(variableResolve, graph, vertex, idMap, ctx) {
82
- if (!vertex.args || vertex.args.length === 0 || !idMap) {
97
+ function hasCharacterOnly(variableResolve, graph, vertex, ctx) {
98
+ if (vertex.args.length === 0 || !graph.idMap) {
83
99
  return false;
84
100
  }
85
101
  const treatAsChar = getArgumentStringValue(variableResolve, graph, vertex, 5, 'character.only', true, ctx);
@@ -87,40 +103,21 @@ function hasCharacterOnly(variableResolve, graph, vertex, idMap, ctx) {
87
103
  return false;
88
104
  }
89
105
  const hasTrue = treatAsChar.values().some(set => set?.has('TRUE'));
90
- const hasFalse = hasTrue ? treatAsChar.values().some(set => set === undefined || set.has('FALSE')) : false;
91
- if (hasTrue && hasFalse) {
92
- return 'maybe';
93
- }
94
- else {
95
- return hasTrue;
96
- }
106
+ const hasFalse = hasTrue && treatAsChar.values().some(set => set === undefined || set.has('FALSE'));
107
+ return hasTrue && hasFalse ? 'maybe' : hasTrue;
97
108
  }
98
- function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environment, idMap, resolveValue, ctx) {
99
- let full = true;
100
- if (!resolveValue) {
101
- full = false;
102
- }
103
- if (resolveValue === 'library') {
104
- const hasChar = hasCharacterOnly(variableResolve, graph, vertex, idMap, ctx);
105
- if (hasChar === false) {
106
- if (r_symbol_1.RSymbol.is(argument)) {
107
- return [argument.lexeme];
108
- }
109
- full = false;
109
+ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, resolveValue, ctx) {
110
+ let full = !!resolveValue;
111
+ if (resolveValue === 'library' && hasCharacterOnly(variableResolve, graph, vertex, ctx) === false) {
112
+ if (r_symbol_1.RSymbol.is(argument)) {
113
+ return [argument.lexeme];
110
114
  }
115
+ full = false;
111
116
  }
112
- const resolved = (0, general_1.valueSetGuard)(resolve_helper_1.Resolve.toValue(argument, { environment, graph, full, resolve: variableResolve, ctx }));
113
- if (resolved) {
114
- const values = [];
115
- for (const value of resolved.elements) {
116
- const strings = (0, r_value_2.isValue)(value) ? stringsOfValue(value, full) : undefined;
117
- if (strings === undefined) {
118
- return undefined;
119
- }
120
- values.push(...strings);
121
- }
122
- return values;
123
- }
117
+ // this should be evaluated in the callee-context
118
+ const resolved = (0, general_1.valueSetGuard)(resolve_helper_1.Resolve.toValue(argument, { environment: vertex.environment, graph, full, resolve: variableResolve, ctx }));
119
+ const strings = resolved?.elements.map(value => (0, r_value_2.isValue)(value) ? stringsOfValue(value, full) : undefined);
120
+ return strings?.every(assert_1.isNotUndefined) ? strings.flat() : undefined;
124
121
  }
125
122
  /**
126
123
  * The strings a resolved value stands for. A value that is no string is data given inline and hence reported as
@@ -17,13 +17,19 @@ export interface WorkingDirectoryResolution {
17
17
  readonly certain: boolean;
18
18
  }
19
19
  type Guards = readonly ControlDependency[];
20
+ /** apply one `setwd(dir)`: an absolute (or `~`-rooted) `dir` replaces `current`, a relative `dir` joins onto it */
21
+ declare function applyChange(current: string, dir: string): string;
20
22
  declare function resolveAt(target: NodeId, targetCds: Guards, baseWd: string, changes: readonly WorkingDirectoryChange[], cfg: ControlFlowGraph): WorkingDirectoryResolution;
21
23
  declare function collect(graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext): WorkingDirectoryChange[];
22
24
  /** Resolve R's process-global working directory (sensitive to `setwd`) at a program point; path-sensitive, unbounded rather than wrong under loops/functions. */
23
25
  export declare const WorkingDirectory: {
24
26
  readonly collect: typeof collect;
25
27
  readonly resolveAt: typeof resolveAt;
26
- /** reusable `(callId, scriptFile?) => candidate roots`, collecting the changes once for the whole graph */
27
- readonly rootsResolver: (graph: DataflowGraph, cfg: ControlFlowGraph, ctx: ReadOnlyFlowrAnalyzerContext) => (id: NodeId, file?: string) => readonly string[];
28
+ readonly applyChange: typeof applyChange;
29
+ /** reusable `(callId, scriptFile?) => candidate roots`, collecting the changes once for the whole graph; `pinned` when a `setwd` decides them */
30
+ readonly rootsResolver: (graph: DataflowGraph, cfg: ControlFlowGraph, ctx: ReadOnlyFlowrAnalyzerContext) => (id: NodeId, file?: string) => {
31
+ roots: readonly string[];
32
+ pinned: boolean;
33
+ };
28
34
  };
29
35
  export {};
@@ -10,10 +10,11 @@ const dependencies_query_format_1 = require("../../../queries/catalog/dependenci
10
10
  const strings_1 = require("../../../util/text/strings");
11
11
  const info_1 = require("../../info");
12
12
  const edge_1 = require("../../graph/edge");
13
+ const frame_reflection_1 = require("../../fn/frame-reflection");
14
+ const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
13
15
  const defaultmap_1 = require("../../../util/collections/defaultmap");
14
16
  const files_1 = require("../../../util/files");
15
17
  const built_in_source_1 = require("../../internal/process/functions/call/built-in/built-in-source");
16
- const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
17
18
  const arrays_1 = require("../../../util/collections/arrays");
18
19
  /** functions recognized as changing the working directory; a registry so more (e.g. `withr::with_dir`) can be added */
19
20
  const ChangeFunctions = [
@@ -21,9 +22,6 @@ const ChangeFunctions = [
21
22
  ];
22
23
  const CandidateCap = 64;
23
24
  function matchSpec(name) {
24
- if (name === undefined) {
25
- return undefined;
26
- }
27
25
  const bare = identifier_1.Identifier.getName(name);
28
26
  const ns = identifier_1.Identifier.getNamespace(name);
29
27
  return ChangeFunctions.find(s => s.name === bare && (ns === undefined || ns === s.namespace));
@@ -36,7 +34,7 @@ function applyChange(current, dir) {
36
34
  return isAbsoluteDir(dir) ? files_1.RPath.normalize(dir) : files_1.RPath.join(current, dir);
37
35
  }
38
36
  function guardIn(g, set) {
39
- return set.some(b => b.id === g.id && b.when === g.when);
37
+ return set.some(b => info_1.ControlDependency.same(b, g));
40
38
  }
41
39
  function subsumed(inner, outer) {
42
40
  return inner.every(g => guardIn(g, outer));
@@ -64,15 +62,7 @@ function topoOrder(changes, cfg) {
64
62
  return result;
65
63
  }
66
64
  function enclosingFunction(idMap, id) {
67
- let cursor = idMap?.get(id)?.info.parent;
68
- while (cursor !== undefined) {
69
- const node = idMap?.get(cursor);
70
- if (r_function_definition_1.RFunctionDefinition.is(node)) {
71
- return node.info.id;
72
- }
73
- cursor = node?.info.parent;
74
- }
75
- return undefined;
65
+ return idMap === undefined ? undefined : model_1.RNode.strictlyEnclosingFunction(id, idMap);
76
66
  }
77
67
  function isIterated(cds, idMap) {
78
68
  return cds.some(cd => info_1.ControlDependency.isIterated(cd, idMap));
@@ -140,10 +130,7 @@ function collect(graph, ctx) {
140
130
  // a function's setwd is propagated to its call sites; only a lone unconditional setwd has a site-independent effect
141
131
  for (const [fn, setwds] of byFn.entries()) {
142
132
  const net = setwds.length === 1 && setwds[0].cds.length === 0 && !setwds[0].iterated ? setwds[0].dir : undefined;
143
- for (const [site, edge] of graph.edgesTo(fn)) {
144
- if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
145
- continue;
146
- }
133
+ for (const site of (0, frame_reflection_1.edgeSources)(graph, fn, edge_1.EdgeType.Calls)) {
147
134
  const cds = graph.getVertex(site)?.cds ?? [];
148
135
  out.push({ id: site, dir: net, cds, iterated: isIterated(cds, graph.idMap), enclosedInFunction: enclosingFunction(graph.idMap, site) !== undefined });
149
136
  }
@@ -154,10 +141,15 @@ function collect(graph, ctx) {
154
141
  exports.WorkingDirectory = {
155
142
  collect,
156
143
  resolveAt,
157
- /** reusable `(callId, scriptFile?) => candidate roots`, collecting the changes once for the whole graph */
144
+ applyChange,
145
+ /** reusable `(callId, scriptFile?) => candidate roots`, collecting the changes once for the whole graph; `pinned` when a `setwd` decides them */
158
146
  rootsResolver(graph, cfg, ctx) {
159
147
  const changes = collect(graph, ctx);
160
- return (id, file) => resolveAt(id, graph.getVertex(id)?.cds ?? [], file ? (0, built_in_source_1.platformDirname)(file) : '.', changes, cfg).candidates;
148
+ return (id, file) => {
149
+ const base = file ? (0, built_in_source_1.platformDirname)(file) : '.';
150
+ const roots = resolveAt(id, graph.getVertex(id)?.cds ?? [], base, changes, cfg).candidates;
151
+ return { roots, pinned: roots.length > 0 && (roots.length > 1 || roots[0] !== base) };
152
+ };
161
153
  }
162
154
  };
163
155
  //# sourceMappingURL=resolve-working-directory.js.map
@@ -1,5 +1,9 @@
1
+ import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
2
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
1
3
  import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
2
4
  import { type Lift, Top, type Value, type ValueNumber, type ValueVector } from '../values/r-value';
5
+ /** Whether the operator only combines literals (`1 + 2`), which alone fold while the analysis runs, as a name may still change its value. */
6
+ export declare function onlyLiterals(node: RNode<ParentInformation>): boolean;
3
7
  /**
4
8
  * Converts an RNode to its Value, either directly for a constant or by handing the node to the
5
9
  * {@link BuiltInEvalHandler} its built-in declares, which may resolve further nodes recursively.
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onlyLiterals = onlyLiterals;
3
4
  exports.resolveNode = resolveNode;
4
5
  exports.resolveAsVector = resolveAsVector;
5
6
  exports.resolveAsSeq = resolveAsSeq;
6
7
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
8
  const r_value_1 = require("../values/r-value");
8
9
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
10
+ const r_number_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-number");
11
+ const r_string_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
12
+ const r_logical_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
9
13
  const r_value_2 = require("../../../util/r-value");
10
14
  const logical_constants_1 = require("../values/logical/logical-constants");
11
15
  const r_value_3 = require("../values/r-value");
@@ -17,6 +21,7 @@ const df_helper_1 = require("../../graph/df-helper");
17
21
  const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
18
22
  const resolve_helper_1 = require("../../environments/resolve-helper");
19
23
  const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
24
+ const r_unary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-unary-op");
20
25
  const r_expression_list_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
21
26
  /**
22
27
  * The {@link BuiltInEvalHandler} the given name resolves to in the current environment, just like the
@@ -24,21 +29,27 @@ const r_expression_list_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/
24
29
  * by a user definition or its built-in declares no handler.
25
30
  */
26
31
  function evalHandlerOf(name, environment, ctx) {
27
- const defs = environment ?
28
- resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.BuiltInFunction)
29
- /* without an environment the search path is unknown, so what a package states about the name has its say */
30
- : ctx.env.builtInEnvironment.memory.get(identifier_1.Identifier.getName(name))
31
- ?? ctx.env.statedDefinitionsOf(name);
32
+ /* without an environment the search path is unknown, so what a package states about the name has its say */
33
+ const defs = environment ? resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.BuiltInFunction) : builtInDefinitionsOf(name, ctx);
32
34
  const def = defs?.length === 1 ? defs[0] : undefined;
33
35
  return def?.type === identifier_1.ReferenceType.BuiltInFunction ? def.evalHandler : undefined;
34
36
  }
35
- function foldsThroughBuiltIn(name, ctx) {
36
- const defs = ctx.env.builtInEnvironment.memory.get(identifier_1.Identifier.getName(name))
37
+ function builtInDefinitionsOf(name, ctx) {
38
+ return ctx.env.builtInEnvironment.memory.get(identifier_1.Identifier.getName(name))
37
39
  ?? ctx.env.statedDefinitionsOf(name);
38
- return defs?.some(d => d.type === identifier_1.ReferenceType.BuiltInFunction && d.evalHandler !== undefined) ?? false;
40
+ }
41
+ function foldsThroughBuiltIn(name, ctx) {
42
+ return builtInDefinitionsOf(name, ctx)?.some(d => d.type === identifier_1.ReferenceType.BuiltInFunction && d.evalHandler !== undefined) ?? false;
39
43
  }
40
44
  /** the node types that may fold through a built-in: calls, operators, and the `(`/`{` groupings */
41
45
  const EvalNodeTypes = [type_1.RType.FunctionCall, type_1.RType.BinaryOp, type_1.RType.UnaryOp, type_1.RType.ExpressionList];
46
+ /** Whether the operator only combines literals (`1 + 2`), which alone fold while the analysis runs, as a name may still change its value. */
47
+ function onlyLiterals(node) {
48
+ return r_binary_op_1.RBinaryOp.is(node) ? onlyLiterals(node.lhs) && onlyLiterals(node.rhs)
49
+ : r_unary_op_1.RUnaryOp.is(node) ? onlyLiterals(node.operand)
50
+ : r_expression_list_1.RExpressionList.is(node) && node.grouping !== undefined && node.children.length === 1 ? onlyLiterals(node.children[0])
51
+ : r_number_1.RNumber.is(node) || r_string_1.RString.is(node) || r_logical_1.RLogical.is(node);
52
+ }
42
53
  /**
43
54
  * The name of the built-in the given node folds through, `undefined` if it is no call to one or if it may just
44
55
  * as well resolve to something else (a user redefinition, a conditional one, ...), which must not be folded.
@@ -49,7 +60,8 @@ function evalNameOf({ node, graph, environment, ctx }) {
49
60
  }
50
61
  else if (graph === undefined) {
51
62
  const named = r_expression_list_1.RExpressionList.is(node) ? r_expression_list_1.RExpressionList.groupStart(node)?.content
52
- : r_function_call_1.RFunctionCall.isNamed(node) ? node.functionName.content : undefined;
63
+ : r_function_call_1.RFunctionCall.isNamed(node) ? node.functionName.content
64
+ : (r_binary_op_1.RBinaryOp.is(node) || r_unary_op_1.RUnaryOp.is(node)) && onlyLiterals(node) ? identifier_1.Identifier.make(node.operator) : undefined;
53
65
  return named !== undefined && environment !== undefined && foldsThroughBuiltIn(named, ctx)
54
66
  && resolve_helper_1.Resolve.isBuiltIn(named, environment, identifier_1.ReferenceType.Function) ? named : undefined;
55
67
  }
@@ -114,11 +126,8 @@ function resolveAsSeq(args) {
114
126
  }
115
127
  const leftValue = (0, r_value_2.unliftRValue)(resolve_helper_1.Resolve.toValue(operator.lhs, args));
116
128
  const rightValue = (0, r_value_2.unliftRValue)(resolve_helper_1.Resolve.toValue(operator.rhs, args));
117
- if ((0, r_value_2.isRNumberValue)(leftValue) && (0, r_value_2.isRNumberValue)(rightValue)) {
118
- const sequence = createNumberSequence(leftValue, rightValue);
119
- return sequence === undefined ? r_value_3.Top : (0, vector_constants_1.vectorFrom)(sequence.map(scalar_constants_1.liftScalar));
120
- }
121
- return r_value_3.Top;
129
+ const sequence = (0, r_value_2.isRNumberValue)(leftValue) && (0, r_value_2.isRNumberValue)(rightValue) ? createNumberSequence(leftValue, rightValue) : undefined;
130
+ return sequence === undefined ? r_value_3.Top : (0, vector_constants_1.vectorFrom)(sequence.map(scalar_constants_1.liftScalar));
122
131
  }
123
132
  /**
124
133
  * How many elements of a sequence are worth naming one by one. `1:148066` is a loop bound rather than a set of