@eagleoutice/flowr 2.2.16 → 2.4.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 (147) hide show
  1. package/README.md +48 -20
  2. package/abstract-interpretation/data-frame/absint-info.d.ts +109 -0
  3. package/abstract-interpretation/data-frame/absint-info.js +31 -0
  4. package/abstract-interpretation/data-frame/absint-visitor.d.ts +58 -0
  5. package/abstract-interpretation/data-frame/absint-visitor.js +171 -0
  6. package/abstract-interpretation/data-frame/domain.d.ts +107 -0
  7. package/abstract-interpretation/data-frame/domain.js +315 -0
  8. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +17 -0
  9. package/abstract-interpretation/data-frame/mappers/access-mapper.js +166 -0
  10. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +117 -0
  11. package/abstract-interpretation/data-frame/mappers/arguments.js +188 -0
  12. package/abstract-interpretation/data-frame/mappers/assignment-mapper.d.ts +20 -0
  13. package/abstract-interpretation/data-frame/mappers/assignment-mapper.js +34 -0
  14. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +261 -0
  15. package/abstract-interpretation/data-frame/mappers/function-mapper.js +1219 -0
  16. package/abstract-interpretation/data-frame/mappers/replacement-mapper.d.ts +12 -0
  17. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +206 -0
  18. package/abstract-interpretation/data-frame/resolve-args.d.ts +42 -0
  19. package/abstract-interpretation/data-frame/resolve-args.js +118 -0
  20. package/abstract-interpretation/data-frame/semantics.d.ts +213 -0
  21. package/abstract-interpretation/data-frame/semantics.js +363 -0
  22. package/abstract-interpretation/data-frame/shape-inference.d.ts +38 -0
  23. package/abstract-interpretation/data-frame/shape-inference.js +111 -0
  24. package/benchmark/slicer.d.ts +15 -1
  25. package/benchmark/slicer.js +137 -0
  26. package/benchmark/stats/print.js +123 -45
  27. package/benchmark/stats/size-of.d.ts +7 -0
  28. package/benchmark/stats/size-of.js +1 -0
  29. package/benchmark/stats/stats.d.ts +30 -1
  30. package/benchmark/stats/stats.js +4 -2
  31. package/benchmark/summarizer/data.d.ts +33 -2
  32. package/benchmark/summarizer/first-phase/input.js +5 -1
  33. package/benchmark/summarizer/first-phase/process.js +47 -1
  34. package/benchmark/summarizer/second-phase/graph.js +1 -1
  35. package/benchmark/summarizer/second-phase/process.js +102 -4
  36. package/cli/benchmark-app.d.ts +2 -0
  37. package/cli/benchmark-app.js +2 -0
  38. package/cli/benchmark-helper-app.d.ts +2 -0
  39. package/cli/benchmark-helper-app.js +10 -3
  40. package/cli/common/options.js +4 -0
  41. package/cli/repl/commands/repl-query.js +1 -1
  42. package/cli/repl/server/connection.js +14 -5
  43. package/config.d.ts +31 -0
  44. package/config.js +21 -1
  45. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -2
  46. package/control-flow/basic-cfg-guided-visitor.js +0 -6
  47. package/control-flow/cfg-simplification.d.ts +6 -0
  48. package/control-flow/cfg-simplification.js +18 -9
  49. package/control-flow/control-flow-graph.d.ts +3 -8
  50. package/control-flow/control-flow-graph.js +5 -6
  51. package/control-flow/dfg-cfg-guided-visitor.js +1 -1
  52. package/control-flow/extract-cfg.d.ts +2 -2
  53. package/control-flow/extract-cfg.js +52 -63
  54. package/control-flow/semantic-cfg-guided-visitor.d.ts +1 -1
  55. package/control-flow/semantic-cfg-guided-visitor.js +1 -1
  56. package/core/steps/all/static-slicing/00-slice.d.ts +7 -1
  57. package/core/steps/all/static-slicing/00-slice.js +9 -3
  58. package/core/steps/pipeline/default-pipelines.d.ts +74 -74
  59. package/dataflow/environments/built-in.d.ts +7 -5
  60. package/dataflow/environments/built-in.js +16 -13
  61. package/dataflow/eval/resolve/alias-tracking.js +2 -2
  62. package/dataflow/eval/resolve/resolve.d.ts +53 -9
  63. package/dataflow/eval/resolve/resolve.js +132 -38
  64. package/dataflow/graph/dataflowgraph-builder.js +2 -2
  65. package/dataflow/graph/graph.js +1 -1
  66. package/dataflow/graph/invert-dfg.d.ts +2 -0
  67. package/dataflow/graph/invert-dfg.js +17 -0
  68. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -0
  69. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +4 -0
  70. package/documentation/doc-util/doc-query.js +11 -1
  71. package/documentation/doc-util/doc-search.js +2 -2
  72. package/documentation/print-cfg-wiki.js +3 -4
  73. package/documentation/print-core-wiki.js +2 -2
  74. package/documentation/print-dataflow-graph-wiki.js +7 -0
  75. package/documentation/print-faq-wiki.js +4 -0
  76. package/documentation/print-interface-wiki.js +11 -0
  77. package/documentation/print-linter-wiki.js +36 -4
  78. package/documentation/print-linting-and-testing-wiki.js +13 -1
  79. package/documentation/print-onboarding-wiki.js +4 -0
  80. package/documentation/print-query-wiki.js +29 -3
  81. package/linter/linter-executor.js +1 -2
  82. package/linter/linter-format.d.ts +26 -4
  83. package/linter/linter-format.js +25 -6
  84. package/linter/linter-rules.d.ts +63 -12
  85. package/linter/linter-rules.js +5 -1
  86. package/linter/rules/absolute-path.d.ts +4 -7
  87. package/linter/rules/absolute-path.js +9 -6
  88. package/linter/rules/dataframe-access-validation.d.ts +55 -0
  89. package/linter/rules/dataframe-access-validation.js +118 -0
  90. package/linter/rules/dead-code.d.ts +43 -0
  91. package/linter/rules/dead-code.js +50 -0
  92. package/linter/rules/deprecated-functions.d.ts +3 -2
  93. package/linter/rules/deprecated-functions.js +3 -1
  94. package/linter/rules/file-path-validity.d.ts +4 -4
  95. package/linter/rules/file-path-validity.js +8 -6
  96. package/linter/rules/naming-convention.d.ts +5 -4
  97. package/linter/rules/naming-convention.js +8 -2
  98. package/linter/rules/seeded-randomness.d.ts +4 -3
  99. package/linter/rules/seeded-randomness.js +3 -1
  100. package/linter/rules/unused-definition.d.ts +2 -0
  101. package/linter/rules/unused-definition.js +3 -1
  102. package/package.json +2 -2
  103. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -1
  104. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -0
  105. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  106. package/queries/catalog/df-shape-query/df-shape-query-executor.d.ts +3 -0
  107. package/queries/catalog/df-shape-query/df-shape-query-executor.js +46 -0
  108. package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +72 -0
  109. package/queries/catalog/df-shape-query/df-shape-query-format.js +31 -0
  110. package/queries/catalog/linter-query/linter-query-format.js +1 -1
  111. package/queries/catalog/location-map-query/location-map-query-executor.js +7 -5
  112. package/queries/catalog/location-map-query/location-map-query-format.d.ts +3 -0
  113. package/queries/catalog/location-map-query/location-map-query-format.js +1 -0
  114. package/queries/catalog/search-query/search-query-executor.js +1 -1
  115. package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -1
  116. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +3 -0
  117. package/queries/catalog/static-slice-query/static-slice-query-format.js +3 -1
  118. package/queries/query-print.d.ts +1 -1
  119. package/queries/query-print.js +0 -1
  120. package/queries/query.d.ts +77 -6
  121. package/queries/query.js +26 -11
  122. package/search/flowr-search-builder.d.ts +6 -6
  123. package/search/flowr-search-executor.d.ts +2 -2
  124. package/search/flowr-search-executor.js +1 -1
  125. package/search/flowr-search.d.ts +13 -8
  126. package/search/flowr-search.js +21 -0
  127. package/search/search-executor/search-enrichers.d.ts +87 -20
  128. package/search/search-executor/search-enrichers.js +44 -5
  129. package/search/search-executor/search-generators.d.ts +4 -4
  130. package/search/search-executor/search-generators.js +12 -7
  131. package/search/search-executor/search-mappers.js +3 -2
  132. package/search/search-executor/search-transformer.d.ts +3 -3
  133. package/search/search-executor/search-transformer.js +2 -2
  134. package/slicing/static/static-slicer.d.ts +4 -2
  135. package/slicing/static/static-slicer.js +10 -4
  136. package/util/collections/arrays.d.ts +2 -0
  137. package/util/collections/arrays.js +9 -0
  138. package/util/files.d.ts +8 -2
  139. package/util/files.js +22 -4
  140. package/util/mermaid/dfg.js +4 -2
  141. package/util/r-value.d.ts +23 -0
  142. package/util/r-value.js +113 -0
  143. package/util/range.d.ts +1 -0
  144. package/util/range.js +5 -1
  145. package/util/version.js +1 -1
  146. package/util/cfg/cfg.d.ts +0 -0
  147. package/util/cfg/cfg.js +0 -2
