@eagleoutice/flowr 2.17.9 → 2.17.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/cli/repl/core.js +4 -0
  2. package/config.d.ts +10 -0
  3. package/config.js +8 -1
  4. package/control-flow/control-flow-graph.js +11 -1
  5. package/dataflow/environments/default-builtin-config/guards-primitive-lang.js +1 -1
  6. package/dataflow/environments/default-builtin-config/guards.js +6 -1
  7. package/dataflow/environments/default-builtin-config/index.d.ts +1 -1
  8. package/dataflow/environments/default-builtin-config/network-access.d.ts +1 -1
  9. package/dataflow/environments/default-builtin-config/network-access.js +2 -0
  10. package/dataflow/environments/environment.d.ts +2 -0
  11. package/dataflow/environments/environment.js +5 -0
  12. package/dataflow/environments/frame-memory.d.ts +9 -0
  13. package/dataflow/environments/frame-memory.js +37 -0
  14. package/dataflow/environments/group-generics.d.ts +2 -0
  15. package/dataflow/environments/group-generics.js +7 -0
  16. package/dataflow/environments/identifier.d.ts +2 -0
  17. package/dataflow/environments/identifier.js +16 -0
  18. package/dataflow/environments/pkg-name.d.ts +1 -0
  19. package/dataflow/environments/query-fn-props.d.ts +4 -0
  20. package/dataflow/environments/query-fn-props.js +21 -4
  21. package/dataflow/environments/resolve-by-name.js +5 -3
  22. package/dataflow/extractor.js +26 -4
  23. package/dataflow/fn/argument-roles.js +17 -4
  24. package/dataflow/fn/guards/call-contracts.js +8 -4
  25. package/dataflow/fn/guards/function-guards.d.ts +13 -4
  26. package/dataflow/fn/guards/function-guards.js +147 -52
  27. package/dataflow/fn/guards/guard-term.d.ts +6 -3
  28. package/dataflow/fn/guards/guard-term.js +12 -6
  29. package/dataflow/fn/strict-function.js +6 -2
  30. package/dataflow/graph/df-helper.d.ts +5 -0
  31. package/dataflow/graph/df-helper.js +22 -0
  32. package/dataflow/graph/graph.d.ts +2 -0
  33. package/dataflow/graph/graph.js +9 -5
  34. package/dataflow/internal/dispatch-linking.d.ts +6 -0
  35. package/dataflow/internal/dispatch-linking.js +25 -0
  36. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +32 -2
  37. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +52 -21
  38. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +28 -19
  39. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +75 -0
  40. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +20 -6
  41. package/dataflow/processor.d.ts +3 -0
  42. package/documentation/data/faq/faqs.js +4 -0
  43. package/documentation/wiki-analyzer.js +13 -2
  44. package/documentation/wiki-interface.js +1 -0
  45. package/documentation/wiki-linter.js +3 -0
  46. package/linter/linter-executor.js +4 -1
  47. package/linter/linter-format.d.ts +5 -5
  48. package/linter/linter-rules.d.ts +47 -13
  49. package/linter/linter-rules.js +3 -1
  50. package/linter/rules/absolute-file-paths.js +1 -1
  51. package/linter/rules/autoload-files.d.ts +33 -0
  52. package/linter/rules/autoload-files.js +94 -0
  53. package/linter/rules/cmd-check/description-metadata.d.ts +2 -2
  54. package/linter/rules/cmd-check/description-metadata.js +1 -1
  55. package/linter/rules/cmd-check/documentation-mismatch.d.ts +2 -2
  56. package/linter/rules/cmd-check/documentation-mismatch.js +1 -1
  57. package/linter/rules/cmd-check/file-checks.d.ts +6 -11
  58. package/linter/rules/cmd-check/file-checks.js +8 -3
  59. package/linter/rules/cmd-check/package-data.d.ts +2 -2
  60. package/linter/rules/cmd-check/package-data.js +1 -1
  61. package/linter/rules/cmd-check/package-metafiles.js +1 -1
  62. package/linter/rules/cmd-check/package-structure.d.ts +2 -2
  63. package/linter/rules/cmd-check/package-structure.js +1 -1
  64. package/linter/rules/cmd-check/rd-files.js +1 -1
  65. package/linter/rules/naming-convention.d.ts +9 -2
  66. package/linter/rules/process-state-in-session.js +4 -1
  67. package/linter/rules/software-has-license.d.ts +2 -2
  68. package/linter/rules/software-has-license.js +1 -2
  69. package/linter/rules/stop-call.d.ts +8 -3
  70. package/linter/rules/useless-loop.d.ts +1 -1
  71. package/package.json +1 -1
  72. package/project/cache/flowr-analyzer-cache.d.ts +3 -0
  73. package/project/cache/flowr-analyzer-cache.js +9 -0
  74. package/project/context/flowr-analyzer-context.d.ts +4 -3
  75. package/project/context/flowr-analyzer-context.js +18 -6
  76. package/project/context/flowr-analyzer-dependencies-context.d.ts +9 -0
  77. package/project/context/flowr-analyzer-dependencies-context.js +35 -6
  78. package/project/context/flowr-analyzer-environment-context.d.ts +1 -0
  79. package/project/context/flowr-analyzer-environment-context.js +1 -0
  80. package/project/context/flowr-analyzer-files-context.d.ts +4 -0
  81. package/project/context/flowr-analyzer-files-context.js +24 -0
  82. package/project/context/flowr-analyzer-functions-context.d.ts +1 -0
  83. package/project/context/flowr-analyzer-functions-context.js +6 -0
  84. package/project/context/flowr-analyzer-gas-context.d.ts +1 -0
  85. package/project/context/flowr-analyzer-gas-context.js +1 -0
  86. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +24 -0
  87. package/project/context/flowr-analyzer-incremental-analysis-context.js +54 -0
  88. package/project/context/flowr-analyzer-loading-order-context.d.ts +1 -0
  89. package/project/context/flowr-analyzer-loading-order-context.js +14 -0
  90. package/project/context/flowr-analyzer-meta-context.d.ts +1 -0
  91. package/project/context/flowr-analyzer-meta-context.js +11 -0
  92. package/project/context/flowr-file.d.ts +2 -1
  93. package/project/context/flowr-file.js +5 -2
  94. package/project/flowr-analyzer.d.ts +22 -3
  95. package/project/flowr-analyzer.js +36 -0
  96. package/project/incremental/incremental-dataflow/incremental-dataflow.d.ts +142 -0
  97. package/project/incremental/incremental-dataflow/incremental-dataflow.js +330 -0
  98. package/project/plugins/flowr-analyzer-plugin.d.ts +22 -2
  99. package/project/plugins/flowr-analyzer-plugin.js +16 -1
  100. package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-heuristic-plugin.d.ts +52 -0
  101. package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-heuristic-plugin.js +50 -0
  102. package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-update-type-plugin.d.ts +77 -0
  103. package/project/plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-update-type-plugin.js +151 -0
  104. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -0
  105. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +4 -0
  106. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -0
  107. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +3 -0
  108. package/project/plugins/plugin-registry.d.ts +3 -1
  109. package/project/plugins/plugin-registry.js +6 -1
  110. package/project/sigdb/decode.js +4 -1
  111. package/project/sigdb/dict.d.ts +7 -4
  112. package/project/sigdb/dict.js +20 -6
  113. package/project/sigdb/guarded-source.js +10 -0
  114. package/project/sigdb/reader.d.ts +8 -2
  115. package/project/sigdb/reader.js +44 -30
  116. package/queries/catalog/input-sources-query/simple-input-classifier.js +84 -10
  117. package/util/flowr-version.d.ts +1 -1
  118. package/util/flowr-version.js +2 -2
  119. package/util/objects.d.ts +14 -0
  120. package/util/objects.js +100 -0
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IncrementalDataflow = void 0;
4
+ const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source");
5
+ const environment_1 = require("../../../dataflow/environments/environment");
6
+ const frame_memory_1 = require("../../../dataflow/environments/frame-memory");
7
+ const graph_1 = require("../../../dataflow/graph/graph");
8
+ const objects_1 = require("../../../util/objects");
9
+ const gas_1 = require("../../../gas");
10
+ const flowr_analyzer_incremental_dataflow_update_type_plugin_1 = require("../../plugins/incremental/incremental-dataflow/flowr-analyzer-incremental-dataflow-update-type-plugin");
11
+ /** Whether `o` is the node `idMap` holds for its id, which a copy shares as the AST does not change. */
12
+ function isNodeOf(o, idMap) {
13
+ return 'info' in o && typeof o.info === 'object' && o.info !== null && 'id' in o.info && idMap.get(o.info.id) === o;
14
+ }
15
+ /**
16
+ * The edges are most of what a copy of a graph holds, and nearly all of them only carry their types, so these are copied as they are.
17
+ * A control edge shares its dependency with the vertices behind it, so it goes through the clone; the edges without side effects on calls are derived from the edges, so they start out empty.
18
+ */
19
+ const GraphCopiers = new Map([
20
+ ['edgeInformation', (value, clone) => {
21
+ const copy = new Map();
22
+ for (const [from, targets] of value) {
23
+ const copied = new Map();
24
+ for (const [to, edge] of targets) {
25
+ copied.set(to, edge.cd === undefined ? { types: edge.types } : clone(edge));
26
+ }
27
+ copy.set(from, copied);
28
+ }
29
+ return copy;
30
+ }],
31
+ ['beyondSideEffects', () => new Map()]
32
+ ]);
33
+ /** what a graph, an environment, and a frame derive from what they hold on demand is left out, so a copy rebuilds it when it needs it */
34
+ const GraphFields = { drop: new Set(['incomingIndex', 'qualifiedNames', 'targetWalks', 'derived']), replace: GraphCopiers };
35
+ const EnvironmentFields = { drop: new Set(['cache', 'tailCache']) };
36
+ const FrameFields = { drop: new Set(['flat', 'flatKeys']) };
37
+ function clonedFieldsOf(owner) {
38
+ return owner instanceof graph_1.DataflowGraph ? GraphFields : owner instanceof environment_1.Environment ? EnvironmentFields : owner instanceof frame_memory_1.Frame ? FrameFields : undefined;
39
+ }
40
+ /** The nodes `idMap` gained since it held `before` of them: it only grows during an analysis, and keeps the nodes in the order they were added. */
41
+ function nodesAddedSince(idMap, before) {
42
+ return idMap.size > before ? [...idMap.entries().drop(before)] : [];
43
+ }
44
+ function cfgOf(info) {
45
+ return info === undefined ? undefined : { entryPoint: info.entryPoint, cfgEntry: info.cfgEntry, cfgExit: info.cfgExit, exitPoints: info.exitPoints, hooks: info.hooks };
46
+ }
47
+ function marksOf(environment) {
48
+ const builtIn = environment_1.REnvironment.findBuiltIn(environment);
49
+ return { forcing: builtIn.forcing, locking: builtIn.locking, methods: builtIn.methods, unknownMethodsAt: builtIn.unknownMethodsAt?.slice() };
50
+ }
51
+ function restoreMarks(environment, marks) {
52
+ const builtIn = environment_1.REnvironment.findBuiltIn(environment);
53
+ builtIn.forcing = marks.forcing;
54
+ builtIn.locking = marks.locking;
55
+ builtIn.methods = marks.methods;
56
+ builtIn.unknownMethodsAt = marks.unknownMethodsAt?.slice();
57
+ }
58
+ function contentOf(ctx, path) {
59
+ try {
60
+ const content = ctx.files.resolveFile(path)?.content();
61
+ return typeof content === 'string' ? content : undefined;
62
+ }
63
+ catch {
64
+ return undefined;
65
+ }
66
+ }
67
+ /**
68
+ * One dataflow analysis that may reuse what the analysis before it kept, and keeps what the next one may reuse.
69
+ * Created by {@link IncrementalDataflow.begin}.
70
+ */
71
+ class IncrementalDataflowSession {
72
+ ast;
73
+ ctx;
74
+ files;
75
+ /** how many nodes the id map held before the analysis, which only adds to it */
76
+ initialNodes;
77
+ /** how many nodes of the id map the analysis of the statements does not add itself, see {@link resume} */
78
+ listNodes;
79
+ initialFiles;
80
+ initialRead;
81
+ config;
82
+ keep;
83
+ /** the number of statements the checkpoints end at, see {@link IncrementalDataflowPlan#after} */
84
+ after;
85
+ /** whether the analysis resumes from checkpoints, see `incremental.dataflow.activated` */
86
+ resumes;
87
+ /** whether the analysis hands out the one before again for unchanged files, see `incremental.dataflow.reuse` */
88
+ reuses;
89
+ minimum;
90
+ recorded = [];
91
+ update;
92
+ resumeFrom;
93
+ reuseFinal;
94
+ /** the first file the reused analysis did not analyze */
95
+ reuseFrom = 0;
96
+ /** the earlier checkpoints that hold for this analysis too */
97
+ carried = [];
98
+ applied = false;
99
+ previous;
100
+ stored;
101
+ constructor(ast, ctx, previous, update, plan) {
102
+ this.ast = ast;
103
+ this.ctx = ctx;
104
+ this.files = ast.ast.files.map(f => ({ filePath: f.filePath, root: f.root }));
105
+ this.initialNodes = ast.idMap.size;
106
+ this.listNodes = this.initialNodes;
107
+ this.initialFiles = ast.ast.files.length;
108
+ this.initialRead = ctx.files.consideredFilesList().length;
109
+ this.config = ctx.config;
110
+ this.keep = plan.checkpoints;
111
+ this.after = plan.after ?? Infinity;
112
+ this.resumes = plan.checkpoints > 0;
113
+ this.reuses = plan.reuse;
114
+ this.minimum = plan.minStatements;
115
+ this.previous = previous;
116
+ this.update = update;
117
+ if (previous !== undefined && update !== undefined) {
118
+ this.plan(previous, update);
119
+ }
120
+ }
121
+ /** The configuration of this analysis if it stayed the same so far, see {@link AnalysisAdditions#config}. */
122
+ stableConfig() {
123
+ return this.ctx.config === this.config ? this.config : undefined;
124
+ }
125
+ /** Whether the analysis up to the given state would run the same now: with the same configuration, and reading the same files. */
126
+ holds(state) {
127
+ return state.config === this.config && this.unchangedReads(state.considered);
128
+ }
129
+ unchangedReads(considered) {
130
+ return considered.every(([path, content]) => contentOf(this.ctx, path) === content);
131
+ }
132
+ plan(previous, update) {
133
+ const unchanged = flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdate.unchanged(update) || flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdate.is(update, flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdateType.NewFileAtEnd);
134
+ if (unchanged && previous.final !== undefined && this.holds(previous.final)) {
135
+ this.reuseFinal = previous.final;
136
+ this.reuseFrom = previous.files.length;
137
+ return;
138
+ }
139
+ const prefix = unchanged ? previous.files[0]?.root.children.length : update.commonPrefix;
140
+ if (prefix === undefined) {
141
+ return;
142
+ }
143
+ const usable = previous.checkpoints.filter(c => c.list.count <= prefix && this.holds(c));
144
+ this.resumeFrom = usable.at(-1);
145
+ const total = this.ast.ast.files[0].root.children.length;
146
+ this.carried = usable.filter(c => c !== this.resumeFrom && this.wants(c.list.count, total));
147
+ }
148
+ /** Reuses the complete dataflow information of the analysis before, if nothing it read changed. */
149
+ reuse(base) {
150
+ const final = this.reuseFinal;
151
+ if (final === undefined) {
152
+ return undefined;
153
+ }
154
+ this.reuseFinal = undefined;
155
+ const files = this.ast.ast.files;
156
+ const dfData = {
157
+ ...base,
158
+ environment: final.df.environment,
159
+ cds: undefined,
160
+ referenceChain: [files[0].filePath],
161
+ statementOrder: new Map(),
162
+ unreachable: new Set()
163
+ };
164
+ this.restore(final, dfData);
165
+ final.df.graph.setIdMap(this.ast.idMap);
166
+ this.applied = true;
167
+ let df = final.df;
168
+ for (let i = this.reuseFrom; i < this.initialFiles; i++) {
169
+ df = (0, built_in_source_1.standaloneSourceFile)(i, files[i], dfData, df);
170
+ }
171
+ return { df, dfData };
172
+ }
173
+ resume(fileIndex, info) {
174
+ const data = info;
175
+ if (fileIndex !== 0) {
176
+ return undefined;
177
+ }
178
+ /* the list wraps its statements as arguments before it starts, which every analysis does anew, so these do not count as added by a statement */
179
+ this.listNodes = data.completeAst.idMap.size;
180
+ const from = this.resumeFrom;
181
+ if (from === undefined) {
182
+ return undefined;
183
+ }
184
+ this.resumeFrom = undefined;
185
+ this.restore(from, data);
186
+ from.list.graph.setIdMap(data.completeAst.idMap);
187
+ this.applied = true;
188
+ const total = data.completeAst.ast.files[0].root.children.length;
189
+ if (this.wants(from.list.count, total)) {
190
+ this.record(fileIndex, from.list, data);
191
+ }
192
+ return from.list;
193
+ }
194
+ wants(count, total) {
195
+ const last = Math.min(this.after, total);
196
+ return this.resumes && this.initialFiles === 1 && total >= this.minimum && count > last - this.keep && count <= last;
197
+ }
198
+ record(fileIndex, list, info) {
199
+ const data = info;
200
+ if (fileIndex !== 0) {
201
+ return;
202
+ }
203
+ /* resuming the list only needs where the statements before passed on the control flow, not all they computed */
204
+ const cfg = { ...list, processed: list.processed.map(cfgOf), defaultReturn: cfgOf(list.defaultReturn) };
205
+ this.recorded.push(this.stateOf({ list: cfg }, data, list.environment.current, this.listNodes));
206
+ }
207
+ /** The state to continue the analysis from: a copy of `changing` and of whatever else the analysis goes on to change, with what it added so far. */
208
+ stateOf(changing, data, environment, before) {
209
+ return {
210
+ ...this.copy({ ...changing, statementOrder: data.statementOrder, unreachable: data.unreachable }, data),
211
+ marks: marksOf(environment),
212
+ addedNodes: nodesAddedSince(data.completeAst.idMap, before),
213
+ addedFiles: data.completeAst.ast.files.slice(this.initialFiles),
214
+ considered: this.ctx.files.consideredFilesList().slice(this.initialRead).map(p => [p, contentOf(this.ctx, p)]),
215
+ config: this.stableConfig()
216
+ };
217
+ }
218
+ /** A copy that shares what the analysis never changes in place: the AST, the built-in environment, and frozen frames. */
219
+ copy(state, data) {
220
+ const idMap = data.completeAst.idMap;
221
+ /* the sourced files are known by identity, a file sourced again is analyzed again */
222
+ const files = new Set(data.completeAst.ast.files);
223
+ /* a live frame is handed to the copy and forks on its owner's next write, so it costs nothing to copy */
224
+ const shared = new Set();
225
+ return (0, objects_1.deepCloneSharing)(state, o => {
226
+ /* most of what a copy meets are plain records (edges, vertices, references), so these are asked first */
227
+ if (Object.getPrototypeOf(o) === Object.prototype) {
228
+ return o === this.config || files.has(o) || isNodeOf(o, idMap);
229
+ }
230
+ else if (o instanceof environment_1.Environment) {
231
+ if (o.builtInEnv === true) {
232
+ return true;
233
+ }
234
+ shared.add(o.shareMemory());
235
+ return false;
236
+ }
237
+ return o === idMap || o instanceof frame_memory_1.LazyBindings || (o instanceof frame_memory_1.Frame && (o.isFrozen || shared.has(o)));
238
+ }, clonedFieldsOf);
239
+ }
240
+ restore(state, data) {
241
+ if (state.statementOrder !== undefined) {
242
+ for (const [id, span] of state.statementOrder) {
243
+ data.statementOrder?.set(id, span);
244
+ }
245
+ }
246
+ if (state.unreachable !== undefined) {
247
+ for (const id of state.unreachable) {
248
+ data.unreachable?.add(id);
249
+ }
250
+ }
251
+ restoreMarks(data.environment.current, state.marks);
252
+ this.addAgain(state, data.completeAst);
253
+ }
254
+ /** Adds what the analysis before added to the AST and the context again, which a continued analysis does not do itself. */
255
+ addAgain(added, ast) {
256
+ for (const [id, node] of added.addedNodes) {
257
+ /* an id added for a node of the AST names the node this AST holds for it */
258
+ ast.idMap.set(id, ast.idMap.get(node.info.id) ?? node);
259
+ }
260
+ const files = ast.ast.files;
261
+ for (const file of added.addedFiles) {
262
+ if (!files.some(f => f.filePath === file.filePath)) {
263
+ files.push(file);
264
+ }
265
+ }
266
+ for (const [path] of added.considered) {
267
+ this.ctx.files.addConsideredFile(path);
268
+ }
269
+ }
270
+ /** Hands out the finalized analysis before again if the program did not change, which skips the analysis altogether. */
271
+ reuseFinalized() {
272
+ const finalized = this.previous?.finalized;
273
+ if (!this.reuses || this.update === undefined || !flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdate.unchanged(this.update) || finalized === undefined || !this.holds(finalized)) {
274
+ return undefined;
275
+ }
276
+ this.addAgain(finalized, this.ast);
277
+ finalized.df.graph.setIdMap(this.ast.idMap);
278
+ this.ctx.inc.storeAppliedIncrementalUpdate({ ...this.update, applied: true });
279
+ this.ctx.inc.storeDataflowSnapshot({ ...this.previous, files: this.files, finalized });
280
+ return finalized.df;
281
+ }
282
+ /** Keeps the finalized `df` for {@link reuseFinalized}, and hands it back. */
283
+ finalized(df) {
284
+ if (this.reuses && this.stored !== undefined) {
285
+ const requested = new Set(this.files.map(f => f.filePath));
286
+ this.ctx.inc.storeDataflowSnapshot({ ...this.stored, finalized: {
287
+ df,
288
+ addedNodes: nodesAddedSince(this.ast.idMap, this.initialNodes),
289
+ addedFiles: this.ast.ast.files.slice(this.initialFiles),
290
+ considered: this.ctx.files.consideredFilesList().slice(this.initialRead).filter(p => !requested.has(p)).map(p => [p, contentOf(this.ctx, p)]),
291
+ config: this.stableConfig()
292
+ } });
293
+ }
294
+ return df;
295
+ }
296
+ /** Keeps what the next analysis may continue from, unless the analysis was cut short. */
297
+ end(result) {
298
+ if (this.update !== undefined) {
299
+ this.ctx.inc.storeAppliedIncrementalUpdate({ ...this.update, applied: this.applied });
300
+ }
301
+ if (gas_1.activeDataflowBudget?.exhausted !== undefined) {
302
+ return;
303
+ }
304
+ const checkpoints = [...this.carried, ...this.recorded].sort((a, b) => a.list.count - b.list.count);
305
+ const final = this.resumes && this.initialFiles > 1 ? this.stateOf({ df: result.df }, result.dfData, result.df.environment.current, this.initialNodes) : undefined;
306
+ this.stored = { files: this.files, checkpoints, final };
307
+ this.ctx.inc.storeDataflowSnapshot(this.stored);
308
+ }
309
+ }
310
+ /**
311
+ * Helper functions of the incremental dataflow analysis, which continues the analysis before it where the files did not change.
312
+ * The dataflow analysis {@link IncrementalDataflow.begin|begins} a session, which may {@link IncrementalDataflowSession#reuse|reuse} a complete earlier analysis,
313
+ * or hands itself to the processors as their {@link DataflowProcessorInformation#checkpoints|checkpoints} to resume the top-level statements of a file after
314
+ * those that did not change.
315
+ * Either way, it {@link IncrementalDataflowSession#end|ends} before the dataflow is finalized, keeping copies of what the next analysis may continue from.
316
+ */
317
+ exports.IncrementalDataflow = {
318
+ name: 'IncrementalDataflow',
319
+ /**
320
+ * Begins an incremental dataflow analysis of `ast`, before the analysis adds the files it sources, as the {@link FlowrAnalyzerIncrementalDataflowHeuristicPlugin} plans it
321
+ * for how the files changed; `undefined` if it plans neither to reuse nor to resume, and no analysis before kept its files to compare with.
322
+ */
323
+ begin(ast, ctx) {
324
+ const previous = ctx.inc.takeDataflowSnapshot();
325
+ const update = previous === undefined ? undefined : ctx.inc.determineUpdateTypes(previous.files, ast, ctx);
326
+ const plan = ctx.inc.planDataflow(ctx, update);
327
+ return plan.reuse || plan.checkpoints > 0 || update !== undefined ? new IncrementalDataflowSession(ast, ctx, previous, update, plan) : undefined;
328
+ }
329
+ };
330
+ //# sourceMappingURL=incremental-dataflow.js.map
@@ -49,7 +49,20 @@ export declare enum PluginType {
49
49
  * Multiple Gas plugins are combined by taking the maximum level returned.
50
50
  * @see {@link FlowrAnalyzerGasPlugin} - for the base class to implement such a plugin.
51
51
  */
52
- Gas = "gas"
52
+ Gas = "gas",
53
+ /**
54
+ * Plugins that classifies the {@link IncrementalUpdateType}, so the dataflow analysis can be
55
+ * patched incrementally instead of fully recomputed. At most one may be registered; the default
56
+ * plugin runs otherwise.
57
+ * @see {@link FlowrAnalyzerIncrementalDataflowUpdateTypePlugin} - for the base class to implement such a plugin.
58
+ */
59
+ IncrementalDataflowUpdateType = "incremental-dataflow-update-type",
60
+ /**
61
+ * Plugins that plan how a dataflow analysis builds on the one before (reuse it, resume from checkpoints, or start over).
62
+ * At most one may be registered; the plugin following the configuration runs otherwise.
63
+ * @see {@link FlowrAnalyzerIncrementalDataflowHeuristicPlugin} - for the base class to implement such a plugin.
64
+ */
65
+ IncrementalDataflowHeuristic = "incremental-dataflow-heuristic"
53
66
  }
