@eagleoutice/flowr 2.17.3 → 2.17.5
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 +13 -52
- package/abstract-interpretation/absint-inference.js +1 -2
- package/abstract-interpretation/data-frame/arguments.d.ts +14 -3
- package/abstract-interpretation/data-frame/arguments.js +34 -0
- package/abstract-interpretation/data-frame/dataframe-semantics.js +7 -15
- package/abstract-interpretation/data-frame/resolve-args.d.ts +2 -2
- package/abstract-interpretation/data-frame/semantics.d.ts +8 -1
- package/abstract-interpretation/data-frame/semantics.js +14 -6
- package/abstract-interpretation/domains/state-abstract-domain.js +28 -18
- package/abstract-interpretation/domains/state-map.d.ts +43 -0
- package/abstract-interpretation/domains/state-map.js +147 -0
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +8 -7
- package/cli/repl/commands/repl-dataflow.js +5 -5
- package/cli/repl/commands/repl-execute.js +3 -2
- package/cli/repl/commands/repl-parse.js +2 -1
- package/cli/repl/commands/repl-signature.d.ts +1 -1
- package/cli/repl/completion.d.ts +23 -0
- package/cli/repl/completion.js +9 -0
- package/cli/repl/core.d.ts +0 -23
- package/cli/repl/core.js +0 -5
- package/cli/repl/parser/slice-query-parser.d.ts +1 -1
- package/cli/repl/parser/slice-query-parser.js +3 -3
- package/cli/repl/print-version.d.ts +1 -1
- package/cli/repl/print-version.js +2 -1
- package/cli/repl/server/connection.d.ts +1 -1
- package/cli/repl/server/connection.js +7 -9
- package/cli/slicer-app.js +2 -1
- package/clones/algorithms/baxter-ast.d.ts +33 -0
- package/clones/algorithms/baxter-ast.js +70 -0
- package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
- package/clones/algorithms/greedy-string-tiling.js +56 -0
- package/clones/algorithms/winnowing.d.ts +27 -0
- package/clones/algorithms/winnowing.js +66 -0
- package/clones/clone-ast.d.ts +75 -0
- package/clones/clone-ast.js +174 -0
- package/clones/clone-dataflow.d.ts +11 -0
- package/clones/clone-dataflow.js +83 -0
- package/clones/clone-detector.d.ts +116 -0
- package/clones/clone-detector.js +200 -0
- package/clones/clone-index.d.ts +54 -0
- package/clones/clone-index.js +56 -0
- package/config.d.ts +21 -2
- package/config.js +7 -1
- package/control-flow/basic-cfg-guided-visitor.js +1 -2
- package/control-flow/happens-before.d.ts +2 -0
- package/control-flow/happens-before.js +15 -9
- package/control-flow/simple-visitor.js +2 -4
- package/core/steps/all/core/00-parse.js +2 -1
- package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
- package/core/steps/all/core/10-normalize.js +2 -1
- package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
- package/core/steps/all/static-slicing/00-slice.js +2 -1
- package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
- package/core/steps/pipeline/create-pipeline.js +1 -2
- package/core/steps/pipeline/default-pipelines.d.ts +1 -1
- package/core/steps/pipeline/default-pipelines.js +5 -4
- package/core/steps/pipeline-step.d.ts +3 -1
- package/core/steps/pipeline-step.js +5 -0
- package/data/r-base-primitives.generated.d.ts +2 -1
- package/dataflow/cluster.js +1 -2
- package/dataflow/environments/ambient-state-name.d.ts +14 -22
- package/dataflow/environments/ambient-state-name.js +4 -18
- package/dataflow/environments/apply-kill.d.ts +9 -20
- package/dataflow/environments/apply-kill.js +51 -25
- package/dataflow/environments/built-in-config.d.ts +7 -15
- package/dataflow/environments/built-in-config.js +15 -16
- package/dataflow/environments/built-in-eval-name.d.ts +5 -6
- package/dataflow/environments/built-in-eval-name.js +4 -5
- package/dataflow/environments/built-in-kinds.d.ts +111 -0
- package/dataflow/environments/built-in-kinds.js +35 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +11 -0
- package/dataflow/environments/built-in-props.d.ts +66 -172
- package/dataflow/environments/built-in-props.js +47 -151
- package/dataflow/environments/built-in.d.ts +42 -76
- package/dataflow/environments/built-in.js +46 -66
- package/dataflow/environments/data-masking-functions.d.ts +2 -2
- package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
- package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
- package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/base-language.js +66 -0
- package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
- package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
- package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/database-access.js +16 -0
- package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
- package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
- package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
- package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/file-io.js +81 -0
- package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
- package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
- package/dataflow/environments/default-builtin-config/index.js +114 -0
- package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
- package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
- package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/network-access.js +47 -0
- package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
- package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
- package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
- package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
- package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
- package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
- package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
- package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
- package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
- package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
- package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
- package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
- package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/statistics.js +32 -0
- package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
- package/dataflow/environments/environment.d.ts +28 -52
- package/dataflow/environments/environment.js +24 -71
- package/dataflow/environments/group-generics.d.ts +12 -19
- package/dataflow/environments/group-generics.js +17 -14
- package/dataflow/environments/identifier.d.ts +72 -427
- package/dataflow/environments/identifier.js +34 -145
- package/dataflow/environments/pkg-name.d.ts +197 -0
- package/dataflow/environments/pkg-name.js +3 -0
- package/dataflow/environments/query-fn-props.d.ts +27 -76
- package/dataflow/environments/query-fn-props.js +34 -95
- package/dataflow/environments/resolve-by-name.d.ts +6 -16
- package/dataflow/environments/resolve-by-name.js +23 -35
- package/dataflow/environments/scoping.d.ts +5 -5
- package/dataflow/environments/scoping.js +13 -5
- package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
- package/dataflow/eval/resolve/alias-tracking.js +611 -126
- package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
- package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
- package/dataflow/eval/resolve/resolve-argument.js +35 -35
- package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
- package/dataflow/eval/resolve/resolve-field.js +127 -0
- package/dataflow/eval/resolve/resolve-numbers.d.ts +1 -178
- package/dataflow/eval/resolve/resolve-numbers.js +2 -13
- package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
- package/dataflow/eval/resolve/resolve-replacement.js +80 -0
- package/dataflow/eval/resolve/resolve-strings.d.ts +3 -95
- package/dataflow/eval/resolve/resolve-strings.js +2 -17
- package/dataflow/eval/resolve/resolve-working-directory.js +3 -4
- package/dataflow/eval/resolve/resolve.d.ts +13 -10
- package/dataflow/eval/resolve/resolve.js +81 -32
- package/dataflow/eval/values/general.d.ts +6 -24
- package/dataflow/eval/values/general.js +12 -29
- package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
- package/dataflow/eval/values/lists/list-constants.js +65 -0
- package/dataflow/eval/values/r-value.d.ts +20 -23
- package/dataflow/eval/values/r-value.js +22 -17
- package/dataflow/extractor.d.ts +2 -10
- package/dataflow/extractor.js +134 -62
- package/dataflow/fn/argument-roles.d.ts +2 -4
- package/dataflow/fn/argument-roles.js +49 -23
- package/dataflow/fn/class-declaration.d.ts +36 -52
- package/dataflow/fn/class-declaration.js +22 -56
- package/dataflow/fn/condition-handlers.d.ts +2 -1
- package/dataflow/fn/dispatch.d.ts +70 -0
- package/dataflow/fn/dispatch.js +434 -0
- package/dataflow/fn/exceptions-of-function.d.ts +1 -2
- package/dataflow/fn/exceptions-of-function.js +36 -106
- package/dataflow/fn/frame-reflection.d.ts +1 -3
- package/dataflow/fn/frame-reflection.js +8 -16
- package/dataflow/fn/function-props.d.ts +2 -5
- package/dataflow/fn/function-props.js +27 -36
- package/dataflow/fn/function-semantics.d.ts +14 -26
- package/dataflow/fn/function-semantics.js +4 -18
- package/dataflow/fn/higher-order-function.js +2 -4
- package/dataflow/fn/strict-function.d.ts +10 -35
- package/dataflow/fn/strict-function.js +126 -138
- package/dataflow/graph/ambient-access.d.ts +51 -0
- package/dataflow/graph/ambient-access.js +80 -0
- package/dataflow/graph/call-graph.d.ts +9 -29
- package/dataflow/graph/call-graph.js +17 -41
- package/dataflow/graph/closure-frames.d.ts +46 -0
- package/dataflow/graph/closure-frames.js +225 -0
- package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
- package/dataflow/graph/dataflowgraph-builder.js +29 -97
- package/dataflow/graph/df-helper.d.ts +48 -187
- package/dataflow/graph/df-helper.js +107 -207
- package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
- package/dataflow/graph/diff-dataflow-graph.js +25 -25
- package/dataflow/graph/edge.js +1 -1
- package/dataflow/graph/graph-helper.d.ts +10 -46
- package/dataflow/graph/graph-helper.js +16 -50
- package/dataflow/graph/graph.d.ts +44 -97
- package/dataflow/graph/graph.js +83 -79
- package/dataflow/graph/match-args.d.ts +21 -88
- package/dataflow/graph/match-args.js +284 -97
- package/dataflow/graph/vertex.d.ts +101 -128
- package/dataflow/graph/vertex.js +23 -20
- package/dataflow/hooks.d.ts +7 -14
- package/dataflow/hooks.js +15 -13
- package/dataflow/info.d.ts +2 -17
- package/dataflow/internal/dispatch-linking.d.ts +71 -0
- package/dataflow/internal/dispatch-linking.js +332 -0
- package/dataflow/internal/linker.d.ts +48 -50
- package/dataflow/internal/linker.js +458 -155
- package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +25 -69
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +292 -89
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +85 -64
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -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-s-three-dispatch.d.ts +8 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -34
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +42 -56
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +16 -22
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +39 -21
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +587 -107
- package/dataflow/internal/process/functions/call/common.d.ts +8 -24
- package/dataflow/internal/process/functions/call/common.js +24 -24
- package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
- package/dataflow/internal/process/functions/call/deferred.js +6 -27
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +7 -50
- package/dataflow/internal/process/functions/call/known-call-handling.js +14 -50
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
- package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
- package/dataflow/internal/process/functions/call/nse-kind.d.ts +24 -0
- package/dataflow/internal/process/functions/call/nse-kind.js +30 -0
- package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
- package/dataflow/internal/process/functions/call/nse.js +6 -13
- package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
- package/dataflow/internal/process/functions/call/quoted.js +26 -62
- package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
- package/dataflow/internal/process/functions/process-parameter.js +1 -1
- package/dataflow/internal/program-order.d.ts +3 -10
- package/dataflow/internal/program-order.js +19 -10
- package/dataflow/origin/dfg-get-origin.js +2 -1
- package/documentation/data/faq/faqs.js +16 -1
- package/documentation/data/interface/doc-writing-code.js +5 -7
- package/documentation/doc-capabilities.js +3 -3
- package/documentation/doc-readme.js +1 -1
- package/documentation/doc-util/doc-code.d.ts +0 -5
- package/documentation/doc-util/doc-code.js +2 -22
- package/documentation/doc-util/doc-query.d.ts +1 -2
- package/documentation/doc-util/doc-query.js +4 -5
- package/documentation/doc-util/doc-search.js +1 -1
- package/documentation/wiki-analyzer.js +4 -3
- package/documentation/wiki-core.js +5 -5
- package/documentation/wiki-dataflow-graph.js +6 -0
- package/documentation/wiki-interface.js +2 -1
- package/documentation/wiki-linter.js +15 -3
- package/documentation/wiki-linting-and-testing.js +15 -2
- package/documentation/wiki-query.js +114 -31
- package/index.d.ts +3 -1
- package/index.js +6 -3
- package/linter/linter-executor.js +1 -1
- package/linter/linter-rules.d.ts +37 -8
- package/linter/linter-rules.js +8 -1
- package/linter/linter-util.d.ts +3 -3
- package/linter/linter-util.js +1 -1
- package/linter/rules/absolute-path.js +5 -5
- package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
- package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
- package/linter/rules/cmd-check/call-arguments.js +5 -5
- package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
- package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
- package/linter/rules/cmd-check/dependency-declaration.js +3 -3
- package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
- package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
- package/linter/rules/cmd-check/file-checks.d.ts +2 -2
- package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
- package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
- package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
- package/linter/rules/cmd-check/non-ascii-code.js +1 -1
- package/linter/rules/cmd-check/package-files.d.ts +2 -2
- package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
- package/linter/rules/cmd-check/package-runtime.js +4 -4
- package/linter/rules/cmd-check/rd-files.js +2 -1
- package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
- package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
- package/linter/rules/code-clones.d.ts +57 -0
- package/linter/rules/code-clones.js +53 -0
- package/linter/rules/deprecated-functions.js +5 -8
- package/linter/rules/file-path-validity.js +11 -9
- package/linter/rules/function-finder-util.d.ts +4 -2
- package/linter/rules/function-finder-util.js +2 -2
- package/linter/rules/naming-convention.d.ts +6 -5
- package/linter/rules/naming-convention.js +2 -3
- package/linter/rules/no-leaked-credentials.d.ts +2 -1
- package/linter/rules/no-leaked-credentials.js +1 -1
- package/linter/rules/overwritten-file.d.ts +2 -1
- package/linter/rules/overwritten-file.js +2 -4
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +3 -3
- package/linter/rules/process-state-in-session.d.ts +7 -6
- package/linter/rules/process-state-in-session.js +1 -1
- package/linter/rules/roxygen-arguments.d.ts +1 -1
- package/linter/rules/secret-exfiltration.d.ts +3 -2
- package/linter/rules/secret-exfiltration.js +9 -4
- package/linter/rules/seeded-randomness.d.ts +3 -3
- package/linter/rules/unclosed-connection.js +1 -2
- package/linter/rules/undefined-symbol-util.d.ts +3 -2
- package/linter/rules/undefined-symbol.d.ts +3 -2
- package/linter/rules/unescaped-arguments.d.ts +1 -1
- package/linter/rules/unescaped-arguments.js +6 -8
- package/linter/rules/unused-definition.d.ts +4 -3
- package/linter/rules/unused-definition.js +10 -12
- package/linter/rules/unused-import.d.ts +6 -5
- package/linter/rules/unused-import.js +20 -6
- package/package.json +1 -1
- package/project/attached-packages.d.ts +5 -4
- package/project/cache/flowr-analyzer-cache.d.ts +14 -1
- package/project/cache/flowr-analyzer-cache.js +40 -3
- package/project/cache/flowr-analyzer-controlflow-cache.d.ts +0 -6
- package/project/cache/flowr-analyzer-controlflow-cache.js +7 -27
- package/project/context/flowr-analyzer-context.d.ts +2 -2
- package/project/context/flowr-analyzer-context.js +2 -2
- package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
- package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
- package/project/context/flowr-analyzer-environment-context.js +3 -3
- package/project/context/flowr-analyzer-files-context.d.ts +8 -0
- package/project/context/flowr-analyzer-files-context.js +51 -6
- package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
- package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
- package/project/context/flowr-analyzer-gas-context.js +34 -4
- package/project/dependency-version-space.d.ts +30 -29
- package/project/dependency-version-space.js +1 -2
- package/project/flowr-analyzer-builder.d.ts +2 -3
- package/project/flowr-analyzer.d.ts +35 -12
- package/project/flowr-analyzer.js +18 -33
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -17
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +57 -163
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -3
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -3
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -2
- package/project/plugins/package-version-plugins/package.d.ts +6 -5
- package/project/plugins/package-version-plugins/package.js +1 -1
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -3
- package/project/sigdb/build.js +1 -1
- package/project/sigdb/decode.d.ts +8 -7
- package/project/sigdb/decode.js +1 -2
- package/project/sigdb/dict.d.ts +2 -1
- package/project/sigdb/dict.js +2 -2
- package/project/sigdb/index-format.d.ts +2 -1
- package/project/sigdb/manifest.d.ts +1 -1
- package/project/sigdb/memory-source.d.ts +18 -17
- package/project/sigdb/on-demand/package-sources.d.ts +4 -3
- package/project/sigdb/on-demand/recoverer.d.ts +2 -1
- package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
- package/project/sigdb/reader.d.ts +85 -80
- package/project/sigdb/reader.js +0 -4
- package/project/sigdb/schema.d.ts +9 -8
- package/project/sigdb/signature-db.d.ts +6 -6
- package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
- package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
- package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
- package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
- package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
- package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
- package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
- package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
- package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
- package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
- package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
- package/queries/catalog/config-query/config-query-format.d.ts +1 -1
- package/queries/catalog/config-query/config-query-format.js +4 -4
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
- package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
- package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +11 -10
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +4 -6
- package/queries/catalog/dependencies-query/dependencies-query-format.js +12 -12
- package/queries/catalog/dependencies-query/dependency-values.d.ts +9 -0
- package/queries/catalog/dependencies-query/dependency-values.js +13 -0
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
- package/queries/catalog/dependencies-query/function-info/remote-functions.js +2 -2
- package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -7
- package/queries/catalog/dependencies-query/implicit-echo.js +4 -2
- package/queries/catalog/dependencies-query/plot-description.d.ts +1 -1
- package/queries/catalog/dependencies-query/plot-description.js +2 -2
- package/queries/catalog/dice-query/dice-query-format.d.ts +2 -1
- package/queries/catalog/dice-query/dice-query-format.js +1 -0
- package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
- package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
- package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
- package/queries/catalog/files-query/files-query-format.d.ts +1 -1
- package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
- package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
- package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
- package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.js +4 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
- package/queries/catalog/linter-query/linter-query-format.js +16 -11
- package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
- package/queries/catalog/origin-query/origin-query-format.js +1 -0
- package/queries/catalog/project-query/project-query-format.d.ts +2 -1
- package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
- package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
- package/queries/catalog/signature-query/signature-query-executor.d.ts +10 -7
- package/queries/catalog/signature-query/signature-query-executor.js +14 -15
- package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
- package/queries/catalog/signature-query/signature-query-render.js +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
- package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
- package/queries/catalog/taint-query/taint-query-format.d.ts +1 -1
- package/queries/query.d.ts +61 -10
- package/queries/query.js +59 -37
- package/r-bridge/data/data.d.ts +39 -28
- package/r-bridge/data/data.js +37 -28
- package/r-bridge/init.js +1 -1
- package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
- package/r-bridge/lang-4.x/ast/model/model.js +30 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
- package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
- package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/model/type.js +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
- package/r-bridge/parser.d.ts +8 -2
- package/r-bridge/parser.js +6 -0
- package/r-bridge/shell-executor.d.ts +2 -2
- package/r-bridge/shell-executor.js +3 -2
- package/r-bridge/shell.d.ts +2 -2
- package/r-bridge/shell.js +3 -2
- package/reconstruct/auto-select/magic-comments.js +1 -1
- package/reconstruct/reconstruct.d.ts +0 -5
- package/reconstruct/reconstruct.js +6 -5
- package/search/flowr-search-builder.d.ts +14 -0
- package/search/flowr-search-builder.js +7 -0
- package/search/flowr-search-executor.js +2 -2
- package/search/flowr-search-filters.js +10 -11
- package/search/flowr-search.js +1 -1
- package/search/search-executor/search-enrichers.d.ts +2 -0
- package/search/search-executor/search-enrichers.js +6 -1
- package/search/search-executor/search-generators.d.ts +2 -3
- package/search/search-executor/search-generators.js +18 -14
- package/search/search-executor/search-mappers.js +1 -1
- package/search/search-executor/search-transformer.d.ts +2 -2
- package/search/search-executor/search-transformer.js +6 -6
- package/search/search-logger.d.ts +1 -0
- package/search/search-logger.js +6 -0
- package/slicing/criterion/parse.d.ts +2 -1
- package/slicing/criterion/parse.js +2 -1
- package/slicing/static/removal-slice.js +2 -1
- package/slicing/static/slice-call.d.ts +30 -4
- package/slicing/static/slice-call.js +74 -9
- package/slicing/static/slicer-types.d.ts +2 -1
- package/slicing/static/static-slicer.js +66 -11
- package/slicing/static/visiting-queue.d.ts +2 -0
- package/slicing/static/visiting-queue.js +4 -0
- package/taint-analysis/builder/report-template.d.ts +3 -3
- package/util/arg-matching.d.ts +1 -1
- package/util/collections/relation.d.ts +23 -0
- package/util/collections/relation.js +63 -0
- package/util/fixpoint.d.ts +65 -0
- package/util/fixpoint.js +216 -0
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/json.d.ts +4 -0
- package/util/json.js +12 -3
- package/util/mermaid/cfg.js +1 -2
- package/util/mermaid/dfg.d.ts +1 -1
- package/util/mermaid/dfg.js +1 -1
- package/util/mermaid/mermaid.d.ts +2 -1
- package/util/monoid.d.ts +26 -0
- package/util/monoid.js +31 -0
- package/util/prefix.d.ts +1 -1
- package/util/r-base-packages.d.ts +10 -7
- package/util/r-base-packages.js +11 -6
- package/util/r-package-urls.d.ts +10 -9
- package/util/r-value.js +2 -1
- package/util/r-version-order.d.ts +2 -0
- package/util/r-version-order.js +19 -0
- package/util/r-version.d.ts +2 -1
- package/util/r-version.js +2 -14
- package/util/range.d.ts +38 -29
- package/util/range.js +10 -5
- package/util/simple-df/dfg-ascii.js +2 -2
- package/util/text/ansi.d.ts +13 -9
- package/util/text/ansi.js +4 -6
- package/util/text/strings.d.ts +10 -3
- package/util/text/strings.js +10 -1
- package/util/version.d.ts +1 -1
- package/util/version.js +2 -1
- package/dataflow/environments/default-builtin-config.d.ts +0 -8856
- package/dataflow/environments/default-builtin-config.js +0 -1735
- package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
- package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
- package/taint-analysis/eval/eval.d.ts +0 -1
- package/taint-analysis/eval/eval.js +0 -124
- package/taint-analysis/eval/instrumentation.d.ts +0 -59
- package/taint-analysis/eval/instrumentation.js +0 -124
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClosureRefs = void 0;
|
|
3
|
+
exports.ClosureRefs = exports.LinkedFunctionResolver = void 0;
|
|
4
4
|
exports.findNonLocalReads = findNonLocalReads;
|
|
5
5
|
exports.produceNameSharedIdMap = produceNameSharedIdMap;
|
|
6
|
+
exports.linkInstanceReads = linkInstanceReads;
|
|
7
|
+
exports.readsOfUncalledClosures = readsOfUncalledClosures;
|
|
6
8
|
exports.linkFunctionCallWithSingleTarget = linkFunctionCallWithSingleTarget;
|
|
9
|
+
exports.isWithinArgumentOf = isWithinArgumentOf;
|
|
7
10
|
exports.linkFunctionCalls = linkFunctionCalls;
|
|
8
11
|
exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
|
|
9
12
|
exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
|
|
@@ -11,12 +14,15 @@ exports.linkExpressionIn = linkExpressionIn;
|
|
|
11
14
|
exports.linkCallToDefinitions = linkCallToDefinitions;
|
|
12
15
|
exports.linkInputs = linkInputs;
|
|
13
16
|
exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
|
|
17
|
+
exports.linkWritesCarriedByLoop = linkWritesCarriedByLoop;
|
|
14
18
|
exports.reapplyLoopExitPoints = reapplyLoopExitPoints;
|
|
15
19
|
exports.accessedFieldName = accessedFieldName;
|
|
20
|
+
exports.recordFound = recordFound;
|
|
16
21
|
exports.linkFieldReads = linkFieldReads;
|
|
17
22
|
exports.bindAccessedField = bindAccessedField;
|
|
18
23
|
exports.separateClosureInstances = separateClosureInstances;
|
|
19
24
|
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
25
|
+
const arrays_1 = require("../../util/collections/arrays");
|
|
20
26
|
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
21
27
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
22
28
|
const function_semantics_1 = require("../fn/function-semantics");
|
|
@@ -28,24 +34,28 @@ const identifier_1 = require("../environments/identifier");
|
|
|
28
34
|
const logger_1 = require("../logger");
|
|
29
35
|
const edge_1 = require("../graph/edge");
|
|
30
36
|
const vertex_1 = require("../graph/vertex");
|
|
37
|
+
const environment_1 = require("../environments/environment");
|
|
31
38
|
const info_1 = require("../info");
|
|
32
39
|
const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
|
|
33
40
|
const r_number_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-number");
|
|
34
41
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
35
42
|
const unnamed_call_handling_1 = require("./process/functions/call/unnamed-call-handling");
|
|
43
|
+
const built_in_envir_utils_1 = require("./process/functions/call/built-in/built-in-envir-utils");
|
|
36
44
|
const built_in_proc_name_1 = require("../environments/built-in-proc-name");
|
|
37
45
|
const vertex_2 = require("../graph/vertex");
|
|
38
46
|
const resolve_helper_1 = require("../environments/resolve-helper");
|
|
47
|
+
const resolve_by_name_1 = require("../environments/resolve-by-name");
|
|
39
48
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
40
49
|
const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
41
50
|
const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
42
51
|
const df_helper_1 = require("../graph/df-helper");
|
|
52
|
+
const closure_frames_1 = require("../graph/closure-frames");
|
|
43
53
|
const ambient_state_name_1 = require("../environments/ambient-state-name");
|
|
54
|
+
const class_declaration_1 = require("../fn/class-declaration");
|
|
55
|
+
const fixpoint_1 = require("../../util/fixpoint");
|
|
44
56
|
const ValueFlowBits = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
|
|
45
57
|
const FCallLinkReadBits = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall;
|
|
46
|
-
/**
|
|
47
|
-
* Find all reads within the graph that do not reference a local definition in the graph.
|
|
48
|
-
*/
|
|
58
|
+
/** Find all reads within the graph that do not reference a local definition in the graph. */
|
|
49
59
|
function findNonLocalReads(graph, ignores = new Set()) {
|
|
50
60
|
const defs = new Set();
|
|
51
61
|
for (const tag of [vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition]) {
|
|
@@ -54,17 +64,18 @@ function findNonLocalReads(graph, ignores = new Set()) {
|
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
const nonLocalReads = [];
|
|
57
|
-
/* the tag already says what the reference is, so no vertex has to be fetched to decide */
|
|
58
|
-
for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function]]) {
|
|
59
|
-
for (const [nodeId] of graph.verticesOfType(tag)) {
|
|
60
|
-
if (ignores.has(nodeId)) {
|
|
67
|
+
/* the tag already says what the reference is, so no vertex has to be fetched to decide; the target of a replacement (`x$a <- v`) reads the binding it replaces as well */
|
|
68
|
+
for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function], [vertex_1.VertexType.VariableDefinition, identifier_1.ReferenceType.Unknown]]) {
|
|
69
|
+
for (const [nodeId, vertex] of graph.verticesOfType(tag)) {
|
|
70
|
+
if (ignores.has(nodeId) || (vertex_2.DfgVertex.isVariableDefinition(vertex) && !vertex.par)) {
|
|
61
71
|
continue;
|
|
62
72
|
}
|
|
63
73
|
/* control flow edges say nothing about what a name resolves to, so they do not count as a link */
|
|
64
74
|
let linked = false;
|
|
65
75
|
let nonLocal = false;
|
|
66
76
|
for (const [target, e] of graph.edgesFrom(nodeId)) {
|
|
67
|
-
|
|
77
|
+
/* a replacement target is defined by its call, it reads only the binding it replaces */
|
|
78
|
+
if (edge_1.DfEdge.isOnlyControlFlow(e) || (tag === vertex_1.VertexType.VariableDefinition && edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy))) {
|
|
68
79
|
continue;
|
|
69
80
|
}
|
|
70
81
|
linked = true;
|
|
@@ -80,9 +91,7 @@ function findNonLocalReads(graph, ignores = new Set()) {
|
|
|
80
91
|
}
|
|
81
92
|
return nonLocalReads;
|
|
82
93
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Produces a map from names to all identifier references sharing that name.
|
|
85
|
-
*/
|
|
94
|
+
/** Produces a map from names to all identifier references sharing that name. */
|
|
86
95
|
function produceNameSharedIdMap(references) {
|
|
87
96
|
const nameIdShares = new defaultmap_1.DefaultMap(() => []);
|
|
88
97
|
for (const reference of references) {
|
|
@@ -92,43 +101,121 @@ function produceNameSharedIdMap(references) {
|
|
|
92
101
|
}
|
|
93
102
|
return nameIdShares;
|
|
94
103
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
/** how many vertices the walk for the holders of an instance visits before it settles for what it found */
|
|
105
|
+
const MaxInstanceFlow = 64;
|
|
106
|
+
/** The definitions holding the instance a method call `receiver$m(...)` runs a method on: every variable the value of the receiver flows through (aliases, the parameters it is bound to, what called functions return) and the containers it is a field of, as the environment of the call knows them, with the tracked state they carry. */
|
|
107
|
+
function instanceHolders(receiver, graph, environment, idMap) {
|
|
108
|
+
const holders = [];
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
const todo = [receiver];
|
|
111
|
+
for (let id = todo.pop(); id !== undefined && seen.size < MaxInstanceFlow; id = todo.pop()) {
|
|
112
|
+
if (seen.has(id)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
seen.add(id);
|
|
116
|
+
const node = idMap.get(id);
|
|
117
|
+
if (r_argument_1.RArgument.is(node)) {
|
|
118
|
+
todo.push(...node.value ? [node.value.info.id] : []);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const vertex = graph.getVertex(id);
|
|
122
|
+
if (vertex_2.DfgVertex.isUse(vertex)) {
|
|
123
|
+
/* a `self` a method hands back is bound on the call to the instance */
|
|
124
|
+
todo.push(...df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall).filter(t => !node_id_1.NodeId.isBuiltIn(t)));
|
|
125
|
+
}
|
|
126
|
+
else if (vertex_2.DfgVertex.isFunctionCall(vertex)) {
|
|
127
|
+
/* an access hands back a field of what it accesses, a function what it returns */
|
|
128
|
+
todo.push(...df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Returns));
|
|
129
|
+
}
|
|
130
|
+
else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
|
|
131
|
+
const name = node_id_1.NodeId.recoverName(id, idMap);
|
|
132
|
+
const known = name === undefined ? undefined : resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Variable)?.find(d => d.nodeId === id);
|
|
133
|
+
holders.push(known ?? { nodeId: id, name, type: identifier_1.ReferenceType.Variable, definedAt: id, cds: undefined });
|
|
134
|
+
const value = df_helper_1.Dataflow.assignedValueOf(id, graph);
|
|
135
|
+
todo.push(...value === undefined ? df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.DefinedByOnCall) : [value]);
|
|
136
|
+
}
|
|
98
137
|
}
|
|
99
|
-
return
|
|
138
|
+
return holders;
|
|
100
139
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
140
|
+
/** Links the reads of the names a method sees its instance by (`self`, `private`, `.self`) to the definitions holding the instance the call runs the method on. */
|
|
141
|
+
function linkInstanceReads(graph, info, fn, environment, idMap) {
|
|
142
|
+
const bindings = fn.subflow.in.length === 0 ? undefined : (0, class_declaration_1.instanceBindingsOfMethod)(fn.id, graph, idMap);
|
|
143
|
+
const reads = bindings === undefined ? [] : fn.subflow.in.filter(r => r.name !== undefined && bindings.includes(identifier_1.Identifier.getName(r.name)));
|
|
144
|
+
if (reads.length === 0) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const call = idMap.get(info.id);
|
|
148
|
+
/* a method taken out of its instance first, `f <- o$m; f()`, still runs on that instance */
|
|
149
|
+
const accesses = r_function_call_1.RFunctionCall.isUnnamed(call) ? [call.calledFunction] : df_helper_1.Dataflow.targetsOf(graph, info.id, edge_1.EdgeType.Reads).map(d => idMap.get(df_helper_1.Dataflow.assignedValueOf(d, graph) ?? d));
|
|
150
|
+
const holders = accesses.flatMap(a => r_access_1.RAccess.is(a) ? instanceHolders(a.accessed.info.id, graph, environment, idMap) : []);
|
|
151
|
+
for (const read of reads) {
|
|
152
|
+
for (const holder of holders) {
|
|
153
|
+
if (fn.subflow.graph.has(holder.nodeId) || node_id_1.NodeId.isBuiltIn(holder.nodeId)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
graph.addEdge(read.nodeId, holder.nodeId, edge_1.EdgeType.DefinedByOnCall);
|
|
157
|
+
graph.addEdge(info.id, holder.nodeId, edge_1.EdgeType.DefinesOnCall);
|
|
158
|
+
linkFieldWritesOnCall(graph, info.id, fn.id, read.nodeId, holder.nodeId, holder.envState, idMap);
|
|
159
|
+
(0, built_in_envir_utils_1.readEnvironmentContents)(graph, info.id, holder);
|
|
160
|
+
}
|
|
110
161
|
}
|
|
111
|
-
return { current, level };
|
|
112
162
|
}
|
|
113
|
-
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
163
|
+
/** The function definition directly within `fn` that holds `id`, `undefined` if `id` is in the body of `fn` itself. */
|
|
164
|
+
function outermostClosureOf(id, fn, idMap) {
|
|
165
|
+
let closure;
|
|
166
|
+
for (const parent of model_1.RNode.iterateParents(idMap.get(id), idMap)) {
|
|
167
|
+
if (parent.info.id === fn) {
|
|
168
|
+
return closure;
|
|
169
|
+
}
|
|
170
|
+
else if (r_function_definition_1.RFunctionDefinition.is(parent)) {
|
|
171
|
+
closure = parent.info.id;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
/** Which free reads of the function `fn` are in a closure it makes without calling it: such a closure reads its free variables where it is called, which links them there (or, if nothing calls it, at the end of its scope), so a call of `fn` does not read them. */
|
|
177
|
+
function readsOfUncalledClosures(fn, subflow, graph, idMap) {
|
|
178
|
+
let called;
|
|
179
|
+
return read => {
|
|
180
|
+
const closure = subflow.graph.has(read) ? undefined : outermostClosureOf(read, fn, idMap);
|
|
181
|
+
if (closure === undefined) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (called === undefined) {
|
|
185
|
+
called = new Set();
|
|
186
|
+
for (const node of subflow.graph) {
|
|
187
|
+
if (vertex_2.DfgVertex.isFunctionCall(graph.getVertex(node))) {
|
|
188
|
+
df_helper_1.Dataflow.targetsOf(graph, node, edge_1.EdgeType.Calls).forEach(t => called?.add(t));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return !called.has(closure);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/** Links the free variables of the function `fnId` the call `info` runs to their definitions where the function was defined, as the environment of the call sees them. */
|
|
196
|
+
function linkFreeReads(graph, fnSubflow, fnId, info, idMap) {
|
|
117
197
|
const id = info.id;
|
|
118
198
|
const environment = info.environment;
|
|
119
199
|
if (environment !== undefined) {
|
|
120
200
|
let callee;
|
|
121
201
|
let lexical;
|
|
202
|
+
const instance = fnSubflow.in.length === 0 ? undefined : (0, class_declaration_1.instanceBindingsOfMethod)(fnId, graph, idMap);
|
|
203
|
+
const readWhereCalled = readsOfUncalledClosures(fnId, fnSubflow, graph, idMap);
|
|
122
204
|
/* for each open ingoing reference, try to resolve it here, and if so, add a read edge from the call to signal that it reads it */
|
|
123
205
|
for (const ingoing of fnSubflow.in) {
|
|
124
206
|
const name = ingoing.name;
|
|
125
|
-
if (name === undefined) {
|
|
207
|
+
if (name === undefined || instance?.includes(identifier_1.Identifier.getName(name)) || readWhereCalled(ingoing.nodeId)) {
|
|
126
208
|
continue;
|
|
127
209
|
}
|
|
128
210
|
/* a variable is looked up where the function was defined, global state (options, files, the working directory) is what it is where it is called */
|
|
129
|
-
const inCallee = ambient_state_name_1.AmbientStateName.is(name) ? undefined : (callee ??=
|
|
130
|
-
|
|
131
|
-
|
|
211
|
+
const inCallee = ambient_state_name_1.AmbientStateName.is(name) ? undefined : (callee ??= (info.name === undefined ? [] : resolve_helper_1.Resolve.byName(info.name, environment) ?? []).filter(identifier_1.hasEnvState).map(d => d.envState)).values().map(env => resolve_helper_1.Resolve.byNameAndType(name, env, ingoing.type)).find(assert_1.isNotUndefined);
|
|
212
|
+
let defs = inCallee ?? resolve_helper_1.Resolve.byNameAndType(name, ambient_state_name_1.AmbientStateName.is(name) ? environment : lexical ??= environment_1.REnvironment.visibleTo(fnSubflow.environment.level, environment), ingoing.type) ?? [];
|
|
213
|
+
/* R looks the methods of a dispatch up where the generic is called first */
|
|
214
|
+
if (ingoing.type === identifier_1.ReferenceType.S3MethodPrefix && inCallee === undefined) {
|
|
215
|
+
defs = (0, arrays_1.uniqueArrayMerge)(defs, resolve_helper_1.Resolve.byNameAndType(name, environment, ingoing.type) ?? []);
|
|
216
|
+
}
|
|
217
|
+
for (const def of defs) {
|
|
218
|
+
const { nodeId, type, value, definedAt, envState } = def;
|
|
132
219
|
/* the state an earlier run of the function left behind is what its next run reads */
|
|
133
220
|
if (fnSubflow.graph.has(nodeId) && !ambient_state_name_1.AmbientStateName.is(name) || node_id_1.NodeId.isBuiltIn(nodeId)) {
|
|
134
221
|
continue;
|
|
@@ -137,6 +224,7 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
137
224
|
graph.addEdge(id, nodeId, edge_1.EdgeType.DefinesOnCall);
|
|
138
225
|
if (envState !== undefined) {
|
|
139
226
|
linkFieldWritesOnCall(graph, id, fnId, ingoing.nodeId, nodeId, envState, idMap);
|
|
227
|
+
(0, built_in_envir_utils_1.readEnvironmentContents)(graph, id, def);
|
|
140
228
|
}
|
|
141
229
|
if (definedAt !== undefined && definedAt !== nodeId && !node_id_1.NodeId.isBuiltIn(definedAt)
|
|
142
230
|
&& graph.hasVertex(definedAt) && !vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(nodeId))) {
|
|
@@ -147,14 +235,23 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
147
235
|
graph.addEdge(id, v, edge_1.EdgeType.Calls);
|
|
148
236
|
graph.addEdge(ingoing.nodeId, v, edge_1.EdgeType.Calls);
|
|
149
237
|
const vInfo = graph.getVertex(v);
|
|
150
|
-
if (vertex_2.DfgVertex.isFunctionDefinition(vInfo) && !vInfo.mode?.includes(
|
|
151
|
-
(vInfo.mode ??= []).push(
|
|
238
|
+
if (vertex_2.DfgVertex.isFunctionDefinition(vInfo) && !vInfo.mode?.includes(vertex_1.FunctionDispatch.S7)) {
|
|
239
|
+
(vInfo.mode ??= []).push(vertex_1.FunctionDispatch.S7);
|
|
152
240
|
}
|
|
153
241
|
}
|
|
154
242
|
}
|
|
155
243
|
}
|
|
156
244
|
}
|
|
157
245
|
}
|
|
246
|
+
}
|
|
247
|
+
/** Links a function call with a single target function definition. */
|
|
248
|
+
function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoints, id: fnId, params, envOps }, info, idMap) {
|
|
249
|
+
const id = info.id;
|
|
250
|
+
const environment = info.environment;
|
|
251
|
+
linkFreeReads(graph, fnSubflow, fnId, info, idMap);
|
|
252
|
+
if (environment !== undefined) {
|
|
253
|
+
linkInstanceReads(graph, info, { subflow: fnSubflow, id: fnId }, environment, idMap);
|
|
254
|
+
}
|
|
158
255
|
for (const node of fnSubflow.graph) {
|
|
159
256
|
if (!vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(node)) || fieldAssignmentOf(node, idMap) === undefined) {
|
|
160
257
|
continue;
|
|
@@ -176,10 +273,27 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
|
|
|
176
273
|
graph.addEdge(id, fnId, edge_1.EdgeType.Calls);
|
|
177
274
|
const fn = idMap.get(fnId);
|
|
178
275
|
if (r_function_definition_1.RFunctionDefinition.is(fn)) {
|
|
179
|
-
|
|
276
|
+
const argToParam = function_semantics_1.FunctionSemantics.call.match.onCallAndLink(info.args, fn.parameters, graph);
|
|
277
|
+
applyForForcedArgs(graph, id, params, argToParam);
|
|
278
|
+
if (environment !== undefined) {
|
|
279
|
+
readArgumentContents(graph, info.id, environment, argToParam, envOps, idMap);
|
|
280
|
+
}
|
|
180
281
|
}
|
|
181
282
|
return exitPoints.filter(e => (0, info_1.doesExitPointPropagateCalls)(e.type));
|
|
182
283
|
}
|
|
284
|
+
/** A call reads everything written into an environment it hands to a parameter (see {@link readEnvironmentContents}), unless the body only writes into what the parameter holds, by writes each call replays (see {@link DeferredEnvOp}): `register <- function(env, f) env$h <- f` reads nothing of `env`, so one call does not read what another stored. */
|
|
285
|
+
function readArgumentContents(graph, call, environment, argToParam, envOps, idMap) {
|
|
286
|
+
const written = new Set(envOps?.filter(o => o.kind === vertex_1.EnvOpKind.Define || o.kind === vertex_1.EnvOpKind.Replace).map(o => o.envir));
|
|
287
|
+
for (const [arg, param] of argToParam) {
|
|
288
|
+
const value = r_argument_1.RArgument.valueOf(idMap.get(arg)) ?? idMap.get(arg);
|
|
289
|
+
if (!r_symbol_1.RSymbol.is(value) || df_helper_1.Dataflow.sourcesOf(graph, param, edge_1.EdgeType.Reads).every(r => written.has(r))) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
for (const holder of resolve_helper_1.Resolve.byName(value.content, environment) ?? []) {
|
|
293
|
+
(0, built_in_envir_utils_1.readEnvironmentContents)(graph, call, holder);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
183
297
|
/** for each parameter that we link that gets forced, add a reads edge from the call to argument to show that it reads it */
|
|
184
298
|
function applyForForcedArgs(graph, callId, readParams, argToParam) {
|
|
185
299
|
for (const [arg, param] of argToParam) {
|
|
@@ -201,7 +315,9 @@ function linkFieldWritesOnCall(graph, id, fnId, start, binding, envState, idMap)
|
|
|
201
315
|
}
|
|
202
316
|
}
|
|
203
317
|
for (const read of aliases) {
|
|
204
|
-
|
|
318
|
+
if (envState !== undefined) {
|
|
319
|
+
bindAccessedField(graph, read, envState, idMap, id);
|
|
320
|
+
}
|
|
205
321
|
const write = fieldAssignmentOf(read, idMap);
|
|
206
322
|
if (write !== undefined) {
|
|
207
323
|
graph.addEdge(id, write, edge_1.EdgeType.Reads);
|
|
@@ -214,17 +330,31 @@ function linkFieldWritesOnCall(graph, id, fnId, start, binding, envState, idMap)
|
|
|
214
330
|
}
|
|
215
331
|
}
|
|
216
332
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Whether the call `info` may get its function from `target`, which it has the edge `e` to. An unnamed call reads
|
|
219
|
-
* the expression that gives its function. A named call that only reads another call reads state that call wrote,
|
|
220
|
-
* like the options, unless that call binds the name. No call binds a name that resolves to nothing (`unbound`),
|
|
221
|
-
* and a call processed by default (`options()`, `par()`) binds no name at all.
|
|
222
|
-
*/
|
|
333
|
+
/** Whether the call `info` may get its function from `target`, which it has the edge `e` to. */
|
|
223
334
|
function mayBeFunctionSource(graph, info, target, e, unbound = false) {
|
|
335
|
+
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall)) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
else if (isWithinArgumentOf(graph, info.id, target)) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
224
341
|
const vertex = graph.getVertex(target);
|
|
225
|
-
return vertex_2.DfgVertex.hasOrigin(info, built_in_proc_name_1.BuiltInProcName.Unnamed) ||
|
|
342
|
+
return vertex_2.DfgVertex.hasOrigin(info, built_in_proc_name_1.BuiltInProcName.Unnamed) || !vertex_2.DfgVertex.isFunctionCall(vertex)
|
|
226
343
|
|| (!unbound && (vertex.origin === 'unnamed' || vertex.origin.some(o => o !== built_in_proc_name_1.BuiltInProcName.Default)));
|
|
227
344
|
}
|
|
345
|
+
/** Whether `target` lies within an argument of `call`, which the call reads when it forces that argument, not to find its function. */
|
|
346
|
+
function isWithinArgumentOf(graph, call, target) {
|
|
347
|
+
const idMap = graph.idMap;
|
|
348
|
+
if (idMap === undefined) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
for (let node = idMap.get(target); node !== undefined && node.info.id !== call; node = model_1.RNode.directParent(node, idMap)) {
|
|
352
|
+
if (df_helper_1.Dataflow.hasEdge(graph, call, node.info.id, edge_1.EdgeType.Argument)) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
228
358
|
function linkFunctionCall(graph, id, info, idMap, isRoot) {
|
|
229
359
|
const readIds = new Set();
|
|
230
360
|
for (const [t, e] of graph.edgesFrom(id)) {
|
|
@@ -247,10 +377,7 @@ function linkFunctionCall(graph, id, info, idMap, isRoot) {
|
|
|
247
377
|
const calledBuiltIns = builtIns.size > 0 ? [...builtIns] : undefined;
|
|
248
378
|
return { functionCall: id, called: [...functionDefs], propagateExitPoints, calledBuiltIns };
|
|
249
379
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Returns the called functions within `graph` (ideally a superset of `thisGraph`, the graph searched for calls), which
|
|
252
|
-
* can be used to merge the environments with the call; also links the corresponding arguments.
|
|
253
|
-
*/
|
|
380
|
+
/** Returns the called functions within `graph` (ideally a superset of `thisGraph`, the graph searched for calls), which can be used to merge the environments with the call; also links the corresponding arguments. */
|
|
254
381
|
function linkFunctionCalls(graph, idMap, thisGraph,
|
|
255
382
|
/** calls `graph` knows of that `thisGraph` does not, as a read that became a call */
|
|
256
383
|
alsoCalls = []) {
|
|
@@ -269,10 +396,10 @@ alsoCalls = []) {
|
|
|
269
396
|
return called.filter(assert_1.isNotUndefined);
|
|
270
397
|
}
|
|
271
398
|
/**
|
|
272
|
-
* convenience function returning all known call targets, as well as the name source which defines them
|
|
399
|
+
* convenience function returning all known call targets, as well as the name source which defines them Over-approximates for calls through reads and aliases (all functions the read may evaluate to are returned).
|
|
273
400
|
* @useInstead {@link Dataflow.callTargetsOf}
|
|
274
401
|
*/
|
|
275
|
-
function getAllFunctionCallTargets(call, graph, environment) {
|
|
402
|
+
function getAllFunctionCallTargets(call, graph, environment, resolver) {
|
|
276
403
|
const info = graph.getVertex(call);
|
|
277
404
|
if (!vertex_2.DfgVertex.isFunctionCall(info)) {
|
|
278
405
|
return [];
|
|
@@ -295,78 +422,194 @@ function getAllFunctionCallTargets(call, graph, environment) {
|
|
|
295
422
|
if (functionCallDefs.length === 0) {
|
|
296
423
|
return [];
|
|
297
424
|
}
|
|
298
|
-
const
|
|
299
|
-
|
|
425
|
+
const reads = new Set(functionCallDefs);
|
|
426
|
+
const shared = resolver ?? graph.sharedTargetWalks(g => new LinkedFunctionResolver(g));
|
|
427
|
+
const [targets, builtIns] = shared?.resolve(reads) ?? getAllLinkedFunctionDefinitions(reads, graph);
|
|
428
|
+
const all = new Set([...targets.values().map(t => t.id), ...builtIns, ...functionCallDefs]);
|
|
429
|
+
/* the methods its dispatch rules out are still found by the name */
|
|
430
|
+
info.ruledOut?.forEach(e => all.delete(e));
|
|
431
|
+
return [...all];
|
|
300
432
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Finds all linked function definitions starting from the given read ids; expects the caller to already have resolved
|
|
303
|
-
* the accessed objects (first layer of reads/returns/calls/...). For call targets, use {@link Dataflow.callTargetsOf} instead.
|
|
304
|
-
*/
|
|
433
|
+
/** Finds all linked function definitions starting from the given read ids; expects the caller to already have resolved the accessed objects (first layer of reads/returns/calls/...). */
|
|
305
434
|
function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGraph) {
|
|
306
435
|
const result = new Set();
|
|
307
436
|
const builtIns = new Set();
|
|
308
|
-
/* `call` is the call whose return led into the current body, so a parameter it binds holds only what it passes */
|
|
309
437
|
const potential = Array.from(functionDefinitionReadIds, id => [id, false, undefined]);
|
|
310
|
-
|
|
311
|
-
const expanded = new
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
438
|
+
/* the calls each vertex was expanded under, by whether an access led to it */
|
|
439
|
+
const expanded = [new Map(), new Map()];
|
|
440
|
+
const scopes = new Map();
|
|
441
|
+
const next = (id, viaAccess, call) => {
|
|
442
|
+
if (expanded[viaAccess ? 1 : 0].get(id)?.has(call) !== true) {
|
|
443
|
+
potential.push([id, viaAccess, call]);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
for (let item = potential.pop(); item !== undefined; item = potential.pop()) {
|
|
447
|
+
const [cid, viaAccess, call] = item;
|
|
448
|
+
const done = expanded[viaAccess ? 1 : 0];
|
|
449
|
+
const calls = done.get(cid);
|
|
450
|
+
/* without a call nothing restricts the walk, so that visit covers those under any call */
|
|
451
|
+
if (calls === undefined) {
|
|
452
|
+
done.set(cid, new Set([call]));
|
|
453
|
+
}
|
|
454
|
+
else if (calls.has(call) || calls.has(undefined)) {
|
|
318
455
|
continue;
|
|
319
456
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (node_id_1.NodeId.isBuiltIn(cid)) {
|
|
323
|
-
builtIns.add(cid);
|
|
324
|
-
continue;
|
|
457
|
+
else {
|
|
458
|
+
calls.add(call);
|
|
325
459
|
}
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
460
|
+
const end = walkLinkedDefinitions(dataflowGraph, cid, viaAccess, call, scopes, next);
|
|
461
|
+
if (end === undefined) {
|
|
328
462
|
continue;
|
|
329
463
|
}
|
|
330
|
-
else if (
|
|
331
|
-
|
|
332
|
-
continue;
|
|
464
|
+
else if (node_id_1.NodeId.isBuiltIn(end)) {
|
|
465
|
+
builtIns.add(end);
|
|
333
466
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
467
|
+
else {
|
|
468
|
+
result.add(dataflowGraph.getVertex(end));
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return [result, builtIns];
|
|
472
|
+
}
|
|
473
|
+
/** One step of the walk for the function definitions that reads may evaluate to: hands each state the walk goes on to from `id` to `next`, or returns `id` if the walk ends at it, being a built-in or a function definition. */
|
|
474
|
+
function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next) {
|
|
475
|
+
if (node_id_1.NodeId.isBuiltIn(id)) {
|
|
476
|
+
return id;
|
|
477
|
+
}
|
|
478
|
+
const vertex = graph.getVertex(id);
|
|
479
|
+
if (vertex === undefined) {
|
|
480
|
+
return undefined;
|
|
481
|
+
}
|
|
482
|
+
else if (vertex.subflow !== undefined) {
|
|
483
|
+
return id;
|
|
484
|
+
}
|
|
485
|
+
else if (!viaAccess && vertex_2.DfgVertex.isValue(vertex)) {
|
|
486
|
+
for (const named of functionsNamedBy(graph, id)) {
|
|
487
|
+
next(named, false, undefined);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const nextViaAccess = viaAccess || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access);
|
|
491
|
+
const isSkipType = vertex_2.DfgVertex.isFunctionCall(vertex);
|
|
492
|
+
/* a replacement keeps its target what it was (`environment(f) <- e` leaves `f` the same function), unless the call is to what it put into a part of it, so the walk goes on to the binding it replaces only */
|
|
493
|
+
const replaces = vertex_2.DfgVertex.isVariableDefinition(vertex) && vertex.par && !nextViaAccess;
|
|
494
|
+
let hasReturnEdge = false;
|
|
495
|
+
let followTargets;
|
|
496
|
+
/* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
|
|
497
|
+
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;
|
|
498
|
+
/* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
|
|
499
|
+
const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? id : call;
|
|
500
|
+
for (const [target, e] of graph.edgesFrom(id)) {
|
|
501
|
+
if (edge_1.DfEdge.includesType(e, handedBack)) {
|
|
502
|
+
hasReturnEdge = true;
|
|
503
|
+
next(target, nextViaAccess, returnedTo === call ? scopedTo(graph, scopes, call, target) : returnedTo);
|
|
504
|
+
}
|
|
505
|
+
else if (!isSkipType && !hasReturnEdge && edge_1.DfEdge.includesType(e, ValueFlowBits) && edge_1.DfEdge.doesNotIncludeType(e, replaces ? edge_1.EdgeType.SideEffectOnCall | edge_1.EdgeType.DefinedBy : edge_1.EdgeType.SideEffectOnCall)) {
|
|
506
|
+
(followTargets ??= []).push([target, edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)]);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!hasReturnEdge && followTargets) {
|
|
510
|
+
/* a parameter the call binds holds only what that call passes, the walk then goes on in the caller */
|
|
511
|
+
const passed = call === undefined ? undefined : new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Argument));
|
|
512
|
+
const bound = followTargets.some(([target, onCall]) => onCall && passed?.has(target));
|
|
513
|
+
for (const [target, onCall] of followTargets) {
|
|
514
|
+
if (!bound || !onCall || passed?.has(target)) {
|
|
515
|
+
next(target, nextViaAccess, onCall ? undefined : scopedTo(graph, scopes, call, target));
|
|
351
516
|
}
|
|
352
517
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
518
|
+
}
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
/** A string where a function is wanted names the function (`match.fun`, `do.call` and the apply family look it up), which is resolved where the string is written, by the environment of the call it is passed to. */
|
|
522
|
+
function functionsNamedBy(graph, id) {
|
|
523
|
+
const idMap = graph.idMap;
|
|
524
|
+
const node = idMap?.get(id);
|
|
525
|
+
if (idMap === undefined || !r_string_1.RString.is(node)) {
|
|
526
|
+
return [];
|
|
527
|
+
}
|
|
528
|
+
for (let at = model_1.RNode.directParent(node, idMap); at !== undefined; at = model_1.RNode.directParent(at, idMap)) {
|
|
529
|
+
const call = graph.getVertex(at.info.id);
|
|
530
|
+
if (vertex_2.DfgVertex.isFunctionCall(call) && call.environment !== undefined) {
|
|
531
|
+
return resolve_helper_1.Resolve.byNameAndType(node.content.str, call.environment, identifier_1.ReferenceType.Function)?.map(d => d.nodeId) ?? [];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return [];
|
|
535
|
+
}
|
|
536
|
+
/** The call that restricts what `target` may hold: a call binds only the parameters of the functions it runs, so once the walk leaves their bodies (to a global, say), the call restricts nothing any more. */
|
|
537
|
+
function scopedTo(graph, scopes, call, target) {
|
|
538
|
+
const idMap = graph.idMap;
|
|
539
|
+
if (call === undefined || idMap === undefined) {
|
|
540
|
+
return call;
|
|
541
|
+
}
|
|
542
|
+
let bodies = scopes.get(call);
|
|
543
|
+
if (bodies === undefined) {
|
|
544
|
+
bodies = new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns).map(t => model_1.RNode.findEnclosing(t, idMap, r_function_definition_1.RFunctionDefinition.is)).filter(assert_1.isNotUndefined));
|
|
545
|
+
scopes.set(call, bodies);
|
|
546
|
+
}
|
|
547
|
+
for (let node = idMap.get(target); node !== undefined; node = model_1.RNode.directParent(node, idMap)) {
|
|
548
|
+
if (bodies.has(node.info.id)) {
|
|
549
|
+
return call;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
const ReachesNothing = new Set();
|
|
555
|
+
/** Finds the function definitions and built-ins that reads may evaluate to (see {@link getAllLinkedFunctionDefinitions}). */
|
|
556
|
+
class LinkedFunctionResolver {
|
|
557
|
+
graph;
|
|
558
|
+
/** the number of each state, by whether an access led to it, its vertex, and its call */
|
|
559
|
+
numbers = [new Map(), new Map()];
|
|
560
|
+
states = [];
|
|
561
|
+
/** the built-ins and function definitions the walk ends at, by their state */
|
|
562
|
+
ends = new Map();
|
|
563
|
+
scopes = new Map();
|
|
564
|
+
summaries;
|
|
565
|
+
constructor(graph) {
|
|
566
|
+
this.graph = graph;
|
|
567
|
+
this.summaries = new fixpoint_1.ReachSummaries(state => this.expand(state), state => this.ends.get(state), { empty: ReachesNothing, concat: fixpoint_1.unionOfSets });
|
|
568
|
+
}
|
|
569
|
+
/** The function definitions and built-ins the reads with the given ids may evaluate to. */
|
|
570
|
+
resolve(reads) {
|
|
571
|
+
const definitions = new Set();
|
|
572
|
+
const builtIns = new Set();
|
|
573
|
+
for (const read of reads) {
|
|
574
|
+
for (const id of this.summaries.of(this.state(read, false, undefined))) {
|
|
575
|
+
if (node_id_1.NodeId.isBuiltIn(id)) {
|
|
576
|
+
builtIns.add(id);
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
definitions.add(this.graph.getVertex(id));
|
|
361
580
|
}
|
|
362
581
|
}
|
|
363
582
|
}
|
|
583
|
+
return [definitions, builtIns];
|
|
584
|
+
}
|
|
585
|
+
state(id, viaAccess, call) {
|
|
586
|
+
const byCall = this.numbers[viaAccess ? 1 : 0].get(id) ?? new Map();
|
|
587
|
+
let state = byCall.get(call);
|
|
588
|
+
if (state === undefined) {
|
|
589
|
+
state = this.states.push([id, viaAccess, call]) - 1;
|
|
590
|
+
if (byCall.size === 0) {
|
|
591
|
+
this.numbers[viaAccess ? 1 : 0].set(id, byCall);
|
|
592
|
+
}
|
|
593
|
+
byCall.set(call, state);
|
|
594
|
+
}
|
|
595
|
+
return state;
|
|
596
|
+
}
|
|
597
|
+
/** The states the walk goes on to from `state`, none for a built-in or function definition it ends at. */
|
|
598
|
+
expand(state) {
|
|
599
|
+
const [id, viaAccess, call] = this.states[state];
|
|
600
|
+
const successors = [];
|
|
601
|
+
const end = walkLinkedDefinitions(this.graph, id, viaAccess, call, this.scopes, (target, nextViaAccess, nextCall) => {
|
|
602
|
+
successors.push(this.state(target, nextViaAccess, nextCall));
|
|
603
|
+
});
|
|
604
|
+
if (end !== undefined) {
|
|
605
|
+
this.ends.set(state, new Set([end]));
|
|
606
|
+
}
|
|
607
|
+
return successors;
|
|
364
608
|
}
|
|
365
|
-
return [result, builtIns];
|
|
366
609
|
}
|
|
610
|
+
exports.LinkedFunctionResolver = LinkedFunctionResolver;
|
|
367
611
|
/**
|
|
368
|
-
* Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
|
|
369
|
-
* hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
|
|
612
|
+
* Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and hands back what stays unresolved.
|
|
370
613
|
* @useInstead {@link FunctionSemantics.call.quoted.evaluateIn}
|
|
371
614
|
*/
|
|
372
615
|
function linkExpressionIn(graph, expr, environment, idMap) {
|
|
@@ -405,14 +648,10 @@ function linkCallToDefinitions(graph, callId, definitions, idMap) {
|
|
|
405
648
|
}
|
|
406
649
|
}
|
|
407
650
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or
|
|
410
|
-
* links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
|
|
411
|
-
* @param alsoFrom - a node that reads every definition found as well
|
|
412
|
-
*/
|
|
651
|
+
/** Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned. */
|
|
413
652
|
function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation, givenInputs, graph, maybeForRemaining, alsoFrom) {
|
|
414
653
|
for (const bodyInput of referencesToLinkAgainstEnvironment) {
|
|
415
|
-
const probableTarget = bodyInput.name ? resolve_helper_1.Resolve.byNameAndType(bodyInput.name, environmentInformation, bodyInput.type) : undefined;
|
|
654
|
+
const probableTarget = bodyInput.name ? resolve_helper_1.Resolve.byNameAndType(identifier_1.Identifier.boundAs(bodyInput.name), (0, resolve_by_name_1.scopeOf)(bodyInput, environmentInformation), bodyInput.type) : undefined;
|
|
416
655
|
if (probableTarget === undefined) {
|
|
417
656
|
if (maybeForRemaining) {
|
|
418
657
|
bodyInput.cds ??= [];
|
|
@@ -433,22 +672,21 @@ function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation,
|
|
|
433
672
|
}
|
|
434
673
|
return givenInputs;
|
|
435
674
|
}
|
|
436
|
-
/**
|
|
437
|
-
* A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the
|
|
438
|
-
* prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit.
|
|
439
|
-
*/
|
|
675
|
+
/** A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit, which the calls in the loop see as well (see {@link linkLoopCarriedCalls}). */
|
|
440
676
|
function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environment) {
|
|
441
677
|
if (environment !== undefined) {
|
|
442
678
|
const outgoingIds = new Set(outgoing.map(o => o.nodeId));
|
|
443
679
|
for (const [name, targets] of openIns.entries()) {
|
|
444
680
|
for (const def of environment.current.memory.get(identifier_1.Identifier.getName(name)) ?? []) {
|
|
445
|
-
|
|
681
|
+
/* a definition within an argument of a call (`f(x <- x + 1)`) is made in the loop as well, if it is made at all */
|
|
682
|
+
if (outgoingIds.has(def.nodeId) || vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(def.nodeId))) {
|
|
446
683
|
for (const target of targets) {
|
|
447
684
|
graph.addEdge(target.nodeId, def.nodeId, edge_1.EdgeType.Reads);
|
|
448
685
|
}
|
|
449
686
|
}
|
|
450
687
|
}
|
|
451
688
|
}
|
|
689
|
+
linkLoopCarriedCalls(graph, environment, outgoingIds, new Set(outgoing.map(o => identifier_1.Identifier.getName(o.name))));
|
|
452
690
|
return;
|
|
453
691
|
}
|
|
454
692
|
/* fallback: keep only the last definition per identifier (used when no environment is available) */
|
|
@@ -468,6 +706,76 @@ function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environm
|
|
|
468
706
|
}
|
|
469
707
|
}
|
|
470
708
|
}
|
|
709
|
+
/** A call in a loop runs again after the rest of the body ran, so it sees what the body leaves behind as well (`environment`), and so do the free variables of the closures it calls: in `f <- function() x; for(i in 1:2) { y <- f(); x <- 2 }` the second call of `f` reads `x <- 2`. */
|
|
710
|
+
function linkLoopCarriedCalls(graph, environment, made, names) {
|
|
711
|
+
const idMap = graph.idMap;
|
|
712
|
+
for (const [id, info] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
713
|
+
if (info.onlyBuiltin || info.environment?.level !== environment.level) {
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
info.environment = environment_1.REnvironment.append(info.environment, idMap === undefined ? environment : carriedTo(graph, info, info.environment, environment, made, names, idMap));
|
|
717
|
+
for (const target of idMap === undefined ? [] : df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)) {
|
|
718
|
+
const fn = graph.getVertex(target);
|
|
719
|
+
if (vertex_2.DfgVertex.isFunctionDefinition(fn)) {
|
|
720
|
+
linkFreeReads(graph, fn.subflow, target, info, idMap);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
/** What `exit` carries into the next run for the call `info`, without the `names` the body (`made`) surely binds anew before the call: a binding the call sees that the body makes in an earlier statement, under no condition the call is not under as well. */
|
|
726
|
+
function carriedTo(graph, info, atCall, exit, made, names, idMap) {
|
|
727
|
+
let carried;
|
|
728
|
+
const call = idMap.get(info.id);
|
|
729
|
+
for (const name of names) {
|
|
730
|
+
const defs = name === undefined || exit.current.memory.get(name) === undefined ? undefined : atCall.current.memory.get(name);
|
|
731
|
+
if (defs?.some(d => made.has(d.nodeId) && info_1.ControlDependency.minus(graph.getVertex(d.nodeId)?.cds ?? [], info.cds ?? []).length === 0 && model_1.RNode.precedesInBlock(idMap.get(d.nodeId), call, idMap))) {
|
|
732
|
+
carried ??= exit.current.clone(false);
|
|
733
|
+
carried.writableMemory.delete(name);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return carried === undefined ? exit : { current: carried, level: exit.level };
|
|
737
|
+
}
|
|
738
|
+
/** A call in a loop runs again, so what its callee writes reaches the reads of the loop before the call as well: in `ch <- function() g <<- 2; for(i in 1:2) { s <- g; ch() }` the second `s <- g` reads `g <<- 2`. */
|
|
739
|
+
function linkWritesCarriedByLoop(graph, call, written, idMap) {
|
|
740
|
+
let loop;
|
|
741
|
+
for (let node = idMap.get(call); node !== undefined && !r_function_definition_1.RFunctionDefinition.is(node); node = model_1.RNode.directParent(node, idMap)) {
|
|
742
|
+
if (model_1.RLoopConstructs.is(node)) {
|
|
743
|
+
loop = node;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (loop === undefined || written.length === 0) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
const byName = new Map();
|
|
750
|
+
for (const def of written) {
|
|
751
|
+
if (def.name !== undefined) {
|
|
752
|
+
const name = identifier_1.Identifier.getName(def.name);
|
|
753
|
+
byName.set(name, [...byName.get(name) ?? [], def]);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const writtenAs = (name) => name === undefined ? undefined : byName.get(identifier_1.Identifier.getName(name));
|
|
757
|
+
for (const id of model_1.RNode.collectAllIdsWithStop(loop, r_function_definition_1.RFunctionDefinition.is)) {
|
|
758
|
+
const vertex = graph.getVertex(id);
|
|
759
|
+
if (!vertex_2.DfgVertex.isUse(vertex) && !vertex_2.DfgVertex.isFunctionCall(vertex)) {
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
for (const def of writtenAs(vertex_2.DfgVertex.isFunctionCall(vertex) ? vertex.name : node_id_1.NodeId.recoverBareName(id, idMap)) ?? []) {
|
|
763
|
+
graph.addEdge(id, def.nodeId, edge_1.EdgeType.Reads);
|
|
764
|
+
if (vertex_2.DfgVertex.isFunctionCall(vertex)) {
|
|
765
|
+
getAllLinkedFunctionDefinitions(new Set([def.nodeId]), graph)[0].forEach(fn => graph.addEdge(id, fn.id, edge_1.EdgeType.Calls));
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
for (const target of vertex_2.DfgVertex.isFunctionCall(vertex) ? df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls) : []) {
|
|
769
|
+
const fn = graph.getVertex(target);
|
|
770
|
+
for (const ingoing of vertex_2.DfgVertex.isFunctionDefinition(fn) ? fn.subflow.in : []) {
|
|
771
|
+
for (const def of writtenAs(ingoing.name) ?? []) {
|
|
772
|
+
graph.addEdge(ingoing.nodeId, def.nodeId, edge_1.EdgeType.DefinedByOnCall);
|
|
773
|
+
graph.addEdge(id, def.nodeId, edge_1.EdgeType.DefinesOnCall);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
471
779
|
function addControlDependency(holder, cd) {
|
|
472
780
|
if (holder.cds?.some(c => c.id === cd.id)) {
|
|
473
781
|
return false;
|
|
@@ -475,9 +783,7 @@ function addControlDependency(holder, cd) {
|
|
|
475
783
|
holder.cds = [...holder.cds ?? [], cd];
|
|
476
784
|
return true;
|
|
477
785
|
}
|
|
478
|
-
/**
|
|
479
|
-
* Reapplies the loop exit points' control dependencies to the given identifier references.
|
|
480
|
-
*/
|
|
786
|
+
/** Reapplies the loop exit points' control dependencies to the given identifier references. */
|
|
481
787
|
function reapplyLoopExitPoints(exits, references, graph) {
|
|
482
788
|
const exitCds = exits.flatMap(e => e.cds?.map(info_1.negateControlDependency))
|
|
483
789
|
.filter(assert_1.isNotUndefined)
|
|
@@ -505,10 +811,7 @@ function reapplyLoopExitPoints(exits, references, graph) {
|
|
|
505
811
|
*/
|
|
506
812
|
exports.ClosureRefs = {
|
|
507
813
|
name: 'ClosureRefs',
|
|
508
|
-
/**
|
|
509
|
-
* Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
|
|
510
|
-
* links what resolves, and leaves only the references that stay open.
|
|
511
|
-
*/
|
|
814
|
+
/** Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`, links what resolves, and leaves only the references that stay open. */
|
|
512
815
|
resolveOpenIngoing(graph, callId, definition, environment) {
|
|
513
816
|
definition.subflow.in = linkInputs(definition.subflow.in, environment, [], graph, false, callId);
|
|
514
817
|
}
|
|
@@ -524,11 +827,23 @@ function accessedFieldName(fieldNode, treatIndicesAsString) {
|
|
|
524
827
|
return r_number_1.RNumber.is(fieldNode) && !fieldNode.content.complexNumber && Number.isInteger(fieldNode.content.num) && fieldNode.content.num > 0
|
|
525
828
|
? String(fieldNode.content.num) : undefined;
|
|
526
829
|
}
|
|
527
|
-
/**
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
830
|
+
/** Adds the definitions `found` to what the lookup `lookup` finds where it is written, or when `call` runs it, see {@link DataflowGraphVertexFunctionCall#found} and {@link DataflowGraphVertexFunctionCall#foundOnCall}. */
|
|
831
|
+
function recordFound(graph, lookup, found, call) {
|
|
832
|
+
const vertex = graph.getVertex(lookup);
|
|
833
|
+
if (found.length === 0 || !vertex_2.DfgVertex.isFunctionCall(vertex)) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
else if (call === undefined) {
|
|
837
|
+
vertex.found = vertex.found === undefined ? found : (0, arrays_1.uniqueArrayMerge)(vertex.found, found);
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const known = vertex.foundOnCall?.find(f => f.call === call);
|
|
841
|
+
const entry = { call, found: known === undefined ? found : (0, arrays_1.uniqueArrayMerge)(known.found, found) };
|
|
842
|
+
vertex.foundOnCall = [...vertex.foundOnCall?.filter(f => f !== known) ?? [], entry];
|
|
843
|
+
}
|
|
844
|
+
/** Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns, and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`. */
|
|
845
|
+
function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions, call) {
|
|
846
|
+
recordFound(graph, accessId, fieldDefs?.map(d => d.nodeId).filter(d => !node_id_1.NodeId.isBuiltIn(d)) ?? [], call);
|
|
532
847
|
for (const fd of fieldDefs ?? []) {
|
|
533
848
|
graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Reads);
|
|
534
849
|
if (fd.definedAt !== undefined && fd.definedAt !== fd.nodeId) {
|
|
@@ -539,14 +854,18 @@ function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
|
|
|
539
854
|
}
|
|
540
855
|
}
|
|
541
856
|
}
|
|
857
|
+
const AssignFormals = ['x', 'value', 'pos', 'envir', 'inherits', 'immediate'];
|
|
542
858
|
/** The call writing a field into the environment the symbol `readId` holds: `x$f <- v` (its replacement call) or `assign("f", v, envir = x)`. */
|
|
543
859
|
function fieldAssignmentOf(readId, idMap) {
|
|
544
860
|
const read = idMap.get(readId);
|
|
545
861
|
const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
|
|
546
862
|
/* `assign("f", v, envir = x)` writes into `x` as well */
|
|
547
863
|
const call = access === undefined ? undefined : model_1.RNode.directParent(access, idMap);
|
|
548
|
-
if (r_function_call_1.RFunctionCall.isNamed(call, 'assign')
|
|
549
|
-
|
|
864
|
+
if (r_function_call_1.RFunctionCall.isNamed(call, 'assign')) {
|
|
865
|
+
const bound = function_semantics_1.FunctionSemantics.call.match.toNames(call.arguments, AssignFormals);
|
|
866
|
+
if (access === bound.get('envir') || access === bound.get('pos')) {
|
|
867
|
+
return call.info.id;
|
|
868
|
+
}
|
|
550
869
|
}
|
|
551
870
|
if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
|
|
552
871
|
return undefined;
|
|
@@ -561,18 +880,15 @@ function fieldAssignmentOf(readId, idMap) {
|
|
|
561
880
|
/* the replacement call `$<-` carries the id of the access it writes through */
|
|
562
881
|
return r_binary_op_1.RBinaryOp.is(assign) && assign.lhs.info.id === target.info.id && /^(<<?-|=)$/.test(assign.operator) ? access.info.id : undefined;
|
|
563
882
|
}
|
|
564
|
-
/**
|
|
565
|
-
|
|
566
|
-
* known, so binding the read at `readId` to a definition holding `envState` links the access to that field.
|
|
567
|
-
*/
|
|
568
|
-
function bindAccessedField(graph, readId, envState, idMap) {
|
|
883
|
+
/** An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is known, so binding the read at `readId` to a definition holding `envState` links the access to that field. */
|
|
884
|
+
function bindAccessedField(graph, readId, envState, idMap, call) {
|
|
569
885
|
const read = idMap.get(readId);
|
|
570
886
|
const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
|
|
571
887
|
if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
|
|
572
888
|
return;
|
|
573
889
|
}
|
|
574
890
|
const fieldName = accessedFieldName(r_argument_1.RArgument.valueOf(access.access[0]), r_access_1.RAccess.isNamed(access));
|
|
575
|
-
linkFieldReads(graph, access.info.id, fieldName ? envState.current.memory.get(fieldName) : undefined, true);
|
|
891
|
+
linkFieldReads(graph, access.info.id, fieldName ? envState.current.memory.get(fieldName) : undefined, true, call);
|
|
576
892
|
}
|
|
577
893
|
/** The factory that creates and returns only `closure`, calling only known built-ins and not reflecting on its frame, with the names its frame binds. */
|
|
578
894
|
function factoryOf(closure, graph, known, idMap) {
|
|
@@ -589,7 +905,7 @@ function factoryOf(closure, graph, known, idMap) {
|
|
|
589
905
|
continue;
|
|
590
906
|
}
|
|
591
907
|
else if (vertex_2.DfgVertex.isFunctionDefinition(vertex) || (vertex_2.DfgVertex.isFunctionCall(vertex) && (!vertex.onlyBuiltin || graph.unknownSideEffects.has(node_id_1.NodeId.normalize(node))))
|
|
592
|
-
||
|
|
908
|
+
|| df_helper_1.Dataflow.superAssigns(graph, node)) {
|
|
593
909
|
return undefined;
|
|
594
910
|
}
|
|
595
911
|
else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
|
|
@@ -606,24 +922,11 @@ function instancesOf(call, closure, factory, graph) {
|
|
|
606
922
|
if (!df_helper_1.Dataflow.hasEdge(graph, call, closure, edge_1.EdgeType.Calls)) {
|
|
607
923
|
return undefined;
|
|
608
924
|
}
|
|
609
|
-
const instances =
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
/* the binding the call reads holds what one call of the factory created, and nothing else */
|
|
615
|
-
const isCallOfAFunction = (target) => {
|
|
616
|
-
const vertex = graph.getVertex(target);
|
|
617
|
-
return vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Assignment);
|
|
618
|
-
};
|
|
619
|
-
const created = vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(binding)) ? df_helper_1.Dataflow.targetsOf(graph, binding, edge_1.EdgeType.DefinedBy).filter(isCallOfAFunction) : [];
|
|
620
|
-
const callees = created.length === 1 ? df_helper_1.Dataflow.targetsOf(graph, created[0], edge_1.EdgeType.Calls) : [];
|
|
621
|
-
if (callees.length !== 1 || callees[0] !== factory) {
|
|
622
|
-
return undefined;
|
|
623
|
-
}
|
|
624
|
-
instances.push(created[0]);
|
|
625
|
-
}
|
|
626
|
-
return instances.length > 0 ? instances : undefined;
|
|
925
|
+
const instances = closure_frames_1.ClosureFrames.instancesOf(graph, call);
|
|
926
|
+
return instances?.every(created => {
|
|
927
|
+
const callees = df_helper_1.Dataflow.targetsOf(graph, created, edge_1.EdgeType.Calls);
|
|
928
|
+
return callees.length === 1 && callees[0] === factory;
|
|
929
|
+
}) ? instances : undefined;
|
|
627
930
|
}
|
|
628
931
|
/** A closure's `<<-` into its factory frame is seen only by calls of closures from the same factory call, so such calls depend on each other instead. */
|
|
629
932
|
function separateClosureInstances(graph, known) {
|
|
@@ -633,7 +936,7 @@ function separateClosureInstances(graph, known) {
|
|
|
633
936
|
}
|
|
634
937
|
for (const [closure, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
635
938
|
/* only a closure writing with `<<-` can share state */
|
|
636
|
-
const superAssignments = vertex.subflow.graph.values().filter(id =>
|
|
939
|
+
const superAssignments = vertex.subflow.graph.values().filter(id => df_helper_1.Dataflow.superAssigns(graph, id)).toArray();
|
|
637
940
|
const found = superAssignments.length === 0 ? undefined : factoryOf(vertex, graph, known, idMap);
|
|
638
941
|
if (found === undefined) {
|
|
639
942
|
continue;
|