package/README.md CHANGED
@@ -24,7 +24,7 @@ It offers a wide variety of features, for example:
24
24
 
25
25
  ```shell
26
26
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
27
- flowR repl using flowR v2.2.15, R v4.5.0 (r-shell engine)
27
+ flowR repl using flowR v2.3.0, R v4.5.0 (r-shell engine)
28
28
  R> :query @linter "read.csv(\"/root/x.txt\")"
29
29
  ```
30
30
 
@@ -33,24 +33,28 @@ It offers a wide variety of features, for example:
33
33
 
34
34
 
35
35
  ```text
36
- Query: linter (2 ms)
36
+ Query: linter (3 ms)
37
37
  ╰ **Deprecated Functions** (deprecated-functions):
38
38
  ╰ _Metadata_: <code>{"totalDeprecatedCalls":0,"totalDeprecatedFunctionDefinitions":0,"searchTimeMs":0,"processTimeMs":0}</code>
39
39
  ╰ **File Path Validity** (file-path-validity):
40
- definitely:
40
+ certain:
41
41
  ╰ Path `/root/x.txt` at 1.1-23
42
42
  ╰ _Metadata_: <code>{"totalReads":1,"totalUnknown":0,"totalWritesBeforeAlways":0,"totalValid":0,"searchTimeMs":1,"processTimeMs":0}</code>
43
43
  ╰ **Seeded Randomness** (seeded-randomness):
44
44
  ╰ _Metadata_: <code>{"consumerCalls":0,"callsWithFunctionProducers":0,"callsWithAssignmentProducers":0,"callsWithNonConstantProducers":0,"searchTimeMs":0,"processTimeMs":0}</code>
45
45
  ╰ **Absolute Paths** (absolute-file-paths):
46
- definitely:
46
+ certain:
47
47
  ╰ Path `/root/x.txt` at 1.1-23
48
48
  ╰ _Metadata_: <code>{"totalConsidered":1,"totalUnknown":0,"searchTimeMs":1,"processTimeMs":0}</code>
49
49
  ╰ **Unused Definitions** (unused-definitions):
50
50
  ╰ _Metadata_: <code>{"totalConsidered":0,"searchTimeMs":0,"processTimeMs":0}</code>
51
51
  ╰ **Naming Convention** (naming-convention):
52
52
  ╰ _Metadata_: <code>{"numMatches":0,"numBreak":0,"searchTimeMs":0,"processTimeMs":0}</code>
53
- All queries together required ≈2 ms (1ms accuracy, total 7 ms)
53
+ **Dataframe Access Validation** (dataframe-access-validation):
54
+ ╰ _Metadata_: <code>{"numOperations":0,"numAccesses":0,"totalAccessed":0,"searchTimeMs":0,"processTimeMs":0}</code>
55
+ ╰ **Dead Code** (dead-code):
56
+ ╰ _Metadata_: <code>{"consideredNodes":5,"searchTimeMs":1,"processTimeMs":0}</code>
57
+ All queries together required ≈3 ms (1ms accuracy, total 9 ms)
54
58
  ```
