@eagleoutice/flowr 2.15.9 → 2.16.0

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 (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -7,15 +7,16 @@ const function_semantics_1 = require("../../../../fn/function-semantics");
7
7
  const control_flow_1 = require("../../../control-flow");
8
8
  const common_1 = require("./common");
9
9
  const edge_1 = require("../../../../graph/edge");
10
+ const logic_1 = require("../../../../../util/logic");
10
11
  const graph_1 = require("../../../../graph/graph");
11
12
  const unknown_side_effect_1 = require("../../../../graph/unknown-side-effect");
12
13
  const vertex_1 = require("../../../../graph/vertex");
13
- const logger_1 = require("../../../../logger");
14
14
  const identifier_1 = require("../../../../environments/identifier");
15
15
  const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
16
16
  const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
17
17
  const r_access_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
18
18
  const r_function_definition_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
19
+ const frame_reflection_1 = require("../../../../fn/frame-reflection");
19
20
  exports.UnnamedFunctionCallPrefix = 'unnamed-fc-';
20
21
  /**
21
22
  * Whether a `$`/`[[` access callee resolved a field to a stored function: a resolved dispatch (`dispatch$foo()`)
@@ -23,17 +24,8 @@ exports.UnnamedFunctionCallPrefix = 'unnamed-fc-';
23
24
  * while an opaque object (`g$greet()` on an untracked `g`) only carries the base `Returns`.
24
25
  */
25
26
  function accessResolvesToField(graph, accessId, accessedId) {
26
- const outgoing = graph.outgoingEdges(accessId);
27
- if (outgoing === undefined) {
28
- return false;
29
- }
30
27
  const base = node_id_1.NodeId.normalize(accessedId);
31
- for (const [target, edge] of outgoing) {
32
- if (node_id_1.NodeId.normalize(target) !== base && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
33
- return true;
34
- }
35
- }
36
- return false;
28
+ return (0, frame_reflection_1.edgeTargets)(graph, accessId, edge_1.EdgeType.Returns).some(target => node_id_1.NodeId.normalize(target) !== base);
37
29
  }
38
30
  /**
39
31
  * Processes an unnamed function call.
@@ -45,62 +37,49 @@ function processUnnamedFunctionCall(functionCall, data) {
45
37
  const functionRootId = functionCall.info.id;
46
38
  const calledRootId = functionCall.calledFunction.info.id;
47
39
  const functionCallName = `${exports.UnnamedFunctionCallPrefix}${functionRootId}`;
48
- logger_1.dataflowLogger.debug(`Using ${functionRootId} as root for the unnamed function call`);
49
- // we know that it reads the toplevel:
50
40
  finalGraph.addEdge(functionRootId, calledRootId, edge_1.EdgeType.Reads);
51
- // keep the defined function
52
41
  finalGraph.mergeWith(calledFunction.graph);
42
+ /* the call is right there and fully resolved, so there is no need to force arguments */
53
43
  const { finalEnv, callArgs, remainingReadInArgs, processedArguments } = (0, common_1.processAllArguments)({
54
44
  functionName: calledFunction,
55
45
  args: functionCall.arguments,
56
46
  data,
57
47
  finalGraph,
58
48
  functionRootId
59
- /* we know the call is right there and fully resolved, there is no need to artificially force arguments as we identify them within the subtree */
60
49
  });
61
50
  finalGraph.addVertex({
62
51
  tag: vertex_1.VertexType.FunctionCall,
63
52
  id: functionRootId,
64
53
  environment: data.environment,
65
54
  name: functionCallName,
66
- /* can never be a direct built-in-call */
67
55
  onlyBuiltin: false,
68
56
  cds: data.cds,
69
- args: callArgs, // same reference
57
+ args: callArgs,
70
58
  origin: [built_in_proc_name_1.BuiltInProcName.Unnamed]
71
59
  }, data.ctx.env.cleanEnv);
72
60
  const cfgEntry = control_flow_1.ControlFlow.inSequence(finalGraph, [calledFunction, ...processedArguments], functionRootId);
73
- /* a jump within an argument is caught here, just like for a named call */
74
- for (const argument of processedArguments) {
75
- for (const exit of argument?.exitPoints ?? []) {
76
- if (exit.type !== 0 /* ExitPointType.Default */) {
77
- finalGraph.addEdge(exit.nodeId, functionRootId, edge_1.EdgeType.FlowEdge);
78
- }
79
- }
80
- }
81
- let inIds = remainingReadInArgs;
82
- inIds.push({ nodeId: functionRootId, name: functionCallName, cds: data.cds, type: identifier_1.ReferenceType.Function });
83
- // if we just call a nested fdef
84
- if (r_function_definition_1.RFunctionDefinition.is(functionCall.calledFunction)) {
85
- function_semantics_1.FunctionSemantics.call.match.onCallAndLink(callArgs, functionCall.calledFunction.parameters, finalGraph);
61
+ /* what the called function forces is up to its body, just like for a named call */
62
+ const argumentExits = processedArguments.flatMap(a => control_flow_1.ControlFlow.promise(finalGraph, a, logic_1.Ternary.Maybe, functionRootId));
63
+ const called = functionCall.calledFunction;
64
+ if (r_function_definition_1.RFunctionDefinition.is(called)) {
65
+ function_semantics_1.FunctionSemantics.call.match.onCallAndLink(callArgs, called.parameters, finalGraph);
86
66
  }
87
- else if (r_access_1.RAccess.is(functionCall.calledFunction) && !accessResolvesToField(finalGraph, calledRootId, functionCall.calledFunction.accessed.info.id)) {
88
- // `obj$method()` whose callee did not resolve to a stored function: reached-but-unknown rather than dropped
67
+ else if (r_access_1.RAccess.is(called) && !accessResolvesToField(finalGraph, calledRootId, called.accessed.info.id)) {
68
+ /* `obj$method()` whose field did not resolve to a stored function is reached but unknown rather than dropped */
89
69
  (0, unknown_side_effect_1.handleUnknownSideEffect)(finalGraph, data.environment, functionRootId);
90
70
  }
91
- // push the called function to the ids:
92
- inIds = inIds.concat(calledFunction.in, calledFunction.unknownReferences);
71
+ const fnRef = { nodeId: functionRootId, name: functionCallName, cds: data.cds, type: identifier_1.ReferenceType.Function };
93
72
  return {
94
73
  unknownReferences: [],
95
- in: inIds,
96
- // we do not keep the argument out as it has been linked by the function
74
+ in: [...remainingReadInArgs, fnRef, ...calledFunction.in, ...calledFunction.unknownReferences],
75
+ /* we do not keep the argument out as it has been linked by the function */
97
76
  out: calledFunction.out,
98
77
  graph: finalGraph,
99
78
  environment: finalEnv,
100
- entryPoint: functionCall.info.id,
79
+ entryPoint: functionRootId,
101
80
  cfgEntry: cfgEntry === functionRootId ? undefined : cfgEntry,
102
81
  cfgExit: functionRootId,
103
- exitPoints: calledFunction.exitPoints,
82
+ exitPoints: calledFunction.exitPoints.concat(argumentExits),
104
83
  hooks: calledFunction.hooks,
105
84
  };
106
85
  }
@@ -2,12 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processFunctionParameter = processFunctionParameter;
4
4
  const processor_1 = require("../../../processor");
5
- const log_1 = require("../../../../util/log");
6
5
  const identifier_1 = require("../../../environments/identifier");
7
6
  const define_1 = require("../../../environments/define");
8
7
  const edge_1 = require("../../../graph/edge");
9
8
  const control_flow_1 = require("../../control-flow");
9
+ const logic_1 = require("../../../../util/logic");
10
10
  const r_function_definition_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
11
+ function definedByDefault(parameter, defaultValue) {
12
+ if (defaultValue === undefined) {
13
+ return [];
14
+ }
15
+ if (r_function_definition_1.RFunctionDefinition.is(parameter.defaultValue)) {
16
+ return [parameter.defaultValue.info.id];
17
+ }
18
+ return defaultValue.in.concat(defaultValue.unknownReferences).map(r => r.nodeId);
19
+ }
11
20
  /**
12
21
  * The dataflow of one function parameter: its name becomes a definition in the function's frame, and its
13
22
  * default value, if it has one, is processed in the same frame so it may read the parameters before it.
@@ -16,52 +25,36 @@ const r_function_definition_1 = require("../../../../r-bridge/lang-4.x/ast/model
16
25
  */
17
26
  function processFunctionParameter(parameter, data) {
18
27
  const name = (0, processor_1.processDataflowFor)(parameter.name, data);
19
- const defaultValue = parameter.defaultValue === undefined ? undefined : (0, processor_1.processDataflowFor)(parameter.defaultValue, data);
28
+ /* a default is a promise the parameter holds, forced where the parameter is first used */
29
+ const defaultValue = parameter.defaultValue === undefined ? undefined : (0, processor_1.processDataflowFor)(parameter.defaultValue, control_flow_1.ControlFlow.withinPromise(data, parameter.name.info.id));
20
30
  const graph = defaultValue === undefined ? name.graph : name.graph.mergeWith(defaultValue.graph);
21
- const writtenNodes = name.unknownReferences.map(n => ({
22
- ...n,
23
- type: identifier_1.ReferenceType.Parameter,
24
- definedAt: parameter.info.id
25
- }));
26
- // keep the default's environment so its escaping (`<<-`) writes are carried on
31
+ const definedBy = definedByDefault(parameter, defaultValue);
32
+ /* keep the default's environment so its escaping (`<<-`) writes are carried on */
27
33
  let environment = defaultValue?.environment ?? name.environment;
28
- for (const writtenNode of writtenNodes) {
29
- const wid = writtenNode.nodeId;
30
- (0, log_1.expensiveTrace)(log_1.log, () => `parameter ${writtenNode.name} (${wid}) is defined at id ${writtenNode.definedAt} with ${defaultValue === undefined ? 'no default value' : ' a default value'}`);
31
- graph.setDefinitionOfVertex(writtenNode, defaultValue?.entryPoint ? [defaultValue?.entryPoint] : []);
32
- environment = (0, define_1.define)(writtenNode, false, environment);
33
- if (defaultValue !== undefined) {
34
- if (r_function_definition_1.RFunctionDefinition.is(parameter.defaultValue)) {
35
- graph.addEdge(wid, parameter.defaultValue.info.id, edge_1.EdgeType.DefinedBy);
36
- }
37
- else {
38
- const definedBy = defaultValue.in.concat(defaultValue.unknownReferences);
39
- for (const node of definedBy) {
40
- graph.addEdge(wid, node.nodeId, edge_1.EdgeType.DefinedBy);
41
- }
42
- }
34
+ for (const reference of name.unknownReferences) {
35
+ const written = { ...reference, type: identifier_1.ReferenceType.Parameter, definedAt: parameter.info.id };
36
+ graph.setDefinitionOfVertex(written, defaultValue === undefined ? [] : [defaultValue.entryPoint]);
37
+ environment = (0, define_1.define)(written, false, environment);
38
+ for (const node of definedBy) {
39
+ graph.addEdge(written.nodeId, node, edge_1.EdgeType.DefinedBy);
43
40
  }
44
41
  }
45
42
  const boundAt = name.entryPoint;
46
43
  if (defaultValue !== undefined) {
47
44
  control_flow_1.ControlFlow.continuesWith(graph, defaultValue, boundAt);
48
- for (const exit of defaultValue.exitPoints) {
49
- /* R only forces a default when the parameter is used, so a jump within one does not cut the binding */
50
- if (exit.type !== 0 /* ExitPointType.Default */) {
51
- graph.addEdge(exit.nodeId, boundAt, edge_1.EdgeType.FlowEdge);
52
- }
53
- }
54
45
  }
46
+ /* R only forces a default when the parameter is used, so a jump within one does not cut the binding */
47
+ const defaultExits = control_flow_1.ControlFlow.promise(graph, defaultValue, logic_1.Ternary.Maybe, boundAt);
55
48
  return {
56
49
  unknownReferences: [],
57
50
  in: defaultValue === undefined ? [] : defaultValue.in.concat(defaultValue.unknownReferences, name.in),
58
51
  out: (defaultValue?.out ?? []).concat(name.out, name.unknownReferences),
59
- graph: graph,
60
- environment: environment,
52
+ graph,
53
+ environment,
61
54
  entryPoint: parameter.info.id,
62
55
  cfgEntry: defaultValue === undefined ? boundAt : control_flow_1.ControlFlow.entryOf(defaultValue),
63
56
  cfgExit: boundAt,
64
- exitPoints: [{ nodeId: parameter.info.id, type: 0 /* ExitPointType.Default */, cds: data.cds }],
57
+ exitPoints: [...defaultExits, { nodeId: parameter.info.id, type: 0 /* ExitPointType.Default */, cds: data.cds }],
65
58
  hooks: []
66
59
  };
67
60
  }
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSymbol = processSymbol;
4
+ const identifier_1 = require("../../environments/identifier");
4
5
  const process_value_1 = require("./process-value");
5
6
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
6
7
  const graph_1 = require("../../graph/graph");
7
8
  const vertex_1 = require("../../graph/vertex");
8
- const identifier_1 = require("../../environments/identifier");
9
+ const built_in_ambient_state_1 = require("./functions/call/built-in/built-in-ambient-state");
9
10
  /**
10
11
  * Process a symbol node in the AST for dataflow analysis.
11
12
  * If the symbol is `NULL` or `NA`, it is processed as a value.
@@ -16,7 +17,7 @@ function processSymbol(symbol, data) {
16
17
  return (0, process_value_1.processValue)(symbol, data);
17
18
  }
18
19
  const sid = symbol.info.id;
19
- return {
20
+ return (0, built_in_ambient_state_1.ambientAccessOfSymbol)({
20
21
  unknownReferences: [{ nodeId: sid, name: symbol.content, cds: data.cds, type: identifier_1.ReferenceType.Unknown }],
21
22
  in: [],
22
23
  out: [],
@@ -29,6 +30,6 @@ function processSymbol(symbol, data) {
29
30
  entryPoint: sid,
30
31
  exitPoints: [{ nodeId: sid, type: 0 /* ExitPointType.Default */, cds: data.cds }],
31
32
  hooks: []
32
- };
33
+ }, symbol, data);
33
34
  }
