@eagleoutice/flowr 2.10.10 → 2.11.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 +35 -27
- package/cli/common/options.d.ts +2 -108
- package/cli/common/options.js +3 -27
- package/cli/common/scripts-info.d.ts +2 -123
- package/cli/common/scripts-info.js +0 -17
- package/cli/flowr-main-options.d.ts +5 -0
- package/cli/flowr-main-options.js +10 -0
- package/cli/flowr.js +2 -2
- package/cli/repl/commands/repl-commands.js +7 -6
- package/cli/repl/print-version.d.ts +3 -1
- package/cli/repl/print-version.js +21 -2
- package/cli/repl/server/connection.d.ts +2 -0
- package/cli/repl/server/connection.js +40 -31
- package/cli/script-core/summarizer-core.js +13 -32
- package/cli/wiki.d.ts +2 -1
- package/cli/wiki.js +2 -0
- package/config.d.ts +9 -0
- package/config.js +10 -0
- package/control-flow/semantic-cfg-guided-visitor.js +1 -0
- package/core/steps/pipeline/default-pipelines.d.ts +146 -146
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/dataflow/environments/append.d.ts +1 -2
- package/dataflow/environments/append.js +3 -10
- package/dataflow/environments/apply-kill.d.ts +21 -0
- package/dataflow/environments/apply-kill.js +155 -0
- package/dataflow/environments/built-in-proc-name.d.ts +2 -0
- package/dataflow/environments/built-in-proc-name.js +2 -0
- package/dataflow/environments/built-in.d.ts +2 -0
- package/dataflow/environments/built-in.js +2 -0
- package/dataflow/environments/default-builtin-config.d.ts +63 -3
- package/dataflow/environments/default-builtin-config.js +40 -8
- package/dataflow/environments/environment.d.ts +49 -32
- package/dataflow/environments/environment.js +133 -18
- package/dataflow/environments/identifier.d.ts +10 -0
- package/dataflow/environments/identifier.js +23 -0
- package/dataflow/environments/overwrite.js +2 -10
- package/dataflow/environments/resolve-by-name.d.ts +1 -1
- package/dataflow/environments/resolve-by-name.js +10 -2
- package/dataflow/environments/scoping.d.ts +9 -2
- package/dataflow/environments/scoping.js +15 -2
- package/dataflow/extractor.js +23 -2
- package/dataflow/graph/df-helper.d.ts +8 -0
- package/dataflow/graph/df-helper.js +8 -0
- package/dataflow/graph/graph.d.ts +4 -1
- package/dataflow/graph/graph.js +5 -1
- package/dataflow/info.d.ts +26 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +7 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +9 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -47
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +17 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +37 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +391 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +131 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +25 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +94 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +10 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +30 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +279 -0
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +17 -0
- package/documentation/data/faq/faqs.js +3 -0
- package/documentation/data/interface/doc-writing-code.js +4 -80
- package/documentation/doc-util/doc-structure.js +1 -2
- package/documentation/wiki-core.js +2 -1
- package/documentation/wiki-dataflow-graph.js +35 -1
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linter.js +2 -0
- package/documentation/wiki-overview.js +1 -14
- package/documentation/wiki-package-database.d.ts +9 -0
- package/documentation/wiki-package-database.js +63 -0
- package/documentation/wiki-query.js +1 -0
- package/linter/linter-rules.d.ts +23 -0
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-path.js +2 -1
- package/linter/rules/undefined-symbol.d.ts +39 -0
- package/linter/rules/undefined-symbol.js +80 -0
- package/package.json +4 -4
- package/project/cache/flowr-analyzer-cache.d.ts +2 -0
- package/project/cache/flowr-analyzer-cache.js +9 -1
- package/project/context/flowr-analyzer-dependencies-context.d.ts +16 -8
- package/project/context/flowr-analyzer-dependencies-context.js +39 -4
- package/project/context/flowr-analyzer-environment-context.d.ts +2 -4
- package/project/context/flowr-analyzer-environment-context.js +3 -4
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-file.d.ts +2 -0
- package/project/context/flowr-file.js +2 -0
- package/project/flowr-analyzer-builder.js +3 -0
- package/project/flowr-analyzer.d.ts +2 -1
- package/project/flowr-analyzer.js +3 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +13 -15
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +36 -13
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +27 -0
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +41 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +18 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +62 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +63 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +176 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +10 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +6 -0
- package/project/plugins/package-version-plugins/package.d.ts +3 -0
- package/project/plugins/package-version-plugins/package.js +12 -0
- package/project/plugins/package-version-plugins/pkgdb.d.ts +133 -0
- package/project/plugins/package-version-plugins/pkgdb.js +370 -0
- package/project/plugins/plugin-registry.d.ts +4 -1
- package/project/plugins/plugin-registry.js +7 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +8 -0
- package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -0
- package/queries/catalog/call-context-query/call-context-query-format.js +1 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +8 -0
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -3
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -1
- package/queries/catalog/dependencies-query/dependencies-query-format.js +3 -2
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +1 -1
- package/queries/catalog/dependencies-query/function-info/other-path-functions.d.ts +2 -0
- package/queries/catalog/dependencies-query/function-info/other-path-functions.js +27 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -4
- package/queries/catalog/dependencies-query/function-info/visualize-functions.js +3 -1
- package/queries/catalog/linter-query/linter-query-executor.js +1 -0
- package/r-bridge/data/data.d.ts +2 -2
- package/r-bridge/data/data.js +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +13 -4
- package/search/search-executor/search-enrichers.d.ts +1 -1
- package/search/search-executor/search-enrichers.js +7 -4
- package/util/mermaid/mermaid.d.ts +4 -0
- package/util/mermaid/mermaid.js +8 -1
- package/util/text/ansi.d.ts +10 -1
- package/util/text/ansi.js +17 -4
- package/util/version.js +10 -2
- package/cli/common/features.d.ts +0 -9
- package/cli/common/features.js +0 -35
- package/cli/script-core/statistics-core.d.ts +0 -6
- package/cli/script-core/statistics-core.js +0 -104
- package/cli/script-core/statistics-helper-core.d.ts +0 -6
- package/cli/script-core/statistics-helper-core.js +0 -86
- package/cli/statistics-app.d.ts +0 -11
- package/cli/statistics-app.js +0 -16
- package/cli/statistics-helper-app.d.ts +0 -11
- package/cli/statistics-helper-app.js +0 -14
- package/statistics/features/common-syntax-probability.d.ts +0 -38
- package/statistics/features/common-syntax-probability.js +0 -169
- package/statistics/features/feature.d.ts +0 -179
- package/statistics/features/feature.js +0 -38
- package/statistics/features/post-processing.d.ts +0 -18
- package/statistics/features/post-processing.js +0 -26
- package/statistics/features/supported/assignments/assignments.d.ts +0 -12
- package/statistics/features/supported/assignments/assignments.js +0 -56
- package/statistics/features/supported/assignments/post-process.d.ts +0 -6
- package/statistics/features/supported/assignments/post-process.js +0 -126
- package/statistics/features/supported/comments/comments.d.ts +0 -18
- package/statistics/features/supported/comments/comments.js +0 -143
- package/statistics/features/supported/comments/post-process.d.ts +0 -6
- package/statistics/features/supported/comments/post-process.js +0 -51
- package/statistics/features/supported/control-flow/control-flow.d.ts +0 -17
- package/statistics/features/supported/control-flow/control-flow.js +0 -69
- package/statistics/features/supported/control-flow/post-process.d.ts +0 -6
- package/statistics/features/supported/control-flow/post-process.js +0 -66
- package/statistics/features/supported/data-access/data-access.d.ts +0 -15
- package/statistics/features/supported/data-access/data-access.js +0 -122
- package/statistics/features/supported/data-access/post-process.d.ts +0 -6
- package/statistics/features/supported/data-access/post-process.js +0 -108
- package/statistics/features/supported/defined-functions/defined-functions.d.ts +0 -34
- package/statistics/features/supported/defined-functions/defined-functions.js +0 -145
- package/statistics/features/supported/defined-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/defined-functions/post-process.js +0 -168
- package/statistics/features/supported/expression-list/post-process.d.ts +0 -6
- package/statistics/features/supported/expression-list/post-process.js +0 -45
- package/statistics/features/supported/expression-list/statistics-expression-list.d.ts +0 -9
- package/statistics/features/supported/expression-list/statistics-expression-list.js +0 -37
- package/statistics/features/supported/loops/loops.d.ts +0 -20
- package/statistics/features/supported/loops/loops.js +0 -81
- package/statistics/features/supported/loops/post-process.d.ts +0 -6
- package/statistics/features/supported/loops/post-process.js +0 -73
- package/statistics/features/supported/used-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/used-functions/post-process.js +0 -176
- package/statistics/features/supported/used-functions/used-functions.d.ts +0 -24
- package/statistics/features/supported/used-functions/used-functions.js +0 -99
- package/statistics/features/supported/used-packages/post-process.d.ts +0 -6
- package/statistics/features/supported/used-packages/post-process.js +0 -122
- package/statistics/features/supported/used-packages/used-packages.d.ts +0 -16
- package/statistics/features/supported/used-packages/used-packages.js +0 -140
- package/statistics/features/supported/values/post-process.d.ts +0 -6
- package/statistics/features/supported/values/post-process.js +0 -73
- package/statistics/features/supported/values/values.d.ts +0 -14
- package/statistics/features/supported/values/values.js +0 -111
- package/statistics/features/supported/variables/post-process.d.ts +0 -15
- package/statistics/features/supported/variables/post-process.js +0 -126
- package/statistics/features/supported/variables/variables.d.ts +0 -15
- package/statistics/features/supported/variables/variables.js +0 -62
- package/statistics/meta-statistics.d.ts +0 -32
- package/statistics/meta-statistics.js +0 -16
- package/statistics/output/file-provider.d.ts +0 -36
- package/statistics/output/file-provider.js +0 -96
- package/statistics/output/print-stats.d.ts +0 -29
- package/statistics/output/print-stats.js +0 -81
- package/statistics/output/statistics-file.d.ts +0 -36
- package/statistics/output/statistics-file.js +0 -68
- package/statistics/statistics.d.ts +0 -29
- package/statistics/statistics.js +0 -108
- package/statistics/summarizer/auto-detect.d.ts +0 -5
- package/statistics/summarizer/auto-detect.js +0 -34
- package/statistics/summarizer/first-phase/process.d.ts +0 -6
- package/statistics/summarizer/first-phase/process.js +0 -81
- package/statistics/summarizer/post-process/clusterer.d.ts +0 -25
- package/statistics/summarizer/post-process/clusterer.js +0 -40
- package/statistics/summarizer/post-process/file-based-count.d.ts +0 -16
- package/statistics/summarizer/post-process/file-based-count.js +0 -47
- package/statistics/summarizer/post-process/histogram.d.ts +0 -57
- package/statistics/summarizer/post-process/histogram.js +0 -126
- package/statistics/summarizer/post-process/post-process-output.d.ts +0 -14
- package/statistics/summarizer/post-process/post-process-output.js +0 -102
- package/statistics/summarizer/second-phase/process.d.ts +0 -15
- package/statistics/summarizer/second-phase/process.js +0 -118
- package/statistics/summarizer/summarizer.d.ts +0 -34
- package/statistics/summarizer/summarizer.js +0 -141
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Environment = void 0;
|
|
3
|
+
exports.REnvironment = exports.Environment = exports.EnvType = void 0;
|
|
4
4
|
exports.isDefaultBuiltInEnvironment = isDefaultBuiltInEnvironment;
|
|
5
5
|
exports.builtInEnvJsonReplacer = builtInEnvJsonReplacer;
|
|
6
6
|
/**
|
|
7
7
|
* Provides an environment structure similar to R.
|
|
8
|
-
* This allows the dataflow to hold current definition locations for variables, based on the current scope.
|
|
9
8
|
* @module
|
|
10
9
|
*/
|
|
11
10
|
const json_1 = require("../../util/json");
|
|
@@ -14,9 +13,15 @@ const assert_1 = require("../../util/assert");
|
|
|
14
13
|
const info_1 = require("../info");
|
|
15
14
|
const append_1 = require("./append");
|
|
16
15
|
const log_1 = require("../../util/log");
|
|
16
|
+
var EnvType;
|
|
17
|
+
(function (EnvType) {
|
|
18
|
+
EnvType["Namespace"] = "ns";
|
|
19
|
+
EnvType["Imports"] = "imp";
|
|
20
|
+
/** `requireNamespace("pkg")`: `pkg::fn` resolves, bare `fn` does not */
|
|
21
|
+
EnvType["LoadedNamespace"] = "lns";
|
|
22
|
+
})(EnvType || (exports.EnvType = EnvType = {}));
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
19
|
-
* Otherwise, rely on {@link IEnvironment#builtInEnv}
|
|
24
|
+
* Use only if you do not know the object type; otherwise rely on {@link IEnvironment#builtInEnv}.
|
|
20
25
|
*/
|
|
21
26
|
function isDefaultBuiltInEnvironment(obj) {
|
|
22
27
|
return typeof obj === 'object' && obj !== null && (obj.builtInEnv === true);
|
|
@@ -27,12 +32,16 @@ class Environment {
|
|
|
27
32
|
id;
|
|
28
33
|
/** Optional name for namespaced/non-anonymous environments, please only set if you know what you are doing */
|
|
29
34
|
n;
|
|
35
|
+
/** which search-path layer this env is (package/namespace/imports), if any */
|
|
36
|
+
t;
|
|
30
37
|
/** if created by a closure, the node id of that closure */
|
|
31
38
|
c;
|
|
32
39
|
parent;
|
|
33
40
|
memory;
|
|
34
41
|
cache;
|
|
35
42
|
builtInEnv;
|
|
43
|
+
/** marks the global environment (`.GlobalEnv`); attached packages (see {@link EnvType}) live below it */
|
|
44
|
+
globalEnv;
|
|
36
45
|
constructor(parent, isBuiltInDefault = undefined) {
|
|
37
46
|
this.id = isBuiltInDefault ? 0 : environmentIdCounter++;
|
|
38
47
|
this.parent = parent;
|
|
@@ -42,20 +51,27 @@ class Environment {
|
|
|
42
51
|
this.builtInEnv = isBuiltInDefault;
|
|
43
52
|
}
|
|
44
53
|
}
|
|
54
|
+
/** Marks this as an attached-package layer (see {@link EnvType}) for package `name`. */
|
|
55
|
+
asLibrary(name, type) {
|
|
56
|
+
this.n = name;
|
|
57
|
+
this.t = type;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/** Marks this as the global environment (`.GlobalEnv`); see {@link globalEnv}. */
|
|
61
|
+
asGlobal() {
|
|
62
|
+
this.globalEnv = true;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
45
65
|
/** please only use if you know what you are doing */
|
|
46
66
|
setClosureNodeId(nodeId) {
|
|
47
67
|
this.c = nodeId;
|
|
48
68
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Provides the closure linked to this environment.
|
|
51
|
-
* This is of importance if, for example, if you want to know the function definition associated with this environment.
|
|
52
|
-
*/
|
|
69
|
+
/** Provides the closure linked to this environment. */
|
|
53
70
|
get closure() {
|
|
54
71
|
return this.c;
|
|
55
72
|
}
|
|
56
73
|
/**
|
|
57
|
-
* Create a clone of this environment.
|
|
58
|
-
* (never mutated in place) and hence shared with the clone.
|
|
74
|
+
* Create a clone of this environment.
|
|
59
75
|
* @param recurseParents - Whether to also clone parent environments
|
|
60
76
|
*/
|
|
61
77
|
clone(recurseParents) {
|
|
@@ -66,6 +82,8 @@ class Environment {
|
|
|
66
82
|
const clone = new Environment(parent, this.builtInEnv);
|
|
67
83
|
clone.c = this.c;
|
|
68
84
|
clone.n = this.n;
|
|
85
|
+
clone.t = this.t;
|
|
86
|
+
clone.globalEnv = this.globalEnv;
|
|
69
87
|
clone.memory = new Map(this.memory);
|
|
70
88
|
return clone;
|
|
71
89
|
}
|
|
@@ -152,6 +170,12 @@ class Environment {
|
|
|
152
170
|
found = true;
|
|
153
171
|
break;
|
|
154
172
|
}
|
|
173
|
+
// `<<-` falls back to the global env, never an attached package below it
|
|
174
|
+
if (current.globalEnv) {
|
|
175
|
+
current.memory.set(name, [definition]);
|
|
176
|
+
found = true;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
155
179
|
last = current;
|
|
156
180
|
current.parent = current.parent.clone(false);
|
|
157
181
|
current = current.parent;
|
|
@@ -163,12 +187,17 @@ class Environment {
|
|
|
163
187
|
return newEnvironment;
|
|
164
188
|
}
|
|
165
189
|
/**
|
|
166
|
-
*
|
|
167
|
-
* <b>But</b> if all definitions within other are maybe, then they are appended to the current definitions (updating them to be `maybe` from now on as well), similar to {@link appendEnvironment}.
|
|
168
|
-
* This always recurses parents.
|
|
190
|
+
* Definitions within `other` replace those here by name; if all of `other`'s are maybe, they are appended instead (turning existing ones maybe too), like {@link appendEnvironment}. Always recurses parents.
|
|
169
191
|
*/
|
|
170
192
|
overwrite(other, applyCds) {
|
|
171
|
-
if (
|
|
193
|
+
if (!other || this === other) {
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
// package blocks are unioned, never overwritten (see mergePackageBlocks)
|
|
197
|
+
if (this.t !== undefined || other.t !== undefined) {
|
|
198
|
+
return this.mergePackageBlocks(other);
|
|
199
|
+
}
|
|
200
|
+
if (this.builtInEnv || this.n !== other.n) {
|
|
172
201
|
return this;
|
|
173
202
|
}
|
|
174
203
|
const map = new Map(this.memory);
|
|
@@ -207,15 +236,23 @@ class Environment {
|
|
|
207
236
|
const out = new Environment(this.parent.overwrite(other.parent, applyCds));
|
|
208
237
|
out.c = this.c;
|
|
209
238
|
out.n = this.n;
|
|
239
|
+
out.t = this.t;
|
|
240
|
+
out.globalEnv = this.globalEnv;
|
|
210
241
|
out.memory = map;
|
|
211
242
|
return out;
|
|
212
243
|
}
|
|
213
244
|
/**
|
|
214
|
-
* Adds all writes of `other` to this environment (
|
|
215
|
-
* This always recurses parents.
|
|
245
|
+
* Adds all writes of `other` to this environment (`other`'s operations *might* happen). Always recurses parents.
|
|
216
246
|
*/
|
|
217
247
|
append(other) {
|
|
218
|
-
if (!other || this
|
|
248
|
+
if (!other || this === other) {
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
// package blocks may diverge between branches; union them before the built-in guard
|
|
252
|
+
if (this.t !== undefined || other.t !== undefined) {
|
|
253
|
+
return this.mergePackageBlocks(other);
|
|
254
|
+
}
|
|
255
|
+
if (this.builtInEnv || this.n !== other.n) {
|
|
219
256
|
return this;
|
|
220
257
|
}
|
|
221
258
|
const map = new Map(this.memory);
|
|
@@ -229,9 +266,43 @@ class Environment {
|
|
|
229
266
|
}
|
|
230
267
|
}
|
|
231
268
|
const out = new Environment(this.parent.append(other.parent));
|
|
269
|
+
out.n = this.n;
|
|
270
|
+
out.t = this.t;
|
|
271
|
+
out.globalEnv = this.globalEnv;
|
|
232
272
|
out.memory = map;
|
|
233
273
|
return out;
|
|
234
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Unions two attached-package blocks, keeping every package once (memory merged for a package in both).
|
|
277
|
+
*/
|
|
278
|
+
mergePackageBlocks(other) {
|
|
279
|
+
const [thisLayers, thisBase] = splitLibraryLayers(this);
|
|
280
|
+
const [otherLayers, otherBase] = splitLibraryLayers(other);
|
|
281
|
+
// `other` first so its packages end up nearest global (most recently attached is nearest, cf. R `search()`)
|
|
282
|
+
const merged = new Map();
|
|
283
|
+
for (const layers of [otherLayers, thisLayers]) {
|
|
284
|
+
for (const layer of layers) {
|
|
285
|
+
const key = `${layer.t}:${layer.n}`;
|
|
286
|
+
const existing = merged.get(key);
|
|
287
|
+
if (existing === undefined) {
|
|
288
|
+
merged.set(key, layer.clone(false));
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
for (const [name, value] of layer.memory) {
|
|
292
|
+
const old = existing.memory.get(name);
|
|
293
|
+
existing.memory.set(name, old ? (0, append_1.uniqueMergeValuesInDefinitions)(old, value) : value);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const uniqueLayers = Array.from(merged.values());
|
|
299
|
+
let current = thisBase.append(otherBase);
|
|
300
|
+
for (let i = uniqueLayers.length - 1; i >= 0; i--) {
|
|
301
|
+
uniqueLayers[i].parent = current;
|
|
302
|
+
current = uniqueLayers[i];
|
|
303
|
+
}
|
|
304
|
+
return current;
|
|
305
|
+
}
|
|
235
306
|
remove(id) {
|
|
236
307
|
if (this.builtInEnv) {
|
|
237
308
|
return this;
|
|
@@ -274,13 +345,57 @@ class Environment {
|
|
|
274
345
|
id: this.id,
|
|
275
346
|
parent: this.parent,
|
|
276
347
|
memory: this.memory,
|
|
348
|
+
// markers needed to rebuild the search path after a round-trip (undefined values are dropped by JSON.stringify)
|
|
349
|
+
n: this.n,
|
|
350
|
+
t: this.t,
|
|
351
|
+
globalEnv: this.globalEnv,
|
|
277
352
|
};
|
|
278
353
|
}
|
|
279
354
|
}
|
|
280
355
|
exports.Environment = Environment;
|
|
356
|
+
/** Walks up to the global environment (see {@link Environment#globalEnv}), falling back to the last non-builtin env. */
|
|
357
|
+
function findGlobalEnvironment(env) {
|
|
358
|
+
let current = env;
|
|
359
|
+
while (!current.globalEnv && !current.parent.builtInEnv) {
|
|
360
|
+
current = current.parent;
|
|
361
|
+
}
|
|
362
|
+
return current;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Splices a package block (`blockTop`..`blockBottom`) directly below the global environment. Returns a fresh `current`, cloning only the path down to global.
|
|
366
|
+
*/
|
|
367
|
+
function attachPackageBelowGlobal(current, blockTop, blockBottom) {
|
|
368
|
+
const clonedCurrent = current.clone(false);
|
|
369
|
+
let global = clonedCurrent;
|
|
370
|
+
while (!global.globalEnv && !global.parent.builtInEnv) {
|
|
371
|
+
global.parent = global.parent.clone(false);
|
|
372
|
+
global = global.parent;
|
|
373
|
+
}
|
|
374
|
+
blockBottom.parent = global.parent; // the built-in env, or the previously attached packages
|
|
375
|
+
global.parent = blockTop;
|
|
376
|
+
return clonedCurrent;
|
|
377
|
+
}
|
|
281
378
|
/**
|
|
282
|
-
*
|
|
379
|
+
* Helpers for navigating and manipulating {@link REnvironmentInformation|environments} around the global environment and attached-package search path.
|
|
283
380
|
*/
|
|
381
|
+
exports.REnvironment = {
|
|
382
|
+
name: 'REnvironment',
|
|
383
|
+
/** Walks up to the global environment (`.GlobalEnv`); see {@link findGlobalEnvironment}. */
|
|
384
|
+
findGlobal: findGlobalEnvironment,
|
|
385
|
+
/** Attaches a package block below the global environment; see {@link attachPackageBelowGlobal}. */
|
|
386
|
+
attachBelowGlobal: attachPackageBelowGlobal,
|
|
387
|
+
};
|
|
388
|
+
/** Splits a package block (a contiguous run of attached-package layers, see {@link EnvType}) into its layers and the env below them. */
|
|
389
|
+
function splitLibraryLayers(env) {
|
|
390
|
+
const layers = [];
|
|
391
|
+
let current = env;
|
|
392
|
+
while (current.t !== undefined && !current.builtInEnv) {
|
|
393
|
+
layers.push(current);
|
|
394
|
+
current = current.parent;
|
|
395
|
+
}
|
|
396
|
+
return [layers, current];
|
|
397
|
+
}
|
|
398
|
+
/** Serializes an environment, replacing the built-in environment with a placeholder. */
|
|
284
399
|
function builtInEnvJsonReplacer(k, v) {
|
|
285
400
|
if (isDefaultBuiltInEnvironment(v)) {
|
|
286
401
|
return '<BuiltInEnvironment>';
|
|
@@ -2,6 +2,7 @@ import type { BuiltInIdentifierConstant, BuiltInIdentifierDefinition } from './b
|
|
|
2
2
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
3
3
|
import type { ControlDependency } from '../info';
|
|
4
4
|
import type { REnvironmentInformation } from './environment';
|
|
5
|
+
import type { Origin } from '../origin/dfg-get-origin';
|
|
5
6
|
/** this is just a safe-guard type to prevent mixing up branded identifiers with normal strings */
|
|
6
7
|
export type BrandedIdentifier = string & {
|
|
7
8
|
__brand?: 'identifier';
|
|
@@ -110,6 +111,14 @@ export declare const Identifier: {
|
|
|
110
111
|
* Convert the identifier to its array representation
|
|
111
112
|
*/
|
|
112
113
|
readonly toArray: (this: void, id: Identifier) => [BrandedIdentifier, BrandedNamespace | undefined, boolean | undefined];
|
|
114
|
+
/**
|
|
115
|
+
* The qualified identifier of a call from its dataflow {@link Origin}s (via `getOriginInDfg`), if it
|
|
116
|
+
* resolves to an export of a loaded package (the `flowr-pkgdb` info attached by `library()`/`use()`);
|
|
117
|
+
* `undefined` otherwise. With `purrr` loaded, `map()` yields `Identifier.make('map', 'purrr')`.
|
|
118
|
+
*/
|
|
119
|
+
readonly toQualified: (this: void, origins: readonly Origin[] | undefined) => Identifier | undefined;
|
|
120
|
+
/** The fully qualified `package::name` of a resolved call (see {@link Identifier.toQualified}). */
|
|
121
|
+
readonly toQualifiedName: (this: void, origins: readonly Origin[] | undefined) => string | undefined;
|
|
113
122
|
};
|
|
114
123
|
/**
|
|
115
124
|
* Well-known R package names used in {@link DefaultBuiltinConfig}.
|
|
@@ -124,6 +133,7 @@ export declare const enum PkgName {
|
|
|
124
133
|
Stats = "stats",
|
|
125
134
|
Utils = "utils",
|
|
126
135
|
AssertThat = "assertthat",
|
|
136
|
+
Box = "box",
|
|
127
137
|
Cli = "cli",
|
|
128
138
|
DataTable = "data.table",
|
|
129
139
|
Devtools = "devtools",
|
|
@@ -188,6 +188,29 @@ exports.Identifier = {
|
|
|
188
188
|
else {
|
|
189
189
|
return [id, undefined, undefined];
|
|
190
190
|
}
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* The qualified identifier of a call from its dataflow {@link Origin}s (via `getOriginInDfg`), if it
|
|
194
|
+
* resolves to an export of a loaded package (the `flowr-pkgdb` info attached by `library()`/`use()`);
|
|
195
|
+
* `undefined` otherwise. With `purrr` loaded, `map()` yields `Identifier.make('map', 'purrr')`.
|
|
196
|
+
*/
|
|
197
|
+
toQualified(origins) {
|
|
198
|
+
for (const origin of origins ?? []) {
|
|
199
|
+
// a package-export origin carries the target builtin id `built-in:pkg:func` in `proc`
|
|
200
|
+
if ('proc' in origin && origin.proc.startsWith('built-in:')) {
|
|
201
|
+
const rest = origin.proc.slice('built-in:'.length);
|
|
202
|
+
const sep = rest.indexOf(':'); // base builtins (`built-in:print`) have no separator
|
|
203
|
+
if (sep > 0) {
|
|
204
|
+
return exports.Identifier.make(rest.slice(sep + 1), rest.slice(0, sep));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
},
|
|
210
|
+
/** The fully qualified `package::name` of a resolved call (see {@link Identifier.toQualified}). */
|
|
211
|
+
toQualifiedName(origins) {
|
|
212
|
+
const qualified = exports.Identifier.toQualified(origins);
|
|
213
|
+
return qualified === undefined ? undefined : exports.Identifier.toString(qualified);
|
|
191
214
|
}
|
|
192
215
|
};
|
|
193
216
|
/**
|
|
@@ -3,22 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.overwriteEnvironment = overwriteEnvironment;
|
|
4
4
|
const scoping_1 = require("./scoping");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* <b>But</b> if all definitions within next are maybe, then they are appended to the base definitions (updating them to be `maybe` from now on as well), similar to {@link appendEnvironment}.
|
|
6
|
+
* Definitions within `next` replace those in `base` by name; if all of `next`'s are maybe, they are appended instead (turning existing ones maybe too), like {@link appendEnvironment}.
|
|
8
7
|
* @see {@link Environment.overwrite} - for details on how definitions are handled.
|
|
9
8
|
*/
|
|
10
9
|
function overwriteEnvironment(base, next, applyCds) {
|
|
11
10
|
if (base === undefined || next === undefined) {
|
|
12
11
|
return next ?? base;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
while (next.level < base.level) {
|
|
16
|
-
next = (0, scoping_1.pushLocalEnvironment)(next);
|
|
17
|
-
}
|
|
18
|
-
while (next.level > base.level) {
|
|
19
|
-
base = (0, scoping_1.pushLocalEnvironment)(base);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
13
|
+
({ base, next } = (0, scoping_1.padToCommonScope)(base, next));
|
|
22
14
|
return {
|
|
23
15
|
current: base.current.overwrite(next.current, applyCds),
|
|
24
16
|
level: base.level
|
|
@@ -3,10 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resolveByName = resolveByName;
|
|
4
4
|
exports.resolveByNameAnyType = resolveByNameAnyType;
|
|
5
5
|
exports.resolvesToBuiltInConstant = resolvesToBuiltInConstant;
|
|
6
|
+
const environment_1 = require("./environment");
|
|
6
7
|
const logic_1 = require("../../util/logic");
|
|
7
8
|
const identifier_1 = require("./identifier");
|
|
8
9
|
const info_1 = require("../info");
|
|
9
10
|
const built_in_s_seven_dispatch_1 = require("../internal/process/functions/call/built-in/built-in-s-seven-dispatch");
|
|
11
|
+
/** A namespaced lookup only sees its matching layer; a bare lookup skips loaded-but-unattached namespaces (`requireNamespace`). */
|
|
12
|
+
function layerSkipped(layer, ns) {
|
|
13
|
+
if (ns !== undefined) {
|
|
14
|
+
return layer.n !== ns;
|
|
15
|
+
}
|
|
16
|
+
return layer.t === environment_1.EnvType.LoadedNamespace;
|
|
17
|
+
}
|
|
10
18
|
const FunctionTargetTypes = identifier_1.ReferenceType.Function | identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.Unknown | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Parameter;
|
|
11
19
|
const VariableTargetTypes = identifier_1.ReferenceType.Variable | identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Unknown;
|
|
12
20
|
const ConstantTargetTypes = identifier_1.ReferenceType.Constant | identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.Unknown;
|
|
@@ -42,7 +50,7 @@ function resolveByName(id, environment, target) {
|
|
|
42
50
|
let definitions = undefined;
|
|
43
51
|
const wantedType = TargetTypePredicate[target];
|
|
44
52
|
do {
|
|
45
|
-
if (
|
|
53
|
+
if (layerSkipped(current, ns)) {
|
|
46
54
|
current = current.parent;
|
|
47
55
|
continue;
|
|
48
56
|
}
|
|
@@ -101,7 +109,7 @@ function resolveByNameAnyType(id, environment) {
|
|
|
101
109
|
const [name, ns, internal] = identifier_1.Identifier.toArray(id);
|
|
102
110
|
let definitions = undefined;
|
|
103
111
|
do {
|
|
104
|
-
if (
|
|
112
|
+
if (layerSkipped(current, ns)) {
|
|
105
113
|
current = current.parent;
|
|
106
114
|
continue;
|
|
107
115
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { type REnvironmentInformation } from './environment';
|
|
2
2
|
/**
|
|
3
|
-
* Add a new local environment scope to the stack, returns the modified variant
|
|
3
|
+
* Add a new local environment scope to the stack, returns the modified variant (shares the original stack, no deep-clone).
|
|
4
4
|
* @see {@link popLocalEnvironment} - to remove the local scope again
|
|
5
5
|
*/
|
|
6
6
|
export declare function pushLocalEnvironment({ level, current }: REnvironmentInformation): REnvironmentInformation;
|
|
7
7
|
/**
|
|
8
|
-
* Remove the top local environment scope from the stack, returns the modified variant
|
|
8
|
+
* Remove the top local environment scope from the stack, returns the modified variant (shares the original stack, no deep-clone).
|
|
9
9
|
* @see {@link pushLocalEnvironment} - to add a local scope
|
|
10
10
|
*/
|
|
11
11
|
export declare function popLocalEnvironment({ current, level }: REnvironmentInformation): REnvironmentInformation;
|
|
12
|
+
/**
|
|
13
|
+
* Pads whichever of `base`/`next` is shallower with empty local scopes until both are at the same lexical {@link REnvironmentInformation#level|level}.
|
|
14
|
+
*/
|
|
15
|
+
export declare function padToCommonScope(base: REnvironmentInformation, next: REnvironmentInformation): {
|
|
16
|
+
base: REnvironmentInformation;
|
|
17
|
+
next: REnvironmentInformation;
|
|
18
|
+
};
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pushLocalEnvironment = pushLocalEnvironment;
|
|
4
4
|
exports.popLocalEnvironment = popLocalEnvironment;
|
|
5
|
+
exports.padToCommonScope = padToCommonScope;
|
|
5
6
|
const environment_1 = require("./environment");
|
|
6
7
|
const assert_1 = require("../../util/assert");
|
|
7
8
|
/**
|
|
8
|
-
* Add a new local environment scope to the stack, returns the modified variant
|
|
9
|
+
* Add a new local environment scope to the stack, returns the modified variant (shares the original stack, no deep-clone).
|
|
9
10
|
* @see {@link popLocalEnvironment} - to remove the local scope again
|
|
10
11
|
*/
|
|
11
12
|
function pushLocalEnvironment({ level, current }) {
|
|
@@ -15,7 +16,7 @@ function pushLocalEnvironment({ level, current }) {
|
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* Remove the top local environment scope from the stack, returns the modified variant
|
|
19
|
+
* Remove the top local environment scope from the stack, returns the modified variant (shares the original stack, no deep-clone).
|
|
19
20
|
* @see {@link pushLocalEnvironment} - to add a local scope
|
|
20
21
|
*/
|
|
21
22
|
function popLocalEnvironment({ current, level }) {
|
|
@@ -25,4 +26,16 @@ function popLocalEnvironment({ current, level }) {
|
|
|
25
26
|
level: level - 1
|
|
26
27
|
};
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Pads whichever of `base`/`next` is shallower with empty local scopes until both are at the same lexical {@link REnvironmentInformation#level|level}.
|
|
31
|
+
*/
|
|
32
|
+
function padToCommonScope(base, next) {
|
|
33
|
+
while (next.level < base.level) {
|
|
34
|
+
next = pushLocalEnvironment(next);
|
|
35
|
+
}
|
|
36
|
+
while (next.level > base.level) {
|
|
37
|
+
base = pushLocalEnvironment(base);
|
|
38
|
+
}
|
|
39
|
+
return { base, next };
|
|
40
|
+
}
|
|
28
41
|
//# sourceMappingURL=scoping.js.map
|
package/dataflow/extractor.js
CHANGED
|
@@ -18,7 +18,10 @@ const extract_cfg_1 = require("../control-flow/extract-cfg");
|
|
|
18
18
|
const edge_1 = require("./graph/edge");
|
|
19
19
|
const identify_link_to_last_call_relation_1 = require("../queries/catalog/call-context-query/identify-link-to-last-call-relation");
|
|
20
20
|
const built_in_function_definition_1 = require("./internal/process/functions/call/built-in/built-in-function-definition");
|
|
21
|
+
const transitive_side_effects_1 = require("./internal/process/functions/call/built-in/transitive-side-effects");
|
|
21
22
|
const flowr_file_1 = require("../project/context/flowr-file");
|
|
23
|
+
/** Round cap for the transitive-side-effect fixpoint. */
|
|
24
|
+
const transitiveSideEffectRounds = 32;
|
|
22
25
|
const identifier_1 = require("./environments/identifier");
|
|
23
26
|
const range_1 = require("../util/range");
|
|
24
27
|
const logger_1 = require("./logger");
|
|
@@ -145,8 +148,26 @@ function produceDataFlowGraph(parser, completeAst, ctx) {
|
|
|
145
148
|
/* source requests register automatically */
|
|
146
149
|
df = (0, built_in_source_1.standaloneSourceFile)(i, files[i], dfData, df);
|
|
147
150
|
}
|
|
148
|
-
//
|
|
149
|
-
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment);
|
|
151
|
+
// resolve linkages and propagate transitive side effects across calls to a fixpoint
|
|
152
|
+
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
153
|
+
const escapedNames = new Set();
|
|
154
|
+
for (let round = 0; round < transitiveSideEffectRounds; round++) {
|
|
155
|
+
const { environment, grew, escapedNames: roundNames } = (0, transitive_side_effects_1.propagateTransitiveSideEffects)(df.graph, df.environment, ctx);
|
|
156
|
+
df.environment = environment;
|
|
157
|
+
for (const n of roundNames) {
|
|
158
|
+
escapedNames.add(n);
|
|
159
|
+
}
|
|
160
|
+
if (!grew) {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
164
|
+
}
|
|
165
|
+
// resolve top-level reads that now see the escaped `<<-` definitions folded in above
|
|
166
|
+
if (escapedNames.size > 0) {
|
|
167
|
+
(0, transitive_side_effects_1.reResolveOpenReferences)(df.graph, df.environment, [...df.in, ...df.unknownReferences], escapedNames);
|
|
168
|
+
}
|
|
169
|
+
// link on-demand-materialized package exports back to their `library()` loaders
|
|
170
|
+
(0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
|
|
150
171
|
df.cfgQuick = resolveLinkToSideEffects(completeAst, df.graph, ctx);
|
|
151
172
|
// performance optimization: return cfgQuick as part of the result to avoid recomputation
|
|
152
173
|
return df;
|
|
@@ -3,6 +3,7 @@ import { EdgeType } from './edge';
|
|
|
3
3
|
import { emptyGraph } from './dataflowgraph-builder';
|
|
4
4
|
import { getOriginInDfg } from '../origin/dfg-get-origin';
|
|
5
5
|
import { CallGraph } from './call-graph';
|
|
6
|
+
import { computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
|
|
6
7
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
8
|
import type { REnvironmentInformation } from '../environments/environment';
|
|
8
9
|
import type { DataflowGraphVertexInfo } from './vertex';
|
|
@@ -80,6 +81,13 @@ export declare const Dataflow: {
|
|
|
80
81
|
* @see {@link getOriginInDfg} - for the underlying function
|
|
81
82
|
*/
|
|
82
83
|
readonly origin: typeof getOriginInDfg;
|
|
84
|
+
/**
|
|
85
|
+
* Interprocedural propagation of escaped side effects (attached packages, `<<-` definitions) to their callers.
|
|
86
|
+
*/
|
|
87
|
+
readonly sideEffects: {
|
|
88
|
+
readonly propagateTransitive: typeof propagateTransitiveSideEffects;
|
|
89
|
+
readonly callGraphSummaries: typeof computeCallGraphSummaries;
|
|
90
|
+
};
|
|
83
91
|
/**
|
|
84
92
|
* Only returns the sub-part of the graph that is determined by the given selection.
|
|
85
93
|
* In other words, this will return a graph with only vertices that are part of the selected ids,
|
|
@@ -7,6 +7,7 @@ const dataflowgraph_builder_1 = require("./dataflowgraph-builder");
|
|
|
7
7
|
const dfg_get_origin_1 = require("../origin/dfg-get-origin");
|
|
8
8
|
const graph_helper_1 = require("./graph-helper");
|
|
9
9
|
const call_graph_1 = require("./call-graph");
|
|
10
|
+
const transitive_side_effects_1 = require("../internal/process/functions/call/built-in/transitive-side-effects");
|
|
10
11
|
/**
|
|
11
12
|
* This is the root helper object to work with the {@link DataflowGraph}.
|
|
12
13
|
*
|
|
@@ -50,6 +51,13 @@ exports.Dataflow = {
|
|
|
50
51
|
* @see {@link getOriginInDfg} - for the underlying function
|
|
51
52
|
*/
|
|
52
53
|
origin: dfg_get_origin_1.getOriginInDfg,
|
|
54
|
+
/**
|
|
55
|
+
* Interprocedural propagation of escaped side effects (attached packages, `<<-` definitions) to their callers.
|
|
56
|
+
*/
|
|
57
|
+
sideEffects: {
|
|
58
|
+
propagateTransitive: transitive_side_effects_1.propagateTransitiveSideEffects,
|
|
59
|
+
callGraphSummaries: transitive_side_effects_1.computeCallGraphSummaries,
|
|
60
|
+
},
|
|
53
61
|
/**
|
|
54
62
|
* Only returns the sub-part of the graph that is determined by the given selection.
|
|
55
63
|
* In other words, this will return a graph with only vertices that are part of the selected ids,
|
|
@@ -4,7 +4,7 @@ import { type DataflowGraphVertexArgument, type DataflowGraphVertexFunctionCall,
|
|
|
4
4
|
import { EmptyArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
5
|
import type { BrandedIdentifier, IdentifierDefinition, IdentifierReference } from '../environments/identifier';
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
-
import { type REnvironmentInformation } from '../environments/environment';
|
|
7
|
+
import { type EnvType, type REnvironmentInformation } from '../environments/environment';
|
|
8
8
|
import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
9
9
|
import type { LinkTo } from '../../queries/catalog/call-context-query/call-context-query-format';
|
|
10
10
|
/**
|
|
@@ -303,4 +303,7 @@ export interface IEnvironmentJson {
|
|
|
303
303
|
parent: IEnvironmentJson;
|
|
304
304
|
memory: Record<BrandedIdentifier, IdentifierDefinition[]>;
|
|
305
305
|
builtInEnv: true | undefined;
|
|
306
|
+
n?: string;
|
|
307
|
+
t?: EnvType;
|
|
308
|
+
globalEnv?: true;
|
|
306
309
|
}
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -540,7 +540,11 @@ function envFromJson(json) {
|
|
|
540
540
|
const obj = new environment_1.Environment(parent, json.builtInEnv);
|
|
541
541
|
obj.id = json.id;
|
|
542
542
|
obj.memory = memory;
|
|
543
|
-
|
|
543
|
+
const env = obj;
|
|
544
|
+
env.n = json.n;
|
|
545
|
+
env.t = json.t;
|
|
546
|
+
env.globalEnv = json.globalEnv;
|
|
547
|
+
return env;
|
|
544
548
|
}
|
|
545
549
|
function renvFromJson(json) {
|
|
546
550
|
const current = envFromJson(json.current);
|
package/dataflow/info.d.ts
CHANGED
|
@@ -77,6 +77,27 @@ export declare function addNonDefaultExitPoints(existing: ExitPoint[], invertExi
|
|
|
77
77
|
* Overwrites the existing exit points with the given ones, taking care of cds.
|
|
78
78
|
*/
|
|
79
79
|
export declare function overwriteExitPoints(existing: readonly ExitPoint[], replace: ExitPoint[]): ExitPoint[];
|
|
80
|
+
/**
|
|
81
|
+
* A reference removed from scope within the current subtree (e.g., via `rm`). Like {@link DataflowInformation#out|out}
|
|
82
|
+
* references, kills bubble up so the enclosing scope can apply the removal at the right location.
|
|
83
|
+
* @see {@link applyKills}
|
|
84
|
+
*/
|
|
85
|
+
export type KillReference =
|
|
86
|
+
/** a statically known name (carries {@link IdentifierReference#cds|cds} for conditional removals) */
|
|
87
|
+
{
|
|
88
|
+
readonly kind: 'named';
|
|
89
|
+
readonly reference: IdentifierReference;
|
|
90
|
+
}
|
|
91
|
+
/** the whole current scope is cleared, e.g., `rm(list = ls())` */
|
|
92
|
+
| {
|
|
93
|
+
readonly kind: 'all';
|
|
94
|
+
readonly cds?: readonly ControlDependency[];
|
|
95
|
+
}
|
|
96
|
+
/** a not statically resolvable set of names, e.g., `rm(list = someVector)` */
|
|
97
|
+
| {
|
|
98
|
+
readonly kind: 'unknown';
|
|
99
|
+
readonly cds?: readonly ControlDependency[];
|
|
100
|
+
};
|
|
80
101
|
/** The control flow information for the current DataflowInformation. */
|
|
81
102
|
export interface DataflowCfgInformation {
|
|
82
103
|
/** The entry node into the subgraph */
|
|
@@ -123,6 +144,11 @@ export interface DataflowInformation extends DataflowCfgInformation {
|
|
|
123
144
|
environment: REnvironmentInformation;
|
|
124
145
|
/** The current constructed dataflow graph */
|
|
125
146
|
graph: DataflowGraph;
|
|
147
|
+
/**
|
|
148
|
+
* References removed from scope within the current subtree (e.g., via `rm`); `undefined` unless an `rm` occurred.
|
|
149
|
+
* @see {@link KillReference}
|
|
150
|
+
*/
|
|
151
|
+
kill?: readonly KillReference[];
|
|
126
152
|
}
|
|
127
153
|
/**
|
|
128
154
|
* Helper object for {@link DataflowInformation}
|
|
@@ -14,6 +14,7 @@ const reference_to_maybe_1 = require("../../../../../environments/reference-to-m
|
|
|
14
14
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
15
15
|
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
16
16
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
17
|
+
const built_in_stack_env_1 = require("./built-in-stack-env");
|
|
17
18
|
function tableAssignmentProcessor(name, args, rootId, data, outInfo) {
|
|
18
19
|
outInfo.definitionRootNodes.push(rootId);
|
|
19
20
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.TableAssignment }).information;
|
|
@@ -59,15 +60,16 @@ function processAccess(name, args, rootId, data, config) {
|
|
|
59
60
|
}
|
|
60
61
|
/* we include the read edges to the constant arguments as well so that they are included if necessary */
|
|
61
62
|
}
|
|
62
|
-
/* for $ access on a tracked env variable, add Reads edges to the field definition
|
|
63
|
+
/* for $ access on a tracked env variable or a stack env (globalenv()/.GlobalEnv), add Reads edges to the field definition */
|
|
63
64
|
if (config.treatIndicesAsString && identifier_1.Identifier.getName(name.content) === '$'
|
|
64
|
-
&& head !== r_function_call_1.EmptyArgument && head.value
|
|
65
|
+
&& head !== r_function_call_1.EmptyArgument && head.value !== undefined
|
|
65
66
|
&& args.length >= 2 && args[1] !== r_function_call_1.EmptyArgument) {
|
|
66
|
-
const
|
|
67
|
-
|
|
67
|
+
const envState = (0, built_in_stack_env_1.resolveNodeToStackEnv)(head.value, data)
|
|
68
|
+
?? (head.value.type === type_1.RType.Symbol ? (0, built_in_envir_utils_1.resolveSymbolToEnvir)(head.value.content, head.value.info.id, data)?.envDef.envState : undefined);
|
|
69
|
+
if (envState) {
|
|
68
70
|
const fieldNode = (0, unpack_argument_1.unpackArg)(args[1]);
|
|
69
71
|
const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : fieldNode?.lexeme;
|
|
70
|
-
const fieldDefs = fieldName ?
|
|
72
|
+
const fieldDefs = fieldName ? envState.current.memory.get(fieldName) : undefined;
|
|
71
73
|
for (const fd of fieldDefs ?? []) {
|
|
72
74
|
info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Reads);
|
|
73
75
|
}
|