@eagleoutice/flowr 2.13.16 → 2.14.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 +36 -25
- package/abstract-interpretation/absint-visitor.js +1 -1
- package/abstract-interpretation/data-frame/mappers/access-mapper.js +4 -4
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -4
- package/abstract-interpretation/data-frame/mappers/function-mapper.js +18 -17
- package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +6 -6
- package/abstract-interpretation/data-frame/resolve-args.d.ts +9 -4
- package/abstract-interpretation/data-frame/resolve-args.js +10 -5
- package/benchmark/calibration.d.ts +16 -7
- package/benchmark/calibration.js +44 -17
- package/benchmark/slicer.d.ts +3 -2
- package/benchmark/slicer.js +9 -5
- package/benchmark/stats/size-of.js +1 -1
- package/benchmark/summarizer/first-phase/process.d.ts +2 -0
- package/benchmark/summarizer/first-phase/process.js +2 -0
- package/cli/benchmark-app.js +4 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +2 -2
- package/cli/common/options.d.ts +5 -31
- package/cli/common/options.js +2 -8
- package/cli/common/scripts-info.d.ts +5 -38
- package/cli/common/scripts-info.js +0 -8
- package/cli/repl/core.js +1 -1
- package/cli/repl/execute.d.ts +2 -2
- package/cli/repl/execute.js +2 -2
- package/cli/repl/parser/slice-query-parser.js +1 -1
- package/cli/repl/print-version.js +2 -2
- package/config.d.ts +16 -0
- package/config.js +83 -5
- package/control-flow/extract-cfg.js +1 -1
- package/control-flow/semantic-cfg-guided-visitor.d.ts +1 -1
- package/control-flow/semantic-cfg-guided-visitor.js +1 -1
- package/control-flow/useless-loop.js +1 -1
- package/core/print/slice-diff-ansi.js +1 -1
- package/core/steps/pipeline/create-pipeline.js +1 -1
- package/dataflow/cluster.js +2 -2
- package/dataflow/environments/apply-kill.js +1 -1
- package/dataflow/environments/built-in-props.d.ts +13 -2
- package/dataflow/environments/built-in-props.js +23 -1
- package/dataflow/environments/built-in.d.ts +7 -1
- package/dataflow/environments/built-in.js +42 -3
- package/dataflow/environments/default-builtin-config.d.ts +518 -11
- package/dataflow/environments/default-builtin-config.js +218 -23
- package/dataflow/environments/environment.d.ts +10 -2
- package/dataflow/environments/environment.js +25 -7
- package/dataflow/environments/identifier.d.ts +8 -2
- package/dataflow/environments/identifier.js +6 -1
- package/dataflow/environments/query-fn-props.d.ts +6 -0
- package/dataflow/environments/query-fn-props.js +22 -2
- package/dataflow/environments/reference-to-maybe.js +5 -5
- package/dataflow/environments/resolve-by-name.d.ts +3 -0
- package/dataflow/environments/resolve-by-name.js +44 -7
- package/dataflow/environments/resolve-helper.d.ts +6 -0
- package/dataflow/environments/resolve-helper.js +6 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +5 -0
- package/dataflow/eval/resolve/alias-tracking.js +21 -14
- package/dataflow/eval/resolve/node-value.d.ts +6 -0
- package/dataflow/eval/resolve/node-value.js +15 -9
- package/dataflow/eval/resolve/resolve-argument.js +2 -2
- package/dataflow/eval/resolve/resolve-numbers.js +2 -2
- package/dataflow/eval/resolve/resolve-operators.js +5 -4
- package/dataflow/eval/resolve/resolve-strings.js +3 -3
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +1 -1
- package/dataflow/eval/resolve/resolve-working-directory.js +3 -3
- package/dataflow/eval/resolve/resolve.d.ts +5 -5
- package/dataflow/eval/resolve/resolve.js +10 -11
- package/dataflow/eval/values/general.d.ts +4 -1
- package/dataflow/eval/values/general.js +1 -1
- package/dataflow/extractor.js +2 -1
- package/dataflow/fn/exceptions-of-function.d.ts +3 -1
- package/dataflow/fn/exceptions-of-function.js +87 -39
- package/dataflow/fn/higher-order-function.js +5 -4
- package/dataflow/fn/strict-function.d.ts +40 -0
- package/dataflow/fn/strict-function.js +337 -0
- package/dataflow/graph/call-graph.js +14 -14
- package/dataflow/graph/df-helper.d.ts +24 -1
- package/dataflow/graph/df-helper.js +29 -7
- package/dataflow/graph/diff-dataflow-graph.js +6 -6
- package/dataflow/graph/edge.d.ts +27 -0
- package/dataflow/graph/edge.js +33 -0
- package/dataflow/graph/graph-helper.d.ts +3 -4
- package/dataflow/graph/graph-helper.js +4 -5
- package/dataflow/graph/graph.d.ts +39 -3
- package/dataflow/graph/graph.js +75 -7
- package/dataflow/graph/vertex.d.ts +42 -6
- package/dataflow/graph/vertex.js +42 -6
- package/dataflow/info.d.ts +26 -0
- package/dataflow/info.js +28 -1
- package/dataflow/internal/linker.d.ts +1 -0
- package/dataflow/internal/linker.js +11 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +6 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +7 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +19 -18
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-list.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +5 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +29 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +44 -20
- package/dataflow/internal/process/functions/call/common.d.ts +9 -1
- package/dataflow/internal/process/functions/call/common.js +17 -6
- package/dataflow/internal/process/functions/call/deferred.js +2 -1
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +3 -1
- package/dataflow/internal/process/functions/call/known-call-handling.js +6 -3
- package/dataflow/internal/process/functions/call/named-call-handling.js +44 -12
- package/dataflow/internal/process/functions/call/nse.d.ts +33 -5
- package/dataflow/internal/process/functions/call/nse.js +113 -6
- package/dataflow/internal/process/functions/call/quoted.d.ts +5 -0
- package/dataflow/internal/process/functions/call/quoted.js +21 -9
- package/dataflow/origin/dfg-get-origin.d.ts +1 -0
- package/dataflow/origin/dfg-get-origin.js +9 -6
- package/documentation/data/faq/faqs.js +88 -88
- package/documentation/data/faq/recommended-configs.js +1 -1
- package/documentation/data/faq/wiki-faq-store.js +1 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-readme.js +1 -1
- package/documentation/doc-util/doc-auto-gen.js +6 -2
- package/documentation/doc-util/doc-functions.js +1 -1
- package/documentation/wiki-cfg.js +2 -2
- package/documentation/wiki-core.js +1 -1
- package/documentation/wiki-create-linting-rules.js +45 -45
- package/documentation/wiki-dataflow-graph.js +18 -18
- package/documentation/wiki-linter.js +1 -0
- package/documentation/wiki-linting-and-testing.js +93 -5
- package/documentation/wiki-mk/doc-maker.js +1 -1
- package/documentation/wiki-overview.js +12 -1
- package/documentation/wiki-query.js +53 -0
- package/documentation/wiki-signature-database.js +3 -0
- package/linter/linter-output.js +1 -1
- package/linter/linter-rules.d.ts +24 -0
- package/linter/linter-rules.js +3 -1
- package/linter/rules/file-path-validity.js +1 -1
- package/linter/rules/function-finder-util.js +1 -1
- package/linter/rules/naming-convention.js +1 -1
- package/linter/rules/network-functions.d.ts +1 -1
- package/linter/rules/no-leaked-credentials.js +2 -1
- package/linter/rules/stop-with-call-arg.js +4 -4
- package/linter/rules/unclosed-connection.d.ts +44 -0
- package/linter/rules/unclosed-connection.js +200 -0
- package/linter/rules/undefined-symbol-util.d.ts +1 -1
- package/linter/rules/undefined-symbol-util.js +5 -4
- package/linter/rules/undefined-symbol.js +3 -3
- package/linter/rules/unused-definition.js +2 -1
- package/package.json +38 -51
- package/project/context/flowr-analyzer-environment-context.d.ts +23 -0
- package/project/context/flowr-analyzer-environment-context.js +25 -0
- package/project/dependency-version-space.d.ts +3 -3
- package/project/dependency-version-space.js +3 -4
- package/project/flowr-analyzer.js +1 -1
- package/project/plugins/file-plugins/files/flowr-description-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-description-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-news-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.js +4 -4
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +5 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +36 -7
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/build.js +16 -16
- package/project/sigdb/codec.d.ts +1 -1
- package/project/sigdb/codec.js +13 -13
- package/project/sigdb/decompress.d.ts +1 -1
- package/project/sigdb/decompress.js +33 -33
- package/project/sigdb/index-format.js +2 -2
- package/project/sigdb/manifest.d.ts +3 -1
- package/project/sigdb/manifest.js +68 -27
- package/project/sigdb/memory-source.d.ts +64 -0
- package/project/sigdb/memory-source.js +133 -0
- package/project/sigdb/reader.js +14 -14
- package/project/sigdb/schema.d.ts +2 -2
- package/project/sigdb/schema.js +2 -2
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -1
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +2 -2
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
- package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
- package/queries/catalog/dependencies-query/link-devices.js +3 -9
- package/queries/catalog/does-call-query/does-call-query-executor.js +2 -1
- package/queries/catalog/input-sources-query/simple-input-classifier.js +4 -4
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -1
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +6 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +25 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +31 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +56 -0
- package/queries/catalog/location-map-query/location-map-query-format.js +1 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +2 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -0
- package/queries/catalog/signature-query/signature-query-executor.js +3 -2
- package/queries/catalog/slice-query-options.d.ts +1 -1
- package/queries/catalog/slice-query-options.js +1 -1
- package/queries/query-function-filter.d.ts +8 -2
- package/queries/query-function-filter.js +11 -1
- package/queries/query.d.ts +11 -1
- package/queries/query.js +2 -0
- package/r-bridge/lang-4.x/ast/model/model.d.ts +4 -4
- package/r-bridge/lang-4.x/ast/model/model.js +4 -4
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +3 -3
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +1 -1
- package/r-bridge/retriever.d.ts +2 -1
- package/r-bridge/retriever.js +3 -2
- package/r-bridge/roxygen2/documentation-provider.d.ts +1 -0
- package/r-bridge/roxygen2/documentation-provider.js +1 -0
- package/r-bridge/roxygen2/roxygen-parse.d.ts +1 -1
- package/r-bridge/roxygen2/roxygen-parse.js +1 -1
- package/search/flowr-search-filters.d.ts +1 -1
- package/search/flowr-search-filters.js +2 -14
- package/search/search-executor/search-enrichers.js +4 -4
- package/search/search-executor/search-generators.js +1 -1
- package/slicing/criterion/parse.d.ts +2 -2
- package/slicing/criterion/parse.js +5 -5
- package/slicing/static/fingerprint.js +1 -1
- package/slicing/static/slice-call.d.ts +1 -1
- package/slicing/static/slice-call.js +2 -2
- package/slicing/static/static-slicer.js +4 -3
- package/util/assert.js +1 -1
- package/util/log.d.ts +4 -1
- package/util/log.js +15 -2
- package/util/logic.js +2 -2
- package/util/mermaid/cfg.js +1 -1
- package/util/mermaid/dfg.js +6 -6
- package/util/mermaid/mermaid.js +3 -1
- package/util/objects.d.ts +12 -0
- package/util/objects.js +48 -0
- package/util/quads.js +19 -6
- package/util/schema.js +2 -2
- package/util/simple-df/dfg-ascii.js +14 -3
- package/util/text/ansi.d.ts +2 -0
- package/util/text/ansi.js +8 -0
- package/util/text/name-rank.d.ts +29 -0
- package/util/text/name-rank.js +39 -0
- package/util/text/url-encoding.d.ts +15 -0
- package/util/text/url-encoding.js +59 -0
- package/util/version.js +1 -1
- package/cli/export-quads-app.d.ts +0 -7
- package/cli/export-quads-app.js +0 -44
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strictnessOfFunction = strictnessOfFunction;
|
|
4
|
+
exports.strictnessOfFunctions = strictnessOfFunctions;
|
|
5
|
+
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
6
|
+
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
7
|
+
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
8
|
+
const graph_1 = require("../graph/graph");
|
|
9
|
+
const edge_1 = require("../graph/edge");
|
|
10
|
+
const vertex_1 = require("../graph/vertex");
|
|
11
|
+
const built_in_proc_name_1 = require("../environments/built-in-proc-name");
|
|
12
|
+
const built_in_props_1 = require("../environments/built-in-props");
|
|
13
|
+
const query_fn_props_1 = require("../environments/query-fn-props");
|
|
14
|
+
const identifier_1 = require("../environments/identifier");
|
|
15
|
+
const logic_1 = require("../../util/logic");
|
|
16
|
+
/**
|
|
17
|
+
* What an argument is used for when the call never evaluates it: quoted or read in another frame
|
|
18
|
+
* ({@link ArgProp.Nse}), or looked at only for having been supplied ({@link ArgProp.Presence}).
|
|
19
|
+
*/
|
|
20
|
+
const NotEvaluated = built_in_props_1.ArgProp.Nse | built_in_props_1.ArgProp.Presence;
|
|
21
|
+
/**
|
|
22
|
+
* The processors whose calls reach their first argument and the rest only on the way the run happens to
|
|
23
|
+
* take: `switch` picks one of its branches, and `try`/`tryCatch` reach a handler only when one is needed.
|
|
24
|
+
*/
|
|
25
|
+
const LazyAfterFirst = [built_in_proc_name_1.BuiltInProcName.Switch, built_in_proc_name_1.BuiltInProcName.Try];
|
|
26
|
+
/**
|
|
27
|
+
* The processors putting off what they are given until a moment that may never come: a hook runs when the
|
|
28
|
+
* function exits, and `Recall` starts the same function over rather than reading anything itself.
|
|
29
|
+
*/
|
|
30
|
+
const LazyThroughout = [built_in_proc_name_1.BuiltInProcName.RegisterHook, built_in_proc_name_1.BuiltInProcName.Recall];
|
|
31
|
+
/** The processors dispatching to a method chosen at run time. */
|
|
32
|
+
const DispatchProcessors = [
|
|
33
|
+
built_in_proc_name_1.BuiltInProcName.S3Dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext, built_in_proc_name_1.BuiltInProcName.S7Dispatch
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Whether the call hands the work to a method chosen at run time: flowR's own dispatch processors say so for
|
|
37
|
+
* `UseMethod` and `NextMethod`, and {@link DispatchCallees} covers the ones it has no processor for.
|
|
38
|
+
*/
|
|
39
|
+
function isDispatch(vertex) {
|
|
40
|
+
return hasProcessor(vertex, DispatchProcessors) || built_in_props_1.DispatchCallees.has(identifier_1.Identifier.getName(vertex.name));
|
|
41
|
+
}
|
|
42
|
+
/** Whether the call belongs to one of the given processors. */
|
|
43
|
+
function hasProcessor(vertex, of) {
|
|
44
|
+
return vertex.origin !== 'unnamed' && of.some(p => vertex.origin.includes(p));
|
|
45
|
+
}
|
|
46
|
+
/** The definition a node sits in. */
|
|
47
|
+
function enclosingDefinition(id, idMap, graph) {
|
|
48
|
+
let node = idMap.get(id);
|
|
49
|
+
while (node !== undefined) {
|
|
50
|
+
if (vertex_1.FunctionDefinitionVertex.is(graph.getVertex(node.info.id))) {
|
|
51
|
+
return node.info.id;
|
|
52
|
+
}
|
|
53
|
+
node = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function makeState(graph, ctx) {
|
|
58
|
+
const idMap = graph.idMap;
|
|
59
|
+
const owner = new Map();
|
|
60
|
+
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
61
|
+
for (const param of Object.keys(vertex.params)) {
|
|
62
|
+
owner.set(node_id_1.NodeId.normalize(param), id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const dispatch = new Map();
|
|
66
|
+
if (idMap !== undefined) {
|
|
67
|
+
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
68
|
+
if (!isDispatch(vertex) || typeof node_id_1.NodeId.normalize(id) !== 'number') {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const within = enclosingDefinition(id, idMap, graph);
|
|
72
|
+
if (within === undefined) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const node = idMap.get(id);
|
|
76
|
+
const known = dispatch.get(within);
|
|
77
|
+
const named = (node?.type === type_1.RType.FunctionCall && (node.arguments?.length ?? 0) > 1) || (known?.named ?? false);
|
|
78
|
+
const certain = !underCondition(vertex.cds, graph.getVertex(within)?.cds) || (known?.certain ?? false);
|
|
79
|
+
const next = [...known?.next ?? []];
|
|
80
|
+
for (const [target, edge] of graph.outgoingEdges(id) ?? graph_1.NoEdges) {
|
|
81
|
+
if (target !== within && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.FunctionDefinitionVertex.is(graph.getVertex(target))) {
|
|
82
|
+
next.push(target);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
dispatch.set(within, { named, certain, next });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const environment = ctx?.env.makeCleanEnv();
|
|
89
|
+
const props = environment === undefined
|
|
90
|
+
? (name) => query_fn_props_1.BuiltInIndex.default().get(name)?.sig
|
|
91
|
+
: (name) => (0, query_fn_props_1.queryFnProps)(name, { environment })?.sig;
|
|
92
|
+
return { graph, idMap, owner, dispatch, sigs: new Map(), props, known: new Map(), asking: new Set(), assumed: false };
|
|
93
|
+
}
|
|
94
|
+
/** What is certain becomes a possibility once something may intervene. */
|
|
95
|
+
function weaken(value) {
|
|
96
|
+
return value === logic_1.Ternary.Always ? logic_1.Ternary.Maybe : value;
|
|
97
|
+
}
|
|
98
|
+
/** What several answers amount to when only one applies and nothing says which. */
|
|
99
|
+
function agree(values) {
|
|
100
|
+
if (values.length === 0) {
|
|
101
|
+
return logic_1.Ternary.Never;
|
|
102
|
+
}
|
|
103
|
+
return values.every(v => v === values[0]) ? values[0] : logic_1.Ternary.Maybe;
|
|
104
|
+
}
|
|
105
|
+
/** Whether the control dependencies exceed the ones the definition itself stands under. */
|
|
106
|
+
function underCondition(cds, definition) {
|
|
107
|
+
return cds?.some(c => !definition?.some(d => d.id === c.id && d.when === c.when)) ?? false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Built-ins force what they are given, and the ones that do not (`quote` and its relatives) leave no read of
|
|
111
|
+
* the argument in the graph in the first place, so there is nothing to hold back here. A call of something
|
|
112
|
+
* the code worked out for itself (`obj$method(...)`) is none of them, whichever way it was written.
|
|
113
|
+
*/
|
|
114
|
+
function isBuiltInCall(vertex) {
|
|
115
|
+
return vertex.origin !== 'unnamed'
|
|
116
|
+
&& !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Function)
|
|
117
|
+
&& !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Unnamed);
|
|
118
|
+
}
|
|
119
|
+
/** The node whose value an argument stands for, carrying the link to the parameter it binds to. */
|
|
120
|
+
function argumentValue(id, idMap) {
|
|
121
|
+
const node = idMap.get(id);
|
|
122
|
+
return node?.type === type_1.RType.Argument ? node.value?.info.id ?? id : id;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Where the given node stands in the call's arguments. The graph names an argument by the value it wraps,
|
|
126
|
+
* while the walk arrives at the argument itself, so both count as a hit; `-1` when neither does, which a
|
|
127
|
+
* call whose arguments flowR rewrote (`on.exit` and the other deferred ones) is enough to bring about.
|
|
128
|
+
*/
|
|
129
|
+
function argumentIndex(call, child, idMap) {
|
|
130
|
+
const value = argumentValue(child, idMap);
|
|
131
|
+
return call.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && (arg.nodeId === child || arg.nodeId === value));
|
|
132
|
+
}
|
|
133
|
+
/** Whether the node is the function a call is of rather than something handed to it. */
|
|
134
|
+
function isCallee(call, child, idMap) {
|
|
135
|
+
const node = idMap.get(call);
|
|
136
|
+
if (!r_function_call_1.RFunctionCall.is(node)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return (r_function_call_1.RFunctionCall.isNamed(node) ? node.functionName.info.id : node.calledFunction.info.id) === child;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* What flowR states the argument at `index` of the call is used for. A `...` covers every position from
|
|
143
|
+
* where it is declared, which {@link FnSig.propAt} takes care of.
|
|
144
|
+
*/
|
|
145
|
+
function argProps(vertex, index, state) {
|
|
146
|
+
const name = identifier_1.Identifier.getName(vertex.name);
|
|
147
|
+
let sig = state.sigs.get(name);
|
|
148
|
+
if (sig === undefined && !state.sigs.has(name)) {
|
|
149
|
+
state.sigs.set(name, sig = state.props(vertex.name));
|
|
150
|
+
}
|
|
151
|
+
return sig === undefined || index < 0 ? 0 : built_in_props_1.FnSig.propAt(built_in_props_1.FnSig.layout(sig), index);
|
|
152
|
+
}
|
|
153
|
+
/** The verdict a callee's parameter carries over to what is handed to it. */
|
|
154
|
+
function handedTo(param, state) {
|
|
155
|
+
const owner = state.owner.get(param);
|
|
156
|
+
return owner === undefined ? logic_1.Ternary.Maybe : strictnessOf(owner, state).parameters[param] ?? logic_1.Ternary.Maybe;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether handing `argument` to `call` forces it. An argument the call passes on is forced exactly as the
|
|
160
|
+
* function receiving it forces the parameter it binds to; a call flowR cannot resolve, and one whose argument
|
|
161
|
+
* it cannot match to a parameter, leave the question open.
|
|
162
|
+
*/
|
|
163
|
+
function forcedByCallee(call, argument, idMap, state) {
|
|
164
|
+
const resolved = [...state.graph.outgoingEdges(call.id) ?? graph_1.NoEdges]
|
|
165
|
+
.some(([target, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.FunctionDefinitionVertex.is(state.graph.getVertex(target)));
|
|
166
|
+
if (!resolved) {
|
|
167
|
+
return logic_1.Ternary.Maybe;
|
|
168
|
+
}
|
|
169
|
+
const bound = [];
|
|
170
|
+
for (const from of new Set([argument, argumentValue(argument, idMap)])) {
|
|
171
|
+
for (const [target, edge] of state.graph.outgoingEdges(from) ?? graph_1.NoEdges) {
|
|
172
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinesOnCall)) {
|
|
173
|
+
bound.push(handedTo(target, state));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return bound.length === 0 ? logic_1.Ternary.Maybe : agree(bound);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* How far the given read of a parameter is unavoidable: it has to stand under no condition the definition
|
|
181
|
+
* does not already stand under, must not sit in a function or a default of its own that may never be
|
|
182
|
+
* reached, and must not merely be handed to something that leaves it alone.
|
|
183
|
+
*/
|
|
184
|
+
function forces(read, definition, state) {
|
|
185
|
+
const idMap = state.idMap;
|
|
186
|
+
if (idMap === undefined) {
|
|
187
|
+
return logic_1.Ternary.Maybe;
|
|
188
|
+
}
|
|
189
|
+
let certain = true;
|
|
190
|
+
let child = read;
|
|
191
|
+
let node = idMap.get(read);
|
|
192
|
+
while (node !== undefined && node.info.id !== definition.id) {
|
|
193
|
+
const vertex = state.graph.getVertex(node.info.id);
|
|
194
|
+
if (underCondition(vertex?.cds, definition.cds)) {
|
|
195
|
+
certain = false;
|
|
196
|
+
}
|
|
197
|
+
if (node.info.id !== read) {
|
|
198
|
+
if (vertex_1.FunctionDefinitionVertex.is(vertex)) {
|
|
199
|
+
/* nothing says the nested definition is ever called */
|
|
200
|
+
certain = false;
|
|
201
|
+
}
|
|
202
|
+
else if (node.type === type_1.RType.Parameter) {
|
|
203
|
+
/* a default is evaluated only when the argument is left out */
|
|
204
|
+
certain = false;
|
|
205
|
+
}
|
|
206
|
+
else if (vertex_1.FunctionCallVertex.is(vertex) && !isDispatch(vertex) && !isCallee(node.info.id, child, idMap)) {
|
|
207
|
+
if (!isBuiltInCall(vertex)) {
|
|
208
|
+
const handed = forcedByCallee(vertex, child, idMap, state);
|
|
209
|
+
return certain ? handed : weaken(handed);
|
|
210
|
+
}
|
|
211
|
+
const index = argumentIndex(vertex, child, idMap);
|
|
212
|
+
const props = argProps(vertex, index, state);
|
|
213
|
+
if ((props & NotEvaluated) !== 0) {
|
|
214
|
+
return logic_1.Ternary.Never;
|
|
215
|
+
}
|
|
216
|
+
else if ((props & built_in_props_1.ArgProp.Forced) === 0
|
|
217
|
+
&& (hasProcessor(vertex, LazyThroughout) || (index !== 0 && hasProcessor(vertex, LazyAfterFirst)))) {
|
|
218
|
+
certain = false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
child = node.info.id;
|
|
223
|
+
node = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
|
|
224
|
+
}
|
|
225
|
+
if (node === undefined) {
|
|
226
|
+
return logic_1.Ternary.Never;
|
|
227
|
+
}
|
|
228
|
+
return certain ? logic_1.Ternary.Always : logic_1.Ternary.Maybe;
|
|
229
|
+
}
|
|
230
|
+
function strictnessOfParameter(param, definition, state) {
|
|
231
|
+
const reads = [];
|
|
232
|
+
for (const [read, edge] of state.graph.ingoingEdges(param) ?? graph_1.NoEdges) {
|
|
233
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
|
|
234
|
+
reads.push(forces(read, definition, state));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const dispatch = state.dispatch.get(definition.id);
|
|
238
|
+
if (dispatch !== undefined) {
|
|
239
|
+
const methods = [];
|
|
240
|
+
for (const [target, edge] of state.graph.outgoingEdges(param) ?? graph_1.NoEdges) {
|
|
241
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinesOnCall)) {
|
|
242
|
+
methods.push(handedTo(target, state));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
reads.push(dispatch.certain ? agree(methods) : weaken(agree(methods)));
|
|
246
|
+
if (dispatch.next.length > 0) {
|
|
247
|
+
const at = parameterIds(definition.id, state.idMap).indexOf(param);
|
|
248
|
+
const along = at < 0 ? [] : dispatch.next.map(method => {
|
|
249
|
+
const same = parameterIds(method, state.idMap)[at];
|
|
250
|
+
return same === undefined ? logic_1.Ternary.Maybe : strictnessOf(method, state).parameters[same] ?? logic_1.Ternary.Maybe;
|
|
251
|
+
});
|
|
252
|
+
reads.push(dispatch.certain ? agree(along) : weaken(agree(along)));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return logic_1.TernaryLogic.or(...reads);
|
|
256
|
+
}
|
|
257
|
+
/** The parameters of a definition in the order they are written. */
|
|
258
|
+
function parameterIds(definition, idMap) {
|
|
259
|
+
const node = idMap?.get(definition);
|
|
260
|
+
return node?.type === type_1.RType.FunctionDefinition ? node.parameters.map(p => p.name.info.id) : [];
|
|
261
|
+
}
|
|
262
|
+
function strictnessOf(id, state) {
|
|
263
|
+
const known = state.known.get(id);
|
|
264
|
+
if (known !== undefined) {
|
|
265
|
+
return known;
|
|
266
|
+
}
|
|
267
|
+
const vertex = state.graph.getVertex(id);
|
|
268
|
+
if (!vertex_1.FunctionDefinitionVertex.is(vertex)) {
|
|
269
|
+
return { strict: logic_1.Ternary.Never, parameters: {} };
|
|
270
|
+
}
|
|
271
|
+
const params = Object.keys(vertex.params);
|
|
272
|
+
if (state.asking.has(id)) {
|
|
273
|
+
/* the answer is the one still being worked out */
|
|
274
|
+
state.assumed = true;
|
|
275
|
+
return { strict: logic_1.Ternary.Maybe, parameters: Object.fromEntries(params.map(param => [param, logic_1.Ternary.Maybe])) };
|
|
276
|
+
}
|
|
277
|
+
state.asking.add(id);
|
|
278
|
+
const parameters = {};
|
|
279
|
+
for (const param of params) {
|
|
280
|
+
parameters[param] = strictnessOfParameter(node_id_1.NodeId.normalize(param), vertex, state);
|
|
281
|
+
}
|
|
282
|
+
const dispatch = state.dispatch.get(id);
|
|
283
|
+
if (dispatch !== undefined) {
|
|
284
|
+
for (const param of params) {
|
|
285
|
+
parameters[param] = logic_1.TernaryLogic.or(parameters[param], logic_1.Ternary.Maybe);
|
|
286
|
+
}
|
|
287
|
+
const object = dispatch.named ? undefined : parameterIds(id, state.idMap)[0];
|
|
288
|
+
if (object !== undefined && parameters[object] !== undefined) {
|
|
289
|
+
parameters[object] = dispatch.certain ? logic_1.Ternary.Always : logic_1.TernaryLogic.or(parameters[object], logic_1.Ternary.Maybe);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
state.asking.delete(id);
|
|
293
|
+
const result = { strict: logic_1.TernaryLogic.and(...Object.values(parameters)), parameters };
|
|
294
|
+
if (!state.assumed) {
|
|
295
|
+
state.known.set(id, result);
|
|
296
|
+
}
|
|
297
|
+
else if (state.asking.size === 0) {
|
|
298
|
+
state.assumed = false;
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Determines whether the function with the given id is strict, i.e., whether calling it forces its arguments.
|
|
304
|
+
* {@link Ternary#Always} says every call forces every parameter, {@link Ternary#Never} that no call forces
|
|
305
|
+
* all of them, and {@link Ternary#Maybe} that it depends on the path taken, on the caller, or on a function
|
|
306
|
+
* flowR could not resolve. A definition without parameters has nothing to leave unforced and is strict.
|
|
307
|
+
*
|
|
308
|
+
* The analysis follows an argument that is handed on into the function receiving it, and treats a read in a
|
|
309
|
+
* default, in a loop, in a branch, or in a nested definition as one that may not happen. What a built-in
|
|
310
|
+
* does with an argument is not guessed from its name: an argument stated {@link ArgProp.Nse} or
|
|
311
|
+
* {@link ArgProp.Presence} is never evaluated, one stated {@link ArgProp.Forced} always is, and the calls
|
|
312
|
+
* reaching an argument only on the way the run takes are the ones flowR hands to the processor that says so
|
|
313
|
+
* (`switch` picking a branch, `try` reaching a handler, a hook running at exit).
|
|
314
|
+
* For a generic, the methods reached by S3 dispatch decide: they agree on a parameter or it is left open,
|
|
315
|
+
* while the object the dispatch is on is forced by the dispatch itself. A `NextMethod` carries the same
|
|
316
|
+
* question on to the methods it reaches, matched by the position the parameter is written in.
|
|
317
|
+
* An argument in `...` is followed to the parameter it binds to, whereas the method of an object flowR
|
|
318
|
+
* cannot resolve (`obj$m(x)`) is one more thing it cannot claim anything about.
|
|
319
|
+
* Cyclic dependencies between functions and calls flowR cannot resolve answer {@link Ternary#Maybe}, so this
|
|
320
|
+
* only claims certainty where the code gives it.
|
|
321
|
+
* What a built-in does with an argument comes from the {@link ArgProp} bits its signature states, so a
|
|
322
|
+
* configured or overwritten built-in is the one that answers when the analyzer context is handed along.
|
|
323
|
+
* @see {@link strictnessOfFunctions} - to ask about several definitions at once, sharing the work
|
|
324
|
+
*/
|
|
325
|
+
function strictnessOfFunction(id, graph, ctx) {
|
|
326
|
+
return strictnessOf(id, makeState(graph, ctx));
|
|
327
|
+
}
|
|
328
|
+
/** The {@link strictnessOfFunction|strictness} of several definitions, sharing the work between them. */
|
|
329
|
+
function strictnessOfFunctions(ids, graph, ctx) {
|
|
330
|
+
const state = makeState(graph, ctx);
|
|
331
|
+
const result = {};
|
|
332
|
+
for (const id of ids) {
|
|
333
|
+
result[id] = strictnessOf(id, state);
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=strict-function.js.map
|
|
@@ -43,7 +43,7 @@ function fallbackUntargetedCall(vtx, graph) {
|
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
let addedNew = false;
|
|
46
|
-
for (const [tar, e] of graph.outgoingEdges(currentId) ??
|
|
46
|
+
for (const [tar, e] of graph.outgoingEdges(currentId) ?? graph_1.NoEdges) {
|
|
47
47
|
if (edge_1.DfEdge.includesType(e, UntargetedCallFollow) && edge_1.DfEdge.doesNotIncludeType(e, UntargetedCallAvoid)) {
|
|
48
48
|
addedNew = true;
|
|
49
49
|
toVisit.push(tar);
|
|
@@ -79,7 +79,7 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
81
|
const targetVtx = graph.getVertex(tar);
|
|
82
|
-
if (
|
|
82
|
+
if (!vertex_1.FunctionDefinitionVertex.is(targetVtx)) {
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
addedTarget = true;
|
|
@@ -89,7 +89,7 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
89
89
|
for (const origs of vtx.origin) {
|
|
90
90
|
if (origs.startsWith('builtin:')) {
|
|
91
91
|
addedTarget = true;
|
|
92
|
-
result.addEdge(vid, node_id_1.NodeId.toBuiltIn(origs.
|
|
92
|
+
result.addEdge(vid, node_id_1.NodeId.toBuiltIn(origs.slice('builtin:'.length)), edge_1.EdgeType.Calls);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -102,7 +102,7 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
102
102
|
}
|
|
103
103
|
result.addEdge(vid, ori, edge_1.EdgeType.Calls);
|
|
104
104
|
const name = graph.idMap?.get(ori);
|
|
105
|
-
if (name?.lexeme &&
|
|
105
|
+
if (name?.lexeme && vertex_1.UseVertex.is(oriVtx)) {
|
|
106
106
|
result.addVertex({
|
|
107
107
|
...oriVtx,
|
|
108
108
|
tag: vertex_1.VertexType.FunctionCall,
|
|
@@ -115,7 +115,7 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
// handle arguments, traversing the 'reads' and the 'returns' edges
|
|
118
|
-
for (const [tar, e] of graph.outgoingEdges(vtx.id) ??
|
|
118
|
+
for (const [tar, e] of graph.outgoingEdges(vtx.id) ?? graph_1.NoEdges) {
|
|
119
119
|
if (edge_1.DfEdge.doesNotIncludeType(e, edge_1.EdgeType.Reads | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument)) {
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
@@ -168,7 +168,7 @@ function followCalls(graph, seeds, reached) {
|
|
|
168
168
|
continue;
|
|
169
169
|
}
|
|
170
170
|
reached.add(current);
|
|
171
|
-
for (const [target, edge] of graph.outgoingEdges(current) ??
|
|
171
|
+
for (const [target, edge] of graph.outgoingEdges(current) ?? graph_1.NoEdges) {
|
|
172
172
|
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
|
|
173
173
|
toVisit.push(target);
|
|
174
174
|
}
|
|
@@ -180,7 +180,7 @@ function reachedCallNames(graph, reached) {
|
|
|
180
180
|
const names = new Set();
|
|
181
181
|
for (const id of reached) {
|
|
182
182
|
const vertex = graph.getVertex(id);
|
|
183
|
-
if (
|
|
183
|
+
if (vertex_1.FunctionCallVertex.is(vertex)) {
|
|
184
184
|
names.add(identifier_1.Identifier.getName(vertex.name));
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -207,7 +207,7 @@ function mayRunAnyway(graph, reached) {
|
|
|
207
207
|
const seeds = [];
|
|
208
208
|
let generics;
|
|
209
209
|
for (const [id, vertex] of graph.vertices(true)) {
|
|
210
|
-
if (
|
|
210
|
+
if (!vertex_1.FunctionDefinitionVertex.is(vertex) || reached.has(id)) {
|
|
211
211
|
continue;
|
|
212
212
|
}
|
|
213
213
|
const node = idMap.get(id);
|
|
@@ -253,7 +253,7 @@ exports.CallGraph = {
|
|
|
253
253
|
continue;
|
|
254
254
|
}
|
|
255
255
|
result.addVertex(currentVtx, undefined, true);
|
|
256
|
-
for (const [tar, e] of graph.outgoingEdges(currentId) ??
|
|
256
|
+
for (const [tar, e] of graph.outgoingEdges(currentId) ?? graph_1.NoEdges) {
|
|
257
257
|
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls)) {
|
|
258
258
|
result.addEdge(currentId, tar, edge_1.EdgeType.Calls);
|
|
259
259
|
toVisit.push(tar);
|
|
@@ -270,7 +270,7 @@ exports.CallGraph = {
|
|
|
270
270
|
return entries;
|
|
271
271
|
}
|
|
272
272
|
for (const [id, vertex] of graph.vertices(true)) {
|
|
273
|
-
const node =
|
|
273
|
+
const node = vertex_1.FunctionCallVertex.is(vertex) ? idMap.get(id) : undefined;
|
|
274
274
|
if (node !== undefined && r_function_definition_1.RFunctionDefinition.wrappingFunctionDefinition(node, idMap) === undefined) {
|
|
275
275
|
entries.add(id);
|
|
276
276
|
}
|
|
@@ -288,7 +288,7 @@ exports.CallGraph = {
|
|
|
288
288
|
followCalls(graph, seeds, reached);
|
|
289
289
|
}
|
|
290
290
|
return graph.vertices(true)
|
|
291
|
-
.filter(([id, vertex]) =>
|
|
291
|
+
.filter(([id, vertex]) => vertex_1.FunctionCallVertex.is(vertex) && !reached.has(id))
|
|
292
292
|
.map(([id]) => id)
|
|
293
293
|
.toArray();
|
|
294
294
|
},
|
|
@@ -322,10 +322,10 @@ exports.CallGraph = {
|
|
|
322
322
|
potentials: []
|
|
323
323
|
};
|
|
324
324
|
for (const [, vert] of graph.vertices(false)) {
|
|
325
|
-
if (
|
|
325
|
+
if (vertex_1.FunctionCallVertex.is(vert)) {
|
|
326
326
|
processCall(vert, undefined, graph, result, state);
|
|
327
327
|
}
|
|
328
|
-
else if (
|
|
328
|
+
else if (vertex_1.FunctionDefinitionVertex.is(vert)) {
|
|
329
329
|
processFunctionDefinition(vert, undefined, graph, result, state);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
@@ -335,7 +335,7 @@ exports.CallGraph = {
|
|
|
335
335
|
const v = graph.getVertex(to);
|
|
336
336
|
if (v) {
|
|
337
337
|
processUnknown(v, from, graph, result, state);
|
|
338
|
-
if (
|
|
338
|
+
if (vertex_1.FunctionDefinitionVertex.is(v)) {
|
|
339
339
|
processFunctionDefinition(v, from, graph, result, state);
|
|
340
340
|
}
|
|
341
341
|
}
|
|
@@ -14,10 +14,17 @@ import { Identifier } from '../environments/identifier';
|
|
|
14
14
|
* - {@link Dataflow.visualize} - for visualization helpers (e.g., rendering the DFG as a mermaid graph),
|
|
15
15
|
* - {@link Dataflow.views} - for working with specific views of the dataflow graph (e.g., the call graph),
|
|
16
16
|
* - {@link Dataflow.edge} - for working with the edges in the dataflow graph,
|
|
17
|
-
* - {@link Dataflow.qualify} - for the package-qualified `pkg::fn` identifier of a call
|
|
17
|
+
* - {@link Dataflow.qualify}/{@link Dataflow.qualifyAll} - for the package-qualified `pkg::fn` identifier of a call
|
|
18
|
+
* from its id and graph, or of every call of a graph at once,
|
|
18
19
|
* - {@link Dataflow.resolve} - for resolving a name against an environment,
|
|
19
20
|
* - {@link Dataflow.packagesOf} - for the packages a set of nodes (e.g. a slice) calls into,
|
|
20
21
|
* - {@link Dataflow.valueIsUsed}/{@link Dataflow.hasComputedArguments} - for what a call does with, and gets as, values,
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* Dataflow.origin(graph, id); // where the use at `id` comes from
|
|
25
|
+
* Dataflow.edge.includesType(edge, EdgeType.Reads); // the edge helpers
|
|
26
|
+
* Dataflow.visualize.mermaid.url(graph); // a link to the rendered graph
|
|
27
|
+
* ```
|
|
21
28
|
*/
|
|
22
29
|
export declare const Dataflow: {
|
|
23
30
|
readonly name: "Dataflow";
|
|
@@ -39,6 +46,15 @@ export declare const Dataflow: {
|
|
|
39
46
|
readonly doesNotIncludeType: (this: void, { types }: {
|
|
40
47
|
types: number;
|
|
41
48
|
}, any: EdgeType) => boolean;
|
|
49
|
+
readonly hasAnyType: (this: void, { types }: {
|
|
50
|
+
types: number;
|
|
51
|
+
}) => boolean;
|
|
52
|
+
readonly hasNoType: (this: void, { types }: {
|
|
53
|
+
types: number;
|
|
54
|
+
}) => boolean;
|
|
55
|
+
readonly isOnlyType: (this: void, { types }: {
|
|
56
|
+
types: number;
|
|
57
|
+
}, only: EdgeType) => boolean;
|
|
42
58
|
};
|
|
43
59
|
/**
|
|
44
60
|
* Dispatches to helper objects that relate to (sub-) views of the dataflow graph, e.g. the call graph.
|
|
@@ -124,6 +140,13 @@ export declare const Dataflow: {
|
|
|
124
140
|
* Set this to `false` to only qualify what the origins resolve to (or what is already namespaced).
|
|
125
141
|
*/
|
|
126
142
|
readonly qualify: (this: void, id: NodeId, graph: DataflowGraph, qualifyBaseR?: boolean) => Identifier | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* The qualified name of every call of the graph, `undefined` for the calls that do not qualify.
|
|
145
|
+
* Prefer this over asking call by call: it resolves each call once for both `qualifyBaseR` variants.
|
|
146
|
+
* @param graph - The graph to qualify
|
|
147
|
+
* @param qualifyBaseR - Which of the two results to return, see {@link Dataflow.qualify}
|
|
148
|
+
*/
|
|
149
|
+
readonly qualifyAll: (this: void, graph: DataflowGraph, qualifyBaseR?: boolean) => ReadonlyMap<NodeId, Identifier | undefined>;
|
|
127
150
|
/**
|
|
128
151
|
* The packages the given nodes call into, as {@link Dataflow.qualify} resolves every call among them.
|
|
129
152
|
* This is what a selection needs, which is not what the program loads: a `library()` whose exports the
|
|
@@ -20,10 +20,17 @@ const r_base_packages_1 = require("../../util/r-base-packages");
|
|
|
20
20
|
* - {@link Dataflow.visualize} - for visualization helpers (e.g., rendering the DFG as a mermaid graph),
|
|
21
21
|
* - {@link Dataflow.views} - for working with specific views of the dataflow graph (e.g., the call graph),
|
|
22
22
|
* - {@link Dataflow.edge} - for working with the edges in the dataflow graph,
|
|
23
|
-
* - {@link Dataflow.qualify} - for the package-qualified `pkg::fn` identifier of a call
|
|
23
|
+
* - {@link Dataflow.qualify}/{@link Dataflow.qualifyAll} - for the package-qualified `pkg::fn` identifier of a call
|
|
24
|
+
* from its id and graph, or of every call of a graph at once,
|
|
24
25
|
* - {@link Dataflow.resolve} - for resolving a name against an environment,
|
|
25
26
|
* - {@link Dataflow.packagesOf} - for the packages a set of nodes (e.g. a slice) calls into,
|
|
26
27
|
* - {@link Dataflow.valueIsUsed}/{@link Dataflow.hasComputedArguments} - for what a call does with, and gets as, values,
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* Dataflow.origin(graph, id); // where the use at `id` comes from
|
|
31
|
+
* Dataflow.edge.includesType(edge, EdgeType.Reads); // the edge helpers
|
|
32
|
+
* Dataflow.visualize.mermaid.url(graph); // a link to the rendered graph
|
|
33
|
+
* ```
|
|
27
34
|
*/
|
|
28
35
|
exports.Dataflow = {
|
|
29
36
|
/**
|
|
@@ -80,8 +87,16 @@ exports.Dataflow = {
|
|
|
80
87
|
* Set this to `false` to only qualify what the origins resolve to (or what is already namespaced).
|
|
81
88
|
*/
|
|
82
89
|
qualify(id, graph, qualifyBaseR = true) {
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
return graph.qualify(id, qualifyBaseR, resolveQualification);
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* The qualified name of every call of the graph, `undefined` for the calls that do not qualify.
|
|
94
|
+
* Prefer this over asking call by call: it resolves each call once for both `qualifyBaseR` variants.
|
|
95
|
+
* @param graph - The graph to qualify
|
|
96
|
+
* @param qualifyBaseR - Which of the two results to return, see {@link Dataflow.qualify}
|
|
97
|
+
*/
|
|
98
|
+
qualifyAll(graph, qualifyBaseR = true) {
|
|
99
|
+
return graph.qualifyAll(qualifyBaseR, resolveQualification);
|
|
85
100
|
},
|
|
86
101
|
/**
|
|
87
102
|
* The packages the given nodes call into, as {@link Dataflow.qualify} resolves every call among them.
|
|
@@ -115,8 +130,8 @@ exports.Dataflow = {
|
|
|
115
130
|
*/
|
|
116
131
|
valueIsUsed(id, graph) {
|
|
117
132
|
const consuming = edge_1.EdgeType.Argument | edge_1.EdgeType.Returns | edge_1.EdgeType.DefinedBy;
|
|
118
|
-
for (const [, edge] of graph.ingoingEdges(id) ??
|
|
119
|
-
if ((edge
|
|
133
|
+
for (const [, edge] of graph.ingoingEdges(id) ?? graph_1.NoEdges) {
|
|
134
|
+
if (edge_1.DfEdge.includesType(edge, consuming)) {
|
|
120
135
|
return true;
|
|
121
136
|
}
|
|
122
137
|
}
|
|
@@ -128,8 +143,8 @@ exports.Dataflow = {
|
|
|
128
143
|
* A call among the arguments counts as computed, even one over literals such as `paste("a", "b")`.
|
|
129
144
|
*/
|
|
130
145
|
hasComputedArguments(id, graph) {
|
|
131
|
-
for (const [target] of graph.outgoingEdges(id) ??
|
|
132
|
-
if (!node_id_1.NodeId.isBuiltIn(target) && graph.getVertex(target)
|
|
146
|
+
for (const [target] of graph.outgoingEdges(id) ?? graph_1.NoEdges) {
|
|
147
|
+
if (!node_id_1.NodeId.isBuiltIn(target) && !vertex_1.ValueVertex.is(graph.getVertex(target))) {
|
|
133
148
|
return true;
|
|
134
149
|
}
|
|
135
150
|
}
|
|
@@ -306,4 +321,11 @@ exports.Dataflow = {
|
|
|
306
321
|
return exports.Dataflow.reduceGraph(graph, exports.Dataflow.provenance(id, graph, consider));
|
|
307
322
|
}
|
|
308
323
|
};
|
|
324
|
+
/** both qualifications of a call from a single origin resolution, as the base-R step only adds to what the origins gave */
|
|
325
|
+
const resolveQualification = (graph, id, vertex) => {
|
|
326
|
+
const origins = (0, dfg_get_origin_1.getOriginInDfg)(graph, id);
|
|
327
|
+
const name = vertex_1.FunctionCallVertex.is(vertex) ? vertex.name : undefined;
|
|
328
|
+
const bare = identifier_1.Identifier.toQualified(origins, name, false);
|
|
329
|
+
return [bare, bare ?? identifier_1.Identifier.toQualified(origins, name, true)];
|
|
330
|
+
};
|
|
309
331
|
//# sourceMappingURL=df-helper.js.map
|
|
@@ -8,7 +8,6 @@ const graph_1 = require("./graph");
|
|
|
8
8
|
const diff_1 = require("../../util/diff");
|
|
9
9
|
const json_1 = require("../../util/json");
|
|
10
10
|
const arrays_1 = require("../../util/collections/arrays");
|
|
11
|
-
const vertex_1 = require("./vertex");
|
|
12
11
|
const edge_1 = require("./edge");
|
|
13
12
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
14
13
|
const identifier_1 = require("../environments/identifier");
|
|
@@ -16,6 +15,7 @@ const diff_2 = require("../environments/diff");
|
|
|
16
15
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
17
16
|
const info_1 = require("../info");
|
|
18
17
|
const diff_graph_1 = require("../../util/diff-graph");
|
|
18
|
+
const vertex_1 = require("./vertex");
|
|
19
19
|
/**
|
|
20
20
|
* This is the underlying function to calculate the difference based on a given context.
|
|
21
21
|
* Use {@link Dataflow.diff} to calculate the diff of two graphs.
|
|
@@ -135,8 +135,8 @@ function diffVertices(ctx) {
|
|
|
135
135
|
position: `${ctx.position}Vertex ${id} differs in environment. `
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
if (
|
|
139
|
-
if (
|
|
138
|
+
if (vertex_1.FunctionCallVertex.is(lInfo)) {
|
|
139
|
+
if (!vertex_1.FunctionCallVertex.is(rInfo)) {
|
|
140
140
|
ctx.report.addComment(`Vertex ${id} differs in tags. ${ctx.leftname}: ${lInfo.tag} vs. ${ctx.rightname}: ${rInfo.tag}`);
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
@@ -152,8 +152,8 @@ function diffVertices(ctx) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
155
|
+
if (vertex_1.FunctionDefinitionVertex.is(lInfo)) {
|
|
156
|
+
if (!vertex_1.FunctionDefinitionVertex.is(rInfo)) {
|
|
157
157
|
ctx.report.addComment(`Vertex ${id} differs in tags. ${ctx.leftname}: ${lInfo.tag} vs. ${ctx.rightname}: ${rInfo.tag}`, { tag: 'vertex', id });
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
@@ -280,7 +280,7 @@ function diffEdge(edge, otherEdge, ctx, id, target) {
|
|
|
280
280
|
if ((edgeTypes.length < otherEdgeTypes.length && !ctx.config.leftIsSubgraph) || (edgeTypes.length > otherEdgeTypes.length && !ctx.config.rightIsSubgraph)) {
|
|
281
281
|
ctx.report.addComment(`Target of ${id}->${target} in ${ctx.leftname} differs in number of edge types: ${JSON.stringify([...edgeTypes])} vs ${JSON.stringify([...otherEdgeTypes])}`, { tag: 'edge', from: id, to: target });
|
|
282
282
|
}
|
|
283
|
-
if (edge
|
|
283
|
+
if (!edge_1.DfEdge.isOnlyType(edge, otherEdge.types)) {
|
|
284
284
|
ctx.report.addComment(`Target of ${id}->${target} in ${ctx.leftname} differs in edge types: ${JSON.stringify([...edge_1.DfEdge.typesToNames(edge)])} vs ${JSON.stringify([...edge_1.DfEdge.typesToNames(otherEdge)])}`, { tag: 'edge', from: id, to: target });
|
|
285
285
|
}
|
|
286
286
|
}
|
package/dataflow/graph/edge.d.ts
CHANGED
|
@@ -96,6 +96,33 @@ export declare const DfEdge: {
|
|
|
96
96
|
* Counterpart of {@link DfEdge#includesType}.
|
|
97
97
|
*/
|
|
98
98
|
readonly doesNotIncludeType: (this: void, { types }: DfEdgeLike, any: EdgeType) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the edge carries any type at all.
|
|
101
|
+
* Counterpart of {@link DfEdge#hasNoType}.
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* DfEdge.hasAnyType({ types: EdgeType.Reads }) // true
|
|
106
|
+
* DfEdge.hasAnyType({ types: 0 }) // false
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
readonly hasAnyType: (this: void, { types }: DfEdgeLike) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the edge carries no type at all. Such an edge states nothing and has to be removed, not kept.
|
|
112
|
+
* Counterpart of {@link DfEdge#hasAnyType}.
|
|
113
|
+
*/
|
|
114
|
+
readonly hasNoType: (this: void, { types }: DfEdgeLike) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Check whether the edge carries the given types and nothing else.
|
|
117
|
+
* Strict counterpart of {@link DfEdge#includesType}, which already holds if one of the bits is set.
|
|
118
|
+
* @example
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* DfEdge.isOnlyType({ types: EdgeType.Reads | EdgeType.Calls }, EdgeType.Reads) // false
|
|
122
|
+
* DfEdge.isOnlyType({ types: EdgeType.Reads | EdgeType.Calls }, EdgeType.Reads | EdgeType.Calls) // true
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
readonly isOnlyType: (this: void, { types }: DfEdgeLike, only: EdgeType) => boolean;
|
|
99
126
|
};
|
|
100
127
|
export declare const enum TraverseEdge {
|
|
101
128
|
/** Do not traverse this edge */
|