34
35
  //# sourceMappingURL=process-symbol.js.map
@@ -0,0 +1,26 @@
1
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
+ import { RNode } from '../../r-bridge/lang-4.x/ast/model/model';
4
+ import type { DataflowGraph } from '../graph/graph';
5
+ /**
6
+ * Program order of top-level code outside loops and quotes: it runs once, so its definitions are not there yet for the statements before.
7
+ * @helper dataflow
8
+ * @example
9
+ * ```r
10
+ * f <- function() y
11
+ * f() # runs once, before `y` is defined below
12
+ * y <- 1
13
+ * ```
14
+ */
15
+ export declare const ProgramOrder: {
16
+ readonly name: "ProgramOrder";
17
+ /** The top-level statement holding `id` if the program runs it once, in program order, `undefined` otherwise. */
18
+ readonly runsOnceAt: (this: void, id: NodeId, graph: DataflowGraph) => RNode<ParentInformation> | undefined;
19
+ /** How many top-level statements of the same file after `statement` the top-level definition at `definition` is made, `0` for any other. */
20
+ readonly offset: (this: void, definition: NodeId, statement: RNode<ParentInformation> | undefined, graph: DataflowGraph) => number;
21
+ /**
22
+ * Whether the definition at `definition` is made only after `statement` ran: it sits in a later top-level statement,
23
+ * which holds a nested one too, as the function it is nested in does not exist before.
24
+ */
25
+ readonly definedLater: (this: void, definition: NodeId, statement: RNode<ParentInformation> | undefined, graph: DataflowGraph) => boolean;
26
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProgramOrder = void 0;
4
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
5
+ const info_1 = require("../info");
6
+ /**
7
+ * Program order of top-level code outside loops and quotes: it runs once, so its definitions are not there yet for the statements before.
8
+ * @helper dataflow
9
+ * @example
10
+ * ```r
11
+ * f <- function() y
12
+ * f() # runs once, before `y` is defined below
13
+ * y <- 1
14
+ * ```
15
+ */
16
+ exports.ProgramOrder = {
17
+ name: 'ProgramOrder',
18
+ /** The top-level statement holding `id` if the program runs it once, in program order, `undefined` otherwise. */
19
+ runsOnceAt(id, graph) {
20
+ const idMap = graph.idMap;
21
+ const node = idMap?.get(id);
22
+ if (idMap === undefined || node === undefined || !graph.isRoot(id)
23
+ || graph.getVertex(id)?.cds?.some(cd => info_1.ControlDependency.isIterated(cd, idMap)) || graph.isQuoted(id)) {
24
+ return undefined;
25
+ }
26
+ return model_1.RNode.topLevelStatement(node, idMap);
27
+ },
28
+ /** How many top-level statements of the same file after `statement` the top-level definition at `definition` is made, `0` for any other. */
29
+ offset(definition, statement, graph) {
30
+ return graph.isRoot(definition) ? statementsAfter(definition, statement, graph) : 0;
31
+ },
32
+ /**
33
+ * Whether the definition at `definition` is made only after `statement` ran: it sits in a later top-level statement,
34
+ * which holds a nested one too, as the function it is nested in does not exist before.
35
+ */
36
+ definedLater(definition, statement, graph) {
37
+ return statementsAfter(definition, statement, graph) > 0;
38
+ }
39
+ };
40
+ function statementsAfter(id, statement, graph) {
41
+ const idMap = graph.idMap;
42
+ const node = idMap?.get(id);
43
+ if (idMap === undefined || statement === undefined || node === undefined) {
44
+ return 0;
45
+ }
46
+ const other = model_1.RNode.topLevelStatement(node, idMap);
47
+ return other.info.parent === statement.info.parent ? other.info.index - statement.info.index : 0;
48
+ }
49
+ //# sourceMappingURL=program-order.js.map
@@ -79,7 +79,7 @@ To add a new linting rule, see ${ctx.linkPage('wiki/Create Linting Rules')}.
79
79
  .addFaq('Where do I find *all the helper objects*?', `
80
80
  flowR stores its data as plain values and puts the behavior beside it in a helper object named after the
81
81
  thing it is about (${ctx.link({ name: 'SourceLocation' }, undefined, { type: 'variable' })},
82
- ${ctx.link({ name: 'Vertex' }, undefined, { type: 'variable' })},
82
+ ${ctx.link({ name: 'DfgVertex' }, undefined, { type: 'variable' })},
83
83
  ${ctx.link({ name: 'Identifier' }, undefined, { type: 'variable' })}, ...).
84
84
  The ${ctx.linkPage('wiki/Helper Objects', 'Helper Objects')} wiki page lists every one of them, grouped by what
85
85
  it is about, so you can find the one that answers your question without knowing where it lives.
@@ -120,12 +120,12 @@ sections in the output of \`sessionInfo()\`.
120
120
  .addFaq('How to get *documentation* for a function or package?', `
121
121
  There are a couple of ways to get documentation for a function or package.
122
122
 
123
- 🖥️ Firstly, if you have already installed the package the function originated from you can simply run \`?<package name>::<function name>\` in an R session to print the
123
+ 🖥️ Firstly, if you have already installed the package the function originated from you can run \`?<package name>::<function name>\` in an R session to print the
124
124
  relevant documentation. If you don't know the origin of the package, you can use
125
125
  \`??<function name>\` in an R shell to fuzzy find all documentations containing
126
126
  \`<function name>\` or something similar.
127
127
 
128
- 🌐 Secondly, if you don't have or don't want to install the package you can simply google the fully qualified name of the function. Good sources include [rdrr.io](https://rdrr.io/)
128
+ 🌐 Secondly, if you don't have or don't want to install the package you can google the fully qualified name of the function. Good sources include [rdrr.io](https://rdrr.io/)
129
129
  or [rdocumentation.org](https://rdocumentation.org/). Additionally, the package documentation PDF can also
130
130
  be downloaded directly from [cran](https://cran.r-project.org/).
131
131
  `)
@@ -20,7 +20,6 @@ async function staticSliceExample() {
20
20
  criteria: ['3@x']
21
21
  }
22
22
  ]);
