@eagleoutice/flowr 2.13.12 → 2.13.14

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 (77) hide show
  1. package/README.md +29 -26
  2. package/benchmark/calibration.d.ts +18 -0
  3. package/benchmark/calibration.js +63 -0
  4. package/benchmark/slicer.d.ts +19 -0
  5. package/benchmark/slicer.js +84 -1
  6. package/benchmark/stats/feature-counts.d.ts +6 -0
  7. package/benchmark/stats/feature-counts.js +61 -0
  8. package/benchmark/stats/print.js +20 -0
  9. package/benchmark/stats/sigdb-counts.d.ts +7 -0
  10. package/benchmark/stats/sigdb-counts.js +219 -0
  11. package/benchmark/stats/size-of.d.ts +6 -0
  12. package/benchmark/stats/size-of.js +8 -0
  13. package/benchmark/stats/stats.d.ts +79 -0
  14. package/benchmark/stats/stats.js +7 -1
  15. package/benchmark/stopwatch.d.ts +4 -0
  16. package/benchmark/stopwatch.js +12 -1
  17. package/benchmark/summarizer/data.d.ts +17 -1
  18. package/benchmark/summarizer/first-phase/input.js +5 -0
  19. package/benchmark/summarizer/first-phase/process.js +12 -2
  20. package/benchmark/summarizer/second-phase/graph.d.ts +1 -1
  21. package/benchmark/summarizer/second-phase/graph.js +214 -16
  22. package/benchmark/summarizer/second-phase/process.js +56 -0
  23. package/benchmark/summarizer/summarizer.js +1 -2
  24. package/cli/benchmark-app.d.ts +1 -0
  25. package/cli/benchmark-app.js +2 -1
  26. package/cli/benchmark-helper-app.d.ts +1 -0
  27. package/cli/benchmark-helper-app.js +12 -2
  28. package/cli/common/options.d.ts +10 -0
  29. package/cli/common/options.js +3 -1
  30. package/cli/common/scripts-info.d.ts +10 -0
  31. package/config.js +13 -7
  32. package/control-flow/cfg-builder.d.ts +30 -0
  33. package/control-flow/cfg-builder.js +79 -0
  34. package/control-flow/extract-cfg.js +17 -10
  35. package/dataflow/environments/apply-kill.d.ts +3 -3
  36. package/dataflow/environments/apply-kill.js +60 -31
  37. package/dataflow/environments/reference-to-maybe.d.ts +5 -3
  38. package/dataflow/environments/reference-to-maybe.js +17 -52
  39. package/dataflow/environments/resolve-helper.d.ts +2 -1
  40. package/dataflow/environments/resolve-helper.js +2 -1
  41. package/dataflow/graph/df-helper.d.ts +2 -1
  42. package/dataflow/info.d.ts +7 -1
  43. package/dataflow/info.js +36 -7
  44. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
  45. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
  46. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
  47. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
  48. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
  49. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +8 -1
  50. package/documentation/doc-readme.js +5 -2
  51. package/documentation/doc-util/doc-issue.d.ts +2 -0
  52. package/documentation/doc-util/doc-issue.js +3 -1
  53. package/documentation/wiki-analyzer.js +10 -4
  54. package/documentation/wiki-core.js +58 -0
  55. package/documentation/wiki-dataflow-graph.js +4 -0
  56. package/documentation/wiki-faq.js +6 -2
  57. package/documentation/wiki-onboarding.js +11 -1
  58. package/documentation/wiki-setup.js +2 -1
  59. package/gas.d.ts +56 -6
  60. package/package.json +9 -4
  61. package/project/cache/flowr-analyzer-cache.d.ts +1 -0
  62. package/project/cache/flowr-analyzer-cache.js +4 -0
  63. package/project/context/flowr-analyzer-context.js +5 -0
  64. package/project/context/flowr-analyzer-gas-context.d.ts +58 -4
  65. package/project/context/flowr-analyzer-gas-context.js +137 -15
  66. package/project/flowr-analyzer.d.ts +25 -7
  67. package/project/flowr-analyzer.js +6 -6
  68. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
  69. package/slicing/static/slice-call.js +4 -4
  70. package/slicing/static/slicer-types.d.ts +13 -0
  71. package/slicing/static/static-slicer.d.ts +7 -1
  72. package/slicing/static/static-slicer.js +11 -5
  73. package/slicing/static/visiting-queue.d.ts +3 -1
  74. package/slicing/static/visiting-queue.js +4 -1
  75. package/util/node-version.d.ts +4 -0
  76. package/util/node-version.js +29 -0
  77. package/util/version.js +1 -1
@@ -1,6 +1,7 @@
1
- import { type FlowrGasConfig, GasLevel } from '../../gas';
1
+ import { type FlowrGasConfig, GasLevel, type GasOverrides } from '../../gas';
2
2
  import type { FlowrAnalyzerGasPlugin } from '../plugins/gas-plugins/flowr-analyzer-gas-plugin';
3
3
  import type { FlowrAnalyzerContext } from './flowr-analyzer-context';