54
67
  /**
55
68
  * This is the main interface that every plugin to be used with the {@link FlowrAnalyzer} must comply with.
@@ -89,7 +102,14 @@ export declare abstract class FlowrAnalyzerPlugin<In = unknown, Out extends Asyn
89
102
  abstract readonly type: PluginType;
90
103
  /** Returns a default/dummy implementation to be used when no plugin of this type is registered or triggered. */
91
104
  static defaultPlugin(): FlowrAnalyzerPlugin<unknown, unknown>;
92
- /** Run the plugin with the given context and arguments. */
105
+ /**
106
+ * Optional Hook to create deep copies of a Plugin for analyzer forks
107
+ * If not implemented forking an analyzer will copy by reference
108
+ */
109
+ fork?(): FlowrAnalyzerPlugin<In, Out>;
110
+ /**
111
+ * Run the plugin with the given context and arguments.
112
+ */
93
113
  processor(context: FlowrAnalyzerContext, args: In): Out;
94
114
  protected abstract process(analyzer: FlowrAnalyzerContext, args: In): Out;
95
115
  }
@@ -52,6 +52,19 @@ var PluginType;
52
52
  * @see {@link FlowrAnalyzerGasPlugin} - for the base class to implement such a plugin.
53
53
  */
54
54
  PluginType["Gas"] = "gas";
