@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processLocal = processLocal;
|
|
4
|
+
exports.evaluateInEnvir = evaluateInEnvir;
|
|
4
5
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
5
6
|
const built_in_function_definition_1 = require("./built-in-function-definition");
|
|
6
7
|
const processor_1 = require("../../../../../processor");
|
|
@@ -47,10 +48,7 @@ function processLocal(name, args, rootId, data, config) {
|
|
|
47
48
|
});
|
|
48
49
|
return dfEnv;
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
-
? envirResolution.envirData.environment // evaluate in the tracked custom env
|
|
52
|
-
: environment_1.REnvironment.pushLocal(data.environment); // normal new local scope
|
|
53
|
-
const dfExpr = (0, processor_1.processDataflowFor)(expr, { ...data, environment: baseEnvironment });
|
|
51
|
+
const dfExpr = evaluateInEnvir(expr, envirResolution, rootId, data);
|
|
54
52
|
(0, common_1.patchFunctionCall)({
|
|
55
53
|
nextGraph: dfEnv.graph,
|
|
56
54
|
rootId,
|
|
@@ -59,11 +57,6 @@ function processLocal(name, args, rootId, data, config) {
|
|
|
59
57
|
argumentProcessResult: env ? [dfExpr, dfEnv] : [dfExpr],
|
|
60
58
|
origin: built_in_proc_name_1.BuiltInProcName.Local
|
|
61
59
|
});
|
|
62
|
-
/* in `local({ y <- 1; function() y })` the read of `y` is linked now, as the frame of `local` is dropped below */
|
|
63
|
-
(0, built_in_function_definition_1.updateNestedFunctionClosures)(dfExpr.graph, dfExpr.environment, []);
|
|
64
|
-
const resultEnvironment = envirResolution ? data.environment : environment_1.REnvironment.popLocal(dfExpr.environment);
|
|
65
|
-
/* definitions of the local scope vanish with it, only what escaped it (e.g. via `<<-`) may bubble up */
|
|
66
|
-
const escaping = envirResolution ? dfExpr.out : dfExpr.out.filter(o => o.name !== undefined && resolve_helper_1.Resolve.byNameAndType(o.name, resultEnvironment, o.type)?.some(d => d.nodeId === o.nodeId));
|
|
67
60
|
const graph = dfEnv.graph.mergeWith(dfExpr.graph);
|
|
68
61
|
graph.addEdge(rootId, expr.info.id, edge_1.EdgeType.Returns);
|
|
69
62
|
/* `y` in `local(y <- 1)` gets its value from `1`, so a definition in the body gets no `Reads` edge to `local` */
|
|
@@ -79,17 +72,35 @@ function processLocal(name, args, rootId, data, config) {
|
|
|
79
72
|
ingoing.push({ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function });
|
|
80
73
|
const baseResult = {
|
|
81
74
|
hooks: dfExpr.hooks.concat(dfEnv.hooks),
|
|
82
|
-
environment:
|
|
75
|
+
environment: dfExpr.environment,
|
|
83
76
|
exitPoints: dfEnv.exitPoints.concat(dfExpr.exitPoints.filter(e => e.type !== 1 /* ExitPointType.Return */)),
|
|
84
77
|
graph,
|
|
85
78
|
entryPoint: rootId,
|
|
86
79
|
cfgEntry,
|
|
87
80
|
cfgExit: rootId,
|
|
88
81
|
in: ingoing,
|
|
89
|
-
out:
|
|
82
|
+
out: dfExpr.out.concat(dfEnv.out),
|
|
90
83
|
unknownReferences: []
|
|
91
84
|
};
|
|
92
85
|
(0, built_in_envir_utils_1.unknownIfAmbiguous)(envirRouting, baseResult, rootId);
|
|
93
|
-
return
|
|
86
|
+
return baseResult;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Evaluates `expr` in the environment `envir` pins down, or in a fresh frame on top of the current one, as `local`
|
|
90
|
+
* and `eval(expr, envir)` do. The search path is global, so what `expr` attaches stays, and of a fresh frame only
|
|
91
|
+
* what escaped it (e.g., via `<<-`) remains.
|
|
92
|
+
*/
|
|
93
|
+
function evaluateInEnvir(expr, envir, rootId, data) {
|
|
94
|
+
const dfExpr = (0, processor_1.processDataflowFor)(expr, { ...data, environment: envir?.envirData.environment ?? environment_1.REnvironment.pushLocal(data.environment) });
|
|
95
|
+
/* in `local({ y <- 1; function() y })` the read of `y` is linked now, as the frame of `local` is dropped below */
|
|
96
|
+
(0, built_in_function_definition_1.updateNestedFunctionClosures)(dfExpr.graph, dfExpr.environment, []);
|
|
97
|
+
if (envir !== undefined) {
|
|
98
|
+
const environment = { level: data.environment.level, current: environment_1.REnvironment.adoptSearchPath(data.environment.current, dfExpr.environment.current) };
|
|
99
|
+
return (0, built_in_envir_utils_1.routeWrittenToEnvir)({ ...dfExpr, environment }, envir, rootId, data.environment);
|
|
100
|
+
}
|
|
101
|
+
const environment = environment_1.REnvironment.popLocal(dfExpr.environment);
|
|
102
|
+
/* definitions of the local scope vanish with it, only what escaped it may bubble up */
|
|
103
|
+
const out = dfExpr.out.filter(o => o.name !== undefined && resolve_helper_1.Resolve.byNameAndType(o.name, environment, o.type)?.some(d => d.nodeId === o.nodeId));
|
|
104
|
+
return { ...dfExpr, environment, out };
|
|
94
105
|
}
|
|
95
106
|
//# sourceMappingURL=built-in-local.js.map
|
|
@@ -10,6 +10,7 @@ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/proce
|
|
|
10
10
|
import type { NoInfo } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
|
|
11
11
|
import type { ReadOnlyFlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
|
|
12
12
|
import type { RProjectFile } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-project';
|
|
13
|
+
import type { FnSig } from '../../../../../environments/built-in-props';
|
|
13
14
|
/**
|
|
14
15
|
* Infers working directories based on the given option and reference chain
|
|
15
16
|
*/
|
|
@@ -34,7 +35,8 @@ export declare function findSource(resolveSource: FlowrLaxSourcingOptions | unde
|
|
|
34
35
|
ctx: ReadOnlyFlowrAnalyzerContext;
|
|
35
36
|
}): string[] | undefined;
|
|
36
37
|
/**
|
|
37
|
-
* Processes a
|
|
38
|
+
* Processes a call to `source` or `sys.source`, analyzing the file it names in the caller's frame or the environment
|
|
39
|
+
* its {@link envIn} formal names.
|
|
38
40
|
*/
|
|
39
41
|
export declare function processSourceCall<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: {
|
|
40
42
|
/** should this produce an explicit source function call in the graph? */
|
|
@@ -42,6 +44,10 @@ export declare function processSourceCall<OtherInfo>(name: RSymbol<OtherInfo & P
|
|
|
42
44
|
/** should this function call be followed, even when the configuration disables it? */
|
|
43
45
|
forceFollow?: boolean;
|
|
44
46
|
ambient?: AmbientStateAccess | readonly AmbientStateAccess[];
|
|
47
|
+
/** the formals, to find the file and the environment however they are passed */
|
|
48
|
+
sig?: FnSig;
|
|
49
|
+
/** the formal naming the environment to evaluate in, `local` for `source` (`TRUE`/`FALSE` there name the caller's frame or the global one) */
|
|
50
|
+
envIn?: string;
|
|
45
51
|
}): DataflowInformation;
|
|
46
52
|
/**
|
|
47
53
|
* Processes a source request with the given dataflow processor information and existing dataflow information
|
|
@@ -30,9 +30,11 @@ const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
|
30
30
|
const edge_1 = require("../../../../../graph/edge");
|
|
31
31
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
32
32
|
const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
33
|
-
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
34
33
|
const control_flow_1 = require("../../../../control-flow");
|
|
35
34
|
const environment_1 = require("../../../../../environments/environment");
|
|
35
|
+
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
36
|
+
const r_logical_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
|
|
37
|
+
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
36
38
|
/**
|
|
37
39
|
* Infers working directories based on the given option and reference chain
|
|
38
40
|
*/
|
|
@@ -127,34 +129,45 @@ function findSource(resolveSource, seed, data) {
|
|
|
127
129
|
return [...found];
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
|
-
* Processes a
|
|
132
|
+
* Processes a call to `source` or `sys.source`, analyzing the file it names in the caller's frame or the environment
|
|
133
|
+
* its {@link envIn} formal names.
|
|
131
134
|
*/
|
|
132
135
|
function processSourceCall(name, args, rootId, data, config) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
const bound = function_semantics_1.FunctionSemantics.call.match.toNames(args, config.sig?.map(([formal]) => formal) ?? ['file']);
|
|
137
|
+
const sourceFileArgument = bound.get('file');
|
|
138
|
+
if (sourceFileArgument === undefined) {
|
|
139
|
+
logger_1.dataflowLogger.warn('Expected a file argument for source, skipping');
|
|
140
|
+
const unknown = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
141
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(unknown.graph, unknown.environment, rootId);
|
|
142
|
+
return unknown;
|
|
136
143
|
}
|
|
144
|
+
const localArg = bound.get(config.envIn ?? 'local');
|
|
145
|
+
const routing = localArg === undefined || r_logical_1.RLogical.is(localArg.value) ? undefined : (0, built_in_envir_utils_1.resolveArgToEnvirOrAmbiguous)(localArg, data);
|
|
146
|
+
const resolution = (0, built_in_envir_utils_1.envirOf)(routing);
|
|
137
147
|
const information = config.includeFunctionCall ?
|
|
138
148
|
(0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Source }).information
|
|
139
149
|
: info_1.DataflowInformation.initialize(rootId, data);
|
|
140
150
|
const withAmbient = () => config.ambient === undefined ? information : (0, built_in_ambient_state_1.applyAmbientStateAccess)(information, args, rootId, data, config.ambient);
|
|
141
|
-
const sourceFileArgument = args[0];
|
|
142
151
|
if (!config.forceFollow && data.ctx.config.ignoreSourceCalls) {
|
|
143
152
|
(0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Skipping source call ${JSON.stringify(sourceFileArgument)} (disabled in config file)`);
|
|
144
153
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
|
|
145
154
|
return withAmbient();
|
|
146
155
|
}
|
|
147
156
|
let sourceFile;
|
|
148
|
-
if (
|
|
157
|
+
if (r_string_1.RString.is(sourceFileArgument.value)) {
|
|
149
158
|
sourceFile = [r_string_1.RString.unquote(sourceFileArgument.lexeme)];
|
|
150
159
|
}
|
|
151
|
-
else
|
|
160
|
+
else {
|
|
152
161
|
sourceFile = node_value_1.NodeValue.knownStringsOf(sourceFileArgument.info.id, data);
|
|
153
162
|
}
|
|
154
163
|
const path = sourceFile?.length === 1 ? r_string_1.RString.unquote(sourceFile[0]) : undefined;
|
|
155
164
|
const filepath = path ? findSource(data.ctx.config.solver.resolveSource, path, data) : undefined;
|
|
165
|
+
if (localArg !== undefined && !r_logical_1.RLogical.is(localArg.value) && resolution === undefined) {
|
|
166
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
|
|
167
|
+
return withAmbient();
|
|
168
|
+
}
|
|
156
169
|
if (filepath !== undefined && filepath.length > 0) {
|
|
157
|
-
let result = information;
|
|
170
|
+
let result = resolution ? { ...information, environment: resolution.envirData.environment } : information;
|
|
158
171
|
const origCds = data.cds?.slice() ?? [];
|
|
159
172
|
const maybe = !data.ctx.config.solver.resolveSource?.assumeFilesExist || filepath.length > 1;
|
|
160
173
|
const limit = data.ctx.config.solver.resolveSource?.repeatedSourceLimit ?? 0;
|
|
@@ -173,7 +186,12 @@ function processSourceCall(name, args, rootId, data, config) {
|
|
|
173
186
|
const getId = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(idPrefix, name.location);
|
|
174
187
|
result = sourceRequest(rootId, { request: 'file', content: f }, data, result, maybe, getId);
|
|
175
188
|
}
|
|
176
|
-
|
|
189
|
+
if (resolution === undefined) {
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
const routed = (0, built_in_envir_utils_1.routeWrittenToEnvir)({ ...result, environment: { level: data.environment.level, current: environment_1.REnvironment.adoptSearchPath(data.environment.current, result.environment.current) } }, resolution, rootId, data.environment);
|
|
193
|
+
(0, built_in_envir_utils_1.unknownIfAmbiguous)(routing, routed, rootId);
|
|
194
|
+
return routed;
|
|
177
195
|
}
|
|
178
196
|
(0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Non-constant argument ${JSON.stringify(sourceFile)} for source is currently not supported, skipping`);
|
|
179
197
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
|
|
@@ -318,7 +318,7 @@ function promoteCallToFunction(call, arg, info, data) {
|
|
|
318
318
|
}
|
|
319
319
|
const functionId = val.info.id;
|
|
320
320
|
info.graph.addEdge(arg, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
|
|
321
|
-
const syntheticCall =
|
|
321
|
+
const syntheticCall = node_id_1.NodeId.anonymousCall(functionId);
|
|
322
322
|
info.graph.addVertex({
|
|
323
323
|
tag: vertex_1.VertexType.FunctionCall,
|
|
324
324
|
id: syntheticCall,
|
|
@@ -7,6 +7,7 @@ const processor_1 = require("../../../../../processor");
|
|
|
7
7
|
const info_1 = require("../../../../../info");
|
|
8
8
|
const known_call_handling_1 = require("../known-call-handling");
|
|
9
9
|
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
10
|
+
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
10
11
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
11
12
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
12
13
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
@@ -18,11 +19,12 @@ const linker_1 = require("../../../../linker");
|
|
|
18
19
|
const environment_1 = require("../../../../../environments/environment");
|
|
19
20
|
/** Fallback formal parameter names for `with(data, expr, ...)` / `within(data, expr, ...)` when the signature database has no `base::with`. */
|
|
20
21
|
const withParamsFallback = ['data', 'expr'];
|
|
21
|
-
/** Normal call analysis, marking the data-masked arguments (columns of the data) as NSE. */
|
|
22
|
-
function markAsMaskedFallback(name, args, rootId, data) {
|
|
23
|
-
const
|
|
22
|
+
/** Normal call analysis, marking the data-masked arguments (columns of the data) as NSE; `expr` runs in a frame of its own built from the data. */
|
|
23
|
+
function markAsMaskedFallback(name, args, rootId, data, expr) {
|
|
24
|
+
const patchData = expr === undefined ? undefined : (d, i) => r_argument_1.RArgument.valueOf(args[i]) === expr ? { ...d, environment: environment_1.REnvironment.pushLocal(d.environment) } : d;
|
|
25
|
+
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With, keepArgumentGraphs: true, patchData });
|
|
24
26
|
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.AllButFirst, { kind: known_call_handling_1.NseKind.DataMasked });
|
|
25
|
-
return information;
|
|
27
|
+
return expr === undefined ? information : { ...information, environment: environment_1.REnvironment.popLocal(information.environment) };
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Processes `with(data, expr)` and `within(data, expr)`.
|
|
@@ -58,7 +60,7 @@ function processWithEnv(name, args, rootId, data) {
|
|
|
58
60
|
const envirRouting = (0, built_in_envir_utils_1.resolveArgToEnvirOrAmbiguous)(dataArg, data);
|
|
59
61
|
const envirResolution = (0, built_in_envir_utils_1.envirOf)(envirRouting);
|
|
60
62
|
if (!envirResolution) {
|
|
61
|
-
const fallback = markAsMaskedFallback(name, args, rootId, data);
|
|
63
|
+
const fallback = markAsMaskedFallback(name, args, rootId, data, exprArg.value);
|
|
62
64
|
/* only a definition or a call we cannot see into (a closure of `data`) can write to a `data` we cannot pin down */
|
|
63
65
|
if ((!fallback.graph.verticesOfType(vertex_1.VertexType.VariableDefinition).next().done || callsOpaque(fallback.graph, rootId)) && !(0, built_in_envir_utils_1.unknownIfAmbiguous)(envirRouting, fallback, rootId)) {
|
|
64
66
|
return mayWriteInto(dataArg.value, fallback, rootId, data);
|
|
@@ -4,7 +4,7 @@ import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing
|
|
|
4
4
|
import { type REnvironmentInformation } from '../../../../../environments/environment';
|
|
5
5
|
import type { FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
|
|
6
6
|
import type { IdentifierReference } from '../../../../../environments/identifier';
|
|
7
|
-
import type
|
|
7
|
+
import { type DataflowInformation } from '../../../../../info';
|
|
8
8
|
/**
|
|
9
9
|
* Computes, for every function-definition vertex `F`, `summary(F) = own(F)` unioned with `summary(G)` over every transitive callee `G`.
|
|
10
10
|
* @param graph - the fully linked dataflow graph
|
|
@@ -18,7 +18,7 @@ export declare function computeCallGraphSummaries<T>(this: void, graph: Dataflow
|
|
|
18
18
|
* reading the loading call from the export binding's `definedAt` in the (final, authoritative) environment.
|
|
19
19
|
* Only vertices created on demand (exports actually referenced) get an edge, keeping the graph small.
|
|
20
20
|
*/
|
|
21
|
-
export declare function linkMaterializedExportsToLoaders(graph: DataflowGraph, environment: REnvironmentInformation): void;
|
|
21
|
+
export declare function linkMaterializedExportsToLoaders(graph: DataflowGraph, environment: REnvironmentInformation, ctx: FlowrAnalyzerContext): void;
|
|
22
22
|
/** Re-resolves still-open reads whose name is one of the transitively escaped `<<-` definitions in `escapedNames`, adding {@link EdgeType.Reads} edges. */
|
|
23
23
|
export declare function reResolveOpenReferences(this: void, graph: DataflowGraph, environment: REnvironmentInformation, references: readonly IdentifierReference[], escapedNames: ReadonlySet<string>): void;
|
|
24
24
|
/**
|
|
@@ -19,6 +19,7 @@ const built_in_ambient_state_1 = require("./built-in-ambient-state");
|
|
|
19
19
|
const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
|
|
20
20
|
const df_helper_1 = require("../../../../../graph/df-helper");
|
|
21
21
|
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
22
|
+
const info_1 = require("../../../../../info");
|
|
22
23
|
/**
|
|
23
24
|
* Computes, for every function-definition vertex `F`, `summary(F) = own(F)` unioned with `summary(G)` over every transitive callee `G`.
|
|
24
25
|
* @param graph - the fully linked dataflow graph
|
|
@@ -51,14 +52,14 @@ function computeCallGraphSummaries(graph, own) {
|
|
|
51
52
|
* reading the loading call from the export binding's `definedAt` in the (final, authoritative) environment.
|
|
52
53
|
* Only vertices created on demand (exports actually referenced) get an edge, keeping the graph small.
|
|
53
54
|
*/
|
|
54
|
-
function linkMaterializedExportsToLoaders(graph, environment) {
|
|
55
|
+
function linkMaterializedExportsToLoaders(graph, environment, ctx) {
|
|
55
56
|
/* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the
|
|
56
|
-
* cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or
|
|
57
|
-
* `
|
|
57
|
+
* cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or something points
|
|
58
|
+
* to it, called or read as a value (`g <- select`). Both are read off the graph once here instead of per export binding. */
|
|
58
59
|
const called = new Set(graph.vertices(true).map(([id]) => id).filter(node_id_1.NodeId.isBuiltIn));
|
|
59
60
|
for (const [, outgoing] of graph.edges()) {
|
|
60
|
-
for (const
|
|
61
|
-
if (node_id_1.NodeId.isBuiltIn(target)
|
|
61
|
+
for (const target of outgoing.keys()) {
|
|
62
|
+
if (node_id_1.NodeId.isBuiltIn(target)) {
|
|
62
63
|
called.add(target);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -83,6 +84,8 @@ function linkMaterializedExportsToLoaders(graph, environment) {
|
|
|
83
84
|
/* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further
|
|
84
85
|
* export qualify -- the lazy checks this replaces could not have observed one either */
|
|
85
86
|
for (const [id, loadedAt] of loaders) {
|
|
87
|
+
/* an export only read as a value (`g <- select`) has no vertex yet, which a slice could not pass */
|
|
88
|
+
(0, built_in_library_1.attachExportVertex)(graph, id, environment, ctx);
|
|
86
89
|
graph.addEdge(id, loadedAt, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
|
|
87
90
|
}
|
|
88
91
|
}
|
|
@@ -170,26 +173,25 @@ function propagateTransitiveDefinitions(graph, environment, ctx, summary) {
|
|
|
170
173
|
*/
|
|
171
174
|
function propagateTransitivePackages(graph, environment, ctx) {
|
|
172
175
|
const summary = computeCallGraphSummaries(graph, ownLibraryCalls);
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
/* package to its loading `library()` call and, unless a call reaching it surely runs, the cds of one that may */
|
|
177
|
+
const reachable = new Map();
|
|
178
|
+
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
175
179
|
if (!graph.isRoot(id)) {
|
|
176
180
|
continue;
|
|
177
181
|
}
|
|
182
|
+
const cds = (0, info_1.happensInEveryBranch)(vertex.cds) ? undefined : vertex.cds;
|
|
178
183
|
for (const target of df_helper_1.Dataflow.calleeIdsOf(graph, id)) {
|
|
179
184
|
for (const { pack, definedAt } of summary.get(target) ?? []) {
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
const known = reachable.get(pack);
|
|
186
|
+
if (known === undefined || (known.cds !== undefined && cds === undefined)) {
|
|
187
|
+
reachable.set(pack, { definedAt, cds });
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
192
|
let grew = false;
|
|
187
|
-
for (const [pack, definedAt] of reachable) {
|
|
188
|
-
const
|
|
189
|
-
if (dependency === undefined) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
const next = (0, built_in_library_1.attachDependencyToEnvironment)(dependency, environment, ctx, {}, definedAt);
|
|
193
|
+
for (const [pack, { definedAt, cds }] of reachable) {
|
|
194
|
+
const next = (0, built_in_library_1.attachLibrary)(pack, ctx.deps.getDependency(pack), environment, ctx, {}, definedAt, cds);
|
|
193
195
|
if (next !== environment) {
|
|
194
196
|
environment = next;
|
|
195
197
|
grew = true;
|
|
@@ -218,6 +220,7 @@ function hiddenBuiltInAccess(graph, environment) {
|
|
|
218
220
|
for (const target of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)) {
|
|
219
221
|
if (node_id_1.NodeId.isBuiltIn(target) && (own === undefined || node_id_1.NodeId.toBuiltIn(identifier_1.Identifier.getName(own)) !== target)) {
|
|
220
222
|
const targets = resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(target), { current: builtIns, level: 0 }, identifier_1.ReferenceType.Function) ?? [];
|
|
223
|
+
(0, built_in_ambient_state_1.hiddenSideEffects)(graph, environment, id, targets);
|
|
221
224
|
const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id));
|
|
222
225
|
if (defs.length > 0) {
|
|
223
226
|
writesOf.get(id).push(...defs);
|
|
@@ -23,6 +23,7 @@ const edge_1 = require("../../../../graph/edge");
|
|
|
23
23
|
const built_in_library_1 = require("./built-in/built-in-library");
|
|
24
24
|
const vertex_1 = require("../../../../graph/vertex");
|
|
25
25
|
const resolve_helper_1 = require("../../../../environments/resolve-helper");
|
|
26
|
+
const ambient_state_name_1 = require("../../../../environments/ambient-state-name");
|
|
26
27
|
const assert_1 = require("../../../../../util/assert");
|
|
27
28
|
const built_in_props_1 = require("../../../../environments/built-in-props");
|
|
28
29
|
const query_fn_props_1 = require("../../../../environments/query-fn-props");
|
|
@@ -230,10 +231,13 @@ function processNamedCall(name, callArguments, rootId, data) {
|
|
|
230
231
|
const owners = ns !== undefined ? [ns] : resolved
|
|
231
232
|
.map(r => r.type === identifier_1.ReferenceType.BuiltInFunction && r.name !== undefined ? identifier_1.Identifier.getNamespace(r.name) : undefined)
|
|
232
233
|
.filter(assert_1.isNotUndefined);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
/* a call nothing resolves may call into whatever was attached in ways we cannot see (a package we could not
|
|
235
|
+
resolve, code that is evaluated), so it reads the search path */
|
|
236
|
+
const loads = resolved.length === 0 && ns === undefined
|
|
237
|
+
? (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.SearchPath), data.environment) ?? []).map(d => d.nodeId)
|
|
238
|
+
: owners.flatMap(owner => (0, built_in_library_1.loadNodesForNamespace)(data.environment, String(owner)));
|
|
239
|
+
for (const loadNode of loads) {
|
|
240
|
+
information.graph.addEdge(rootId, loadNode, edge_1.EdgeType.Reads);
|
|
237
241
|
}
|
|
238
242
|
/* opt-in: link a bare base-R call to its sigdb function vertex (base-R qualification is edge-free otherwise);
|
|
239
243
|
same guards as Identifier.toQualified: not namespaced, not resolving to a user definition */
|
|
@@ -4,6 +4,8 @@ import { NodeId } from '../../../../../r-bridge/lang-4.x/ast/model/processing/no
|
|
|
4
4
|
import type { DataflowGraph } from '../../../../graph/graph';
|
|
5
5
|
import { linkExpressionIn } from '../../../linker';
|
|
6
6
|
import type { REnvironmentInformation } from '../../../../environments/environment';
|
|
7
|
+
/** Calls capturing every argument as a language object, unlike `quote` marking the one it captures. */
|
|
8
|
+
export declare const CapturingCalls: ReadonlySet<string>;
|
|
7
9
|
/**
|
|
8
10
|
* A language object reads nothing where it is written and everything where it reaches `eval`, with the bindings
|
|
9
11
|
* in effect there. Working on the finished graph makes assignments, branches, loops, and calls one traversal.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Quoted = void 0;
|
|
3
|
+
exports.Quoted = exports.CapturingCalls = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* `FunctionSemantics.call` is the entry point these members are reached through, and it is built on this file, so the backing
|
|
6
6
|
* functions are called directly here; going through `FunctionSemantics` would make `src/dataflow/fn/function-semantics.ts` import its own
|
|
@@ -28,8 +28,8 @@ const happens_before_1 = require("../../../../../control-flow/happens-before");
|
|
|
28
28
|
const query_fn_props_1 = require("../../../../environments/query-fn-props");
|
|
29
29
|
const built_in_props_1 = require("../../../../environments/built-in-props");
|
|
30
30
|
const defaultmap_1 = require("../../../../../util/collections/defaultmap");
|
|
31
|
-
/** Calls
|
|
32
|
-
|
|
31
|
+
/** Calls capturing every argument as a language object, unlike `quote` marking the one it captures. */
|
|
32
|
+
exports.CapturingCalls = new Set(['expression']);
|
|
33
33
|
/** Calls capturing an expression as a promise, forced at some later read of the variable they bind. */
|
|
34
34
|
const DelayingCalls = new Set(['delayedAssign']);
|
|
35
35
|
const DelayedAssignFormals = ['x', 'value', 'eval.env', 'assign.env'];
|
|
@@ -57,7 +57,7 @@ exports.Quoted = {
|
|
|
57
57
|
return [];
|
|
58
58
|
}
|
|
59
59
|
const marked = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Quote);
|
|
60
|
-
return marked || CapturingCalls.has(identifier_1.Identifier.getName(vertex.name)) ? capturedArgumentsOf(graph, id, marked) : [];
|
|
60
|
+
return marked || exports.CapturingCalls.has(identifier_1.Identifier.getName(vertex.name)) ? capturedArgumentsOf(graph, id, marked) : [];
|
|
61
61
|
},
|
|
62
62
|
/** Every expression the value at `id` may hold, with the call that captured it. Several is normal. */
|
|
63
63
|
sourcesOf(graph, id) {
|
|
@@ -358,10 +358,11 @@ function resolveEvaluation(graph, call, idMap, names, bindings, cfg, reachOf, en
|
|
|
358
358
|
forgetUnknownSideEffect(graph, id);
|
|
359
359
|
}
|
|
360
360
|
if (sources.length > 0 && environment !== undefined && !sources.some(({ expr }) => mayConfigure(graph, expr, environment))) {
|
|
361
|
-
|
|
361
|
+
/* without the evaluation, a capture elsewhere or of several expressions (`expression(a, b)`) would not run */
|
|
362
|
+
forgetStateWrites(graph, id, new Set(sources.filter(({ at }) => model_1.RNode.findEnclosing(at, idMap, n => n.info.id === id) === undefined || exports.Quoted.capturedBy(graph, at).length > 1).map(({ expr }) => expr)));
|
|
362
363
|
}
|
|
363
364
|
}
|
|
364
|
-
/** Whether evaluating `expr` may change the options, graphics, or
|
|
365
|
+
/** Whether evaluating `expr` may change the options, graphics, RNG state, or search path: a call states {@link CallProp.Configures}, {@link SemanticCallTag.Random} or that it changes the search path, or is opaque. */
|
|
365
366
|
function mayConfigure(graph, expr, environment) {
|
|
366
367
|
const seen = new Set();
|
|
367
368
|
const todo = [expr];
|
|
@@ -374,7 +375,7 @@ function mayConfigure(graph, expr, environment) {
|
|
|
374
375
|
const vertex = graph.getVertex(id);
|
|
375
376
|
if (vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
376
377
|
const builtIn = Array.isArray(vertex.origin) && vertex.origin.every(o => String(o).startsWith('builtin:') && o !== built_in_proc_name_1.BuiltInProcName.Function && o !== built_in_proc_name_1.BuiltInProcName.Eval);
|
|
377
|
-
if (!builtIn || built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), [built_in_props_1.CallProp.Configures, built_in_props_1.SemanticCallTag.Random])) {
|
|
378
|
+
if (!builtIn || built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), [built_in_props_1.CallProp.Configures, built_in_props_1.SemanticCallTag.Random, built_in_props_1.SemanticCallTag.AttachesPackage, built_in_props_1.SemanticCallTag.DetachesPackage])) {
|
|
378
379
|
return true;
|
|
379
380
|
}
|
|
380
381
|
}
|
|
@@ -765,6 +765,15 @@ the edge names the vertex that decides (e.g. an \`if\`) and whether it is the br
|
|
|
765
765
|
}
|
|
766
766
|
return results.join('\n');
|
|
767
767
|
}
|
|
768
|
+
/** what `library(tidyverse)` would do, asked without analyzing any code */
|
|
769
|
+
function askWhatLibraryDoes(analyzer) {
|
|
770
|
+
const ctx = analyzer.context();
|
|
771
|
+
return {
|
|
772
|
+
attaches: df_helper_1.Dataflow.library.attaches(ctx, 'tidyverse'), // the search() entries it adds, dplyr, ggplot2, ... included
|
|
773
|
+
loads: df_helper_1.Dataflow.library.loads(ctx, 'tidyverse'), // every namespace it loads, transitively
|
|
774
|
+
layers: df_helper_1.Dataflow.library.layers(ctx, 'tidyverse') // the namespace and imports environments it attaches
|
|
775
|
+
};
|
|
776
|
+
}
|
|
768
777
|
async function dummyDataflow() {
|
|
769
778
|
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder().build();
|
|
770
779
|
analyzer.addRequest('x <- 1\nx + 1');
|
|
@@ -1022,7 +1031,17 @@ Mirroring R's \`search()\`, _flowR_ inserts the package's namespace and imports
|
|
|
1022
1031
|
A global binding shadows a package export of the same name, exactly as in R.
|
|
1023
1032
|
The most recently attached package is the nearest one, and re-attaching neither moves nor duplicates it.
|
|
1024
1033
|
The \`pos\` argument attaches further down the search path instead, given either as a position or as the name of an existing entry (an unknown position or name falls back to the default of 2, directly below the global environment).
|
|
1025
|
-
Attaching inside a function propagates to the caller (R attaches globally)
|
|
1034
|
+
Attaching inside a function propagates to the caller (R attaches globally).
|
|
1035
|
+
A package attached in only one branch, or in a loop body that may not run, or by a function called in one, is only maybe attached: its exports may be what a name means, but so may whatever it would shadow.
|
|
1036
|
+
\`detach\` and \`unloadNamespace\` remove the entry again (named, by position, or the topmost one), uncovering what it masked.
|
|
1037
|
+
|
|
1038
|
+
Attaching brings a package's \`Depends\` onto the search path below it (so the package masks them), and for a meta-package like \`tidyverse\` the core set of that version above it, while its \`Imports\` are only loaded: \`pkg::fn\` resolves for them, a bare \`fn\` does not.
|
|
1039
|
+
Besides \`library\` and \`require\`, the multi-package loaders \`pacman::p_load\`, \`librarian::shelf\`, \`xfun::pkg_attach\` and \`easypackages::libraries\` attach the same way.
|
|
1040
|
+
To ask what a \`library\` call does without analyzing any code, use ${ctx.link('Dataflow::library')}, which builds the very layers the analysis would:
|
|
1041
|
+
|
|
1042
|
+
${ctx.code(askWhatLibraryDoes, { dropLinesStart: 1 })}
|
|
1043
|
+
|
|
1044
|
+
It answers from the signature database at the versions the analysis assumes, and also from what flowR states about a package and from the \`NAMESPACE\` files it read.
|
|
1026
1045
|
|
|
1027
1046
|
Last but not least, the information contains the single **entry point** (${JSON.stringify(result.entryPoint)}) and a set of **exit points** (${JSON.stringify(result.exitPoints.map(e => e.nodeId))}).
|
|
1028
1047
|
Besides marking potential exits, the exit points also provide information about why the exit occurs and which control dependencies affect the exit.
|
|
@@ -36,13 +36,19 @@ function addressParam(params) {
|
|
|
36
36
|
*/
|
|
37
37
|
function networkFunctions(index) {
|
|
38
38
|
const resources = new Map();
|
|
39
|
+
/* the calls with a destination they save to, like the `destfile` of a download, which is a path rather than an address */
|
|
40
|
+
const saving = new Set();
|
|
39
41
|
for (const param of index.params(built_in_props_1.ArgProp.Resource)) {
|
|
42
|
+
const key = identifier_1.Identifier.toString(param.call);
|
|
40
43
|
/* R opens a path it writes to as a local file (or a `|` pipe), never as a url, and a command is no address either */
|
|
41
44
|
const tags = index.get(param.call)?.tags;
|
|
45
|
+
if ((param.props & built_in_props_1.ArgProp.Written) !== 0) {
|
|
46
|
+
saving.add(key);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
42
49
|
if ((tags?.includes(built_in_props_1.SemanticCallTag.Writes) && !tags.includes(built_in_props_1.SemanticCallTag.Reads)) || tags?.includes(built_in_props_1.SemanticCallTag.Process)) {
|
|
43
50
|
continue;
|
|
44
51
|
}
|
|
45
|
-
const key = identifier_1.Identifier.toString(param.call);
|
|
46
52
|
resources.set(key, [...resources.get(key) ?? [], param]);
|
|
47
53
|
}
|
|
48
54
|
const names = new Map(index.with(built_in_props_1.SemanticCallTag.Network).map(call => [identifier_1.Identifier.toString(call), call]));
|
|
@@ -55,10 +61,12 @@ function networkFunctions(index) {
|
|
|
55
61
|
const params = resources.get(key);
|
|
56
62
|
const address = params === undefined ? undefined : addressParam(params);
|
|
57
63
|
const tags = index.get(name)?.tags;
|
|
64
|
+
/* a call touching files only to save what it fetched, like `req_perform(req, path)`, opens no local file in place of the network */
|
|
65
|
+
const mayOpenLocal = tags?.includes(built_in_props_1.SemanticCallTag.File) && !(saving.has(key) && address === undefined);
|
|
58
66
|
return {
|
|
59
67
|
name,
|
|
60
68
|
...(address === undefined ? {} : { info: { argIdx: address.index, argName: address.name, resolveValue: true } }),
|
|
61
|
-
...(tags?.includes(built_in_props_1.SemanticCallTag.Network) && !
|
|
69
|
+
...(tags?.includes(built_in_props_1.SemanticCallTag.Network) && !mayOpenLocal ? {} : { onlyTriggerWithArgument: UrlPattern })
|
|
62
70
|
};
|
|
63
71
|
});
|
|
64
72
|
}
|
|
@@ -65,9 +65,9 @@ function assignedNames(graph, ctx) {
|
|
|
65
65
|
}
|
|
66
66
|
return names;
|
|
67
67
|
}
|
|
68
|
-
/** calls that load or attach a package
|
|
68
|
+
/** calls that load or attach a package; an unresolved one means we cannot enumerate all exports in scope */
|
|
69
69
|
function libraryLoadFunctions(index) {
|
|
70
|
-
return new Set([...(0, linter_util_1.namesWith)(index, built_in_props_1.SemanticCallTag.LoadsPackage), ...(0, linter_util_1.namesWith)(index, built_in_props_1.SemanticCallTag.AttachesPackage)
|
|
70
|
+
return new Set([...(0, linter_util_1.namesWith)(index, built_in_props_1.SemanticCallTag.LoadsPackage), ...(0, linter_util_1.namesWith)(index, built_in_props_1.SemanticCallTag.AttachesPackage)]);
|
|
71
71
|
}
|
|
72
72
|
/** test frameworks whose namespace a test file runs under implicitly (e.g. `tests/testthat/test-*.R` sees testthat's exports without a `library()`) */
|
|
73
73
|
const ImplicitTestFrameworks = ['testthat', 'tinytest', 'RUnit'];
|
|
@@ -61,8 +61,18 @@ function unusedPackages(attachments, graph, src) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/* what each imported package exports, read once: asking which packages export a name searches the whole database */
|
|
65
|
+
const exportsOf = new Map();
|
|
66
|
+
const exports = (pkg) => {
|
|
67
|
+
let found = exportsOf.get(pkg);
|
|
68
|
+
if (found === undefined) {
|
|
69
|
+
found = new Set(src.lookup(pkg)?.exported);
|
|
70
|
+
exportsOf.set(pkg, found);
|
|
71
|
+
}
|
|
72
|
+
return found;
|
|
73
|
+
};
|
|
64
74
|
for (const { name, callable, imports } of attachments) {
|
|
65
|
-
const usesPackage = (call) => callable.has(call) ||
|
|
75
|
+
const usesPackage = (call) => callable.has(call) || imports.values().some(p => exports(p).has(call));
|
|
66
76
|
if (pending.has(name) && unbound.values().some(usesPackage)) {
|
|
67
77
|
pending.delete(name);
|
|
68
78
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { PackageSignatureSource } from './sigdb/reader';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* whole set on the search path, so `library(tidyverse)` has to resolve `ggplot()`.
|
|
6
|
-
* `Depends` is handled generally by {@link attachedAlongside} and hence not repeated here.
|
|
3
|
+
* The core set the {@link MetaPackageCores|meta-package} `pack` attaches from its `.onAttach` hook at `version`
|
|
4
|
+
* (the newest release's when unknown, the oldest one's for a version predating every recorded release), empty for any other package.
|
|
7
5
|
*/
|
|
8
|
-
export declare
|
|
6
|
+
export declare function metaPackageCore(pack: string, version?: string): readonly string[];
|
|
7
|
+
/** What attaching a package puts on the search path with it, in the order R attaches them. */
|
|
8
|
+
export interface AttachedAlongside {
|
|
9
|
+
/** what it `Depends` on: R attaches these first, so they end up below it */
|
|
10
|
+
readonly depends: readonly string[];
|
|
11
|
+
/** the core set a {@link MetaPackageCores|meta-package} attaches from its `.onAttach` hook, above it */
|
|
12
|
+
readonly onAttach: readonly string[];
|
|
13
|
+
}
|
|
9
14
|
/**
|
|
10
15
|
* The packages that end up on the search path alongside `pack` when it is attached: everything it `Depends` on
|
|
11
16
|
* (which R attaches with it) and, for a {@link MetaPackageCores|meta-package}, the core set it attaches itself.
|
|
12
17
|
*/
|
|
13
|
-
export declare function attachedAlongside(pack: string, sources: readonly PackageSignatureSource[], version?: string):
|
|
18
|
+
export declare function attachedAlongside(pack: string, sources: readonly PackageSignatureSource[], version?: string): AttachedAlongside;
|