55
59
 
56
60
 
@@ -66,32 +70,38 @@ It offers a wide variety of features, for example:
66
70
  ```
67
71
 
68
72
 
73
+ (This query can be shortened to `@linter` when used within the REPL command <span title="Description (Repl Command): Query the given R code, start with 'file://' to indicate a file. The query is to be a valid query in json format (use 'help' to get more information).">`:query`</span>).
74
+
69
75
 
70
76
 
71
77
  _Results (prettified and summarized):_
72
78
 
73
- Query: **linter** (10 ms)\
79
+ Query: **linter** (14 ms)\
74
80
  &nbsp;&nbsp;&nbsp;╰ **Deprecated Functions** (deprecated-functions):\
75
81
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"totalDeprecatedCalls":0,"totalDeprecatedFunctionDefinitions":0,"searchTimeMs":2,"processTimeMs":0}</code>\
76
82
  &nbsp;&nbsp;&nbsp;╰ **File Path Validity** (file-path-validity):\
77
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ definitely:\
83
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ certain:\
78
84
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ Path `/root/x.txt` at 1.1-23\
79
85
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"totalReads":1,"totalUnknown":0,"totalWritesBeforeAlways":0,"totalValid":0,"searchTimeMs":4,"processTimeMs":1}</code>\
80
86
  &nbsp;&nbsp;&nbsp;╰ **Seeded Randomness** (seeded-randomness):\
81
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"consumerCalls":0,"callsWithFunctionProducers":0,"callsWithAssignmentProducers":0,"callsWithNonConstantProducers":0,"searchTimeMs":0,"processTimeMs":0}</code>\
87
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"consumerCalls":0,"callsWithFunctionProducers":0,"callsWithAssignmentProducers":0,"callsWithNonConstantProducers":0,"searchTimeMs":0,"processTimeMs":1}</code>\
82
88
  &nbsp;&nbsp;&nbsp;╰ **Absolute Paths** (absolute-file-paths):\
83
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ definitely:\
89
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ certain:\
84
90
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ Path `/root/x.txt` at 1.1-23\
85
91
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"totalConsidered":1,"totalUnknown":0,"searchTimeMs":1,"processTimeMs":1}</code>\
86
92
  &nbsp;&nbsp;&nbsp;╰ **Unused Definitions** (unused-definitions):\
87
93
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"totalConsidered":0,"searchTimeMs":0,"processTimeMs":0}</code>\
88
94
  &nbsp;&nbsp;&nbsp;╰ **Naming Convention** (naming-convention):\
89
95
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"numMatches":0,"numBreak":0,"searchTimeMs":0,"processTimeMs":0}</code>\
90
- _All queries together required ≈10 ms (1ms accuracy, total 208 ms)_
96
+ &nbsp;&nbsp;&nbsp;╰ **Dataframe Access Validation** (dataframe-access-validation):\
97
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"numOperations":0,"numAccesses":0,"totalAccessed":0,"searchTimeMs":0,"processTimeMs":2}</code>\
98
+ &nbsp;&nbsp;&nbsp;╰ **Dead Code** (dead-code):\
99
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;╰ _Metadata_: <code>{"consideredNodes":5,"searchTimeMs":0,"processTimeMs":0}</code>\
100
+ _All queries together required ≈14 ms (1ms accuracy, total 214 ms)_
91
101
 
92
102
  <details> <summary style="color:gray">Show Detailed Results as Json</summary>
93
103
 
94
- The analysis required _207.6 ms_ (including parsing and normalization and the query) within the generation environment.
104
+ The analysis required _213.8 ms_ (including parsing and normalization and the query) within the generation environment.
95
105
 
96
106
  In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
97
107
  Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
@@ -122,7 +132,7 @@ It offers a wide variety of features, for example:
122
132
  23
123
133
  ],
124
134
  "filePath": "/root/x.txt",
125
- "certainty": "definitely"
135
+ "certainty": "certain"
126
136
  }
127
137
  ],
128
138
  ".meta": {
@@ -142,13 +152,13 @@ It offers a wide variety of features, for example:
142
152
  "callsWithAssignmentProducers": 0,
143
153
  "callsWithNonConstantProducers": 0,
144
154
  "searchTimeMs": 0,
145
- "processTimeMs": 0
155
+ "processTimeMs": 1
146
156
  }
147
157
  },
148
158
  "absolute-file-paths": {
149
159
  "results": [
150
160
  {
151
- "certainty": "definitely",
161
+ "certainty": "certain",
152
162
  "filePath": "/root/x.txt",
153
163
  "range": [
154
164
  1,
@@ -181,14 +191,32 @@ It offers a wide variety of features, for example:
181
191
  "searchTimeMs": 0,
182
192
  "processTimeMs": 0
183
193
  }
194
+ },
195
+ "dataframe-access-validation": {
196
+ "results": [],
197
+ ".meta": {
198
+ "numOperations": 0,
199
+ "numAccesses": 0,
200
+ "totalAccessed": 0,
201
+ "searchTimeMs": 0,
202
+ "processTimeMs": 2
203
+ }
204
+ },
205
+ "dead-code": {
206
+ "results": [],
207
+ ".meta": {
208
+ "consideredNodes": 5,
209
+ "searchTimeMs": 0,
210
+ "processTimeMs": 0
211
+ }
184
212
  }
185
213
  },
186
214
  ".meta": {
187
- "timing": 10
215
+ "timing": 14
188
216
  }
189
217
  },
190
218
  ".meta": {
191
- "timing": 10
219
+ "timing": 14
192
220
  }
193
221
  }
194
222
  ```