23
- //console.log(result['static-slice']);
24
23
  return result;
25
24
  }
26
25
  /**
@@ -86,7 +85,7 @@ Each ${ctx.link(shell_1.RShell)} controls a new instance of the R&nbsp;interpret
86
85
  make sure to call ${(0, doc_code_1.codeInline)(ctx.linkM(shell_1.RShell, 'close', { codeFont: false, realNameWrapper: 'i' }) + '()')} when you are done.`
87
86
  })}
88
87
 
89
- You can start a new "session" simply by constructing a new object with ${(0, doc_code_1.codeInline)('new ' + ctx.link(shell_1.RShell, { codeFont: false }) + '()')}.
88
+ You can start a new "session" by constructing a new object with ${(0, doc_code_1.codeInline)('new ' + ctx.link(shell_1.RShell, { codeFont: false }) + '()')}.
90
89
 
91
90
  However, there are several options that may be of interest
92
91
  (e.g., to automatically revive the shell in case of errors or to control the name location of the R process on the system).
@@ -35,7 +35,7 @@ function documentAllServerMessages(ctx) {
35
35
  text: async (shell) => {
36
36
  return `
37
37
 
38
- After launching _flowR_, for example, with <code>docker run -it --rm ${doc_docker_1.DockerName} ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'server', false, false)}</code>&nbsp;(🐳️), simply connecting should present you with a \`${message_hello_1.helloMessageDefinition.type}\` message, that amongst others should reveal the versions of&nbsp;_flowR_ and&nbsp;R, using the [semver 2.0](https://semver.org/spec/v2.0.0.html) versioning scheme.
38
+ After launching _flowR_, for example, with <code>docker run -it --rm ${doc_docker_1.DockerName} ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'server', false, false)}</code>&nbsp;(🐳️), connecting should present you with a \`${message_hello_1.helloMessageDefinition.type}\` message, that amongst others should reveal the versions of&nbsp;_flowR_ and&nbsp;R, using the [semver 2.0](https://semver.org/spec/v2.0.0.html) versioning scheme.
39
39
  The message looks like this:
40
40
 
41
41
  ${(0, doc_code_1.codeBlock)('json', await (0, doc_server_message_1.inServerContext)(shell, socket => {
@@ -203,7 +203,7 @@ ${await (0, doc_server_message_1.documentServerMessageResponse)({
203
203
  type: 'response',
204
204
  expectedType: 'response-file-analysis',
205
205
  description: `
206
- Please note, that the base message format is still JSON. Only the individual results get converted.
206
+ The base message format is still JSON, only the individual results get converted.
207
207
  While the context is derived from the \`filename\`, we currently offer no way to customize other parts of the quads
208
208
  (please open a [new issue](${doc_issue_1.NewIssueUrl}) if you require this).
209
209
 
@@ -214,7 +214,7 @@ While the context is derived from the \`filename\`, we currently offer no way to
214
214
  <a id="analysis-format-compact"></a>
215
215
  **Retrieve the Output in a Compacted Form**
216
216
 
217
- The default response is formatted as JSON. But this can get very big quickly.
217
+ The default JSON response can get very big quickly.
218
218
  By specifying \`format: "compact"\`, you can retrieve the results heavily compacted (using [lz-string](https://www.npmjs.com/package/lz-string)).
219
219
  This works with and without the control flow graph as described [above](#analysis-include-cfg).
220
220
 
@@ -236,7 +236,7 @@ ${await (0, doc_server_message_1.documentServerMessageResponse)({
236
236
  type: 'response',
237
237
  expectedType: 'response-file-analysis',
238
238
  description: `
239
- Please note, that the base message format is still JSON. Only the individual results are printed as binary objects.
239
+ The base message format is still JSON, only the individual results are printed as binary objects.
240
240
  `
241
241
  }]
242
242
  })}
@@ -267,7 +267,7 @@ Please note, that the base message format is still JSON. Only the individual res
267
267
 
268
268
  To slice, you have to send a file analysis request first. The \`filetoken\` you assign is of use here as you can re-use it to repeatedly slice the same file.
269
269
  Besides that, you only need to add an array of slicing criteria, using one of the formats described on the [terminology wiki page](${doc_files_1.FlowrWikiBaseRef}/Terminology#slicing-criterion)
270
- (however, instead of using \`;\`, you can simply pass separate array elements).
270
+ (however, instead of using \`;\`, you can pass separate array elements).
271
271
  See the implementation of the request-slice message for more information.
272
272
 
273
273
  Additionally, you may pass \`"noMagicComments": true\` to disable the automatic selection of elements based on magic comments (see below).
@@ -292,7 +292,7 @@ See [above](#message-request-file-analysis) for the general structure of the res
292
292
  `
293
293
  }, {
294
294
  type: 'request',
295
- description: 'Of course, the second slice criterion `2:1` is redundant for the input, as they refer to the same variable. It is only for demonstration purposes.',
295
+ description: 'The second slice criterion `2:1` is redundant for the input, as they refer to the same variable. It is only for demonstration purposes.',
296
296
  message: {
297
297
  type: 'request-slice',
298
298
  id: '2',
@@ -368,7 +368,7 @@ Furthermore, you can set the \`ansi\` field to \`true\` if you are interested in
368
368
  We strongly recommend you to make use of the \`id\` field to link answers with requests as you can theoretically request the execution of multiple scripts at the same time, which then happens in parallel.
369
369
 
370
370
  > [!WARNING]
371
- > There is currently no automatic sandboxing or safeguarding against such requests. They simply execute the respective&nbsp;R code on your machine.
371
+ > There is currently no automatic sandboxing or safeguarding against such requests. They execute the respective&nbsp;R code on your machine.
372
372
  > Please be very careful (and do not use ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'r-session-access')} if you are unsure).
373
373
 
374
374
 
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.capabilitiesAsHtml = capabilitiesAsHtml;
7
7
  const data_1 = require("../r-bridge/data/data");
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const child_process_1 = require("child_process");
9
10
  const path_1 = __importDefault(require("path"));
10
11
  const summary_def_1 = require("../../test/functionality/summary-def");
11
12
  const doc_files_1 = require("./doc-util/doc-files");
@@ -18,17 +19,34 @@ const maxSignatureTests = 3;
18
19
  const preferredContext = 'dataflow';
19
20
  const labelCallRegex = /\blabel\(\s*(['"`])((?:\\.|(?!\1)[^])*?)\1\s*,\s*\[((?:[^[\]]|\[[^[\]]*\])*)\]/g;
20
21
  const quotedStringRegex = /(['"])((?:\\.|(?!\1)[^])*?)\1/g;
22
+ const literalRegex = /(['"`])((?:\\.|(?!\1)[^\\\n])*)\1/g;
23
+ /* suites about the tooling around the analysis, whose tests rarely show what a capability means */
24
+ const toolingSuiteRegex = /\/(project|plugins?|cli|server|repl)\//;
25
+ const genericWords = new Set(['empty', 'single', 'simple', 'basic', 'test', 'next', 'one', 'two', 'all', 'some', 'multiple', 'other', 'foo', 'bar']);
21
26
  const operatorSpreadRegex = /\.{3}\s*OperatorDatabase\[\s*(['"])((?:\\.|(?!\1)[^])*?)\1\s*]\s*\.capabilities/g;
22
27
  function claimedCapabilities(array) {
23
28
  const ids = [...array.matchAll(quotedStringRegex)].map(([, , id]) => id).filter(id => capabilityNames.has(id));
24
29
  for (const [, , operator] of array.matchAll(operatorSpreadRegex)) {
25
30
  ids.push(...operators_1.OperatorDatabase[operator]?.capabilities ?? []);
26
31
  }
27
- return { ids: [...new Set(ids)], opaque: /\.{3}/.test(array.replace(operatorSpreadRegex, '')) };
32
+ return [...new Set(ids)];
33
+ }
34
+ /** a test name as the source spells it, with its escapes (`\\name`) resolved */
35
+ function unescapeSource(name) {
36
+ return name.replace(/\\([^])/g, (_, c) => /[ntr]/.test(c) ? ' ' : c);
37
+ }
38
+ /** the capabilities a `// \@signature <ids>` comment on the line of `index` or the line above names */
39
+ function pinnedCapabilities(content, index) {
40
+ const from = content.lastIndexOf('\n', content.lastIndexOf('\n', index - 1) - 1) + 1;
41
+ const marker = /@signature\b(.*)/.exec(content.slice(from, index));
42
+ return marker === null ? [] : marker[1].split(/[\s,]+/).filter(id => capabilityNames.has(id));
43
+ }
44
+ function lineAt(content, index) {
45
+ return content.slice(0, index).split('\n').length;
28
46
  }
29
47
  function indexTestSources() {
30
48
  const byCapability = new defaultmap_1.DefaultMap(() => []);
31
- const byName = new defaultmap_1.DefaultMap(() => []);
49
+ const literals = new Map();
32
50
  for (const { folder: testSourceFolder } of testSuites) {
33
51
  if (!fs_1.default.existsSync(testSourceFolder)) {
34
52
  continue;
@@ -36,37 +54,55 @@ function indexTestSources() {
36
54
  const files = fs_1.default.readdirSync(testSourceFolder, { recursive: true, encoding: 'utf-8' }).filter(f => f.endsWith('.ts')).sort();
37
55
  for (const file of files) {
38
56
  const content = fs_1.default.readFileSync(path_1.default.join(testSourceFolder, file), 'utf-8');
57
+ const source = `${testSourceFolder}/${file.split(path_1.default.sep).join('/')}`;
58
+ let previousLine = 0;
59
+ for (const match of content.matchAll(literalRegex)) {
60
+ const name = unescapeSource(match[2]);
61
+ const line = lineAt(content, match.index);
62
+ if (!literals.has(name)) {
63
+ literals.set(name, { file: source, line });
64
+ }
65
+ /* a marker pins the name of the test, the first literal of its line, never the code after it */
66
+ if (line !== previousLine) {
67
+ for (const id of pinnedCapabilities(content, match.index)) {
68
+ byCapability.get(id).push({ name, file: source, line, claimed: 0, pinned: true });
69
+ }
70
+ }
71
+ previousLine = line;
72
+ }
39
73
  for (const match of content.matchAll(labelCallRegex)) {
40
- const { ids, opaque } = claimedCapabilities(match[3]);
41
- const test = {
42
- name: match[2],
43
- file: `${testSourceFolder}/${file.split(path_1.default.sep).join('/')}`,
44
- line: content.slice(0, match.index).split('\n').length,
45
- claimed: ids.length,
46
- opaque
47
- };
48
- byName.get(test.name.toLowerCase()).push(test);
74
+ const ids = claimedCapabilities(match[3]);
75
+ const test = { name: unescapeSource(match[2]), file: source, line: lineAt(content, match.index), claimed: ids.length };
49
76
  for (const id of ids) {
50
77
  byCapability.get(id).push(test);
51
78
  }
52
79
  }
53
80
  }
54
81
  }
55
- return { byCapability, byName };
82
+ return { byCapability, literals };
56
83
  }
57
84
  function displayName(name) {
58
- return name.replace(/\$\{[^}]*}/g, '...').trim();
85
+ return name.replace(/\$\{[^}]*}/g, '...').replace(/\s+/g, ' ').trim();
86
+ }
87
+ /** the words of a test name that say something, so `simple x` says nothing and `a call reads its arguments` a lot */
88
+ function telling(name) {
89
+ return displayName(name).toLowerCase().split(/[^a-z0-9]+/).filter(w => w.length > 2 && !genericWords.has(w)).length;
90
+ }
91
+ /** lower is better: a pinned test wins, then a test that claims little and describes what it shows in words */
92
+ function signatureScore(test, preferred) {
93
+ return (test.pinned ? -1000 : 0) + test.claimed * 2
94
+ + (preferred.has(test.name.toLowerCase()) ? 0 : 6)
95
+ + (toolingSuiteRegex.test(test.file) ? 20 : 0)
96
+ + Math.max(0, 4 - telling(test.name)) * 6;
59
97
  }
60
98
  function pickSignatureTests(tests, preferred) {
61
99
  const unique = [...new Map(tests.map(t => [`${t.file}:${t.line}`, t])).values()];
62
- const literal = unique.filter(t => !t.name.includes('${'));
63
- const named = literal.length > 0 ? literal : unique.filter(t => /[A-Za-z0-9]/.test(displayName(t.name)));
100
+ const named = unique.filter(t => /[A-Za-z0-9]/.test(displayName(t.name)));
64
101
  const picked = new Map();
65
- const rank = (t) => preferred.has(t.name.toLowerCase()) ? 0 : 1;
66
- for (const test of named.sort((a, b) => rank(a) - rank(b) || a.claimed - b.claimed || a.name.length - b.name.length || a.file.localeCompare(b.file) || a.line - b.line)) {
67
- const key = displayName(test.name).toLowerCase();
102
+ for (const t of named.sort((a, b) => signatureScore(a, preferred) - signatureScore(b, preferred) || a.name.length - b.name.length || a.file.localeCompare(b.file) || a.line - b.line)) {
103
+ const key = displayName(t.name).toLowerCase();
68
104
  if (!picked.has(key)) {
69
- picked.set(key, test);
105
+ picked.set(key, t);
70
106
  }
71
107
  }
72
108
  return [...picked.values()].slice(0, maxSignatureTests);
@@ -74,18 +110,12 @@ function pickSignatureTests(tests, preferred) {
74
110
  function signatureTestsFor(info, capability) {
75
111
  const recorded = info.info?.get(capability.id) ?? [];
76
112
  const preferred = new Set(recorded.filter(l => l.context.has(preferredContext)).map(l => l.name));
77
- const direct = info.tests.byCapability.get(capability.id);
78
- if (direct.length > 0) {
79
- return pickSignatureTests(direct, preferred);
80
- }
81
- const byName = [];
82
- for (const { name } of recorded) {
83
- const locations = info.tests.byName.get(name);
84
- if (locations.length === 1 && !locations[0].opaque) {
85
- byName.push(locations[0]);
86
- }
87
- }
88
- return pickSignatureTests(byName, preferred);
113
+ /* a test a helper labels is found where its name is written */
114
+ const located = recorded.flatMap(({ name, capabilities }) => {
115
+ const at = info.tests.literals.get(name);
116
+ return at === undefined ? [] : [{ name, claimed: capabilities.size, ...at }];
117
+ });
118
+ return pickSignatureTests([...info.tests.byCapability.get(capability.id), ...located], preferred);
89
119
  }
90
120
  function capabilitySearchUrl(id) {
91
121
  return `https://github.com/search?q=${encodeURIComponent(`repo:${doc_files_1.FlowrGithubGroupName}/flowr "'${id}'"`)}&type=code`;
@@ -295,6 +325,20 @@ function iconLabel(what) {
295
325
  function foldHtml(cssClass, icon, tooltip, label, content, open = false) {
296
326
  return `<details class="${cssClass}"${open ? ' open' : ''}><summary title="${(0, r_highlight_1.escapeHtml)(tooltip)}">${icon}<span>${label}</span></summary>${content}</details>`;
297
327
  }
328
+ let revision;
329
+ /** the commit the page is generated from, so a link to a test line keeps pointing at that line */
330
+ function currentRevision() {
331
+ try {
332
+ revision ??= process.env.GITHUB_SHA ?? (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
333
+ }
334
+ catch {
335
+ revision = 'main';
336
+ }
337
+ return revision;
338
+ }
339
+ function permalinkOf(file, line) {
340
+ return `${(0, doc_files_1.flowrSourceFileUrl)(file).replace('/tree/main/', `/blob/${currentRevision()}/`)}#L${line}`;
341
+ }
298
342
  function signatureTestsHtml(info, capability) {
299
343
  const tests = signatureTestsFor(info, capability);
300
344
  if (tests.length === 0) {
@@ -302,7 +346,7 @@ function signatureTestsHtml(info, capability) {
302
346
  }
303
347
  const links = tests.map(t => {
304
348
  const name = displayName(t.name);
305
- return `<a href="${(0, doc_files_1.flowrSourceFileUrl)(t.file)}#L${t.line}">${(0, r_highlight_1.escapeHtml)(name.length > 72 ? name.slice(0, 69) + '...' : name)}</a>`;
349
+ return `<a href="${permalinkOf(t.file, t.line)}">${(0, r_highlight_1.escapeHtml)(name.length > 72 ? name.slice(0, 69) + '...' : name)}</a>`;
306
350
  });
307
351
  return foldHtml('proof', icon('i-proof'), 'the tests that demonstrate this capability', 'signature tests', `<p>${links.join(', ')}</p>`);
308
352
  }
@@ -394,9 +438,11 @@ async function capabilityHtml(info, capability, extra = false, depth = 0) {
394
438
  const support = capability.supported;
395
439
  const prose = proseOf(info, capability.id);
396
440
  const parts = [
397
- `<div class="head"><a class="anchor" href="#${capability.id}"${iconLabel('link to this capability')}>#</a>`,
441
+ '<div class="head">',
398
442
  support ? `<span class="badge ${support}" title="${support} supported"></span>` : '',
399
- `<span class="name" id="${capability.id}" title="${(0, r_highlight_1.escapeHtml)(capability.id)}">${(0, r_highlight_1.escapeHtml)(capability.name)}</span>`,
443
+ /* after the badge, so the permalink lies on top of the bullet it replaces on hover */
444
+ `<a class="hash" href="#${capability.id}"${iconLabel('link to this capability')}>#</a>`,
445
+ `<a class="name" id="${capability.id}" href="#${capability.id}" title="${(0, r_highlight_1.escapeHtml)(capability.id)}">${(0, r_highlight_1.escapeHtml)(capability.name)}</a>`,
400
446
  versionHtml(capability),
401
447
  testDetails(info, capability),
402
448
  signatureTestsHtml(info, capability),
@@ -29,9 +29,6 @@ export interface QueryDocumentation {
29
29
  readonly name?: string;
30
30
  readonly type: 'virtual' | 'active';
31
31
  readonly shortDescription: string;
32
- readonly functionName: string;
33
- /** Path to the file implementing the query function, the wiki generation will fail if this isn't found */
34
- readonly functionFile: string;
35
32
  readonly buildExplanation: (shell: RShell, ctx: GeneralDocContext) => Promise<string>;
36
33
  }
37
34
  export declare const RegisteredQueries: {