@eagleoutice/flowr 2.16.6 → 2.16.7
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 +21 -15
- package/abstract-interpretation/data-frame/dataframe-semantics.d.ts +2 -0
- package/abstract-interpretation/data-frame/dataframe-semantics.js +3 -1
- package/abstract-interpretation/data-frame/resolve-args.d.ts +1 -7
- package/abstract-interpretation/data-frame/resolve-args.js +2 -11
- package/cli/repl/commands/repl-cfg.js +5 -19
- package/cli/repl/commands/repl-code-command.d.ts +10 -0
- package/cli/repl/commands/repl-code-command.js +18 -0
- package/cli/repl/commands/repl-dataflow.js +34 -59
- package/cli/repl/commands/repl-normalize.js +24 -41
- package/cli/repl/commands/repl-query.js +10 -17
- package/config.js +3 -3
- package/control-flow/cfg-dead-code.js +15 -2
- package/control-flow/useless-loop.js +1 -2
- package/data/r-base-packages.generated.d.ts +1 -1
- package/data/r-base-packages.generated.js +3 -3
- package/dataflow/environments/ambient-state-name.d.ts +80 -0
- package/dataflow/environments/ambient-state-name.js +113 -0
- package/dataflow/environments/built-in-eval-name.d.ts +3 -1
- package/dataflow/environments/built-in-eval-name.js +2 -0
- package/dataflow/environments/built-in-props.d.ts +27 -7
- package/dataflow/environments/built-in-props.js +59 -44
- package/dataflow/environments/built-in.d.ts +5 -2
- package/dataflow/environments/built-in.js +22 -5
- package/dataflow/environments/default-builtin-config.d.ts +538 -14
- package/dataflow/environments/default-builtin-config.js +189 -123
- package/dataflow/environments/environment.d.ts +7 -1
- package/dataflow/environments/environment.js +19 -1
- package/dataflow/environments/identifier.d.ts +11 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +13 -3
- package/dataflow/eval/resolve/alias-tracking.js +66 -37
- package/dataflow/eval/resolve/resolve-argument.d.ts +4 -2
- package/dataflow/eval/resolve/resolve-argument.js +23 -11
- package/dataflow/eval/resolve/resolve.d.ts +5 -0
- package/dataflow/eval/resolve/resolve.js +25 -3
- package/dataflow/eval/values/r-value.d.ts +4 -2
- package/dataflow/eval/values/r-value.js +3 -1
- package/dataflow/eval/values/string/string-constants.d.ts +7 -1
- package/dataflow/eval/values/string/string-constants.js +38 -36
- package/dataflow/extractor.js +105 -2
- package/dataflow/fn/argument-roles.js +22 -8
- package/dataflow/fn/function-semantics.d.ts +3 -2
- package/dataflow/fn/strict-function.js +13 -2
- package/dataflow/graph/df-helper.d.ts +14 -1
- package/dataflow/graph/df-helper.js +37 -4
- package/dataflow/graph/graph.d.ts +6 -0
- package/dataflow/graph/graph.js +6 -0
- package/dataflow/internal/linker.d.ts +4 -1
- package/dataflow/internal/linker.js +11 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +41 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +88 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +19 -44
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +125 -158
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +35 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +10 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +3 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +21 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +3 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +5 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +11 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +6 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +42 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +11 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +29 -4
- package/dataflow/internal/process/functions/call/common.js +3 -4
- package/dataflow/internal/process/functions/call/deferred.d.ts +3 -2
- package/dataflow/internal/process/functions/call/deferred.js +17 -9
- package/dataflow/internal/process/functions/call/quoted.js +1 -1
- package/documentation/doc-capabilities.js +3 -2
- package/documentation/doc-readme.js +1 -2
- package/documentation/doc-util/doc-dfg.js +2 -2
- package/documentation/doc-util/doc-query.d.ts +3 -1
- package/documentation/doc-util/doc-query.js +4 -4
- package/documentation/wiki-create-linting-rules.js +1 -1
- package/documentation/wiki-linter.js +16 -206
- package/documentation/wiki-linting-and-testing.js +31 -64
- package/documentation/wiki-query.js +41 -0
- package/index.d.ts +1 -0
- package/index.js +5 -1
- package/linter/linter-format.d.ts +6 -0
- package/linter/linter-format.js +10 -0
- package/linter/linter-rules.d.ts +155 -103
- package/linter/linter-rules.js +2 -0
- package/linter/linter-util.d.ts +23 -0
- package/linter/linter-util.js +58 -0
- package/linter/rules/absolute-path.d.ts +2 -2
- package/linter/rules/absolute-path.js +1 -4
- package/linter/rules/cmd-check/bogus-return.d.ts +2 -2
- package/linter/rules/cmd-check/bogus-return.js +3 -7
- package/linter/rules/cmd-check/call-arguments.d.ts +2 -2
- package/linter/rules/cmd-check/class-string-comparison.d.ts +2 -2
- package/linter/rules/cmd-check/class-string-comparison.js +3 -7
- package/linter/rules/cmd-check/cmd-check-util.d.ts +8 -9
- package/linter/rules/cmd-check/cmd-check-util.js +14 -26
- package/linter/rules/cmd-check/compiled-code.d.ts +8 -3
- package/linter/rules/cmd-check/compiled-code.js +3 -13
- package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -2
- package/linter/rules/cmd-check/dependency-declaration.js +6 -7
- package/linter/rules/cmd-check/description-metadata.d.ts +4 -4
- package/linter/rules/cmd-check/documentation-mismatch.d.ts +2 -2
- package/linter/rules/cmd-check/documentation-mismatch.js +4 -11
- package/linter/rules/cmd-check/file-checks.d.ts +19 -6
- package/linter/rules/cmd-check/file-checks.js +13 -5
- package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -2
- package/linter/rules/cmd-check/global-environment-modification.d.ts +2 -2
- package/linter/rules/cmd-check/global-environment-modification.js +3 -2
- package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -2
- package/linter/rules/cmd-check/namespace-tampering.js +9 -9
- package/linter/rules/cmd-check/non-ascii-code.d.ts +2 -2
- package/linter/rules/cmd-check/package-data.d.ts +11 -5
- package/linter/rules/cmd-check/package-data.js +5 -12
- package/linter/rules/cmd-check/package-files.js +4 -10
- package/linter/rules/cmd-check/package-hooks.d.ts +2 -2
- package/linter/rules/cmd-check/package-hooks.js +10 -8
- package/linter/rules/cmd-check/package-metafiles.d.ts +8 -3
- package/linter/rules/cmd-check/package-metafiles.js +3 -12
- package/linter/rules/cmd-check/package-runtime.d.ts +18 -5
- package/linter/rules/cmd-check/package-runtime.js +64 -20
- package/linter/rules/cmd-check/package-structure.d.ts +11 -5
- package/linter/rules/cmd-check/package-structure.js +4 -12
- package/linter/rules/cmd-check/rd-files.d.ts +8 -3
- package/linter/rules/cmd-check/rd-files.js +4 -14
- package/linter/rules/cmd-check/s-three-method-consistency.d.ts +2 -2
- package/linter/rules/cmd-check/s-three-method-consistency.js +3 -4
- package/linter/rules/cmd-check/true-false-abbreviation.d.ts +2 -2
- package/linter/rules/dataframe-access-validation.d.ts +2 -2
- package/linter/rules/dataframe-access-validation.js +5 -8
- package/linter/rules/dead-code.d.ts +5 -4
- package/linter/rules/dead-code.js +25 -14
- package/linter/rules/deprecated-functions.d.ts +3 -3
- package/linter/rules/deprecated-functions.js +16 -23
- package/linter/rules/file-path-validity.d.ts +2 -2
- package/linter/rules/file-path-validity.js +3 -6
- package/linter/rules/function-finder-util.d.ts +3 -3
- package/linter/rules/function-finder-util.js +7 -14
- package/linter/rules/namespace-access.d.ts +2 -2
- package/linter/rules/namespace-access.js +6 -9
- package/linter/rules/naming-convention.d.ts +2 -2
- package/linter/rules/naming-convention.js +1 -4
- package/linter/rules/network-functions.d.ts +3 -3
- package/linter/rules/no-leaked-credentials.d.ts +2 -2
- package/linter/rules/no-leaked-credentials.js +1 -4
- package/linter/rules/overwritten-file.d.ts +38 -0
- package/linter/rules/overwritten-file.js +102 -0
- package/linter/rules/problematic-inputs.d.ts +16 -6
- package/linter/rules/problematic-inputs.js +78 -34
- package/linter/rules/roxygen-arguments.d.ts +2 -2
- package/linter/rules/roxygen-arguments.js +1 -4
- package/linter/rules/seeded-randomness.d.ts +3 -3
- package/linter/rules/seeded-randomness.js +6 -23
- package/linter/rules/software-has-license.d.ts +2 -2
- package/linter/rules/software-has-license.js +1 -4
- package/linter/rules/software-has-tests.d.ts +2 -2
- package/linter/rules/software-has-tests.js +1 -4
- package/linter/rules/stop-with-call-arg.d.ts +2 -2
- package/linter/rules/stop-with-call-arg.js +4 -11
- package/linter/rules/syntactically-valid.d.ts +4 -2
- package/linter/rules/syntactically-valid.js +29 -10
- package/linter/rules/unclosed-connection.d.ts +2 -2
- package/linter/rules/unclosed-connection.js +1 -4
- package/linter/rules/undefined-symbol.d.ts +2 -2
- package/linter/rules/undefined-symbol.js +25 -22
- package/linter/rules/unescaped-arguments.d.ts +2 -2
- package/linter/rules/unescaped-arguments.js +1 -4
- package/linter/rules/unused-definition.d.ts +2 -2
- package/linter/rules/unused-definition.js +37 -25
- package/linter/rules/unused-import.d.ts +2 -2
- package/linter/rules/unused-import.js +9 -14
- package/linter/rules/useless-loop.d.ts +7 -6
- package/linter/rules/useless-loop.js +4 -8
- package/package.json +5 -3
- package/project/cache/flowr-analyzer-cache.d.ts +2 -0
- package/project/cache/flowr-analyzer-cache.js +15 -11
- package/project/context/flowr-analyzer-files-context.d.ts +3 -0
- package/project/context/flowr-analyzer-files-context.js +6 -0
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +6 -1
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +35 -0
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +2 -1
- package/project/plugins/file-plugins/files/flowr-rsession-file.d.ts +26 -0
- package/project/plugins/file-plugins/files/flowr-rsession-file.js +44 -0
- package/project/plugins/file-plugins/files/r-session.d.ts +20 -0
- package/project/plugins/file-plugins/files/r-session.js +58 -0
- package/project/plugins/file-plugins/files/recorded-runs.d.ts +18 -0
- package/project/plugins/file-plugins/files/recorded-runs.js +8 -0
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rsession-file-plugin.d.ts +20 -0
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rsession-file-plugin.js +28 -0
- package/project/plugins/plugin-registry.d.ts +2 -1
- package/project/plugins/plugin-registry.js +2 -0
- package/project/sigdb/spec-query.d.ts +73 -0
- package/project/sigdb/spec-query.js +339 -0
- package/queries/base-query-format.d.ts +1 -1
- package/queries/base-query-format.js +2 -2
- package/queries/catalog/absint-query/absint-query-executor.js +3 -6
- package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +113 -73
- package/queries/catalog/call-graph-query/call-graph-query-executor.js +2 -3
- package/queries/catalog/cluster-query/cluster-query-executor.js +2 -3
- package/queries/catalog/config-query/config-query-format.d.ts +0 -1
- package/queries/catalog/config-query/config-query-format.js +1 -2
- package/queries/catalog/control-flow-query/control-flow-query-executor.js +2 -3
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +2 -4
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +0 -1
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +1 -2
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -3
- package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +7 -0
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +72 -42
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +24 -6
- package/queries/catalog/dependencies-query/dependencies-query-format.js +108 -3
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -1
- package/queries/catalog/dependencies-query/function-info/read-functions.js +6 -6
- package/queries/catalog/dependencies-query/function-info/write-functions.js +13 -7
- package/queries/catalog/dependencies-query/implicit-echo.js +21 -7
- package/queries/catalog/dice-query/dice-query-executor.js +2 -3
- package/queries/catalog/does-call-query/does-call-query-executor.js +2 -3
- package/queries/catalog/files-query/files-query-executor.js +2 -3
- package/queries/catalog/function-info-query/function-info-query-executor.js +2 -1
- package/queries/catalog/function-info-query/function-info-query-format.d.ts +0 -2
- package/queries/catalog/function-info-query/function-info-query-format.js +1 -2
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -2
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +0 -2
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +1 -2
- package/queries/catalog/happens-before-query/happens-before-query-executor.js +2 -3
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +0 -1
- package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -2
- package/queries/catalog/id-map-query/id-map-query-executor.js +2 -3
- package/queries/catalog/id-map-query/id-map-query-format.d.ts +0 -1
- package/queries/catalog/id-map-query/id-map-query-format.js +1 -2
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +3 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +2 -1
- package/queries/catalog/input-sources-query/simple-input-classifier.js +60 -13
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -3
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +2 -3
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +2 -1
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.d.ts +3 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -7
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +6 -9
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +8 -33
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.d.ts +3 -2
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +1 -7
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +6 -7
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +8 -31
- package/queries/catalog/linter-query/linter-query-executor.js +2 -3
- package/queries/catalog/location-map-query/location-map-query-executor.js +2 -3
- package/queries/catalog/location-map-query/location-map-query-format.d.ts +0 -1
- package/queries/catalog/location-map-query/location-map-query-format.js +1 -2
- package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.js +2 -3
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +0 -1
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +1 -2
- package/queries/catalog/origin-query/origin-query-executor.d.ts +0 -5
- package/queries/catalog/origin-query/origin-query-executor.js +3 -11
- package/queries/catalog/project-query/project-query-executor.js +23 -7
- package/queries/catalog/project-query/project-query-format.d.ts +5 -0
- package/queries/catalog/project-query/project-query-format.js +20 -2
- package/queries/catalog/provenance-query/provenance-query-executor.js +2 -3
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +2 -3
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +0 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -2
- package/queries/catalog/search-query/search-query-executor.js +2 -3
- package/queries/catalog/signature-query/signature-query-executor.js +39 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +7 -1
- package/queries/catalog/signature-query/signature-query-format.js +15 -1
- package/queries/catalog/signature-query/signature-query-render.js +2 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -3
- package/queries/query-function-property.d.ts +28 -0
- package/queries/query-function-property.js +48 -0
- package/queries/query-meta.d.ts +3 -0
- package/queries/query-meta.js +8 -0
- package/queries/query.d.ts +13 -18
- package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +2 -2
- package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -3
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +9 -0
- package/r-bridge/lang-4.x/ast/model/syntax-version.d.ts +8 -0
- package/r-bridge/lang-4.x/ast/model/syntax-version.js +49 -0
- package/r-bridge/lang-4.x/ast/model/type.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/type.js +3 -0
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +4 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-single-node.js +1 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +1 -1
- package/reconstruct/reconstruct.js +35 -1
- package/search/search-executor/search-generators.js +1 -1
- package/slicing/static/fingerprint.js +7 -3
- package/slicing/static/static-slicer.js +6 -0
- package/util/assert.js +2 -2
- package/util/collections/arrays.d.ts +4 -0
- package/util/collections/arrays.js +11 -0
- package/util/collections/defaultmap.d.ts +5 -1
- package/util/collections/defaultmap.js +6 -1
- package/util/files.js +26 -5
- package/util/flowr-version.d.ts +10 -0
- package/util/flowr-version.js +20 -0
- package/util/glob.js +6 -4
- package/util/r-regex.d.ts +6 -0
- package/util/r-regex.js +17 -0
- package/util/text/args.d.ts +5 -0
- package/util/text/args.js +28 -22
- package/util/text/name-rank.d.ts +2 -0
- package/util/text/name-rank.js +3 -1
- package/util/text/regex.d.ts +10 -0
- package/util/text/regex.js +29 -0
- package/util/version.d.ts +1 -6
- package/util/version.js +6 -14
- package/documentation/doc-util/doc-functions.d.ts +0 -24
- package/documentation/doc-util/doc-functions.js +0 -65
|
@@ -2,8 +2,14 @@ import type { RStringValue } from '../../../../r-bridge/lang-4.x/convert-values'
|
|
|
2
2
|
import { type Value, type ValueString } from '../r-value';
|
|
3
3
|
/** lift a raw string or R string value into a ValueString */
|
|
4
4
|
export declare function stringFrom(str: RStringValue | string): ValueString;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The characters R stores for the content of a string literal, with its escapes undone as R's parser undoes them:
|
|
7
|
+
* `a\tb` is three characters. It is `undefined` where R rejects the literal (an unknown escape such as `\.`, a nul)
|
|
8
|
+
* or stores a byte no character stands for (`\xff`).
|
|
9
|
+
*/
|
|
6
10
|
export declare function unescapeRString(this: void, str: string): string | undefined;
|
|
11
|
+
/** the characters a string literal stands for, see {@link unescapeRString}: a raw string stands for its characters as written */
|
|
12
|
+
export declare function contentOf(this: void, { str, flag }: RStringValue): string | undefined;
|
|
7
13
|
/** the {@link ValueString} an R string literal stands for, escapes resolved (a raw string has none, so it stands for its characters as written); undefined for an escape R would reject */
|
|
8
14
|
export declare function stringFromLiteral(this: void, value: RStringValue): ValueString | undefined;
|
|
9
15
|
/** collect strings from an array of ValueString, with quotes if `withQuotes`; undefined if any value is not a string, or is Bottom/Top */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringFrom = stringFrom;
|
|
4
4
|
exports.unescapeRString = unescapeRString;
|
|
5
|
+
exports.contentOf = contentOf;
|
|
5
6
|
exports.stringFromLiteral = stringFromLiteral;
|
|
6
7
|
exports.collectStrings = collectStrings;
|
|
7
8
|
const general_1 = require("../general");
|
|
@@ -10,49 +11,50 @@ const r_value_1 = require("../r-value");
|
|
|
10
11
|
function stringFrom(str) {
|
|
11
12
|
return { type: 'string', value: typeof str === 'string' ? { quotes: '"', str } : str };
|
|
12
13
|
}
|
|
13
|
-
/** the escapes
|
|
14
|
+
/** the escapes of an R string that stand for one character each */
|
|
14
15
|
const SimpleEscapes = {
|
|
15
|
-
n: '\n',
|
|
16
|
-
r: '\r',
|
|
17
|
-
t: '\t',
|
|
18
|
-
b: '\b',
|
|
19
|
-
a: '\x07',
|
|
20
|
-
f: '\f',
|
|
21
|
-
v: '\v',
|
|
22
|
-
'\\': '\\',
|
|
23
|
-
'"': '"',
|
|
24
|
-
'\'': '\'',
|
|
25
|
-
'`': '`'
|
|
16
|
+
a: '\x07', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\', '"': '"', '\'': '\'', '`': '`', ' ': ' ', '\n': '\n'
|
|
26
17
|
};
|
|
27
|
-
/** the
|
|
28
|
-
const
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
/** the escapes of an R string that state a code: octal, hex, and the unicode forms with and without braces */
|
|
19
|
+
const CodedEscape = /^(?:([0-7]{1,3})|x([0-9a-fA-F]{1,2})|u\{([0-9a-fA-F]{1,4})\}|u([0-9a-fA-F]{1,4})|U\{([0-9a-fA-F]{1,8})\}|U([0-9a-fA-F]{1,8}))/;
|
|
20
|
+
/**
|
|
21
|
+
* The characters R stores for the content of a string literal, with its escapes undone as R's parser undoes them:
|
|
22
|
+
* `a\tb` is three characters. It is `undefined` where R rejects the literal (an unknown escape such as `\.`, a nul)
|
|
23
|
+
* or stores a byte no character stands for (`\xff`).
|
|
24
|
+
*/
|
|
32
25
|
function unescapeRString(str) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
let out = '';
|
|
27
|
+
for (let i = 0; i < str.length; i++) {
|
|
28
|
+
if (str[i] !== '\\') {
|
|
29
|
+
out += str[i];
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const simple = SimpleEscapes[str[++i]];
|
|
33
|
+
if (simple !== undefined) {
|
|
34
|
+
out += simple;
|
|
35
|
+
continue;
|
|
43
36
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
const coded = CodedEscape.exec(str.slice(i));
|
|
38
|
+
if (coded === null) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const [whole, octal, hex, ...unicode] = coded;
|
|
42
|
+
const code = parseInt(octal ?? hex ?? unicode.find(u => u !== undefined) ?? '', octal === undefined ? 16 : 8);
|
|
43
|
+
if (code === 0 || code > 0x10FFFF || (code >= 0xD800 && code <= 0xDFFF) || ((octal ?? hex) !== undefined && code > 0x7F)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
out += String.fromCodePoint(code);
|
|
47
|
+
i += whole.length - 1;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** the characters a string literal stands for, see {@link unescapeRString}: a raw string stands for its characters as written */
|
|
52
|
+
function contentOf({ str, flag }) {
|
|
53
|
+
return flag === 'raw' ? str : unescapeRString(str);
|
|
49
54
|
}
|
|
50
55
|
/** the {@link ValueString} an R string literal stands for, escapes resolved (a raw string has none, so it stands for its characters as written); undefined for an escape R would reject */
|
|
51
56
|
function stringFromLiteral(value) {
|
|
52
|
-
|
|
53
|
-
return stringFrom(value);
|
|
54
|
-
}
|
|
55
|
-
const str = unescapeRString(value.str);
|
|
57
|
+
const str = contentOf(value);
|
|
56
58
|
return str === undefined ? undefined : stringFrom({ ...value, str });
|
|
57
59
|
}
|
|
58
60
|
/** collect strings from an array of ValueString, with quotes if `withQuotes`; undefined if any value is not a string, or is Bottom/Top */
|
package/dataflow/extractor.js
CHANGED
|
@@ -40,6 +40,7 @@ const gas_1 = require("../gas");
|
|
|
40
40
|
const config_1 = require("../config");
|
|
41
41
|
const df_helper_1 = require("./graph/df-helper");
|
|
42
42
|
const built_in_ambient_state_1 = require("./internal/process/functions/call/built-in/built-in-ambient-state");
|
|
43
|
+
const ambient_state_name_1 = require("./environments/ambient-state-name");
|
|
43
44
|
const unnamed_call_handling_1 = require("./internal/process/functions/call/unnamed-call-handling");
|
|
44
45
|
const built_in_proc_name_1 = require("./environments/built-in-proc-name");
|
|
45
46
|
const arrays_1 = require("../util/collections/arrays");
|
|
@@ -50,6 +51,8 @@ const query_fn_props_1 = require("./environments/query-fn-props");
|
|
|
50
51
|
const resolve_helper_1 = require("./environments/resolve-helper");
|
|
51
52
|
const happens_before_1 = require("../control-flow/happens-before");
|
|
52
53
|
const assert_1 = require("../util/assert");
|
|
54
|
+
const node_value_1 = require("./eval/resolve/node-value");
|
|
55
|
+
const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
53
56
|
/**
|
|
54
57
|
* The best friend of {@link produceDataFlowGraph} and {@link processDataflowFor}.
|
|
55
58
|
* Maps every {@link RType} in the normalized AST to a processor.
|
|
@@ -151,7 +154,7 @@ function openReadsOfCalledFunctions(graph) {
|
|
|
151
154
|
for (const [id, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
152
155
|
if (df_helper_1.Dataflow.sourcesOf(graph, id, edge_1.EdgeType.Calls).length > 0) {
|
|
153
156
|
for (const read of definition.subflow.in) {
|
|
154
|
-
if (read.name !== undefined && !
|
|
157
|
+
if (read.name !== undefined && !ambient_state_name_1.AmbientStateName.is(read.name) && !identifier_1.Identifier.getName(read.name).startsWith(unnamed_call_handling_1.UnnamedFunctionCallPrefix)) {
|
|
155
158
|
reads.set(read.nodeId, read);
|
|
156
159
|
}
|
|
157
160
|
}
|
|
@@ -340,6 +343,104 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
340
343
|
}
|
|
341
344
|
}
|
|
342
345
|
}
|
|
346
|
+
/** The paths the {@link ArgProp.Resource} arguments of the file accessing call `id` name, `undefined` unless every one resolves to strings. */
|
|
347
|
+
function pathsOf(id, graph, environment, ctx, callContext) {
|
|
348
|
+
const vertex = graph.getVertex(id);
|
|
349
|
+
if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
const resources = argsWithProp((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.ArgProp.Resource);
|
|
353
|
+
const paths = new Set();
|
|
354
|
+
for (const resource of resources) {
|
|
355
|
+
const strings = node_value_1.NodeValue.stringsOf(r_argument_1.RArgument.valueOf(graph.idMap?.get(resource)) ?? resource, resolve_helper_1.Resolve.info(graph, ctx), { callContext });
|
|
356
|
+
if (strings === undefined || strings.length === 0) {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
strings.forEach(p => paths.add(p));
|
|
360
|
+
}
|
|
361
|
+
return resources.length === 0 ? undefined : paths;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The levels of calls that run the file write `writer`: the calls of the function holding it, then the calls of the
|
|
365
|
+
* function holding such a call, and so on. Each call resolves the file for the calls leading to it ({@link CallContext}).
|
|
366
|
+
* `undefined` unless the levels account for every call the write has an effect on (a recursive function, a call we
|
|
367
|
+
* do not see through), as only then can the write leave it to the calls to tell which of them run it.
|
|
368
|
+
*/
|
|
369
|
+
function fileWriteLevels(writer, graph, idMap, paths) {
|
|
370
|
+
const affected = new Set(df_helper_1.Dataflow.targetsOf(graph, writer, edge_1.EdgeType.SideEffectOnCall));
|
|
371
|
+
const first = model_1.RNode.findEnclosing(writer, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
372
|
+
if (first === undefined || affected.size === 0) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
const levels = [];
|
|
376
|
+
const covered = new Set();
|
|
377
|
+
const queue = [{ at: writer, definition: first, context: new Map() }];
|
|
378
|
+
for (let item = queue.shift(); item !== undefined; item = queue.shift()) {
|
|
379
|
+
const { at, definition, context } = item;
|
|
380
|
+
const calls = [...affected].filter(c => df_helper_1.Dataflow.targetsOf(graph, c, edge_1.EdgeType.Calls).includes(definition));
|
|
381
|
+
if (calls.length === 0 || context.has(definition)) {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
levels.push({ at, definition, calls: calls.map(call => {
|
|
385
|
+
covered.add(call);
|
|
386
|
+
const within = new Map(context).set(definition, call);
|
|
387
|
+
const outer = model_1.RNode.strictlyEnclosingFunction(call, idMap);
|
|
388
|
+
if (outer !== undefined) {
|
|
389
|
+
queue.push({ at: call, definition: outer, context: within });
|
|
390
|
+
}
|
|
391
|
+
return { call, paths: paths(within) };
|
|
392
|
+
}) });
|
|
393
|
+
}
|
|
394
|
+
return covered.size === affected.size ? levels : undefined;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* A file written within a function is written at each of its calls, so whatever reads it reads the write in the body,
|
|
398
|
+
* which in turn depends on every call ({@link EdgeType.SideEffectOnCall}). Where the calls name their files, as
|
|
399
|
+
* `save <- function(n) writeLines("x", n)` does for `save("a.txt")` and `save("b.txt")`, a read reads the calls writing
|
|
400
|
+
* the file it reads as well, so the write no longer needs to depend on all of them: a read of `a.txt` needs `save("a.txt")`
|
|
401
|
+
* only. Through a function calling `save` in turn, the read reads the call within it and the calls of that function.
|
|
402
|
+
*/
|
|
403
|
+
function separateFileWritesPerCall(graph, environment, ctx) {
|
|
404
|
+
const idMap = graph.idMap;
|
|
405
|
+
if (idMap === undefined) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const fileAccess = (0, defaultmap_1.memoize)((id) => {
|
|
409
|
+
const info = (0, query_fn_props_1.callFnProps)(id, { graph, environment });
|
|
410
|
+
return function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes]) ? 'write'
|
|
411
|
+
: function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Reads]) ? 'read' : undefined;
|
|
412
|
+
});
|
|
413
|
+
const readPaths = (0, defaultmap_1.memoize)((id) => fileAccess(id) === 'read' ? pathsOf(id, graph, environment, ctx) : undefined);
|
|
414
|
+
/* writing to the console (`cat(x)`) names no file, and has no call to tell apart */
|
|
415
|
+
const namesFile = (id) => {
|
|
416
|
+
const vertex = graph.getVertex(id);
|
|
417
|
+
return argsWithProp((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.ArgProp.Resource).length > 0;
|
|
418
|
+
};
|
|
419
|
+
const writers = [...graph.verticesOfType(vertex_1.VertexType.FunctionCall)].map(([id]) => id)
|
|
420
|
+
.filter(id => graph.edgesFrom(id).values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.SideEffectOnCall)) && !graph.unknownSideEffects.has(id) && fileAccess(id) === 'write' && namesFile(id));
|
|
421
|
+
const separated = new Set();
|
|
422
|
+
for (const writer of writers) {
|
|
423
|
+
const levels = fileWriteLevels(writer, graph, idMap, callContext => pathsOf(writer, graph, environment, ctx, callContext));
|
|
424
|
+
if (levels !== undefined) {
|
|
425
|
+
separated.add(writer);
|
|
426
|
+
}
|
|
427
|
+
for (const { at, definition, calls } of levels ?? []) {
|
|
428
|
+
const body = graph.getVertex(definition).subflow.graph;
|
|
429
|
+
/* what holds the definition (`(function(p) ...)`) is no reader of what its body writes */
|
|
430
|
+
const holders = new Set([...model_1.RNode.iterateParents(idMap.get(at), idMap)].map(n => n.info.id));
|
|
431
|
+
const readers = df_helper_1.Dataflow.sourcesOf(graph, at, edge_1.EdgeType.Reads).filter(r => !body.has(r) && !holders.has(r) && !calls.some(c => c.call === r));
|
|
432
|
+
for (const { call, paths } of calls) {
|
|
433
|
+
for (const reader of readers) {
|
|
434
|
+
const read = readPaths(reader);
|
|
435
|
+
if (read === undefined || paths === undefined || !read.isDisjointFrom(paths)) {
|
|
436
|
+
graph.addEdge(reader, call, edge_1.EdgeType.Reads);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
graph.fileWritesPerCall = separated;
|
|
443
|
+
}
|
|
343
444
|
/** A variable read linked to a call diverting the output (`sink(con)`, see `AmbientStateName.textConnection`) also reads what that call diverts. */
|
|
344
445
|
function linkReadsOfDivertedOutput(graph, environment) {
|
|
345
446
|
if (!(0, built_in_ambient_state_1.mayForce)(environment)) {
|
|
@@ -461,7 +562,7 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
461
562
|
const foldedIn = new Set();
|
|
462
563
|
const rounds = ctx.config.solver.transitiveSideEffectRounds ?? config_1.DefaultTransitiveSideEffectRounds;
|
|
463
564
|
/* a read of the options or graphics state nothing set reads the state R starts with, unless a write escaping a call replaces it */
|
|
464
|
-
const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r =>
|
|
565
|
+
const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r => ambient_state_name_1.AmbientStateName.is(r.name));
|
|
465
566
|
for (let round = 0; round < rounds; round++) {
|
|
466
567
|
const { environment, grew, escapedNames: roundNames } = df_helper_1.Dataflow.sideEffects.propagateTransitive(df.graph, df.environment, ctx, foldedIn, initialState);
|
|
467
568
|
df.environment = environment;
|
|
@@ -484,12 +585,14 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
484
585
|
const cleanEnvironment = ctx.env.makeCleanEnv();
|
|
485
586
|
(0, linker_1.separateClosureInstances)(df.graph, name => (0, query_fn_props_1.queryFnProps)(name, { environment: cleanEnvironment }));
|
|
486
587
|
function_semantics_1.FunctionSemantics.call.quoted.finalize(df.graph, df.environment, completeAst.idMap, () => new control_flow_graph_1.ControlFlowGraph(df.graph));
|
|
588
|
+
(0, built_in_try_catch_1.linkLateWarningsAsErrors)(df.graph, df.environment, completeAst.idMap);
|
|
487
589
|
(0, built_in_try_catch_1.orderRaisingBodies)(df.graph, completeAst.idMap, ctx);
|
|
488
590
|
function_semantics_1.FunctionSemantics.settleJumpsInPromises(df.graph, df.exitPoints, { ctx });
|
|
489
591
|
linkEnvironmentArgumentsWrittenByCallee(df.graph, df.environment);
|
|
490
592
|
resolveLinkToSideEffects(df.graph, ctx);
|
|
491
593
|
linkResourceReadersToWriters(df.graph, df.environment, ctx);
|
|
492
594
|
linkReadsOfDivertedOutput(df.graph, df.environment);
|
|
595
|
+
separateFileWritesPerCall(df.graph, df.environment, ctx);
|
|
493
596
|
return df;
|
|
494
597
|
}
|
|
495
598
|
//# sourceMappingURL=extractor.js.map
|
|
@@ -135,8 +135,12 @@ function statedRoles(definition, state) {
|
|
|
135
135
|
const byName = formalsByName(definition, state);
|
|
136
136
|
const roles = new Map();
|
|
137
137
|
const add = (node, props) => {
|
|
138
|
+
/* forcing `if(c) a else b` evaluates only one of `a` and `b`, so neither is forced for certain */
|
|
139
|
+
const always = (props & built_in_props_1.ArgProp.Forced) === 0 ? undefined : identityFrom(node, state, 0, new Set());
|
|
140
|
+
const written = writtenFormal(node, byName, state);
|
|
138
141
|
for (const formal of aliasTargets(node, byName, state)) {
|
|
139
|
-
|
|
142
|
+
const own = always === undefined || always.has(formal) || formal === written ? props : props & ~built_in_props_1.ArgProp.Forced;
|
|
143
|
+
roles.set(formal, (roles.get(formal) ?? 0) | own);
|
|
140
144
|
}
|
|
141
145
|
};
|
|
142
146
|
for (const [node, vertex] of df_helper_1.Dataflow.callsIn(definition, state.graph)) {
|
|
@@ -168,7 +172,7 @@ function calledNames(id, vertex, state) {
|
|
|
168
172
|
const called = identifier_1.Identifier.getName(vertex.name);
|
|
169
173
|
return [...state.graph.edgesFrom(id)]
|
|
170
174
|
.filter(([target, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !handed.has(target) && !node_id_1.NodeId.isBuiltIn(target)
|
|
171
|
-
&& node_id_1.NodeId.
|
|
175
|
+
&& node_id_1.NodeId.recoverBareName(target, state.graph.idMap) === called)
|
|
172
176
|
.map(([target]) => target);
|
|
173
177
|
}
|
|
174
178
|
/**
|
|
@@ -191,18 +195,25 @@ function aliasTargets(node, byName, state) {
|
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
|
-
const
|
|
195
|
-
const formal = r_symbol_1.RSymbol.is(written) ? byName.get(written.lexeme) : undefined;
|
|
198
|
+
const formal = writtenFormal(node, byName, state);
|
|
196
199
|
if (formal !== undefined) {
|
|
197
200
|
found.add(formal);
|
|
198
201
|
}
|
|
199
202
|
return found;
|
|
200
203
|
}
|
|
201
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* The formal parameter a symbol argument names. In `f <- function(x) quote(x)` the `x` of `quote` is never evaluated,
|
|
206
|
+
* so no edge links it to the formal `x`, and its name is all there is to go by.
|
|
207
|
+
*/
|
|
208
|
+
function writtenFormal(node, byName, state) {
|
|
209
|
+
const name = r_symbol_1.RSymbol.is(state.graph.idMap?.get(node)) ? node_id_1.NodeId.recoverBareName(node, state.graph.idMap) : undefined;
|
|
210
|
+
return name === undefined ? undefined : byName.get(name);
|
|
211
|
+
}
|
|
212
|
+
/** The formals of `definition` by name, for {@link writtenFormal}. */
|
|
202
213
|
function formalsByName(definition, state) {
|
|
203
214
|
const byName = new Map();
|
|
204
215
|
for (const formal of Object.keys(definition.params)) {
|
|
205
|
-
const name = node_id_1.NodeId.
|
|
216
|
+
const name = node_id_1.NodeId.recoverBareName(node_id_1.NodeId.normalize(formal), state.graph.idMap);
|
|
206
217
|
if (name !== undefined) {
|
|
207
218
|
byName.set(name, node_id_1.NodeId.normalize(formal));
|
|
208
219
|
}
|
|
@@ -237,8 +248,11 @@ function matchArgumentProps(vertex, state) {
|
|
|
237
248
|
if (props === 0) {
|
|
238
249
|
continue;
|
|
239
250
|
}
|
|
240
|
-
|
|
241
|
-
|
|
251
|
+
const given = bound.get(formal) ?? [];
|
|
252
|
+
for (const [i, argument] of given.entries()) {
|
|
253
|
+
/* an alias on `...` is only the last argument */
|
|
254
|
+
const had = formal === '...' && i < given.length - 1 ? props & ~built_in_props_1.ArgProp.Alias : props;
|
|
255
|
+
found.push([had, values.get(argument) ?? argument]);
|
|
242
256
|
}
|
|
243
257
|
}
|
|
244
258
|
return found;
|
|
@@ -59,6 +59,7 @@ export declare const FunctionSemantics: {
|
|
|
59
59
|
readonly filter: (this: void, stated: import("../environments/built-in-props").StatedProps | undefined, selector: import("../environments/built-in-props").PropSelector) => import("../environments/built-in-props").StatedProps;
|
|
60
60
|
readonly key: (this: void, selector: import("../environments/built-in-props").PropSelector) => string;
|
|
61
61
|
readonly names: (this: void, selector: import("../environments/built-in-props").PropSelector) => string[];
|
|
62
|
+
readonly vocabulary: Readonly<Record<import("../environments/built-in-props").CallProp, import("../environments/built-in-props").PropWord>>;
|
|
62
63
|
readonly labels: (this: void, stated: import("../environments/built-in-props").StatedProps | undefined) => string[];
|
|
63
64
|
readonly words: (this: void, props: CallProps | undefined) => string[];
|
|
64
65
|
readonly mask: (this: void, names: readonly string[]) => import("../environments/built-in-props").PropMask;
|
|
@@ -77,7 +78,7 @@ export declare const FunctionSemantics: {
|
|
|
77
78
|
};
|
|
78
79
|
/** The same as {@link FunctionSemantics.call.props}, for one argument. */
|
|
79
80
|
readonly argument: {
|
|
80
|
-
readonly
|
|
81
|
+
readonly vocabulary: Readonly<Record<import("../environments/built-in-props").ArgProp, import("../environments/built-in-props").PropWord>>;
|
|
81
82
|
readonly words: (props: ArgProps | undefined) => string[];
|
|
82
83
|
readonly mask: (names: readonly string[]) => ArgProps;
|
|
83
84
|
};
|
|
@@ -114,7 +115,7 @@ export declare const FunctionSemantics: {
|
|
|
114
115
|
readonly indexOf: <Info>(this: void, graph: import("../..").DataflowGraph, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>) => import("../internal/process/functions/call/deferred").NameIndex;
|
|
115
116
|
readonly forcedAt: (this: void, graph: import("../..").DataflowGraph, binding: import("../..").NodeId, cfg: import("../../control-flow/control-flow-graph").ControlFlowGraph, viaClosures?: boolean) => readonly import("../..").NodeId[];
|
|
116
117
|
readonly publish: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, at: import("../..").NodeId, sites: readonly import("../..").NodeId[], cfg?: import("../../control-flow/control-flow-graph").ControlFlowGraph) => void;
|
|
117
|
-
readonly link: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, forces?: import("../internal/process/functions/call/deferred").ForceSites) => void;
|
|
118
|
+
readonly link: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, forces?: import("../internal/process/functions/call/deferred").ForceSites, inCallerFrame?: boolean) => void;
|
|
118
119
|
};
|
|
119
120
|
/** The calls that change the environment in ways flowR cannot follow. */
|
|
120
121
|
readonly unsupported: {
|
|
@@ -64,6 +64,12 @@ function hasProcessor(vertex, of) {
|
|
|
64
64
|
function enclosingDefinition(id, idMap, graph) {
|
|
65
65
|
return model_1.RNode.findEnclosing(id, idMap, node => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(node.info.id)));
|
|
66
66
|
}
|
|
67
|
+
/** The `UseMethod` call of a dispatch vertex: the vertex sits on the generic argument, `"f"` in `UseMethod("f", x)`. */
|
|
68
|
+
function dispatchCallOf(id, idMap) {
|
|
69
|
+
const node = idMap.get(id);
|
|
70
|
+
const argument = node !== undefined && node.info.role === "arg-v" /* RoleInParent.ArgumentValue */ ? model_1.RNode.directParent(node, idMap) : undefined;
|
|
71
|
+
return argument === undefined ? node : model_1.RNode.directParent(argument, idMap);
|
|
72
|
+
}
|
|
67
73
|
/** The definitions whose body dispatches, with what each dispatch does with the arguments. */
|
|
68
74
|
function dispatchingDefinitions(graph) {
|
|
69
75
|
const idMap = graph.idMap;
|
|
@@ -79,7 +85,7 @@ function dispatchingDefinitions(graph) {
|
|
|
79
85
|
if (within === undefined) {
|
|
80
86
|
continue;
|
|
81
87
|
}
|
|
82
|
-
const node =
|
|
88
|
+
const node = dispatchCallOf(id, idMap);
|
|
83
89
|
const known = dispatch.get(within);
|
|
84
90
|
dispatch.set(within, {
|
|
85
91
|
named: (r_function_call_1.RFunctionCall.is(node) && node.arguments.length > 1) || (known?.named ?? false),
|
|
@@ -439,11 +445,16 @@ function forcingPointsOf(params, graph, idMap, seen = new Set()) {
|
|
|
439
445
|
const owner = idMap.get(idMap.get(param)?.info.parent ?? -1)?.info.parent;
|
|
440
446
|
for (const read of df_helper_1.Dataflow.sourcesOf(graph, param, edge_1.EdgeType.Reads)) {
|
|
441
447
|
found.push(read);
|
|
448
|
+
/* only a closure within the function owning the parameter captures it, a read elsewhere is no call of one */
|
|
449
|
+
const closures = [];
|
|
442
450
|
let closure = model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
443
451
|
while (closure !== undefined && closure !== owner) {
|
|
444
|
-
|
|
452
|
+
closures.push(closure);
|
|
445
453
|
closure = model_1.RNode.strictlyEnclosingFunction(closure, idMap);
|
|
446
454
|
}
|
|
455
|
+
if (closure === owner) {
|
|
456
|
+
found.push(...closures.flatMap(c => df_helper_1.Dataflow.sourcesOf(graph, c, edge_1.EdgeType.Calls)));
|
|
457
|
+
}
|
|
447
458
|
/* a read that is an argument hands the promise on */
|
|
448
459
|
for (const holder of df_helper_1.Dataflow.sourcesOf(graph, read, edge_1.EdgeType.Argument)) {
|
|
449
460
|
const call = graph.getVertex(holder);
|
|
@@ -2,7 +2,7 @@ import { DataflowGraph } from './graph';
|
|
|
2
2
|
import { EdgeType } from './edge';
|
|
3
3
|
import { emptyGraph } from './dataflowgraph-builder';
|
|
4
4
|
import { getOriginInDfg } from '../origin/dfg-get-origin';
|
|
5
|
-
import { computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
|
|
5
|
+
import { ambientWritesOfFunctions, computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
7
|
import type { REnvironmentInformation } from '../environments/environment';
|
|
8
8
|
import { type DataflowGraphVertexFunctionCall, type DataflowGraphVertexFunctionDefinition, type DataflowGraphVertexInfo } from './vertex';
|
|
@@ -120,6 +120,14 @@ export declare const Dataflow: {
|
|
|
120
120
|
* @param environment - The environment to resolve the call name in, if the call does not carry one itself
|
|
121
121
|
*/
|
|
122
122
|
readonly callTargetsOf: (this: void, call: NodeId, graph: DataflowGraph, environment?: REnvironmentInformation) => NodeId[];
|
|
123
|
+
/**
|
|
124
|
+
* Whether every function the call may run is a built-in or one the program defines, so that what flowR knows
|
|
125
|
+
* about those functions is all there is to know about the call. In `f <- function(x) x; do.call(f, list(1))` the
|
|
126
|
+
* symbol `f` is called this way, while in `g <- get(name); g(1)` it is not known what `g` runs.
|
|
127
|
+
* A call of a name the program binds nowhere runs what a package exports under that name, which counts as known.
|
|
128
|
+
* @see {@link Dataflow.callTargetsOf} - for the targets themselves
|
|
129
|
+
*/
|
|
130
|
+
readonly callsOnlyKnownFunctions: (this: void, call: NodeId, graph: DataflowGraph, environment?: REnvironmentInformation) => boolean;
|
|
123
131
|
/**
|
|
124
132
|
* The calls within the body of a function definition, id and vertex paired.
|
|
125
133
|
* @see {@link Dataflow.calleeIdsOf} - for what a single call calls
|
|
@@ -144,6 +152,11 @@ export declare const Dataflow: {
|
|
|
144
152
|
readonly sideEffects: {
|
|
145
153
|
readonly propagateTransitive: typeof propagateTransitiveSideEffects;
|
|
146
154
|
readonly callGraphSummaries: typeof computeCallGraphSummaries;
|
|
155
|
+
/**
|
|
156
|
+
* The global state each function may leave changed when called, as pseudo variable names ({@link AmbientStateName}),
|
|
157
|
+
* including what the functions it calls change. Writes only to the function's own frame are left out.
|
|
158
|
+
*/
|
|
159
|
+
readonly ambientWrites: typeof ambientWritesOfFunctions;
|
|
147
160
|
};
|
|
148
161
|
/**
|
|
149
162
|
* Only returns the sub-part of the graph that is determined by the given selection.
|
|
@@ -12,7 +12,6 @@ const vertex_1 = require("./vertex");
|
|
|
12
12
|
const identifier_1 = require("../environments/identifier");
|
|
13
13
|
const r_base_packages_1 = require("../../util/r-base-packages");
|
|
14
14
|
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
15
|
-
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
16
15
|
const linker_1 = require("../internal/linker");
|
|
17
16
|
const dfg_get_symbol_refs_1 = require("../origin/dfg-get-symbol-refs");
|
|
18
17
|
/**
|
|
@@ -183,6 +182,16 @@ exports.Dataflow = {
|
|
|
183
182
|
callTargetsOf(call, graph, environment) {
|
|
184
183
|
return (0, linker_1.getAllFunctionCallTargets)(call, graph, environment);
|
|
185
184
|
},
|
|
185
|
+
/**
|
|
186
|
+
* Whether every function the call may run is a built-in or one the program defines, so that what flowR knows
|
|
187
|
+
* about those functions is all there is to know about the call. In `f <- function(x) x; do.call(f, list(1))` the
|
|
188
|
+
* symbol `f` is called this way, while in `g <- get(name); g(1)` it is not known what `g` runs.
|
|
189
|
+
* A call of a name the program binds nowhere runs what a package exports under that name, which counts as known.
|
|
190
|
+
* @see {@link Dataflow.callTargetsOf} - for the targets themselves
|
|
191
|
+
*/
|
|
192
|
+
callsOnlyKnownFunctions(call, graph, environment) {
|
|
193
|
+
return exports.Dataflow.callTargetsOf(call, graph, environment).every(t => node_id_1.NodeId.isBuiltIn(t) || vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
|
|
194
|
+
},
|
|
186
195
|
/**
|
|
187
196
|
* The calls within the body of a function definition, id and vertex paired.
|
|
188
197
|
* @see {@link Dataflow.calleeIdsOf} - for what a single call calls
|
|
@@ -199,9 +208,9 @@ exports.Dataflow = {
|
|
|
199
208
|
definitionsByName(graph) {
|
|
200
209
|
const byName = new defaultmap_1.DefaultMap(() => []);
|
|
201
210
|
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
202
|
-
const name = node_id_1.NodeId.
|
|
211
|
+
const name = node_id_1.NodeId.recoverBareName(id, graph.idMap);
|
|
203
212
|
if (name !== undefined) {
|
|
204
|
-
byName.get(
|
|
213
|
+
byName.get(name).push(id);
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
return byName;
|
|
@@ -247,6 +256,11 @@ exports.Dataflow = {
|
|
|
247
256
|
sideEffects: {
|
|
248
257
|
propagateTransitive: transitive_side_effects_1.propagateTransitiveSideEffects,
|
|
249
258
|
callGraphSummaries: transitive_side_effects_1.computeCallGraphSummaries,
|
|
259
|
+
/**
|
|
260
|
+
* The global state each function may leave changed when called, as pseudo variable names ({@link AmbientStateName}),
|
|
261
|
+
* including what the functions it calls change. Writes only to the function's own frame are left out.
|
|
262
|
+
*/
|
|
263
|
+
ambientWrites: transitive_side_effects_1.ambientWritesOfFunctions,
|
|
250
264
|
},
|
|
251
265
|
/**
|
|
252
266
|
* Only returns the sub-part of the graph that is determined by the given selection.
|
|
@@ -380,6 +394,25 @@ const resolveQualification = (graph, id, vertex) => {
|
|
|
380
394
|
const origins = exports.Dataflow.origin(graph, id);
|
|
381
395
|
const name = vertex_1.DfgVertex.isFunctionCall(vertex) ? vertex.name : undefined;
|
|
382
396
|
const bare = identifier_1.Identifier.toQualified(origins, name, false);
|
|
383
|
-
return [bare, bare ?? identifier_1.Identifier.toQualified(origins, name, true)];
|
|
397
|
+
return [bare, bare ?? identifier_1.Identifier.toQualified(origins, name, true) ?? aliasedBaseR(graph, id, origins)];
|
|
384
398
|
};
|
|
399
|
+
/**
|
|
400
|
+
* The base-R function an aliased call resolves to when it reaches nothing of the analyzed code, `utils::read.csv` for the
|
|
401
|
+
* `f()` of `f <- read.csv`, which the origins alone cannot tell from a call of the code, as both read the definition of `f`.
|
|
402
|
+
* Only a call reading such a binding is one, as an unknown `stat_summary(fun = mean)` is said to call `mean` as well.
|
|
403
|
+
*/
|
|
404
|
+
function aliasedBaseR(graph, id, origins) {
|
|
405
|
+
if (!origins?.some(o => !('proc' in o) && !node_id_1.NodeId.isBuiltIn(o.id))) {
|
|
406
|
+
return undefined;
|
|
407
|
+
}
|
|
408
|
+
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
409
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && !node_id_1.NodeId.isBuiltIn(target)) {
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const names = new Set(origins.flatMap(o => 'proc' in o && node_id_1.NodeId.isBuiltIn(o.proc) ? [node_id_1.NodeId.fromBuiltIn(o.proc)] : []));
|
|
414
|
+
const [name] = names;
|
|
415
|
+
const owner = names.size === 1 ? (0, r_base_packages_1.baseRExportOwner)(name) : undefined;
|
|
416
|
+
return owner === undefined ? undefined : identifier_1.Identifier.make(name, owner);
|
|
417
|
+
}
|
|
385
418
|
//# sourceMappingURL=df-helper.js.map
|
|
@@ -138,6 +138,12 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
138
138
|
* statement sourcing a file runs that file's statements in between. Set once the whole program is analyzed.
|
|
139
139
|
*/
|
|
140
140
|
statementOrder: ReadonlyMap<NodeId, readonly [start: number, end: number]> | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* The file writes within function bodies whose readers read the calls writing their file as well, so only a slice
|
|
143
|
+
* starting in their body needs every call they have an {@link EdgeType.SideEffectOnCall} on. Set once the whole
|
|
144
|
+
* program is analyzed.
|
|
145
|
+
*/
|
|
146
|
+
fileWritesPerCall: ReadonlySet<NodeId> | undefined;
|
|
141
147
|
private readonly _unknownSideEffects;
|
|
142
148
|
constructor(idMap: AstIdMap | undefined);
|
|
143
149
|
/** Contains the vertices of the root level graph (i.e., included those vertices from the complete graph, that are nested within function definitions) */
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -104,6 +104,12 @@ class DataflowGraph {
|
|
|
104
104
|
* statement sourcing a file runs that file's statements in between. Set once the whole program is analyzed.
|
|
105
105
|
*/
|
|
106
106
|
statementOrder;
|
|
107
|
+
/**
|
|
108
|
+
* The file writes within function bodies whose readers read the calls writing their file as well, so only a slice
|
|
109
|
+
* starting in their body needs every call they have an {@link EdgeType.SideEffectOnCall} on. Set once the whole
|
|
110
|
+
* program is analyzed.
|
|
111
|
+
*/
|
|
112
|
+
fileWritesPerCall;
|
|
107
113
|
/*
|
|
108
114
|
* Set of vertices which have sideEffects that we do not know anything about.
|
|
109
115
|
* As a (temporary) solution until we have FD edges, a side effect may also store known target links
|
|
@@ -83,7 +83,10 @@ export declare const ClosureRefs: {
|
|
|
83
83
|
};
|
|
84
84
|
/** The field an access names, if it is written out: `x$f`, `x[["f"]]`, or `x[[2]]`, which is how a list records its positional entries. */
|
|
85
85
|
export declare function accessedFieldName(fieldNode: RNode<ParentInformation> | undefined, treatIndicesAsString: boolean | undefined): string | undefined;
|
|
86
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
|
|
88
|
+
* and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
|
|
89
|
+
*/
|
|
87
90
|
export declare function linkFieldReads(graph: DataflowGraph, accessId: NodeId, fieldDefs: readonly IdentifierDefinition[] | undefined, returnsFunctions: boolean): void;
|
|
88
91
|
/**
|
|
89
92
|
* An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is
|
|
@@ -73,7 +73,7 @@ function findNonLocalReads(graph, ignores = new Set()) {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
if (!linked || nonLocal) {
|
|
76
|
-
nonLocalReads.push({ nodeId, name: node_id_1.NodeId.
|
|
76
|
+
nonLocalReads.push({ nodeId, name: node_id_1.NodeId.recoverBareName(nodeId, graph.idMap), type });
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -147,7 +147,7 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
147
147
|
for (const captured of df_helper_1.Dataflow.targetsOf(graph, node, edge_1.EdgeType.Reads)) {
|
|
148
148
|
const frame = fnSubflow.graph.has(captured) ? undefined : model_1.RNode.findEnclosing(captured, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
149
149
|
const owner = frame === undefined ? undefined : graph.getVertex(frame);
|
|
150
|
-
const name = node_id_1.NodeId.
|
|
150
|
+
const name = node_id_1.NodeId.recoverBareName(captured, idMap);
|
|
151
151
|
const envState = vertex_2.DfgVertex.isFunctionDefinition(owner) && name !== undefined ? resolve_helper_1.Resolve.byName(name, owner.subflow.environment)?.filter(identifier_1.hasEnvState).find(d => d.nodeId === captured)?.envState : undefined;
|
|
152
152
|
if (envState !== undefined) {
|
|
153
153
|
linkFieldWritesOnCall(graph, id, fnId, node, captured, envState, idMap);
|
|
@@ -322,7 +322,8 @@ function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGrap
|
|
|
322
322
|
let followTargets;
|
|
323
323
|
/* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
|
|
324
324
|
const handedBack = !viaAccess && vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? edge_1.EdgeType.Returns | edge_1.EdgeType.Argument : edge_1.EdgeType.Returns;
|
|
325
|
-
|
|
325
|
+
/* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
|
|
326
|
+
const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? cid : call;
|
|
326
327
|
for (const [target, e] of dataflowGraph.edgesFrom(cid)) {
|
|
327
328
|
if (edge_1.DfEdge.includesType(e, handedBack)) {
|
|
328
329
|
hasReturnEdge = true;
|
|
@@ -507,14 +508,17 @@ function accessedFieldName(fieldNode, treatIndicesAsString) {
|
|
|
507
508
|
return r_number_1.RNumber.is(fieldNode) && !fieldNode.content.complexNumber && Number.isInteger(fieldNode.content.num) && fieldNode.content.num > 0
|
|
508
509
|
? String(fieldNode.content.num) : undefined;
|
|
509
510
|
}
|
|
510
|
-
/**
|
|
511
|
+
/**
|
|
512
|
+
* Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
|
|
513
|
+
* and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
|
|
514
|
+
*/
|
|
511
515
|
function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
|
|
512
516
|
for (const fd of fieldDefs ?? []) {
|
|
513
517
|
graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Reads);
|
|
514
518
|
if (fd.definedAt !== undefined && fd.definedAt !== fd.nodeId) {
|
|
515
519
|
graph.addEdge(accessId, fd.definedAt, edge_1.EdgeType.Reads);
|
|
516
520
|
}
|
|
517
|
-
if (returnsFunctions && fd.type
|
|
521
|
+
if (returnsFunctions && (fd.type & (identifier_1.ReferenceType.Function | identifier_1.ReferenceType.Unknown)) !== 0) {
|
|
518
522
|
graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Returns);
|
|
519
523
|
}
|
|
520
524
|
}
|
|
@@ -573,11 +577,11 @@ function factoryOf(closure, graph, known, idMap) {
|
|
|
573
577
|
return undefined;
|
|
574
578
|
}
|
|
575
579
|
else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
|
|
576
|
-
locals.add(node_id_1.NodeId.
|
|
580
|
+
locals.add(node_id_1.NodeId.recoverBareName(node, idMap) ?? '');
|
|
577
581
|
}
|
|
578
582
|
}
|
|
579
583
|
for (const param of Object.keys(factory.params)) {
|
|
580
|
-
locals.add(node_id_1.NodeId.
|
|
584
|
+
locals.add(node_id_1.NodeId.recoverBareName(node_id_1.NodeId.normalize(param), idMap) ?? '');
|
|
581
585
|
}
|
|
582
586
|
return { factory: factory.id, locals };
|
|
583
587
|
}
|