@eagleoutice/flowr 2.15.10 → 2.16.0
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 +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/control-flow/happens-before.d.ts +5 -0
- package/control-flow/happens-before.js +48 -34
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/built-in-props.d.ts +9 -0
- package/dataflow/environments/built-in-props.js +25 -19
- package/dataflow/environments/built-in.d.ts +2 -2
- package/dataflow/environments/built-in.js +41 -77
- package/dataflow/environments/default-builtin-config.d.ts +181 -29
- package/dataflow/environments/default-builtin-config.js +38 -24
- package/dataflow/environments/environment.d.ts +6 -4
- package/dataflow/environments/environment.js +54 -121
- package/dataflow/environments/identifier.d.ts +4 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +176 -59
- package/dataflow/fn/class-declaration.d.ts +8 -2
- package/dataflow/fn/class-declaration.js +96 -97
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +51 -41
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.js +13 -17
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +285 -122
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +6 -1
- package/dataflow/graph/graph.js +57 -66
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +31 -4
- package/dataflow/internal/control-flow.js +61 -39
- package/dataflow/internal/linker.d.ts +15 -9
- package/dataflow/internal/linker.js +253 -241
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
- 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 +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
- package/dataflow/internal/process/functions/call/common.d.ts +1 -3
- package/dataflow/internal/process/functions/call/common.js +36 -76
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
- package/dataflow/internal/process/functions/call/deferred.js +54 -57
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +162 -172
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +3 -6
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/wiki-setup.js +23 -0
- package/linter/linter-rules.d.ts +17 -8
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +114 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +128 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.js +6 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell.js +6 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +115 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -40,10 +40,8 @@ const StructuralRoles = new Set([
|
|
|
40
40
|
function collectAliveNodes(ast, reachable) {
|
|
41
41
|
const alive = new Set();
|
|
42
42
|
for (const id of reachable) {
|
|
43
|
-
let node = ast.idMap.get(id);
|
|
44
|
-
while (node !== undefined && !alive.has(node.info.id)) {
|
|
43
|
+
for (let node = ast.idMap.get(id); node !== undefined && !alive.has(node.info.id); node = model_1.RNode.directParent(node, ast.idMap)) {
|
|
45
44
|
alive.add(node.info.id);
|
|
46
|
-
node = node.info.parent === undefined ? undefined : ast.idMap.get(node.info.parent);
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
return alive;
|
|
@@ -58,10 +56,7 @@ function isReachedByControlFlow(node, alive) {
|
|
|
58
56
|
if (alive.has(node.info.id)) {
|
|
59
57
|
return true;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
return node.info.parent !== undefined && alive.has(node.info.parent);
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
59
|
+
return StructuralRoles.has(node.info.role) && node.info.parent !== undefined && alive.has(node.info.parent);
|
|
65
60
|
}
|
|
66
61
|
/**
|
|
67
62
|
* One entry per distinct call target. A call to a package export is modelled by the built-in flowR states for
|
|
@@ -107,37 +102,15 @@ exports.Enrichments = {
|
|
|
107
102
|
const n = shared?.ast ?? await analyzer.normalize();
|
|
108
103
|
const callVertex = df.graph.getVertex(e.node.info.id);
|
|
109
104
|
if (vertex_1.DfgVertex.isFunctionCall(callVertex)) {
|
|
110
|
-
const origins = df_helper_1.Dataflow.origin(df.graph, callVertex.id);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
content.targets =
|
|
105
|
+
const origins = df_helper_1.Dataflow.origin(df.graph, callVertex.id) ?? [];
|
|
106
|
+
// find call targets in user code (which have ids!)
|
|
107
|
+
const targets = origins.map(targetOf).filter(assert_1.isNotUndefined);
|
|
108
|
+
if (targets.length > 0) {
|
|
109
|
+
content.targets = targets;
|
|
115
110
|
}
|
|
116
111
|
else {
|
|
117
|
-
|
|
118
|
-
content.targets = origins
|
|
119
|
-
switch (o.type) {
|
|
120
|
-
case 2 /* OriginType.FunctionCallOrigin */: {
|
|
121
|
-
if (node_id_1.NodeId.isBuiltIn(o.id)) {
|
|
122
|
-
// a built-in target (e.g. a materialized package export from `library()`) has no
|
|
123
|
-
// user-code node, so surface it as a built-in identifier (see `onlyBuiltin` below)
|
|
124
|
-
const name = node_id_1.NodeId.recoverName(o.id, n.idMap);
|
|
125
|
-
return qualifyIdentifier([o], name) ?? String(o.id);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return { node: n.idMap.get(o.id) };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
case 3 /* OriginType.BuiltInFunctionOrigin */:
|
|
132
|
-
return qualifyIdentifier([o], o.fn.name);
|
|
133
|
-
default:
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
}).filter(assert_1.isNotUndefined);
|
|
137
|
-
if (content.targets.length === 0) {
|
|
138
|
-
const name = node_id_1.NodeId.recoverName(callVertex.id, n.idMap);
|
|
139
|
-
content.targets = [qualifyIdentifier(origins, name)];
|
|
140
|
-
}
|
|
112
|
+
const name = node_id_1.NodeId.recoverName(callVertex.id, n.idMap);
|
|
113
|
+
content.targets = [qualifyIdentifier(origins, name)];
|
|
141
114
|
}
|
|
142
115
|
}
|
|
143
116
|
/* a package export and the built-in flowR models it with are one target seen twice, so keep the
|
|
@@ -152,6 +125,21 @@ exports.Enrichments = {
|
|
|
152
125
|
content.targets.push(...prev.targets);
|
|
153
126
|
}
|
|
154
127
|
return content;
|
|
128
|
+
function targetOf(o) {
|
|
129
|
+
switch (o.type) {
|
|
130
|
+
case 2 /* OriginType.FunctionCallOrigin */:
|
|
131
|
+
if (node_id_1.NodeId.isBuiltIn(o.id)) {
|
|
132
|
+
// a built-in target (e.g. a materialized package export from `library()`) has no
|
|
133
|
+
// user-code node, so surface it as a built-in identifier (see `onlyBuiltin` above)
|
|
134
|
+
return qualifyIdentifier([o], node_id_1.NodeId.recoverName(o.id, n.idMap)) ?? String(o.id);
|
|
135
|
+
}
|
|
136
|
+
return { node: n.idMap.get(o.id) };
|
|
137
|
+
case 3 /* OriginType.BuiltInFunctionOrigin */:
|
|
138
|
+
return qualifyIdentifier([o], o.fn.name);
|
|
139
|
+
default:
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
155
143
|
function qualifyIdentifier(origins, name) {
|
|
156
144
|
if (args?.qualifyNames === undefined || args.qualifyNames) {
|
|
157
145
|
const qualified = identifier_1.Identifier.toQualified(origins, name);
|
|
@@ -159,7 +147,7 @@ exports.Enrichments = {
|
|
|
159
147
|
return identifier_1.Identifier.toString(qualified);
|
|
160
148
|
}
|
|
161
149
|
}
|
|
162
|
-
return name;
|
|
150
|
+
return name === undefined ? undefined : identifier_1.Identifier.toString(name);
|
|
163
151
|
}
|
|
164
152
|
},
|
|
165
153
|
// as built-in call target enrichments are not nodes, we don't return them as part of the mapper!
|
|
@@ -11,8 +11,8 @@ import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/deco
|
|
|
11
11
|
/**
|
|
12
12
|
* Returns the function call targets (definitions) by the given caller
|
|
13
13
|
*/
|
|
14
|
-
export declare function getAllFunctionCallTargetsForSlice(dataflowGraph: DataflowGraph, callerInfo: DataflowGraphVertexFunctionCall, baseEnvironment: REnvironmentInformation,
|
|
15
|
-
/**
|
|
14
|
+
export declare function getAllFunctionCallTargetsForSlice(dataflowGraph: DataflowGraph, callerInfo: DataflowGraphVertexFunctionCall, baseEnvironment: REnvironmentInformation, ctx: ReadOnlyFlowrAnalyzerContext): [ReadonlySet<DataflowGraphVertexInfo>, REnvironmentInformation];
|
|
15
|
+
/** Links the call `callerInfo` to the definitions it resolves to, or to the closures of its arguments if it resolves to none. */
|
|
16
16
|
export declare function sliceForCall(current: NodeToSlice, callerInfo: DataflowGraphVertexFunctionCall, { graph }: DataflowInformation, queue: VisitingQueue, ctx: ReadOnlyFlowrAnalyzerContext): void;
|
|
17
17
|
/**
|
|
18
18
|
* Finds the nearest enclosing function-definition node for the given id by walking up the AST parent chain.
|
|
@@ -34,7 +34,8 @@ export declare function sliceReachesFunctionInterface(fnDefId: NodeId, graph: Da
|
|
|
34
34
|
* `calls` edges). Call site arguments are picked up automatically once the call vertex is processed normally,
|
|
35
35
|
* as `argument` edges are always traversed.
|
|
36
36
|
* This is the reverse of what {@link sliceForCall} does for call -\> definition linking.
|
|
37
|
+
* @returns the enqueued ids
|
|
37
38
|
*/
|
|
38
|
-
export declare function includeCalleesOfDefinition(fnDefId: NodeId, graph: DataflowGraph, queue: VisitingQueue, baseEnvironment: REnvironmentInformation, baseEnvFingerprint: Fingerprint):
|
|
39
|
+
export declare function includeCalleesOfDefinition(fnDefId: NodeId, graph: DataflowGraph, queue: VisitingQueue, baseEnvironment: REnvironmentInformation, baseEnvFingerprint: Fingerprint): NodeId[];
|
|
39
40
|
/** Returns true if we found at least one return edge */
|
|
40
41
|
export declare function handleReturns(from: NodeId, queue: VisitingQueue, currentEdges: OutgoingEdges, baseEnvFingerprint: Fingerprint, baseEnvironment: REnvironmentInformation): boolean;
|
|
@@ -18,87 +18,73 @@ const built_in_function_definition_1 = require("../../dataflow/internal/process/
|
|
|
18
18
|
const static_slicer_1 = require("./static-slicer");
|
|
19
19
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
20
20
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
21
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
21
22
|
const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
|
|
22
23
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
23
24
|
const NoCallTargets = new Set();
|
|
25
|
+
const linkedByGraph = new WeakMap();
|
|
26
|
+
function linkedDefinitions(defs, graph) {
|
|
27
|
+
let known = linkedByGraph.get(graph);
|
|
28
|
+
if (known === undefined) {
|
|
29
|
+
linkedByGraph.set(graph, known = new Map());
|
|
30
|
+
}
|
|
31
|
+
const key = defs.join(';');
|
|
32
|
+
let linked = known.get(key);
|
|
33
|
+
if (linked === undefined) {
|
|
34
|
+
known.set(key, linked = (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(defs), graph)[0]);
|
|
35
|
+
}
|
|
36
|
+
return linked;
|
|
37
|
+
}
|
|
24
38
|
/**
|
|
25
39
|
* Returns the function call targets (definitions) by the given caller
|
|
26
40
|
*/
|
|
27
|
-
function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnvironment,
|
|
41
|
+
function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnvironment, ctx) {
|
|
42
|
+
(0, assert_1.guard)(dataflowGraph.hasVertex(callerInfo.id), () => `outgoing edges of id: ${callerInfo.id} must be in graph but can not be found, keep in slice to be sure`);
|
|
28
43
|
// bind with call-local environments during slicing
|
|
29
|
-
const outgoingEdges = dataflowGraph.get(callerInfo.id, true);
|
|
30
|
-
(0, assert_1.guard)(outgoingEdges !== undefined, () => `outgoing edges of id: ${callerInfo.id} must be in graph but can not be found, keep in slice to be sure`);
|
|
31
|
-
// lift baseEnv on the same level
|
|
32
44
|
const activeEnvironment = callerInfo.environment === undefined ? baseEnvironment : (0, built_in_function_definition_1.retrieveActiveEnvironment)(callerInfo.environment, baseEnvironment, ctx);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
for (const d of resolve_helper_1.Resolve.byName(name, activeEnvironment) ?? []) {
|
|
37
|
-
if (!node_id_1.NodeId.isBuiltIn(d.definedAt)) {
|
|
38
|
-
functionCallDefs.push(d.nodeId);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const [target, outgoingEdge] of outgoingEdges[1].entries()) {
|
|
42
|
-
if (edge_1.DfEdge.includesType(outgoingEdge, edge_1.EdgeType.Calls)) {
|
|
43
|
-
functionCallDefs.push(target);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const functionCallTargets = functionCallDefs.length === 0 ? NoCallTargets :
|
|
47
|
-
queue.memoizeCallTargets(functionCallDefs.join(';'), () => (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(functionCallDefs), dataflowGraph)[0]);
|
|
45
|
+
const resolved = (resolve_helper_1.Resolve.byName(callerInfo.name, activeEnvironment) ?? []).filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt));
|
|
46
|
+
const functionCallDefs = [...resolved.map(d => d.nodeId), ...(0, frame_reflection_1.edgeTargets)(dataflowGraph, callerInfo.id, edge_1.EdgeType.Calls)];
|
|
47
|
+
const functionCallTargets = functionCallDefs.length === 0 ? NoCallTargets : linkedDefinitions(functionCallDefs, dataflowGraph);
|
|
48
48
|
return [functionCallTargets, activeEnvironment];
|
|
49
49
|
}
|
|
50
|
-
function includeArgumentFunctionCallClosure(arg, activeEnvironment, activeEnvironmentFingerprint, queue, dataflowGraph) {
|
|
51
|
-
const valueRoot = graph_1.FunctionArgument.getReference(arg);
|
|
52
|
-
if (!valueRoot) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const callTargets = queue.memoizeCallTargets(valueRoot, () => (0, linker_1.getAllLinkedFunctionDefinitions)(new Set([valueRoot]), dataflowGraph)[0]);
|
|
56
|
-
linkCallTargets(false, callTargets, activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
57
|
-
}
|
|
58
50
|
function linkCallTargets(onlyForSideEffects, functionCallTargets, activeEnvironment, activeEnvironmentFingerprint, queue) {
|
|
59
51
|
for (const functionCallTarget of functionCallTargets) {
|
|
60
|
-
for
|
|
61
|
-
|
|
52
|
+
/* a call kept only for what it does needs what its function reads, not what it returns */
|
|
53
|
+
for (const exitPoint of onlyForSideEffects ? [] : functionCallTarget.exitPoints) {
|
|
54
|
+
queue.add(exitPoint.nodeId, activeEnvironment, activeEnvironmentFingerprint(), false);
|
|
62
55
|
}
|
|
63
|
-
// handle open reads
|
|
64
56
|
for (const openIn of functionCallTarget.subflow.in) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const resolved = resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment);
|
|
68
|
-
for (const res of resolved ?? []) {
|
|
69
|
-
(0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint());
|
|
70
|
-
}
|
|
57
|
+
for (const res of openIn.name ? resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment) ?? [] : []) {
|
|
58
|
+
(0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint());
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
/**
|
|
63
|
+
/** Links the call `callerInfo` to the definitions it resolves to, or to the closures of its arguments if it resolves to none. */
|
|
76
64
|
function sliceForCall(current, callerInfo, { graph }, queue, ctx) {
|
|
77
|
-
const [functionCallTargets, activeEnvironment] = getAllFunctionCallTargetsForSlice(graph, callerInfo, current.baseEnvironment,
|
|
65
|
+
const [functionCallTargets, activeEnvironment] = getAllFunctionCallTargetsForSlice(graph, callerInfo, current.baseEnvironment, ctx);
|
|
78
66
|
/* hashing the environment is expensive, so only a call that links something pays for it */
|
|
79
67
|
let fingerprint;
|
|
80
68
|
const activeEnvironmentFingerprint = () => fingerprint ??= activeEnvironment === current.baseEnvironment ? current.envFingerprint : (0, fingerprint_1.envFingerprint)(activeEnvironment);
|
|
81
|
-
if (functionCallTargets.size
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (const arg of callerInfo.args) {
|
|
93
|
-
const reference = graph_1.FunctionArgument.getReference(arg);
|
|
94
|
-
const edge = reference === undefined ? undefined : outgoing?.get(reference);
|
|
95
|
-
if (edge === undefined || !edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
|
|
96
|
-
includeArgumentFunctionCallClosure(arg, activeEnvironment, activeEnvironmentFingerprint, queue, graph);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
69
|
+
if (functionCallTargets.size > 0) {
|
|
70
|
+
linkCallTargets(current.onlyForSideEffects, functionCallTargets, activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
* if we do not have any call to resolve this function, we have to assume that every function passed is actually called!
|
|
75
|
+
* hence, we add all argument values to the queue causing directly
|
|
76
|
+
* (an assignment only stores the function, and a call handing an argument back unchanged, like `return(f)`,
|
|
77
|
+
* did not call it either: what it is bound to is called later, or never)
|
|
78
|
+
*/
|
|
79
|
+
if (vertex_1.DfgVertex.hasOrigin(callerInfo, built_in_proc_name_1.BuiltInProcName.Assignment)) {
|
|
99
80
|
return;
|
|
100
81
|
}
|
|
101
|
-
|
|
82
|
+
for (const arg of callerInfo.args) {
|
|
83
|
+
const reference = graph_1.FunctionArgument.getReference(arg);
|
|
84
|
+
if (reference && !(0, frame_reflection_1.hasEdgeOfType)(graph, callerInfo.id, reference, edge_1.EdgeType.Returns)) {
|
|
85
|
+
linkCallTargets(false, linkedDefinitions([reference], graph), activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
102
88
|
}
|
|
103
89
|
/**
|
|
104
90
|
* Finds the nearest enclosing function-definition node for the given id by walking up the AST parent chain.
|
|
@@ -117,31 +103,23 @@ function findEnclosingFunctionDefinition(id, idMap) {
|
|
|
117
103
|
*/
|
|
118
104
|
function sliceReachesFunctionInterface(fnDefId, graph, queue, idMap, ctx) {
|
|
119
105
|
const vertex = graph.getVertex(fnDefId);
|
|
120
|
-
if (
|
|
106
|
+
if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
121
107
|
return false;
|
|
122
108
|
}
|
|
123
109
|
// (a) the slice reaches a parameter of this definition
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
110
|
+
if (Object.keys(vertex.params).some(paramId => queue.hasId(node_id_1.NodeId.normalize(paramId)))) {
|
|
111
|
+
return true;
|
|
128
112
|
}
|
|
129
113
|
// (b) a sliced body node captures a variable from the enclosing scope: it links (via `defined-by-on-call`, the
|
|
130
114
|
// closure/argument binding resolved at the call site) to a non-builtin definition that lives outside this body.
|
|
131
|
-
const
|
|
132
|
-
const bodyIds = fnNode ? new Set(model_1.RNode.collectAllIds(fnNode)) : new Set();
|
|
115
|
+
const bodyIds = model_1.RNode.collectAllIds(idMap.get(fnDefId));
|
|
133
116
|
for (const bodyId of bodyIds) {
|
|
134
117
|
if (!queue.hasId(bodyId)) {
|
|
135
118
|
continue;
|
|
136
119
|
}
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
for (const [target, edge] of outgoing) {
|
|
142
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedByOnCall) && !node_id_1.NodeId.isBuiltIn(target) && !bodyIds.has(target)) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
120
|
+
const captures = (0, frame_reflection_1.edgeTargets)(graph, bodyId, edge_1.EdgeType.DefinedByOnCall);
|
|
121
|
+
if (captures.some(target => !node_id_1.NodeId.isBuiltIn(target) && !bodyIds.has(target))) {
|
|
122
|
+
return true;
|
|
145
123
|
}
|
|
146
124
|
}
|
|
147
125
|
// (c) fallback for captures that could not be resolved at definition time: an open in-reference that is in the
|
|
@@ -165,29 +143,19 @@ const CalleeBoundaryEdges = edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Calls;
|
|
|
165
143
|
* `calls` edges). Call site arguments are picked up automatically once the call vertex is processed normally,
|
|
166
144
|
* as `argument` edges are always traversed.
|
|
167
145
|
* This is the reverse of what {@link sliceForCall} does for call -\> definition linking.
|
|
146
|
+
* @returns the enqueued ids
|
|
168
147
|
*/
|
|
169
148
|
function includeCalleesOfDefinition(fnDefId, graph, queue, baseEnvironment, baseEnvFingerprint) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
for (const [source, edge] of ingoing) {
|
|
175
|
-
if (edge_1.DfEdge.includesType(edge, CalleeBoundaryEdges)) {
|
|
176
|
-
queue.add(source, baseEnvironment, baseEnvFingerprint, false);
|
|
177
|
-
}
|
|
149
|
+
const added = (0, frame_reflection_1.edgeSources)(graph, fnDefId, CalleeBoundaryEdges);
|
|
150
|
+
for (const source of added) {
|
|
151
|
+
queue.add(source, baseEnvironment, baseEnvFingerprint, false);
|
|
178
152
|
}
|
|
153
|
+
return added;
|
|
179
154
|
}
|
|
180
155
|
const PotentialFollowOnReturn = edge_1.EdgeType.DefinesOnCall | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Argument;
|
|
181
156
|
/** Returns true if we found at least one return edge */
|
|
182
157
|
function handleReturns(from, queue, currentEdges, baseEnvFingerprint, baseEnvironment) {
|
|
183
|
-
|
|
184
|
-
for (const edge of currentEdges.values()) {
|
|
185
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
|
|
186
|
-
returns = true;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!returns) {
|
|
158
|
+
if (![...currentEdges.values()].some(edge => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns))) {
|
|
191
159
|
return false;
|
|
192
160
|
}
|
|
193
161
|
for (const [target, edge] of currentEdges) {
|
|
@@ -10,10 +10,14 @@ const visiting_queue_1 = require("./visiting-queue");
|
|
|
10
10
|
const slice_call_1 = require("./slice-call");
|
|
11
11
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
12
12
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
13
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
14
|
+
const function_semantics_1 = require("../../dataflow/fn/function-semantics");
|
|
13
15
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
14
16
|
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
15
17
|
const slice_direction_1 = require("../../util/slice-direction");
|
|
16
18
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
19
|
+
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
20
|
+
const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
17
21
|
exports.slicerLogger = log_1.log.getSubLogger({ name: 'slicer' });
|
|
18
22
|
/**
|
|
19
23
|
* Computes the node ids to include in a static slice, starting from the given seed ids.
|
|
@@ -23,53 +27,56 @@ function staticSlice(options) {
|
|
|
23
27
|
const { ctx, info, ids, cache, sliceGraph } = options;
|
|
24
28
|
const { idMap } = options.ast;
|
|
25
29
|
const direction = options.direction ?? slice_direction_1.SliceDirection.Backward;
|
|
26
|
-
const threshold = options.threshold ?? 75;
|
|
27
30
|
(0, assert_1.guard)(ids.length > 0, 'must have at least one seed id to calculate slice');
|
|
28
31
|
// includeCallees only makes sense on the original (non-reduced) graph, backward
|
|
29
32
|
const trackCallees = (options.includeCallees ?? false) && direction === slice_direction_1.SliceDirection.Backward && sliceGraph === undefined;
|
|
30
33
|
// enclosing function definitions whose callees still need to be considered, mapped to the env to enqueue them in
|
|
31
34
|
const pendingCalleeBoundaries = new Map();
|
|
32
35
|
const resolvedCalleeBoundaries = new Set();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
graph = info.graph;
|
|
39
|
-
if (direction === slice_direction_1.SliceDirection.Forward) {
|
|
40
|
-
graph = df_helper_1.Dataflow.invertGraph(graph, ctx.env.makeCleanEnv());
|
|
36
|
+
/* a body entered through a call gets its arguments from that call, so only bodies the slice starts in open their callers */
|
|
37
|
+
const openedBodies = new Set();
|
|
38
|
+
const openBodiesAround = (from) => {
|
|
39
|
+
for (let fn = model_1.RNode.findEnclosing(from, idMap, r_function_definition_1.RFunctionDefinition.is); fn !== undefined; fn = model_1.RNode.strictlyEnclosingFunction(fn, idMap)) {
|
|
40
|
+
openedBodies.add(fn);
|
|
41
41
|
}
|
|
42
|
-
}
|
|
43
|
-
const
|
|
42
|
+
};
|
|
43
|
+
const graph = sliceGraph ?? (direction === slice_direction_1.SliceDirection.Forward ? df_helper_1.Dataflow.invertGraph(info.graph, ctx.env.makeCleanEnv()) : info.graph);
|
|
44
|
+
const emptyEnv = ctx.env.makeCleanEnv();
|
|
45
|
+
const basePrint = ctx.env.getCleanEnvFingerprint();
|
|
46
|
+
const queue = new visiting_queue_1.VisitingQueue(options.threshold ?? 75, cache, graph, ctx.gas.scope(options.gas), [emptyEnv, basePrint]);
|
|
47
|
+
const enclosingHandled = new Set();
|
|
48
|
+
const enqueue = (id, env, print) => {
|
|
49
|
+
if (!queue.hasId(id)) {
|
|
50
|
+
queue.add(id, env, print, true);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
44
53
|
let minNesting = Number.MAX_SAFE_INTEGER;
|
|
45
54
|
const sliceSeedIds = new Set();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
|
|
54
|
-
sliceSeedIds.add(startId);
|
|
55
|
-
}
|
|
56
|
-
/* additionally,
|
|
57
|
-
* include all the implicit side effects that we have to consider as we are unable to narrow them down
|
|
58
|
-
*/
|
|
59
|
-
for (const id of graph.unknownSideEffects) {
|
|
60
|
-
if (typeof id !== 'object') {
|
|
61
|
-
/* otherwise, their target is just missing */
|
|
62
|
-
queue.add(id, emptyEnv, basePrint, true);
|
|
63
|
-
}
|
|
55
|
+
for (const startId of ids) {
|
|
56
|
+
queue.add(startId, emptyEnv, basePrint, false);
|
|
57
|
+
// retrieve the minimum nesting of all nodes to only add control dependencies if they are "part" of the current execution
|
|
58
|
+
minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
|
|
59
|
+
sliceSeedIds.add(startId);
|
|
60
|
+
if (trackCallees) {
|
|
61
|
+
openBodiesAround(startId);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
64
|
+
/* include all the implicit side effects that we have to consider as we are unable to narrow them down */
|
|
65
|
+
for (const id of graph.unknownSideEffects) {
|
|
66
|
+
/* a linked side effect is no vertex of its own, its target is just missing */
|
|
67
|
+
if (typeof id !== 'object') {
|
|
68
|
+
queue.add(id, emptyEnv, basePrint, true);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/* a call asked about does what the functions it runs do, which includes what they print */
|
|
72
|
+
for (const id of outputWithinCallees(ids, graph)) {
|
|
73
|
+
queue.add(id, emptyEnv, basePrint, false);
|
|
74
|
+
}
|
|
75
|
+
/* a drained queue completes the body slice, only then can a boundary decide whether its callers matter */
|
|
66
76
|
do {
|
|
67
77
|
while (queue.nonEmpty()) {
|
|
68
78
|
processNode();
|
|
69
79
|
}
|
|
70
|
-
// the queue drained: only now do we know the full body slice, so decide per boundary whether the callers
|
|
71
|
-
// can actually influence the result (i.e., the slice reaches a parameter or a captured scope variable).
|
|
72
|
-
// resolving a boundary may enqueue new nodes, hence the surrounding do-while re-enters the traversal.
|
|
73
80
|
resolveCalleeBoundaries();
|
|
74
81
|
} while (queue.nonEmpty());
|
|
75
82
|
function processNode() {
|
|
@@ -81,31 +88,41 @@ function staticSlice(options) {
|
|
|
81
88
|
return;
|
|
82
89
|
}
|
|
83
90
|
const [currentVertex, currentEdges] = currentInfo;
|
|
91
|
+
const strictlyEnclosing = model_1.RNode.strictlyEnclosingFunction(id, idMap);
|
|
92
|
+
if (!enclosingHandled.has(strictlyEnclosing)) {
|
|
93
|
+
enclosingHandled.add(strictlyEnclosing);
|
|
94
|
+
definitionWithHolders(strictlyEnclosing, idMap, graph).forEach(outer => enqueue(outer, emptyEnv, basePrint));
|
|
95
|
+
}
|
|
84
96
|
// includeCallees: note the enclosing function definition (if any) so its callees can be considered once the body slice is complete
|
|
85
97
|
if (trackCallees) {
|
|
86
|
-
const enclosingFnDef = (
|
|
87
|
-
if (enclosingFnDef !== undefined && !resolvedCalleeBoundaries.has(enclosingFnDef) && !pendingCalleeBoundaries.has(enclosingFnDef)) {
|
|
98
|
+
const enclosingFnDef = r_function_definition_1.RFunctionDefinition.is(idMap.get(id)) ? id : strictlyEnclosing;
|
|
99
|
+
if (enclosingFnDef !== undefined && openedBodies.has(enclosingFnDef) && !resolvedCalleeBoundaries.has(enclosingFnDef) && !pendingCalleeBoundaries.has(enclosingFnDef)) {
|
|
88
100
|
pendingCalleeBoundaries.set(enclosingFnDef, [baseEnvironment, baseEnvFingerprint]);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
|
|
97
|
-
}
|
|
103
|
+
/* control dependencies count only in a different call or at least at the nesting of the seeds */
|
|
104
|
+
const topLevel = graph.isRoot(id) || sliceSeedIds.has(id);
|
|
105
|
+
for (const cd of currentVertex.cds?.filter(({ id }) => !queue.hasId(id)) ?? []) {
|
|
106
|
+
if (!topLevel || (idMap.get(cd.id)?.info.nest ?? 0) >= minNesting) {
|
|
107
|
+
queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
/* a call or a definition within a promise runs only when the promise is forced, within captured code only when it is evaluated */
|
|
111
|
+
if (vertex_1.DfgVertex.isFunctionCall(currentVertex) || vertex_1.DfgVertex.isVariableDefinition(currentVertex)) {
|
|
112
|
+
const dependencies = function_semantics_1.FunctionSemantics.promiseDependencies(id, graph);
|
|
113
|
+
if (graph.isQuoted(id)) {
|
|
114
|
+
dependencies.push(...function_semantics_1.FunctionSemantics.call.quoted.evaluationDependencies(graph, id));
|
|
103
115
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
return;
|
|
116
|
+
for (const dep of dependencies) {
|
|
117
|
+
enqueue(dep, baseEnvironment, baseEnvFingerprint);
|
|
107
118
|
}
|
|
108
119
|
}
|
|
120
|
+
if (vertex_1.DfgVertex.isFunctionCall(currentVertex)) {
|
|
121
|
+
(0, slice_call_1.sliceForCall)(current, currentVertex, info, queue, ctx);
|
|
122
|
+
}
|
|
123
|
+
if (!onlyForSideEffects && (0, slice_call_1.handleReturns)(id, queue, currentEdges, baseEnvFingerprint, baseEnvironment)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
109
126
|
for (const [target, e] of currentEdges) {
|
|
110
127
|
const t = (0, edge_1.shouldTraverseEdge)(e);
|
|
111
128
|
switch (t) {
|
|
@@ -126,16 +143,13 @@ function staticSlice(options) {
|
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
function resolveCalleeBoundaries() {
|
|
129
|
-
if (pendingCalleeBoundaries.size === 0) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
146
|
const boundaries = [...pendingCalleeBoundaries];
|
|
133
147
|
pendingCalleeBoundaries.clear();
|
|
134
148
|
for (const [fnDefId, [env, fingerprint]] of boundaries) {
|
|
135
149
|
resolvedCalleeBoundaries.add(fnDefId);
|
|
136
150
|
// only continue past the boundary if the callers can actually influence the sliced result
|
|
137
151
|
if ((0, slice_call_1.sliceReachesFunctionInterface)(fnDefId, info.graph, queue, idMap, ctx)) {
|
|
138
|
-
(0, slice_call_1.includeCalleesOfDefinition)(fnDefId, info.graph, queue, env, fingerprint);
|
|
152
|
+
(0, slice_call_1.includeCalleesOfDefinition)(fnDefId, info.graph, queue, env, fingerprint).forEach(openBodiesAround);
|
|
139
153
|
}
|
|
140
154
|
}
|
|
141
155
|
}
|
|
@@ -143,6 +157,47 @@ function staticSlice(options) {
|
|
|
143
157
|
const result = ctx.config.solver.slicer?.autoExtend ? extendSlices(status.result, idMap) : status.result;
|
|
144
158
|
return { ...status, slicedFor: ids, result, freeNames: freeNamesOf(result, info.graph) };
|
|
145
159
|
}
|
|
160
|
+
/** The calls writing output (`cat`, `print`, ...: a side effect linked to `sink`) within the functions the call `seeds` run, transitively. */
|
|
161
|
+
function outputWithinCallees(seeds, graph) {
|
|
162
|
+
const writers = new Set();
|
|
163
|
+
for (const effect of graph.unknownSideEffects) {
|
|
164
|
+
if (typeof effect === 'object') {
|
|
165
|
+
writers.add(effect.id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (writers.size === 0) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const found = [];
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
const calls = [...seeds].filter(id => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(id)));
|
|
174
|
+
while (calls.length > 0) {
|
|
175
|
+
for (const target of (0, frame_reflection_1.calledDefinitions)(graph, calls.pop()).filter(t => !seen.has(t))) {
|
|
176
|
+
seen.add(target);
|
|
177
|
+
const callee = graph.getVertex(target);
|
|
178
|
+
found.push(...[...callee.subflow.graph].filter(inner => writers.has(inner)));
|
|
179
|
+
calls.push(...[...(0, frame_reflection_1.callsIn)(callee, graph)].map(([inner]) => inner));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return found;
|
|
183
|
+
}
|
|
184
|
+
/** The function `definition` and what holds it, up to its statement, as a body only runs as part of its definition. */
|
|
185
|
+
function definitionWithHolders(definition, idMap, graph) {
|
|
186
|
+
const definitionNode = definition === undefined ? undefined : idMap.get(definition);
|
|
187
|
+
if (definitionNode === undefined) {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
const outer = [definitionNode.info.id];
|
|
191
|
+
for (const node of model_1.RNode.iterateParents(definitionNode, idMap)) {
|
|
192
|
+
if (r_function_definition_1.RFunctionDefinition.is(node) || (r_expression_list_1.RExpressionList.is(node) && node.grouping?.[0].lexeme !== '(')) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (graph.hasVertex(node.info.id)) {
|
|
196
|
+
outer.push(node.info.id);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return outer;
|
|
200
|
+
}
|
|
146
201
|
/**
|
|
147
202
|
* The names the slice reads without defining them: a use whose definitions all stayed outside meets that name
|
|
148
203
|
* undefined, and so does one that reads nothing at all (a name the program never defines). Reading a built-in
|
|
@@ -154,13 +209,7 @@ function freeNamesOf(slice, graph) {
|
|
|
154
209
|
if (!vertex_1.DfgVertex.isUse(graph.getVertex(id))) {
|
|
155
210
|
continue;
|
|
156
211
|
}
|
|
157
|
-
|
|
158
|
-
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
159
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && (slice.has(target) || node_id_1.NodeId.isBuiltIn(target))) {
|
|
160
|
-
defined = true;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
212
|
+
const defined = (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).some(t => slice.has(t) || node_id_1.NodeId.isBuiltIn(t));
|
|
164
213
|
const name = defined ? undefined : node_id_1.NodeId.recoverName(id, graph.idMap);
|
|
165
214
|
if (name !== undefined) {
|
|
166
215
|
free.add(name);
|
|
@@ -180,18 +229,12 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
|
|
|
180
229
|
(0, assert_1.guard)(startIds.length > 0 && endIds.length > 0, 'must have at least one start and one end id for dicing');
|
|
181
230
|
const backward = staticSlice({ ctx, info, ast, ids: endIds, direction: slice_direction_1.SliceDirection.Backward, threshold, includeCallees, gas });
|
|
182
231
|
// reduce to backward result and invert edges in one pass; original info kept for sliceForCall
|
|
183
|
-
const
|
|
184
|
-
const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph
|
|
185
|
-
// explicit intersection handles seed nodes that landed outside the reduced graph
|
|
186
|
-
const result = new Set();
|
|
187
|
-
for (const id of forward.result) {
|
|
188
|
-
if (backward.result.has(id)) {
|
|
189
|
-
result.add(id);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
232
|
+
const sliceGraph = df_helper_1.Dataflow.reduceAndInvertGraph(info.graph, backward.result, ctx.env.makeCleanEnv());
|
|
233
|
+
const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph, gas });
|
|
192
234
|
return {
|
|
193
235
|
timesHitThreshold: forward.timesHitThreshold + backward.timesHitThreshold,
|
|
194
|
-
|
|
236
|
+
// explicit intersection handles seed nodes that landed outside the reduced graph
|
|
237
|
+
result: new Set([...forward.result].filter(id => backward.result.has(id))),
|
|
195
238
|
slicedFor: [...startIds, ...endIds],
|
|
196
239
|
...(forward.stoppedEarly || backward.stoppedEarly ? {
|
|
197
240
|
stoppedEarly: true,
|
|
@@ -203,18 +246,11 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
|
|
|
203
246
|
};
|
|
204
247
|
}
|
|
205
248
|
function extendSlices(results, ast) {
|
|
206
|
-
const res = new Set();
|
|
249
|
+
const res = new Set(results);
|
|
207
250
|
for (const id of results) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
parent = parent.info.parent ? ast.get(parent.info.parent) : undefined;
|
|
212
|
-
}
|
|
213
|
-
if (!parent) {
|
|
214
|
-
continue; // no parent, no need to extend
|
|
215
|
-
}
|
|
216
|
-
for (const id of model_1.RNode.collectAllIds(parent)) {
|
|
217
|
-
res.add(id);
|
|
251
|
+
const statement = model_1.RNode.findEnclosing(id, ast, n => n.info.role === "root" /* RoleInParent.Root */ || n.info.role === "el-c" /* RoleInParent.ExpressionListChild */);
|
|
252
|
+
for (const inner of statement === undefined ? [] : model_1.RNode.collectAllIds(ast.get(statement))) {
|
|
253
|
+
res.add(inner);
|
|
218
254
|
}
|
|
219
255
|
}
|
|
220
256
|
return res;
|