@eagleoutice/flowr 2.13.13 → 2.13.15
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 +31 -28
- package/abstract-interpretation/data-frame/resolve-args.js +11 -12
- package/benchmark/calibration.d.ts +18 -0
- package/benchmark/calibration.js +63 -0
- package/benchmark/slicer.d.ts +19 -0
- package/benchmark/slicer.js +84 -1
- package/benchmark/stats/feature-counts.d.ts +6 -0
- package/benchmark/stats/feature-counts.js +61 -0
- package/benchmark/stats/print.js +20 -0
- package/benchmark/stats/sigdb-counts.d.ts +7 -0
- package/benchmark/stats/sigdb-counts.js +219 -0
- package/benchmark/stats/size-of.d.ts +6 -0
- package/benchmark/stats/size-of.js +8 -0
- package/benchmark/stats/stats.d.ts +79 -0
- package/benchmark/stats/stats.js +7 -1
- package/benchmark/stopwatch.d.ts +4 -0
- package/benchmark/stopwatch.js +12 -1
- package/benchmark/summarizer/data.d.ts +17 -1
- package/benchmark/summarizer/first-phase/input.js +5 -0
- package/benchmark/summarizer/first-phase/process.js +12 -2
- package/benchmark/summarizer/second-phase/graph.d.ts +24 -1
- package/benchmark/summarizer/second-phase/graph.js +249 -18
- package/benchmark/summarizer/second-phase/process.js +56 -0
- package/benchmark/summarizer/summarizer.js +1 -2
- package/cli/benchmark-app.d.ts +1 -0
- package/cli/benchmark-app.js +2 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +12 -2
- package/cli/common/options.d.ts +10 -0
- package/cli/common/options.js +3 -1
- package/cli/common/scripts-info.d.ts +10 -0
- package/cli/repl/commands/repl-cfg.js +2 -42
- package/cli/repl/commands/repl-clipboard.d.ts +7 -0
- package/cli/repl/commands/repl-clipboard.js +53 -0
- package/cli/repl/commands/repl-dataflow.js +5 -70
- package/cli/repl/commands/repl-normalize.js +3 -51
- package/control-flow/cfg-builder.d.ts +30 -0
- package/control-flow/cfg-builder.js +79 -0
- package/control-flow/cfg-dead-code.js +5 -29
- package/control-flow/diff-cfg.js +2 -56
- package/control-flow/extract-cfg.js +17 -10
- package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
- package/control-flow/semantic-cfg-guided-visitor.js +14 -0
- package/control-flow/useless-loop.js +4 -26
- package/core/steps/all/core/10-normalize.d.ts +8 -0
- package/core/steps/all/core/10-normalize.js +10 -8
- package/core/steps/all/core/11-normalize-tree-sitter.d.ts +5 -7
- package/core/steps/all/core/11-normalize-tree-sitter.js +2 -9
- package/data/r-base-packages.generated.d.ts +1 -0
- package/data/r-base-packages.generated.js +5 -3
- package/dataflow/environments/apply-kill.d.ts +3 -3
- package/dataflow/environments/apply-kill.js +60 -31
- package/dataflow/environments/built-in-config.d.ts +9 -1
- 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-props.d.ts +4 -0
- package/dataflow/environments/built-in-props.js +3 -3
- package/dataflow/environments/built-in.d.ts +4 -2
- package/dataflow/environments/built-in.js +53 -3
- package/dataflow/environments/data-masking-functions.d.ts +3 -4
- package/dataflow/environments/data-masking-functions.js +7 -8
- package/dataflow/environments/default-builtin-config.d.ts +92 -12
- package/dataflow/environments/default-builtin-config.js +86 -43
- package/dataflow/environments/environment.d.ts +5 -0
- package/dataflow/environments/environment.js +17 -12
- package/dataflow/environments/identifier.d.ts +3 -0
- package/dataflow/environments/reference-to-maybe.d.ts +5 -3
- package/dataflow/environments/reference-to-maybe.js +17 -52
- package/dataflow/environments/resolve-helper.d.ts +2 -1
- package/dataflow/environments/resolve-helper.js +2 -1
- package/dataflow/eval/resolve/alias-tracking.js +4 -7
- package/dataflow/eval/resolve/node-value.d.ts +51 -0
- package/dataflow/eval/resolve/node-value.js +71 -0
- package/dataflow/eval/resolve/resolve-argument.js +10 -7
- package/dataflow/eval/resolve/resolve-operators.js +1 -2
- package/dataflow/eval/values/general.d.ts +4 -0
- package/dataflow/eval/values/general.js +11 -0
- package/dataflow/eval/values/r-value.d.ts +15 -0
- package/dataflow/eval/values/r-value.js +27 -1
- package/dataflow/extractor.js +2 -0
- package/dataflow/fn/higher-order-function.js +2 -3
- package/dataflow/graph/df-helper.d.ts +2 -1
- package/dataflow/graph/diff-dataflow-graph.js +3 -55
- package/dataflow/graph/graph.d.ts +5 -0
- package/dataflow/graph/graph.js +27 -0
- package/dataflow/info.d.ts +7 -1
- package/dataflow/info.js +36 -7
- package/dataflow/internal/linker.d.ts +23 -0
- package/dataflow/internal/linker.js +70 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +4 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -29
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +39 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +10 -22
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +29 -53
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +19 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +3 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +69 -52
- package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +2 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +23 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +7 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +20 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +25 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +105 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +9 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +1 -1
- package/dataflow/internal/process/functions/call/deferred.d.ts +41 -0
- package/dataflow/internal/process/functions/call/deferred.js +127 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +13 -12
- package/dataflow/internal/process/functions/call/known-call-handling.js +35 -35
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
- package/dataflow/internal/process/functions/call/nse.d.ts +28 -0
- package/dataflow/internal/process/functions/call/nse.js +87 -0
- package/dataflow/internal/process/functions/call/quoted.d.ts +29 -0
- package/dataflow/internal/process/functions/call/quoted.js +188 -0
- package/documentation/doc-readme.js +5 -2
- package/documentation/doc-util/doc-issue.d.ts +2 -0
- package/documentation/doc-util/doc-issue.js +3 -1
- package/documentation/doc-util/doc-types.js +15 -9
- package/documentation/wiki-dataflow-graph.js +4 -0
- package/documentation/wiki-faq.js +6 -2
- package/documentation/wiki-onboarding.js +11 -1
- package/documentation/wiki-setup.js +2 -1
- package/linter/rules/deprecated-functions.js +9 -3
- package/linter/rules/seeded-randomness.js +2 -3
- package/linter/rules/undefined-symbol.js +10 -1
- package/package.json +9 -4
- package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +6 -0
- package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +17 -1
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +2 -11
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +3 -15
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +16 -0
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +26 -0
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -11
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +3 -15
- package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +4 -10
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -9
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -9
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +1 -1
- package/project/sigdb/reader.d.ts +9 -0
- package/project/sigdb/reader.js +30 -0
- package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -1
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -12
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -37
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -23
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
- package/queries/query-function-filter.d.ts +21 -0
- package/queries/query-function-filter.js +48 -0
- package/r-bridge/data/data.d.ts +13 -3
- package/r-bridge/data/data.js +15 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +4 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
- package/search/flowr-search-filters.d.ts +5 -1
- package/search/flowr-search-filters.js +31 -21
- package/search/search-executor/search-enrichers.d.ts +24 -4
- package/search/search-executor/search-enrichers.js +22 -9
- package/search/search-executor/search-transformer.js +1 -1
- package/slicing/static/slice-call.js +4 -4
- package/util/diff-graph.d.ts +13 -0
- package/util/diff-graph.js +64 -1
- package/util/files.js +9 -8
- package/util/node-version.d.ts +4 -0
- package/util/node-version.js +29 -0
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +3 -1
- package/util/version.js +1 -1
|
@@ -5,8 +5,7 @@ const known_call_handling_1 = require("../known-call-handling");
|
|
|
5
5
|
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
6
6
|
const logger_1 = require("../../../../../logger");
|
|
7
7
|
const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
|
|
8
|
-
const
|
|
9
|
-
const general_1 = require("../../../../../eval/values/general");
|
|
8
|
+
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
10
9
|
const assert_1 = require("../../../../../../util/assert");
|
|
11
10
|
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
12
11
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
@@ -45,12 +44,11 @@ function processStopIfNot(name, args, rootId, data) {
|
|
|
45
44
|
}
|
|
46
45
|
const localArgs = argMap.get('local');
|
|
47
46
|
const localArg = localArgs.length > 0 ? localArgs.at(-1) : undefined;
|
|
48
|
-
const resolveArgs = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx };
|
|
49
47
|
// we collect all control dependencies from: all '...', all expressions in 'exprs', and 'exprObject'
|
|
50
48
|
const ids = collectIdsForControl(argMap, data);
|
|
51
49
|
if (localArg !== undefined && localArg !== r_function_call_1.EmptyArgument) {
|
|
52
|
-
const localVal =
|
|
53
|
-
const alwaysTrue =
|
|
50
|
+
const localVal = node_value_1.NodeValue.setOf(localArg?.value?.info.id, data);
|
|
51
|
+
const alwaysTrue = localVal?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
|
|
54
52
|
if (!alwaysTrue) {
|
|
55
53
|
logger_1.dataflowLogger.warn(`stopifnot (${identifier_1.Identifier.toString(name.content)}) with non-true 'local' argument is not yet supported, over-approximate`);
|
|
56
54
|
const cds = (data.cds ?? []).concat(Array.from(ids).map(r => ({
|
|
@@ -67,8 +65,8 @@ function processStopIfNot(name, args, rootId, data) {
|
|
|
67
65
|
}
|
|
68
66
|
const cds = [];
|
|
69
67
|
for (const id of ids) {
|
|
70
|
-
const val =
|
|
71
|
-
const alwaysFalse =
|
|
68
|
+
const val = node_value_1.NodeValue.setOf(id, data);
|
|
69
|
+
const alwaysFalse = val?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
|
|
72
70
|
if (alwaysFalse) {
|
|
73
71
|
// we know that this fails *always*
|
|
74
72
|
res.exitPoints.push(data.cds ? {
|
|
@@ -81,7 +79,7 @@ function processStopIfNot(name, args, rootId, data) {
|
|
|
81
79
|
});
|
|
82
80
|
return res;
|
|
83
81
|
}
|
|
84
|
-
const alwaysTrue =
|
|
82
|
+
const alwaysTrue = val?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
|
|
85
83
|
if (!alwaysTrue) {
|
|
86
84
|
cds.push({
|
|
87
85
|
id: id,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
2
|
+
import type { DataflowInformation } from '../../../../../info';
|
|
3
|
+
import { type ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
+
import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
|
+
import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
6
|
+
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
+
export interface StringTemplateConfiguration {
|
|
8
|
+
/** what opens an interpolation, `{` unless given */
|
|
9
|
+
readonly open?: string;
|
|
10
|
+
/** what closes it, `}` unless given */
|
|
11
|
+
readonly close?: string;
|
|
12
|
+
/** whether `{.cls ...}` styles its content instead of evaluating it, as cli does */
|
|
13
|
+
readonly markup?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The R expressions a template interpolates. A doubled delimiter escapes it, delimiters nest, and one inside a
|
|
17
|
+
* string is literal, so this walks the template. With `markup`, `{.cls ...}` contributes its content instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare function interpolationsOf(template: string, open: string, close: string, markup?: boolean): readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Processes a call whose string arguments are templates carrying R code, as `glue` and `cli` use them.
|
|
22
|
+
* The code runs where the call is, reading and writing like anything written there, so that is how it is
|
|
23
|
+
* analyzed. A template pointed at another scope is marked unknown instead.
|
|
24
|
+
*/
|
|
25
|
+
export declare function processStringTemplate<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: StringTemplateConfiguration): DataflowInformation;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolationsOf = interpolationsOf;
|
|
4
|
+
exports.processStringTemplate = processStringTemplate;
|
|
5
|
+
const known_call_handling_1 = require("../known-call-handling");
|
|
6
|
+
const retriever_1 = require("../../../../../../r-bridge/retriever");
|
|
7
|
+
const decorate_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate");
|
|
8
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
9
|
+
const identifier_1 = require("../../../../../environments/identifier");
|
|
10
|
+
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
11
|
+
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
|
|
12
|
+
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
13
|
+
const built_in_source_1 = require("./built-in-source");
|
|
14
|
+
const linker_1 = require("../../../../linker");
|
|
15
|
+
/** Arguments naming the scope the template runs against, which we cannot follow. */
|
|
16
|
+
const RedirectingParameters = ['.envir', '.con', '.x', '.data'];
|
|
17
|
+
/** cli markup: `{.cls text}` styles its content, so the class is no expression but the content may hold some. */
|
|
18
|
+
const Markup = /^\.[A-Za-z][\w.-]*[\s]/;
|
|
19
|
+
/**
|
|
20
|
+
* The R expressions a template interpolates. A doubled delimiter escapes it, delimiters nest, and one inside a
|
|
21
|
+
* string is literal, so this walks the template. With `markup`, `{.cls ...}` contributes its content instead.
|
|
22
|
+
*/
|
|
23
|
+
function interpolationsOf(template, open, close, markup = false) {
|
|
24
|
+
const found = [];
|
|
25
|
+
let at = 0;
|
|
26
|
+
while (at < template.length) {
|
|
27
|
+
if (template.startsWith(open + open, at)) {
|
|
28
|
+
at += 2 * open.length;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
else if (!template.startsWith(open, at)) {
|
|
32
|
+
at += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const from = at + open.length;
|
|
36
|
+
let depth = 1, quote = undefined, i = from;
|
|
37
|
+
for (; i < template.length && depth > 0; i++) {
|
|
38
|
+
const c = template[i];
|
|
39
|
+
if (quote !== undefined) {
|
|
40
|
+
quote = c === '\\' ? (i++, quote) : c === quote ? undefined : quote;
|
|
41
|
+
}
|
|
42
|
+
else if (c === '"' || c === '\'' || c === '`') {
|
|
43
|
+
quote = c;
|
|
44
|
+
}
|
|
45
|
+
else if (template.startsWith(open, i)) {
|
|
46
|
+
depth++;
|
|
47
|
+
}
|
|
48
|
+
else if (template.startsWith(close, i)) {
|
|
49
|
+
depth--;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (depth === 0) {
|
|
53
|
+
const content = template.slice(from, i - close.length);
|
|
54
|
+
if (markup && Markup.test(content)) {
|
|
55
|
+
found.push(...interpolationsOf(content, open, close, markup));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
found.push(content);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
at = i;
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
/** The argument given under `name`, `undefined` if the call does not name it. */
|
|
66
|
+
function namedArgument(args, name) {
|
|
67
|
+
return args.find((a) => a !== r_function_call_1.EmptyArgument && a.name !== undefined
|
|
68
|
+
&& identifier_1.Identifier.getName(a.name.content) === name);
|
|
69
|
+
}
|
|
70
|
+
/** The string a named argument spells out, `undefined` unless it is a literal. */
|
|
71
|
+
function literalOf(args, name) {
|
|
72
|
+
const value = namedArgument(args, name)?.value;
|
|
73
|
+
return value?.type === type_1.RType.String ? value.content.str : undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Processes a call whose string arguments are templates carrying R code, as `glue` and `cli` use them.
|
|
77
|
+
* The code runs where the call is, reading and writing like anything written there, so that is how it is
|
|
78
|
+
* analyzed. A template pointed at another scope is marked unknown instead.
|
|
79
|
+
*/
|
|
80
|
+
function processStringTemplate(name, args, rootId, data, config) {
|
|
81
|
+
const { information } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.StringTemplate });
|
|
82
|
+
/* these are only ever given by name, and matching them positionally would swallow the template itself */
|
|
83
|
+
if (RedirectingParameters.some(p => namedArgument(args, p) !== undefined)) {
|
|
84
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
|
|
85
|
+
return information;
|
|
86
|
+
}
|
|
87
|
+
const open = literalOf(args, '.open') ?? config.open ?? '{';
|
|
88
|
+
const close = literalOf(args, '.close') ?? config.close ?? '}';
|
|
89
|
+
const results = [];
|
|
90
|
+
for (const arg of args) {
|
|
91
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined || arg.value?.type !== type_1.RType.String) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const template = arg.value;
|
|
95
|
+
for (const code of interpolationsOf(template.content.str, open, close, config.markup)) {
|
|
96
|
+
const generator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(`${name.lexeme}::${template.info.id}`, template.location);
|
|
97
|
+
const result = (0, built_in_source_1.sourceRequest)(rootId, (0, retriever_1.requestFromInput)(code), data, information, false, generator);
|
|
98
|
+
/* the template stands where the call does, so what it leaves open resolves against the bindings here */
|
|
99
|
+
(0, linker_1.linkInputs)([...result.in, ...result.unknownReferences], data.environment, [], result.graph, false);
|
|
100
|
+
results.push(result);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return (0, built_in_source_1.mergeSourced)(information, results);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=built-in-string-template.js.map
|
|
@@ -13,9 +13,6 @@ const assert_1 = require("../../../../../../util/assert");
|
|
|
13
13
|
const edge_1 = require("../../../../../graph/edge");
|
|
14
14
|
const unnamed_call_handling_1 = require("../unnamed-call-handling");
|
|
15
15
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
16
|
-
const identifier_2 = require("../../../../../environments/identifier");
|
|
17
|
-
const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
|
|
18
|
-
const log_1 = require("../../../../../../util/log");
|
|
19
16
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
20
17
|
/**
|
|
21
18
|
* Process a built-in try-catch or similar handler.
|
|
@@ -88,7 +85,14 @@ function processTryCatch(name, args, rootId, data, config) {
|
|
|
88
85
|
info.graph.addEdge(rootId, e.nodeId, edge_1.EdgeType.Returns);
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
|
-
|
|
88
|
+
/* block and finally are evaluated in the enclosing environment, so their definitions have to bubble up */
|
|
89
|
+
const escaping = [];
|
|
90
|
+
for (const arg of res.processedArguments) {
|
|
91
|
+
if (arg && (blockArg.has(arg.entryPoint) || finallyArg.has(arg.entryPoint))) {
|
|
92
|
+
escaping.push(...arg.out);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return escaping.length > 0 ? { ...info, out: info.out.concat(escaping) } : info;
|
|
92
96
|
}
|
|
93
97
|
function promoteCallToFunction(call, arg, info, data) {
|
|
94
98
|
let functionId = undefined;
|
|
@@ -118,30 +122,7 @@ function promoteCallToFunction(call, arg, info, data) {
|
|
|
118
122
|
info.graph.addEdge(arg, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
|
|
119
123
|
const dfVert = info.graph.getVertex(call);
|
|
120
124
|
if (dfVert && dfVert.tag === vertex_1.VertexType.FunctionDefinition) {
|
|
121
|
-
|
|
122
|
-
const ingoingRefs = dfVert.subflow.in;
|
|
123
|
-
const remainingIn = [];
|
|
124
|
-
for (const ingoing of ingoingRefs) {
|
|
125
|
-
const resolved = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, data.environment, ingoing.type) : undefined;
|
|
126
|
-
if (resolved === undefined) {
|
|
127
|
-
remainingIn.push(ingoing);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
(0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Found ${resolved.length} references to open ref ${ingoing.nodeId} in closure of function definition ${call}`);
|
|
131
|
-
let allBuiltIn = true;
|
|
132
|
-
for (const ref of resolved) {
|
|
133
|
-
const rid = ref.nodeId;
|
|
134
|
-
info.graph.addEdge(ingoing.nodeId, rid, edge_1.EdgeType.Reads);
|
|
135
|
-
info.graph.addEdge(call, rid, edge_1.EdgeType.Reads); // because the def. is the anonymous call
|
|
136
|
-
if (!(0, identifier_2.isReferenceType)(ref.type, identifier_2.ReferenceType.BuiltInConstant | identifier_2.ReferenceType.BuiltInFunction)) {
|
|
137
|
-
allBuiltIn = false;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (allBuiltIn) {
|
|
141
|
-
remainingIn.push(ingoing);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
dfVert.subflow.in = remainingIn;
|
|
125
|
+
linker_1.ClosureRefs.resolveOpenIngoing(info.graph, call, dfVert, data.environment);
|
|
145
126
|
}
|
|
146
127
|
// we did the linking
|
|
147
128
|
return undefined;
|
|
@@ -10,8 +10,7 @@ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model
|
|
|
10
10
|
const logger_1 = require("../../../../../logger");
|
|
11
11
|
const edge_1 = require("../../../../../graph/edge");
|
|
12
12
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
13
|
-
const
|
|
14
|
-
const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
|
|
13
|
+
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
15
14
|
const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
|
|
16
15
|
const apply_kill_1 = require("../../../../../environments/apply-kill");
|
|
17
16
|
const append_1 = require("../../../../../environments/append");
|
|
@@ -32,8 +31,8 @@ function processWhileLoop(name, args, rootId, data) {
|
|
|
32
31
|
const nameId = name.info.id;
|
|
33
32
|
const origEnv = data.environment;
|
|
34
33
|
// we should defer this to the abstract interpretation
|
|
35
|
-
const values =
|
|
36
|
-
const conditionIsAlwaysFalse =
|
|
34
|
+
const values = node_value_1.NodeValue.setOf(unpackedArgs[0]?.info.id, data);
|
|
35
|
+
const conditionIsAlwaysFalse = values?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
|
|
37
36
|
//We don't care about the body if it never executes
|
|
38
37
|
if (conditionIsAlwaysFalse) {
|
|
39
38
|
unpackedArgs.pop();
|
|
@@ -62,7 +61,7 @@ function processWhileLoop(name, args, rootId, data) {
|
|
|
62
61
|
hooks: condition.hooks
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
|
-
const conditionIsAlwaysTrue =
|
|
64
|
+
const conditionIsAlwaysTrue = values?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
|
|
66
65
|
(0, assert_1.guard)(condition !== undefined && body !== undefined, () => `While-Loop ${identifier_1.Identifier.toString(name.content)} has no condition or body, impossible!`);
|
|
67
66
|
const originalDependency = data.cds;
|
|
68
67
|
if ((0, info_1.alwaysExits)(condition)) {
|
|
@@ -15,7 +15,7 @@ const withParamsFallback = ['data', 'expr'];
|
|
|
15
15
|
/** Normal call analysis, marking the data-masked arguments (columns of the data) as NSE. */
|
|
16
16
|
function markAsMaskedFallback(name, args, rootId, data) {
|
|
17
17
|
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With });
|
|
18
|
-
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.AllButFirst, known_call_handling_1.NseKind.DataMasked);
|
|
18
|
+
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.AllButFirst, { kind: known_call_handling_1.NseKind.DataMasked });
|
|
19
19
|
return information;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AstIdMap, ParentInformation } from '../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
2
|
+
import type { NodeId } from '../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
3
|
+
import type { DataflowGraph } from '../../../../graph/graph';
|
|
4
|
+
import type { ControlFlowGraph } from '../../../../../control-flow/control-flow-graph';
|
|
5
|
+
/** The reads that may force the expression, and the control flow deciding what they can see. */
|
|
6
|
+
export interface ForceSites {
|
|
7
|
+
readonly cfg: ControlFlowGraph;
|
|
8
|
+
readonly sites: readonly NodeId[];
|
|
9
|
+
/** the name the deferred expression is bound to, whose binding its own writes replace */
|
|
10
|
+
readonly binding: NodeId;
|
|
11
|
+
}
|
|
12
|
+
/** Where a name is bound and where it is read, so that a deferred expression can reach either. */
|
|
13
|
+
interface NameIndex {
|
|
14
|
+
readonly definitions: ReadonlyMap<string, NodeId[]>;
|
|
15
|
+
readonly uses: ReadonlyMap<string, NodeId[]>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An expression R evaluates at a time we cannot pin down: the body a `delayedAssign` binds, forced at some
|
|
19
|
+
* later read of the name, or a promise a closure carries past the call that created it.
|
|
20
|
+
*
|
|
21
|
+
* Since the moment is open, every binding the expression may meet is a candidate, and symmetrically so:
|
|
22
|
+
* a name it reads may read any definition of that name, and a name it writes may be read by any use of it.
|
|
23
|
+
* That is the may-analysis both directions ask for, so nothing the expression really depends on, and nothing
|
|
24
|
+
* really depending on it, can be missed.
|
|
25
|
+
*/
|
|
26
|
+
export declare const Deferred: {
|
|
27
|
+
/** Where each name is bound and read, built once and shared by every deferred expression in the graph. */
|
|
28
|
+
readonly indexOf: <Info>(this: void, graph: DataflowGraph, idMap: AstIdMap<Info & ParentInformation>) => NameIndex;
|
|
29
|
+
/**
|
|
30
|
+
* The reads that may be the one forcing `binding`: every read of it that no other read always precedes,
|
|
31
|
+
* since an earlier read would already have forced it and cached the value.
|
|
32
|
+
*/
|
|
33
|
+
readonly forcedAt: (this: void, graph: DataflowGraph, binding: NodeId, cfg: ControlFlowGraph) => readonly NodeId[];
|
|
34
|
+
/**
|
|
35
|
+
* Links the expression rooted at `expr` to the bindings it may meet when it is evaluated. Given the reads
|
|
36
|
+
* that may force it, control flow rules out what no force can reach; without them every binding stays a
|
|
37
|
+
* candidate.
|
|
38
|
+
*/
|
|
39
|
+
readonly link: <Info>(this: void, graph: DataflowGraph, expr: NodeId, index: NameIndex, idMap: AstIdMap<Info & ParentInformation>, forces?: ForceSites) => void;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deferred = void 0;
|
|
4
|
+
const model_1 = require("../../../../../r-bridge/lang-4.x/ast/model/model");
|
|
5
|
+
const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
6
|
+
const type_1 = require("../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
7
|
+
const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
8
|
+
const identifier_1 = require("../../../../environments/identifier");
|
|
9
|
+
const retriever_1 = require("../../../../../r-bridge/retriever");
|
|
10
|
+
const edge_1 = require("../../../../graph/edge");
|
|
11
|
+
const vertex_1 = require("../../../../graph/vertex");
|
|
12
|
+
const happens_before_1 = require("../../../../../control-flow/happens-before");
|
|
13
|
+
const logic_1 = require("../../../../../util/logic");
|
|
14
|
+
/** Drops the read of `target` from `use`, for a binding another write has replaced. */
|
|
15
|
+
function dropRead(graph, use, target) {
|
|
16
|
+
graph.removeEdgeType(use, target, edge_1.EdgeType.Reads);
|
|
17
|
+
}
|
|
18
|
+
function add(index, name, id) {
|
|
19
|
+
const known = index.get(name);
|
|
20
|
+
if (known) {
|
|
21
|
+
known.push(id);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
index.set(name, [id]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The names a deferred expression touches, each with the node touching it and whether it is written. */
|
|
28
|
+
function namesWithin(expr, graph, idMap) {
|
|
29
|
+
const node = idMap.get(expr);
|
|
30
|
+
const names = [];
|
|
31
|
+
if (node === undefined) {
|
|
32
|
+
return names;
|
|
33
|
+
}
|
|
34
|
+
const callees = new Set();
|
|
35
|
+
model_1.RNode.visitAst(node, inner => {
|
|
36
|
+
if (r_function_call_1.RFunctionCall.isNamed(inner)) {
|
|
37
|
+
callees.add(inner.functionName.info.id);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
else if (inner.type !== type_1.RType.Symbol || callees.has(inner.info.id)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const vertex = graph.getVertex(inner.info.id);
|
|
44
|
+
if (vertex_1.UseVertex.is(vertex) || vertex_1.VariableDefinitionVertex.is(vertex)) {
|
|
45
|
+
names.push([inner.info.id, identifier_1.Identifier.getName(inner.content), vertex_1.VariableDefinitionVertex.is(vertex)]);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
return names;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* An expression R evaluates at a time we cannot pin down: the body a `delayedAssign` binds, forced at some
|
|
53
|
+
* later read of the name, or a promise a closure carries past the call that created it.
|
|
54
|
+
*
|
|
55
|
+
* Since the moment is open, every binding the expression may meet is a candidate, and symmetrically so:
|
|
56
|
+
* a name it reads may read any definition of that name, and a name it writes may be read by any use of it.
|
|
57
|
+
* That is the may-analysis both directions ask for, so nothing the expression really depends on, and nothing
|
|
58
|
+
* really depending on it, can be missed.
|
|
59
|
+
*/
|
|
60
|
+
exports.Deferred = {
|
|
61
|
+
/** Where each name is bound and read, built once and shared by every deferred expression in the graph. */
|
|
62
|
+
indexOf(graph, idMap) {
|
|
63
|
+
const definitions = new Map();
|
|
64
|
+
const uses = new Map();
|
|
65
|
+
for (const [type, index] of [[vertex_1.VertexType.VariableDefinition, definitions], [vertex_1.VertexType.Use, uses]]) {
|
|
66
|
+
for (const [id] of graph.verticesOfType(type)) {
|
|
67
|
+
const name = (0, node_id_1.recoverName)(id, idMap);
|
|
68
|
+
if (name !== undefined) {
|
|
69
|
+
add(index, name, id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { definitions, uses };
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* The reads that may be the one forcing `binding`: every read of it that no other read always precedes,
|
|
77
|
+
* since an earlier read would already have forced it and cached the value.
|
|
78
|
+
*/
|
|
79
|
+
forcedAt(graph, binding, cfg) {
|
|
80
|
+
const reads = [];
|
|
81
|
+
for (const [reader, edge] of graph.ingoingEdges(binding) ?? []) {
|
|
82
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
|
|
83
|
+
reads.push(reader);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return reads.filter(r => !reads.some(other => other !== r && (0, happens_before_1.happensBefore)(cfg, other, r) === logic_1.Ternary.Always));
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Links the expression rooted at `expr` to the bindings it may meet when it is evaluated. Given the reads
|
|
90
|
+
* that may force it, control flow rules out what no force can reach; without them every binding stays a
|
|
91
|
+
* candidate.
|
|
92
|
+
*/
|
|
93
|
+
link(graph, expr, index, idMap, forces) {
|
|
94
|
+
const within = namesWithin(expr, graph, idMap);
|
|
95
|
+
const own = new Set(within.map(([id]) => id));
|
|
96
|
+
/* a binding matters only if some force can see it, and a use only if some force can reach it */
|
|
97
|
+
const seenByAForce = (definition) => forces === undefined
|
|
98
|
+
|| forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, definition, site) !== logic_1.Ternary.Never);
|
|
99
|
+
/* the forcing read yields the promise's value, so only reads after it observe what the promise wrote */
|
|
100
|
+
const reachedByAForce = (use) => forces === undefined
|
|
101
|
+
|| (!forces.sites.includes(use) && forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, site, use) !== logic_1.Ternary.Never));
|
|
102
|
+
/* `delayedAssign` names its variable with a string literal, so the recovered name still carries quotes */
|
|
103
|
+
const bindingName = forces === undefined ? undefined : (0, retriever_1.removeRQuotes)((0, node_id_1.recoverName)(forces.binding, idMap) ?? '');
|
|
104
|
+
for (const [node, name, writes] of within) {
|
|
105
|
+
if (writes) {
|
|
106
|
+
/* a write of the bound name replaces the binding, so a read it definitely reaches sees only it */
|
|
107
|
+
const shadows = forces !== undefined && name === bindingName && graph.getVertex(node)?.cds === undefined;
|
|
108
|
+
for (const use of index.uses.get(name) ?? []) {
|
|
109
|
+
if (!own.has(use) && reachedByAForce(use)) {
|
|
110
|
+
graph.addEdge(use, node, edge_1.EdgeType.Reads);
|
|
111
|
+
if (shadows && forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, site, use) === logic_1.Ternary.Always)) {
|
|
112
|
+
dropRead(graph, use, forces.binding);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
for (const definition of index.definitions.get(name) ?? []) {
|
|
119
|
+
if (seenByAForce(definition)) {
|
|
120
|
+
graph.addEdge(node, definition, edge_1.EdgeType.Reads);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=deferred.js.map
|
|
@@ -21,7 +21,7 @@ export interface ProcessKnownFunctionCallInput<OtherInfo> extends ForceArguments
|
|
|
21
21
|
readonly data: DataflowProcessorInformation<OtherInfo & ParentInformation>;
|
|
22
22
|
/** should arguments be processed from right to left? This does not affect the order recorded in the call but of the environments */
|
|
23
23
|
readonly reverseOrder?: boolean;
|
|
24
|
-
/** which arguments are
|
|
24
|
+
/** which arguments are {@link NseKind.Reevaluated|reevaluated}, like a loop body */
|
|
25
25
|
readonly markAsNSE?: readonly number[];
|
|
26
26
|
/** allows passing a data processor in-between each argument */
|
|
27
27
|
readonly patchData?: (data: DataflowProcessorInformation<OtherInfo & ParentInformation>, arg: number) => DataflowProcessorInformation<OtherInfo & ParentInformation>;
|
|
@@ -65,20 +65,21 @@ export declare enum NseKind {
|
|
|
65
65
|
/** the argument is not evaluated at all (`quote(x + y)`), so nothing within it is */
|
|
66
66
|
Quoted = "quoted",
|
|
67
67
|
/** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */
|
|
68
|
-
DataMasked = "data-masked"
|
|
68
|
+
DataMasked = "data-masked",
|
|
69
|
+
/** evaluated, just not exactly once (a loop body), so only the argument itself is marked */
|
|
70
|
+
Reevaluated = "reevaluated"
|
|
71
|
+
}
|
|
72
|
+
export interface NseMarkOptions {
|
|
73
|
+
readonly kind?: NseKind;
|
|
74
|
+
/** ids an unquote escape splices back in, see {@link Nse.unquoted} */
|
|
75
|
+
readonly evaluated?: ReadonlySet<NodeId>;
|
|
69
76
|
}
|
|
70
77
|
/**
|
|
71
|
-
* Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* names the mask supplies (those that resolve to nothing else) taken from the data, so only those are marked.
|
|
75
|
-
* Besides the {@link NseArguments} shorthands, the positions may be listed explicitly, `undefined` marks nothing.
|
|
76
|
-
*/
|
|
77
|
-
export declare function markArgumentsAsNonStandardEvaluation(graph: DataflowGraph, rootId: NodeId, processedArguments: readonly (DataflowInformation | undefined)[], which: NseArguments | readonly number[] | undefined, kind?: NseKind): void;
|
|
78
|
-
/**
|
|
79
|
-
* Marks the given arguments as being involved in R's non-standard evaluation.
|
|
78
|
+
* Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}: a {@link NseKind.Quoted|quoted} one
|
|
79
|
+
* entirely, a {@link NseKind.DataMasked|data-masked} one only where {@link Nse.suppliedByMask} holds, and a
|
|
80
|
+
* {@link NseKind.Reevaluated|reevaluated} one as a whole but not within.
|
|
80
81
|
*/
|
|
81
|
-
export declare function
|
|
82
|
+
export declare function markArgumentsAsNonStandardEvaluation(graph: DataflowGraph, rootId: NodeId, processedArguments: readonly (DataflowInformation | undefined)[], which: NseArguments | readonly number[] | undefined, { kind, evaluated }?: NseMarkOptions): void;
|
|
82
83
|
/**
|
|
83
84
|
* The main processor for function calls for which we know the target but need not
|
|
84
85
|
* add any specific handling.
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NseKind = exports.NseArguments = void 0;
|
|
4
4
|
exports.markArgumentsAsNonStandardEvaluation = markArgumentsAsNonStandardEvaluation;
|
|
5
|
-
exports.markNonStandardEvaluationEdges = markNonStandardEvaluationEdges;
|
|
6
5
|
exports.processKnownFunctionCall = processKnownFunctionCall;
|
|
7
6
|
const processor_1 = require("../../../../processor");
|
|
8
7
|
const common_1 = require("./common");
|
|
@@ -13,6 +12,7 @@ const logger_1 = require("../../../../logger");
|
|
|
13
12
|
const vertex_1 = require("../../../../graph/vertex");
|
|
14
13
|
const unknown_side_effect_1 = require("../../../../graph/unknown-side-effect");
|
|
15
14
|
const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
|
|
15
|
+
const nse_1 = require("./nse");
|
|
16
16
|
/**
|
|
17
17
|
* Which arguments of a call {@link markArgumentsAsNonStandardEvaluation|are non-standardly evaluated}:
|
|
18
18
|
* every argument, all but the (data) first one, or only the first one.
|
|
@@ -36,48 +36,50 @@ var NseKind;
|
|
|
36
36
|
NseKind["Quoted"] = "quoted";
|
|
37
37
|
/** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */
|
|
38
38
|
NseKind["DataMasked"] = "data-masked";
|
|
39
|
+
/** evaluated, just not exactly once (a loop body), so only the argument itself is marked */
|
|
40
|
+
NseKind["Reevaluated"] = "reevaluated";
|
|
39
41
|
})(NseKind || (exports.NseKind = NseKind = {}));
|
|
40
42
|
/**
|
|
41
|
-
* Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* names the mask supplies (those that resolve to nothing else) taken from the data, so only those are marked.
|
|
45
|
-
* Besides the {@link NseArguments} shorthands, the positions may be listed explicitly, `undefined` marks nothing.
|
|
43
|
+
* Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}: a {@link NseKind.Quoted|quoted} one
|
|
44
|
+
* entirely, a {@link NseKind.DataMasked|data-masked} one only where {@link Nse.suppliedByMask} holds, and a
|
|
45
|
+
* {@link NseKind.Reevaluated|reevaluated} one as a whole but not within.
|
|
46
46
|
*/
|
|
47
|
-
function markArgumentsAsNonStandardEvaluation(graph, rootId, processedArguments, which, kind = NseKind.Quoted) {
|
|
47
|
+
function markArgumentsAsNonStandardEvaluation(graph, rootId, processedArguments, which, { kind = NseKind.Quoted, evaluated } = {}) {
|
|
48
48
|
if (which === undefined) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
graph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.NonStandardEvaluation);
|
|
59
|
-
}
|
|
60
|
-
for (const [vtx, info] of arg.graph.vertices(true)) {
|
|
61
|
-
/* a masked name the caller does not bind is the one the data supplies */
|
|
62
|
-
if (kind === NseKind.Quoted || (vertex_1.UseVertex.is(info) && !arg.graph.outgoingEdges(vtx)?.values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Reads)))) {
|
|
63
|
-
graph.addEdge(rootId, vtx, edge_1.EdgeType.NonStandardEvaluation);
|
|
51
|
+
if (typeof which !== 'string') {
|
|
52
|
+
for (const i of which) {
|
|
53
|
+
if (i < processedArguments.length) {
|
|
54
|
+
markArgument(graph, rootId, processedArguments[i], kind, evaluated);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
logger_1.dataflowLogger.warn(`Trying to mark argument ${i} as non-standard-evaluation, but only ${processedArguments.length} arguments are available`);
|
|
64
58
|
}
|
|
65
59
|
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const end = which === NseArguments.First ? 1 : processedArguments.length;
|
|
63
|
+
for (let i = which === NseArguments.AllButFirst ? 1 : 0; i < end; i++) {
|
|
64
|
+
markArgument(graph, rootId, processedArguments[i], kind, evaluated);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
function markArgument(graph, rootId, arg, kind, evaluated) {
|
|
68
|
+
if (arg === undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (kind !== NseKind.DataMasked) {
|
|
72
|
+
graph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.NonStandardEvaluation);
|
|
73
|
+
}
|
|
74
|
+
if (kind === NseKind.Reevaluated) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (const [vtx, info] of arg.graph.vertices(true)) {
|
|
78
|
+
if (evaluated?.has(vtx)) {
|
|
79
|
+
continue;
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
if (kind === NseKind.Quoted || nse_1.Nse.suppliedByMask(arg.graph, vtx, info)) {
|
|
82
|
+
graph.addEdge(rootId, vtx, edge_1.EdgeType.NonStandardEvaluation);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
@@ -91,9 +93,7 @@ function processKnownFunctionCall({ name, args, rootId, data, reverseOrder = fal
|
|
|
91
93
|
const functionCallName = name.content;
|
|
92
94
|
const processArgs = reverseOrder ? args.toReversed() : args;
|
|
93
95
|
const { finalEnv, callArgs, remainingReadInArgs, processedArguments } = (0, common_1.processAllArguments)({ functionName, args: processArgs, data, finalGraph, functionRootId: rootId, patchData, forceArgs });
|
|
94
|
-
|
|
95
|
-
markNonStandardEvaluationEdges(markAsNSE, processedArguments, finalGraph, rootId);
|
|
96
|
-
}
|
|
96
|
+
markArgumentsAsNonStandardEvaluation(finalGraph, rootId, processedArguments, markAsNSE, { kind: NseKind.Reevaluated });
|
|
97
97
|
const onlyBuiltin = data.builtInNoEnv === rootId;
|
|
98
98
|
finalGraph.addVertex({
|
|
99
99
|
tag: vertex_1.VertexType.FunctionCall,
|
|
@@ -8,7 +8,7 @@ import type { DataflowGraph } from '../../../../graph/graph';
|
|
|
8
8
|
/**
|
|
9
9
|
* Marks the given function call node as only calling built-in functions.
|
|
10
10
|
*/
|
|
11
|
-
export declare function markAsOnlyBuiltIn(graph: DataflowGraph, rootId: NodeId): void;
|
|
11
|
+
export declare function markAsOnlyBuiltIn(graph: DataflowGraph, rootId: NodeId, keepEnvironment?: boolean): void;
|
|
12
12
|
/**
|
|
13
13
|
* Processes a named function call within the dataflow analysis.
|
|
14
14
|
* For example, `myFunction(arg1, arg2)`, resolves against the environment.
|