@@ -255,7 +283,7 @@ It offers a wide variety of features, for example:
255
283
 
256
284
  ```shell
257
285
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
258
- flowR repl using flowR v2.2.15, R v4.5.0 (r-shell engine)
286
+ flowR repl using flowR v2.3.0, R v4.5.0 (r-shell engine)
259
287
  R> :slicer test/testfiles/example.R --criterion "11@sum"
260
288
  ```
261
289
 
@@ -302,7 +330,7 @@ It offers a wide variety of features, for example:
302
330
 
303
331
 
304
332
  * 🚀 **fast data- and control-flow graphs**\
305
- Within just <i><span title="This measurement is automatically fetched from the latest benchmark!">136.2 ms</span></i> (as of Jun 2, 2025),
333
+ Within just <i><span title="This measurement is automatically fetched from the latest benchmark!">136.8 ms</span></i> (as of Jul 21, 2025),
306
334
  _flowR_ can analyze the data- and control-flow of the average real-world R script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
307
335
  and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph) for more details on the dataflow graph.
308
336
 
@@ -338,7 +366,7 @@ It offers a wide variety of features, for example:
338
366
 
339
367
  ```shell
340
368
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
341
- flowR repl using flowR v2.2.15, R v4.5.0 (r-shell engine)
369
+ flowR repl using flowR v2.3.0, R v4.5.0 (r-shell engine)
342
370
  R> :dataflow* test/testfiles/example.R
343
371
  ```
344
372
 