55
+ /**
56
+ * Plugins that classifies the {@link IncrementalUpdateType}, so the dataflow analysis can be
57
+ * patched incrementally instead of fully recomputed. At most one may be registered; the default
58
+ * plugin runs otherwise.
59
+ * @see {@link FlowrAnalyzerIncrementalDataflowUpdateTypePlugin} - for the base class to implement such a plugin.
60
+ */
61
+ PluginType["IncrementalDataflowUpdateType"] = "incremental-dataflow-update-type";
62
+ /**
63
+ * Plugins that plan how a dataflow analysis builds on the one before (reuse it, resume from checkpoints, or start over).
64
+ * At most one may be registered; the plugin following the configuration runs otherwise.
65
+ * @see {@link FlowrAnalyzerIncrementalDataflowHeuristicPlugin} - for the base class to implement such a plugin.
66
+ */
67
+ PluginType["IncrementalDataflowHeuristic"] = "incremental-dataflow-heuristic";
55
68
  })(PluginType || (exports.PluginType = PluginType = {}));
56
69
  const generalPluginLog = log_1.log.getSubLogger({ name: 'plugins' });
57
70
  /**
@@ -67,7 +80,9 @@ class FlowrAnalyzerPlugin {
67
80
  static defaultPlugin() {
68
81
  throw new Error('This is to be implemented by every Plugin Layer');
69
82
  }
70
- /** Run the plugin with the given context and arguments. */
83
+ /**
84
+ * Run the plugin with the given context and arguments.
85
+ */
71
86
  processor(context, args) {
72
87
  const now = Date.now();
73
88
  try {
@@ -0,0 +1,52 @@
1
+ import { SemVer } from 'semver';
2
+ import { FlowrAnalyzerPlugin, PluginType } from '../../flowr-analyzer-plugin';
3
+ import type { FlowrAnalyzerContext } from '../../../context/flowr-analyzer-context';
4
+ import { type IncrementalUpdateResult } from './flowr-analyzer-incremental-dataflow-update-type-plugin';
5
+ /** How a dataflow analysis builds on the one before, see {@link FlowrAnalyzerIncrementalDataflowHeuristicPlugin}. */
6
+ export interface IncrementalDataflowPlan {
7
+ /** hand out the analysis before again if only comments changed, see `incremental.dataflow.reuse` */
8
+ readonly reuse: boolean;
9
+ /** after how many of the last top-level statements to keep a checkpoint to resume from, `0` resumes nothing, see `incremental.dataflow.checkpoints` */
10
+ readonly checkpoints: number;
11
+ /** the number of top-level statements the checkpoints end at, so that a change after them resumes; the end of the file by default */
12
+ readonly after?: number;
13
+ /** keep checkpoints only for files with at least this many top-level statements, see `incremental.dataflow.minStatements` */
14
+ readonly minStatements: number;
15
+ }
16
+ /** What a {@link FlowrAnalyzerIncrementalDataflowHeuristicPlugin} decides on. */
17
+ export interface IncrementalDataflowHeuristicInformation {
18
+ /** how many dataflow analyses the context ran before this one */
19
+ readonly analyses: number;
20
+ /** how the analysis before classified its change, and whether it reused anything */
21
+ readonly lastUpdate: IncrementalUpdateResult | undefined;
22
+ /** how the files of this analysis differ from those of the analysis before, if that kept them */
23
+ readonly update: IncrementalUpdateResult | undefined;
24
+ }
25
+ /**
26
+ * Base class for plugins that plan how a dataflow analysis builds on the one before, see {@link IncrementalDataflowPlan}.
27
+ * At most one may be registered, {@link AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin} runs otherwise.
28
+ */
29
+ export declare abstract class FlowrAnalyzerIncrementalDataflowHeuristicPlugin extends FlowrAnalyzerPlugin<IncrementalDataflowHeuristicInformation, IncrementalDataflowPlan> {
30
+ readonly type = PluginType.IncrementalDataflowHeuristic;
31
+ static defaultPlugin(): FlowrAnalyzerIncrementalDataflowHeuristicPlugin;
32
+ }
33
+ /** Plans as {@link FlowrConfig.incremental.dataflow} states, checkpoints only if `activated`. */
34
+ export declare class ConfiguredFlowrAnalyzerIncrementalDataflowHeuristicPlugin extends FlowrAnalyzerIncrementalDataflowHeuristicPlugin {
35
+ readonly name = "configured-incremental-dataflow-heuristic-plugin";
36
+ readonly description = "Plans the incremental dataflow analysis as the incremental.dataflow configuration states.";
37
+ readonly version: SemVer;
38
+ protected process(ctx: FlowrAnalyzerContext): IncrementalDataflowPlan;
39
+ }
40
+ /**
41
+ * With `activated`, resumes only once a context analyzes its files again, as an editor or a watch does, and where it pays:
42
+ * the first analysis keeps no checkpoint, so an analysis that stays the only one costs nothing.
43
+ * Every later one keeps a single checkpoint, after the statements its change left as they were, as the next change likely happens where this one did.
44
+ * So changing a statement again resumes right before it, however far from the end of the file it is, at the cost of one copy of the analysis up to there,
45
+ * and a change that leaves nothing to resume from (e.g., of the first statement, or of one of multiple files) keeps no checkpoint at all.
46
+ */
47
+ export declare class AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin extends FlowrAnalyzerIncrementalDataflowHeuristicPlugin {
48
+ readonly name = "adaptive-incremental-dataflow-heuristic-plugin";
49
+ readonly description = "Keeps a checkpoint for the incremental dataflow analysis only once the files are analyzed again, where the last change happened.";
50
+ readonly version: SemVer;
51
+ protected process(ctx: FlowrAnalyzerContext, { analyses, update }: IncrementalDataflowHeuristicInformation): IncrementalDataflowPlan;
52
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin = exports.ConfiguredFlowrAnalyzerIncrementalDataflowHeuristicPlugin = exports.FlowrAnalyzerIncrementalDataflowHeuristicPlugin = void 0;
4
+ const semver_1 = require("semver");
5
+ const flowr_analyzer_plugin_1 = require("../../flowr-analyzer-plugin");
6
+ const flowr_analyzer_incremental_dataflow_update_type_plugin_1 = require("./flowr-analyzer-incremental-dataflow-update-type-plugin");
7
+ /**
8
+ * Base class for plugins that plan how a dataflow analysis builds on the one before, see {@link IncrementalDataflowPlan}.
9
+ * At most one may be registered, {@link AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin} runs otherwise.
10
+ */
11
+ class FlowrAnalyzerIncrementalDataflowHeuristicPlugin extends flowr_analyzer_plugin_1.FlowrAnalyzerPlugin {
12
+ type = flowr_analyzer_plugin_1.PluginType.IncrementalDataflowHeuristic;
13
+ static defaultPlugin() {
14
+ return new AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin();
15
+ }
16
+ }
17
+ exports.FlowrAnalyzerIncrementalDataflowHeuristicPlugin = FlowrAnalyzerIncrementalDataflowHeuristicPlugin;
18
+ /** Plans as {@link FlowrConfig.incremental.dataflow} states, checkpoints only if `activated`. */
19
+ class ConfiguredFlowrAnalyzerIncrementalDataflowHeuristicPlugin extends FlowrAnalyzerIncrementalDataflowHeuristicPlugin {
20
+ name = 'configured-incremental-dataflow-heuristic-plugin';
21
+ description = 'Plans the incremental dataflow analysis as the incremental.dataflow configuration states.';
22
+ version = new semver_1.SemVer('0.1.0');
23
+ process(ctx) {
24
+ const { reuse, activated, checkpoints, minStatements } = ctx.config.incremental.dataflow;
25
+ return { reuse, checkpoints: activated ? checkpoints : 0, minStatements };
26
+ }
27
+ }
28
+ exports.ConfiguredFlowrAnalyzerIncrementalDataflowHeuristicPlugin = ConfiguredFlowrAnalyzerIncrementalDataflowHeuristicPlugin;
29
+ /**
30
+ * With `activated`, resumes only once a context analyzes its files again, as an editor or a watch does, and where it pays:
31
+ * the first analysis keeps no checkpoint, so an analysis that stays the only one costs nothing.
32
+ * Every later one keeps a single checkpoint, after the statements its change left as they were, as the next change likely happens where this one did.
33
+ * So changing a statement again resumes right before it, however far from the end of the file it is, at the cost of one copy of the analysis up to there,
34
+ * and a change that leaves nothing to resume from (e.g., of the first statement, or of one of multiple files) keeps no checkpoint at all.
35
+ */
36
+ class AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin extends FlowrAnalyzerIncrementalDataflowHeuristicPlugin {
37
+ name = 'adaptive-incremental-dataflow-heuristic-plugin';
38
+ description = 'Keeps a checkpoint for the incremental dataflow analysis only once the files are analyzed again, where the last change happened.';
39
+ version = new semver_1.SemVer('0.2.0');
40
+ process(ctx, { analyses, update }) {
41
+ const { reuse, activated, checkpoints, minStatements } = ctx.config.incremental.dataflow;
42
+ return { reuse, checkpoints: activated && analyses > 0 && mayResumeAfter(update) ? Math.min(checkpoints, 1) : 0, after: update?.commonPrefix, minStatements };
43
+ }
44
+ }
45
+ exports.AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin = AdaptiveFlowrAnalyzerIncrementalDataflowHeuristicPlugin;
46
+ /** Whether an analysis may resume after a change like `update`: one that kept part of the analysis before, or an unknown one. */
47
+ function mayResumeAfter(update) {
48
+ return update === undefined || update.commonPrefix !== undefined || flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdate.unchanged(update) || flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdate.is(update, flowr_analyzer_incremental_dataflow_update_type_plugin_1.IncrementalUpdateType.NewFileAtEnd);
49
+ }
50
+ //# sourceMappingURL=flowr-analyzer-incremental-dataflow-heuristic-plugin.js.map
@@ -0,0 +1,77 @@
1
+ import { SemVer } from 'semver';
2
+ import { FlowrAnalyzerPlugin, PluginType } from '../../flowr-analyzer-plugin';
3
+ import type { FlowrAnalyzerContext } from '../../../context/flowr-analyzer-context';
4
+ import type { FilePath } from '../../../context/flowr-file';
5
+ import type { NormalizedAst, ParentInformation } from '../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
+ import type { RExpressionList } from '../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list';
7
+ /** How the files of an analysis differ from those of the analysis before, see {@link FlowrAnalyzerIncrementalDataflowUpdateTypePlugin}. */
8
+ export declare enum IncrementalUpdateType {
9
+ /** Anything else, the dataflow is analyzed again from scratch. */
10
+ Full = "Full",
11
+ /** The single file got statements appended. */
12
+ AddedAtEnd = "AddedAtEnd",
13
+ /** The single file lost statements at its end. */
14
+ RemovedAtEnd = "RemovedAtEnd",
15
+ /** The single file changed after its first {@link IncrementalUpdateResult#commonPrefix|commonPrefix} statements. */
16
+ ChangedAtEnd = "ChangedAtEnd",
17
+ /** A file was added after all the files analyzed before. */
18
+ NewFileAtEnd = "NewFileAtEnd",
19
+ /** The last file analyzed before was removed. */
20
+ RemovedFileAtEnd = "RemovedFileAtEnd",
21
+ /** Only the source locations changed, which nodes created during the analysis copy, so this is analyzed again from the first statement that moved. */
22
+ Location = "Location",
23
+ /** Only comments changed, which the dataflow analysis does not read. */
24
+ Comment = "Comment",
25
+ /** Nothing changed. */
26
+ Nothing = "Nothing"
27
+ }
28
+ /**
29
+ * What a {@link FlowrAnalyzerIncrementalDataflowUpdateTypePlugin} classified, plus whether the incremental dataflow
30
+ * analysis actually reused the earlier analysis for it.
31
+ */
32
+ export interface IncrementalUpdateResult {
33
+ readonly types: readonly IncrementalUpdateType[];
34
+ /** The file the change happened in, if it is a single one. */
35
+ readonly filePath?: FilePath;
36
+ /** For a change within a single file, how many of its top-level statements stayed the same, locations included. */
37
+ readonly commonPrefix?: number;
38
+ /** Whether the incremental analysis reused anything for this change. */
39
+ readonly applied?: boolean;
40
+ }
41
+ /** Helper functions to ask an {@link IncrementalUpdateResult} what kind of change it is. */
42
+ export declare const IncrementalUpdate: {
43
+ readonly name: "IncrementalUpdate";
44
+ /** Whether the files changed in nothing the dataflow analysis reads, i.e., at most in their comments. */
45
+ readonly unchanged: (this: void, update: IncrementalUpdateResult) => boolean;
46
+ /** Whether `type` is the only kind of change. */
47
+ readonly is: (this: void, update: IncrementalUpdateResult, type: IncrementalUpdateType) => boolean;
48
+ };
49
+ /** A file as an analysis saw it before the dataflow analysis added the files it sourced. */
50
+ export interface AnalyzedFile {
51
+ readonly filePath: FilePath | undefined;
52
+ readonly root: RExpressionList<ParentInformation>;
53
+ }
54
+ /** What a {@link FlowrAnalyzerIncrementalDataflowUpdateTypePlugin} compares. */
55
+ export interface IncrementalDataflowUpdateTypeInformation {
56
+ readonly previous: readonly AnalyzedFile[];
57
+ readonly current: NormalizedAst;
58
+ }
59
+ /**
60
+ * Base class for plugins that classify how the files of an analysis changed since the analysis before,
61
+ * producing an {@link IncrementalUpdateResult} the incremental dataflow analysis acts on.
62
+ * At most one may be registered, {@link DefaultFlowrAnalyzerIncrementalDataflowUpdateTypePlugin} runs otherwise.
63
+ */
64
+ export declare abstract class FlowrAnalyzerIncrementalDataflowUpdateTypePlugin extends FlowrAnalyzerPlugin<IncrementalDataflowUpdateTypeInformation, IncrementalUpdateResult> {
65
+ readonly type = PluginType.IncrementalDataflowUpdateType;
66
+ static defaultPlugin(): FlowrAnalyzerIncrementalDataflowUpdateTypePlugin;
67
+ }
68
+ /**
69
+ * The default classifier, comparing the ASTs structurally.
70
+ * Node ids take part in the comparison, as the dataflow graph refers to the nodes by them.
71
+ */
72
+ export declare class DefaultFlowrAnalyzerIncrementalDataflowUpdateTypePlugin extends FlowrAnalyzerIncrementalDataflowUpdateTypePlugin {
73
+ readonly name = "default-incremental-dataflow-update-type-plugin";
74
+ readonly description = "Classifies changes by comparing the top-level statements of the analyzed files.";
75
+ readonly version: SemVer;
76
+ protected process(_ctx: FlowrAnalyzerContext, { previous, current }: IncrementalDataflowUpdateTypeInformation): IncrementalUpdateResult;
77
+ }