4
+ import type { InvalidationEvent, InvalidationEventReceiver } from '../cache/flowr-cache';
4
5
  /** Read-only gas context exposed via `ctx.gas`. */
5
6
  export interface ReadOnlyFlowrAnalyzerGasContext {
6
7
  readonly name: string;
@@ -8,21 +9,74 @@ export interface ReadOnlyFlowrAnalyzerGasContext {
8
9
  * Returns the resource-pressure level for `key` (`config.gas.features[key]`).
9
10
  * Returns `GasLevel.Normal` with zero overhead when the feature factor is 0 or absent
10
11
  * and no gas plugins are registered (plugins are always consulted and may escalate any key).
12
+ *
13
+ * Measured from the start of the enclosing contingent, against the thresholds configured for `key`
14
+ * (see {@link GasThresholdSpec}), not one allowance shared by everything the analyzer does.
11
15
  */
12
16
  checkGas(key: string): GasLevel;
17
+ /**
18
+ * A view with a fresh contingent, measured from this call, for one operation to run against.
19
+ * The enclosing bounds still apply, `overrides` winning over them. Derives a new object rather than
20
+ * mutating this one, so it is safe for nested and concurrent work.
21
+ */
22
+ scope(overrides?: GasOverrides): ReadOnlyFlowrAnalyzerGasContext;
23
+ }
24
+ /**
25
+ * The gas context as the owner of the analyzer sees it, reachable via `analyzer.context().gas`.
26
+ * Adds the operations that restart a contingent to {@link ReadOnlyFlowrAnalyzerGasContext}.
27
+ */
28
+ export interface WriteableFlowrAnalyzerGasContext extends ReadOnlyFlowrAnalyzerGasContext {
29
+ /** see {@link FlowrAnalyzerGasContext#reset} */
30
+ reset(): void;
31
+ /** see {@link FlowrAnalyzerGasContext#withGas} */
32
+ withGas<T>(overrides: GasOverrides | undefined, fn: () => T): T;
13
33
  }
14
34
  /** Checks heap and elapsed-time pressure for named analysis features. See {@link ReadOnlyFlowrAnalyzerGasContext}. */
15
- export declare class FlowrAnalyzerGasContext implements ReadOnlyFlowrAnalyzerGasContext {
35
+ export declare class FlowrAnalyzerGasContext implements WriteableFlowrAnalyzerGasContext, InvalidationEventReceiver {
16
36
  readonly name = "flowr-analyzer-gas-context";
17
- private startTime;
37
+ /** what a gas check falls back to when no operation declared a contingent of its own */
38
+ private readonly base;
39
+ /** the contingents of the operations in flight, innermost last */
40
+ private readonly frames;
18
41
  private readonly config;
19
42
  private readonly ctx;
20
43
  private readonly plugins;
21
44
  constructor(ctx: FlowrAnalyzerContext, config: FlowrGasConfig | undefined, plugins: readonly FlowrAnalyzerGasPlugin[]);
22
- /** Restart the elapsed-time counter (called when the owning context is reset). */
45
+ /**
46
+ * Restart the contingent, so what follows is measured from now. Supported API: call it between phases
47
+ * that should each get the full allowance (`analyzer.context().gas.reset()`).
48
+ *
49
+ * flowR calls it itself whenever a new analysis begins, so a caller only has to split its *own* phases.
50
+ * Operations in flight keep their contingent, as restarting a running traversal's clock would defeat the
51
+ * guard bounding it.
52
+ */
23
53
  reset(): void;
54
+ /** A new analysis makes the spent contingent irrelevant. */
55
+ receive(_event: InvalidationEvent): void;
56
+ /**
57
+ * Run `fn` against a fresh contingent bounded by `overrides`, ending when it settles if `fn` is async.
58
+ * Every check while `fn` runs sees it, however deep, which is how the bounds reach sites that only ever
59
+ * get a context handed to them.
60
+ *
61
+ * Being ambient, concurrent operations on one analyzer see whichever started last, so prefer
62
+ * {@link scope} wherever the context can be threaded through.
63
+ */
64
+ withGas<T>(overrides: GasOverrides | undefined, fn: () => T): T;
65
+ scope(overrides?: GasOverrides): ReadOnlyFlowrAnalyzerGasContext;
66
+ private derive;
67
+ private viewOf;
68
+ private drop;
69
+ private activeScope;
70
+ /**
71
+ * The innermost layer stating this bound wins, the configured thresholds apply when none does.
72
+ * Resolved per bound, so a layer naming only `critical` leaves `problematic` to the layer outside it.
73
+ */
74
+ private bound;
75
+ /** An override naming the feature enables it even when the config disables it. */
76
+ private factorFor;
24
77
  private memoryLevel;
25
78
  private static maxLevel;
26
79
  private timeLevel;
27
80
  checkGas(key: string): GasLevel;
81
+ private levelFor;
28
82
  }
@@ -28,10 +28,39 @@ function tryGetHeapStatistics() {
28
28
  }
29
29
  return heapStatisticsProvider ? heapStatisticsProvider() : undefined;
30
30
  }
31
+ function isPair(v) {
32
+ return typeof v === 'object' && v !== null;
33
+ }
34
+ /** feature entry, then `default`, then the shared pair */
35
+ function configuredBound(spec, feature, bound) {
36
+ const own = spec?.[feature];
37
+ if (isPair(own) && own[bound] !== undefined) {
38
+ return own[bound];
39
+ }
40
+ const fallback = spec?.default?.[bound];
41
+ if (fallback !== undefined) {
42
+ return fallback;
43
+ }
44
+ const shared = spec?.[bound];
45
+ return typeof shared === 'number' ? shared : undefined;
46
+ }
47
+ /** a bare number is an elapsed-time bound in ms */
48
+ function overriddenBound(entry, dim, bound) {
49
+ return entry?.[dim]?.[bound] ?? (dim === 'timeMs' ? entry?.[bound] : undefined);
50
+ }
51
+ function entryOf(layer, key) {
52
+ return layer[key] ?? layer.default;
53
+ }
54
+ function isThenable(v) {
55
+ return typeof v?.then === 'function';
56
+ }
31
57
  /** Checks heap and elapsed-time pressure for named analysis features. See {@link ReadOnlyFlowrAnalyzerGasContext}. */
32
58
  class FlowrAnalyzerGasContext {
33
59
  name = 'flowr-analyzer-gas-context';
34
- startTime;
60
+ /** what a gas check falls back to when no operation declared a contingent of its own */
61
+ base;
62
+ /** the contingents of the operations in flight, innermost last */
63
+ frames = [];
35
64
  config;
36
65
  ctx;
37
66
  plugins;
@@ -39,22 +68,113 @@ class FlowrAnalyzerGasContext {
39
68
  this.ctx = ctx;
40
69
  this.config = config;
41
70
  this.plugins = plugins;
42
- this.startTime = Date.now();
71
+ this.base = { startTime: Date.now(), layers: [] };
43
72
  }
44
- /** Restart the elapsed-time counter (called when the owning context is reset). */
73
+ /**
74
+ * Restart the contingent, so what follows is measured from now. Supported API: call it between phases
75
+ * that should each get the full allowance (`analyzer.context().gas.reset()`).
76
+ *
77
+ * flowR calls it itself whenever a new analysis begins, so a caller only has to split its *own* phases.
78
+ * Operations in flight keep their contingent, as restarting a running traversal's clock would defeat the
79
+ * guard bounding it.
80
+ */
45
81
  reset() {
46
- this.startTime = Date.now();
82
+ this.base.startTime = Date.now();
83
+ }
84
+ /** A new analysis makes the spent contingent irrelevant. */
85
+ receive(_event) {
86
+ this.reset();
87
+ }
88
+ /**
89
+ * Run `fn` against a fresh contingent bounded by `overrides`, ending when it settles if `fn` is async.
90
+ * Every check while `fn` runs sees it, however deep, which is how the bounds reach sites that only ever
91
+ * get a context handed to them.
92
+ *
93
+ * Being ambient, concurrent operations on one analyzer see whichever started last, so prefer
94
+ * {@link scope} wherever the context can be threaded through.
95
+ */
96
+ withGas(overrides, fn) {
97
+ const frame = this.derive(overrides);
98
+ this.frames.push(frame);
99
+ let result;
100
+ try {
101
+ result = fn();
102
+ }
103
+ catch (e) {
104
+ this.drop(frame);
105
+ throw e;
106
+ }
107
+ if (isThenable(result)) {
108
+ return result.then(v => {
109
+ this.drop(frame);
110
+ return v;
111
+ }, (e) => {
112
+ this.drop(frame);
113
+ throw e;
114
+ });
115
+ }
116
+ this.drop(frame);
117
+ return result;
118
+ }
119
+ scope(overrides) {
120
+ return this.viewOf(this.derive(overrides));
47
121
  }
48
- memoryLevel(factor, t) {
122
+ derive(overrides, from) {
123
+ const inherited = (from ?? this.activeScope()).layers;
124
+ return { startTime: Date.now(), layers: overrides ? [...inherited, overrides] : inherited };
125
+ }
126
+ viewOf(scope) {
127
+ return {
128
+ name: `${this.name}:scope`,
129
+ checkGas: key => this.levelFor(key, scope),
130
+ scope: o => this.viewOf(this.derive(o, scope))
131
+ };
132
+ }
133
+ drop(frame) {
134
+ const idx = this.frames.lastIndexOf(frame);
135
+ if (idx >= 0) {
136
+ this.frames.splice(idx, 1);
137
+ }
138
+ }
139
+ activeScope() {
140
+ return this.frames.length > 0 ? this.frames[this.frames.length - 1] : this.base;
141
+ }
142
+ /**
143
+ * The innermost layer stating this bound wins, the configured thresholds apply when none does.
144
+ * Resolved per bound, so a layer naming only `critical` leaves `problematic` to the layer outside it.
145
+ */
146
+ bound(scope, key, dim, bound) {
147
+ for (let i = scope.layers.length - 1; i >= 0; i--) {
148
+ const stated = overriddenBound(entryOf(scope.layers[i], key), dim, bound);
149
+ if (stated !== undefined) {
150
+ return stated;
151
+ }
152
+ }
153
+ return configuredBound(this.config?.thresholds?.[dim], key, bound) ?? Number.POSITIVE_INFINITY;
154
+ }
155
+ /** An override naming the feature enables it even when the config disables it. */
156
+ factorFor(scope, key) {
157
+ const configured = this.config?.features?.[key] ?? 0;
158
+ let named = false;
159
+ for (let i = scope.layers.length - 1; i >= 0; i--) {
160
+ const entry = entryOf(scope.layers[i], key);
161
+ if (entry?.factor !== undefined) {
162
+ return entry.factor;
163
+ }
164
+ named ||= entry !== undefined;
165
+ }
166
+ return named ? configured || 1 : configured;
167
+ }
168
+ memoryLevel(factor, key, scope) {
49
169
  const stats = this.config?.heapProvider ? this.config.heapProvider() : tryGetHeapStatistics();
50
170
  if (stats === undefined || stats.heap_size_limit <= 0) {
51
171
  return 0 /* GasLevel.Normal */;
52
172
  }
53
173
  const ratio = (stats.used_heap_size / stats.heap_size_limit) * factor;
54
- if (ratio >= t.memory.critical) {
174
+ if (ratio >= this.bound(scope, key, 'memory', 'critical')) {
55
175
  return 2 /* GasLevel.Critical */;
56
176
  }
57
- if (ratio >= t.memory.problematic) {
177
+ if (ratio >= this.bound(scope, key, 'memory', 'problematic')) {
58
178
  return 1 /* GasLevel.Problematic */;
59
179
  }
60
180
  return 0 /* GasLevel.Normal */;
@@ -62,27 +182,29 @@ class FlowrAnalyzerGasContext {
62
182
  static maxLevel(a, b) {
63
183
  return a >= b ? a : b;
64
184
  }
65
- timeLevel(factor, t) {
66
- const elapsed = (Date.now() - this.startTime) * factor;
67
- if (elapsed >= t.timeMs.critical) {
185
+ timeLevel(factor, key, scope) {
186
+ const elapsed = (Date.now() - scope.startTime) * factor;
187
+ if (elapsed >= this.bound(scope, key, 'timeMs', 'critical')) {
68
188
  return 2 /* GasLevel.Critical */;
69
189
  }
70
- if (elapsed >= t.timeMs.problematic) {
190
+ if (elapsed >= this.bound(scope, key, 'timeMs', 'problematic')) {
71
191
  return 1 /* GasLevel.Problematic */;
72
192
  }
73
193
  return 0 /* GasLevel.Normal */;
74
194
  }
75
195
  checkGas(key) {
76
- const factor = this.config?.features?.[key];
196
+ return this.levelFor(key, this.activeScope());
197
+ }
198
+ levelFor(key, scope) {
199
+ const factor = this.factorFor(scope, key);
77
200
  if (!factor && this.plugins.length === 0) {
78
201
  return 0 /* GasLevel.Normal */;
79
202
  }
80
203
  let level = 0 /* GasLevel.Normal */;
81
204
  if (factor) {
82
- const t = this.config.thresholds;
83
- level = FlowrAnalyzerGasContext.maxLevel(level, this.memoryLevel(factor, t));
205
+ level = FlowrAnalyzerGasContext.maxLevel(level, this.memoryLevel(factor, key, scope));
84
206
  if (level < 2 /* GasLevel.Critical */) {
85
- level = FlowrAnalyzerGasContext.maxLevel(level, this.timeLevel(factor, t));
207
+ level = FlowrAnalyzerGasContext.maxLevel(level, this.timeLevel(factor, key, scope));
86
208
  }
87
209
  }
88
210
  for (const plugin of this.plugins) {
@@ -19,6 +19,19 @@ import type { FlowrFileProvider } from './context/flowr-file';
19
19
  import type { Tree } from 'web-tree-sitter';
20
20
  import type { CallGraph } from '../dataflow/graph/call-graph';
21
21
  import type { InvalidationEvent } from './cache/flowr-cache';
22
+ import type { GasOverrides } from '../gas';
23
+ /** Options for a single analyzer operation, bounding what it may cost. */
24
+ export interface FlowrAnalysisOptions {
25
+ /**
26
+ * Gas bounds for this call (see {@link GasOverrides}), measured from it rather than against whatever the
27
+ * analyzer already spent, and winning over `config.gas.thresholds` for its duration:
28
+ *
29
+ * ```ts
30
+ * analyzer.query([...], { gas: { slicer: { critical: 30_000 } } });
31
+ * ```
32
+ */
33
+ readonly gas?: GasOverrides;
34
+ }
22
35
  /**
23
36
  * Extends the {@link ReadonlyFlowrAnalysisProvider} with methods that allow modifying the analyzer state.
24
37
  */
@@ -133,17 +146,22 @@ export interface ReadonlyFlowrAnalysisProvider<Parser extends KnownParser = Know
133
146
  peekCallGraph(): CallGraph | undefined;
134
147
  /**
135
148
  * Access the query API for the request.
136
- * @param query - The list of queries.
149
+ * @param query - The list of queries.
150
+ * @param options - Bounds for this call, see {@link FlowrAnalysisOptions}.
137
151
  */
138
- query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>): Promise<QueryResults<Types>>;
152
+ query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>, options?: FlowrAnalysisOptions): Promise<QueryResults<Types>>;
139
153
  /**
140
154
  * Run a search on the current analysis.
155
+ * @param search - The search to run.
156
+ * @param options - Bounds for this call, see {@link FlowrAnalysisOptions}.
141
157
  */
142
- runSearch<Search extends FlowrSearchLike>(search: Search): Promise<GetSearchElements<SearchOutput<Search>>>;
158
+ runSearch<Search extends FlowrSearchLike>(search: Search, options?: FlowrAnalysisOptions): Promise<GetSearchElements<SearchOutput<Search>>>;
143
159
  /**
144
160
  * This executes all steps of the core analysis (parse, normalize, dataflow).
161
+ * @param force - Do not use the cache, instead force a new analysis.
162
+ * @param options - Bounds for this call, see {@link FlowrAnalysisOptions}.
145
163
  */
146
- runFull(force?: boolean): Promise<void>;
164
+ runFull(force?: boolean, options?: FlowrAnalysisOptions): Promise<void>;
147
165
  /** This is the config used for the analyzer */
148
166
  flowrConfig: FlowrConfig;
149
167
  /** Merge a runtime update into the base config and invalidate the derived config and cached analysis, so it takes effect. */
@@ -202,13 +220,13 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
202
220
  peekNormalize(): NonNullable<AnalyzerCacheType<Parser>['normalize']> | undefined;
203
221
  dataflow(force?: boolean): Promise<NonNullable<AnalyzerCacheType<Parser>['dataflow']>>;
204
222
  peekDataflow(): NonNullable<AnalyzerCacheType<Parser>['dataflow']> | undefined;
205
- runFull(force?: boolean): Promise<void>;
223
+ runFull(force?: boolean, options?: FlowrAnalysisOptions): Promise<void>;
206
224
  controlflow(simplifications?: readonly CfgSimplificationPassName[], kind?: CfgKind, force?: boolean): Promise<ControlFlowInformation>;
207
225
  peekControlflow(simplifications?: readonly CfgSimplificationPassName[], kind?: CfgKind): ControlFlowInformation | undefined;
208
226
  callGraph(force?: boolean): Promise<CallGraph>;
209
227
  peekCallGraph(): CallGraph | undefined;
210
- query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>): Promise<QueryResults<Types>>;
211
- runSearch<Search extends FlowrSearchLike>(search: Search): Promise<GetSearchElements<SearchOutput<Search>>>;
228
+ query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>, options?: FlowrAnalysisOptions): Promise<QueryResults<Types>>;
229
+ runSearch<Search extends FlowrSearchLike>(search: Search, options?: FlowrAnalysisOptions): Promise<GetSearchElements<SearchOutput<Search>>>;
212
230
  /**
213
231
  * Free the cached analyses (including any WASM-backed parse trees) and close the parser.
214
232
  * Closing is only required for an RShell/remote engine, but this also frees the cached parse trees.
@@ -136,8 +136,8 @@ class FlowrAnalyzer {
136
136
  peekDataflow() {
137
137
  return this.cache.peekDataflow();
138
138
  }
139
- async runFull(force) {
140
- await this.dataflow(force);
139
+ async runFull(force, options) {
140
+ await this.ctx.gas.withGas(options?.gas, () => this.dataflow(force));
141
141
  return;
142
142
  }
143
143
  async controlflow(simplifications, kind, force) {
@@ -152,11 +152,11 @@ class FlowrAnalyzer {
152
152
  peekCallGraph() {
153
153
  return this.cache.peekCallGraph();
154
154
  }
155
- async query(query) {
156
- return (0, query_1.executeQueries)({ analyzer: this }, query);
155
+ async query(query, options) {
156
+ return this.ctx.gas.withGas(options?.gas, () => (0, query_1.executeQueries)({ analyzer: this }, query));
157
157
  }
158
- async runSearch(search) {
159
- return (0, flowr_search_executor_1.runSearch)(search, this);
158
+ async runSearch(search, options) {
159
+ return this.ctx.gas.withGas(options?.gas, () => (0, flowr_search_executor_1.runSearch)(search, this));
160
160
  }
161
161
  /**
162
162
  * Free the cached analyses (including any WASM-backed parse trees) and close the parser.
@@ -66,6 +66,16 @@ function makeTreeSitterStrict() {
66
66
  log_1.log.info('[Tree-Sitter] Strict parsing active');
67
67
  nonErrorChildren = nonErrorChildrenStrict;
68
68
  }
69
+ function makeDefaultInfo(node, fullRange, fullLexeme) {
70
+ return {
71
+ info: {
72
+ fullRange,
73
+ adToks: [],
74
+ fullLexeme,
75
+ tsId: node.id
76
+ }
77
+ };
78
+ }
69
79
  function convertTreeNode(node) {
70
80
  if (!node) {
71
81
  return {
@@ -91,17 +101,9 @@ function convertTreeNode(node) {
91
101
  textCache ??= node.text;
92
102
  return textCache;
93
103
  };
94
- const makeDefaultInfo = () => ({
95
- info: {
96
- fullRange: range,
97
- adToks: [],
98
- fullLexeme: text(),
99
- tsId: node.id
100
- }
101
- });
102
104
  let defaultInfoCache = undefined;
103
105
  const defaultInfo = () => {
104
- defaultInfoCache ??= makeDefaultInfo();
106
+ defaultInfoCache ??= makeDefaultInfo(node, range, text());
105
107
  return defaultInfoCache;
106
108
  };
107
109
  switch (node.type) {
@@ -11,7 +11,7 @@ const fingerprint_1 = require("./fingerprint");
11
11
  const linker_1 = require("../../dataflow/internal/linker");
12
12
  const vertex_1 = require("../../dataflow/graph/vertex");
13
13
  const graph_1 = require("../../dataflow/graph/graph");
14
- const resolve_by_name_1 = require("../../dataflow/environments/resolve-by-name");
14
+ const resolve_helper_1 = require("../../dataflow/environments/resolve-helper");
15
15
  const edge_1 = require("../../dataflow/graph/edge");
16
16
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
17
17
  const identifier_1 = require("../../dataflow/environments/identifier");
@@ -30,7 +30,7 @@ function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnviro
30
30
  const activeEnvironment = (0, built_in_function_definition_1.retrieveActiveEnvironment)(callerInfo.environment, baseEnvironment, ctx);
31
31
  const name = callerInfo.name;
32
32
  (0, assert_1.guard)(name !== undefined, () => `name of id: ${callerInfo.id} can not be found in id map`);
33
- const functionCallDefs = (0, resolve_by_name_1.resolveByNameAnyType)(name, activeEnvironment)?.filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt))?.map(d => d.nodeId) ?? [];
33
+ const functionCallDefs = resolve_helper_1.Resolve.byName(name, activeEnvironment)?.filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt))?.map(d => d.nodeId) ?? [];
34
34
  for (const [target, outgoingEdge] of outgoingEdges[1].entries()) {
35
35
  if (edge_1.DfEdge.includesType(outgoingEdge, edge_1.EdgeType.Calls)) {
36
36
  functionCallDefs.push(target);
@@ -56,7 +56,7 @@ function linkCallTargets(onlyForSideEffects, functionCallTargets, activeEnvironm
56
56
  for (const openIn of functionCallTarget.subflow.in) {
57
57
  // resolve them in the active env
58
58
  if (openIn.name) {
59
- const resolved = (0, resolve_by_name_1.resolveByNameAnyType)(openIn.name, activeEnvironment);
59
+ const resolved = resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment);
60
60
  for (const res of resolved ?? []) {
61
61
  (0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint);
62
62
  }
@@ -139,7 +139,7 @@ function sliceReachesFunctionInterface(fnDefId, graph, queue, idMap, ctx) {
139
139
  if (open.name === undefined || !queue.hasId(open.nodeId)) {
140
140
  continue;
141
141
  }
142
- const resolved = (0, resolve_by_name_1.resolveByName)(open.name, definitionEnvironment, open.type ?? identifier_1.ReferenceType.Unknown);
142
+ const resolved = resolve_helper_1.Resolve.byNameAndType(open.name, definitionEnvironment, open.type ?? identifier_1.ReferenceType.Unknown);
143
143
  if (resolved?.some(d => !node_id_1.NodeId.isBuiltIn(d.nodeId))) {
144
144
  return true;
145
145
  }
@@ -13,6 +13,17 @@ export interface NodeToSlice {
13
13
  /** if we add a function call, we may need it only for its side effects (e.g., a redefinition of a global variable), if so, 'returns' links will not be traced */
14
14
  readonly onlyForSideEffects: boolean;
15
15
  }
16
+ /**
17
+ * How far a traversal got before it was cut short, so a caller can judge a truncated slice instead of
18
+ * having to drop it: a `frontier` of `0` means the queue drained after all, and a small `frontier` next to
19
+ * a large `visited` says little is missing.
20
+ */
21
+ export interface SliceProgress {
22
+ /** queue entries the traversal expanded */
23
+ readonly visited: number;
24
+ /** entries still queued when it stopped */
25
+ readonly frontier: number;
26
+ }
16
27
  /**
17
28
  * The result of the slice step
18
29
  */
@@ -36,6 +47,8 @@ export interface SliceResult {
36
47
  * {@link result} is what was reached until then and not the complete slice.
37
48
  */
38
49
  readonly stoppedEarly?: boolean;
50
+ /** How far the traversal got, set exactly when {@link stoppedEarly} is. */
51
+ readonly progress?: SliceProgress;
39
52
  /**
40
53
  * The names the slice reads without defining them, so running it on its own would fail with
41
54
  * `object 'x' not found`. Empty when the slice is closed under the names it uses.
@@ -8,6 +8,7 @@ import type { DataflowInformation } from '../../dataflow/info';
8
8
  import type { DataflowGraph } from '../../dataflow/graph/graph';
9
9
  import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
10
10
  import { SliceDirection } from '../../util/slice-direction';
11
+ import type { GasOverrides } from '../../gas';
11
12
  export declare const slicerLogger: import("tslog").Logger<import("tslog").ILogObj>;
12
13
  /** Options for {@link staticSlice}. */
13
14
  export interface StaticSliceOptions {
@@ -41,6 +42,11 @@ export interface StaticSliceOptions {
41
42
  * Defaults to `false` (slicing stops at the function-definition boundary, the historic behavior).
42
43
  */
43
44
  readonly includeCallees?: boolean;
45
+ /**
46
+ * Gas bounds for this slice (see {@link GasOverrides}), on top of the enclosing operation's.
47
+ * A slice always gets a contingent of its own, so it is never billed for the analysis or the slices before it.
48
+ */
49
+ readonly gas?: GasOverrides;
44
50
  }
45
51
  /**
46
52
  * Computes the node ids to include in a static slice, starting from the given seed ids.
@@ -55,7 +61,7 @@ export declare function staticSlice(options: StaticSliceOptions): Readonly<Slice
55
61
  * reduced to that set and its edges are inverted in a single pass via {@link Dataflow.reduceAndInvertGraph}.
56
62
  * The forward traversal then runs only within that subgraph, avoiding nodes that cannot contribute to the dice.
57
63
  */
58
- export declare function staticDice(ctx: ReadOnlyFlowrAnalyzerContext, info: DataflowInformation, ast: NormalizedAst, startIds: readonly NodeId[], endIds: readonly NodeId[], threshold?: number, includeCallees?: boolean): Readonly<SliceResult>;
64
+ export declare function staticDice(ctx: ReadOnlyFlowrAnalyzerContext, info: DataflowInformation, ast: NormalizedAst, startIds: readonly NodeId[], endIds: readonly NodeId[], threshold?: number, includeCallees?: boolean, gas?: GasOverrides): Readonly<SliceResult>;
59
65
  /**
60
66
  * Updates the potential addition for the given target node in the visiting queue.
61
67
  * This describes vertices that might be added *if* another path reaches them.
@@ -40,7 +40,7 @@ function staticSlice(options) {
40
40
  graph = df_helper_1.Dataflow.invertGraph(graph, ctx.env.makeCleanEnv());
41
41
  }
42
42
  }
43
- const queue = new visiting_queue_1.VisitingQueue(threshold, cache, id => graph.hasVertex(id), ctx.gas);
43
+ const queue = new visiting_queue_1.VisitingQueue(threshold, cache, id => graph.hasVertex(id), ctx.gas.scope(options.gas));
44
44
  let minNesting = Number.MAX_SAFE_INTEGER;
45
45
  const sliceSeedIds = new Set();
46
46
  // every node ships the call environment which registers the calling environment
@@ -176,12 +176,12 @@ function freeNamesOf(slice, graph) {
176
176
  * reduced to that set and its edges are inverted in a single pass via {@link Dataflow.reduceAndInvertGraph}.
177
177
  * The forward traversal then runs only within that subgraph, avoiding nodes that cannot contribute to the dice.
178
178
  */
179
- function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCallees = false) {
179
+ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCallees = false, gas) {
180
180
  (0, assert_1.guard)(startIds.length > 0 && endIds.length > 0, 'must have at least one start and one end id for dicing');
181
- const backward = staticSlice({ ctx, info, ast, ids: endIds, direction: slice_direction_1.SliceDirection.Backward, threshold, includeCallees });
181
+ const backward = staticSlice({ ctx, info, ast, ids: endIds, direction: slice_direction_1.SliceDirection.Backward, threshold, includeCallees, gas });
182
182
  // reduce to backward result and invert edges in one pass; original info kept for sliceForCall
183
183
  const invertedReduced = df_helper_1.Dataflow.reduceAndInvertGraph(info.graph, backward.result, ctx.env.makeCleanEnv());
184
- const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph: invertedReduced });
184
+ const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph: invertedReduced, gas });
185
185
  // explicit intersection handles seed nodes that landed outside the reduced graph
186
186
  const result = new Set();
187
187
  for (const id of forward.result) {
@@ -193,7 +193,13 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
193
193
  timesHitThreshold: forward.timesHitThreshold + backward.timesHitThreshold,
194
194
  result,
195
195
  slicedFor: [...startIds, ...endIds],
196
- ...(forward.stoppedEarly || backward.stoppedEarly ? { stoppedEarly: true } : {})
196
+ ...(forward.stoppedEarly || backward.stoppedEarly ? {
197
+ stoppedEarly: true,
198
+ progress: {
199
+ visited: (forward.progress?.visited ?? 0) + (backward.progress?.visited ?? 0),
200
+ frontier: (forward.progress?.frontier ?? 0) + (backward.progress?.frontier ?? 0)
201
+ }
202
+ } : {})
197
203
  };
198
204
  }
199
205
  function extendSlices(results, ast) {
@@ -19,6 +19,8 @@ export declare class VisitingQueue {
19
19
  private readonly gas?;
20
20
  private stoppedEarly;
21
21
  private untilGasCheck;
22
+ /** entries dequeued, see {@link SliceProgress} */
23
+ private visited;
22
24
  constructor(threshold: number, cache?: Map<Fingerprint, Set<NodeId>>, isGraphVertex?: (id: NodeId) => boolean, gas?: ReadOnlyFlowrAnalyzerGasContext);
23
25
  /**
24
26
  * Adds a node to the queue if it has not been seen before.
@@ -38,5 +40,5 @@ export declare class VisitingQueue {
38
40
  private outOfGas;
39
41
  hasId(id: NodeId): boolean;
40
42
  memoizeCallTargets(id: NodeId, targets: () => Set<DataflowGraphVertexInfo>): Set<DataflowGraphVertexInfo>;
41
- status(): Readonly<Pick<SliceResult, 'timesHitThreshold' | 'result' | 'stoppedEarly'>>;
43
+ status(): Readonly<Pick<SliceResult, 'timesHitThreshold' | 'result' | 'stoppedEarly' | 'progress'>>;
42
44
  }
@@ -24,6 +24,8 @@ class VisitingQueue {
24
24
  gas;
25
25
  stoppedEarly = false;
26
26
  untilGasCheck = 0;
27
+ /** entries dequeued, see {@link SliceProgress} */
28
+ visited = 0;
27
29
  constructor(threshold, cache, isGraphVertex, gas) {
28
30
  this.threshold = threshold;
29
31
  this.cache = cache;
@@ -64,6 +66,7 @@ class VisitingQueue {
64
66
  }
65
67
  }
66
68
  next() {
69
+ this.visited++;
67
70
  return this.queue.pop();
68
71
  }
69
72
  /** Whether there is anything left to visit, which the traversal is out of gas for as soon as it is exhausted. */
@@ -98,7 +101,7 @@ class VisitingQueue {
98
101
  return {
99
102
  timesHitThreshold: this.timesHitThreshold,
100
103
  result: new Set([...this.seen.values(), ...this.seenByCache]),
101
- ...(this.stoppedEarly ? { stoppedEarly: true } : {})
104
+ ...(this.stoppedEarly ? { stoppedEarly: true, progress: { visited: this.visited, frontier: this.queue.length } } : {})
102
105
  };
103
106
  }
104
107
  }
@@ -0,0 +1,4 @@
1
+ /** The `engines.node` range of the package.json, e.g. `>=22`. */
2
+ export declare function supportedNodeVersions(): string;
3
+ /** The oldest major node version flowR runs on, derived from {@link supportedNodeVersions}. */
4
+ export declare function minimumNodeMajor(): number;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.supportedNodeVersions = supportedNodeVersions;
7
+ exports.minimumNodeMajor = minimumNodeMajor;
8
+ /**
9
+ * The node version flowR requires, taken from the `engines.node` field of the package.json so that the
10
+ * package manager, the setup script, and the documentation all state the same thing.
11
+ * @module
12
+ */
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const path_1 = __importDefault(require("path"));
15
+ let cached = undefined;
16
+ /** The `engines.node` range of the package.json, e.g. `>=22`. */
17
+ function supportedNodeVersions() {
18
+ if (cached === undefined) {
19
+ const raw = fs_1.default.readFileSync(path_1.default.join(__dirname, '..', '..', 'package.json'), 'utf-8');
20
+ const { engines } = JSON.parse(raw);
21
+ cached = engines?.node ?? '>=22';
22
+ }
23
+ return cached;
24
+ }
25
+ /** The oldest major node version flowR runs on, derived from {@link supportedNodeVersions}. */
26
+ function minimumNodeMajor() {
27
+ return Number(/\d+/.exec(supportedNodeVersions())?.[0] ?? 22);
28
+ }
29
+ //# sourceMappingURL=node-version.js.map
package/util/version.js CHANGED
@@ -42,7 +42,7 @@ const assert_1 = require("./assert");
42
42
  const sigdb_download_1 = require("../project/sigdb/sigdb-download");
43
43
  const doc_files_1 = require("../documentation/doc-util/doc-files");
44
44
  // this is automatically replaced with the current version by release-it
45
- const version = '2.13.12';
45
+ const version = '2.13.14';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
47
  const versionDate = '2026-07-15T07:13:44Z';
48
48
  /**