@eagleoutice/flowr 2.17.4 → 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/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 +62 -175
- package/dataflow/environments/built-in-props.js +42 -154
- package/dataflow/environments/built-in.d.ts +37 -73
- package/dataflow/environments/built-in.js +41 -62
- 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 +25 -30
- package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
- package/dataflow/eval/resolve/resolve-field.js +127 -0
- 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 +2 -2
- 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 +100 -46
- 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 -188
- package/dataflow/graph/df-helper.js +107 -208
- 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 +457 -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 +23 -75
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +263 -97
- 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 +82 -62
- 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-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 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +31 -35
- 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 +13 -19
- 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/transitive-side-effects.d.ts +38 -30
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +584 -114
- 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 +6 -26
- package/dataflow/internal/process/functions/call/known-call-handling.js +6 -16
- 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.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 +111 -29
- 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/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 +1 -1
- 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 +2 -2
- 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 +3 -6
- package/linter/rules/file-path-validity.js +6 -4
- package/linter/rules/function-finder-util.d.ts +4 -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/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.js +1 -1
- 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/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/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-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 -3
- package/project/flowr-analyzer.js +11 -5
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -14
- 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 -1
- package/project/plugins/package-version-plugins/package.d.ts +6 -5
- 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/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/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 +5 -5
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -2
- package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
- package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
- package/queries/catalog/dice-query/dice-query-format.d.ts +1 -0
- 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/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.js +3 -2
- 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 +9 -6
- 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/query-function-filter.d.ts +1 -1
- package/queries/query.d.ts +59 -8
- 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/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 +8 -9
- 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 -2
- package/search/search-executor/search-generators.js +13 -8
- 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/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 -8874
- package/dataflow/environments/default-builtin-config.js +0 -1737
- 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,16 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computeCallGraphSummaries = computeCallGraphSummaries;
|
|
4
|
+
exports.foldCallGraph = foldCallGraph;
|
|
5
|
+
exports.linkPromisesToWritesOfCall = linkPromisesToWritesOfCall;
|
|
6
|
+
exports.settleConditionalWritesOfCalls = settleConditionalWritesOfCalls;
|
|
4
7
|
exports.linkMaterializedExportsToLoaders = linkMaterializedExportsToLoaders;
|
|
5
8
|
exports.reResolveOpenReferences = reResolveOpenReferences;
|
|
6
|
-
exports.
|
|
9
|
+
exports.ambientAccessOfFunctions = ambientAccessOfFunctions;
|
|
10
|
+
exports.ambientAccessOf = ambientAccessOf;
|
|
7
11
|
exports.propagateTransitiveSideEffects = propagateTransitiveSideEffects;
|
|
12
|
+
const graph_1 = require("../../../../../graph/graph");
|
|
8
13
|
const edge_1 = require("../../../../../graph/edge");
|
|
9
14
|
const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
10
15
|
const environment_1 = require("../../../../../environments/environment");
|
|
11
16
|
const built_in_library_1 = require("./built-in-library");
|
|
12
17
|
const frame_memory_1 = require("../../../../../environments/frame-memory");
|
|
13
18
|
const vertex_1 = require("../../../../../graph/vertex");
|
|
19
|
+
const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
|
|
20
|
+
const r_project_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-project");
|
|
14
21
|
const program_order_1 = require("../../../../program-order");
|
|
15
22
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
16
23
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
@@ -19,43 +26,432 @@ const built_in_ambient_state_1 = require("./built-in-ambient-state");
|
|
|
19
26
|
const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
|
|
20
27
|
const df_helper_1 = require("../../../../../graph/df-helper");
|
|
21
28
|
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
29
|
+
const ambient_access_1 = require("../../../../../graph/ambient-access");
|
|
30
|
+
const query_fn_props_1 = require("../../../../../environments/query-fn-props");
|
|
31
|
+
const built_in_props_1 = require("../../../../../environments/built-in-props");
|
|
32
|
+
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
33
|
+
const built_in_props_2 = require("../../../../../environments/built-in-props");
|
|
34
|
+
const logic_1 = require("../../../../../../util/logic");
|
|
22
35
|
const info_1 = require("../../../../../info");
|
|
36
|
+
const fixpoint_1 = require("../../../../../../util/fixpoint");
|
|
37
|
+
const monoid_1 = require("../../../../../../util/monoid");
|
|
38
|
+
const relation_1 = require("../../../../../../util/collections/relation");
|
|
39
|
+
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
40
|
+
const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
41
|
+
const r_binary_op_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
42
|
+
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
43
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
44
|
+
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
45
|
+
const r_value_1 = require("../../../../../eval/values/r-value");
|
|
46
|
+
const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
47
|
+
const r_base_packages_1 = require("../../../../../../util/r-base-packages");
|
|
23
48
|
/**
|
|
24
49
|
* Computes, for every function-definition vertex `F`, `summary(F) = own(F)` unioned with `summary(G)` over every transitive callee `G`.
|
|
25
|
-
* @param graph - the fully linked dataflow graph
|
|
26
|
-
* @param own - the effects a single function definition produces itself (its contribution to the summary)
|
|
27
|
-
* @returns a map from each function-definition vertex to its transitive-effect summary
|
|
28
50
|
* @useInstead {@link Dataflow.sideEffects.callGraphSummaries}
|
|
29
51
|
*/
|
|
30
52
|
function computeCallGraphSummaries(graph, own) {
|
|
31
|
-
|
|
32
|
-
const callees = new Map();
|
|
33
|
-
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
34
|
-
summary.set(id, new Set(own(id, vertex)));
|
|
35
|
-
callees.set(id, df_helper_1.Dataflow.callsIn(vertex, graph).flatMap(([node]) => df_helper_1.Dataflow.calleeIdsOf(graph, node)).toArray());
|
|
36
|
-
}
|
|
37
|
-
/* pull each callee's summary, its callers are revisited whenever a function grew */
|
|
38
|
-
df_helper_1.Dataflow.propagateToFixpoint(summary.keys(), callees, id => {
|
|
39
|
-
const effects = summary.get(id);
|
|
40
|
-
const before = effects.size;
|
|
41
|
-
for (const callee of callees.get(id) ?? []) {
|
|
42
|
-
for (const effect of summary.get(callee) ?? []) {
|
|
43
|
-
effects.add(effect);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return effects.size > before;
|
|
47
|
-
});
|
|
48
|
-
return summary;
|
|
53
|
+
return foldCallGraph(graph, monoid_1.Monoid.set(), (id, fdef) => new Set(own(id, fdef)));
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* Only vertices created on demand (exports actually referenced) get an edge, keeping the graph small.
|
|
56
|
+
* Computes, for every function-definition vertex `F`, what `F` and every function it transitively calls contribute together.
|
|
57
|
+
* @useInstead {@link Dataflow.sideEffects.foldCallGraph}
|
|
54
58
|
*/
|
|
59
|
+
function foldCallGraph(graph, monoid, own) {
|
|
60
|
+
const summaries = new fixpoint_1.ReachSummaries(id => {
|
|
61
|
+
const vertex = graph.getVertex(id);
|
|
62
|
+
if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
/* an exit hook (`on.exit(expr)`) runs as part of the function */
|
|
66
|
+
return df_helper_1.Dataflow.callsIn(vertex, graph).flatMap(([node]) => df_helper_1.Dataflow.calleeIdsOf(graph, node)).toArray().concat(vertex.subflow.hooks.map(h => h.id));
|
|
67
|
+
}, id => {
|
|
68
|
+
const vertex = graph.getVertex(id);
|
|
69
|
+
return vertex_1.DfgVertex.isFunctionDefinition(vertex) ? own(id, vertex) : undefined;
|
|
70
|
+
}, monoid);
|
|
71
|
+
return new Map(graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).map(([id]) => [id, summaries.of(id)]));
|
|
72
|
+
}
|
|
73
|
+
/** A promise reads the state at the point it is forced, which is wherever the callee first needs it: after the call wrote what the promise reads (`g <- function(b) { x <<- 1; b }; g(x)`), after another argument did (`f(n, n <- 4)`), or, once a closure captured its parameter, after the call returned (`mk <- function(a) function() a`). */
|
|
74
|
+
function linkPromisesToWritesOfCall(graph, ctx) {
|
|
75
|
+
const idMap = graph.idMap;
|
|
76
|
+
if (idMap === undefined) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const nameOf = (id) => {
|
|
80
|
+
const node = idMap.get(id);
|
|
81
|
+
return r_symbol_1.RSymbol.is(node) ? identifier_1.Identifier.getName(node.content) : undefined;
|
|
82
|
+
};
|
|
83
|
+
let outlives;
|
|
84
|
+
let later;
|
|
85
|
+
let forcing;
|
|
86
|
+
let order;
|
|
87
|
+
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
88
|
+
/* a function of a package flowR has no body for forces its arguments as its signature states, see `keptPromisesOfPackageCall` */
|
|
89
|
+
const kept = df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)))
|
|
90
|
+
? undefined : keptPromisesOfPackageCall(graph, vertex, ctx);
|
|
91
|
+
if (kept === false) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const args = vertex.args.filter(graph_1.FunctionArgument.isNotEmpty).map(a => ({ ids: new Set(model_1.RNode.collectAllIds(idMap.get(a.nodeId))), at: a.nodeId }));
|
|
95
|
+
/* what each write is named, and the argument it is written in, if any */
|
|
96
|
+
const writes = new Map();
|
|
97
|
+
const write = (name, def, within) => {
|
|
98
|
+
if (name !== undefined) {
|
|
99
|
+
writes.set(name, [...writes.get(name) ?? [], [def, within]]);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
for (const def of df_helper_1.Dataflow.sourcesOf(graph, id, edge_1.EdgeType.SideEffectOnCall)) {
|
|
103
|
+
write(node_id_1.NodeId.isBuiltIn(def) ? undefined : nameOf(def), def);
|
|
104
|
+
}
|
|
105
|
+
for (const { ids } of args) {
|
|
106
|
+
for (const node of ids) {
|
|
107
|
+
write(vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(node)) ? nameOf(node) : undefined, node, ids);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const { ids, at } of args) {
|
|
111
|
+
/* whether the promise may be forced after the call, asked only once a read has a later definition to see */
|
|
112
|
+
let late;
|
|
113
|
+
const outlived = () => {
|
|
114
|
+
/* resolving the condition of each branch to a constant would cost a value resolution per branch */
|
|
115
|
+
forcing ??= function_semantics_1.FunctionSemantics.promiseForcing(graph, { ctx, constantBranches: false });
|
|
116
|
+
outlives ??= promiseOutlivesCall(graph, idMap, forcing);
|
|
117
|
+
late ??= kept === undefined ? df_helper_1.Dataflow.targetsOf(graph, at, edge_1.EdgeType.DefinesOnCall).some(outlives) && forcing(id, at) !== logic_1.Ternary.Always : kept.has(at);
|
|
118
|
+
return late;
|
|
119
|
+
};
|
|
120
|
+
for (const node of ids) {
|
|
121
|
+
const name = vertex_1.DfgVertex.isUse(graph.getVertex(node)) ? nameOf(node) : undefined;
|
|
122
|
+
if (name === undefined) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
for (const [def, within] of writes.get(name) ?? []) {
|
|
126
|
+
if (within !== ids) {
|
|
127
|
+
graph.addEdge(node, def, edge_1.EdgeType.Reads);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
later ??= definitionsAfter(graph, idMap);
|
|
131
|
+
const after = later(id, name);
|
|
132
|
+
if (after.length > 0 && outlived()) {
|
|
133
|
+
for (const def of after) {
|
|
134
|
+
graph.addEdge(node, def, edge_1.EdgeType.Reads);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
(order ??= new PromiseOrder(graph, idMap)).settle(id, at, node, name);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const [fn] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
142
|
+
const definition = idMap.get(fn);
|
|
143
|
+
for (const parameter of r_function_definition_1.RFunctionDefinition.is(definition) ? definition.parameters : []) {
|
|
144
|
+
for (const read of parameter.defaultValue === undefined ? [] : model_1.RNode.collectAllIds(parameter.defaultValue)) {
|
|
145
|
+
const name = vertex_1.DfgVertex.isUse(graph.getVertex(read)) ? nameOf(read) : undefined;
|
|
146
|
+
if (name !== undefined) {
|
|
147
|
+
(order ??= new PromiseOrder(graph, idMap)).settleDefault(fn, parameter.name.info.id, read, name);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Whether the branches of `fn` a node stands under are taken in the frame `call` makes: a parameter holds what that call hands it, so a condition on it may be constant there. */
|
|
154
|
+
function branchesTakenIn(conditions, fn, call, graph, ctx) {
|
|
155
|
+
let result = logic_1.Ternary.Always;
|
|
156
|
+
for (const cd of conditions) {
|
|
157
|
+
const branch = graph.getVertex(cd.id);
|
|
158
|
+
const condition = vertex_1.DfgVertex.isFunctionCall(branch) && vertex_1.DfgVertex.hasOrigin(branch, built_in_proc_name_1.BuiltInProcName.IfThenElse) ? branch.args[0] : undefined;
|
|
159
|
+
const values = condition === undefined || condition === r_function_call_1.EmptyArgument || cd.when === undefined ? undefined
|
|
160
|
+
: node_value_1.NodeValue.setOf(condition.nodeId, resolve_helper_1.Resolve.info(graph, ctx), { callContext: new Map([[fn, call]]) })?.elements.map(r_value_1.RValue.truthOf);
|
|
161
|
+
const outcome = values !== undefined && values.length > 0 && values.every(v => v !== undefined && v === values[0]) ? values[0] : undefined;
|
|
162
|
+
if (outcome === undefined) {
|
|
163
|
+
result = logic_1.Ternary.Maybe;
|
|
164
|
+
}
|
|
165
|
+
else if (outcome !== cd.when) {
|
|
166
|
+
return logic_1.Ternary.Never;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/** Whether every reference to the definition is a call of it among `calls`: it is bound to names (`f <- function...`) only these calls read, so no other way leads into it. */
|
|
172
|
+
function onlyCalledBy(fn, calls, graph) {
|
|
173
|
+
const binds = (source) => vertex_1.DfgVertex.hasOrigin(graph.getVertex(source), built_in_proc_name_1.BuiltInProcName.Assignment);
|
|
174
|
+
const holders = [];
|
|
175
|
+
for (const [source, edge] of graph.edgesTo(fn)) {
|
|
176
|
+
if (edge_1.DfEdge.isOnlyControlFlow(edge) || binds(source) || (edge_1.DfEdge.isOnlyType(edge, edge_1.EdgeType.Calls) && calls.has(source))) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
else if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy) && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(source))) {
|
|
180
|
+
holders.push(source);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return holders.every(holder => graph.edgesTo(holder).entries().every(([source, edge]) => edge_1.DfEdge.isOnlyControlFlow(edge) || binds(source) || calls.has(source)));
|
|
187
|
+
}
|
|
188
|
+
/** Settles what a function writes beyond its frame (`<<-`) under branches of its own, once the calls passing the write on are linked: bound to what a call hands it, a parameter may make a branch constant (`f <- function(go) if(go) n <<- 5; f(FALSE)`). */
|
|
189
|
+
function settleConditionalWritesOfCalls(graph, ctx) {
|
|
190
|
+
const idMap = graph.idMap;
|
|
191
|
+
if (idMap === undefined) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
for (const [write, vertex] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
195
|
+
const calls = df_helper_1.Dataflow.targetsOf(graph, write, edge_1.EdgeType.SideEffectOnCall);
|
|
196
|
+
const fn = calls.length === 0 ? undefined : model_1.RNode.strictlyEnclosingFunction(write, idMap);
|
|
197
|
+
const conditions = fn === undefined ? [] : info_1.ControlDependency.minus(vertex.cds ?? [], graph.getVertex(fn)?.cds ?? []);
|
|
198
|
+
if (fn === undefined || conditions.length === 0 || calls.some(c => !df_helper_1.Dataflow.hasEdge(graph, c, fn, edge_1.EdgeType.Calls))) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const taken = calls.map(call => branchesTakenIn(conditions, fn, call, graph, ctx));
|
|
202
|
+
if (taken.every(t => t === logic_1.Ternary.Never)) {
|
|
203
|
+
if (onlyCalledBy(fn, new Set(calls), graph)) {
|
|
204
|
+
for (const reader of df_helper_1.Dataflow.sourcesOf(graph, write, edge_1.EdgeType.Reads)) {
|
|
205
|
+
graph.removeEdgeType(reader, write, edge_1.EdgeType.Reads);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const definition = graph.getVertex(fn);
|
|
211
|
+
const at = idMap.get(write)?.location;
|
|
212
|
+
/* a return or an error before the write may end the call without it */
|
|
213
|
+
const reached = vertex_1.DfgVertex.isFunctionDefinition(definition) && at !== undefined && model_1.RNode.strictlyEnclosingFunction(fn, idMap) === undefined
|
|
214
|
+
&& !definition.exitPoints.some(e => {
|
|
215
|
+
const exit = idMap.get(e.nodeId)?.location;
|
|
216
|
+
return e.type !== 0 /* ExitPointType.Default */ && (exit === undefined || exit[0] < at[0] || (exit[0] === at[0] && exit[1] <= at[1]));
|
|
217
|
+
});
|
|
218
|
+
for (let i = 0; reached && i < calls.length; i++) {
|
|
219
|
+
const statement = taken[i] === logic_1.Ternary.Always && !graph.getVertex(calls[i])?.cds?.length ? program_order_1.ProgramOrder.runsOnceAt(calls[i], graph) : undefined;
|
|
220
|
+
if (statement !== undefined) {
|
|
221
|
+
program_order_1.ProgramOrder.replaceEarlier(write, statement, graph, true);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** How many calls deep {@link PromiseOrder} follows a promise handed on, or a callee that writes. */
|
|
227
|
+
const MaxPromiseHandOn = 4;
|
|
228
|
+
/** When a promise is forced relative to the writes of the call it is handed to: `f <- function(a) { x <<- 2; a }` forces `a` only once `x` is replaced, so `f(x)` never sees what `x` held before the call. */
|
|
229
|
+
class PromiseOrder {
|
|
230
|
+
graph;
|
|
231
|
+
idMap;
|
|
232
|
+
constructor(graph, idMap) {
|
|
233
|
+
this.graph = graph;
|
|
234
|
+
this.idMap = idMap;
|
|
235
|
+
}
|
|
236
|
+
/** The one definition the call is linked to, if it is a closure defined at the top level. */
|
|
237
|
+
topLevelTarget(call) {
|
|
238
|
+
const targets = df_helper_1.Dataflow.calleeIdsOf(this.graph, call);
|
|
239
|
+
const [target] = targets;
|
|
240
|
+
return targets.length === 1 && !node_id_1.NodeId.isBuiltIn(target) && vertex_1.DfgVertex.isFunctionDefinition(this.graph.getVertex(target))
|
|
241
|
+
&& model_1.RNode.strictlyEnclosingFunction(target, this.idMap) === undefined ? target : undefined;
|
|
242
|
+
}
|
|
243
|
+
/** The statements of the body of the definition, in the order they run. */
|
|
244
|
+
statementsOf(fn) {
|
|
245
|
+
const definition = this.idMap.get(fn);
|
|
246
|
+
if (!r_function_definition_1.RFunctionDefinition.is(definition)) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
return r_expression_list_1.RExpressionList.is(definition.body) ? definition.body.children : [definition.body];
|
|
250
|
+
}
|
|
251
|
+
/** Where among the statements the node is, `-1` if in none. */
|
|
252
|
+
statementIndex(id, statements) {
|
|
253
|
+
const node = this.idMap.get(id);
|
|
254
|
+
for (const at of node === undefined ? [] : [node, ...model_1.RNode.iterateParents(node, this.idMap)]) {
|
|
255
|
+
const index = statements.indexOf(at);
|
|
256
|
+
if (index >= 0) {
|
|
257
|
+
return index;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return -1;
|
|
261
|
+
}
|
|
262
|
+
/** The call a statement makes on its own (`g()`) or assigns the result of (`v <- g()`). */
|
|
263
|
+
callOf(statement) {
|
|
264
|
+
const vertex = this.graph.getVertex(statement.info.id);
|
|
265
|
+
const value = r_binary_op_1.RBinaryOp.is(statement) && vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Assignment) ? statement.rhs : statement;
|
|
266
|
+
return vertex_1.DfgVertex.isFunctionCall(this.graph.getVertex(value.info.id)) ? value.info.id : undefined;
|
|
267
|
+
}
|
|
268
|
+
/** Whether the call defines `name` in the frame it is evaluated in, with an assignment of its own. */
|
|
269
|
+
assigns(id, name, origin) {
|
|
270
|
+
return vertex_1.DfgVertex.hasOrigin(this.graph.getVertex(id), origin)
|
|
271
|
+
&& df_helper_1.Dataflow.targetsOf(this.graph, id, edge_1.EdgeType.Returns).some(t => {
|
|
272
|
+
const node = this.idMap.get(t);
|
|
273
|
+
return vertex_1.DfgVertex.isVariableDefinition(this.graph.getVertex(t)) && r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.getName(node.content) === name;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/** Whether running the statement of the top-level closure `fn` surely replaces the global `name`: `name <<- v`, a call of a top-level closure surely doing so, or, for the call the promise came from, forcing another of its arguments that assigns `name` (`f(n, n <- 4)`). */
|
|
277
|
+
surelyWrites(statement, name, fn, call, depth) {
|
|
278
|
+
const id = statement.info.id;
|
|
279
|
+
if (this.assigns(id, name, built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
if (depth === 0 && vertex_1.DfgVertex.isUse(this.graph.getVertex(id))) {
|
|
283
|
+
const forced = df_helper_1.Dataflow.targetsOf(this.graph, id, edge_1.EdgeType.Reads).filter(p => this.idMap.get(this.idMap.get(p)?.info.parent ?? -1)?.info.parent === fn);
|
|
284
|
+
return forced.some(p => df_helper_1.Dataflow.argumentsBoundTo(this.graph, p).some(a => model_1.RNode.findEnclosing(a, this.idMap, n => n.info.id === call) !== undefined
|
|
285
|
+
&& (this.assigns(a, name, built_in_proc_name_1.BuiltInProcName.Assignment) || this.assigns(a, name, built_in_proc_name_1.BuiltInProcName.SuperAssignment))));
|
|
286
|
+
}
|
|
287
|
+
const inner = this.callOf(statement);
|
|
288
|
+
const callee = inner === undefined || depth >= MaxPromiseHandOn ? undefined : this.topLevelTarget(inner);
|
|
289
|
+
if (inner === undefined || callee === undefined) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
const statements = this.statementsOf(callee);
|
|
293
|
+
const at = statements.findIndex(s => this.surelyWrites(s, name, callee, inner, depth + 1));
|
|
294
|
+
const definition = this.graph.getVertex(callee);
|
|
295
|
+
/* a return before the write may leave the callee without it */
|
|
296
|
+
return at >= 0 && !definition.exitPoints.some(e => e.type === 1 /* ExitPointType.Return */ && this.statementIndex(e.nodeId, statements) < at);
|
|
297
|
+
}
|
|
298
|
+
/** Whether the top-level closure `fn` surely replaces the global `name` before anything forces the promise `call` binds to its parameter `param`: every read of the parameter follows a statement surely writing `name`, or hands the promise on to a callee for which the same holds. */
|
|
299
|
+
writtenBeforeForced(fn, param, name, call, depth = 0) {
|
|
300
|
+
const reads = df_helper_1.Dataflow.sourcesOf(this.graph, param, edge_1.EdgeType.Reads);
|
|
301
|
+
const statements = this.statementsOf(fn);
|
|
302
|
+
let firstWrite;
|
|
303
|
+
return reads.length > 0 && reads.every(read => {
|
|
304
|
+
const at = model_1.RNode.findEnclosing(read, this.idMap, r_function_definition_1.RFunctionDefinition.is) === fn ? this.statementIndex(read, statements) : -1;
|
|
305
|
+
if (at < 0) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
firstWrite ??= statements.findIndex(s => this.surelyWrites(s, name, fn, call, depth));
|
|
309
|
+
if (firstWrite >= 0 && firstWrite < at) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
/* `g(a)`: the promise is handed on, and `g` decides when it is forced */
|
|
313
|
+
const inner = this.callOf(statements[at]);
|
|
314
|
+
const callee = inner === undefined || depth >= MaxPromiseHandOn ? undefined : this.topLevelTarget(inner);
|
|
315
|
+
const argument = this.idMap.get(read)?.info.parent;
|
|
316
|
+
const handed = argument === undefined ? undefined : this.idMap.get(argument);
|
|
317
|
+
if (inner === undefined || callee === undefined || !r_argument_1.RArgument.is(handed) || handed.info.parent !== inner) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
const bound = [read, handed.info.id].flatMap(r => df_helper_1.Dataflow.targetsOf(this.graph, r, edge_1.EdgeType.DefinesOnCall));
|
|
321
|
+
return bound.length === 1 && this.writtenBeforeForced(callee, bound[0], name, inner, depth + 1);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/** Drops what a read in an argument of the top-level call `call` sees of the definitions the program made before the call, when the call replaces the name before it forces the promise. */
|
|
325
|
+
settle(call, argument, read, name) {
|
|
326
|
+
const fn = this.topLevelTarget(call);
|
|
327
|
+
const statement = fn === undefined || !this.graph.isRoot(read) ? undefined : program_order_1.ProgramOrder.runsOnceAt(call, this.graph);
|
|
328
|
+
if (fn === undefined || statement === undefined) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const before = df_helper_1.Dataflow.targetsOf(this.graph, read, edge_1.EdgeType.Reads).filter(t => program_order_1.ProgramOrder.runsOnceAt(t, this.graph) !== undefined && program_order_1.ProgramOrder.offset(t, statement, this.graph) < 0);
|
|
332
|
+
const params = before.length === 0 ? [] : df_helper_1.Dataflow.targetsOf(this.graph, argument, edge_1.EdgeType.DefinesOnCall);
|
|
333
|
+
if (params.length !== 1 || !this.writtenBeforeForced(fn, params[0], name, call)) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
/* where a `<<-` writes depends on whether the name was bound before, so its writes read what the promise no longer does */
|
|
337
|
+
const writes = df_helper_1.Dataflow.sourcesOf(this.graph, call, edge_1.EdgeType.SideEffectOnCall).filter(w => {
|
|
338
|
+
const node = this.idMap.get(w);
|
|
339
|
+
return r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.getName(node.content) === name;
|
|
340
|
+
});
|
|
341
|
+
for (const def of before) {
|
|
342
|
+
this.graph.removeEdgeType(read, def, edge_1.EdgeType.Reads);
|
|
343
|
+
for (const write of writes) {
|
|
344
|
+
this.graph.addEdge(write, def, edge_1.EdgeType.Reads);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/** Drops what a read in the default of `param` cannot see: the default is evaluated once, in the frame of `fn`, by the statement first forcing it, so it sees neither what later statements define, nor, once a statement before surely redefines the name, the parameter it names or what came before (`function(a, b = a) { a <- 10; b }`). */
|
|
349
|
+
settleDefault(fn, param, read, name) {
|
|
350
|
+
const seen = df_helper_1.Dataflow.targetsOf(this.graph, read, edge_1.EdgeType.Reads);
|
|
351
|
+
if (seen.length < 2) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const statements = this.statementsOf(fn);
|
|
355
|
+
const reads = df_helper_1.Dataflow.sourcesOf(this.graph, param, edge_1.EdgeType.Reads);
|
|
356
|
+
const at = (r) => model_1.RNode.findEnclosing(r, this.idMap, r_function_definition_1.RFunctionDefinition.is) === fn ? this.statementIndex(r, statements) : -1;
|
|
357
|
+
/* the first statement that may force it, and the first that surely does */
|
|
358
|
+
const mayForce = Math.min(...reads.map(at));
|
|
359
|
+
const own = this.graph.getVertex(fn)?.cds ?? [];
|
|
360
|
+
const surelyForces = Math.min(...reads.filter(r => info_1.ControlDependency.minus(this.graph.getVertex(r)?.cds ?? [], own).length === 0).map(at));
|
|
361
|
+
if (mayForce < 0 || !Number.isFinite(mayForce)) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const lastWrite = statements.findLastIndex((s, i) => i < mayForce && this.assigns(s.info.id, name, built_in_proc_name_1.BuiltInProcName.Assignment));
|
|
365
|
+
for (const before of seen) {
|
|
366
|
+
const node = this.idMap.get(before);
|
|
367
|
+
const parameter = node?.info.role === "param-n" /* RoleInParent.ParameterName */ && this.idMap.get(node.info.parent ?? -1)?.info.parent === fn;
|
|
368
|
+
const index = this.statementIndex(before, statements);
|
|
369
|
+
if ((parameter && lastWrite >= 0) || (index >= 0 && (index < lastWrite || index > surelyForces))) {
|
|
370
|
+
this.graph.removeEdgeType(read, before, edge_1.EdgeType.Reads);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/** For a call of a package function flowR has no body for (not one of R's own packages, whose functions the built-in configuration states): `false` if it is none, else the arguments whose promises may be forced after the call returned. */
|
|
376
|
+
function keptPromisesOfPackageCall(graph, call, ctx) {
|
|
377
|
+
const info = call.name === undefined ? undefined : ctx.functionInfo(call.name);
|
|
378
|
+
const pkg = info?.package ?? (call.name === undefined ? undefined : identifier_1.Identifier.getNamespace(call.name));
|
|
379
|
+
if (pkg === undefined || (0, r_base_packages_1.isBaseRPackage)(pkg)) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
if (!handsBackCalledValue(graph, call.id)) {
|
|
383
|
+
return new Set();
|
|
384
|
+
}
|
|
385
|
+
const layout = info?.sig === undefined ? undefined : built_in_props_1.FnSig.layout(info.sig);
|
|
386
|
+
const args = call.args.filter(graph_1.FunctionArgument.isNotEmpty);
|
|
387
|
+
const slots = layout === undefined ? undefined : built_in_props_1.FnSig.slots(layout, args.map(graph_1.FunctionArgument.getName));
|
|
388
|
+
return new Set(args.filter((_, i) => {
|
|
389
|
+
const props = layout === undefined || slots === undefined || slots[i] < 0 ? 0 : layout.props[slots[i]];
|
|
390
|
+
return (props & (built_in_props_1.ArgProp.Forced | built_in_props_1.ArgProp.Lazy)) === 0;
|
|
391
|
+
}).map(a => a.nodeId));
|
|
392
|
+
}
|
|
393
|
+
/** Whether the value of `call` may be called after it returned: it is a function, or it flows (through variables, returns, and reads) to where a call takes its function from, as `g` in `g <- f(); g()`. */
|
|
394
|
+
function handsBackCalledValue(graph, call) {
|
|
395
|
+
if (df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Returns).some(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)))) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
const seen = new Set([call]);
|
|
399
|
+
const todo = [call];
|
|
400
|
+
for (let id = todo.pop(); id !== undefined; id = todo.pop()) {
|
|
401
|
+
for (const [source, edge] of graph.edgesTo(id)) {
|
|
402
|
+
if (seen.has(source) || edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) || edge_1.DfEdge.doesNotIncludeType(edge, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns)) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
else if (vertex_1.DfgVertex.isFunctionCall(graph.getVertex(source)) && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
seen.add(source);
|
|
409
|
+
todo.push(source);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
/** Whether the promise bound to a parameter may be forced after its call returned: its function does not surely force it, and a closure within the function reads it or it is handed on to a parameter whose promise may. */
|
|
415
|
+
function promiseOutlivesCall(graph, idMap, forcing) {
|
|
416
|
+
const ownerOf = new Map();
|
|
417
|
+
for (const [id, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
418
|
+
for (const parameter of df_helper_1.Dataflow.parametersOf(definition)) {
|
|
419
|
+
ownerOf.set(parameter, id);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const handedTo = new defaultmap_1.DefaultMap(() => []);
|
|
423
|
+
for (const parameter of ownerOf.keys()) {
|
|
424
|
+
for (const argument of df_helper_1.Dataflow.argumentsBoundTo(graph, parameter)) {
|
|
425
|
+
for (const read of df_helper_1.Dataflow.targetsOf(graph, argument, edge_1.EdgeType.Reads)) {
|
|
426
|
+
if (ownerOf.has(read)) {
|
|
427
|
+
handedTo.get(read).push(parameter);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const captured = (parameter) => df_helper_1.Dataflow.sourcesOf(graph, parameter, edge_1.EdgeType.Reads)
|
|
433
|
+
.some(read => model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is) !== ownerOf.get(parameter));
|
|
434
|
+
const open = (p) => forcing(p, p) !== logic_1.Ternary.Always;
|
|
435
|
+
const outlives = new fixpoint_1.ReachSummaries(p => open(p) ? handedTo.get(p) : [], p => open(p) && captured(p), monoid_1.Monoid.any);
|
|
436
|
+
return parameter => ownerOf.has(parameter) && outlives.of(parameter);
|
|
437
|
+
}
|
|
438
|
+
/** The definitions of a name that may be made after a call: those in its scope it does not surely run after, and every `<<-`. */
|
|
439
|
+
function definitionsAfter(graph, idMap) {
|
|
440
|
+
const byName = df_helper_1.Dataflow.definitionsByName(graph);
|
|
441
|
+
const superAssigned = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionCall)
|
|
442
|
+
.filter(([id]) => df_helper_1.Dataflow.superAssigns(graph, id))
|
|
443
|
+
.flatMap(([id]) => df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Returns)));
|
|
444
|
+
const scopeOf = (0, defaultmap_1.memoize)((id) => graph.isRoot(id) ? undefined : model_1.RNode.strictlyEnclosingFunction(id, idMap));
|
|
445
|
+
return (call, name) => {
|
|
446
|
+
const scope = scopeOf(call);
|
|
447
|
+
const statement = program_order_1.ProgramOrder.runsOnceAt(call, graph);
|
|
448
|
+
return byName.get(name).filter(def => superAssigned.has(def)
|
|
449
|
+
|| (scopeOf(def) === scope && (statement === undefined || program_order_1.ProgramOrder.offset(def, statement, graph) > 0)));
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
/** Links every materialized package-export vertex back to the `library()`/`use()` call that loaded it, reading the loading call from the export binding's `definedAt` in the (final, authoritative) environment. */
|
|
55
453
|
function linkMaterializedExportsToLoaders(graph, environment, ctx) {
|
|
56
|
-
/* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the
|
|
57
|
-
* cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or something points
|
|
58
|
-
* to it, called or read as a value (`g <- select`). Both are read off the graph once here instead of per export binding. */
|
|
454
|
+
/* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or something points to it, called or read as a value (`g <- select`). */
|
|
59
455
|
const called = new Set(graph.vertices(true).map(([id]) => id).filter(node_id_1.NodeId.isBuiltIn));
|
|
60
456
|
for (const [, outgoing] of graph.edges()) {
|
|
61
457
|
for (const target of outgoing.keys()) {
|
|
@@ -81,8 +477,7 @@ function linkMaterializedExportsToLoaders(graph, environment, ctx) {
|
|
|
81
477
|
}
|
|
82
478
|
}
|
|
83
479
|
}
|
|
84
|
-
/* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further
|
|
85
|
-
* export qualify -- the lazy checks this replaces could not have observed one either */
|
|
480
|
+
/* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further export qualify -- the lazy checks this replaces could not have observed one either */
|
|
86
481
|
for (const [id, loadedAt] of loaders) {
|
|
87
482
|
/* an export only read as a value (`g <- select`) has no vertex yet, which a slice could not pass */
|
|
88
483
|
(0, built_in_library_1.attachExportVertex)(graph, id, environment, ctx);
|
|
@@ -108,39 +503,29 @@ function ownLibraryCalls(_id, fdef) {
|
|
|
108
503
|
}
|
|
109
504
|
return packages;
|
|
110
505
|
}
|
|
111
|
-
/** The
|
|
112
|
-
function
|
|
113
|
-
return environment_1.REnvironment.frames(fdef.subflow.environment.current.parent);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* The non-built-in definitions a function body lets escape to an outer scope (e.g. a `<<-` super-assignment),
|
|
117
|
-
* as a callback for {@link computeCallGraphSummaries}. Nested definitions share their outer frames, and a frame is
|
|
118
|
-
* dominated by the built-ins it holds, so filtering each frame once per pass saves the bulk of the work.
|
|
119
|
-
*/
|
|
120
|
-
function escapedDefinitions(hidden) {
|
|
506
|
+
/** The non-built-in definitions a function body lets escape to an outer scope (e.g. a `<<-` super-assignment), as a callback for {@link computeCallGraphSummaries}. */
|
|
507
|
+
function escapedDefinitions(graph, hidden) {
|
|
121
508
|
const perFrame = new Map();
|
|
122
|
-
|
|
509
|
+
/* the function an exit hook runs in folds the hook's writes into its final environment in the order R runs the hooks */
|
|
510
|
+
const hooks = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).flatMap(([, v]) => v.subflow.hooks.map(h => h.id)));
|
|
511
|
+
return (id, fdef) => {
|
|
123
512
|
const defs = hidden.keys().filter(call => fdef.subflow.graph.has(call)).toArray();
|
|
124
|
-
|
|
513
|
+
if (hooks.has(id)) {
|
|
514
|
+
return defs;
|
|
515
|
+
}
|
|
516
|
+
for (const e of environment_1.REnvironment.frames(fdef.subflow.environment.current.parent)) {
|
|
125
517
|
let escaped = perFrame.get(e.memory);
|
|
126
|
-
if (escaped === undefined
|
|
127
|
-
/* an attached package binds nothing but its exports, which are built-ins */
|
|
518
|
+
if (escaped === undefined) {
|
|
128
519
|
escaped = [];
|
|
129
520
|
perFrame.set(e.memory, escaped);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/* a package frame holds thousands of entries and keeps none of them, so this walks them in place
|
|
133
|
-
* rather than through a spread/flatMap/filter/map chain that allocates an array per step */
|
|
134
|
-
const collected = [];
|
|
135
|
-
for (const ds of e.memory.values()) {
|
|
521
|
+
/* an attached package binds nothing but its exports, which are built-ins, and a package frame holds thousands of entries, so this walks the others in place */
|
|
522
|
+
for (const ds of e.memory instanceof frame_memory_1.Frame && e.memory.lazy() !== undefined ? [] : e.memory.values()) {
|
|
136
523
|
for (const d of ds) {
|
|
137
524
|
if (!node_id_1.NodeId.isBuiltIn(d.nodeId)) {
|
|
138
|
-
|
|
525
|
+
escaped.push(d.nodeId);
|
|
139
526
|
}
|
|
140
527
|
}
|
|
141
528
|
}
|
|
142
|
-
escaped = collected;
|
|
143
|
-
perFrame.set(e.memory, escaped);
|
|
144
529
|
}
|
|
145
530
|
for (const d of escaped) {
|
|
146
531
|
/* a package the caller attached is visible in the body, but only one the body attaches escapes it */
|
|
@@ -166,11 +551,7 @@ function propagateTransitiveDefinitions(graph, environment, ctx, summary) {
|
|
|
166
551
|
}
|
|
167
552
|
}
|
|
168
553
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Attaches packages transitively loaded by top-level calls to `environment`.
|
|
171
|
-
* `g <- function() library(A); f <- function() g(); f()` makes `A` available after `f()`.
|
|
172
|
-
* @returns the enriched environment and whether it grew (so the caller can re-link and re-run to a fixpoint).
|
|
173
|
-
*/
|
|
554
|
+
/** Attaches packages transitively loaded by top-level calls to `environment`. */
|
|
174
555
|
function propagateTransitivePackages(graph, environment, ctx) {
|
|
175
556
|
const summary = computeCallGraphSummaries(graph, ownLibraryCalls);
|
|
176
557
|
/* package to its loading `library()` call and, unless a call reaching it surely runs, the cds of one that may */
|
|
@@ -199,19 +580,12 @@ function propagateTransitivePackages(graph, environment, ctx) {
|
|
|
199
580
|
}
|
|
200
581
|
return { environment, grew };
|
|
201
582
|
}
|
|
202
|
-
/** The ambient writes of body calls only linking resolved to a built-in (see {@link writesOfHiddenBuiltIn}), linking their reads as well. */
|
|
203
|
-
function hiddenBuiltInWrites(graph, environment) {
|
|
204
|
-
const { writes, reads } = hiddenBuiltInAccess(graph, environment);
|
|
205
|
-
linkHiddenReads(graph, reads);
|
|
206
|
-
return writes;
|
|
207
|
-
}
|
|
208
|
-
/** The ambient writes and reads of body calls only linking resolved to a built-in, per call. */
|
|
209
|
-
function hiddenBuiltInAccess(graph, environment) {
|
|
583
|
+
/** The ambient writes of body calls only linking resolved to a built-in (see {@link writesOfHiddenBuiltIn}), recording and linking their reads as well. */
|
|
584
|
+
function hiddenBuiltInWrites(graph, environment, drawing) {
|
|
210
585
|
const builtIns = environment_1.REnvironment.findBuiltIn(environment.current);
|
|
211
586
|
const writes = new Map();
|
|
212
587
|
const reads = new Map();
|
|
213
|
-
const
|
|
214
|
-
const readsOf = new defaultmap_1.DefaultMap(() => [], reads);
|
|
588
|
+
const resolved = [];
|
|
215
589
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
216
590
|
if (graph.isRoot(id) || !(0, built_in_ambient_state_1.reachesBuiltInLate)(vertex)) {
|
|
217
591
|
continue;
|
|
@@ -220,19 +594,26 @@ function hiddenBuiltInAccess(graph, environment) {
|
|
|
220
594
|
for (const target of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)) {
|
|
221
595
|
if (node_id_1.NodeId.isBuiltIn(target) && (own === undefined || node_id_1.NodeId.toBuiltIn(identifier_1.Identifier.getName(own)) !== target)) {
|
|
222
596
|
const targets = resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(target), { current: builtIns, level: 0 }, identifier_1.ReferenceType.Function) ?? [];
|
|
223
|
-
|
|
224
|
-
const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id));
|
|
597
|
+
resolved.push([id, targets]);
|
|
598
|
+
const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id, drawing));
|
|
225
599
|
if (defs.length > 0) {
|
|
226
|
-
|
|
600
|
+
writes.set(id, [...writes.get(id) ?? [], ...defs]);
|
|
227
601
|
}
|
|
228
602
|
const names = targets.flatMap(built_in_ambient_state_1.readsOfHiddenBuiltIn);
|
|
229
603
|
if (names.length > 0) {
|
|
230
|
-
|
|
604
|
+
reads.set(id, [...reads.get(id) ?? [], ...names]);
|
|
231
605
|
}
|
|
232
606
|
}
|
|
233
607
|
}
|
|
234
608
|
}
|
|
235
|
-
|
|
609
|
+
for (const [id, targets] of resolved) {
|
|
610
|
+
(0, built_in_ambient_state_1.hiddenSideEffects)(graph, environment, id, targets);
|
|
611
|
+
}
|
|
612
|
+
for (const id of new Set([...writes.keys(), ...reads.keys()])) {
|
|
613
|
+
graph.recordAmbientAccess(id, { reads: reads.get(id), writes: writes.get(id)?.map(d => d.name) });
|
|
614
|
+
}
|
|
615
|
+
linkHiddenReads(graph, reads);
|
|
616
|
+
return writes;
|
|
236
617
|
}
|
|
237
618
|
/** A hidden call reads the state where the functions running it are called. */
|
|
238
619
|
function linkHiddenReads(graph, reads) {
|
|
@@ -257,16 +638,13 @@ function linkHiddenReads(graph, reads) {
|
|
|
257
638
|
}
|
|
258
639
|
}
|
|
259
640
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Maps each definition escaping into the global frame to its full (name-carrying) definitions, one node may define several names
|
|
262
|
-
* (`options(digits = 3)`); a write from a function defined within another one may be caught by that function's frame instead.
|
|
263
|
-
*/
|
|
641
|
+
/** Maps each definition escaping into the global frame to its full (name-carrying) definitions, one node may define several names (`options(digits = 3)`); a write from a function defined within another one may be caught by that function's frame instead. */
|
|
264
642
|
function escapedDefinitionMap(graph, hidden) {
|
|
265
643
|
const map = new Map(hidden.entries().map(([id, defs]) => [id, [...defs]]));
|
|
266
644
|
const definitionsOf = new defaultmap_1.DefaultMap(() => [], map);
|
|
267
645
|
const seen = new Set();
|
|
268
646
|
for (const [, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
269
|
-
const global =
|
|
647
|
+
const global = environment_1.REnvironment.frames(vertex.subflow.environment.current.parent).filter(e => e.t === undefined).reduce((_, e) => e, undefined);
|
|
270
648
|
/* a frame shared with an already-visited definition contributes the same entries */
|
|
271
649
|
if (global !== undefined && !seen.has(global.memory)) {
|
|
272
650
|
seen.add(global.memory);
|
|
@@ -281,11 +659,7 @@ function escapedDefinitionMap(graph, hidden) {
|
|
|
281
659
|
}
|
|
282
660
|
return map;
|
|
283
661
|
}
|
|
284
|
-
/**
|
|
285
|
-
* Folds the `<<-` definitions that escape transitively from top-level calls into `environment`.
|
|
286
|
-
* `f <- function() x <<- 1; g <- function() f(); g(); print(x)` makes `x` resolvable.
|
|
287
|
-
* @returns the enriched environment and whether it grew (so the extractor can re-resolve open reads and re-run).
|
|
288
|
-
*/
|
|
662
|
+
/** Folds the `<<-` definitions that escape transitively from top-level calls into `environment`. */
|
|
289
663
|
function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidden, summary, open) {
|
|
290
664
|
const defs = escapedDefinitionMap(graph, hidden);
|
|
291
665
|
const names = new Set();
|
|
@@ -300,9 +674,7 @@ function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidd
|
|
|
300
674
|
for (const def of (summary.get(target) ?? []).values().flatMap(nodeId => defs.get(nodeId) ?? [])) {
|
|
301
675
|
const nodeId = def.nodeId;
|
|
302
676
|
names.add(def.name);
|
|
303
|
-
/* a name may hold several definitions while a lookup answers with one, so asking the environment
|
|
304
|
-
* would call every shadowed one missing and define it again on every round; what this fixpoint
|
|
305
|
-
* has already folded in is what says whether there is anything left to add */
|
|
677
|
+
/* a name may hold several definitions while a lookup answers with one, so asking the environment would call every shadowed one missing and define it again on every round; what this fixpoint has already folded in is what says whether there is anything left to add */
|
|
306
678
|
const key = `${def.name}\u0000${String(nodeId)}`;
|
|
307
679
|
if (defined.has(key)) {
|
|
308
680
|
continue;
|
|
@@ -319,10 +691,7 @@ function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidd
|
|
|
319
691
|
}
|
|
320
692
|
return { environment, grew, names };
|
|
321
693
|
}
|
|
322
|
-
/**
|
|
323
|
-
* A read that may run after `call` and sees a definition the call may replace (or nothing, as with the `open` reads) may see `def`
|
|
324
|
-
* instead, as with a callee only the call binds: `g <- function(f) f(); x <- 1; g(function() x <<- 2); print(x)`, or `g(runif)`.
|
|
325
|
-
*/
|
|
694
|
+
/** A read that may run after `call` and sees a definition the call may replace (or nothing, as with the `open` reads) may see `def` instead, as with a callee only the call binds: `g <- function(f) f(); x <- 1; g(function() x <<- 2); print(x)`, or `g(runif)`. */
|
|
326
695
|
function linkReadsAfter(graph, call, def, open, definitionsNamed) {
|
|
327
696
|
const before = graph.getVertex(call)?.environment;
|
|
328
697
|
const visible = before === undefined ? definitionsNamed(def.name) : resolve_helper_1.Resolve.byName(def.name, before)?.map(d => d.nodeId) ?? [];
|
|
@@ -349,40 +718,141 @@ function reResolveOpenReferences(graph, environment, references, escapedNames) {
|
|
|
349
718
|
}
|
|
350
719
|
}
|
|
351
720
|
}
|
|
721
|
+
function graphOf(from) {
|
|
722
|
+
return 'graph' in from ? [from.graph, from.environment] : [from, undefined];
|
|
723
|
+
}
|
|
724
|
+
/** Whether the call `id` is tagged as a graphics call, or reaches one through a parameter (`g <- function(f) f(1); g(plot)`). */
|
|
725
|
+
function drawsOn(graph, id, environment) {
|
|
726
|
+
const draws = (info) => function_semantics_1.FunctionSemantics.call.props.hasAny(info, built_in_props_2.SemanticCallTag.Graphics);
|
|
727
|
+
if (draws((0, query_fn_props_1.callFnProps)(id, graph, environment))) {
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
const builtIns = environment === undefined ? undefined : { level: 0, current: environment_1.REnvironment.findBuiltIn(environment.current) };
|
|
731
|
+
return df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => node_id_1.NodeId.isBuiltIn(t)
|
|
732
|
+
&& draws(builtIns === undefined ? query_fn_props_1.BuiltInIndex.default().get(node_id_1.NodeId.fromBuiltIn(t)) : (0, query_fn_props_1.queryFnProps)(node_id_1.NodeId.fromBuiltIn(t), { environment: builtIns })));
|
|
733
|
+
}
|
|
734
|
+
/** What the call `id` itself accesses, without the functions it calls. */
|
|
735
|
+
function accessOfCall(graph, id, environment) {
|
|
736
|
+
const recorded = graph.ambientAccessOf(id) ?? ambient_access_1.AmbientAccess.empty;
|
|
737
|
+
return drawsOn(graph, id, environment) ? { ...recorded, draws: new Set([id]) } : recorded;
|
|
738
|
+
}
|
|
352
739
|
/**
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* and the global variables it binds.
|
|
356
|
-
* A function reports what its callees report as well, so with `a01 <- function() options(digits = 3)` and `a22 <- function() a01()`,
|
|
357
|
-
* both set `#option:digits`. What a function only changes within its own frame (`withr::local_options`) is left out.
|
|
358
|
-
* @param info - the dataflow information of the whole program
|
|
359
|
-
* @returns per function-definition vertex what it may change, which is empty for a function changing nothing
|
|
360
|
-
* @useInstead {@link Dataflow.sideEffects.ambientWrites}
|
|
740
|
+
* What each function accesses when it is called: the pseudo variables it reads and changes (see {@link AmbientStateName}), the global variables it binds and the drawing calls it makes, together with what the functions it calls access.
|
|
741
|
+
* @useInstead {@link Dataflow.sideEffects.ambientAccessOfFunctions}
|
|
361
742
|
*/
|
|
362
|
-
function
|
|
363
|
-
const
|
|
364
|
-
const names = escapedDefinitionMap(
|
|
365
|
-
const
|
|
366
|
-
return
|
|
743
|
+
function ambientAccessOfFunctions(from) {
|
|
744
|
+
const [graph, environment] = graphOf(from);
|
|
745
|
+
const names = escapedDefinitionMap(graph, new Map());
|
|
746
|
+
const escaped = escapedDefinitions(graph, new Map());
|
|
747
|
+
return foldCallGraph(graph, ambient_access_1.AmbientAccess.monoid, (id, fdef) => monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, [
|
|
748
|
+
...df_helper_1.Dataflow.callsIn(fdef, graph).map(([call]) => accessOfCall(graph, call, environment)),
|
|
749
|
+
{
|
|
750
|
+
...ambient_access_1.AmbientAccess.empty,
|
|
751
|
+
variables: relation_1.Relation.fromPairs(escaped(id, fdef).flatMap(def => names.get(def) ?? []).filter(({ name }) => !ambient_state_name_1.AmbientStateName.is(name)).map(({ name, nodeId }) => [name, nodeId]))
|
|
752
|
+
}
|
|
753
|
+
]));
|
|
367
754
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
755
|
+
/** Adds the ids of every file a `source` call among `ids` runs, transitively, found by where the call continues with another file. */
|
|
756
|
+
function addSourcedFiles(graph, ids) {
|
|
757
|
+
const idMap = graph.idMap;
|
|
758
|
+
if (idMap === undefined) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const todo = [...ids];
|
|
762
|
+
for (let id = todo.pop(); id !== undefined; id = todo.pop()) {
|
|
763
|
+
if (!vertex_1.DfgVertex.hasOrigin(graph.getVertex(id), built_in_proc_name_1.BuiltInProcName.Source)) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const file = idMap.get(id)?.info.file;
|
|
767
|
+
for (const next of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.FlowEdge)) {
|
|
768
|
+
const node = idMap.get(next);
|
|
769
|
+
if (node === undefined || node.info.file === file || ids.has(next)) {
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const root = model_1.RNode.iterateParents(node, idMap).reduce((_, parent) => parent, node);
|
|
773
|
+
for (const inner of model_1.RNode.collectAllIds(root)) {
|
|
774
|
+
if (!ids.has(inner)) {
|
|
775
|
+
ids.add(inner);
|
|
776
|
+
todo.push(inner);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function idsOfScope(graph, scope) {
|
|
783
|
+
if (typeof scope === 'string' || typeof scope === 'number') {
|
|
784
|
+
const node = graph.idMap?.get(scope);
|
|
785
|
+
return node === undefined ? new Set([scope]) : model_1.RNode.collectAllIds(node);
|
|
786
|
+
}
|
|
787
|
+
else if (r_project_1.RProject.is(scope)) {
|
|
788
|
+
return r_project_1.RProject.collectAllIds(scope);
|
|
789
|
+
}
|
|
790
|
+
else if ('type' in scope) {
|
|
791
|
+
return model_1.RNode.collectAllIds(scope);
|
|
792
|
+
}
|
|
793
|
+
return new Set(scope);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* What running the given code reads and writes of the global state, see {@link AmbientAccess}: the calls in `scope` and, unless turned off, what the functions they call access.
|
|
797
|
+
* @useInstead {@link Dataflow.sideEffects.ambientAccess}
|
|
798
|
+
*/
|
|
799
|
+
function ambientAccessOf(from, scope, opts) {
|
|
800
|
+
const [graph, environment] = graphOf(from);
|
|
801
|
+
const ids = idsOfScope(graph, scope);
|
|
802
|
+
addSourcedFiles(graph, ids);
|
|
803
|
+
/* the bodies of nested definitions, exit hooks among them, are no part of the scope (`collectAllIds` misses the hooks) */
|
|
804
|
+
const bodies = new Set();
|
|
805
|
+
const definitions = [...ids];
|
|
806
|
+
for (let id = definitions.pop(); id !== undefined; id = definitions.pop()) {
|
|
807
|
+
const vertex = graph.getVertex(id);
|
|
808
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
809
|
+
for (const inner of vertex.subflow.graph) {
|
|
810
|
+
if (!bodies.has(inner)) {
|
|
811
|
+
bodies.add(inner);
|
|
812
|
+
definitions.push(inner);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
const accesses = [];
|
|
818
|
+
const callees = new Set();
|
|
819
|
+
for (const id of ids) {
|
|
820
|
+
if (bodies.has(id) || !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(id))) {
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
accesses.push(accessOfCall(graph, id, environment));
|
|
824
|
+
if (opts?.includeCallees !== false) {
|
|
825
|
+
for (const callee of df_helper_1.Dataflow.calleeIdsOf(graph, id)) {
|
|
826
|
+
callees.add(callee);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/* what the call evaluates that the code does not write (`eval(parse(text = s))`, `eval(call("f"))`, `do.call(name)`) is part of it */
|
|
830
|
+
for (const made of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument)) {
|
|
831
|
+
if (!node_id_1.NodeId.isWritten(made) && !node_id_1.NodeId.isBuiltIn(made)) {
|
|
832
|
+
const node = graph.idMap?.get(made);
|
|
833
|
+
(node === undefined ? [made] : model_1.RNode.collectAllIds(node)).forEach(inner => ids.add(inner));
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (callees.size > 0) {
|
|
838
|
+
const functions = opts?.functions ?? ambientAccessOfFunctions(from);
|
|
839
|
+
for (const callee of callees) {
|
|
840
|
+
const access = functions.get(callee);
|
|
841
|
+
if (access !== undefined) {
|
|
842
|
+
accesses.push(access);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, accesses);
|
|
376
847
|
}
|
|
377
848
|
/**
|
|
378
849
|
* Propagates every function's escaped side effects (attached packages and `<<-` definitions) to its transitive callers.
|
|
379
|
-
* @returns the enriched top-level environment and whether it grew (so the extractor can re-link and re-run to a fixpoint).
|
|
380
850
|
* @useInstead {@link Dataflow.sideEffects.propagateTransitive}
|
|
381
851
|
*/
|
|
382
852
|
function propagateTransitiveSideEffects(graph, environment, ctx, defined = new Set(), open = []) {
|
|
383
|
-
const hidden = hiddenBuiltInWrites(graph, environment);
|
|
853
|
+
const hidden = hiddenBuiltInWrites(graph, environment, (0, built_in_ambient_state_1.drawingWritesDevice)(ctx.config));
|
|
384
854
|
/* both passes ask what escapes each function, and neither changes a body or a call target in between */
|
|
385
|
-
const escapes = computeCallGraphSummaries(graph, escapedDefinitions(hidden));
|
|
855
|
+
const escapes = computeCallGraphSummaries(graph, escapedDefinitions(graph, hidden));
|
|
386
856
|
propagateTransitiveDefinitions(graph, environment, ctx, escapes);
|
|
387
857
|
const packages = propagateTransitivePackages(graph, environment, ctx);
|
|
388
858
|
const escaped = propagateTransitiveEscapedDefinitions(graph, packages.environment, defined, hidden, escapes, open);
|