@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
|
@@ -4,10 +4,12 @@ import { emptyGraph } from './dataflowgraph-builder';
|
|
|
4
4
|
import { getOriginInDfg } from '../origin/dfg-get-origin';
|
|
5
5
|
import { ambientWritesOfFunctions, computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
-
import type { REnvironmentInformation } from '../environments/environment';
|
|
8
7
|
import { type DataflowGraphVertexFunctionCall, type DataflowGraphVertexFunctionDefinition, type DataflowGraphVertexInfo } from './vertex';
|
|
9
8
|
import { Identifier } from '../environments/identifier';
|
|
10
9
|
import { DefaultMap } from '../../util/collections/defaultmap';
|
|
10
|
+
import type { FlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
11
|
+
import { type AttachSpec } from '../internal/process/functions/call/built-in/built-in-library';
|
|
12
|
+
import { type Environment, type REnvironmentInformation } from '../environments/environment';
|
|
11
13
|
/**
|
|
12
14
|
* This is the root helper object to work with the {@link DataflowGraph}.
|
|
13
15
|
*
|
|
@@ -18,6 +20,7 @@ import { DefaultMap } from '../../util/collections/defaultmap';
|
|
|
18
20
|
* - {@link Dataflow.calleesOf}/{@link Dataflow.calleeIdsOf}/{@link Dataflow.callTargetsOf}/{@link Dataflow.callsIn} - for what a call calls and what a definition calls,
|
|
19
21
|
* - {@link Dataflow.packagesOf} - for the packages a set of nodes (e.g. a slice) calls into,
|
|
20
22
|
* - {@link Dataflow.valueIsUsed}/{@link Dataflow.hasComputedArguments} - for what a call does with, and gets as, values,
|
|
23
|
+
* - {@link Dataflow.library} - for what `library(pkg)` attaches, loads, and puts on the search path, without analyzing any code,
|
|
21
24
|
*
|
|
22
25
|
* What it used to re-expose under a second name is imported directly instead: {@link DfEdge} for the edges,
|
|
23
26
|
* {@link CallGraph} for the call-graph view, {@link Resolve} for name and value resolution, and
|
|
@@ -204,6 +207,25 @@ export declare const Dataflow: {
|
|
|
204
207
|
* @see {@link Dataflow.provenance}
|
|
205
208
|
*/
|
|
206
209
|
readonly provenanceGraph: (this: void, id: NodeId, graph: DataflowGraph, consider?: ReadonlySet<NodeId>) => DataflowGraph;
|
|
210
|
+
/**
|
|
211
|
+
* What `library(pkg)` does, asked without analyzing any code.
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* const ctx = analyzer.context();
|
|
215
|
+
* Dataflow.library.attaches(ctx, 'tidyverse'); // the search() entries it adds
|
|
216
|
+
* Dataflow.library.loads(ctx, 'tidyverse'); // every namespace it loads
|
|
217
|
+
* Dataflow.library.layers(ctx, 'tidyverse'); // the namespace and imports environments themselves
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
readonly library: {
|
|
221
|
+
readonly name: "library";
|
|
222
|
+
/** The `search()` entries `library(pkg)` adds; see {@link libraryAttachesOf}. */
|
|
223
|
+
readonly attaches: typeof libraryAttachesOf;
|
|
224
|
+
/** The namespaces `library(pkg)` loads; see {@link libraryLoadsOf}. */
|
|
225
|
+
readonly loads: typeof libraryLoadsOf;
|
|
226
|
+
/** The environment layers `library(pkg)` adds to the search path; see {@link libraryLayersOf}. */
|
|
227
|
+
readonly layers: typeof libraryLayersOf;
|
|
228
|
+
};
|
|
207
229
|
readonly visualize: {
|
|
208
230
|
readonly mermaid: {
|
|
209
231
|
readonly name: "DataflowMermaid";
|
|
@@ -233,3 +255,14 @@ export declare const Dataflow: {
|
|
|
233
255
|
readonly reachable: <G extends DataflowGraph>(this: void, graph: G, seed: NodeId | Iterable<NodeId>, { follow, consider, cds, stopAt }?: import("./graph-helper").ReachOptions) => Set<NodeId>;
|
|
234
256
|
readonly reaches: <G extends DataflowGraph>(this: void, from: NodeId, to: NodeId, graph: G, knownReachability?: DefaultMap<NodeId, Set<NodeId>>) => boolean;
|
|
235
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* The layers `library(pkg)` puts on an empty search path, innermost first, built by the {@link attachLibrary} the
|
|
260
|
+
* analysis uses: per attached package its namespace (exports) and imports layer, or for an unresolved one what flowR
|
|
261
|
+
* states about it or a bare {@link EnvType.LoadedNamespace}. `layer.n` is the package, `layer.t` the type, `layer.memory` the bindings.
|
|
262
|
+
*/
|
|
263
|
+
declare function libraryLayersOf(this: void, ctx: FlowrAnalyzerContext, pkg: string, spec?: AttachSpec): readonly Environment[];
|
|
264
|
+
/** The `search()` entries `library(pkg)` adds, in `search()` order: `pkg`, its `Depends` and a meta-package's core set, recursively. */
|
|
265
|
+
declare function libraryAttachesOf(this: void, ctx: FlowrAnalyzerContext, pkg: string, spec?: AttachSpec): readonly string[];
|
|
266
|
+
/** The namespaces `library(pkg)` loads, `pkg` first: the closure over {@link directLoadsOf} at the versions the analysis assumes. */
|
|
267
|
+
declare function libraryLoadsOf(this: void, ctx: FlowrAnalyzerContext, pkg: string): readonly string[];
|
|
268
|
+
export {};
|
|
@@ -15,6 +15,9 @@ const r_base_packages_1 = require("../../util/r-base-packages");
|
|
|
15
15
|
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
16
16
|
const linker_1 = require("../internal/linker");
|
|
17
17
|
const dfg_get_symbol_refs_1 = require("../origin/dfg-get-symbol-refs");
|
|
18
|
+
const built_in_library_1 = require("../internal/process/functions/call/built-in/built-in-library");
|
|
19
|
+
const environment_1 = require("../environments/environment");
|
|
20
|
+
const attached_packages_1 = require("../../project/attached-packages");
|
|
18
21
|
/**
|
|
19
22
|
* This is the root helper object to work with the {@link DataflowGraph}.
|
|
20
23
|
*
|
|
@@ -25,6 +28,7 @@ const dfg_get_symbol_refs_1 = require("../origin/dfg-get-symbol-refs");
|
|
|
25
28
|
* - {@link Dataflow.calleesOf}/{@link Dataflow.calleeIdsOf}/{@link Dataflow.callTargetsOf}/{@link Dataflow.callsIn} - for what a call calls and what a definition calls,
|
|
26
29
|
* - {@link Dataflow.packagesOf} - for the packages a set of nodes (e.g. a slice) calls into,
|
|
27
30
|
* - {@link Dataflow.valueIsUsed}/{@link Dataflow.hasComputedArguments} - for what a call does with, and gets as, values,
|
|
31
|
+
* - {@link Dataflow.library} - for what `library(pkg)` attaches, loads, and puts on the search path, without analyzing any code,
|
|
28
32
|
*
|
|
29
33
|
* What it used to re-expose under a second name is imported directly instead: {@link DfEdge} for the edges,
|
|
30
34
|
* {@link CallGraph} for the call-graph view, {@link Resolve} for name and value resolution, and
|
|
@@ -394,6 +398,25 @@ exports.Dataflow = {
|
|
|
394
398
|
*/
|
|
395
399
|
provenanceGraph(id, graph, consider) {
|
|
396
400
|
return exports.Dataflow.reduceGraph(graph, exports.Dataflow.provenance(id, graph, consider));
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* What `library(pkg)` does, asked without analyzing any code.
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* const ctx = analyzer.context();
|
|
407
|
+
* Dataflow.library.attaches(ctx, 'tidyverse'); // the search() entries it adds
|
|
408
|
+
* Dataflow.library.loads(ctx, 'tidyverse'); // every namespace it loads
|
|
409
|
+
* Dataflow.library.layers(ctx, 'tidyverse'); // the namespace and imports environments themselves
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
library: {
|
|
413
|
+
name: 'library',
|
|
414
|
+
/** The `search()` entries `library(pkg)` adds; see {@link libraryAttachesOf}. */
|
|
415
|
+
attaches: libraryAttachesOf,
|
|
416
|
+
/** The namespaces `library(pkg)` loads; see {@link libraryLoadsOf}. */
|
|
417
|
+
loads: libraryLoadsOf,
|
|
418
|
+
/** The environment layers `library(pkg)` adds to the search path; see {@link libraryLayersOf}. */
|
|
419
|
+
layers: libraryLayersOf
|
|
397
420
|
}
|
|
398
421
|
};
|
|
399
422
|
/** both qualifications of a call from a single origin resolution, as the base-R step only adds to what the origins gave */
|
|
@@ -422,4 +445,41 @@ function aliasedBaseR(graph, id, origins) {
|
|
|
422
445
|
const owner = names.size === 1 ? (0, r_base_packages_1.baseRExportOwner)(name) : undefined;
|
|
423
446
|
return owner === undefined ? undefined : identifier_1.Identifier.make(name, owner);
|
|
424
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* The layers `library(pkg)` puts on an empty search path, innermost first, built by the {@link attachLibrary} the
|
|
450
|
+
* analysis uses: per attached package its namespace (exports) and imports layer, or for an unresolved one what flowR
|
|
451
|
+
* states about it or a bare {@link EnvType.LoadedNamespace}. `layer.n` is the package, `layer.t` the type, `layer.memory` the bindings.
|
|
452
|
+
*/
|
|
453
|
+
function libraryLayersOf(ctx, pkg, spec) {
|
|
454
|
+
return [...environment_1.REnvironment.searchPath((0, built_in_library_1.attachLibrary)(pkg, ctx.deps.getDependency(pkg), ctx.env.makeCleanEnv(), ctx, spec).current)];
|
|
455
|
+
}
|
|
456
|
+
/** The `search()` entries `library(pkg)` adds, in `search()` order: `pkg`, its `Depends` and a meta-package's core set, recursively. */
|
|
457
|
+
function libraryAttachesOf(ctx, pkg, spec) {
|
|
458
|
+
if (spec?.namespaceOnly) {
|
|
459
|
+
return []; // loading a namespace puts nothing on the search path
|
|
460
|
+
}
|
|
461
|
+
return libraryLayersOf(ctx, pkg, spec).filter(l => l.t !== environment_1.EnvType.Imports && l.n !== undefined).map(l => l.n);
|
|
462
|
+
}
|
|
463
|
+
/** The packages loading `pkg` loads directly: its `Depends` and `Imports`, its `NAMESPACE` imports, and a meta-package's core set. */
|
|
464
|
+
function directLoadsOf(ctx, pkg) {
|
|
465
|
+
const db = ctx.deps.signatures();
|
|
466
|
+
const dependency = ctx.deps.getDependency(pkg);
|
|
467
|
+
return [
|
|
468
|
+
...(db.sources().dependencies(pkg, db.versionOf(pkg)) ?? [])
|
|
469
|
+
.filter(d => (d.type === 0 /* DepType.Depends */ || d.type === 1 /* DepType.Imports */) && d.name !== 'R').map(d => d.name),
|
|
470
|
+
...dependency?.namespaceInfo?.importedPackages.keys() ?? [],
|
|
471
|
+
...dependency?.dependencies?.map(d => d.name) ?? [],
|
|
472
|
+
...(0, attached_packages_1.metaPackageCore)(pkg, db.versionOf(pkg))
|
|
473
|
+
];
|
|
474
|
+
}
|
|
475
|
+
/** The namespaces `library(pkg)` loads, `pkg` first: the closure over {@link directLoadsOf} at the versions the analysis assumes. */
|
|
476
|
+
function libraryLoadsOf(ctx, pkg) {
|
|
477
|
+
const loaded = new Set([pkg]);
|
|
478
|
+
for (const p of loaded) {
|
|
479
|
+
for (const d of directLoadsOf(ctx, p)) {
|
|
480
|
+
loaded.add(d);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return [...loaded];
|
|
484
|
+
}
|
|
425
485
|
//# sourceMappingURL=df-helper.js.map
|
package/dataflow/info.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export declare const ControlDependency: {
|
|
|
52
52
|
readonly isIterated: (this: void, cd: ControlDependency, idMap: AstIdMap | undefined) => boolean;
|
|
53
53
|
/** The dependencies of `a` that `b` is not subject to as well. */
|
|
54
54
|
readonly minus: (this: void, a: readonly ControlDependency[], b: readonly ControlDependency[]) => ControlDependency[];
|
|
55
|
+
/** A string telling the dependencies apart (by condition and branch), empty for none. */
|
|
56
|
+
readonly key: (this: void, cds: readonly ControlDependency[] | undefined) => string;
|
|
55
57
|
};
|
|
56
58
|
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
57
59
|
export declare function appendCds(target: ControlDependency[], toAdd: readonly ControlDependency[] | undefined): void;
|
package/dataflow/info.js
CHANGED
|
@@ -44,6 +44,10 @@ exports.ControlDependency = {
|
|
|
44
44
|
/** The dependencies of `a` that `b` is not subject to as well. */
|
|
45
45
|
minus(a, b) {
|
|
46
46
|
return a.filter(cd => !b.some(other => sameControlDependency(other, cd)));
|
|
47
|
+
},
|
|
48
|
+
/** A string telling the dependencies apart (by condition and branch), empty for none. */
|
|
49
|
+
key(cds) {
|
|
50
|
+
return cds?.map(cd => `${String(cd.id)}:${String(cd.when)}`).join(',') ?? '';
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
@@ -40,6 +40,7 @@ const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes
|
|
|
40
40
|
const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
41
41
|
const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
42
42
|
const df_helper_1 = require("../graph/df-helper");
|
|
43
|
+
const ambient_state_name_1 = require("../environments/ambient-state-name");
|
|
43
44
|
const ValueFlowBits = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
|
|
44
45
|
const FCallLinkReadBits = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall;
|
|
45
46
|
/**
|
|
@@ -97,6 +98,18 @@ function environmentsOfCallee(info, environment) {
|
|
|
97
98
|
}
|
|
98
99
|
return (resolve_helper_1.Resolve.byName(info.name, environment) ?? []).filter(identifier_1.hasEnvState).map(d => d.envState);
|
|
99
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* The frames of `environment` a function whose body runs at `bodyLevel` can see: the frame it was defined in and
|
|
103
|
+
* those around it, never the frames of the functions calling it.
|
|
104
|
+
*/
|
|
105
|
+
function definitionFramesOf(bodyLevel, environment) {
|
|
106
|
+
const level = Math.max(0, Math.min(bodyLevel - 1, environment.level));
|
|
107
|
+
let current = environment.current;
|
|
108
|
+
for (let skip = environment.level - level; skip > 0 && current.parent !== undefined; skip--) {
|
|
109
|
+
current = current.parent;
|
|
110
|
+
}
|
|
111
|
+
return { current, level };
|
|
112
|
+
}
|
|
100
113
|
/**
|
|
101
114
|
* Links a function call with a single target function definition.
|
|
102
115
|
*/
|
|
@@ -105,17 +118,19 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
105
118
|
const environment = info.environment;
|
|
106
119
|
if (environment !== undefined) {
|
|
107
120
|
let callee;
|
|
121
|
+
let lexical;
|
|
108
122
|
/* for each open ingoing reference, try to resolve it here, and if so, add a read edge from the call to signal that it reads it */
|
|
109
123
|
for (const ingoing of fnSubflow.in) {
|
|
110
124
|
const name = ingoing.name;
|
|
111
125
|
if (name === undefined) {
|
|
112
126
|
continue;
|
|
113
127
|
}
|
|
114
|
-
|
|
115
|
-
const inCallee = callee.values().map(env => resolve_helper_1.Resolve.byNameAndType(name, env, ingoing.type)).find(assert_1.isNotUndefined);
|
|
116
|
-
const defs = inCallee ?? resolve_helper_1.Resolve.byNameAndType(name, environment, ingoing.type) ?? [];
|
|
128
|
+
/* a variable is looked up where the function was defined, global state (options, files, the working directory) is what it is where it is called */
|
|
129
|
+
const inCallee = ambient_state_name_1.AmbientStateName.is(name) ? undefined : (callee ??= environmentsOfCallee(info, environment)).values().map(env => resolve_helper_1.Resolve.byNameAndType(name, env, ingoing.type)).find(assert_1.isNotUndefined);
|
|
130
|
+
const defs = inCallee ?? resolve_helper_1.Resolve.byNameAndType(name, ambient_state_name_1.AmbientStateName.is(name) ? environment : lexical ??= definitionFramesOf(fnSubflow.environment.level, environment), ingoing.type) ?? [];
|
|
117
131
|
for (const { nodeId, type, value, definedAt, envState } of defs) {
|
|
118
|
-
|
|
132
|
+
/* the state an earlier run of the function left behind is what its next run reads */
|
|
133
|
+
if (fnSubflow.graph.has(nodeId) && !ambient_state_name_1.AmbientStateName.is(name) || node_id_1.NodeId.isBuiltIn(nodeId)) {
|
|
119
134
|
continue;
|
|
120
135
|
}
|
|
121
136
|
graph.addEdge(ingoing.nodeId, nodeId, edge_1.EdgeType.DefinedByOnCall);
|
|
@@ -411,7 +426,8 @@ function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation,
|
|
|
411
426
|
graph.addEdge(alsoFrom, target.nodeId, edge_1.EdgeType.Reads);
|
|
412
427
|
}
|
|
413
428
|
}
|
|
414
|
-
|
|
429
|
+
/* the state of the session (options, files, the working directory) may change before the next time the code runs, so it stays open */
|
|
430
|
+
if (probableTarget.every(t => (0, identifier_1.isReferenceType)(t.type, identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.BuiltInFunction)) || ambient_state_name_1.AmbientStateName.is(bodyInput.name)) {
|
|
415
431
|
givenInputs.push(bodyInput);
|
|
416
432
|
}
|
|
417
433
|
}
|
|
@@ -14,6 +14,10 @@ export type AmbientKeys = {
|
|
|
14
14
|
readonly from: 'argument-names';
|
|
15
15
|
/** arguments to leave out, like `par(no.readonly = TRUE)` */
|
|
16
16
|
readonly ignore?: readonly string[];
|
|
17
|
+
} | {
|
|
18
|
+
/** every unnamed argument names an entry, like `pacman::p_load(a, b)`; quoted ones are names themselves, others are looked up */
|
|
19
|
+
readonly from: 'unnamed';
|
|
20
|
+
readonly quoted: boolean;
|
|
17
21
|
} | {
|
|
18
22
|
/** the call always sets this entry, like `Sys.setLanguage` sets `LANGUAGE` */
|
|
19
23
|
readonly from: 'constant';
|
|
@@ -78,6 +78,9 @@ function keysOf(keys, args, data) {
|
|
|
78
78
|
});
|
|
79
79
|
case 'parameter':
|
|
80
80
|
return parameterKeys(keys, args, data);
|
|
81
|
+
case 'unnamed':
|
|
82
|
+
return args.flatMap(a => a === r_function_call_1.EmptyArgument || a.name !== undefined || a.value === undefined ? []
|
|
83
|
+
: (keys.quoted ? quotedName(a.value) : undefined) ?? stringValuesOf(a.value, data) ?? [ambient_state_name_1.UnknownKey]);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
/** The pseudo variables a write to the given entries of `state` defines: the entries and what every write to the state adds to. No entry has an empty name. */
|
|
@@ -74,8 +74,11 @@ export declare const enum AmbientStateAccessType {
|
|
|
74
74
|
RunFinalizers = "run-finalizers",
|
|
75
75
|
/** sets entries of a keyed state, like `Sys.setenv(A = "1")` sets the environment variable `A`, see {@link AmbientKeys} */
|
|
76
76
|
SetKeyed = "set-keyed",
|
|
77
|
+
ReadKeyed = "read-keyed",
|
|
77
78
|
/** sets a state without entries, like `sink(file)` diverts the output */
|
|
78
|
-
SetState = "set-state"
|
|
79
|
+
SetState = "set-state",
|
|
80
|
+
/** reads a state without entries, like `search()` reads the search path */
|
|
81
|
+
ReadState = "read-state"
|
|
79
82
|
}
|
|
80
83
|
/** An {@link AmbientStateAccessType} together with what refines it for some of the types. */
|
|
81
84
|
export type AmbientStateAccess = {
|
|
@@ -105,6 +108,14 @@ export type AmbientStateAccess = {
|
|
|
105
108
|
readonly type: AmbientStateAccessType.SetKeyed;
|
|
106
109
|
readonly state: KeyedState;
|
|
107
110
|
readonly keys: AmbientKeys;
|
|
111
|
+
} | {
|
|
112
|
+
readonly type: AmbientStateAccessType.ReadState;
|
|
113
|
+
readonly state: string;
|
|
114
|
+
} | {
|
|
115
|
+
/** reads the entries the call names, like `Sys.getenv("HOME")`, all of them if it names none */
|
|
116
|
+
readonly type: AmbientStateAccessType.ReadKeyed;
|
|
117
|
+
readonly state: KeyedState;
|
|
118
|
+
readonly keys: AmbientKeys;
|
|
108
119
|
} | {
|
|
109
120
|
readonly type: AmbientStateAccessType.SetState;
|
|
110
121
|
/** the pseudo variable the call sets, like {@link AmbientStateName.sink} */
|
|
@@ -127,6 +138,8 @@ declare const UnknownArguments: unique symbol;
|
|
|
127
138
|
type UnknownArguments = typeof UnknownArguments;
|
|
128
139
|
/** A call to `fn` made on our behalf (`do.call(fn, args)`, `sapply(x, fn)`): it accesses the state as `fn` does, or reads all of it if `fn` is opaque. */
|
|
129
140
|
export declare function applyAmbientStateOfCallee<OtherInfo>(res: DataflowInformation, callId: NodeId, fn: Identifier, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
141
|
+
/** Marks the call `callId` to the built-ins `targets` through a parameter or a variable as the unknown side effect they have, see {@link WritesEnvironment}. */
|
|
142
|
+
export declare function hiddenSideEffects(graph: DataflowGraph, environment: REnvironmentInformation, callId: NodeId, targets: readonly IdentifierDefinition[]): void;
|
|
130
143
|
/** The (maybe) writes of the call `callId` to the built-in `target` through a parameter, like `g <- function(f, ...) f(...); g(options, digits = 3)`. */
|
|
131
144
|
export declare function writesOfHiddenBuiltIn(target: IdentifierDefinition, callId: NodeId): (InGraphIdentifierDefinition & {
|
|
132
145
|
name: string;
|
|
@@ -142,13 +155,16 @@ export declare function callOnlyQueries<OtherInfo>(fn: Identifier, args: readonl
|
|
|
142
155
|
export declare function linkAmbientStateWithinLoop(graph: DataflowGraph, reads: readonly IdentifierReference[], body: DataflowInformation): IdentifierReference[];
|
|
143
156
|
/** A scoped state change (`withr`, `rlang`): `with_*` undoes it after its code, `local_*` when the calling function returns. */
|
|
144
157
|
export interface AmbientScope {
|
|
145
|
-
|
|
158
|
+
/** the state the scope changes; the keyed ones (`options`, environment variables, locale) take the entries the call names */
|
|
159
|
+
readonly state: 'options' | 'graphics' | 'device' | 'rng' | 'wd' | KeyedState.Env | KeyedState.Locale;
|
|
146
160
|
/** the formals in order, used to bind the arguments */
|
|
147
161
|
readonly params: readonly string[];
|
|
148
162
|
/** the formal evaluated with the change in effect, absent for the `local_*` variants */
|
|
149
163
|
readonly code?: string;
|
|
150
164
|
/** the formal holding a list of the new values (`list(digits = 3)`), other named arguments are values too */
|
|
151
165
|
readonly new?: string;
|
|
166
|
+
/** the scope changes nothing, it only restores the state afterward (`with_preserve_seed`) */
|
|
167
|
+
readonly preserve?: boolean;
|
|
152
168
|
}
|
|
153
169
|
/** The processor for an {@link AmbientScope}. */
|
|
154
170
|
export declare function processAmbientScope<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, scope: AmbientScope): DataflowInformation;
|