@@ -639,7 +667,7 @@ It offers a wide variety of features, for example:
639
667
  ```
640
668
 
641
669
 
642
- (The analysis required _13.9 ms_ (including parse and normalize, using the [r-shell](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment.)
670
+ (The analysis required _13.8 ms_ (including parse and normalize, using the [r-shell](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment.)
643
671
 
644
672
 
645
673
 
@@ -0,0 +1,109 @@
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';
3
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import type { DataFrameStateDomain } from './domain';
5
+ import type { ConstraintType, DataFrameOperationArgs, DataFrameOperationName, DataFrameOperationOptions } from './semantics';
6
+ /**
7
+ * An abstract data frame operation without additional options.
8
+ * - `operation` contains the type of the abstract operation (see {@link DataFrameOperationName})
9
+ * - `operand` contains the ID of the data frame operand of the operation (may be `undefined`)
10
+ * - `...args` contains the arguments of the abstract operation (see {@link DataFrameOperationArgs})
11
+ */
12
+ export type DataFrameOperationType<OperationName extends DataFrameOperationName = DataFrameOperationName> = {
13
+ [Name in OperationName]: {
14
+ operation: Name;
15
+ operand: NodeId | undefined;
16
+ } & DataFrameOperationArgs<Name>;
17
+ }[OperationName];
18
+ /**
19
+ * An abstract data frame operation.
20
+ * - `operation` contains the type of the abstract operation (see {@link DataFrameOperationName})
21
+ * - `operand` contains the ID of the data frame operand of the operation (may be `undefined`)
22
+ * - `type` optionally contains the constraint type to overwrite the default type of the operation (see {@link ConstraintType})
23
+ * - `options` optionally contains additional options for the abstract operation (see {@link DataFrameOperationOptions})
24
+ * - `...args` contains the arguments of the abstract operation (see {@link DataFrameOperationArgs})
25
+ */
26
+ export type DataFrameOperation<OperationName extends DataFrameOperationName = DataFrameOperationName> = {
27
+ [Name in OperationName]: {
28
+ operation: Name;
29
+ operand: NodeId | undefined;
30
+ type?: ConstraintType;
31
+ options?: DataFrameOperationOptions<Name>;
32
+ } & DataFrameOperationArgs<Name>;
33
+ }[OperationName];
34
+ /**
35
+ * Represents the base data frame information stored in the abstract interpretation info of an AST node.
36
+ * - `type` optionally defines the type of the extra information stored in the data frame info
37
+ * - `domain` contains the abstract data frame shape state of the node
38
+ * This may not be present if the data frame shape inference has not been executed yet or the program contains no data frames
39
+ */
40
+ interface DataFrameInfoBase {
41
+ type?: string;
42
+ domain?: DataFrameStateDomain;
43
+ }
44
+ /** Enum to mark nodes during the data frame shape inference */
45
+ export declare enum DataFrameInfoMarker {
46
+ /** Marks the target symbol of assignments as "unassigned" until the assigned expression is evaluated */
47
+ Unassigned = "unassigned"
48
+ }
49
+ /**
50
+ * Represents the data frame information for a node without extra data frame information,
51
+ * i.e. for all nodes that do not represent a data frame assignment or data frame operation (this is the default).
52
+ *
53
+ * The `marker` can be used to mark nodes during the data frame shape inference.
54
+ */
55
+ interface DataFrameEmptyInfo extends DataFrameInfoBase {
56
+ type?: never;
57
+ marker?: DataFrameInfoMarker;
58
+ }
59
+ /**
60
+ * Represents the data frame information for a data frame assignment with a target identifier (symbol/string) and an assigned expression.
61
+ * This is used during data frame shape inference to mark assignments of data frame expressions to an identifier.
62
+ *
63
+ * Use {@link hasDataFrameAssignmentInfo} to check whether an AST node has attached data frame assignment information.
64
+ */
65
+ export interface DataFrameAssignmentInfo extends DataFrameInfoBase {
66
+ type: 'assignment';
67
+ identifier: NodeId;
68
+ expression: NodeId;
69
+ }
70
+ /**
71
+ * Represents the data frame information for a data frame function/operation with mapped abstract operations.
72
+ * This is used during data frame shape inference to store the abstract operations a data frame function/operation is mapped to.
73
+ *
74
+ * The order of the abstract operations is the order in which their semantics are applied (for example, access operations are typically before other operations in the list).
75
+ * Moreover, abstract operations that take the result of previous abstract operation as data frame operand must have the `operand` set to `undefined`.
76
+ *
77
+ * Use {@link hasDataFrameExpressionInfo} to check whether an AST node has attached data frame expression information.
78
+ */
79
+ export interface DataFrameExpressionInfo extends DataFrameInfoBase {
80
+ type: 'expression';
81
+ operations: DataFrameOperation[];
82
+ }
83
+ /**
84
+ * Represents the data frame shape inference information stored in the abstract interpretation info of AST nodes.
85
+ */
86
+ export type DataFrameInfo = DataFrameEmptyInfo | DataFrameAssignmentInfo | DataFrameExpressionInfo;
87
+ /**
88
+ * Represents the abstract interpretation information attached to AST nodes.
89
+ */
90
+ export interface AbstractInterpretationInfo {
91
+ dataFrame?: DataFrameInfo;
92
+ }
93
+ /**
94
+ * Checks whether an AST node has attached data frame assignment information.
95
+ */
96
+ export declare function hasDataFrameAssignmentInfo<OtherInfo>(node: RNode<OtherInfo & ParentInformation & AbstractInterpretationInfo>): node is RNode<OtherInfo & ParentInformation & AbstractInterpretationInfo & {
97
+ dataFrame: DataFrameAssignmentInfo;
98
+ }>;
99
+ /**
100
+ * Checks whether an AST node has attached data frame expression information.
101
+ */
102
+ export declare function hasDataFrameExpressionInfo<OtherInfo>(node: RNode<OtherInfo & ParentInformation & AbstractInterpretationInfo>): node is RNode<OtherInfo & ParentInformation & AbstractInterpretationInfo & {
103
+ dataFrame: DataFrameExpressionInfo;
104
+ }>;
105
+ /**
106
+ * Checks whether an AST node has an attached data frame info marker.
107
+ */
108
+ export declare function hasDataFrameInfoMarker<OtherInfo>(node: RNode<OtherInfo & ParentInformation & AbstractInterpretationInfo>, marker: DataFrameInfoMarker): boolean;
109
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataFrameInfoMarker = void 0;
4
+ exports.hasDataFrameAssignmentInfo = hasDataFrameAssignmentInfo;
5
+ exports.hasDataFrameExpressionInfo = hasDataFrameExpressionInfo;
6
+ exports.hasDataFrameInfoMarker = hasDataFrameInfoMarker;
7
+ /** Enum to mark nodes during the data frame shape inference */
8
+ var DataFrameInfoMarker;
9
+ (function (DataFrameInfoMarker) {
10
+ /** Marks the target symbol of assignments as "unassigned" until the assigned expression is evaluated */
11
+ DataFrameInfoMarker["Unassigned"] = "unassigned";
12
+ })(DataFrameInfoMarker || (exports.DataFrameInfoMarker = DataFrameInfoMarker = {}));
13
+ /**
14
+ * Checks whether an AST node has attached data frame assignment information.
15
+ */
16
+ function hasDataFrameAssignmentInfo(node) {
17
+ return node.info.dataFrame?.type === 'assignment';
18
+ }
19
+ /**
20
+ * Checks whether an AST node has attached data frame expression information.
21
+ */
22
+ function hasDataFrameExpressionInfo(node) {
23
+ return node.info.dataFrame?.type === 'expression';
24
+ }
25
+ /**
26
+ * Checks whether an AST node has an attached data frame info marker.
27
+ */
28
+ function hasDataFrameInfoMarker(node, marker) {
29
+ return node.info.dataFrame?.type === undefined && node.info.dataFrame?.marker === marker;
30
+ }
31
+ //# sourceMappingURL=absint-info.js.map
@@ -0,0 +1,58 @@
1
+ import type { CfgBasicBlockVertex, CfgSimpleVertex, ControlFlowInformation } from '../../control-flow/control-flow-graph';
2
+ import type { SemanticCfgGuidedVisitorConfiguration } from '../../control-flow/semantic-cfg-guided-visitor';
3
+ import { SemanticCfgGuidedVisitor } from '../../control-flow/semantic-cfg-guided-visitor';
4
+ import type { DataflowGraph } from '../../dataflow/graph/graph';
5
+ import type { DataflowGraphVertexFunctionCall, DataflowGraphVertexVariableDefinition } from '../../dataflow/graph/vertex';
6
+ import type { NoInfo } from '../../r-bridge/lang-4.x/ast/model/model';
7
+ import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
8
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
9
+ import { type AbstractInterpretationInfo } from './absint-info';
10
+ export type DataFrameShapeInferenceVisitorConfiguration<OtherInfo = NoInfo, ControlFlow extends ControlFlowInformation = ControlFlowInformation, Ast extends NormalizedAst<OtherInfo & AbstractInterpretationInfo> = NormalizedAst<OtherInfo & AbstractInterpretationInfo>, Dfg extends DataflowGraph = DataflowGraph> = Omit<SemanticCfgGuidedVisitorConfiguration<OtherInfo & AbstractInterpretationInfo, ControlFlow, Ast, Dfg>, 'defaultVisitingOrder' | 'defaultVisitingType'>;
11
+ /**
12
+ * The control flow graph visitor to infer the shape of data frames using abstract interpretation
13
+ */
14
+ export declare class DataFrameShapeInferenceVisitor<OtherInfo = NoInfo, ControlFlow extends ControlFlowInformation = ControlFlowInformation, Ast extends NormalizedAst<OtherInfo & AbstractInterpretationInfo> = NormalizedAst<OtherInfo & AbstractInterpretationInfo>, Dfg extends DataflowGraph = DataflowGraph, Config extends DataFrameShapeInferenceVisitorConfiguration<OtherInfo, ControlFlow, Ast, Dfg> = DataFrameShapeInferenceVisitorConfiguration<OtherInfo, ControlFlow, Ast, Dfg>> extends SemanticCfgGuidedVisitor<OtherInfo & AbstractInterpretationInfo, ControlFlow, Ast, Dfg, Config & {
15
+ defaultVisitingOrder: 'forward';
16
+ defaultVisitingType: 'exit';
17
+ }> {
18
+ /**
19
+ * The old domain of an AST node before processing the node retrieved from the attached {@link AbstractInterpretationInfo}.
20
+ * This is used to check whether the state has changed and successors should be visited again, and is also required for widening.
21
+ */
22
+ private oldDomain;
23
+ /**
24
+ * The new domain of an AST node during and after processing the node.
25
+ * This information is stored in the {@link AbstractInterpretationInfo} afterwards.
26
+ */
27
+ private newDomain;
28
+ constructor(config: Config);
29
+ protected visitNode(nodeId: NodeId): boolean;
30
+ protected visitDataflowNode(vertex: Exclude<CfgSimpleVertex, CfgBasicBlockVertex>): void;
31
+ protected onVariableDefinition({ vertex }: {
32
+ vertex: DataflowGraphVertexVariableDefinition;
33
+ }): void;
34
+ protected onAssignmentCall({ call, target, source }: {
35
+ call: DataflowGraphVertexFunctionCall;
36
+ target?: NodeId;
37
+ source?: NodeId;
38
+ }): void;
39
+ protected onAccessCall({ call }: {
40
+ call: DataflowGraphVertexFunctionCall;
41
+ }): void;
42
+ protected onDefaultFunctionCall({ call }: {
43
+ call: DataflowGraphVertexFunctionCall;
44
+ }): void;
45
+ protected onReplacementCall({ call, source, target }: {
46
+ call: DataflowGraphVertexFunctionCall;
47
+ source: NodeId | undefined;
48
+ target: NodeId | undefined;
49
+ }): void;
50
+ private applyDataFrameAssignment;
51
+ private applyDataFrameExpression;
52
+ /** We only process vertices of leaf nodes and exit vertices (no entry nodes of complex nodes) */
53
+ private shouldSkipVertex;
54
+ /** Get all AST nodes for the predecessor vertices that are leaf nodes and exit vertices */
55
+ private getPredecessorNodes;
56
+ private shouldWiden;
57
+ private clearUnassignedInfo;
58
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataFrameShapeInferenceVisitor = void 0;
4
+ const control_flow_graph_1 = require("../../control-flow/control-flow-graph");
5
+ const semantic_cfg_guided_visitor_1 = require("../../control-flow/semantic-cfg-guided-visitor");
6
+ const assert_1 = require("../../util/assert");
7
+ const absint_info_1 = require("./absint-info");
8
+ const domain_1 = require("./domain");
9
+ const access_mapper_1 = require("./mappers/access-mapper");
10
+ const assignment_mapper_1 = require("./mappers/assignment-mapper");
11
+ const function_mapper_1 = require("./mappers/function-mapper");
12
+ const replacement_mapper_1 = require("./mappers/replacement-mapper");
13
+ const semantics_1 = require("./semantics");
14
+ const shape_inference_1 = require("./shape-inference");
15
+ /**
16
+ * The control flow graph visitor to infer the shape of data frames using abstract interpretation
17
+ */
18
+ class DataFrameShapeInferenceVisitor extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
19
+ /**
20
+ * The old domain of an AST node before processing the node retrieved from the attached {@link AbstractInterpretationInfo}.
21
+ * This is used to check whether the state has changed and successors should be visited again, and is also required for widening.
22
+ */
23
+ oldDomain = new Map();
24
+ /**
25
+ * The new domain of an AST node during and after processing the node.
26
+ * This information is stored in the {@link AbstractInterpretationInfo} afterwards.
27
+ */
28
+ newDomain = new Map();
29
+ constructor(config) {
30
+ super({ ...config, defaultVisitingOrder: 'forward', defaultVisitingType: 'exit' });
31
+ }
32
+ visitNode(nodeId) {
33
+ const vertex = this.getCfgVertex(nodeId);
34
+ // skip vertices representing entries of complex nodes
35
+ if (vertex === undefined || this.shouldSkipVertex(vertex)) {
36
+ return true;
37
+ }
38
+ const predecessors = this.getPredecessorNodes(vertex.id);
39
+ this.newDomain = (0, domain_1.joinDataFrameStates)(...predecessors.map(node => node.info.dataFrame?.domain ?? new Map()));
40
+ this.onVisitNode(nodeId);
41
+ const visitedCount = this.visited.get(vertex.id) ?? 0;
42
+ this.visited.set(vertex.id, visitedCount + 1);
43
+ // only continue visiting if the node has not been visited before or the data frame value of the node changed
44
+ return visitedCount === 0 || !(0, domain_1.equalDataFrameState)(this.oldDomain, this.newDomain);
45
+ }
46
+ visitDataflowNode(vertex) {
47
+ const node = this.getNormalizedAst((0, control_flow_graph_1.getVertexRootId)(vertex));
48
+ if (node === undefined) {
49
+ return;
50
+ }
51
+ this.oldDomain = node.info.dataFrame?.domain ?? new Map();
52
+ super.visitDataflowNode(vertex);
53
+ if (this.shouldWiden(vertex)) {
54
+ this.newDomain = (0, domain_1.wideningDataFrameStates)(this.oldDomain, this.newDomain);
55
+ }
56
+ node.info.dataFrame ??= {};
57
+ node.info.dataFrame.domain = this.newDomain;
58
+ }
59
+ onVariableDefinition({ vertex }) {
60
+ const node = this.getNormalizedAst(vertex.id);
61
+ if (node !== undefined) {
62
+ // mark variable definitions as "unassigned", as the evaluation of the assigned expression is delayed until processing the assignment
63
+ node.info.dataFrame ??= { marker: absint_info_1.DataFrameInfoMarker.Unassigned };
64
+ }
65
+ }
66
+ onAssignmentCall({ call, target, source }) {
67
+ const node = this.getNormalizedAst(call.id);
68
+ const targetNode = this.getNormalizedAst(target);
69
+ const sourceNode = this.getNormalizedAst(source);
70
+ if (node !== undefined && (0, assignment_mapper_1.isAssignmentTarget)(targetNode) && sourceNode !== undefined) {
71
+ node.info.dataFrame = (0, assignment_mapper_1.mapDataFrameVariableAssignment)(targetNode, sourceNode, this.config.dfg);
72
+ this.applyDataFrameAssignment(node);
73
+ this.clearUnassignedInfo(targetNode);
74
+ }
75
+ }
76
+ onAccessCall({ call }) {
77
+ const node = this.getNormalizedAst(call.id);
78
+ if (node !== undefined) {
79
+ node.info.dataFrame = (0, access_mapper_1.mapDataFrameAccess)(node, this.config.dfg);
80
+ this.applyDataFrameExpression(node);
81
+ }
82
+ }
83
+ onDefaultFunctionCall({ call }) {
84
+ const node = this.getNormalizedAst(call.id);
85
+ if (node !== undefined) {
86
+ node.info.dataFrame = (0, function_mapper_1.mapDataFrameFunctionCall)(node, this.config.dfg, this.config.flowrConfig);
87
+ this.applyDataFrameExpression(node);
88
+ }
89
+ }
90
+ onReplacementCall({ call, source, target }) {
91
+ const node = this.getNormalizedAst(call.id);
92
+ const targetNode = this.getNormalizedAst(target);
93
+ const sourceNode = this.getNormalizedAst(source);
94
+ if (node !== undefined && targetNode !== undefined && sourceNode !== undefined) {
95
+ node.info.dataFrame = (0, replacement_mapper_1.mapDataFrameReplacementFunction)(node, sourceNode, this.config.dfg);
96
+ this.applyDataFrameExpression(node);
97
+ this.clearUnassignedInfo(targetNode);
98
+ }
99
+ }
100
+ applyDataFrameAssignment(node) {
101
+ if (!(0, absint_info_1.hasDataFrameAssignmentInfo)(node)) {
102
+ return;
103
+ }
104
+ const value = (0, shape_inference_1.resolveIdToDataFrameShape)(node.info.dataFrame.expression, this.config.dfg, this.newDomain);
105
+ if (value !== undefined) {
106
+ this.newDomain.set(node.info.dataFrame.identifier, value);
107
+ const identifier = this.getNormalizedAst(node.info.dataFrame.identifier);
108
+ if (identifier !== undefined) {
109
+ identifier.info.dataFrame ??= {};
110
+ identifier.info.dataFrame.domain = new Map(this.newDomain);
111
+ }
112
+ }
113
+ }
114
+ applyDataFrameExpression(node) {
115
+ if (!(0, absint_info_1.hasDataFrameExpressionInfo)(node)) {
116
+ return;
117
+ }
118
+ let value = domain_1.DataFrameTop;
119
+ for (const { operation, operand, type, options, ...args } of node.info.dataFrame.operations) {
120
+ const operandValue = operand !== undefined ? (0, shape_inference_1.resolveIdToDataFrameShape)(operand, this.config.dfg, this.newDomain) : value;
121
+ value = (0, semantics_1.applyDataFrameSemantics)(operation, operandValue ?? domain_1.DataFrameTop, args, options);
122
+ const constraintType = type ?? (0, semantics_1.getConstraintType)(operation);
123
+ if (operand !== undefined && constraintType === semantics_1.ConstraintType.OperandModification) {
124
+ this.newDomain.set(operand, value);
125
+ for (const origin of (0, shape_inference_1.getVariableOrigins)(operand, this.config.dfg)) {
126
+ this.newDomain.set(origin.info.id, value);
127
+ }
128
+ }
129
+ else if (constraintType === semantics_1.ConstraintType.ResultPostcondition) {
130
+ this.newDomain.set(node.info.id, value);
131
+ }
132
+ }
133
+ }
134
+ /** We only process vertices of leaf nodes and exit vertices (no entry nodes of complex nodes) */
135
+ shouldSkipVertex(vertex) {
136
+ return (0, control_flow_graph_1.isMarkerVertex)(vertex) ? vertex.type !== control_flow_graph_1.CfgVertexType.EndMarker : vertex.end !== undefined;
137
+ }
138
+ /** Get all AST nodes for the predecessor vertices that are leaf nodes and exit vertices */
139
+ getPredecessorNodes(vertexId) {
140
+ return this.config.controlFlow.graph.outgoingEdges(vertexId)?.keys() // outgoing dependency edges are incoming CFG edges
141
+ .map(id => this.getCfgVertex(id))
142
+ .flatMap(vertex => {
143
+ if (vertex === undefined) {
144
+ return [];
145
+ }
146
+ else if (this.shouldSkipVertex(vertex)) {
147
+ return this.getPredecessorNodes(vertex.id);
148
+ }
149
+ else {
150
+ return [this.getNormalizedAst((0, control_flow_graph_1.getVertexRootId)(vertex))];
151
+ }
152
+ })
153
+ .filter(assert_1.isNotUndefined)
154
+ .toArray() ?? [];
155
+ }
156
+ shouldWiden(vertex) {
157
+ return (this.visited.get(vertex.id) ?? 0) >= this.config.flowrConfig.abstractInterpretation.dataFrame.wideningThreshold;
158
+ }
159
+ clearUnassignedInfo(node) {
160
+ if ((0, absint_info_1.hasDataFrameInfoMarker)(node, absint_info_1.DataFrameInfoMarker.Unassigned)) {
161
+ if (node.info.dataFrame?.domain !== undefined) {
162
+ node.info.dataFrame = { domain: node.info.dataFrame.domain };
163
+ }
164
+ else {
165
+ delete node.info.dataFrame;
166
+ }
167
+ }
168
+ }
169
+ }
170
+ exports.DataFrameShapeInferenceVisitor = DataFrameShapeInferenceVisitor;
171
+ //# sourceMappingURL=absint-visitor.js.map