@eagleoutice/flowr 2.17.0 → 2.17.2
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.
- package/README.md +8 -8
- package/config.d.ts +32 -0
- package/config.js +22 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/dataflow/environments/ambient-state-name.d.ts +4 -0
- package/dataflow/environments/ambient-state-name.js +4 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in-props.d.ts +18 -2
- package/dataflow/environments/built-in-props.js +26 -4
- package/dataflow/environments/built-in.d.ts +16 -6
- package/dataflow/environments/built-in.js +58 -7
- package/dataflow/environments/default-builtin-config.d.ts +1245 -159
- package/dataflow/environments/default-builtin-config.js +191 -38
- package/dataflow/environments/environment.d.ts +19 -2
- package/dataflow/environments/environment.js +90 -19
- package/dataflow/environments/identifier.d.ts +25 -1
- package/dataflow/environments/query-fn-props.js +4 -3
- package/dataflow/environments/resolve-by-name.js +5 -3
- package/dataflow/eval/resolve/node-value.d.ts +1 -1
- package/dataflow/eval/resolve/node-value.js +2 -2
- package/dataflow/eval/resolve/resolve-argument.js +1 -1
- package/dataflow/extractor.js +68 -17
- package/dataflow/fn/function-semantics.d.ts +1 -0
- package/dataflow/graph/df-helper.d.ts +34 -1
- package/dataflow/graph/df-helper.js +60 -0
- package/dataflow/info.d.ts +2 -0
- package/dataflow/info.js +4 -0
- package/dataflow/internal/linker.js +21 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +3 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +18 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +144 -30
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +10 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +8 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +43 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +67 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +27 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +2 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +1 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +134 -88
- package/dataflow/internal/process/functions/call/built-in/built-in-load.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +87 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +23 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +18 -15
- package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +8 -7
- package/documentation/wiki-dataflow-graph.js +20 -1
- package/linter/rules/network-functions.js +10 -2
- package/linter/rules/undefined-symbol.js +2 -2
- package/linter/rules/unused-import.js +11 -1
- package/package.json +1 -1
- package/project/attached-packages.d.ts +11 -6
- package/project/attached-packages.js +37 -9
- package/project/cache/flowr-analyzer-cache.d.ts +4 -0
- package/project/cache/flowr-analyzer-cache.js +11 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
- package/project/context/flowr-analyzer-dependencies-context.js +6 -0
- package/project/context/flowr-file.d.ts +2 -2
- package/project/context/flowr-file.js +2 -2
- package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
- package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
- package/project/plugins/plugin-registry.d.ts +5 -4
- package/project/plugins/plugin-registry.js +6 -0
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
- package/project/sigdb/decode.js +13 -3
- package/project/sigdb/memory-source.d.ts +6 -4
- package/project/sigdb/memory-source.js +6 -5
- package/project/sigdb/on-demand/fetch.d.ts +18 -0
- package/project/sigdb/on-demand/fetch.js +127 -0
- package/project/sigdb/on-demand/package-sources.d.ts +40 -0
- package/project/sigdb/on-demand/package-sources.js +263 -0
- package/project/sigdb/on-demand/recoverer.d.ts +40 -0
- package/project/sigdb/on-demand/recoverer.js +169 -0
- package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
- package/project/sigdb/on-demand/remote-sources.js +132 -0
- package/project/sigdb/on-demand/tar.d.ts +19 -0
- package/project/sigdb/on-demand/tar.js +119 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +5 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
- package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
- package/queries/catalog/signature-query/signature-query-executor.js +15 -1
- package/queries/catalog/signature-query/signature-query-format.d.ts +3 -2
- package/r-bridge/data/data.d.ts +31 -2
- package/r-bridge/data/data.js +25 -2
- package/r-bridge/lang-4.x/ast/model/model.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/model.js +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +12 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -0
- package/reconstruct/reconstruct.js +2 -5
- package/search/search-executor/search-enrichers.js +17 -2
- package/search/search-executor/search-generators.js +6 -2
- package/slicing/static/slice-call.d.ts +16 -0
- package/slicing/static/slice-call.js +42 -0
- package/slicing/static/static-slicer.js +6 -0
- package/taint-analysis/predefined/secret-analysis.js +7 -2
- package/taint-analysis/taint-mapping.d.ts +5 -2
- package/taint-analysis/taint-mapping.js +17 -6
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/r-version.js +4 -2
|
@@ -27,7 +27,9 @@ export declare enum EnvType {
|
|
|
27
27
|
/** `requireNamespace("pkg")`: `pkg::fn` resolves, bare `fn` does not */
|
|
28
28
|
LoadedNamespace = "lns",
|
|
29
29
|
/** A package `solver.assumeAttachedPackages` states as attached; a `library()` in the analyzed code still attaches it in full over this. */
|
|
30
|
-
AssumedNamespace = "ans"
|
|
30
|
+
AssumedNamespace = "ans",
|
|
31
|
+
/** Data `attach(what)` put on the search path, a list, data frame, or environment */
|
|
32
|
+
Attached = "att"
|
|
31
33
|
}
|
|
32
34
|
interface Jsonified {
|
|
33
35
|
id: NodeId;
|
|
@@ -129,7 +131,11 @@ export declare class Environment implements IEnvironment {
|
|
|
129
131
|
* memories have to be merged. Package blocks are always unioned, never overwritten or appended to.
|
|
130
132
|
*/
|
|
131
133
|
private mergeShortcut;
|
|
132
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Unions two attached-package blocks, keeping every package once (memory merged for a package in both).
|
|
136
|
+
* A package only one block has is only maybe attached if the blocks are alternatives (appended: two branches, a
|
|
137
|
+
* loop body that may not run), or under `applyCds` if only `other` has it (a call in a branch attaching it).
|
|
138
|
+
*/
|
|
133
139
|
private mergePackageBlocks;
|
|
134
140
|
remove(id: Identifier): this;
|
|
135
141
|
removeAll(names: readonly {
|
|
@@ -156,6 +162,13 @@ export declare const GlobalEnvEntryName = ".GlobalEnv";
|
|
|
156
162
|
* ({@link DefaultAttachPosition|2} by default); a position past the end attaches above the built-in env, mirroring R's clamping.
|
|
157
163
|
*/
|
|
158
164
|
declare function attachPackageAt(this: void, current: Environment, blockTop: Environment, blockBottom: Environment, pos?: number): Environment;
|
|
165
|
+
/** Removes the entry at the 1-based `search()` position `pos` (`detach`), with its imports layer; `current` itself if there is none. */
|
|
166
|
+
declare function detachPackageAt(this: void, current: Environment, pos?: number): Environment;
|
|
167
|
+
/**
|
|
168
|
+
* `target` with the packages `source` attached as well: the search path is global, so what code evaluated in
|
|
169
|
+
* another environment attaches (`local(library(x), envir = e)`) is attached for the caller, too.
|
|
170
|
+
*/
|
|
171
|
+
declare function adoptSearchPathOf(this: void, target: Environment, source: Environment): Environment;
|
|
159
172
|
/**
|
|
160
173
|
* The 1-based `search()` position of the entry called `name` (`.GlobalEnv`, `package:x`, or a bare package name), or
|
|
161
174
|
* `undefined` if absent; `package:base` resolves to the built-in env at the bottom if base R is not attached as its own layer.
|
|
@@ -182,6 +195,10 @@ export declare const REnvironment: {
|
|
|
182
195
|
readonly searchPath: typeof searchPathOf;
|
|
183
196
|
/** Attaches a package block at a `search()` position, below the global by default; see {@link attachPackageAt}. */
|
|
184
197
|
readonly attachAt: typeof attachPackageAt;
|
|
198
|
+
/** Removes the entry at a `search()` position, the topmost by default; see {@link detachPackageAt}. */
|
|
199
|
+
readonly detachAt: typeof detachPackageAt;
|
|
200
|
+
/** Takes over what another evaluation attached to the (global) search path; see {@link adoptSearchPathOf}. */
|
|
201
|
+
readonly adoptSearchPath: typeof adoptSearchPathOf;
|
|
185
202
|
/** The `search()` position of a named entry; see {@link searchPositionOf}. */
|
|
186
203
|
readonly searchPosition: typeof searchPositionOf;
|
|
187
204
|
/** The packages on the search path; see {@link attachedPackagesOf}. */
|
|
@@ -27,6 +27,8 @@ var EnvType;
|
|
|
27
27
|
EnvType["LoadedNamespace"] = "lns";
|
|
28
28
|
/** A package `solver.assumeAttachedPackages` states as attached; a `library()` in the analyzed code still attaches it in full over this. */
|
|
29
29
|
EnvType["AssumedNamespace"] = "ans";
|
|
30
|
+
/** Data `attach(what)` put on the search path, a list, data frame, or environment */
|
|
31
|
+
EnvType["Attached"] = "att";
|
|
30
32
|
})(EnvType || (exports.EnvType = EnvType = {}));
|
|
31
33
|
/** Use only if you do not know the object type; otherwise rely on {@link IEnvironment#builtInEnv}. */
|
|
32
34
|
function isDefaultBuiltInEnvironment(obj) {
|
|
@@ -288,7 +290,7 @@ class Environment {
|
|
|
288
290
|
if (!other || this === other) {
|
|
289
291
|
return this;
|
|
290
292
|
}
|
|
291
|
-
const shortcut = this.mergeShortcut(other);
|
|
293
|
+
const shortcut = this.mergeShortcut(other, append, applyCds);
|
|
292
294
|
if (shortcut !== undefined) {
|
|
293
295
|
return shortcut;
|
|
294
296
|
}
|
|
@@ -328,16 +330,21 @@ class Environment {
|
|
|
328
330
|
* The environment a merge with `other` settles on without touching either memory, `undefined` if the
|
|
329
331
|
* memories have to be merged. Package blocks are always unioned, never overwritten or appended to.
|
|
330
332
|
*/
|
|
331
|
-
mergeShortcut(other) {
|
|
333
|
+
mergeShortcut(other, append, applyCds) {
|
|
332
334
|
if (this.t !== undefined || other.t !== undefined) {
|
|
333
|
-
return this.mergePackageBlocks(other);
|
|
335
|
+
return this.mergePackageBlocks(other, append, applyCds);
|
|
334
336
|
}
|
|
335
337
|
return this.builtInEnv || this.n !== other.n ? this : undefined;
|
|
336
338
|
}
|
|
337
|
-
/**
|
|
338
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Unions two attached-package blocks, keeping every package once (memory merged for a package in both).
|
|
341
|
+
* A package only one block has is only maybe attached if the blocks are alternatives (appended: two branches, a
|
|
342
|
+
* loop body that may not run), or under `applyCds` if only `other` has it (a call in a branch attaching it).
|
|
343
|
+
*/
|
|
344
|
+
mergePackageBlocks(other, append, applyCds) {
|
|
339
345
|
const [thisLayers, thisBase] = splitLibraryLayers(this);
|
|
340
346
|
const [otherLayers, otherBase] = splitLibraryLayers(other);
|
|
347
|
+
const oneSided = (layer, fromOther) => append ? maybeLayer(layer) : fromOther && applyCds !== undefined ? maybeLayer(layer, applyCds) : undefined;
|
|
341
348
|
/*
|
|
342
349
|
* One block is the other plus the packages attached since (blocks grow at the front), so their union is
|
|
343
350
|
* the longer one and it is already in R's order: the most recently attached package is searched first,
|
|
@@ -348,10 +355,12 @@ class Environment {
|
|
|
348
355
|
: layersEndWith(otherLayers, thisLayers) ? otherLayers : undefined;
|
|
349
356
|
if (keep !== undefined) {
|
|
350
357
|
const base = thisBase.append(otherBase);
|
|
351
|
-
|
|
358
|
+
const onlyInKeep = keep.length - (keep === thisLayers ? otherLayers : thisLayers).length;
|
|
359
|
+
const front = keep.slice(0, onlyInKeep).map(l => oneSided(l, keep === otherLayers));
|
|
360
|
+
if (front.every(l => l === undefined) && keep === thisLayers && base === thisBase) {
|
|
352
361
|
return this;
|
|
353
362
|
}
|
|
354
|
-
return relinkLayers(keep.map(l => l.clone(false)), base);
|
|
363
|
+
return relinkLayers(keep.map((l, i) => front[i] ?? l.clone(false)), base);
|
|
355
364
|
}
|
|
356
365
|
/*
|
|
357
366
|
* Neither block is recognizably an extension of the other, so union them. The longer attach history goes
|
|
@@ -360,6 +369,8 @@ class Environment {
|
|
|
360
369
|
* Keyed by type and then by name, rather than by a `t:n` string built for every layer of every merge.
|
|
361
370
|
*/
|
|
362
371
|
const order = [];
|
|
372
|
+
const inBoth = new Set();
|
|
373
|
+
const fromOther = new Set();
|
|
363
374
|
const merged = new defaultmap_1.DefaultMap(() => new Map());
|
|
364
375
|
for (const layers of thisLayers.length > otherLayers.length ? [thisLayers, otherLayers] : [otherLayers, thisLayers]) {
|
|
365
376
|
for (const layer of layers) {
|
|
@@ -369,8 +380,11 @@ class Environment {
|
|
|
369
380
|
const cloned = layer.clone(false);
|
|
370
381
|
byName.set(layer.n, cloned);
|
|
371
382
|
order.push(cloned);
|
|
383
|
+
if (layers === otherLayers) {
|
|
384
|
+
fromOther.add(cloned);
|
|
385
|
+
}
|
|
372
386
|
}
|
|
373
|
-
else if (!existing.sameMemoryAs(layer)) {
|
|
387
|
+
else if (inBoth.add(existing) && !existing.sameMemoryAs(layer)) {
|
|
374
388
|
for (const [name, value] of layer.memory) {
|
|
375
389
|
const old = existing.memory.get(name);
|
|
376
390
|
if (old !== value) {
|
|
@@ -380,7 +394,7 @@ class Environment {
|
|
|
380
394
|
}
|
|
381
395
|
}
|
|
382
396
|
}
|
|
383
|
-
return relinkLayers(order, thisBase.append(otherBase));
|
|
397
|
+
return relinkLayers(order.map(l => inBoth.has(l) ? l : oneSided(l, fromOther.has(l)) ?? l), thisBase.append(otherBase));
|
|
384
398
|
}
|
|
385
399
|
remove(id) {
|
|
386
400
|
if (this.builtInEnv) {
|
|
@@ -469,22 +483,62 @@ exports.GlobalEnvEntryName = '.GlobalEnv';
|
|
|
469
483
|
* ({@link DefaultAttachPosition|2} by default); a position past the end attaches above the built-in env, mirroring R's clamping.
|
|
470
484
|
*/
|
|
471
485
|
function attachPackageAt(current, blockTop, blockBottom, pos = exports.DefaultAttachPosition) {
|
|
472
|
-
const clonedCurrent = current
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
486
|
+
const [clonedCurrent, anchor] = cloneToPosition(current, pos);
|
|
487
|
+
blockBottom.parent = anchor.parent; // the built-in env, or the packages attached further down
|
|
488
|
+
anchor.parent = blockTop;
|
|
489
|
+
return clonedCurrent;
|
|
490
|
+
}
|
|
491
|
+
/** Removes the entry at the 1-based `search()` position `pos` (`detach`), with its imports layer; `current` itself if there is none. */
|
|
492
|
+
function detachPackageAt(current, pos = exports.DefaultAttachPosition) {
|
|
493
|
+
const [clonedCurrent, anchor] = cloneToPosition(current, pos);
|
|
494
|
+
const entry = anchor.parent;
|
|
495
|
+
if (entry.builtInEnv || entry.t === undefined) {
|
|
496
|
+
return current;
|
|
497
|
+
}
|
|
498
|
+
anchor.parent = entry.parent.t === EnvType.Imports && entry.parent.n === entry.n ? entry.parent.parent : entry.parent;
|
|
499
|
+
return clonedCurrent;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* A copy of the frames from `current` down to the frame right above the 1-based `search()` position `pos`, walking past
|
|
503
|
+
* the `pos - 2` entries below the global; an imports layer belongs to the entry above it and is never one itself.
|
|
504
|
+
*/
|
|
505
|
+
function cloneToPosition(current, pos) {
|
|
506
|
+
const [cloned, global] = cloneToGlobal(current);
|
|
507
|
+
let anchor = global;
|
|
479
508
|
for (let skip = pos - exports.DefaultAttachPosition; skip > 0 && !anchor.parent.builtInEnv; skip--) {
|
|
480
509
|
do {
|
|
481
510
|
anchor.parent = anchor.parent.clone(false);
|
|
482
511
|
anchor = anchor.parent;
|
|
483
512
|
} while (anchor.parent.t === EnvType.Imports);
|
|
484
513
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
514
|
+
return [cloned, anchor];
|
|
515
|
+
}
|
|
516
|
+
/** A copy of the frames from `current` down to the global environment, so the search path below it can be changed; returns the copy and its global frame. */
|
|
517
|
+
function cloneToGlobal(current) {
|
|
518
|
+
const cloned = current.clone(false);
|
|
519
|
+
let global = cloned;
|
|
520
|
+
while (!global.globalEnv && !global.parent.builtInEnv) {
|
|
521
|
+
global.parent = global.parent.clone(false);
|
|
522
|
+
global = global.parent;
|
|
523
|
+
}
|
|
524
|
+
return [cloned, global];
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* `target` with the packages `source` attached as well: the search path is global, so what code evaluated in
|
|
528
|
+
* another environment attaches (`local(library(x), envir = e)`) is attached for the caller, too.
|
|
529
|
+
*/
|
|
530
|
+
function adoptSearchPathOf(target, source) {
|
|
531
|
+
const into = findGlobalEnvironment(target), from = findGlobalEnvironment(source);
|
|
532
|
+
if (!into.globalEnv || !from.globalEnv || into.parent === from.parent) {
|
|
533
|
+
return target;
|
|
534
|
+
}
|
|
535
|
+
const block = into.parent.overwrite(from.parent);
|
|
536
|
+
if (block === into.parent) {
|
|
537
|
+
return target;
|
|
538
|
+
}
|
|
539
|
+
const [cloned, global] = cloneToGlobal(target);
|
|
540
|
+
global.parent = block;
|
|
541
|
+
return cloned;
|
|
488
542
|
}
|
|
489
543
|
/**
|
|
490
544
|
* The 1-based `search()` position of the entry called `name` (`.GlobalEnv`, `package:x`, or a bare package name), or
|
|
@@ -536,6 +590,10 @@ exports.REnvironment = {
|
|
|
536
590
|
searchPath: searchPathOf,
|
|
537
591
|
/** Attaches a package block at a `search()` position, below the global by default; see {@link attachPackageAt}. */
|
|
538
592
|
attachAt: attachPackageAt,
|
|
593
|
+
/** Removes the entry at a `search()` position, the topmost by default; see {@link detachPackageAt}. */
|
|
594
|
+
detachAt: detachPackageAt,
|
|
595
|
+
/** Takes over what another evaluation attached to the (global) search path; see {@link adoptSearchPathOf}. */
|
|
596
|
+
adoptSearchPath: adoptSearchPathOf,
|
|
539
597
|
/** The `search()` position of a named entry; see {@link searchPositionOf}. */
|
|
540
598
|
searchPosition: searchPositionOf,
|
|
541
599
|
/** The packages on the search path; see {@link attachedPackagesOf}. */
|
|
@@ -581,6 +639,19 @@ function relinkLayers(layers, base) {
|
|
|
581
639
|
}
|
|
582
640
|
return current;
|
|
583
641
|
}
|
|
642
|
+
/** A copy of the package layer whose bindings hold under `cds`, or, without, only maybe (the empty cds, no branch named). */
|
|
643
|
+
function maybeLayer(layer, cds) {
|
|
644
|
+
const out = layer.clone(false);
|
|
645
|
+
const memory = layer.memory;
|
|
646
|
+
const asMaybe = (defs) => defs.map(d => cds !== undefined
|
|
647
|
+
? { ...d, cds: cds.concat(d.cds ?? []) }
|
|
648
|
+
: (0, info_1.happensInEveryBranch)(d.cds) ? { ...d, cds: d.cds?.slice() ?? [] } : d);
|
|
649
|
+
const lazy = memory instanceof frame_memory_1.Frame ? memory.lazy() : undefined;
|
|
650
|
+
out.adoptMap(lazy === undefined
|
|
651
|
+
? new Map([...memory].map(([name, defs]) => [name, asMaybe(defs)]))
|
|
652
|
+
: new frame_memory_1.LazyBindings(new Set(lazy.keys()), name => asMaybe(lazy.get(name) ?? []), `maybe|${info_1.ControlDependency.key(cds)}|${lazy.origin}`));
|
|
653
|
+
return out;
|
|
654
|
+
}
|
|
584
655
|
/** Splits a package block (a contiguous run of attached-package layers, see {@link EnvType}) into its layers and the env below them. */
|
|
585
656
|
function splitLibraryLayers(env) {
|
|
586
657
|
const layers = [];
|
|
@@ -219,11 +219,13 @@ export declare const enum PkgName {
|
|
|
219
219
|
Utils = "utils",
|
|
220
220
|
AnnotationHub = "AnnotationHub",
|
|
221
221
|
Ape = "ape",
|
|
222
|
+
Archive = "archive",
|
|
222
223
|
Arrow = "arrow",
|
|
223
224
|
AssertThat = "assertthat",
|
|
224
225
|
Audio = "audio",
|
|
225
226
|
Av = "av",
|
|
226
227
|
AwsS3 = "aws.s3",
|
|
228
|
+
BiocManager = "BiocManager",
|
|
227
229
|
Box = "box",
|
|
228
230
|
Brew = "brew",
|
|
229
231
|
Callr = "callr",
|
|
@@ -233,6 +235,8 @@ export declare const enum PkgName {
|
|
|
233
235
|
CohortBuilder = "cohortBuilder",
|
|
234
236
|
Corrplot = "corrplot",
|
|
235
237
|
Cowplot = "cowplot",
|
|
238
|
+
Config = "config",
|
|
239
|
+
Conflicted = "conflicted",
|
|
236
240
|
Curl = "curl",
|
|
237
241
|
DataTable = "data.table",
|
|
238
242
|
Dbi = "DBI",
|
|
@@ -243,7 +247,10 @@ export declare const enum PkgName {
|
|
|
243
247
|
DoMc = "doMC",
|
|
244
248
|
DoParallel = "doParallel",
|
|
245
249
|
DoSnow = "doSNOW",
|
|
250
|
+
Downloader = "downloader",
|
|
251
|
+
Dotenv = "dotenv",
|
|
246
252
|
Dplyr = "dplyr",
|
|
253
|
+
EasyPackages = "easypackages",
|
|
247
254
|
EbImage = "EBImage",
|
|
248
255
|
Emmeans = "emmeans",
|
|
249
256
|
ExperimentHub = "ExperimentHub",
|
|
@@ -270,6 +277,7 @@ export declare const enum PkgName {
|
|
|
270
277
|
GoogleCloudStorageR = "googleCloudStorageR",
|
|
271
278
|
GoogleDrive = "googledrive",
|
|
272
279
|
Haven = "haven",
|
|
280
|
+
Groundhog = "groundhog",
|
|
273
281
|
Here = "here",
|
|
274
282
|
Hmisc = "Hmisc",
|
|
275
283
|
HtmlTools = "htmltools",
|
|
@@ -282,7 +290,9 @@ export declare const enum PkgName {
|
|
|
282
290
|
Janitor = "janitor",
|
|
283
291
|
Jpeg = "jpeg",
|
|
284
292
|
Jsonlite = "jsonlite",
|
|
293
|
+
Knitr = "knitr",
|
|
285
294
|
Lattice = "lattice",
|
|
295
|
+
Librarian = "librarian",
|
|
286
296
|
Lim = "LIM",
|
|
287
297
|
Lme4 = "lme4",
|
|
288
298
|
LmTest = "lmtest",
|
|
@@ -292,14 +302,20 @@ export declare const enum PkgName {
|
|
|
292
302
|
Mass = "MASS",
|
|
293
303
|
Meltr = "meltr",
|
|
294
304
|
Mirai = "mirai",
|
|
305
|
+
Mockery = "mockery",
|
|
295
306
|
Msgr = "msgr",
|
|
296
307
|
Multcomp = "multcomp",
|
|
308
|
+
Needs = "needs",
|
|
297
309
|
Ncdf4 = "ncdf4",
|
|
298
310
|
NorTest = "nortest",
|
|
299
311
|
OpenImageR = "OpenImageR",
|
|
300
312
|
OpenXlsx = "openxlsx",
|
|
313
|
+
Osfr = "osfr",
|
|
314
|
+
Pak = "pak",
|
|
315
|
+
Pacman = "pacman",
|
|
301
316
|
Parallelly = "parallelly",
|
|
302
317
|
Patchwork = "patchwork",
|
|
318
|
+
Piggyback = "piggyback",
|
|
303
319
|
PkgLoad = "pkgload",
|
|
304
320
|
Plyr = "plyr",
|
|
305
321
|
Png = "png",
|
|
@@ -307,6 +323,7 @@ export declare const enum PkgName {
|
|
|
307
323
|
Promises = "promises",
|
|
308
324
|
Purrr = "purrr",
|
|
309
325
|
Qs = "qs",
|
|
326
|
+
Quarto = "quarto",
|
|
310
327
|
R6 = "R6",
|
|
311
328
|
Ragg = "ragg",
|
|
312
329
|
Raster = "raster",
|
|
@@ -327,10 +344,14 @@ export declare const enum PkgName {
|
|
|
327
344
|
Rlang = "rlang",
|
|
328
345
|
Rmatlab = "R.matlab",
|
|
329
346
|
RmethodsS3 = "R.methodsS3",
|
|
347
|
+
Renv = "renv",
|
|
348
|
+
Reticulate = "reticulate",
|
|
349
|
+
Rmarkdown = "rmarkdown",
|
|
330
350
|
Rnetcdf = "RNetCDF",
|
|
331
351
|
Roo = "R.oo",
|
|
332
352
|
Rprintf = "rprintf",
|
|
333
353
|
RsConnect = "rsconnect",
|
|
354
|
+
Rsqlite = "RSQLite",
|
|
334
355
|
Rstatix = "rstatix",
|
|
335
356
|
RstudioApi = "rstudioapi",
|
|
336
357
|
Rutils = "R.utils",
|
|
@@ -356,6 +377,7 @@ export declare const enum PkgName {
|
|
|
356
377
|
SvDialogs = "svDialogs",
|
|
357
378
|
Svglite = "svglite",
|
|
358
379
|
Sys = "sys",
|
|
380
|
+
Targets = "targets",
|
|
359
381
|
Tcltk = "tcltk",
|
|
360
382
|
Terra = "terra",
|
|
361
383
|
Texreg = "texreg",
|
|
@@ -378,7 +400,9 @@ export declare const enum PkgName {
|
|
|
378
400
|
XlConnect = "XLConnect",
|
|
379
401
|
Xlsx = "xlsx",
|
|
380
402
|
Xml2 = "xml2",
|
|
381
|
-
Yaml = "yaml"
|
|
403
|
+
Yaml = "yaml",
|
|
404
|
+
Zen4R = "zen4R",
|
|
405
|
+
Zip = "zip"
|
|
382
406
|
}
|
|
383
407
|
/**
|
|
384
408
|
* Each reference has exactly one reference type, stored as the respective number.
|
|
@@ -265,15 +265,16 @@ function entriesOfMemory(builtIns) {
|
|
|
265
265
|
/* the index says what flowR *knows*, not what is in scope, so the packages R does not attach on startup
|
|
266
266
|
belong in it as much as the always-on built-ins do -- being gated changes when a name resolves, not
|
|
267
267
|
whether flowR can answer for it */
|
|
268
|
-
|
|
268
|
+
/* an entry of a package R does not attach keeps the package it belongs to, `config::get` is no `get` */
|
|
269
|
+
for (const [pkg, memory] of [[undefined, builtIns.builtInMemory], ...builtIns.packageMemory.entries()]) {
|
|
269
270
|
for (const [registered, definitions] of memory) {
|
|
270
271
|
for (const d of definitions) {
|
|
271
272
|
if (d.type !== identifier_1.ReferenceType.BuiltInFunction) {
|
|
272
273
|
continue;
|
|
273
274
|
}
|
|
274
275
|
const info = d.config;
|
|
275
|
-
const
|
|
276
|
-
|
|
276
|
+
const namespace = (d.name === undefined ? undefined : identifier_1.Identifier.getNamespace(d.name)) ?? pkg;
|
|
277
|
+
const name = namespace === undefined ? d.name ?? registered : identifier_1.Identifier.make(registered, namespace);
|
|
277
278
|
out.push({ name, props: info?.props, tags: info?.tags, sig: info?.sig, foldable: d.evalHandler !== undefined });
|
|
278
279
|
}
|
|
279
280
|
}
|
|
@@ -148,10 +148,12 @@ function resolveByTargetType(id, environment, target) {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
if (allOk) {
|
|
151
|
+
/* a definite definition ends the walk, the maybe ones above it still count */
|
|
152
|
+
const result = definitions ? definitions.concat(definition) : definition;
|
|
151
153
|
if (flattenAt !== undefined) {
|
|
152
|
-
tailCacheOf(flattenAt, target).set(name,
|
|
154
|
+
tailCacheOf(flattenAt, target).set(name, result);
|
|
153
155
|
}
|
|
154
|
-
return
|
|
156
|
+
return result;
|
|
155
157
|
}
|
|
156
158
|
const filtered = allWanted ? definition : definition.filter(wantedType);
|
|
157
159
|
if (filtered.length > 0) {
|
|
@@ -208,7 +210,7 @@ function resolveByNameAnyType(id, environment) {
|
|
|
208
210
|
definition = definition.filter(({ name }) => name === undefined || !identifier_1.Identifier.accessesInternal(name));
|
|
209
211
|
}
|
|
210
212
|
if (definition.every(inEveryBranch)) {
|
|
211
|
-
return remember(environment, id, definition);
|
|
213
|
+
return remember(environment, id, definitions ? definitions.concat(definition) : definition);
|
|
212
214
|
}
|
|
213
215
|
else if (definition.length > 0) {
|
|
214
216
|
definitions = definitions ? definitions.concat(definition) : definition;
|
|
@@ -30,7 +30,7 @@ export declare const NodeValue: {
|
|
|
30
30
|
readonly of: <OtherInfo>(this: void, id: Target, against: Against<OtherInfo>, overrides?: Partial<ResolveInfo>) => ResolveResult;
|
|
31
31
|
/** The value set the node may hold, `undefined` if it resolves to top or bottom. */
|
|
32
32
|
readonly setOf: <OtherInfo>(this: void, id: Target, against: Against<OtherInfo>, overrides?: Partial<ResolveInfo>) => ValueSet<Value[]> | undefined;
|
|
33
|
-
/** The strings the node may hold, `undefined` if it does not resolve to strings. */
|
|
33
|
+
/** The strings the node may hold, those of a vector of strings (`c("a", "b")`) included, `undefined` if it does not resolve to strings. */
|
|
34
34
|
readonly stringsOf: <OtherInfo>(this: void, id: Target, against: Against<OtherInfo>, overrides?: Partial<ResolveInfo>) => string[] | undefined;
|
|
35
35
|
/** The strings the node may hold, dropping every value that is not one (in contrast to {@link NodeValue.stringsOf}, which gives up on them). */
|
|
36
36
|
readonly knownStringsOf: <OtherInfo>(this: void, id: Target, against: Against<OtherInfo>, overrides?: Partial<ResolveInfo>) => string[];
|
|
@@ -40,10 +40,10 @@ exports.NodeValue = {
|
|
|
40
40
|
setOf(id, against, overrides) {
|
|
41
41
|
return (0, general_1.valueSetGuard)(resolve_helper_1.Resolve.toValue(id, infoOf(against, overrides)));
|
|
42
42
|
},
|
|
43
|
-
/** The strings the node may hold, `undefined` if it does not resolve to strings. */
|
|
43
|
+
/** The strings the node may hold, those of a vector of strings (`c("a", "b")`) included, `undefined` if it does not resolve to strings. */
|
|
44
44
|
stringsOf(id, against, overrides) {
|
|
45
45
|
const resolved = (0, general_1.valueSetGuard)(resolve_helper_1.Resolve.toValue(id, infoOf(against, overrides)));
|
|
46
|
-
return resolved ? (0, string_constants_1.collectStrings)(resolved.elements) : undefined;
|
|
46
|
+
return resolved ? (0, string_constants_1.collectStrings)(resolved.elements.flatMap(v => v.type === 'vector' && (0, r_value_1.isValue)(v.elements) ? v.elements : [v])) : undefined;
|
|
47
47
|
},
|
|
48
48
|
/** The strings the node may hold, dropping every value that is not one (in contrast to {@link NodeValue.stringsOf}, which gives up on them). */
|
|
49
49
|
knownStringsOf(id, against, overrides) {
|
|
@@ -98,7 +98,7 @@ function argumentValues(variableResolve, graph, vertex, ref, resolveValue, ctx,
|
|
|
98
98
|
* already in `opening` is skipped: in `gzfile(d)` with `d` unknown, the provenance of `d` leads back to that very call.
|
|
99
99
|
*/
|
|
100
100
|
function openedResourceOf(variableResolve, graph, argument, ctx, opening) {
|
|
101
|
-
for (const id of df_helper_1.Dataflow.provenance(argument, graph, undefined, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall)) {
|
|
101
|
+
for (const id of df_helper_1.Dataflow.provenance(argument, graph, undefined, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns)) {
|
|
102
102
|
if (opening.has(id)) {
|
|
103
103
|
continue;
|
|
104
104
|
}
|
package/dataflow/extractor.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.processors = void 0;
|
|
4
7
|
exports.produceDataFlowGraph = produceDataFlowGraph;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
5
9
|
const applied_arguments_1 = require("./graph/applied-arguments");
|
|
6
10
|
const function_semantics_1 = require("./fn/function-semantics");
|
|
7
11
|
const processor_1 = require("./processor");
|
|
@@ -266,6 +270,31 @@ function readFramesThroughEnvironment(graph) {
|
|
|
266
270
|
function argsWithProp(vertex, info, prop) {
|
|
267
271
|
return info?.sig === undefined ? [] : match_args_1.MatchArgs.findWithProps(vertex.args, info.sig, prop);
|
|
268
272
|
}
|
|
273
|
+
/** the path with `/` separators, without `./` steps or a trailing `/` */
|
|
274
|
+
function normalizedPath(p) {
|
|
275
|
+
return path_1.default.posix.normalize(p.replaceAll('\\', '/')).replace(/(?<=.)\/$/, '');
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Whether the paths may name one file, as they do when one of them is a directory holding the other:
|
|
279
|
+
* `unzip(zipfile, exdir = "data")` and `file.copy(from, to = "out")` write into one, `list.files("data")` reads one. The working
|
|
280
|
+
* directory holds every relative path.
|
|
281
|
+
*/
|
|
282
|
+
function sharesFile(a, b) {
|
|
283
|
+
const [x, y] = [normalizedPath(a), normalizedPath(b)];
|
|
284
|
+
/* a `setwd` in between makes two paths with the same file name the same file (`f.txt`, then `../f.txt` from `sub`) */
|
|
285
|
+
return x === y || holds(x, y) || holds(y, x) || path_1.default.posix.basename(x) === path_1.default.posix.basename(y);
|
|
286
|
+
}
|
|
287
|
+
function holds(directory, file) {
|
|
288
|
+
return directory === '.' ? !path_1.default.posix.isAbsolute(file) && file !== '..' && !file.startsWith('../') : file.startsWith(directory.endsWith('/') ? directory : `${directory}/`);
|
|
289
|
+
}
|
|
290
|
+
/** whether the call tells the files it reads from the ones it writes, see {@link FnSig.resources} */
|
|
291
|
+
function splitsResources(info) {
|
|
292
|
+
return info?.sig !== undefined && built_in_props_1.FnSig.resources(info.sig, true) !== info.sig;
|
|
293
|
+
}
|
|
294
|
+
/** The {@link ArgProp.Resource} arguments naming what the call writes (`writes`) or reads, see {@link FnSig.resources}. */
|
|
295
|
+
function resourceArgs(vertex, info, writes) {
|
|
296
|
+
return info?.sig === undefined ? [] : match_args_1.MatchArgs.findWithProps(vertex.args, built_in_props_1.FnSig.resources(info.sig, writes), built_in_props_1.ArgProp.Resource);
|
|
297
|
+
}
|
|
269
298
|
function definitionsReachedBy(node, graph) {
|
|
270
299
|
return df_helper_1.Dataflow.reachable(graph, node, {
|
|
271
300
|
follow: edge_1.EdgeType.Reads,
|
|
@@ -302,10 +331,16 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
302
331
|
if (!reads && !writes) {
|
|
303
332
|
continue;
|
|
304
333
|
}
|
|
305
|
-
const
|
|
334
|
+
const applied = (0, applied_arguments_1.appliedArguments)(graph, vertex);
|
|
335
|
+
/* a call stating both without saying which files it writes (`file(path, open)`) counts as a reader */
|
|
336
|
+
const read = reads ? resourceArgs(applied, info, false)[0] : undefined;
|
|
337
|
+
const written = writes && (!reads || splitsResources(info)) ? resourceArgs(applied, info, true)[0] : undefined;
|
|
306
338
|
/* writing to the console names no file, and neither does a reader we cannot pin down */
|
|
307
|
-
if (
|
|
308
|
-
|
|
339
|
+
if (read !== undefined) {
|
|
340
|
+
readers.push({ id, resource: read });
|
|
341
|
+
}
|
|
342
|
+
if (written !== undefined) {
|
|
343
|
+
writers.push({ id, resource: written });
|
|
309
344
|
}
|
|
310
345
|
}
|
|
311
346
|
if (readers.length === 0 || writers.length === 0) {
|
|
@@ -314,14 +349,28 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
314
349
|
const reachedBy = (0, defaultmap_1.memoize)((id) => definitionsReachedBy(id, graph));
|
|
315
350
|
const where = { graph, idMap: graph.idMap, resolve: ctx.config.solver.variables, ctx, environment };
|
|
316
351
|
const pathOf = (0, defaultmap_1.memoize)((id) => resolve_helper_1.Resolve.toSingleString(id, where));
|
|
352
|
+
/* every `tempfile()` call names a file of its own, so paths made from different ones differ */
|
|
353
|
+
const tempFiles = (0, defaultmap_1.memoize)((id) => new Set([...df_helper_1.Dataflow.provenance(r_argument_1.RArgument.valueOf(graph.idMap?.get(id))?.info.id ?? id, graph)]
|
|
354
|
+
.filter(v => {
|
|
355
|
+
const call = graph.getVertex(v);
|
|
356
|
+
return vertex_1.DfgVertex.isFunctionCall(call) && call.name !== undefined && identifier_1.Identifier.getName(call.name) === 'tempfile'
|
|
357
|
+
&& function_semantics_1.FunctionSemantics.call.props.hasAll((0, query_fn_props_1.callFnProps)(v, { graph, environment }), [built_in_props_1.SemanticCallTag.TempFile]);
|
|
358
|
+
})));
|
|
317
359
|
const sameResource = (a, b) => {
|
|
318
|
-
if (a === b
|
|
360
|
+
if (a === b) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
const [ta, tb] = [tempFiles(a), tempFiles(b)];
|
|
364
|
+
if (ta.size > 0 && tb.size > 0 && ta.isDisjointFrom(tb)) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
else if (!reachedBy(b).isDisjointFrom(reachedBy(a))) {
|
|
319
368
|
return true;
|
|
320
369
|
}
|
|
321
370
|
/* a path we cannot resolve may name the other one */
|
|
322
371
|
const path = pathOf(a);
|
|
323
372
|
const other = pathOf(b);
|
|
324
|
-
return path === undefined || other === undefined || path
|
|
373
|
+
return path === undefined || other === undefined || sharesFile(path, other);
|
|
325
374
|
};
|
|
326
375
|
/* each added edge clears the graph's cached call names, but none of these edges changes what a call targets */
|
|
327
376
|
const prints = (0, defaultmap_1.memoize)((id) => function_semantics_1.FunctionSemantics.call.props.hasAll((0, query_fn_props_1.callFnProps)(id, { graph, environment }), [built_in_props_1.SemanticCallTag.Prints]));
|
|
@@ -343,13 +392,13 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
343
392
|
}
|
|
344
393
|
}
|
|
345
394
|
}
|
|
346
|
-
/** The paths the
|
|
347
|
-
function pathsOf(id, graph, environment, ctx, callContext) {
|
|
395
|
+
/** The paths the file accessing call `id` writes (`writes`) or reads, `undefined` unless every one resolves to strings. */
|
|
396
|
+
function pathsOf(id, writes, graph, environment, ctx, callContext) {
|
|
348
397
|
const vertex = graph.getVertex(id);
|
|
349
398
|
if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
350
399
|
return undefined;
|
|
351
400
|
}
|
|
352
|
-
const resources =
|
|
401
|
+
const resources = resourceArgs((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), writes);
|
|
353
402
|
const paths = new Set();
|
|
354
403
|
for (const resource of resources) {
|
|
355
404
|
const strings = node_value_1.NodeValue.stringsOf(r_argument_1.RArgument.valueOf(graph.idMap?.get(resource)) ?? resource, resolve_helper_1.Resolve.info(graph, ctx), { callContext });
|
|
@@ -407,20 +456,21 @@ function separateFileWritesPerCall(graph, environment, ctx) {
|
|
|
407
456
|
}
|
|
408
457
|
const fileAccess = (0, defaultmap_1.memoize)((id) => {
|
|
409
458
|
const info = (0, query_fn_props_1.callFnProps)(id, { graph, environment });
|
|
410
|
-
|
|
411
|
-
|
|
459
|
+
const writes = function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes]);
|
|
460
|
+
const reads = function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Reads]) && (!writes || splitsResources(info));
|
|
461
|
+
return { reads, writes };
|
|
412
462
|
});
|
|
413
|
-
const readPaths = (0, defaultmap_1.memoize)((id) => fileAccess(id)
|
|
463
|
+
const readPaths = (0, defaultmap_1.memoize)((id) => fileAccess(id).reads ? pathsOf(id, false, graph, environment, ctx) : undefined);
|
|
414
464
|
/* writing to the console (`cat(x)`) names no file, and has no call to tell apart */
|
|
415
465
|
const namesFile = (id) => {
|
|
416
466
|
const vertex = graph.getVertex(id);
|
|
417
|
-
return
|
|
467
|
+
return resourceArgs((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), true).length > 0;
|
|
418
468
|
};
|
|
419
469
|
const writers = [...graph.verticesOfType(vertex_1.VertexType.FunctionCall)].map(([id]) => id)
|
|
420
|
-
.filter(id => graph.edgesFrom(id).values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.SideEffectOnCall)) && !graph.unknownSideEffects.has(id) && fileAccess(id)
|
|
470
|
+
.filter(id => graph.edgesFrom(id).values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.SideEffectOnCall)) && !graph.unknownSideEffects.has(id) && fileAccess(id).writes && namesFile(id));
|
|
421
471
|
const separated = new Set();
|
|
422
472
|
for (const writer of writers) {
|
|
423
|
-
const levels = fileWriteLevels(writer, graph, idMap, callContext => pathsOf(writer, graph, environment, ctx, callContext));
|
|
473
|
+
const levels = fileWriteLevels(writer, graph, idMap, callContext => pathsOf(writer, true, graph, environment, ctx, callContext));
|
|
424
474
|
if (levels !== undefined) {
|
|
425
475
|
separated.add(writer);
|
|
426
476
|
}
|
|
@@ -428,11 +478,12 @@ function separateFileWritesPerCall(graph, environment, ctx) {
|
|
|
428
478
|
const body = graph.getVertex(definition).subflow.graph;
|
|
429
479
|
/* what holds the definition (`(function(p) ...)`) is no reader of what its body writes */
|
|
430
480
|
const holders = new Set([...model_1.RNode.iterateParents(idMap.get(at), idMap)].map(n => n.info.id));
|
|
431
|
-
|
|
481
|
+
/* a function reading the file reads it where it is called */
|
|
482
|
+
const readers = df_helper_1.Dataflow.sourcesOf(graph, at, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall).filter(r => !body.has(r) && !holders.has(r) && !calls.some(c => c.call === r));
|
|
432
483
|
for (const { call, paths } of calls) {
|
|
433
484
|
for (const reader of readers) {
|
|
434
485
|
const read = readPaths(reader);
|
|
435
|
-
if (read === undefined || paths === undefined ||
|
|
486
|
+
if (read === undefined || paths === undefined || read.values().some(r => paths.values().some(w => sharesFile(r, w)))) {
|
|
436
487
|
graph.addEdge(reader, call, edge_1.EdgeType.Reads);
|
|
437
488
|
}
|
|
438
489
|
}
|
|
@@ -581,7 +632,7 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
581
632
|
(0, transitive_side_effects_1.reResolveOpenReferences)(df.graph, df.environment, [...df.in, ...df.unknownReferences], escapedNames);
|
|
582
633
|
}
|
|
583
634
|
// link on-demand-materialized package exports back to their `library()` loaders
|
|
584
|
-
(0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
|
|
635
|
+
(0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment, ctx);
|
|
585
636
|
const cleanEnvironment = ctx.env.makeCleanEnv();
|
|
586
637
|
(0, linker_1.separateClosureInstances)(df.graph, name => (0, query_fn_props_1.queryFnProps)(name, { environment: cleanEnvironment }));
|
|
587
638
|
function_semantics_1.FunctionSemantics.call.quoted.finalize(df.graph, df.environment, completeAst.idMap, () => new control_flow_graph_1.ControlFlowGraph(df.graph));
|
|
@@ -75,6 +75,7 @@ export declare const FunctionSemantics: {
|
|
|
75
75
|
readonly forcing: (this: void, sig: FnSig | undefined, count: number) => readonly import("../../util/logic").Ternary[] | undefined;
|
|
76
76
|
readonly every: FnSig;
|
|
77
77
|
readonly only: (this: void, index: number, name: string) => FnSig;
|
|
78
|
+
readonly resources: (sig: FnSig, writes: boolean) => FnSig;
|
|
78
79
|
};
|
|
79
80
|
/** The same as {@link FunctionSemantics.call.props}, for one argument. */
|
|
80
81
|
readonly argument: {
|