@eagleoutice/flowr 2.15.10 → 2.16.1
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/cli/flowr-main-options.d.ts +15 -0
- package/cli/flowr-main-options.js +18 -0
- package/cli/flowr.d.ts +18 -0
- package/cli/flowr.js +13 -2
- package/cli/repl/commands/repl-clipboard.js +2 -1
- package/cli/repl/commands/repl-commands.js +2 -0
- package/cli/repl/commands/repl-main.d.ts +5 -0
- package/cli/repl/commands/repl-signature.js +2 -0
- package/cli/repl/core.d.ts +7 -1
- package/cli/repl/core.js +17 -8
- package/cli/repl/execute.js +2 -0
- package/cli/repl/server/connection.js +2 -1
- package/cli/repl/server/net.d.ts +10 -0
- package/cli/repl/server/net.js +34 -1
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +12 -2
- package/config.js +91 -14
- 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 +185 -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 +64 -42
- 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 +42 -4
- package/dataflow/internal/control-flow.js +76 -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 +441 -79
- 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 +290 -252
- 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 +120 -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 +60 -58
- 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 +44 -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/doc-capabilities.js +4 -1
- package/documentation/wiki-interface.js +4 -0
- package/documentation/wiki-setup.js +23 -0
- package/engines.js +11 -3
- package/linter/linter-executor.js +19 -1
- 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 +117 -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 +130 -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-rda-file.d.ts +14 -5
- package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
- 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 +18 -42
- package/project/sigdb/decompress.js +3 -1
- package/project/sigdb/sigdb-download.js +9 -6
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/config-query/config-query-executor.js +9 -2
- 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-executor.js +2 -0
- package/r-bridge/shell.js +8 -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 +120 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/files.d.ts +6 -0
- package/util/files.js +12 -0
- package/util/parallel.js +2 -0
- 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/secure-mode.d.ts +42 -0
- package/util/secure-mode.js +70 -0
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -24,28 +24,14 @@ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol"
|
|
|
24
24
|
const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
|
|
25
25
|
const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
|
|
26
26
|
const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
27
|
+
const frame_reflection_1 = require("../../../dataflow/fn/frame-reflection");
|
|
27
28
|
/** how far a function handed to an entry point may be passed along before we give up resolving it */
|
|
28
29
|
const MaxFunctionResolveDepth = 4;
|
|
29
30
|
function isConstantLike(type) {
|
|
30
31
|
return type === input_types_1.InputType.Constant || type === input_types_1.InputType.DerivedConstant;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let result;
|
|
35
|
-
let seen = false;
|
|
36
|
-
for (const v of values) {
|
|
37
|
-
if (v === undefined) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
if (!seen) {
|
|
41
|
-
result = v;
|
|
42
|
-
seen = true;
|
|
43
|
-
}
|
|
44
|
-
else if (v !== result) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
33
|
+
function sourceOf(id, type) {
|
|
34
|
+
return { id, types: [type], trace: input_types_1.InputTraceType.Unknown };
|
|
49
35
|
}
|
|
50
36
|
/**
|
|
51
37
|
* Accumulates types, control-dependency types, values, and purity while traversing origin
|
|
@@ -57,59 +43,63 @@ class ClassificationAccumulator {
|
|
|
57
43
|
values = [];
|
|
58
44
|
allPure = true;
|
|
59
45
|
merge(c) {
|
|
46
|
+
if (c === undefined) {
|
|
47
|
+
this.push(input_types_1.InputType.Unknown);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
60
50
|
this.types.push(...c.types);
|
|
61
51
|
this.values.push(c.value);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (c.trace !== input_types_1.InputTraceType.Pure) {
|
|
66
|
-
this.allPure = false;
|
|
67
|
-
}
|
|
52
|
+
this.cds.push(...c.cds ?? []);
|
|
53
|
+
this.allPure &&= c.trace === input_types_1.InputTraceType.Pure;
|
|
68
54
|
}
|
|
69
|
-
|
|
70
|
-
this.types.push(
|
|
71
|
-
this.values.push(
|
|
55
|
+
push(type, value) {
|
|
56
|
+
this.types.push(type);
|
|
57
|
+
this.values.push(value);
|
|
72
58
|
}
|
|
73
59
|
build(id) {
|
|
74
60
|
const types = this.types.length === 0 ? [input_types_1.InputType.Unknown] : (0, arrays_1.uniqueArray)(this.types);
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return src;
|
|
61
|
+
const first = this.values[0];
|
|
62
|
+
const agreed = first !== undefined && this.values.every(v => v === first);
|
|
63
|
+
const value = agreed && types.every(isConstantLike) ? first : undefined;
|
|
64
|
+
return (0, objects_1.compactRecord)({
|
|
65
|
+
id,
|
|
66
|
+
types,
|
|
67
|
+
trace: this.allPure ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Alias,
|
|
68
|
+
cds: this.cds.length === 0 ? undefined : (0, arrays_1.uniqueArray)(this.cds),
|
|
69
|
+
value
|
|
70
|
+
});
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
73
|
class InputClassifier {
|
|
91
74
|
dfg;
|
|
92
75
|
config;
|
|
93
|
-
cache = new Map();
|
|
94
76
|
fullDfg;
|
|
95
|
-
/** the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
|
|
96
77
|
packages;
|
|
78
|
+
cache = new Map();
|
|
97
79
|
fullClassifier;
|
|
98
80
|
declarationIndex;
|
|
99
81
|
entryPointIndex;
|
|
82
|
+
/** `packages` are the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
|
|
100
83
|
constructor(dfg, config, fullDfg, packages) {
|
|
101
84
|
this.dfg = dfg;
|
|
102
85
|
this.config = config;
|
|
103
86
|
this.fullDfg = fullDfg;
|
|
104
87
|
this.packages = packages;
|
|
105
88
|
}
|
|
89
|
+
get whole() {
|
|
90
|
+
return this.fullDfg ?? this.dfg;
|
|
91
|
+
}
|
|
106
92
|
matches(call, list) {
|
|
107
|
-
return
|
|
93
|
+
return list?.some(id => call.id === id || (identifier_1.Identifier.is(id) && callMeans(call.name, id, this.packages))) ?? false;
|
|
108
94
|
}
|
|
109
95
|
/** whether the package the given entry needs is attached (unknown package information lets everything through) */
|
|
110
96
|
hasPackage(name) {
|
|
111
97
|
return name === undefined || this.packages === undefined || this.packages.has(name);
|
|
112
98
|
}
|
|
99
|
+
classifyAt(ref, graph = this.dfg) {
|
|
100
|
+
const vtx = ref === undefined ? undefined : graph.getVertex(ref);
|
|
101
|
+
return vtx ? this.classifyEntry(vtx) : undefined;
|
|
102
|
+
}
|
|
113
103
|
/**
|
|
114
104
|
* Returns the specification of the {@link LinkedInputObject|linked input object} the given id refers to
|
|
115
105
|
* (e.g., shiny's `input`), or `undefined` if it refers to something else.
|
|
@@ -120,12 +110,8 @@ class InputClassifier {
|
|
|
120
110
|
if (idMap === undefined || !r_symbol_1.RSymbol.is(node)) {
|
|
121
111
|
return undefined;
|
|
122
112
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (positional !== undefined) {
|
|
126
|
-
return positional;
|
|
127
|
-
}
|
|
128
|
-
return this.config.linkedObjects?.find(o => o.name === node.content && this.hasPackage(o.requires) && isBoundAsLinkedObject(node, o, idMap));
|
|
113
|
+
/* the framework may bind the object by position, in a function it is handed (`shinyApp(ui, server)`) */
|
|
114
|
+
return this.boundByEntryPoint(node, idMap) ?? this.config.linkedObjects?.find(o => o.name === node.content && this.hasPackage(o.requires) && isBoundAsLinkedObject(node, o, idMap));
|
|
129
115
|
}
|
|
130
116
|
/**
|
|
131
117
|
* The object a framework binds at this symbol's position, when the function binding it is handed to one of the
|
|
@@ -153,7 +139,7 @@ class InputClassifier {
|
|
|
153
139
|
}
|
|
154
140
|
const index = new Map();
|
|
155
141
|
this.entryPointIndex = index;
|
|
156
|
-
for (const [, call] of
|
|
142
|
+
for (const [, call] of this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
157
143
|
for (const entry of this.config.linkedEntryPoints ?? []) {
|
|
158
144
|
if (!this.matches(call, [entry.call])) {
|
|
159
145
|
continue;
|
|
@@ -168,12 +154,8 @@ class InputClassifier {
|
|
|
168
154
|
}
|
|
169
155
|
/** the function definitions the given id may hold, be it one directly or a variable a definition was assigned to */
|
|
170
156
|
*functionDefinitionsAt(id, depth = 0) {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
if (vtx === undefined) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
else if (vertex_1.DfgVertex.isFunctionDefinition(vtx)) {
|
|
157
|
+
const vtx = id === undefined || depth > MaxFunctionResolveDepth ? undefined : this.whole.getVertex(id);
|
|
158
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vtx)) {
|
|
177
159
|
yield vtx.id;
|
|
178
160
|
}
|
|
179
161
|
else if (vertex_1.DfgVertex.isVariableDefinition(vtx)) {
|
|
@@ -181,8 +163,8 @@ class InputClassifier {
|
|
|
181
163
|
yield* this.functionDefinitionsAt(source, depth + 1);
|
|
182
164
|
}
|
|
183
165
|
}
|
|
184
|
-
else {
|
|
185
|
-
for (const origin of df_helper_1.Dataflow.origin(
|
|
166
|
+
else if (vtx !== undefined) {
|
|
167
|
+
for (const origin of df_helper_1.Dataflow.origin(this.whole, vtx.id) ?? []) {
|
|
186
168
|
if (origin.type === 0 /* OriginType.ReadVariableOrigin */ || origin.type === 1 /* OriginType.WriteVariableOrigin */ || origin.type === 2 /* OriginType.FunctionCallOrigin */) {
|
|
187
169
|
yield* this.functionDefinitionsAt(origin.id, depth + 1);
|
|
188
170
|
}
|
|
@@ -191,9 +173,9 @@ class InputClassifier {
|
|
|
191
173
|
}
|
|
192
174
|
/** the id of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
|
|
193
175
|
argumentReference(call, argIdx, argName) {
|
|
194
|
-
const named = call.args.find(a => graph_1.FunctionArgument.
|
|
176
|
+
const named = call.args.find(a => graph_1.FunctionArgument.hasName(a, argName));
|
|
195
177
|
const arg = named ?? call.args[argIdx];
|
|
196
|
-
if (arg === undefined ||
|
|
178
|
+
if (arg === undefined || (named === undefined && graph_1.FunctionArgument.isNamed(arg))) {
|
|
197
179
|
return undefined;
|
|
198
180
|
}
|
|
199
181
|
return graph_1.FunctionArgument.getReference(arg);
|
|
@@ -205,7 +187,7 @@ class InputClassifier {
|
|
|
205
187
|
}
|
|
206
188
|
/**
|
|
207
189
|
* All declarations of framework entries in the program, keyed by object and entry name, built once on first use.
|
|
208
|
-
* This is what links a read of `input$n` back to the `textInput("n",
|
|
190
|
+
* This is what links a read of `input$n` back to the `textInput("n", ...)` defining it.
|
|
209
191
|
*/
|
|
210
192
|
declarations() {
|
|
211
193
|
if (this.declarationIndex !== undefined) {
|
|
@@ -217,13 +199,13 @@ class InputClassifier {
|
|
|
217
199
|
if (specs.length === 0) {
|
|
218
200
|
return index;
|
|
219
201
|
}
|
|
220
|
-
for (const [, call] of
|
|
202
|
+
for (const [, call] of this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
221
203
|
for (const obj of specs) {
|
|
222
204
|
const spec = obj.declaredBy;
|
|
223
205
|
if (!this.matches(call, spec.calls)) {
|
|
224
206
|
continue;
|
|
225
207
|
}
|
|
226
|
-
const name = this.
|
|
208
|
+
const name = this.classifyAt(this.argumentReference(call, spec.argIdx, spec.argName), this.whole)?.value;
|
|
227
209
|
if (typeof name === 'string') {
|
|
228
210
|
const key = declarationKey(obj.name, name);
|
|
229
211
|
index.set(key, [...(index.get(key) ?? []), call.id]);
|
|
@@ -232,20 +214,6 @@ class InputClassifier {
|
|
|
232
214
|
}
|
|
233
215
|
return index;
|
|
234
216
|
}
|
|
235
|
-
/** the value of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
|
|
236
|
-
argumentValue(call, argIdx, argName) {
|
|
237
|
-
const ref = this.argumentReference(call, argIdx, argName);
|
|
238
|
-
const vtx = ref === undefined ? undefined : (this.fullDfg ?? this.dfg).getVertex(ref);
|
|
239
|
-
return vtx === undefined ? undefined : this.classifyEntry(vtx).value;
|
|
240
|
-
}
|
|
241
|
-
isDefinedByOnCall(id) {
|
|
242
|
-
return this.definedByOnCallTargets(id).length > 0;
|
|
243
|
-
}
|
|
244
|
-
/** the ids the given one is linked to by {@link EdgeType.DefinedByOnCall}, e.g. a parameter to the arguments it is bound to */
|
|
245
|
-
definedByOnCallTargets(id) {
|
|
246
|
-
const out = (this.fullDfg ?? this.dfg).outgoingEdges(id) ?? new Map();
|
|
247
|
-
return out.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)).map(([to]) => to).toArray();
|
|
248
|
-
}
|
|
249
217
|
/**
|
|
250
218
|
* Classifies the given id against the full graph, for everything the reduced graph of the criterion cannot see
|
|
251
219
|
* (the enclosing scopes and the callers of the function the criterion is in).
|
|
@@ -255,24 +223,20 @@ class InputClassifier {
|
|
|
255
223
|
return undefined;
|
|
256
224
|
}
|
|
257
225
|
this.fullClassifier ??= new InputClassifier(this.fullDfg, this.config, undefined, this.packages);
|
|
258
|
-
|
|
259
|
-
return vtx ? this.fullClassifier.classifyEntry(vtx) : undefined;
|
|
226
|
+
return this.fullClassifier.classifyAt(id);
|
|
260
227
|
}
|
|
261
228
|
extractConstantValue(id) {
|
|
262
229
|
const node = this.dfg.idMap?.get(id);
|
|
263
|
-
if (node === undefined) {
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
230
|
if (r_number_1.RNumber.is(node)) {
|
|
267
231
|
return node.content.num;
|
|
268
232
|
}
|
|
269
|
-
if (r_string_1.RString.is(node)) {
|
|
233
|
+
else if (r_string_1.RString.is(node)) {
|
|
270
234
|
return node.content.str;
|
|
271
235
|
}
|
|
272
|
-
if (r_logical_1.RLogical.is(node)) {
|
|
236
|
+
else if (r_logical_1.RLogical.is(node)) {
|
|
273
237
|
return node.content;
|
|
274
238
|
}
|
|
275
|
-
if (r_symbol_1.RSymbol.is(node) && node.content === convert_values_1.RNull) {
|
|
239
|
+
else if (r_symbol_1.RSymbol.is(node) && node.content === convert_values_1.RNull) {
|
|
276
240
|
return null;
|
|
277
241
|
}
|
|
278
242
|
return undefined;
|
|
@@ -282,16 +246,12 @@ class InputClassifier {
|
|
|
282
246
|
if (cached) {
|
|
283
247
|
return cached;
|
|
284
248
|
}
|
|
285
|
-
|
|
286
|
-
this.cache.set(vertex.id,
|
|
249
|
+
/* a temporary unknown breaks cycles */
|
|
250
|
+
this.cache.set(vertex.id, sourceOf(vertex.id, input_types_1.InputType.Unknown));
|
|
287
251
|
switch (vertex.tag) {
|
|
288
252
|
case vertex_1.VertexType.Value: {
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
if (v !== undefined) {
|
|
292
|
-
src.value = v;
|
|
293
|
-
}
|
|
294
|
-
return this.classifyCdsAndReturn(vertex, src);
|
|
253
|
+
const value = this.extractConstantValue(vertex.id);
|
|
254
|
+
return this.classifyCdsAndReturn(vertex, (0, objects_1.compactRecord)({ ...sourceOf(vertex.id, input_types_1.InputType.Constant), value }));
|
|
295
255
|
}
|
|
296
256
|
case vertex_1.VertexType.FunctionCall:
|
|
297
257
|
return this.classifyFunctionCall(vertex);
|
|
@@ -300,9 +260,38 @@ class InputClassifier {
|
|
|
300
260
|
case vertex_1.VertexType.Use:
|
|
301
261
|
return this.classifyVariable(vertex);
|
|
302
262
|
default:
|
|
303
|
-
return this.classifyCdsAndReturn(vertex,
|
|
263
|
+
return this.classifyCdsAndReturn(vertex, sourceOf(vertex.id, input_types_1.InputType.Unknown));
|
|
304
264
|
}
|
|
305
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Whether `call` quotes only the code written in its arguments: no name in them resolves outside of them
|
|
268
|
+
* (built-ins aside), as a `bquote(.(y))` splice would, and none names an enclosing parameter `substitute` would replace.
|
|
269
|
+
*/
|
|
270
|
+
quotesOnlyWrittenCode(call) {
|
|
271
|
+
const idMap = this.dfg.idMap;
|
|
272
|
+
if (idMap === undefined) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
const enclosing = enclosingFunctions(idMap.get(call.id), idMap);
|
|
276
|
+
const parameters = new Set(enclosing.flatMap(fn => fn.parameters.map(p => identifier_1.Identifier.getName(p.name.content))));
|
|
277
|
+
for (const arg of call.args) {
|
|
278
|
+
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
279
|
+
const within = model_1.RNode.collectAllIds(ref === undefined ? undefined : idMap.get(ref));
|
|
280
|
+
for (const id of within) {
|
|
281
|
+
const node = idMap.get(id);
|
|
282
|
+
if (r_symbol_1.RSymbol.is(node) && parameters.has(identifier_1.Identifier.getName(node.content))) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
for (const target of (0, frame_reflection_1.edgeTargets)(this.dfg, id, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall)) {
|
|
286
|
+
/* the call evaluating the code is no input to it */
|
|
287
|
+
if (!within.has(target) && !node_id_1.NodeId.isBuiltIn(target) && !(0, frame_reflection_1.hasEdgeOfType)(this.dfg, target, id, edge_1.EdgeType.Returns)) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
306
295
|
/**
|
|
307
296
|
* Accesses like `input$n` or `input[["n"]]` are reported as a single source of the accessed object,
|
|
308
297
|
* carrying the accessed field as its {@link InputSource.name|name}.
|
|
@@ -311,28 +300,20 @@ class InputClassifier {
|
|
|
311
300
|
if (!call.origin.includes(built_in_proc_name_1.BuiltInProcName.Access)) {
|
|
312
301
|
return undefined;
|
|
313
302
|
}
|
|
314
|
-
const accessed = graph_1.FunctionArgument.
|
|
303
|
+
const accessed = graph_1.FunctionArgument.getReference(call.args[0]);
|
|
315
304
|
const linked = accessed === undefined ? undefined : this.matchLinkedObject(accessed);
|
|
316
305
|
const field = this.accessedField(call);
|
|
317
306
|
if (linked === undefined || !fieldIsInput(linked, field)) {
|
|
318
307
|
return undefined;
|
|
319
308
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
src.declaredAt = declaredAt;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return src;
|
|
309
|
+
return (0, objects_1.compactRecord)({
|
|
310
|
+
...sourceOf(call.id, linked.type),
|
|
311
|
+
name: field,
|
|
312
|
+
declaredAt: field !== undefined && linked.declaredBy ? this.declarations().get(declarationKey(linked.name, field)) : undefined
|
|
313
|
+
});
|
|
329
314
|
}
|
|
330
315
|
accessedField(call) {
|
|
331
|
-
const
|
|
332
|
-
if (arg === undefined || graph_1.FunctionArgument.isEmpty(arg)) {
|
|
333
|
-
return undefined;
|
|
334
|
-
}
|
|
335
|
-
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
316
|
+
const ref = call.args[1] === undefined ? undefined : graph_1.FunctionArgument.getReference(call.args[1]);
|
|
336
317
|
const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
|
|
337
318
|
if (r_string_1.RString.is(node)) {
|
|
338
319
|
return node.content.str;
|
|
@@ -342,45 +323,33 @@ class InputClassifier {
|
|
|
342
323
|
}
|
|
343
324
|
return undefined;
|
|
344
325
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (linkedAccess) {
|
|
348
|
-
return this.classifyCdsAndReturn(call, linkedAccess);
|
|
349
|
-
}
|
|
326
|
+
/** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a branch or loop */
|
|
327
|
+
passedOn(call) {
|
|
350
328
|
if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList)) {
|
|
351
329
|
// `{ a; b }` evaluates to its last expression, just like in R
|
|
352
|
-
|
|
353
|
-
const value = last === undefined ? undefined : graph_1.FunctionArgument.getReference(last);
|
|
354
|
-
const vtx = value === undefined ? undefined : this.dfg.getVertex(value);
|
|
355
|
-
if (vtx) {
|
|
356
|
-
return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
|
|
357
|
-
}
|
|
330
|
+
return { via: call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a)), renamed: true };
|
|
358
331
|
}
|
|
359
332
|
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
|
|
360
|
-
|
|
361
|
-
if (condition) {
|
|
362
|
-
const vtx = this.dfg.getVertex(condition);
|
|
363
|
-
if (vtx) {
|
|
364
|
-
return this.classifyCdsAndReturn(call, this.classifyEntry(vtx));
|
|
365
|
-
}
|
|
366
|
-
}
|
|
333
|
+
return { via: call.args[0], renamed: false };
|
|
367
334
|
}
|
|
368
335
|
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)) {
|
|
369
|
-
|
|
370
|
-
if (condition) {
|
|
371
|
-
const vtx = this.dfg.getVertex(condition);
|
|
372
|
-
if (vtx) {
|
|
373
|
-
return this.classifyCdsAndReturn(call, this.classifyEntry(vtx));
|
|
374
|
-
}
|
|
375
|
-
}
|
|
336
|
+
return { via: call.args[1], renamed: false };
|
|
376
337
|
}
|
|
377
|
-
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !
|
|
338
|
+
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))) {
|
|
378
339
|
// a statically resolved `get("x")` yields the value of the retrieved variable, read via its first argument
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
340
|
+
return { via: call.args[0], renamed: true };
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
classifyFunctionCall(call) {
|
|
345
|
+
const linkedAccess = this.classifyLinkedObjectAccess(call);
|
|
346
|
+
if (linkedAccess) {
|
|
347
|
+
return this.classifyCdsAndReturn(call, linkedAccess);
|
|
348
|
+
}
|
|
349
|
+
const handed = this.passedOn(call);
|
|
350
|
+
const passed = this.classifyAt(handed?.via === undefined ? undefined : graph_1.FunctionArgument.getReference(handed.via));
|
|
351
|
+
if (passed) {
|
|
352
|
+
return this.classifyCdsAndReturn(call, handed?.renamed ? { ...passed, id: call.id } : passed);
|
|
384
353
|
}
|
|
385
354
|
// a narrowing function returns a bounded value: either one of a specific argument's values (e.g. `match.arg`
|
|
386
355
|
// -> its `choices`), or - with no bounding argument - a content-independent value like a count/index/logical
|
|
@@ -389,87 +358,51 @@ class InputClassifier {
|
|
|
389
358
|
continue;
|
|
390
359
|
}
|
|
391
360
|
if (narrow.argIdx === undefined) {
|
|
392
|
-
return this.classifyCdsAndReturn(call,
|
|
361
|
+
return this.classifyCdsAndReturn(call, { id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure });
|
|
393
362
|
}
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
|
|
363
|
+
const narrowed = this.classifyAt(this.argumentReference(call, narrow.argIdx, narrow.argName ?? ''));
|
|
364
|
+
if (narrowed) {
|
|
365
|
+
return this.classifyCdsAndReturn(call, { ...narrowed, id: call.id });
|
|
398
366
|
}
|
|
399
367
|
}
|
|
400
368
|
if (!this.matches(call, this.config.pure)) {
|
|
401
|
-
const types = [];
|
|
402
|
-
for (const type of record_1.Record.values(input_types_1.InputType)) {
|
|
403
|
-
if (this.matches(call, this.config[type])) {
|
|
404
|
-
types.push(type);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
369
|
+
const types = record_1.Record.values(input_types_1.InputType).filter(type => this.matches(call, this.config[type]));
|
|
407
370
|
// if a File-typed call reads from a temp path, replace File with TempFile
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
const argVtx = this.dfg.getVertex(ref);
|
|
418
|
-
if (argVtx && this.classifyEntry(argVtx).types.includes(input_types_1.InputType.TempFile)) {
|
|
419
|
-
types.splice(types.indexOf(input_types_1.InputType.File), 1);
|
|
420
|
-
types.push(input_types_1.InputType.TempFile);
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
371
|
+
const readsFile = types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile);
|
|
372
|
+
if (readsFile && call.args.some(arg => this.classifyAt(graph_1.FunctionArgument.getReference(arg))?.types.includes(input_types_1.InputType.TempFile))) {
|
|
373
|
+
types.splice(types.indexOf(input_types_1.InputType.File), 1);
|
|
374
|
+
types.push(input_types_1.InputType.TempFile);
|
|
375
|
+
}
|
|
376
|
+
/* `quote` yields written code, only capturing (`substitute(x)`) or splicing (`bquote(.(y))`) brings in other code */
|
|
377
|
+
if (types.includes(input_types_1.InputType.Lang) && this.quotesOnlyWrittenCode(call)) {
|
|
378
|
+
types.splice(types.indexOf(input_types_1.InputType.Lang), 1, input_types_1.InputType.DerivedConstant);
|
|
424
379
|
}
|
|
425
380
|
if (types.length === 0) {
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
429
|
-
return this.classifyCdsAndReturn(call, { ...
|
|
430
|
-
}
|
|
431
|
-
// a call of a function the code defines yields whatever that function returns
|
|
432
|
-
const returned = this.classifyDefinitionResult(call);
|
|
433
|
-
if (returned !== undefined) {
|
|
434
|
-
return this.classifyCdsAndReturn(call, returned);
|
|
381
|
+
/* a call of something the code produced (a shiny `reactive()`) or defines yields what that produced or returns */
|
|
382
|
+
const produced = this.classifyCallee(call) ?? this.classifyDefinitionResult(call);
|
|
383
|
+
if (produced !== undefined) {
|
|
384
|
+
return this.classifyCdsAndReturn(call, { ...produced, id: call.id });
|
|
435
385
|
}
|
|
436
386
|
// if it is not pure, we cannot classify based on the inputs, in that case we do not know!
|
|
437
387
|
types.push(input_types_1.InputType.Unknown);
|
|
438
388
|
}
|
|
439
389
|
return this.classifyCdsAndReturn(call, { id: call.id, types, trace: input_types_1.InputTraceType.Unknown });
|
|
440
390
|
}
|
|
441
|
-
// Otherwise, classify by arguments; pure functions get Known/Pure handling
|
|
442
391
|
const argTypes = [];
|
|
443
392
|
const cdTypes = [];
|
|
444
|
-
for (const arg of call.args) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
449
|
-
if (ref === undefined) {
|
|
450
|
-
argTypes.push(input_types_1.InputType.Unknown);
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
const argVtx = this.dfg.getVertex(ref);
|
|
454
|
-
if (!argVtx) {
|
|
455
|
-
argTypes.push(input_types_1.InputType.Unknown);
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
const classified = this.classifyEntry(argVtx);
|
|
459
|
-
// collect all observed types from this argument
|
|
460
|
-
argTypes.push(...classified.types);
|
|
461
|
-
if (classified.cds) {
|
|
462
|
-
cdTypes.push(...classified.cds);
|
|
463
|
-
}
|
|
393
|
+
for (const arg of call.args.filter(graph_1.FunctionArgument.isNotEmpty)) {
|
|
394
|
+
const classified = this.classifyAt(graph_1.FunctionArgument.getReference(arg));
|
|
395
|
+
argTypes.push(...classified?.types ?? [input_types_1.InputType.Unknown]);
|
|
396
|
+
cdTypes.push(...classified?.cds ?? []);
|
|
464
397
|
}
|
|
465
|
-
const cds = cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined;
|
|
466
398
|
// all arguments only contain constant-like types -> derived constant
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
399
|
+
const constLike = argTypes.length > 0 && argTypes.every(isConstantLike);
|
|
400
|
+
return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({
|
|
401
|
+
id: call.id,
|
|
402
|
+
types: constLike ? [input_types_1.InputType.DerivedConstant] : (0, arrays_1.uniqueArray)([...argTypes, input_types_1.InputType.DerivedConstant]),
|
|
403
|
+
trace: constLike ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Known,
|
|
404
|
+
cds: cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined
|
|
405
|
+
}));
|
|
473
406
|
}
|
|
474
407
|
/**
|
|
475
408
|
* What a call of a function the analyzed code defines yields: what its exit points do, as a function whose
|
|
@@ -477,28 +410,22 @@ class InputClassifier {
|
|
|
477
410
|
* when the call names no definition here or when none of them says anything about what it returns.
|
|
478
411
|
*/
|
|
479
412
|
classifyDefinitionResult(call) {
|
|
480
|
-
const graph = this.fullDfg ?? this.dfg;
|
|
481
413
|
const acc = new ClassificationAccumulator();
|
|
482
|
-
let known = false;
|
|
483
414
|
for (const fn of this.functionDefinitionsAt(call.id)) {
|
|
484
|
-
const definition =
|
|
485
|
-
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
for (const { nodeId } of definition.exitPoints) {
|
|
415
|
+
const definition = this.whole.getVertex(fn);
|
|
416
|
+
for (const { nodeId } of vertex_1.DfgVertex.isFunctionDefinition(definition) ? definition.exitPoints : []) {
|
|
489
417
|
for (const value of this.exitValues(nodeId)) {
|
|
490
|
-
const vtx = value === undefined ? undefined : this.dfg.getVertex(value) ??
|
|
491
|
-
|
|
492
|
-
if (classified === undefined) {
|
|
418
|
+
const vtx = value === undefined ? undefined : this.dfg.getVertex(value) ?? this.whole.getVertex(value);
|
|
419
|
+
if (vtx === undefined) {
|
|
493
420
|
/* an exit flowR cannot place says nothing about the call, so neither can the others */
|
|
494
421
|
return undefined;
|
|
495
422
|
}
|
|
496
|
-
|
|
497
|
-
acc.merge(classified);
|
|
423
|
+
acc.merge(this.classifyEntry(vtx));
|
|
498
424
|
}
|
|
499
425
|
}
|
|
500
426
|
}
|
|
501
|
-
|
|
427
|
+
/* every merge records one value, so none means no exit point was found */
|
|
428
|
+
if (acc.values.length === 0) {
|
|
502
429
|
return undefined;
|
|
503
430
|
}
|
|
504
431
|
const built = acc.build(call.id);
|
|
@@ -510,17 +437,19 @@ class InputClassifier {
|
|
|
510
437
|
* value flowR cannot name, a loop above all, so the caller stops rather than answers with the branches alone.
|
|
511
438
|
*/
|
|
512
439
|
*exitValues(id, depth = 0) {
|
|
513
|
-
const vtx =
|
|
514
|
-
if (
|
|
440
|
+
const vtx = this.dfg.getVertex(id) ?? this.whole.getVertex(id);
|
|
441
|
+
if (!vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
515
442
|
yield id;
|
|
516
443
|
return;
|
|
517
444
|
}
|
|
518
|
-
|
|
445
|
+
const isLoop = vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)
|
|
446
|
+
|| vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop);
|
|
447
|
+
if (isLoop) {
|
|
519
448
|
yield undefined;
|
|
520
449
|
}
|
|
521
450
|
else if (vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) && depth <= MaxFunctionResolveDepth) {
|
|
522
451
|
for (const branch of vtx.args.slice(1)) {
|
|
523
|
-
const ref = graph_1.FunctionArgument.
|
|
452
|
+
const ref = graph_1.FunctionArgument.getReference(branch);
|
|
524
453
|
if (ref === undefined) {
|
|
525
454
|
yield undefined;
|
|
526
455
|
}
|
|
@@ -539,8 +468,7 @@ class InputClassifier {
|
|
|
539
468
|
if (o.type !== 0 /* OriginType.ReadVariableOrigin */ && o.type !== 1 /* OriginType.WriteVariableOrigin */) {
|
|
540
469
|
continue;
|
|
541
470
|
}
|
|
542
|
-
const
|
|
543
|
-
const classified = vtx ? this.classifyEntry(vtx) : this.classifyInFullGraph(o.id);
|
|
471
|
+
const classified = this.classifyAt(o.id) ?? this.classifyInFullGraph(o.id);
|
|
544
472
|
if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
|
|
545
473
|
return classified;
|
|
546
474
|
}
|
|
@@ -550,35 +478,40 @@ class InputClassifier {
|
|
|
550
478
|
classifyVariable(vtx) {
|
|
551
479
|
const linked = this.matchWholeLinkedObject(vtx.id);
|
|
552
480
|
if (linked) {
|
|
553
|
-
return this.classifyCdsAndReturn(vtx,
|
|
481
|
+
return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, linked.type));
|
|
554
482
|
}
|
|
555
483
|
const origins = df_helper_1.Dataflow.origin(this.dfg, vtx.id);
|
|
556
484
|
if (origins === undefined || origins.length === 0) {
|
|
557
|
-
if (this.
|
|
558
|
-
return this.classifyCdsAndReturn(vtx,
|
|
485
|
+
if ((0, frame_reflection_1.edgeTargets)(this.whole, vtx.id, edge_1.EdgeType.DefinedByOnCall).length > 0) {
|
|
486
|
+
return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, input_types_1.InputType.Scope));
|
|
559
487
|
}
|
|
560
488
|
// the definition is not part of the criterion's function, so it has to come from an enclosing scope
|
|
561
489
|
const outer = this.classifyInFullGraph(vtx.id);
|
|
562
|
-
return this.classifyCdsAndReturn(vtx, outer ? { ...outer, id: vtx.id } :
|
|
490
|
+
return this.classifyCdsAndReturn(vtx, outer ? { ...outer, id: vtx.id } : sourceOf(vtx.id, input_types_1.InputType.Unknown));
|
|
563
491
|
}
|
|
564
492
|
const acc = new ClassificationAccumulator();
|
|
565
493
|
for (const o of origins) {
|
|
566
494
|
if (o.type === 4 /* OriginType.ConstantOrigin */) {
|
|
567
|
-
acc.
|
|
568
|
-
acc.values.push(this.extractConstantValue(o.id));
|
|
495
|
+
acc.push(input_types_1.InputType.DerivedConstant, this.extractConstantValue(o.id));
|
|
569
496
|
}
|
|
570
497
|
else if (o.type === 0 /* OriginType.ReadVariableOrigin */ || o.type === 1 /* OriginType.WriteVariableOrigin */) {
|
|
571
498
|
this.classifyVariableOrigin(o.id, acc);
|
|
572
499
|
}
|
|
573
500
|
else if (o.type === 2 /* OriginType.FunctionCallOrigin */ || o.type === 3 /* OriginType.BuiltInFunctionOrigin */) {
|
|
574
|
-
this.
|
|
501
|
+
acc.merge(this.classifyAt(o.id));
|
|
575
502
|
}
|
|
576
503
|
else {
|
|
577
|
-
acc.
|
|
504
|
+
acc.merge(undefined);
|
|
578
505
|
}
|
|
579
506
|
}
|
|
580
507
|
return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
|
|
581
508
|
}
|
|
509
|
+
parameterType(id) {
|
|
510
|
+
if (this.dfg.idMap?.get(id)?.info.role !== "param-n" /* RoleInParent.ParameterName */) {
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
return this.matchWholeLinkedObject(id)?.type ?? input_types_1.InputType.Parameter;
|
|
514
|
+
}
|
|
582
515
|
/**
|
|
583
516
|
* Resolves a variable definition or use origin, handling the special cases of
|
|
584
517
|
* scope-escaped variables (DefinedByOnCall) and parameter definitions.
|
|
@@ -586,12 +519,12 @@ class InputClassifier {
|
|
|
586
519
|
classifyVariableOrigin(definitionId, acc) {
|
|
587
520
|
const v = this.dfg.getVertex(definitionId);
|
|
588
521
|
if (!v) {
|
|
589
|
-
acc.
|
|
522
|
+
acc.merge(undefined);
|
|
590
523
|
return;
|
|
591
524
|
}
|
|
592
525
|
// if the referenced definition is linked via defined-by-on-call to another id (e.g., a parameter linked to a
|
|
593
526
|
// caller argument), follow it into the caller; only if that leads nowhere is it an opaque Scope origin
|
|
594
|
-
const onCall = this.
|
|
527
|
+
const onCall = (0, frame_reflection_1.edgeTargets)(this.whole, v.id, edge_1.EdgeType.DefinedByOnCall);
|
|
595
528
|
if (onCall.length > 0) {
|
|
596
529
|
const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
|
|
597
530
|
const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
|
|
@@ -599,60 +532,37 @@ class InputClassifier {
|
|
|
599
532
|
if (known.length > 0 && known.length === callers.length) {
|
|
600
533
|
return;
|
|
601
534
|
}
|
|
602
|
-
acc.
|
|
603
|
-
acc.values.push(undefined);
|
|
535
|
+
acc.push(input_types_1.InputType.Scope);
|
|
604
536
|
acc.allPure = false;
|
|
605
537
|
}
|
|
606
|
-
|
|
607
|
-
if (
|
|
608
|
-
acc.
|
|
609
|
-
acc.values.push(undefined);
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
acc.merge(this.classifyEntry(v));
|
|
613
|
-
}
|
|
614
|
-
classifyByVertex(id, acc) {
|
|
615
|
-
const v = this.dfg.getVertex(id);
|
|
616
|
-
if (v) {
|
|
617
|
-
acc.merge(this.classifyEntry(v));
|
|
538
|
+
const parameter = vertex_1.DfgVertex.isVariableDefinition(v) ? this.parameterType(v.id) : undefined;
|
|
539
|
+
if (parameter !== undefined) {
|
|
540
|
+
acc.push(parameter);
|
|
618
541
|
}
|
|
619
542
|
else {
|
|
620
|
-
acc.
|
|
543
|
+
acc.merge(this.classifyEntry(v));
|
|
621
544
|
}
|
|
622
545
|
}
|
|
623
546
|
classifyVariableDefinition(vtx) {
|
|
624
|
-
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
return this.classifyCdsAndReturn(vtx, { id: vtx.id, types, trace: input_types_1.InputTraceType.Unknown });
|
|
547
|
+
const parameter = this.parameterType(vtx.id);
|
|
548
|
+
if (parameter !== undefined) {
|
|
549
|
+
return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, parameter));
|
|
628
550
|
}
|
|
629
|
-
|
|
630
|
-
if (sources === undefined || sources.length === 0) {
|
|
551
|
+
else if (!vtx.source?.length) {
|
|
631
552
|
// fallback to unknown if we cannot find the value
|
|
632
|
-
return this.classifyCdsAndReturn(vtx,
|
|
553
|
+
return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, input_types_1.InputType.Unknown));
|
|
633
554
|
}
|
|
634
555
|
const acc = new ClassificationAccumulator();
|
|
635
|
-
|
|
636
|
-
const tv = this.dfg.getVertex(tid);
|
|
637
|
-
if (tv) {
|
|
638
|
-
acc.merge(this.classifyEntry(tv));
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
acc.pushUnknown();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
556
|
+
vtx.source.forEach(tid => acc.merge(this.classifyAt(tid)));
|
|
644
557
|
return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
|
|
645
558
|
}
|
|
646
559
|
classifyCdsAndReturn(vtx, src) {
|
|
647
560
|
if (vtx.cds) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const e = this.classifyEntry(cv);
|
|
654
|
-
return e.cds ? [...e.types, ...e.cds] : [...e.types];
|
|
655
|
-
}).filter(assert_1.isNotUndefined).concat(src.cds ?? []));
|
|
561
|
+
/* running only once a call forces it is no condition on the data */
|
|
562
|
+
const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c => {
|
|
563
|
+
const e = this.classifyAt(c.id);
|
|
564
|
+
return e ? [...e.types, ...e.cds ?? []] : [];
|
|
565
|
+
}).concat(src.cds ?? []));
|
|
656
566
|
if (cds.length > 0) {
|
|
657
567
|
src.cds = cds;
|
|
658
568
|
}
|
|
@@ -705,9 +615,6 @@ function callMeans(called, id, packages) {
|
|
|
705
615
|
return identifier_1.Identifier.getNamespace(called) === undefined && identifier_1.Identifier.matches(called, id)
|
|
706
616
|
&& (namespace === undefined || packages === undefined || packages.has(namespace));
|
|
707
617
|
}
|
|
708
|
-
function matchesList(fn, list, packages) {
|
|
709
|
-
return list?.some(id => fn.id === id || (identifier_1.Identifier.is(id) && callMeans(fn.name, id, packages))) ?? false;
|
|
710
|
-
}
|
|
711
618
|
/**
|
|
712
619
|
* Takes the given id which is expected to either be:
|
|
713
620
|
* - a function call - in this case all arguments are considered to be inputs (additionally to all read edges from the function call in the dataflow graph)
|
|
@@ -719,35 +626,19 @@ function matchesList(fn, list, packages) {
|
|
|
719
626
|
*/
|
|
720
627
|
function classifyInput(id, dfg, config, fullDfg, packages) {
|
|
721
628
|
const vtx = dfg.getVertex(id);
|
|
722
|
-
if (!vtx) {
|
|
723
|
-
return [];
|
|
724
|
-
}
|
|
725
629
|
const c = new InputClassifier(dfg, config, fullDfg, packages);
|
|
726
|
-
if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
727
|
-
|
|
728
|
-
const args = vtx.args;
|
|
729
|
-
for (const arg of args) {
|
|
730
|
-
if (graph_1.FunctionArgument.isEmpty(arg)) {
|
|
731
|
-
continue;
|
|
732
|
-
}
|
|
733
|
-
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
734
|
-
if (ref === undefined) {
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
const argVtx = dfg.getVertex(ref);
|
|
738
|
-
if (argVtx === undefined) {
|
|
739
|
-
continue;
|
|
740
|
-
}
|
|
741
|
-
const entry = c.classifyEntry(argVtx);
|
|
742
|
-
const argName = graph_1.FunctionArgument.getName(arg);
|
|
743
|
-
ret.push(argName !== undefined ? { ...entry, name: argName } : entry);
|
|
744
|
-
}
|
|
745
|
-
return ret;
|
|
630
|
+
if (!vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
631
|
+
return vtx ? [c.classifyEntry(vtx)] : [];
|
|
746
632
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
633
|
+
const ret = [];
|
|
634
|
+
for (const arg of vtx.args) {
|
|
635
|
+
const entry = c.classifyAt(graph_1.FunctionArgument.getReference(arg));
|
|
636
|
+
if (entry === undefined) {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const name = graph_1.FunctionArgument.getName(arg);
|
|
640
|
+
ret.push(name !== undefined ? { ...entry, name } : entry);
|
|
751
641
|
}
|
|
642
|
+
return ret;
|
|
752
643
|
}
|
|
753
644
|
//# sourceMappingURL=simple-input-classifier.js.map
|