@eagleoutice/flowr 2.17.4 → 2.17.6
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 +12 -89
- package/abstract-interpretation/absint-inference.d.ts +4 -4
- package/abstract-interpretation/absint-inference.js +12 -13
- package/abstract-interpretation/abstract-semantics.d.ts +2 -1
- package/abstract-interpretation/branch-paths-interpreter.js +60 -0
- package/abstract-interpretation/branch-paths.d.ts +60 -0
- package/abstract-interpretation/branch-paths.js +120 -0
- 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.d.ts +6 -1
- package/abstract-interpretation/data-frame/dataframe-semantics.js +67 -16
- 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 +18 -16
- package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -1
- 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/core.js +51 -0
- 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/cfg-dead-code.js +12 -7
- 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/packed.d.ts +10 -0
- package/data/packed.js +33 -0
- package/data/r-base-guards.generated.d.ts +7 -0
- package/data/r-base-guards.generated.js +12 -0
- package/data/r-base-primitives.generated.d.ts +2 -1
- package/data/r-datasets.generated.d.ts +4 -0
- package/data/r-datasets.generated.js +10 -0
- package/data/r-formals.generated.d.ts +4 -0
- package/data/r-formals.generated.js +10 -0
- package/data/r-group-method-guards.generated.d.ts +3 -0
- package/data/r-group-method-guards.generated.js +8 -0
- package/dataflow/cluster.js +1 -2
- package/dataflow/environments/ambient-effect.d.ts +1000 -0
- package/dataflow/environments/ambient-effect.js +234 -0
- package/dataflow/environments/ambient-state-name.d.ts +59 -24
- package/dataflow/environments/ambient-state-name.js +65 -21
- package/dataflow/environments/apply-kill.d.ts +9 -20
- package/dataflow/environments/apply-kill.js +62 -29
- 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 +69 -0
- package/dataflow/environments/built-in-kinds.js +39 -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 +75 -176
- package/dataflow/environments/built-in-props.js +53 -157
- package/dataflow/environments/built-in.d.ts +42 -73
- package/dataflow/environments/built-in.js +49 -93
- 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 +397 -0
- package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/base-language.js +69 -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 +83 -0
- package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/graphics-devices.js +67 -0
- package/dataflow/environments/default-builtin-config/guard-builders.d.ts +16 -0
- package/dataflow/environments/default-builtin-config/guard-builders.js +29 -0
- package/dataflow/environments/default-builtin-config/guards-primitive-lang.d.ts +15 -0
- package/dataflow/environments/default-builtin-config/guards-primitive-lang.js +228 -0
- package/dataflow/environments/default-builtin-config/guards-primitive-ops.d.ts +11 -0
- package/dataflow/environments/default-builtin-config/guards-primitive-ops.js +154 -0
- package/dataflow/environments/default-builtin-config/guards.d.ts +9 -0
- package/dataflow/environments/default-builtin-config/guards.js +211 -0
- package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
- package/dataflow/environments/default-builtin-config/index.js +129 -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 +33 -0
- package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-tidyverse.js +97 -0
- package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
- package/dataflow/environments/default-builtin-config/package-utils.js +38 -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 +33 -0
- package/dataflow/environments/default-builtin-config/r-formals.d.ts +13 -0
- package/dataflow/environments/default-builtin-config/r-formals.js +110 -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 +328 -0
- package/dataflow/environments/default-builtin-config/shared-configs.js +447 -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 +35 -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/diff.js +5 -2
- package/dataflow/environments/environment.d.ts +48 -52
- package/dataflow/environments/environment.js +62 -74
- package/dataflow/environments/group-generics.d.ts +16 -19
- package/dataflow/environments/group-generics.js +28 -15
- package/dataflow/environments/guard-facts.d.ts +169 -0
- package/dataflow/environments/guard-facts.js +26 -0
- package/dataflow/environments/identifier.d.ts +81 -428
- package/dataflow/environments/identifier.js +39 -145
- package/dataflow/environments/pkg-name.d.ts +198 -0
- package/dataflow/environments/pkg-name.js +3 -0
- package/dataflow/environments/query-fn-props.d.ts +28 -79
- package/dataflow/environments/query-fn-props.js +77 -115
- package/dataflow/environments/removal-marker.d.ts +2 -0
- package/dataflow/environments/removal-marker.js +5 -0
- 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 +4 -7
- package/dataflow/eval/resolve/resolve-strings.js +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 +111 -48
- 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 +4 -1
- package/dataflow/fn/condition-handlers.js +3 -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 +5 -5
- package/dataflow/fn/frame-reflection.js +24 -16
- package/dataflow/fn/function-props.d.ts +2 -5
- package/dataflow/fn/function-props.js +30 -46
- package/dataflow/fn/function-semantics.d.ts +44 -26
- package/dataflow/fn/function-semantics.js +19 -18
- package/dataflow/fn/guards/built-in-guards.d.ts +112 -0
- package/dataflow/fn/guards/built-in-guards.js +199 -0
- package/dataflow/fn/guards/call-contracts.d.ts +97 -0
- package/dataflow/fn/guards/call-contracts.js +331 -0
- package/dataflow/fn/guards/condition-grouping.d.ts +20 -0
- package/dataflow/fn/guards/condition-grouping.js +135 -0
- package/dataflow/fn/guards/function-guards.d.ts +112 -0
- package/dataflow/fn/guards/function-guards.js +1549 -0
- package/dataflow/fn/guards/group-method-guards.d.ts +28 -0
- package/dataflow/fn/guards/group-method-guards.js +56 -0
- package/dataflow/fn/guards/guard-claims.d.ts +125 -0
- package/dataflow/fn/guards/guard-claims.js +678 -0
- package/dataflow/fn/guards/guard-knowledge.d.ts +41 -0
- package/dataflow/fn/guards/guard-knowledge.js +180 -0
- package/dataflow/fn/guards/guard-term-syntax.d.ts +9 -0
- package/dataflow/fn/guards/guard-term-syntax.js +210 -0
- package/dataflow/fn/guards/guard-term.d.ts +136 -0
- package/dataflow/fn/guards/guard-term.js +550 -0
- package/dataflow/fn/guards/stated-guards.d.ts +13 -0
- package/dataflow/fn/guards/stated-guards.js +35 -0
- package/dataflow/fn/higher-order-function.d.ts +2 -0
- package/dataflow/fn/higher-order-function.js +3 -4
- package/dataflow/fn/strict-function.d.ts +14 -35
- package/dataflow/fn/strict-function.js +183 -146
- package/dataflow/graph/ambient-access.d.ts +54 -0
- package/dataflow/graph/ambient-access.js +86 -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 +54 -188
- package/dataflow/graph/df-helper.js +122 -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 +50 -97
- package/dataflow/graph/graph.js +72 -75
- 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 +4 -18
- package/dataflow/info.js +3 -1
- package/dataflow/internal/dispatch-linking.d.ts +73 -0
- package/dataflow/internal/dispatch-linking.js +333 -0
- package/dataflow/internal/linker.d.ts +50 -50
- package/dataflow/internal/linker.js +566 -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 +18 -47
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +12 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +12 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +38 -128
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +681 -339
- 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 +78 -45
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +17 -19
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +185 -78
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +5 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +26 -5
- 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 +438 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +40 -57
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +214 -117
- 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 +74 -17
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +20 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +420 -115
- 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 +6 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +8 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +530 -140
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +20 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +98 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +2 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +9 -16
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +14 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +40 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +18 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +8 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +39 -8
- 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-recall.js +4 -0
- 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 +27 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +74 -38
- 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 +9 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +42 -45
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +12 -18
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +72 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +19 -17
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +286 -81
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +7 -4
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +44 -30
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +723 -115
- 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 +6 -15
- package/dataflow/internal/process/functions/call/quoted.js +48 -65
- 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/dataflow/processor.d.ts +2 -0
- package/documentation/data/dfg/doc-ambient.d.ts +4 -0
- package/documentation/data/dfg/doc-ambient.js +74 -0
- 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 +15 -3
- package/documentation/wiki-interface.js +2 -1
- package/documentation/wiki-linter.js +27 -3
- package/documentation/wiki-linting-and-testing.js +15 -2
- package/documentation/wiki-query.js +223 -30
- package/index.d.ts +3 -1
- package/index.js +6 -3
- package/linter/linter-executor.js +1 -1
- package/linter/linter-rules.d.ts +78 -9
- package/linter/linter-rules.js +12 -1
- package/linter/linter-util.d.ts +3 -3
- package/linter/linter-util.js +1 -1
- package/linter/rules/call-contracts.d.ts +40 -0
- package/linter/rules/call-contracts.js +56 -0
- package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
- package/linter/rules/cmd-check/bogus-return.js +1 -1
- package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
- package/linter/rules/cmd-check/call-arguments.js +10 -11
- package/linter/rules/cmd-check/cmd-check-util.d.ts +8 -13
- package/linter/rules/cmd-check/cmd-check-util.js +0 -28
- 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-hooks.js +2 -1
- 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 +3 -2
- 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/interactive-functions.d.ts +30 -0
- package/linter/rules/interactive-functions.js +87 -0
- 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 +2 -2
- 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 +4 -3
- package/linter/rules/undefined-symbol-util.js +8 -2
- package/linter/rules/undefined-symbol.d.ts +3 -2
- package/linter/rules/undefined-symbol.js +18 -7
- 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/useless-loop.d.ts +1 -1
- 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-dependencies-context.js +2 -1
- 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 +36 -3
- package/project/flowr-analyzer.js +8 -2
- 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 +15 -5
- package/project/sigdb/decode.d.ts +11 -7
- package/project/sigdb/decode.js +11 -3
- package/project/sigdb/dict.d.ts +2 -1
- package/project/sigdb/dict.js +2 -2
- package/project/sigdb/guarded-source.d.ts +6 -0
- package/project/sigdb/guarded-source.js +29 -0
- 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 +90 -80
- package/project/sigdb/reader.js +27 -5
- package/project/sigdb/schema.d.ts +33 -10
- package/project/sigdb/signature-db.d.ts +6 -6
- package/queries/catalog/absint-query/absint-query-format.d.ts +6 -3
- package/queries/catalog/absint-query/absint-query-format.js +57 -2
- package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +58 -0
- package/queries/catalog/ambient-access-query/ambient-access-query-format.js +90 -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/cluster-query/cluster-query-format.d.ts +5 -2
- package/queries/catalog/cluster-query/cluster-query-format.js +19 -2
- package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +57 -0
- package/queries/catalog/code-clones-query/code-clones-query-format.js +105 -0
- package/queries/catalog/config-query/config-query-format.d.ts +5 -2
- package/queries/catalog/config-query/config-query-format.js +41 -2
- package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +5 -2
- package/queries/catalog/control-flow-query/control-flow-query-format.js +19 -2
- package/queries/catalog/data-columns-query/data-columns-query-format.d.ts +72 -0
- package/queries/catalog/data-columns-query/data-columns-query-format.js +215 -0
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +5 -2
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +38 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +5 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.js +18 -2
- 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 +4 -3
- package/queries/catalog/dependencies-query/dependencies-query-format.js +9 -4
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
- package/queries/catalog/dependencies-query/function-info/other-path-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/tagged-functions.d.ts +11 -0
- package/queries/catalog/dependencies-query/function-info/tagged-functions.js +18 -0
- package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
- package/queries/catalog/dice-query/dice-query-format.d.ts +8 -2
- package/queries/catalog/dice-query/dice-query-format.js +35 -2
- package/queries/catalog/does-call-query/does-call-query-format.d.ts +8 -4
- package/queries/catalog/does-call-query/does-call-query-format.js +115 -2
- package/queries/catalog/files-query/files-query-format.d.ts +5 -2
- package/queries/catalog/files-query/files-query-format.js +45 -2
- 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-format.d.ts +11 -7
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +303 -2
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +9 -4
- package/queries/catalog/happens-before-query/happens-before-query-format.js +38 -2
- package/queries/catalog/id-map-query/id-map-query-format.d.ts +5 -2
- package/queries/catalog/id-map-query/id-map-query-format.js +18 -2
- 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/inspect-exceptions-query/inspect-exception-query-format.d.ts +5 -2
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +29 -2
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +37 -0
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +125 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -2
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +54 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +6 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +23 -2
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +6 -2
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +15 -2
- package/queries/catalog/linter-query/linter-query-format.d.ts +8 -2
- package/queries/catalog/linter-query/linter-query-format.js +72 -6
- package/queries/catalog/location-map-query/location-map-query-format.d.ts +7 -3
- package/queries/catalog/location-map-query/location-map-query-format.js +70 -2
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +5 -2
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +18 -2
- package/queries/catalog/origin-query/origin-query-format.d.ts +7 -3
- package/queries/catalog/origin-query/origin-query-format.js +30 -2
- package/queries/catalog/project-query/project-query-format.d.ts +8 -4
- package/queries/catalog/project-query/project-query-format.js +98 -2
- package/queries/catalog/provenance-query/provenance-query-format.d.ts +7 -3
- package/queries/catalog/provenance-query/provenance-query-format.js +31 -2
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +10 -2
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +39 -2
- package/queries/catalog/search-query/search-query-format.d.ts +5 -2
- package/queries/catalog/search-query/search-query-format.js +23 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +9 -6
- package/queries/catalog/signature-query/signature-query-executor.js +17 -16
- package/queries/catalog/signature-query/signature-query-format.d.ts +24 -20
- package/queries/catalog/signature-query/signature-query-render.js +24 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +22 -7
- package/queries/catalog/static-slice-query/static-slice-query-format.js +56 -2
- package/queries/catalog/taint-query/taint-query-format.d.ts +6 -3
- package/queries/catalog/taint-query/taint-query-format.js +28 -2
- package/queries/query-function-filter.d.ts +1 -1
- package/queries/query.d.ts +104 -32
- package/queries/query.js +61 -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 +9 -2
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +18 -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 +10 -4
- package/reconstruct/auto-select/magic-comments.js +1 -1
- package/reconstruct/reconstruct.d.ts +0 -5
- package/reconstruct/reconstruct.js +24 -8
- 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 +6 -4
- package/slicing/static/slice-call.d.ts +41 -4
- package/slicing/static/slice-call.js +117 -11
- package/slicing/static/slicer-types.d.ts +2 -1
- package/slicing/static/static-slicer.d.ts +2 -0
- package/slicing/static/static-slicer.js +199 -28
- package/slicing/static/visiting-queue.d.ts +4 -0
- package/slicing/static/visiting-queue.js +8 -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/objects.d.ts +2 -0
- package/util/objects.js +5 -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-datasets.d.ts +27 -0
- package/util/r-datasets.js +45 -0
- 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/playground-link.d.ts +2 -0
- package/util/text/playground-link.js +2 -0
- 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/queries/catalog/absint-query/absint-query-executor.d.ts +0 -6
- package/queries/catalog/absint-query/absint-query-executor.js +0 -61
- package/queries/catalog/cluster-query/cluster-query-executor.d.ts +0 -6
- package/queries/catalog/cluster-query/cluster-query-executor.js +0 -21
- package/queries/catalog/config-query/config-query-executor.d.ts +0 -6
- package/queries/catalog/config-query/config-query-executor.js +0 -45
- package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +0 -6
- package/queries/catalog/control-flow-query/control-flow-query-executor.js +0 -21
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.d.ts +0 -6
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +0 -40
- package/queries/catalog/dataflow-query/dataflow-query-executor.d.ts +0 -6
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +0 -20
- package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +0 -9
- package/queries/catalog/dependencies-query/function-info/statistics-functions.js +0 -18
- package/queries/catalog/dice-query/dice-query-executor.d.ts +0 -8
- package/queries/catalog/dice-query/dice-query-executor.js +0 -37
- package/queries/catalog/does-call-query/does-call-query-executor.d.ts +0 -6
- package/queries/catalog/does-call-query/does-call-query-executor.js +0 -117
- package/queries/catalog/files-query/files-query-executor.d.ts +0 -6
- package/queries/catalog/files-query/files-query-executor.js +0 -47
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.d.ts +0 -6
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +0 -307
- package/queries/catalog/happens-before-query/happens-before-query-executor.d.ts +0 -7
- package/queries/catalog/happens-before-query/happens-before-query-executor.js +0 -40
- package/queries/catalog/id-map-query/id-map-query-executor.d.ts +0 -6
- package/queries/catalog/id-map-query/id-map-query-executor.js +0 -20
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -6
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +0 -31
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.d.ts +0 -4
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +0 -58
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.d.ts +0 -7
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +0 -25
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.d.ts +0 -7
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +0 -17
- package/queries/catalog/linter-query/linter-query-executor.d.ts +0 -9
- package/queries/catalog/linter-query/linter-query-executor.js +0 -59
- package/queries/catalog/location-map-query/location-map-query-executor.d.ts +0 -7
- package/queries/catalog/location-map-query/location-map-query-executor.js +0 -73
- package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.d.ts +0 -6
- package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.js +0 -20
- package/queries/catalog/origin-query/origin-query-executor.d.ts +0 -6
- package/queries/catalog/origin-query/origin-query-executor.js +0 -31
- package/queries/catalog/project-query/project-query-executor.d.ts +0 -6
- package/queries/catalog/project-query/project-query-executor.js +0 -103
- package/queries/catalog/provenance-query/provenance-query-executor.d.ts +0 -6
- package/queries/catalog/provenance-query/provenance-query-executor.js +0 -33
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.d.ts +0 -10
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +0 -40
- package/queries/catalog/search-query/search-query-executor.d.ts +0 -6
- package/queries/catalog/search-query/search-query-executor.js +0 -25
- package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +0 -14
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +0 -59
- package/queries/catalog/taint-query/taint-query-executor.d.ts +0 -7
- package/queries/catalog/taint-query/taint-query-executor.js +0 -30
- 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.js +0 -124
- package/taint-analysis/eval/instrumentation.d.ts +0 -59
- package/taint-analysis/eval/instrumentation.js +0 -124
- /package/{taint-analysis/eval/eval.d.ts → abstract-interpretation/branch-paths-interpreter.d.ts} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrintingOptions = void 0;
|
|
4
|
-
exports.isAssumedWrite = isAssumedWrite;
|
|
3
|
+
exports.PrintWrites = exports.PrintingOptions = void 0;
|
|
5
4
|
exports.hidesBody = hidesBody;
|
|
6
5
|
exports.reachesBuiltInLate = reachesBuiltInLate;
|
|
7
6
|
exports.readsAllAmbientState = readsAllAmbientState;
|
|
@@ -10,9 +9,13 @@ exports.ambientWritesOfRelease = ambientWritesOfRelease;
|
|
|
10
9
|
exports.makeAmbientWritesMaybe = makeAmbientWritesMaybe;
|
|
11
10
|
exports.ambientWritesBetween = ambientWritesBetween;
|
|
12
11
|
exports.markForcing = markForcing;
|
|
12
|
+
exports.markLocking = markLocking;
|
|
13
|
+
exports.mayLock = mayLock;
|
|
13
14
|
exports.mayForce = mayForce;
|
|
14
15
|
exports.ambientAccessOfSymbol = ambientAccessOfSymbol;
|
|
15
|
-
exports.
|
|
16
|
+
exports.holds = holds;
|
|
17
|
+
exports.drawingWritesDevice = drawingWritesDevice;
|
|
18
|
+
exports.applyAmbientEffects = applyAmbientEffects;
|
|
16
19
|
exports.applyAmbientStateOfCallee = applyAmbientStateOfCallee;
|
|
17
20
|
exports.hiddenSideEffects = hiddenSideEffects;
|
|
18
21
|
exports.writesOfHiddenBuiltIn = writesOfHiddenBuiltIn;
|
|
@@ -21,10 +24,15 @@ exports.callOnlyQueries = callOnlyQueries;
|
|
|
21
24
|
exports.linkAmbientStateWithinLoop = linkAmbientStateWithinLoop;
|
|
22
25
|
exports.processAmbientScope = processAmbientScope;
|
|
23
26
|
exports.evaluatesCapturedCode = evaluatesCapturedCode;
|
|
27
|
+
exports.autoPrintReads = autoPrintReads;
|
|
24
28
|
exports.readsOfAutoPrint = readsOfAutoPrint;
|
|
29
|
+
exports.autoPrintsStatementsOf = autoPrintsStatementsOf;
|
|
25
30
|
exports.autoPrints = autoPrints;
|
|
26
31
|
exports.applyAmbientStateOfCalledBuiltIns = applyAmbientStateOfCalledBuiltIns;
|
|
27
32
|
exports.errorsOfWarnings = errorsOfWarnings;
|
|
33
|
+
exports.signalSites = signalSites;
|
|
34
|
+
exports.maySignal = maySignal;
|
|
35
|
+
exports.testsValue = testsValue;
|
|
28
36
|
const info_1 = require("../../../../../info");
|
|
29
37
|
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
30
38
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
@@ -33,6 +41,8 @@ const built_in_props_1 = require("../../../../../environments/built-in-props");
|
|
|
33
41
|
const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
34
42
|
const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
35
43
|
const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
44
|
+
const r_logical_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
|
|
45
|
+
const query_fn_props_1 = require("../../../../../environments/query-fn-props");
|
|
36
46
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
37
47
|
const environment_1 = require("../../../../../environments/environment");
|
|
38
48
|
const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
|
|
@@ -43,10 +53,12 @@ const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast
|
|
|
43
53
|
const r_value_1 = require("../../../../../eval/values/r-value");
|
|
44
54
|
const match_args_1 = require("../../../../../graph/match-args");
|
|
45
55
|
const known_call_handling_1 = require("../known-call-handling");
|
|
56
|
+
const built_in_expression_list_1 = require("./built-in-expression-list");
|
|
46
57
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
47
58
|
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
48
59
|
const applied_arguments_1 = require("../../../../../graph/applied-arguments");
|
|
49
60
|
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
|
|
61
|
+
const df_helper_1 = require("../../../../../graph/df-helper");
|
|
50
62
|
const edge_1 = require("../../../../../graph/edge");
|
|
51
63
|
const assert_1 = require("../../../../../../util/assert");
|
|
52
64
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
@@ -55,34 +67,96 @@ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/
|
|
|
55
67
|
const convert_values_1 = require("../../../../../../r-bridge/lang-4.x/convert-values");
|
|
56
68
|
const r_if_then_else_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
|
|
57
69
|
const arrays_1 = require("../../../../../../util/collections/arrays");
|
|
70
|
+
const ambient_access_1 = require("../../../../../graph/ambient-access");
|
|
58
71
|
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
59
72
|
const built_in_ambient_keys_1 = require("./built-in-ambient-keys");
|
|
73
|
+
const logic_1 = require("../../../../../../util/logic");
|
|
74
|
+
const base_operators_1 = require("../../../../../environments/default-builtin-config/base-operators");
|
|
75
|
+
const r_while_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-while-loop");
|
|
76
|
+
const r_for_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
|
|
77
|
+
const built_in_kinds_1 = require("../../../../../environments/built-in-kinds");
|
|
78
|
+
const ambient_effect_1 = require("../../../../../environments/ambient-effect");
|
|
79
|
+
var built_in_kinds_2 = require("../../../../../environments/built-in-kinds");
|
|
80
|
+
Object.defineProperty(exports, "PrintingOptions", { enumerable: true, get: function () { return built_in_kinds_2.PrintingOptions; } });
|
|
60
81
|
const ListConstructors = new Set(['list', 'c']);
|
|
61
|
-
|
|
82
|
+
/** the states of the active instance of a family */
|
|
83
|
+
function activeStates(family) {
|
|
84
|
+
return family.states.map(([active]) => active);
|
|
85
|
+
}
|
|
86
|
+
const DeviceStates = ambient_state_name_1.GraphicsDevices.states.flat();
|
|
62
87
|
const Accumulating = new Set([
|
|
63
|
-
...DeviceStates, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.unknownOption,
|
|
88
|
+
...DeviceStates, ...ambient_state_name_1.OutputSinks.states.flat(), ...ambient_state_name_1.MessageSinks.states.flat(), ambient_state_name_1.AmbientStateName.canvas, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.unknownOption,
|
|
64
89
|
ambient_state_name_1.AmbientStateName.warnsAsErrors, ambient_state_name_1.AmbientStateName.files, ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.finalizers, ...ambient_state_name_1.KeyedAccumulators
|
|
65
90
|
]);
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
/** What a call does to the graphics devices. */
|
|
92
|
+
var DeviceAccess;
|
|
93
|
+
(function (DeviceAccess) {
|
|
94
|
+
DeviceAccess["Open"] = "open";
|
|
95
|
+
DeviceAccess["Close"] = "close";
|
|
96
|
+
DeviceAccess["CloseAll"] = "close-all";
|
|
97
|
+
/** closes one that is not known to be the active one, which writes what any of them holds */
|
|
98
|
+
DeviceAccess["CloseSome"] = "close-some";
|
|
99
|
+
/** makes another one active */
|
|
100
|
+
DeviceAccess["Switch"] = "switch";
|
|
101
|
+
})(DeviceAccess || (DeviceAccess = {}));
|
|
102
|
+
/** How a write differs from the default, see {@link AmbientWrite}. */
|
|
103
|
+
var AmbientWriteMode;
|
|
104
|
+
(function (AmbientWriteMode) {
|
|
105
|
+
/** binds in the current frame only (`withr::local_options`) */
|
|
106
|
+
AmbientWriteMode["Local"] = "local";
|
|
107
|
+
/** replaces an accumulating state (a new device) */
|
|
108
|
+
AmbientWriteMode["Reset"] = "reset";
|
|
109
|
+
/** may not happen */
|
|
110
|
+
AmbientWriteMode["Maybe"] = "maybe";
|
|
111
|
+
})(AmbientWriteMode || (AmbientWriteMode = {}));
|
|
70
112
|
/** a write that may not happen: it reads what was there, so it can still replace the state and keep everything before reachable */
|
|
71
113
|
function maybe(name) {
|
|
72
|
-
return { name, mode:
|
|
114
|
+
return { name, mode: AmbientWriteMode.Maybe };
|
|
73
115
|
}
|
|
74
116
|
/** what reading the options `keys` reads, every option if the keys are unknown */
|
|
75
117
|
function optionReads(keys) {
|
|
76
118
|
return keys === undefined ? [ambient_state_name_1.AmbientStateName.allOptions] : [...keys.map(ambient_state_name_1.AmbientStateName.option), ambient_state_name_1.AmbientStateName.unknownOption];
|
|
77
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Links a call handing back the entry `key` of a keyed state (`getOption("digits")`, `Sys.getenv("A")`, `par("mfrow")`) to the values the calls that may have set it last gave it,
|
|
122
|
+
* so value resolution sees them like the result of a call. It links only if these calls cover every path and named the entry, as anything else (`options(op)`, `layout(m)`, a new device) may set it to a value we do not know.
|
|
123
|
+
*/
|
|
124
|
+
function linkEntryValue(res, rootId, state, keys, data) {
|
|
125
|
+
const [key] = keys;
|
|
126
|
+
if (keys.length !== 1 || key === ambient_state_name_1.UnknownKey || resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.keyed(state, ambient_state_name_1.UnknownKey), data.environment)?.some(d => !node_id_1.NodeId.isBuiltIn(d.nodeId))) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const defs = resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.keyed(state, key), data.environment) ?? [];
|
|
130
|
+
const whole = new Set((resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.allOf(state), data.environment) ?? []).map(d => d.nodeId));
|
|
131
|
+
const own = new Set(defs.map(d => d.nodeId));
|
|
132
|
+
/* a write of the whole state that names no entry, like `layout(m)`, may change this one as well */
|
|
133
|
+
const namesEntries = (id) => {
|
|
134
|
+
const setter = data.completeAst.idMap.get(id);
|
|
135
|
+
return node_id_1.NodeId.isBuiltIn(id) || (r_function_call_1.RFunctionCall.is(setter) && setter.arguments.every(a => a === r_function_call_1.EmptyArgument || a.name !== undefined));
|
|
136
|
+
};
|
|
137
|
+
if (defs.length === 0 || [...whole].some(id => !own.has(id) && !namesEntries(id)) || !(defs.some(d => (0, info_1.happensInEveryBranch)(d.cds)) || (0, info_1.happensInEveryBranch)(defs.flatMap(d => d.cds ?? [])))) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const values = [];
|
|
141
|
+
for (const { nodeId } of defs) {
|
|
142
|
+
const setter = data.completeAst.idMap.get(nodeId);
|
|
143
|
+
const named = r_function_call_1.RFunctionCall.is(setter) && whole.has(nodeId) ? setter.arguments.filter(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) === key) : [];
|
|
144
|
+
const value = named.length === 1 ? r_argument_1.RArgument.valueOf(named[0]) : undefined;
|
|
145
|
+
/* setting an option to NULL removes it, so reading it hands back the default instead */
|
|
146
|
+
if (value === undefined || (r_symbol_1.RSymbol.is(value) && identifier_1.Identifier.getName(value.content) === 'NULL')) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
values.push(value.info.id);
|
|
150
|
+
}
|
|
151
|
+
for (const value of values) {
|
|
152
|
+
res.graph.addEdge(rootId, value, edge_1.EdgeType.Returns);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
78
155
|
/** Whether calling `definition` runs a body flowR cannot see: a library function's, or whatever a parameter is bound to. */
|
|
79
156
|
function hidesBody(definition) {
|
|
80
157
|
return node_id_1.NodeId.isBuiltIn(definition.nodeId) || (0, identifier_1.isReferenceType)(definition.type, identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument);
|
|
81
158
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Whether the call `call` of a function body reaches a built-in only once linked where the function is called, through a parameter
|
|
84
|
-
* or a name the body cannot resolve. Through a variable (`p <- par; p(...)`) the body applied the built-in already, see {@link applyAmbientStateOfCalledBuiltIns}.
|
|
85
|
-
*/
|
|
159
|
+
/** Whether the call `call` of a function body reaches a built-in only once linked where the function is called, through a parameter or a name the body cannot resolve. */
|
|
86
160
|
function reachesBuiltInLate(call) {
|
|
87
161
|
const definitions = call.environment === undefined ? [] : resolve_helper_1.Resolve.byNameAndType(call.name, call.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
88
162
|
return definitions.length === 0 || definitions.some(hidesBody);
|
|
@@ -96,13 +170,15 @@ function readsAllAmbientState(res, rootId, data, graphics, draws = true) {
|
|
|
96
170
|
return withAccess(res, rootId, data, reads, draws ? [{ ...maybe(ambient_state_name_1.AmbientStateName.rng), assumed: true }] : []);
|
|
97
171
|
}
|
|
98
172
|
/** Adds the reads and writes of the ambient state to what a call does, see {@link AmbientStateName}. */
|
|
99
|
-
function withAccess(res, rootId, data, reads, writes = []) {
|
|
100
|
-
if (reads.length === 0 && writes.length === 0) {
|
|
173
|
+
function withAccess(res, rootId, data, reads, writes = [], kills = []) {
|
|
174
|
+
if (reads.length === 0 && writes.length === 0 && kills.length === 0) {
|
|
101
175
|
return res;
|
|
102
176
|
}
|
|
103
177
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
104
|
-
const maybeWritten = writes.flatMap(w => typeof w === 'object' && w.mode ===
|
|
105
|
-
const
|
|
178
|
+
const maybeWritten = writes.flatMap(w => typeof w === 'object' && w.mode === AmbientWriteMode.Maybe ? [w.name] : []);
|
|
179
|
+
const read = (0, arrays_1.uniqueArrayMerge)(reads, maybeWritten);
|
|
180
|
+
const readRefs = read.map(name => ({ nodeId: rootId, name, type: identifier_1.ReferenceType.Variable, cds }));
|
|
181
|
+
recordAmbient(res.graph, rootId, res.environment, read, writes, kills);
|
|
106
182
|
/* the writes stay out of `out`: an assignment reads whatever else its source writes (`x <- y <- 3`) */
|
|
107
183
|
return {
|
|
108
184
|
...res,
|
|
@@ -110,15 +186,37 @@ function withAccess(res, rootId, data, reads, writes = []) {
|
|
|
110
186
|
environment: defineAmbient(res.environment, rootId, cds, writes)
|
|
111
187
|
};
|
|
112
188
|
}
|
|
189
|
+
/** Whether the write of `name` binds in the current frame only, see {@link AmbientWrite}. */
|
|
190
|
+
function writesLocally(environment, name, mode) {
|
|
191
|
+
return mode === AmbientWriteMode.Local || (environment.level > 0 && environment.current.memory.has(name));
|
|
192
|
+
}
|
|
193
|
+
/** Notes in `graph` what the call `rootId` reads, writes, and ends (`kills`), see {@link DataflowGraph#recordAmbientAccess}; `environment` is the one the writes apply to. */
|
|
194
|
+
function recordAmbient(graph, rootId, environment, reads, writes, kills = []) {
|
|
195
|
+
if (reads.length === 0 && writes.length === 0 && kills.length === 0) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const global = [];
|
|
199
|
+
const assumed = [];
|
|
200
|
+
const local = [];
|
|
201
|
+
for (const write of writes) {
|
|
202
|
+
const { name, mode, assumed: isAssumed } = typeof write === 'string' ? { name: write, mode: undefined, assumed: undefined } : write;
|
|
203
|
+
(writesLocally(environment, name, mode) ? local : isAssumed ? assumed : global).push(name);
|
|
204
|
+
}
|
|
205
|
+
graph.recordAmbientAccess(rootId, { reads, writes: global, assumed, local, kills });
|
|
206
|
+
}
|
|
207
|
+
/** Whether the code itself binds a variable of the same name, by quoting it in backticks, which a write of the state must not replace, as they only share the name. */
|
|
208
|
+
function boundByCode(environment, name) {
|
|
209
|
+
return resolve_helper_1.Resolve.byName(name, environment)?.some(d => d.nodeId !== d.definedAt) === true;
|
|
210
|
+
}
|
|
113
211
|
/** Applies the writes of the call `rootId` to the environment, see {@link withAccess}. */
|
|
114
212
|
function defineAmbient(environment, rootId, cds, writes) {
|
|
115
213
|
for (const write of writes) {
|
|
116
214
|
const { name, mode, assumed } = typeof write === 'string' ? { name: write, mode: undefined, assumed: undefined } : write;
|
|
117
215
|
const accumulates = Accumulating.has(name) || name.startsWith(ambient_state_name_1.AmbientStateName.file(''));
|
|
118
216
|
/* an assumed write keeps what the body wrote before, which, other than it, surely happened */
|
|
119
|
-
const keep = (accumulates && (mode === undefined || mode ===
|
|
217
|
+
const keep = (accumulates && (mode === undefined || mode === AmbientWriteMode.Maybe)) || assumed === true || boundByCode(environment, name);
|
|
120
218
|
/* an accumulating state only ever grows, its definitions are maybe so merging environments keeps them all; a reset is definite */
|
|
121
|
-
const isMaybe = keep || (accumulates && mode !==
|
|
219
|
+
const isMaybe = keep || (accumulates && mode !== AmbientWriteMode.Reset);
|
|
122
220
|
const def = {
|
|
123
221
|
nodeId: rootId,
|
|
124
222
|
name,
|
|
@@ -128,21 +226,25 @@ function defineAmbient(environment, rootId, cds, writes) {
|
|
|
128
226
|
...assumed ? { assumed } : {}
|
|
129
227
|
};
|
|
130
228
|
/* the state is global, wherever the call happens, unless the call or an earlier one (`local_seed`) scopes it to the current frame */
|
|
131
|
-
|
|
132
|
-
environment = environment_1.REnvironment.define(def, !local, environment, keep);
|
|
229
|
+
environment = environment_1.REnvironment.define(def, !writesLocally(environment, name, mode), environment, keep);
|
|
133
230
|
}
|
|
134
231
|
return environment;
|
|
135
232
|
}
|
|
233
|
+
/** {@link defineAmbient}, recording the writes for `rootId` in `graph` as well. */
|
|
234
|
+
function defineRecorded(graph, environment, rootId, cds, writes) {
|
|
235
|
+
recordAmbient(graph, rootId, environment, [], writes);
|
|
236
|
+
return defineAmbient(environment, rootId, cds, writes);
|
|
237
|
+
}
|
|
136
238
|
/** What an assignment writes beyond its target: only a global `.Random.seed` sets {@link AmbientStateName.rng}. */
|
|
137
|
-
function ambientWritesOfAssignment(environment, target, rootId, cds, global) {
|
|
138
|
-
environment = ambientWritesOfRelease(environment, [target], rootId, cds);
|
|
139
|
-
return global && identifier_1.Identifier.getName(target) === ambient_state_name_1.AmbientStateName.rngVariable ?
|
|
239
|
+
function ambientWritesOfAssignment(graph, environment, target, rootId, cds, global) {
|
|
240
|
+
environment = ambientWritesOfRelease(graph, environment, [target], rootId, cds);
|
|
241
|
+
return global && identifier_1.Identifier.getName(target) === ambient_state_name_1.AmbientStateName.rngVariable ? defineRecorded(graph, environment, rootId, cds, [ambient_state_name_1.AmbientStateName.rng, ambient_state_name_1.AmbientStateName.rngKind]) : environment;
|
|
140
242
|
}
|
|
141
243
|
/** Rebinding or removing the names (all of them if `undefined`) may release an object a finalizer is registered for. */
|
|
142
|
-
function ambientWritesOfRelease(environment, names, rootId, cds) {
|
|
143
|
-
const holders = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.finalizers, environment) ?? []).map(d => d.holder);
|
|
244
|
+
function ambientWritesOfRelease(graph, environment, names, rootId, cds) {
|
|
245
|
+
const holders = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.finalizers, environment) ?? []).filter(identifier_1.isInGraphDefinition).map(d => d.holder);
|
|
144
246
|
const released = holders.some(h => h === undefined || names === undefined || names.some(n => identifier_1.Identifier.getName(n) === h));
|
|
145
|
-
return released ?
|
|
247
|
+
return released ? defineRecorded(graph, environment, rootId, cds, [ambient_state_name_1.AmbientStateName.finalizers]) : environment;
|
|
146
248
|
}
|
|
147
249
|
function* ambientDefinitionsBetween(after, before, skipUnchanged) {
|
|
148
250
|
let unchanged = before.current;
|
|
@@ -182,6 +284,14 @@ function ambientWritesBetween(after, before) {
|
|
|
182
284
|
function markForcing(environment) {
|
|
183
285
|
environment_1.REnvironment.findBuiltIn(environment.current).forcing = true;
|
|
184
286
|
}
|
|
287
|
+
/** Notes that a call may lock a binding or an environment (`lockBinding`), after which binding a name may fail. */
|
|
288
|
+
function markLocking(environment) {
|
|
289
|
+
environment_1.REnvironment.findBuiltIn(environment.current).locking = true;
|
|
290
|
+
}
|
|
291
|
+
/** Whether a call seen so far may lock a binding, see {@link markLocking}. */
|
|
292
|
+
function mayLock(environment) {
|
|
293
|
+
return environment_1.REnvironment.findBuiltIn(environment.current).locking === true;
|
|
294
|
+
}
|
|
185
295
|
/** Whether a definition seen so far binds a promise or a text connection, see {@link markForcing}. */
|
|
186
296
|
function mayForce(environment) {
|
|
187
297
|
return environment_1.REnvironment.findBuiltIn(environment.current).forcing === true;
|
|
@@ -190,8 +300,17 @@ function mayForce(environment) {
|
|
|
190
300
|
function ambientAccessOfSymbol(res, symbol, data) {
|
|
191
301
|
const forcing = mayForce(data.environment);
|
|
192
302
|
const definitions = forcing ? resolve_helper_1.Resolve.byName(symbol.content, data.environment) ?? [] : [];
|
|
193
|
-
const
|
|
194
|
-
|
|
303
|
+
const promises = definitions.filter(identifier_1.isInGraphDefinition);
|
|
304
|
+
const reads = (0, arrays_1.uniqueArrayMerge)(ambientReadsOfSymbol(symbol, data, forcing), promises.flatMap(d => d.forcedReads ?? []));
|
|
305
|
+
const accessed = withAccess(res, symbol.info.id, data, reads, promises.flatMap(d => d.forces ?? []).map(maybe));
|
|
306
|
+
/* a read may be the one forcing the promise, so what its code binds may be bound from here on (the first read forces it, so only maybe) */
|
|
307
|
+
let environment = accessed.environment;
|
|
308
|
+
for (const write of promises.flatMap(d => d.forcedWrites ?? [])) {
|
|
309
|
+
environment = environment_1.REnvironment.define(write, false, environment, true);
|
|
310
|
+
}
|
|
311
|
+
/* a read reached either forces the promise or comes after a forcing that left already, so it leaves as the promise does */
|
|
312
|
+
const exits = promises.flatMap(d => d.forcedExits ?? []).map(e => ({ ...e, nodeId: symbol.info.id, cds: e.cds ?? data.cds }));
|
|
313
|
+
return environment === accessed.environment && exits.length === 0 ? accessed : { ...accessed, environment, exitPoints: [...accessed.exitPoints, ...exits] };
|
|
195
314
|
}
|
|
196
315
|
/** Binds `name` (globally) to the given definitions, in addition to what it holds with `keep`, so `#graphics` can become what another state holds. */
|
|
197
316
|
function setAmbient(environment, name, definitions, keep = false) {
|
|
@@ -246,140 +365,263 @@ const GlobalEffectEnv = /^(TZ|LANG|LANGUAGE|LC_\w+|R_\w+|TMPDIR|TEMP|TMP|HOME|PA
|
|
|
246
365
|
function keyedReads(state, keys) {
|
|
247
366
|
return keys.length === 0 || keys.includes(ambient_state_name_1.UnknownKey) ? [ambient_state_name_1.AmbientStateName.allOf(state)] : [...keys.map(k => ambient_state_name_1.AmbientStateName.keyed(state, k)), ambient_state_name_1.AmbientStateName.keyed(state, ambient_state_name_1.UnknownKey)];
|
|
248
367
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
368
|
+
const Families = {
|
|
369
|
+
[ambient_effect_1.AmbientPart.Device]: { state: ambient_state_name_1.AmbientStateName.device, instances: ambient_state_name_1.GraphicsDevices },
|
|
370
|
+
[ambient_effect_1.AmbientPart.Sink]: { state: ambient_state_name_1.AmbientStateName.sink, instances: ambient_state_name_1.OutputSinks },
|
|
371
|
+
[ambient_effect_1.AmbientPart.MessageSink]: { state: ambient_state_name_1.MessageSinks.switched, instances: ambient_state_name_1.MessageSinks },
|
|
372
|
+
[ambient_effect_1.AmbientPart.Plot]: { state: ambient_state_name_1.AmbientStateName.plot, of: ambient_state_name_1.GraphicsDevices },
|
|
373
|
+
[ambient_state_name_1.KeyedState.Par]: { state: ambient_state_name_1.AmbientStateName.graphics, keyed: ambient_state_name_1.KeyedState.Par, of: ambient_state_name_1.GraphicsDevices },
|
|
374
|
+
[ambient_effect_1.AmbientPart.Palette]: { state: ambient_state_name_1.AmbientStateName.palette },
|
|
375
|
+
[ambient_effect_1.AmbientPart.LastPlot]: { state: ambient_state_name_1.AmbientStateName.lastPlot },
|
|
376
|
+
[ambient_state_name_1.KeyedState.Option]: { state: ambient_state_name_1.AmbientStateName.allOptions, keyed: ambient_state_name_1.KeyedState.Option },
|
|
377
|
+
[ambient_state_name_1.KeyedState.Env]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.Env), keyed: ambient_state_name_1.KeyedState.Env },
|
|
378
|
+
[ambient_state_name_1.KeyedState.Locale]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.Locale), keyed: ambient_state_name_1.KeyedState.Locale },
|
|
379
|
+
[ambient_state_name_1.KeyedState.SearchPath]: { state: ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.SearchPath), keyed: ambient_state_name_1.KeyedState.SearchPath },
|
|
380
|
+
[ambient_effect_1.AmbientPart.Rng]: { state: ambient_state_name_1.AmbientStateName.rng },
|
|
381
|
+
[ambient_effect_1.AmbientPart.RngKind]: { state: ambient_state_name_1.AmbientStateName.rngKind },
|
|
382
|
+
[ambient_effect_1.AmbientPart.WorkingDirectory]: { state: ambient_state_name_1.AmbientStateName.workingDirectory },
|
|
383
|
+
[ambient_effect_1.AmbientPart.Directories]: { state: ambient_state_name_1.AmbientStateName.directories },
|
|
384
|
+
[ambient_effect_1.AmbientPart.Files]: { state: ambient_state_name_1.AmbientStateName.files },
|
|
385
|
+
[ambient_effect_1.AmbientPart.ProjectRoot]: { state: ambient_state_name_1.AmbientStateName.projectRoot },
|
|
386
|
+
[ambient_effect_1.AmbientPart.LibPaths]: { state: ambient_state_name_1.AmbientStateName.libPaths },
|
|
387
|
+
[ambient_effect_1.AmbientPart.Umask]: { state: ambient_state_name_1.AmbientStateName.umask },
|
|
388
|
+
[ambient_effect_1.AmbientPart.Finalizers]: { state: ambient_state_name_1.AmbientStateName.finalizers },
|
|
389
|
+
[ambient_effect_1.AmbientPart.TextConnection]: { state: ambient_state_name_1.AmbientStateName.anyFile },
|
|
390
|
+
[ambient_effect_1.AmbientPart.ErrorMessage]: { state: ambient_state_name_1.AmbientStateName.errorMessage }
|
|
391
|
+
};
|
|
392
|
+
/** Whether an effect changes the state, so a call whose only changes are off only queries it. */
|
|
393
|
+
function changes(effect) {
|
|
394
|
+
return effect.access !== ambient_effect_1.AmbientVerb.Reads && effect.access !== ambient_effect_1.AmbientVerb.Builds;
|
|
395
|
+
}
|
|
396
|
+
/** Whether the `condition` holds for the arguments `args`, what values are known decided with `data`. */
|
|
397
|
+
function holds(condition, args, data) {
|
|
398
|
+
if (condition === 'no-arguments') {
|
|
399
|
+
return args.length === 0 ? logic_1.Ternary.Always : logic_1.Ternary.Never;
|
|
400
|
+
}
|
|
401
|
+
else if (condition === 'query') {
|
|
402
|
+
return isQuery(args) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
|
|
403
|
+
}
|
|
404
|
+
else if ('flag' in condition) {
|
|
405
|
+
const flag = args.find(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) === condition.flag);
|
|
406
|
+
return flag === undefined || flag === r_function_call_1.EmptyArgument ? logic_1.Ternary.Never : r_logical_1.RLogical.is(flag.value) ? flag.value.content ? logic_1.Ternary.Always : logic_1.Ternary.Never : data === undefined ? logic_1.Ternary.Maybe : (0, built_in_ambient_keys_1.flagValue)(flag.value, data);
|
|
407
|
+
}
|
|
408
|
+
else if ('calls' in condition) {
|
|
409
|
+
return argumentCalls(match_args_1.MatchArgs.toNames(args, condition.formals).get(condition.arg), condition.calls, data);
|
|
410
|
+
}
|
|
411
|
+
else if ('arg' in condition) {
|
|
412
|
+
return argumentIs(match_args_1.MatchArgs.toNames(args, condition.formals).get(condition.arg), condition.is, data);
|
|
413
|
+
}
|
|
414
|
+
return args.some((a, i) => a !== r_function_call_1.EmptyArgument && (a.name === undefined ? i >= condition.besides.length : !condition.besides.includes(identifier_1.Identifier.getName(a.name.content)))) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
|
|
415
|
+
}
|
|
416
|
+
/** Whether the argument is one of the strings `is`, `null` standing for a missing or `NULL` argument. */
|
|
417
|
+
function argumentIs(arg, is, data) {
|
|
418
|
+
const value = r_argument_1.RArgument.valueOf(arg);
|
|
419
|
+
if (value === undefined || (r_symbol_1.RSymbol.is(value) && value.content === convert_values_1.RNull)) {
|
|
420
|
+
return is.includes(null) ? logic_1.Ternary.Always : logic_1.Ternary.Never;
|
|
421
|
+
}
|
|
422
|
+
/* an argument given is taken for a value, `NULL` only if written so */
|
|
423
|
+
const strings = r_string_1.RString.is(value) ? [value.content.str] : data === undefined ? undefined : (0, built_in_ambient_keys_1.stringValuesOf)(value, data);
|
|
424
|
+
if (!is.some(v => v !== null)) {
|
|
425
|
+
return logic_1.Ternary.Never;
|
|
426
|
+
}
|
|
427
|
+
else if (strings === undefined) {
|
|
428
|
+
return logic_1.Ternary.Maybe;
|
|
429
|
+
}
|
|
430
|
+
const known = strings.map(v => is.includes(v));
|
|
431
|
+
return known.every(Boolean) ? logic_1.Ternary.Always : known.some(Boolean) ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
|
|
432
|
+
}
|
|
433
|
+
/** Whether the argument is a call of one of the functions `calls`, or a variable bound to one. */
|
|
434
|
+
function argumentCalls(arg, calls, data) {
|
|
435
|
+
if (arg === undefined) {
|
|
436
|
+
return logic_1.Ternary.Never;
|
|
437
|
+
}
|
|
438
|
+
const values = data === undefined ? [r_argument_1.RArgument.valueOf(arg)].filter(assert_1.isNotUndefined) : boundValues(arg.info.id, data);
|
|
439
|
+
const known = values.map(v => r_function_call_1.RFunctionCall.isNamed(v, new Set(calls)));
|
|
440
|
+
return known.length === 0 ? logic_1.Ternary.Maybe : known.every(Boolean) ? logic_1.Ternary.Always : known.some(Boolean) ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
|
|
441
|
+
}
|
|
442
|
+
/** Whether the effect happens for the arguments `args`, see {@link AmbientEffect#when}. */
|
|
443
|
+
function applies(effect, args, data) {
|
|
444
|
+
return logic_1.TernaryLogic.and(effect.when === undefined ? logic_1.Ternary.Always : holds(effect.when, args, data), effect.unless === undefined ? logic_1.Ternary.Always : logic_1.TernaryLogic.negate(holds(effect.unless, args, data)));
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* What the effect on a part without instances does to its state, for the entries `keys` (all of them if `undefined`).
|
|
448
|
+
* A part of the active instance of a family opens one on the fly, a drawing on the plot writes the canvas with `drawing`.
|
|
449
|
+
* With `maybe` the arguments are unknown, so a reset only adds and an entry is not known to be removed.
|
|
450
|
+
*/
|
|
451
|
+
function stateAccess(effect, keys, maybe, drawing) {
|
|
452
|
+
const { state, keyed, of } = Families[effect.family];
|
|
453
|
+
const { access } = effect;
|
|
454
|
+
if (access === ambient_effect_1.AmbientVerb.Builds) {
|
|
455
|
+
return { reads: [], writes: [], kills: [] };
|
|
456
|
+
}
|
|
457
|
+
const read = keyed === undefined ? [state] : keyedReads(keyed, keys ?? []);
|
|
458
|
+
const written = keyed === undefined ? [state] : keys === undefined ? [ambient_state_name_1.AmbientStateName.allOf(keyed)] : (0, built_in_ambient_keys_1.keyedWrites)(keyed, keys);
|
|
459
|
+
const writes = [
|
|
460
|
+
...of === undefined ? [] : [of.used],
|
|
461
|
+
...drawing && effect.family === ambient_effect_1.AmbientPart.Plot && (access === ambient_effect_1.AmbientVerb.Adds || access === ambient_effect_1.AmbientVerb.Resets) ? [ambient_state_name_1.AmbientStateName.canvas] : [],
|
|
462
|
+
...access === ambient_effect_1.AmbientVerb.Reads ? [] : access === ambient_effect_1.AmbientVerb.Resets && !maybe ? written.map(name => ({ name, mode: AmbientWriteMode.Reset })) : written
|
|
463
|
+
];
|
|
464
|
+
return {
|
|
465
|
+
/* with unknown arguments, a reset may add to what is there (`plot(f, add = TRUE)`) */
|
|
466
|
+
reads: access === ambient_effect_1.AmbientVerb.Reads || access === ambient_effect_1.AmbientVerb.Adds || (maybe && access === ambient_effect_1.AmbientVerb.Resets) ? read : [],
|
|
467
|
+
writes,
|
|
468
|
+
kills: access === ambient_effect_1.AmbientVerb.Kills && !maybe ? written.filter(n => keyed === undefined || n !== ambient_state_name_1.AmbientStateName.allOf(keyed)) : []
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
/** Whether a call drawing on a device writes its canvas, see `semantics.ambient.drawingWritesDevice`. */
|
|
472
|
+
function drawingWritesDevice(config) {
|
|
473
|
+
return config.semantics.ambient?.drawingWritesDevice === true;
|
|
474
|
+
}
|
|
475
|
+
/** Wires the {@link AmbientEffect}s of a call into its dataflow information: reads become unknown references, writes define the pseudo variable globally. */
|
|
476
|
+
function applyAmbientEffects(res, args, rootId, data, effects) {
|
|
477
|
+
for (const effect of ambient_effect_1.Ambient.list(effects)) {
|
|
478
|
+
if (args === UnknownArguments) {
|
|
479
|
+
res = applyWithUnknownArguments(res, rootId, data, effect);
|
|
292
480
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
/* a variable R or a child process reads by itself is read by calls we cannot name */
|
|
298
|
-
if (access.state === ambient_state_name_1.KeyedState.Env && keys.some(k => k === ambient_state_name_1.UnknownKey || GlobalEffectEnv.test(k))) {
|
|
299
|
-
res.graph.markIdForUnknownSideEffects(rootId);
|
|
481
|
+
else {
|
|
482
|
+
const happens = applies(effect, args, data);
|
|
483
|
+
if (happens !== logic_1.Ternary.Never) {
|
|
484
|
+
res = applyEffect(res, args, rootId, data, effect, happens === logic_1.Ternary.Maybe);
|
|
300
485
|
}
|
|
301
|
-
writes.push(...(0, built_in_ambient_keys_1.keyedWrites)(access.state, keys));
|
|
302
|
-
break;
|
|
303
486
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
487
|
+
}
|
|
488
|
+
return res;
|
|
489
|
+
}
|
|
490
|
+
/** Applies the effect, which only `maybe` happens. */
|
|
491
|
+
function applyEffect(res, args, rootId, data, effect, maybe = false) {
|
|
492
|
+
const { instances, keyed } = Families[effect.family];
|
|
493
|
+
if (instances !== undefined) {
|
|
494
|
+
return instanceAccess(res, rootId, data, effect, instances, args.length > 0);
|
|
495
|
+
}
|
|
496
|
+
const keys = effect.member === undefined || effect.member === 'every' ? undefined : (0, built_in_ambient_keys_1.keysOf)(effect.member, args, data);
|
|
497
|
+
switch (effect.family) {
|
|
498
|
+
case ambient_state_name_1.KeyedState.Option:
|
|
499
|
+
return effect.access === ambient_effect_1.AmbientVerb.Reads ? readOptions(res, args, rootId, data, effect, keys) : setOptions(res, args, rootId, data);
|
|
500
|
+
case ambient_effect_1.AmbientPart.Files:
|
|
501
|
+
return fileAccess(res, rootId, data, effect);
|
|
502
|
+
case ambient_effect_1.AmbientPart.TextConnection:
|
|
503
|
+
return openTextConnection(res, args, rootId, data);
|
|
504
|
+
case ambient_effect_1.AmbientPart.Finalizers:
|
|
505
|
+
return effect.access === ambient_effect_1.AmbientVerb.Reads ? runFinalizers(res, rootId, data) : registerFinalizer(res, args, rootId, data);
|
|
506
|
+
case ambient_effect_1.AmbientPart.LastPlot:
|
|
507
|
+
if (changes(effect)) {
|
|
508
|
+
/* the plot object is what the outermost `+` the call is part of builds */
|
|
509
|
+
recordAmbient(res.graph, rootId, res.environment, [], [ambient_state_name_1.AmbientStateName.lastPlot]);
|
|
510
|
+
return { ...res, environment: defineAmbient(res.environment, outermostPlus(rootId, data.completeAst.idMap), data.cds ? [...data.cds] : undefined, [ambient_state_name_1.AmbientStateName.lastPlot]) };
|
|
310
511
|
}
|
|
311
512
|
break;
|
|
312
|
-
case
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return deviceAccess(res, rootId, data, 'open');
|
|
317
|
-
case "close-device" /* AmbientStateAccessType.CloseDevice */:
|
|
318
|
-
/* `dev.off(which)` may close a device other than the active one, which keeps its state then */
|
|
319
|
-
return deviceAccess(res, rootId, data, access.all ? 'close-all' : args.length > 0 ? 'switch' : 'close');
|
|
320
|
-
case "switch-device" /* AmbientStateAccessType.SwitchDevice */:
|
|
321
|
-
return deviceAccess(res, rootId, data, 'switch');
|
|
322
|
-
case "evaluate-quoted" /* AmbientStateAccessType.EvaluateQuoted */:
|
|
323
|
-
return evaluatesCapturedCode(res, rootId, data);
|
|
324
|
-
case "set-rng" /* AmbientStateAccessType.SetRng */: {
|
|
325
|
-
const kindFrom = access.kindFrom ?? 1;
|
|
326
|
-
reads.push(ambient_state_name_1.AmbientStateName.rngKind);
|
|
327
|
-
if (kindFrom > 0) {
|
|
328
|
-
writes.push(ambient_state_name_1.AmbientStateName.rng);
|
|
329
|
-
}
|
|
330
|
-
/* a new kind reseeds the generator from its current state, so it changes the stream as well */
|
|
331
|
-
if (args.some((a, i) => a !== r_function_call_1.EmptyArgument && (a.name === undefined ? i >= kindFrom : identifier_1.Identifier.getName(a.name.content) !== 'seed'))) {
|
|
332
|
-
reads.push(ambient_state_name_1.AmbientStateName.rng);
|
|
333
|
-
writes.push(ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.rng);
|
|
513
|
+
case ambient_state_name_1.KeyedState.Env:
|
|
514
|
+
case ambient_state_name_1.KeyedState.Par:
|
|
515
|
+
if (effect.handsBack && keys !== undefined && keyed !== undefined) {
|
|
516
|
+
linkEntryValue(res, rootId, keyed, keys, data);
|
|
334
517
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
reads.push(ambient_state_name_1.AmbientStateName.rng);
|
|
339
|
-
writes.push(ambient_state_name_1.AmbientStateName.rng);
|
|
340
|
-
break;
|
|
341
|
-
case "read-files" /* AmbientStateAccessType.ReadFiles */: {
|
|
342
|
-
const stems = fileStems(res, rootId, data, access);
|
|
343
|
-
if (stems?.length === 0) {
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory, ...stems === undefined ? [ambient_state_name_1.AmbientStateName.files] : [...stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.anyFile]);
|
|
347
|
-
/* a read through a connection the program holds moves its position, so the next read depends on this one */
|
|
348
|
-
if (readsThroughHandle(res, rootId, data, access.sig)) {
|
|
349
|
-
writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] : stems.map(ambient_state_name_1.AmbientStateName.file));
|
|
350
|
-
}
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
case "write-files" /* AmbientStateAccessType.WriteFiles */: {
|
|
354
|
-
const stems = fileStems(res, rootId, data, access);
|
|
355
|
-
if (stems?.length === 0) {
|
|
356
|
-
break;
|
|
518
|
+
/* a variable R or a child process reads by itself is read by calls we cannot name */
|
|
519
|
+
if (effect.family === ambient_state_name_1.KeyedState.Env && changes(effect) && keys?.some(k => k === ambient_state_name_1.UnknownKey || GlobalEffectEnv.test(k))) {
|
|
520
|
+
res.graph.markIdForUnknownSideEffects(rootId);
|
|
357
521
|
}
|
|
358
|
-
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
|
|
359
|
-
writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files);
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
case "set-working-directory" /* AmbientStateAccessType.SetWorkingDirectory */:
|
|
363
|
-
/* a relative `dir` resolves against the current one, which the call also returns */
|
|
364
|
-
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
|
|
365
|
-
writes.push(ambient_state_name_1.AmbientStateName.workingDirectory);
|
|
366
522
|
break;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
523
|
+
}
|
|
524
|
+
const { reads, writes, kills } = stateAccess(effect, keyed === undefined ? undefined : keys, maybe, drawingWritesDevice(data.ctx.config));
|
|
525
|
+
return withAccess(res, rootId, data, reads, (0, arrays_1.uniqueArray)(writes), kills);
|
|
526
|
+
}
|
|
527
|
+
/** What the effect on an instance family does: opening, closing, and switching move the states of the instances, see {@link deviceAccess}. */
|
|
528
|
+
function instanceAccess(res, rootId, data, effect, family, named) {
|
|
529
|
+
const { state } = Families[effect.family];
|
|
530
|
+
switch (effect.access) {
|
|
531
|
+
case ambient_effect_1.AmbientVerb.Opens:
|
|
532
|
+
return deviceAccess(res, rootId, data, DeviceAccess.Open, family);
|
|
533
|
+
case ambient_effect_1.AmbientVerb.Switches:
|
|
534
|
+
return deviceAccess(res, rootId, data, DeviceAccess.Switch, family);
|
|
535
|
+
case ambient_effect_1.AmbientVerb.Closes:
|
|
536
|
+
/* `dev.off(which)` may close an instance other than the active one, which keeps its state then */
|
|
537
|
+
return deviceAccess(res, rootId, data, effect.member === 'every' ? DeviceAccess.CloseAll : named ? DeviceAccess.CloseSome : DeviceAccess.Close, family);
|
|
538
|
+
default: {
|
|
539
|
+
const { reads, writes } = instanceStateAccess(effect, state, family);
|
|
540
|
+
return withAccess(res, rootId, data, reads, writes);
|
|
380
541
|
}
|
|
381
542
|
}
|
|
382
|
-
|
|
543
|
+
}
|
|
544
|
+
/** What reading or using an instance does, `every` one with {@link AmbientEffect#member}: using it adds to what its closing links to. */
|
|
545
|
+
function instanceStateAccess(effect, state, family) {
|
|
546
|
+
const others = family.states.find(([active]) => active === state)?.[1];
|
|
547
|
+
return {
|
|
548
|
+
reads: effect.access === ambient_effect_1.AmbientVerb.Builds ? [] : [state, ...effect.member === 'every' && others !== undefined ? [others] : []],
|
|
549
|
+
writes: changes(effect) ? [family.used] : []
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
/** What reading options does: the entries `keys` names, all options if a method may print the value `print(x)` dispatches on, which draws a plot object. */
|
|
553
|
+
function readOptions(res, args, rootId, data, effect, keys) {
|
|
554
|
+
if (effect.dispatchOn !== undefined) {
|
|
555
|
+
const dispatched = r_argument_1.RArgument.valueOf(args[effect.dispatchOn]);
|
|
556
|
+
return withAccess(res, rootId, data, printingReads(dispatched, true, keys ?? [], data), mayHoldPlot(dispatched, data) ? DrawsNewPlot : []);
|
|
557
|
+
}
|
|
558
|
+
if (effect.handsBack) {
|
|
559
|
+
linkEntryValue(res, rootId, ambient_state_name_1.KeyedState.Option, keys ?? [], data);
|
|
560
|
+
}
|
|
561
|
+
return withAccess(res, rootId, data, keyedReads(ambient_state_name_1.KeyedState.Option, keys ?? []));
|
|
562
|
+
}
|
|
563
|
+
/** what every access of a file reads to find it: the working directory a relative path starts from and the directories the path leads through */
|
|
564
|
+
const FileSystemReads = [ambient_state_name_1.AmbientStateName.workingDirectory, ambient_state_name_1.AmbientStateName.directories];
|
|
565
|
+
/** What reading or writing the files the call names does, see {@link fileStems}. */
|
|
566
|
+
function fileAccess(res, rootId, data, effect) {
|
|
567
|
+
const stems = fileStems(res, rootId, data, effect);
|
|
568
|
+
if (stems?.length === 0) {
|
|
569
|
+
return res;
|
|
570
|
+
}
|
|
571
|
+
if (effect.access === ambient_effect_1.AmbientVerb.Reads) {
|
|
572
|
+
/* a read through a connection the program holds moves its position, so the next read depends on this one */
|
|
573
|
+
const moves = readsThroughHandle(res, rootId, data, effect.sig) ? stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] : stems.map(ambient_state_name_1.AmbientStateName.file) : [];
|
|
574
|
+
return withAccess(res, rootId, data, [...FileSystemReads, ...stems === undefined ? [ambient_state_name_1.AmbientStateName.files] : [...stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.anyFile]], moves);
|
|
575
|
+
}
|
|
576
|
+
return withAccess(res, rootId, data, FileSystemReads, [...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files]);
|
|
577
|
+
}
|
|
578
|
+
/** `gc()` may run every registered finalizer whose object is released. */
|
|
579
|
+
function runFinalizers(res, rootId, data) {
|
|
580
|
+
const registered = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.finalizers, data.environment) ?? []).filter(identifier_1.isInGraphDefinition);
|
|
581
|
+
for (const fn of registered.flatMap(d => d.value ?? [])) {
|
|
582
|
+
res.graph.addEdge(rootId, fn, edge_1.EdgeType.Calls);
|
|
583
|
+
}
|
|
584
|
+
return withAccess(res, rootId, data, [ambient_state_name_1.AmbientStateName.finalizers], registered.flatMap(d => d.writes ?? []).map(maybe));
|
|
585
|
+
}
|
|
586
|
+
/** drawing a new plot adds to the device, which opens one if none is open, and replaces its plot */
|
|
587
|
+
const DrawsNewPlot = [ambient_state_name_1.AmbientStateName.device, { name: ambient_state_name_1.AmbientStateName.plot, mode: AmbientWriteMode.Reset }];
|
|
588
|
+
/**
|
|
589
|
+
* Whether the value of `node` may be a plot object, which printing draws: a call building one ({@link AmbientVerb.Builds}, as `ggplot` does),
|
|
590
|
+
* a `+` adding to one, or a variable bound to either.
|
|
591
|
+
*/
|
|
592
|
+
function mayHoldPlot(node, data, seen = new Set()) {
|
|
593
|
+
if (node === undefined || seen.has(node.info.id)) {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
seen.add(node.info.id);
|
|
597
|
+
if (r_function_call_1.RFunctionCall.isNamed(node)) {
|
|
598
|
+
return ((0, query_fn_props_1.statedFunctions)(node.functionName.content, data.environment) ?? [])
|
|
599
|
+
.some(t => hiddenAccess(t).some(a => a.family === ambient_effect_1.AmbientPart.Plot && a.access === ambient_effect_1.AmbientVerb.Builds));
|
|
600
|
+
}
|
|
601
|
+
else if (r_binary_op_1.RBinaryOp.is(node)) {
|
|
602
|
+
return node.operator === '+' && (mayHoldPlot(node.lhs, data, seen) || mayHoldPlot(node.rhs, data, seen));
|
|
603
|
+
}
|
|
604
|
+
else if (r_if_then_else_1.RIfThenElse.is(node)) {
|
|
605
|
+
return mayHoldPlot(node.then, data, seen) || mayHoldPlot(node.otherwise, data, seen);
|
|
606
|
+
}
|
|
607
|
+
else if (r_expression_list_1.RExpressionList.is(node)) {
|
|
608
|
+
return mayHoldPlot(node.children.at(-1), data, seen);
|
|
609
|
+
}
|
|
610
|
+
else if (!r_symbol_1.RSymbol.is(node)) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
return (resolve_helper_1.Resolve.byName(node.content, data.environment) ?? []).filter(identifier_1.isInGraphDefinition).some(d => {
|
|
614
|
+
const source = data.completeAst.idMap.get(d.definedAt);
|
|
615
|
+
return r_binary_op_1.RBinaryOp.is(source) && mayHoldPlot(source.lhs.info.id === d.nodeId ? source.rhs : source.lhs, data, seen);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
/** the outermost `+` chain holding `id`, `id` itself if it is part of none */
|
|
619
|
+
function outermostPlus(id, idMap) {
|
|
620
|
+
let at = idMap.get(id);
|
|
621
|
+
for (let parent = at === undefined ? undefined : model_1.RNode.directParent(at, idMap); r_binary_op_1.RBinaryOp.is(parent) && parent.operator === '+'; parent = model_1.RNode.directParent(parent, idMap)) {
|
|
622
|
+
at = parent;
|
|
623
|
+
}
|
|
624
|
+
return at?.info.id ?? id;
|
|
383
625
|
}
|
|
384
626
|
/** `reg.finalizer(e, f)` keeps the functions `f` may be, and the name holding `e`, whose release lets `gc()` run them. */
|
|
385
627
|
function registerFinalizer(res, args, rootId, data) {
|
|
@@ -392,6 +634,7 @@ function registerFinalizer(res, args, rootId, data) {
|
|
|
392
634
|
return vertex_1.DfgVertex.isFunctionDefinition(definition) ? ambientWritesBetween(definition.subflow.environment, data.environment) : [];
|
|
393
635
|
});
|
|
394
636
|
const definition = { nodeId: rootId, name: ambient_state_name_1.AmbientStateName.finalizers, type: identifier_1.ReferenceType.Variable, definedAt: rootId, cds: data.cds ? [...data.cds] : [], value, writes, holder: r_symbol_1.RSymbol.is(holder) ? identifier_1.Identifier.getName(holder.content) : undefined };
|
|
637
|
+
recordAmbient(res.graph, rootId, res.environment, [], [ambient_state_name_1.AmbientStateName.finalizers]);
|
|
395
638
|
return { ...res, environment: environment_1.REnvironment.define(definition, true, res.environment, true) };
|
|
396
639
|
}
|
|
397
640
|
/** `textConnection(object, open, local)` opened for writing binds `object` globally, or locally with `local = TRUE`. */
|
|
@@ -435,7 +678,7 @@ function boundValues(id, data, direct = true) {
|
|
|
435
678
|
if (!r_symbol_1.RSymbol.is(node) || node.content === convert_values_1.RNull) {
|
|
436
679
|
return direct && node !== undefined ? [node] : [];
|
|
437
680
|
}
|
|
438
|
-
return (resolve_helper_1.Resolve.byName(node.content, data.environment) ?? []).flatMap(d => d.value ?? [])
|
|
681
|
+
return (resolve_helper_1.Resolve.byName(node.content, data.environment) ?? []).filter(identifier_1.isInGraphDefinition).flatMap(d => d.value ?? [])
|
|
439
682
|
.map(v => data.completeAst.idMap.get(v)).filter(assert_1.isNotUndefined);
|
|
440
683
|
}
|
|
441
684
|
/** Whether `node` calls a function flowR states `tag` of, like {@link SemanticCallTag.Opens} for `file(f)`. */
|
|
@@ -449,10 +692,7 @@ function namesNoFile(id, data) {
|
|
|
449
692
|
return values.length > 0 && values.every(v => (r_string_1.RString.is(v) && v.content.str === '') || (r_symbol_1.RSymbol.is(v) && v.content === convert_values_1.RNull)
|
|
450
693
|
|| callsTagged(v, data, built_in_props_1.SemanticCallTag.Console));
|
|
451
694
|
}
|
|
452
|
-
/**
|
|
453
|
-
* The stems of the files the call names, `undefined` unless every file argument is a known path to a file with an extension (a device's `plot%03d.png` or a directory may stand for others).
|
|
454
|
-
* Empty if the call names no file, as `cat(x)` and `writeLines(x, stdout())`, which print, do.
|
|
455
|
-
*/
|
|
695
|
+
/** The stems of the files the call names, `undefined` unless every file argument is a known path to a file with an extension (a device's `plot%03d.png` or a directory may stand for others). */
|
|
456
696
|
function fileStems(res, rootId, data, { sig, numbered }) {
|
|
457
697
|
const call = res.graph.getVertex(rootId);
|
|
458
698
|
if (sig === undefined || !vertex_1.DfgVertex.isFunctionCall(call)) {
|
|
@@ -502,140 +742,125 @@ function isPlainValue(node, data) {
|
|
|
502
742
|
}
|
|
503
743
|
/** The arguments of a call made on our behalf, like `do.call(par, args)`, which we cannot see. */
|
|
504
744
|
const UnknownArguments = Symbol('unknown-arguments');
|
|
505
|
-
function applyWithUnknownArguments(res, rootId, data,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
745
|
+
function applyWithUnknownArguments(res, rootId, data, effect) {
|
|
746
|
+
const { instances } = Families[effect.family];
|
|
747
|
+
if (instances !== undefined && effect.access !== ambient_effect_1.AmbientVerb.Reads && effect.access !== ambient_effect_1.AmbientVerb.Adds) {
|
|
748
|
+
/* we cannot tell which instance a close closes */
|
|
749
|
+
return instanceAccess(res, rootId, data, effect, instances, true);
|
|
750
|
+
}
|
|
751
|
+
else if (effect.family === ambient_effect_1.AmbientPart.Files) {
|
|
509
752
|
/* the arguments handed on (`do.call(readLines, list("a.txt"))`, `lapply(files, readLines)`) may still name the files */
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
res.graph.markIdForUnknownSideEffects(rootId);
|
|
518
|
-
}
|
|
519
|
-
const { reads, writes } = unknownArgumentAccess(access);
|
|
753
|
+
return applyEffect(res, [], rootId, data, effect);
|
|
754
|
+
}
|
|
755
|
+
else if (effect.family === ambient_state_name_1.KeyedState.Option && changes(effect)) {
|
|
756
|
+
/* like `options(op)`: it may set anything */
|
|
757
|
+
res.graph.markIdForUnknownSideEffects(rootId);
|
|
758
|
+
}
|
|
759
|
+
const { reads, writes } = unknownArgumentAccess(effect, drawingWritesDevice(data.ctx.config));
|
|
520
760
|
return withAccess(res, rootId, data, reads, writes);
|
|
521
761
|
}
|
|
522
|
-
const Devices = { reads: [], writes: [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device] };
|
|
523
762
|
/* evaluated code may attach a package as well, which every call nothing else resolves reads */
|
|
524
763
|
const Quoted = { reads: [ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette], writes: [ambient_state_name_1.AmbientStateName.unknownOption, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.SearchPath)] };
|
|
525
|
-
/** What
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
/** Graphics parameters are per device; within a function the open devices are unknown, so a device call only adds. */
|
|
563
|
-
function deviceAccess(res, rootId, data, kind) {
|
|
564
|
-
/* only a switch reads the state; what a closed device holds reaches its file through the plots on it (see LinkToLastPlot) */
|
|
565
|
-
const reads = kind === 'switch' ? [ambient_state_name_1.AmbientStateName.graphics] : [];
|
|
764
|
+
/** What the effect may read and write when the arguments of the call are unknown, as when only linking reveals it: any condition may hold, and any entry be named but stated ones. */
|
|
765
|
+
function unknownArgumentAccess(effect, drawing) {
|
|
766
|
+
const { state, instances } = Families[effect.family];
|
|
767
|
+
if (instances !== undefined) {
|
|
768
|
+
return effect.access === ambient_effect_1.AmbientVerb.Reads || effect.access === ambient_effect_1.AmbientVerb.Adds ? instanceStateAccess(effect, state, instances) : { reads: [], writes: activeStates(instances) };
|
|
769
|
+
}
|
|
770
|
+
switch (effect.family) {
|
|
771
|
+
case ambient_state_name_1.KeyedState.Option:
|
|
772
|
+
if (changes(effect)) {
|
|
773
|
+
return { reads: [ambient_state_name_1.AmbientStateName.allOptions], writes: [ambient_state_name_1.AmbientStateName.unknownOption, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.warnsAsErrors] };
|
|
774
|
+
}
|
|
775
|
+
break;
|
|
776
|
+
case ambient_effect_1.AmbientPart.Files:
|
|
777
|
+
return effect.access === ambient_effect_1.AmbientVerb.Reads ? { reads: [...FileSystemReads, ambient_state_name_1.AmbientStateName.files], writes: [] }
|
|
778
|
+
: { reads: FileSystemReads, writes: [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] };
|
|
779
|
+
case ambient_effect_1.AmbientPart.TextConnection:
|
|
780
|
+
return { reads: [], writes: [] };
|
|
781
|
+
case ambient_effect_1.AmbientPart.Finalizers:
|
|
782
|
+
return effect.access === ambient_effect_1.AmbientVerb.Reads ? { reads: [state], writes: [] } : { reads: [], writes: [state] };
|
|
783
|
+
}
|
|
784
|
+
const member = effect.member;
|
|
785
|
+
const keys = typeof member === 'object' && member.from === 'constant' && effect.dispatchOn === undefined ? member.keys : [ambient_state_name_1.UnknownKey];
|
|
786
|
+
const { reads, writes } = stateAccess(effect, Families[effect.family].keyed === undefined ? undefined : keys, true, drawing);
|
|
787
|
+
return { reads, writes: writes.map(w => typeof w === 'string' ? w : w.name) };
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Opens, closes, or switches an instance of the `family` (a graphics device), each of whose states is per instance.
|
|
791
|
+
* A close reads the calls that opened and used the closed instance, the explicit opening reads the close in turn, so keeping it keeps the close.
|
|
792
|
+
* Within a function the open instances are unknown, so a call only adds.
|
|
793
|
+
*/
|
|
794
|
+
function deviceAccess(res, rootId, data, kind, family = ambient_state_name_1.GraphicsDevices) {
|
|
795
|
+
const otherOf = (state) => family.states.find(([active]) => active === state)?.[1] ?? state;
|
|
796
|
+
const actives = activeStates(family);
|
|
797
|
+
/* `x <- dev.off()` is the device that is active afterward, one of the others */
|
|
798
|
+
const closing = kind === DeviceAccess.Close ? [family.used, ...resultIsUsed(rootId, data) ? [otherOf(family.used)] : []] : [];
|
|
799
|
+
const all = [family.used, otherOf(family.used)];
|
|
800
|
+
const reads = kind === DeviceAccess.Switch ? [family.switched] : kind === DeviceAccess.CloseSome ? [family.switched, ...all] : kind === DeviceAccess.CloseAll ? all : closing;
|
|
566
801
|
/* closing writes the file of the device, which its opening names unless we do not know the device closed */
|
|
567
|
-
const unnamedFile = kind ===
|
|
802
|
+
const unnamedFile = kind === DeviceAccess.Open ? [] : [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files];
|
|
568
803
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
569
804
|
if (data.environment.level > 0) {
|
|
570
|
-
/* a device the body opened itself is the one a later close in the same body closes:
|
|
571
|
-
|
|
572
|
-
const here = kind === 'close' ? res.environment.current.memory.get(ambient_state_name_1.AmbientStateName.deviceOpenedHere) ?? [] : [];
|
|
805
|
+
/* a device the body opened itself is the one a later close in the same body closes: `f <- function() { pdf("a.pdf"); plot(1); dev.off() }` writes `a.pdf` and no other file */
|
|
806
|
+
const here = kind === DeviceAccess.Close ? res.environment.current.memory.get(family.openedHere) ?? [] : [];
|
|
573
807
|
for (const open of here) {
|
|
574
808
|
res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
575
809
|
}
|
|
576
|
-
let environment = { ...res.environment, current: res.environment.current.removeAll([{ name:
|
|
577
|
-
if (kind ===
|
|
578
|
-
environment = defineAmbient(environment, rootId, cds, [{ name:
|
|
810
|
+
let environment = { ...res.environment, current: res.environment.current.removeAll([{ name: family.openedHere }]) };
|
|
811
|
+
if (kind === DeviceAccess.Open) {
|
|
812
|
+
environment = defineAmbient(environment, rootId, cds, [{ name: family.openedHere, mode: AmbientWriteMode.Local }]);
|
|
579
813
|
}
|
|
580
|
-
|
|
814
|
+
recordAmbient(res.graph, rootId, environment, [], [], kind === DeviceAccess.Close || kind === DeviceAccess.CloseAll ? actives : []);
|
|
815
|
+
return withAccess({ ...res, environment }, rootId, data, reads, [...actives, ...here.length > 0 ? [] : unnamedFile]);
|
|
581
816
|
}
|
|
582
817
|
const lookup = (name) => resolve_helper_1.Resolve.byName(name, res.environment) ?? [];
|
|
583
|
-
|
|
584
|
-
const
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const reset = (name) => defineAmbient(environment, rootId, cds, [{ name, mode: 'reset' }]);
|
|
589
|
-
/* a later plot depends on neither the close nor the closed device's state; a device only depends on its close so it does not catch later plots */
|
|
590
|
-
const closes = (openers) => {
|
|
591
|
-
for (const open of openers) {
|
|
592
|
-
res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
593
|
-
}
|
|
594
|
-
};
|
|
818
|
+
/* a use opening the device on the fly (`plot` without one) names no file and needs no close */
|
|
819
|
+
const closed = kind === DeviceAccess.Close ? lookup(family.opened) : kind === DeviceAccess.CloseAll ? [...lookup(family.opened), ...lookup(otherOf(family.opened))] : [];
|
|
820
|
+
for (const open of closed) {
|
|
821
|
+
res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
822
|
+
}
|
|
595
823
|
/* in a loop, an earlier round may have opened a device this one leaves behind, or a close may leave one open */
|
|
596
824
|
const repeats = model_1.RLoopConstructs.encloses(rootId, data.completeAst.idMap);
|
|
597
|
-
const earlierRound = repeats ? [{ nodeId: rootId, name:
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy, opener, true);
|
|
622
|
-
break;
|
|
825
|
+
const earlierRound = repeats ? [{ nodeId: rootId, name: family.used, type: identifier_1.ReferenceType.Variable, definedAt: rootId, cds: cds ?? [] }] : [];
|
|
826
|
+
let environment = res.environment;
|
|
827
|
+
if (kind === DeviceAccess.Switch || kind === DeviceAccess.CloseSome) {
|
|
828
|
+
environment = defineAmbient(environment, rootId, cds, actives);
|
|
829
|
+
}
|
|
830
|
+
for (const [active, others] of family.states) {
|
|
831
|
+
const current = lookup(active);
|
|
832
|
+
const other = lookup(others);
|
|
833
|
+
switch (kind) {
|
|
834
|
+
case DeviceAccess.Open:
|
|
835
|
+
environment = setAmbient(environment, others, [...other, ...current, ...earlierRound]);
|
|
836
|
+
environment = defineAmbient(environment, rootId, cds, [{ name: active, mode: AmbientWriteMode.Reset }]);
|
|
837
|
+
break;
|
|
838
|
+
case DeviceAccess.Close:
|
|
839
|
+
environment = setAmbient(environment, active, repeats ? [...other, ...current] : other);
|
|
840
|
+
break;
|
|
841
|
+
case DeviceAccess.CloseAll:
|
|
842
|
+
environment = setAmbient(setAmbient(environment, active, []), others, []);
|
|
843
|
+
break;
|
|
844
|
+
case DeviceAccess.Switch:
|
|
845
|
+
case DeviceAccess.CloseSome:
|
|
846
|
+
environment = setAmbient(setAmbient(environment, active, other, true), others, current, true);
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
623
849
|
}
|
|
624
|
-
|
|
625
|
-
|
|
850
|
+
/* a close ends the state of the device it closes, all of them for every device */
|
|
851
|
+
const kills = kind === DeviceAccess.Close ? actives : kind === DeviceAccess.CloseAll ? family.states.flat() : [];
|
|
852
|
+
recordAmbient(res.graph, rootId, res.environment, [], kind === DeviceAccess.CloseAll ? family.states.flat() : actives, kills);
|
|
853
|
+
return withAccess({ ...res, environment }, rootId, data, reads, kind === DeviceAccess.Open || closed.length > 0 ? [] : unnamedFile);
|
|
626
854
|
}
|
|
627
855
|
/** A call to `fn` made on our behalf (`do.call(fn, args)`, `sapply(x, fn)`): it accesses the state as `fn` does, or reads all of it if `fn` is opaque. */
|
|
628
856
|
function applyAmbientStateOfCallee(res, callId, fn, data) {
|
|
629
857
|
const targets = resolve_helper_1.Resolve.byNameAndType(fn, data.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
630
|
-
res =
|
|
858
|
+
res = applyAmbientEffects(res, UnknownArguments, callId, data, targets.flatMap(hiddenAccess));
|
|
631
859
|
hiddenSideEffects(res.graph, res.environment, callId, targets);
|
|
632
860
|
const unknown = (targets.length === 0 && data.environment.level === 0) || targets.some(t => t.type !== identifier_1.ReferenceType.BuiltInFunction && hidesBody(t));
|
|
633
861
|
return unknown ? readsAllAmbientState(res, callId, data, true) : res;
|
|
634
862
|
}
|
|
635
|
-
/**
|
|
636
|
-
* The processors that write the environment from their arguments (define, remove, evaluate code): called through a
|
|
637
|
-
* parameter, `do.call`, or an apply function, what they write is unknown, so the values known so far may be stale.
|
|
638
|
-
*/
|
|
863
|
+
/** The processors that write the environment from their arguments (define, remove, evaluate code): called through a parameter, `do.call`, or an apply function, what they write is unknown, so the values known so far may be stale. */
|
|
639
864
|
const WritesEnvironment = new Set([
|
|
640
865
|
built_in_proc_name_1.BuiltInProcName.Source, built_in_proc_name_1.BuiltInProcName.Load, built_in_proc_name_1.BuiltInProcName.Rm, built_in_proc_name_1.BuiltInProcName.ListToEnv,
|
|
641
866
|
built_in_proc_name_1.BuiltInProcName.Assignment, built_in_proc_name_1.BuiltInProcName.AssignmentLike, built_in_proc_name_1.BuiltInProcName.SuperAssignment, built_in_proc_name_1.BuiltInProcName.Eval, built_in_proc_name_1.BuiltInProcName.Local
|
|
@@ -658,16 +883,15 @@ function hiddenSideEffects(graph, environment, callId, targets) {
|
|
|
658
883
|
}
|
|
659
884
|
}
|
|
660
885
|
function hiddenAccess(target) {
|
|
661
|
-
|
|
662
|
-
return [access ?? []].flat();
|
|
886
|
+
return ambient_effect_1.Ambient.list(target.type === identifier_1.ReferenceType.BuiltInFunction ? target.config?.ambient : undefined);
|
|
663
887
|
}
|
|
664
888
|
/** The (maybe) writes of the call `callId` to the built-in `target` through a parameter, like `g <- function(f, ...) f(...); g(options, digits = 3)`. */
|
|
665
|
-
function writesOfHiddenBuiltIn(target, callId) {
|
|
666
|
-
return hiddenAccess(target).flatMap(a => unknownArgumentAccess(a).writes).map(name => ({ nodeId: callId, name, type: identifier_1.ReferenceType.Variable, definedAt: callId, cds: [] }));
|
|
889
|
+
function writesOfHiddenBuiltIn(target, callId, drawing = false) {
|
|
890
|
+
return hiddenAccess(target).flatMap(a => unknownArgumentAccess(a, drawing).writes).map(name => ({ nodeId: callId, name, type: identifier_1.ReferenceType.Variable, definedAt: callId, cds: [] }));
|
|
667
891
|
}
|
|
668
892
|
/** The states the call to the built-in `target` through a parameter reads, see {@link writesOfHiddenBuiltIn}. */
|
|
669
893
|
function readsOfHiddenBuiltIn(target) {
|
|
670
|
-
return hiddenAccess(target).flatMap(a => unknownArgumentAccess(a).reads);
|
|
894
|
+
return hiddenAccess(target).flatMap(a => unknownArgumentAccess(a, false).reads);
|
|
671
895
|
}
|
|
672
896
|
function setOptions(res, args, rootId, data) {
|
|
673
897
|
const queried = [];
|
|
@@ -683,7 +907,7 @@ function setOptions(res, args, rootId, data) {
|
|
|
683
907
|
const key = identifier_1.Identifier.getName(arg.name.content);
|
|
684
908
|
written.push(ambient_state_name_1.AmbientStateName.option(key));
|
|
685
909
|
global ||= GlobalEffectOptions.has(key);
|
|
686
|
-
warnsAsErrors ||= key === 'warn' && !node_value_1.NodeValue.setOf(arg.value?.info.id, data)?.elements.every(
|
|
910
|
+
warnsAsErrors ||= key === 'warn' && !node_value_1.NodeValue.setOf(arg.value?.info.id, data)?.elements.every(value => value.type === 'logical' || (r_value_1.RValue.numberOf(value) ?? 2) < 2);
|
|
687
911
|
}
|
|
688
912
|
else if (r_string_1.RString.is(arg.value)) {
|
|
689
913
|
queried.push(arg.value.content.str);
|
|
@@ -718,53 +942,44 @@ function setOptions(res, args, rootId, data) {
|
|
|
718
942
|
}
|
|
719
943
|
return withAccess(res, rootId, data, reads, writes);
|
|
720
944
|
}
|
|
721
|
-
/**
|
|
722
|
-
* Whether the call to `fn` only queries the state it may set, as `par("mar")`, `options("digits")` and `palette()`
|
|
723
|
-
* do, which hand that state back visibly where setting it returns the previous one invisibly.
|
|
724
|
-
*/
|
|
945
|
+
/** Whether the call to `fn` only queries the state it may set, as `par("mar")`, `options("digits")` and `palette()` do, which hand that state back visibly where setting it returns the previous one invisibly. */
|
|
725
946
|
function callOnlyQueries(fn, args, environment) {
|
|
726
947
|
const targets = resolve_helper_1.Resolve.byNameAndType(fn, environment, identifier_1.ReferenceType.Function) ?? [];
|
|
727
|
-
return targets.length > 0 && targets.every(t => hiddenAccess(t)
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
case "set-options" /* AmbientStateAccessType.SetOptions */:
|
|
734
|
-
return isQuery(args);
|
|
735
|
-
case "set-palette" /* AmbientStateAccessType.SetPalette */:
|
|
736
|
-
return args.length === 0;
|
|
737
|
-
case "set-state" /* AmbientStateAccessType.SetState */:
|
|
738
|
-
return access.queryWithoutArguments === true && args.length === 0;
|
|
739
|
-
default:
|
|
740
|
-
return false;
|
|
741
|
-
}
|
|
948
|
+
return targets.length > 0 && targets.every(t => onlyQueries(hiddenAccess(t), args));
|
|
949
|
+
}
|
|
950
|
+
/** Whether a call with the `effects` only queries: a change is off for the arguments `args`, and no other one happens. */
|
|
951
|
+
function onlyQueries(effects, args) {
|
|
952
|
+
const changing = effects.filter(changes);
|
|
953
|
+
return changing.some(e => e.unless !== undefined && holds(e.unless, args) === logic_1.Ternary.Always) && changing.every(e => applies(e, args) === logic_1.Ternary.Never);
|
|
742
954
|
}
|
|
743
955
|
/** `par()`, `par("mar", "usr")`, and `par(no.readonly = TRUE)` only query the graphics state */
|
|
744
956
|
function isQuery(args) {
|
|
745
957
|
return args.every(a => a === r_function_call_1.EmptyArgument
|
|
746
958
|
|| (a.name === undefined ? r_string_1.RString.is(a.value) : identifier_1.Identifier.getName(a.name.content) === 'no.readonly'));
|
|
747
959
|
}
|
|
748
|
-
/** Whether the call's value may be used: anything but a non-final statement or
|
|
749
|
-
function resultIsUsed(rootId, data) {
|
|
960
|
+
/** Whether the call's value may be used: anything but a non-final statement or, unless it is `printed` there, a top-level statement of the script (the last of a block is its value). */
|
|
961
|
+
function resultIsUsed(rootId, data, printed) {
|
|
750
962
|
const node = data.completeAst.idMap.get(rootId);
|
|
751
963
|
const parent = node === undefined ? undefined : model_1.RNode.directParent(node, data.completeAst.idMap);
|
|
964
|
+
/* R prints the value a top-level statement leaves visible */
|
|
965
|
+
printed ??= !(r_function_call_1.RFunctionCall.isNamed(node) && returnsInvisibly(node.functionName.content, data.environment));
|
|
752
966
|
if (parent === undefined) {
|
|
753
967
|
return false;
|
|
754
968
|
}
|
|
755
969
|
else if (r_expression_list_1.RExpressionList.is(parent)) {
|
|
756
970
|
/* a block yields its last value, which is used where the block's is */
|
|
757
|
-
return
|
|
971
|
+
return data.completeAst.ast.files.some(f => f.root.info.id === parent.info.id) ? printed && autoPrintsStatementsOf(parent.info.id, data)
|
|
972
|
+
: parent.children.at(-1)?.info.id === rootId && resultIsUsed(parent.info.id, data, printed);
|
|
758
973
|
}
|
|
759
974
|
else if (r_if_then_else_1.RIfThenElse.is(parent)) {
|
|
760
|
-
return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data);
|
|
975
|
+
return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data, printed);
|
|
761
976
|
}
|
|
762
977
|
/* a loop discards what its body yields */
|
|
763
978
|
return !(model_1.RLoopConstructs.is(parent) && parent.body.info.id === rootId);
|
|
764
979
|
}
|
|
765
980
|
/** Links state reads in a loop body to the body's own writes of a later iteration and returns them, as the first iteration reads what is there before the loop. */
|
|
766
981
|
function linkAmbientStateWithinLoop(graph, reads, body) {
|
|
767
|
-
const ambient = reads.filter(r => ambient_state_name_1.AmbientStateName.is(r.name));
|
|
982
|
+
const ambient = reads.filter((r) => ambient_state_name_1.AmbientStateName.is(r.name));
|
|
768
983
|
for (const r of ambient) {
|
|
769
984
|
for (const def of resolve_helper_1.Resolve.byName(r.name, body.environment) ?? []) {
|
|
770
985
|
if (body.graph.hasVertex(def.nodeId)) {
|
|
@@ -778,51 +993,70 @@ function linkAmbientStateWithinLoop(graph, reads, body) {
|
|
|
778
993
|
function processAmbientScope(name, args, rootId, data, scope) {
|
|
779
994
|
const bound = match_args_1.MatchArgs.toNames(args, scope.params);
|
|
780
995
|
const code = scope.code === undefined ? undefined : bound.get(scope.code);
|
|
781
|
-
|
|
996
|
+
/* the code may be several arguments, all that fall to `...` (`capture.output(print(1), print(2))`) */
|
|
997
|
+
const formals = new Set([...bound.entries()].filter(([param]) => param !== '...').map(([, arg]) => arg.info.id));
|
|
998
|
+
const isCode = (arg) => arg !== undefined && arg !== r_function_call_1.EmptyArgument
|
|
999
|
+
&& (scope.code === '...' ? !formals.has(arg.info.id) : arg.info.id === code?.info.id);
|
|
1000
|
+
const family = scopedFamily(scope.state);
|
|
782
1001
|
const local = code === undefined && data.environment.level > 0;
|
|
783
|
-
const { writes, unknown } = scope.preserve ? { writes: local ? [{ name: singleStateOf(
|
|
1002
|
+
const { writes, unknown } = scope.preserve ? { writes: local ? [{ name: singleStateOf(built_in_kinds_1.AmbientSingleState.Rng), mode: AmbientWriteMode.Local }] : [], unknown: false } : scopedWrites(scope, args, bound, local);
|
|
784
1003
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
785
|
-
const apply = (environment) =>
|
|
1004
|
+
const apply = (environment) => family !== undefined ? deviceAccess({ ...info_1.DataflowInformation.initialize(rootId, data), environment }, rootId, data, local ? DeviceAccess.Switch : DeviceAccess.Open, family).environment
|
|
786
1005
|
: defineAmbient(environment, rootId, cds, writes);
|
|
787
|
-
|
|
1006
|
+
let { information } = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
788
1007
|
name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Default,
|
|
789
|
-
patchData: (d, i) => i
|
|
1008
|
+
patchData: (d, i) => isCode(args[i]) ? { ...d, environment: apply(d.environment) } : d
|
|
790
1009
|
});
|
|
1010
|
+
/* `capture.output` prints every visible value of its code into the diversion, as the top level does */
|
|
1011
|
+
for (const value of family === ambient_state_name_1.OutputSinks ? args.filter(isCode).map(r_argument_1.RArgument.valueOf) : []) {
|
|
1012
|
+
if (value !== undefined && autoPrints(value, information, data)) {
|
|
1013
|
+
const environment = information.environment;
|
|
1014
|
+
information = readsOfAutoPrint(information, value, { ...data, environment });
|
|
1015
|
+
(0, built_in_expression_list_1.printMethodsOf)(value.info.id, environment, information.graph, { graph: information.graph, idMap: data.completeAst.idMap, ctx: data.ctx, environment });
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
791
1018
|
if (unknown) {
|
|
792
1019
|
information.graph.markIdForUnknownSideEffects(rootId);
|
|
793
1020
|
}
|
|
1021
|
+
/* the state a scope changes around its code is back afterward */
|
|
1022
|
+
const changed = family !== undefined ? activeStates(family) : writes;
|
|
1023
|
+
recordAmbient(information.graph, rootId, information.environment, [], code === undefined && !(family !== undefined && local) ? changed : changed.map(w => ({ name: typeof w === 'string' ? w : w.name, mode: AmbientWriteMode.Local })));
|
|
794
1024
|
if (code === undefined) {
|
|
795
1025
|
const applied = { ...information, environment: apply(information.environment) };
|
|
796
1026
|
/* the frame starts out with the state as it was */
|
|
797
|
-
return scope.preserve && local ? withAccess(applied, rootId, data, [singleStateOf(
|
|
1027
|
+
return scope.preserve && local ? withAccess(applied, rootId, data, [singleStateOf(built_in_kinds_1.AmbientSingleState.Rng)]) : applied;
|
|
798
1028
|
}
|
|
799
1029
|
/* afterward, what the scope changed is back to what it was before */
|
|
800
1030
|
let environment = information.environment;
|
|
801
1031
|
const keyed = keyedStateOf(scope);
|
|
802
|
-
const restored =
|
|
803
|
-
: scope.state ===
|
|
1032
|
+
const restored = family !== undefined ? family.states.flat()
|
|
1033
|
+
: scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory ? [singleStateOf(scope.state)]
|
|
804
1034
|
: writes.map(w => typeof w === 'string' ? w : w.name).filter(n => keyed !== undefined && n.startsWith(ambient_state_name_1.AmbientStateName.keyed(keyed, '')) && n !== ambient_state_name_1.AmbientStateName.keyed(keyed, ambient_state_name_1.UnknownKey));
|
|
805
1035
|
for (const state of restored) {
|
|
806
1036
|
const before = resolve_helper_1.Resolve.byName(state, data.environment);
|
|
807
1037
|
/* an entry nothing set before keeps the scope's definition, we cannot tell R's default apart */
|
|
808
|
-
if ((before !== undefined && before.length > 0) || ((
|
|
1038
|
+
if ((before !== undefined && before.length > 0) || ((family !== undefined || scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory) && data.environment.level === 0)) {
|
|
809
1039
|
environment = setAmbient(environment, state, before ?? []);
|
|
810
1040
|
}
|
|
811
1041
|
}
|
|
812
|
-
if (scope.state ===
|
|
1042
|
+
if (scope.state === built_in_kinds_1.AmbientSingleState.Graphics) {
|
|
813
1043
|
/* `with_par` restores the parameters it set, what its code set with `par` stays */
|
|
814
1044
|
const kept = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.graphics, environment) ?? []).filter(d => d.nodeId !== rootId);
|
|
815
1045
|
environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.graphics, kept);
|
|
816
1046
|
}
|
|
817
1047
|
return { ...information, environment };
|
|
818
1048
|
}
|
|
1049
|
+
/** The family of instances a scope opens one of for its code, `with_png` a device and `capture.output` a diversion of the output. */
|
|
1050
|
+
function scopedFamily(state) {
|
|
1051
|
+
return state === built_in_kinds_1.AmbientSingleState.Device ? ambient_state_name_1.GraphicsDevices : state === built_in_kinds_1.AmbientSingleState.Sink ? ambient_state_name_1.OutputSinks : undefined;
|
|
1052
|
+
}
|
|
819
1053
|
/** The keyed state an {@link AmbientScope} changes the entries of, `undefined` for a state without entries. */
|
|
820
1054
|
function keyedStateOf(scope) {
|
|
821
|
-
return scope.state ===
|
|
1055
|
+
return scope.state === ambient_state_name_1.KeyedState.Option || scope.state === ambient_state_name_1.KeyedState.Env || scope.state === ambient_state_name_1.KeyedState.Locale ? scope.state : undefined;
|
|
822
1056
|
}
|
|
823
1057
|
/** The pseudo variable of a scoped state without entries. */
|
|
824
1058
|
function singleStateOf(state) {
|
|
825
|
-
return state ===
|
|
1059
|
+
return state === built_in_kinds_1.AmbientSingleState.Rng ? ambient_state_name_1.AmbientStateName.rng : state === built_in_kinds_1.AmbientSingleState.WorkingDirectory ? ambient_state_name_1.AmbientStateName.workingDirectory : ambient_state_name_1.AmbientStateName.graphics;
|
|
826
1060
|
}
|
|
827
1061
|
/** what a scope call writes: the entries of a keyed state it names, or the state it changes as a whole */
|
|
828
1062
|
function scopedWrites(scope, args, bound, local) {
|
|
@@ -830,7 +1064,7 @@ function scopedWrites(scope, args, bound, local) {
|
|
|
830
1064
|
if (keyed === undefined) {
|
|
831
1065
|
const name = singleStateOf(scope.state);
|
|
832
1066
|
/* only the directory is restored as a whole (withr's `local_seed` leaves the generator where the function's draws took it) */
|
|
833
|
-
return { writes: [local && scope.state ===
|
|
1067
|
+
return { writes: [local && scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory ? { name, mode: AmbientWriteMode.Local } : name], unknown: false };
|
|
834
1068
|
}
|
|
835
1069
|
const keys = [];
|
|
836
1070
|
let unknown = false;
|
|
@@ -875,27 +1109,37 @@ function scopedWrites(scope, args, bound, local) {
|
|
|
875
1109
|
names.push(ambient_state_name_1.AmbientStateName.keyed(keyed, ambient_state_name_1.UnknownKey));
|
|
876
1110
|
}
|
|
877
1111
|
names.push(ambient_state_name_1.AmbientStateName.allOf(keyed));
|
|
878
|
-
const writes = names.map(name => local ? { name, mode:
|
|
1112
|
+
const writes = names.map(name => local ? { name, mode: AmbientWriteMode.Local } : name);
|
|
879
1113
|
return { writes, unknown: unknown || (options && keys.some(k => GlobalEffectOptions.has(k))) };
|
|
880
1114
|
}
|
|
881
1115
|
/** Evaluating captured code may access any state; `Quoted.finalize` drops the writes again once the code is known to change none. */
|
|
882
1116
|
function evaluatesCapturedCode(res, rootId, data) {
|
|
883
1117
|
return withAccess(res, rootId, data, Quoted.reads, Quoted.writes);
|
|
884
1118
|
}
|
|
885
|
-
/**
|
|
1119
|
+
/** What the implicit `print` of a top-level value reads (see {@link readsOfAutoPrint}): every option if a method may print it (`dispatched`). */
|
|
1120
|
+
function autoPrintReads(dispatched) {
|
|
1121
|
+
return [...optionReads(dispatched ? undefined : built_in_kinds_1.PrintingOptions), ambient_state_name_1.AmbientStateName.sink];
|
|
1122
|
+
}
|
|
1123
|
+
/** what printing writes: it is part of the diversion of the output, see {@link OutputSinks} */
|
|
1124
|
+
exports.PrintWrites = [ambient_state_name_1.AmbientStateName.sinkOutput];
|
|
1125
|
+
/** R prints every visible top-level value (see {@link autoPrints}) by an implicit `print`, which reads the options the configured `print` reads for that value, and draws a plot object. */
|
|
886
1126
|
function readsOfAutoPrint(processed, expression, data) {
|
|
887
1127
|
const print = resolve_helper_1.Resolve.byNameAndType('print', { current: environment_1.REnvironment.findBuiltIn(data.environment.current), level: 0 }, identifier_1.ReferenceType.Function)?.slice(0, 1) ?? [];
|
|
888
|
-
const reads = print.flatMap(hiddenAccess).flatMap(
|
|
889
|
-
? printingReads(expression,
|
|
890
|
-
return withAccess(processed, expression.info.id, data, reads, []);
|
|
1128
|
+
const reads = print.flatMap(hiddenAccess).flatMap(effect => effect.family === ambient_state_name_1.KeyedState.Option && effect.access === ambient_effect_1.AmbientVerb.Reads
|
|
1129
|
+
? printingReads(expression, effect.dispatchOn !== undefined, typeof effect.member === 'object' && effect.member.from === 'constant' ? effect.member.keys : [], data) : []);
|
|
1130
|
+
return withAccess(processed, expression.info.id, data, [...reads, ambient_state_name_1.AmbientStateName.sink], [...exports.PrintWrites, ...mayHoldPlot(expression, data) ? DrawsNewPlot : []]);
|
|
891
1131
|
}
|
|
892
1132
|
/** the processors whose calls return invisibly, although their configuration states no {@link CallProp.Invisible} */
|
|
893
1133
|
const InvisibleProcessors = new Set([built_in_proc_name_1.BuiltInProcName.ForLoop, built_in_proc_name_1.BuiltInProcName.WhileLoop, built_in_proc_name_1.BuiltInProcName.RepeatLoop,
|
|
894
1134
|
built_in_proc_name_1.BuiltInProcName.Assignment, built_in_proc_name_1.BuiltInProcName.SuperAssignment, built_in_proc_name_1.BuiltInProcName.FunctionDefinition]);
|
|
1135
|
+
/** Whether R prints the visible values of the statements of the expression list `list`: those of the top level of the analyzed script, not of a sourced file. */
|
|
1136
|
+
function autoPrintsStatementsOf(list, data) {
|
|
1137
|
+
return data.referenceChain.length <= 1 && data.environment.level === 0 && data.completeAst.ast.files.some(f => f.root.info.id === list);
|
|
1138
|
+
}
|
|
895
1139
|
/** whether the value of the top-level `expression` is visible, so that R prints it, decided on its vertex */
|
|
896
1140
|
function autoPrints(expression, processed, data) {
|
|
897
1141
|
const vertex = processed.graph.getVertex(expression.info.id);
|
|
898
|
-
if (vertex === undefined
|
|
1142
|
+
if (vertex === undefined) {
|
|
899
1143
|
return false;
|
|
900
1144
|
}
|
|
901
1145
|
else if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
@@ -904,9 +1148,16 @@ function autoPrints(expression, processed, data) {
|
|
|
904
1148
|
else if (Array.isArray(vertex.origin) && vertex.origin.some(o => InvisibleProcessors.has(o))) {
|
|
905
1149
|
return false;
|
|
906
1150
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1151
|
+
else if (r_expression_list_1.RExpressionList.is(expression) && expression.grouping?.[0].lexeme === '{' && vertex.onlyBuiltin && expression.children.length > 0) {
|
|
1152
|
+
/* a block hands on its last value, visible or not */
|
|
1153
|
+
return autoPrints(expression.children[expression.children.length - 1], processed, data);
|
|
1154
|
+
}
|
|
1155
|
+
return !returnsInvisibly(vertex.name, data.environment);
|
|
1156
|
+
}
|
|
1157
|
+
/** `invisible`, `library`, ...: whether everything `name` resolves to returns invisibly */
|
|
1158
|
+
function returnsInvisibly(name, environment) {
|
|
1159
|
+
const targets = resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Function);
|
|
1160
|
+
return targets !== undefined && targets.length > 0 && targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && built_in_props_1.CallProps.hasAny(t.config, built_in_props_1.CallProp.Invisible));
|
|
910
1161
|
}
|
|
911
1162
|
/** A call through a variable bound to a built-in (`p <- par; p(...)`), only revealed when linking the statement's calls. */
|
|
912
1163
|
function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph, data) {
|
|
@@ -917,9 +1168,13 @@ function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph,
|
|
|
917
1168
|
const known = res.unknownReferences.length;
|
|
918
1169
|
for (const builtIn of builtIns) {
|
|
919
1170
|
const targets = node_id_1.NodeId.isBuiltIn(builtIn) ? resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(builtIn), before, identifier_1.ReferenceType.Function) ?? [] : [];
|
|
920
|
-
res =
|
|
1171
|
+
res = applyAmbientEffects(res, call.arguments, callId, data, targets.flatMap(hiddenAccess));
|
|
921
1172
|
hiddenSideEffects(graph, before, callId, targets);
|
|
922
1173
|
}
|
|
1174
|
+
const access = res.graph.ambientAccessOf(callId);
|
|
1175
|
+
if (access !== undefined && res.graph !== graph) {
|
|
1176
|
+
graph.recordAmbientAccess(callId, ambient_access_1.AmbientAccess.names(access));
|
|
1177
|
+
}
|
|
923
1178
|
for (const read of res.unknownReferences.slice(known)) {
|
|
924
1179
|
for (const def of resolve_helper_1.Resolve.byName(read.name, before) ?? []) {
|
|
925
1180
|
graph.addEdge(read.nodeId, def.nodeId, edge_1.EdgeType.Reads);
|
|
@@ -927,53 +1182,133 @@ function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph,
|
|
|
927
1182
|
}
|
|
928
1183
|
return res;
|
|
929
1184
|
}
|
|
930
|
-
/**
|
|
931
|
-
function
|
|
932
|
-
|
|
1185
|
+
/** The writes that may set `warn` to 2 or more before or within what turns `before` into `after`. */
|
|
1186
|
+
function warnsAsErrorsSources(after, before) {
|
|
1187
|
+
const lookup = (name) => [...resolve_helper_1.Resolve.byName(name, before) ?? [], ...resolve_helper_1.Resolve.byName(name, after) ?? []];
|
|
1188
|
+
const marked = new Set(lookup(ambient_state_name_1.AmbientStateName.warnsAsErrors).map(d => d.nodeId));
|
|
1189
|
+
return new Set([...lookup(ambient_state_name_1.AmbientStateName.option('warn')).filter(d => marked.has(d.nodeId)), ...lookup(ambient_state_name_1.AmbientStateName.unknownOption)].map(d => d.nodeId));
|
|
933
1190
|
}
|
|
934
1191
|
/** With `warn >= 2` R turns warnings into errors, so whatever may warn in `block` is a maybe error exit reading the options that may set `warn`. */
|
|
935
1192
|
function errorsOfWarnings(block, after, graph, data) {
|
|
936
|
-
const
|
|
937
|
-
const marked = new Set(lookup(ambient_state_name_1.AmbientStateName.warnsAsErrors).map(d => d.nodeId));
|
|
938
|
-
const sources = new Set([...lookup(ambient_state_name_1.AmbientStateName.option('warn')).filter(d => marked.has(d.nodeId)), ...lookup(ambient_state_name_1.AmbientStateName.unknownOption)].map(d => d.nodeId));
|
|
1193
|
+
const sources = warnsAsErrorsSources(after, data.environment);
|
|
939
1194
|
if (sources.size === 0) {
|
|
940
1195
|
return [];
|
|
941
1196
|
}
|
|
942
1197
|
const cds = data.cds ? [...data.cds] : [];
|
|
943
|
-
return warningSites(block, graph, data, new Map()).map(site => {
|
|
1198
|
+
return warningSites(block, graph, data, new Map(), { muffled: true, link: true }).map(site => {
|
|
944
1199
|
for (const source of sources) {
|
|
945
1200
|
graph.addEdge(site, source, edge_1.EdgeType.Reads);
|
|
946
1201
|
}
|
|
947
1202
|
return { type: 4 /* ExitPointType.Error */, nodeId: site, cds };
|
|
948
1203
|
});
|
|
949
1204
|
}
|
|
950
|
-
/**
|
|
951
|
-
function
|
|
1205
|
+
/** What may signal a condition of the class `name` when `block` runs, which a handler for it depends on: everything that may warn, and for any class other than a warning also what muffles warnings, as that lets other conditions through. */
|
|
1206
|
+
function signalSites(block, name, graph, data, link) {
|
|
1207
|
+
return warningSites(block, graph, data, new Map(), { muffled: name === 'warning', link });
|
|
1208
|
+
}
|
|
1209
|
+
/** the classes of an error R raises on its own, as for arguments a closure does not take */
|
|
1210
|
+
const ErrorClasses = ['simpleError', 'error', 'condition'];
|
|
1211
|
+
/** Whether running `block` may signal a condition a handler for the class `condition` catches, so whether the handler may run. */
|
|
1212
|
+
function maySignal(block, condition, graph, data, after) {
|
|
1213
|
+
if (condition === 'interrupt') {
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
const signal = { condition, warningsAreErrors: warnsAsErrorsSources(after, data.environment).size > 0 };
|
|
1217
|
+
return warningSites(block, graph, data, new Map(), { muffled: condition === 'warning', link: false, signal }).length > 0;
|
|
1218
|
+
}
|
|
1219
|
+
/** Whether a handler for `signal` catches a condition of the `classes`. */
|
|
1220
|
+
function catches(signal, classes) {
|
|
1221
|
+
return classes.includes(signal.condition) || (signal.warningsAreErrors && classes.includes('warning') && ErrorClasses.includes(signal.condition));
|
|
1222
|
+
}
|
|
1223
|
+
/** The classes the call `call` of the built-in `targets` signals, if it states them and is handed nothing but constants. */
|
|
1224
|
+
function signaledClasses(call, targets) {
|
|
1225
|
+
const [target] = targets;
|
|
1226
|
+
const signals = targets.length === 1 && target.type === identifier_1.ReferenceType.BuiltInFunction ? target.config?.signals : undefined;
|
|
1227
|
+
return signals !== undefined && call.arguments.every(a => a !== r_function_call_1.EmptyArgument && model_1.RConstant.is(a.value)) ? signals : undefined;
|
|
1228
|
+
}
|
|
1229
|
+
/** Whether reading the variable `symbol` may signal: it may force a promise, be an active binding, or not exist. */
|
|
1230
|
+
function readMaySignal(symbol, graph, environment, idMap) {
|
|
1231
|
+
/* the body of a closure the block calls is not part of the graph of the block */
|
|
1232
|
+
const vertex = graph.getVertex(symbol.info.id);
|
|
1233
|
+
if (vertex === undefined ? NotRead.has(symbol.info.role) || (symbol.info.role === "bin-l" /* RoleInParent.BinaryOperationLhs */ && assigns(model_1.RNode.directParent(symbol, idMap))) : !vertex_1.DfgVertex.isUse(vertex)) {
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
const definitions = resolve_helper_1.Resolve.byName(symbol.content, environment) ?? [];
|
|
1237
|
+
return definitions.length === 0 || definitions.some(d => {
|
|
1238
|
+
if ((0, identifier_1.isReferenceType)(d.type, identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.BuiltInFunction)) {
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
const at = idMap.get(d.nodeId);
|
|
1242
|
+
const by = at && model_1.RNode.directParent(at, idMap);
|
|
1243
|
+
/* an assignment operator evaluates its value right away */
|
|
1244
|
+
return !assigns(by);
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
/** the places a symbol names something rather than reads it */
|
|
1248
|
+
const NotRead = new Set(["call-name" /* RoleInParent.FunctionCallName */, "param-n" /* RoleInParent.ParameterName */, "arg-n" /* RoleInParent.ArgumentName */, "for-var" /* RoleInParent.ForVariable */]);
|
|
1249
|
+
function assigns(node) {
|
|
1250
|
+
return r_binary_op_1.RBinaryOp.is(node) && r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs === base_operators_1.OperatorUsedAs.Assignment;
|
|
1251
|
+
}
|
|
1252
|
+
/** Whether a call of the closure `definition` errs for its arguments alone, as one it has no parameter for. */
|
|
1253
|
+
function rejectsArguments(definition, call) {
|
|
1254
|
+
const names = definition.parameters.map(p => identifier_1.Identifier.getName(p.name.content));
|
|
1255
|
+
if (names.includes('...')) {
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
const given = call.arguments.filter(a => a !== r_function_call_1.EmptyArgument);
|
|
1259
|
+
return given.length > names.length || given.some(a => a.name !== undefined && !names.some(n => n.startsWith(identifier_1.Identifier.getName(a.name?.content ?? ''))));
|
|
1260
|
+
}
|
|
1261
|
+
/** Whether `id` follows a statement that always exits, so it never runs and has no vertex. */
|
|
1262
|
+
function unanalyzed(id, graph, data) {
|
|
1263
|
+
return data.unreachable?.has(id) === true && !graph.hasVertex(id);
|
|
1264
|
+
}
|
|
1265
|
+
/** what may warn when `root` runs, see {@link WarningSiteMode}, `bodies` holds what may in the bodies of the closures seen so far */
|
|
1266
|
+
function warningSites(root, graph, data, bodies, mode) {
|
|
952
1267
|
const sites = [];
|
|
1268
|
+
const { signal } = mode;
|
|
953
1269
|
model_1.RNode.visitAst(root, node => {
|
|
954
|
-
if (r_function_definition_1.RFunctionDefinition.is(node)) {
|
|
1270
|
+
if (r_function_definition_1.RFunctionDefinition.is(node) || unanalyzed(node.info.id, graph, data)) {
|
|
955
1271
|
return true;
|
|
956
1272
|
}
|
|
957
|
-
else if (r_binary_op_1.RBinaryOp.is(node) ? r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs !==
|
|
1273
|
+
else if (r_binary_op_1.RBinaryOp.is(node) ? r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs !== base_operators_1.OperatorUsedAs.Assignment : r_unary_op_1.RUnaryOp.is(node) || r_access_1.RAccess.is(node)) {
|
|
1274
|
+
sites.push(node.info.id);
|
|
1275
|
+
}
|
|
1276
|
+
else if (signal !== undefined && (r_symbol_1.RSymbol.is(node) ? readMaySignal(node, graph, data.environment, data.completeAst.idMap) : testsValue(node))) {
|
|
958
1277
|
sites.push(node.info.id);
|
|
959
1278
|
}
|
|
960
1279
|
else if (r_function_call_1.RFunctionCall.is(node)) {
|
|
961
1280
|
const targets = node.named ? resolve_helper_1.Resolve.byNameAndType(node.functionName.content, data.environment, identifier_1.ReferenceType.Function) ?? [] : [];
|
|
962
|
-
|
|
1281
|
+
const classes = signal === undefined ? undefined : signaledClasses(node, targets);
|
|
1282
|
+
if (signal !== undefined && classes !== undefined) {
|
|
1283
|
+
if (catches(signal, classes)) {
|
|
1284
|
+
sites.push(node.info.id);
|
|
1285
|
+
}
|
|
1286
|
+
return false;
|
|
1287
|
+
}
|
|
1288
|
+
if (mode.muffled && targets.length > 0 && targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && t.config?.muffles?.includes('warning') === true)) {
|
|
963
1289
|
return true;
|
|
964
1290
|
}
|
|
965
|
-
const handlers = muffledHandlers(node, graph, data);
|
|
1291
|
+
const handlers = mode.muffled ? muffledHandlers(node, graph, data) : undefined;
|
|
966
1292
|
if (handlers !== undefined) {
|
|
967
|
-
sites.push(...handlers.flatMap(h => warningSites(h, graph, data, bodies)));
|
|
1293
|
+
sites.push(...handlers.flatMap(h => warningSites(h, graph, data, bodies, mode)));
|
|
968
1294
|
return true;
|
|
969
1295
|
}
|
|
970
|
-
|
|
1296
|
+
/* a name the construct does not see, as a global called in a function body, runs what the linker bound to the call */
|
|
1297
|
+
const callees = targets.length === 0 ? df_helper_1.Dataflow.calleeIdsOf(graph, node.info.id).map(id => data.completeAst.idMap.get(id))
|
|
1298
|
+
: targets.flatMap(t => hidesBody(t) ? [undefined] : t.value?.map(id => data.completeAst.idMap.get(id)) ?? [undefined]);
|
|
971
1299
|
if (callees.length === 0 || !callees.every(r_function_definition_1.RFunctionDefinition.is)) {
|
|
972
1300
|
sites.push(node.info.id);
|
|
973
1301
|
return false;
|
|
974
1302
|
}
|
|
1303
|
+
if (signal !== undefined && ErrorClasses.includes(signal.condition) && callees.some(c => rejectsArguments(c, node))) {
|
|
1304
|
+
sites.push(node.info.id);
|
|
1305
|
+
}
|
|
975
1306
|
/* the body runs in the function's own scope, we resolve what it calls where the construct is, which is where most functions live */
|
|
976
|
-
const within = callees.flatMap(c => bodySites(c, graph, data, bodies));
|
|
1307
|
+
const within = callees.flatMap(c => bodySites(c, graph, data, bodies, mode));
|
|
1308
|
+
if (!mode.link) {
|
|
1309
|
+
sites.push(...within);
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
977
1312
|
for (const site of within) {
|
|
978
1313
|
graph.addEdge(node.info.id, site, edge_1.EdgeType.Reads);
|
|
979
1314
|
}
|
|
@@ -985,6 +1320,13 @@ function warningSites(root, graph, data, bodies) {
|
|
|
985
1320
|
});
|
|
986
1321
|
return sites;
|
|
987
1322
|
}
|
|
1323
|
+
/** Whether `node` branches or loops on a value R may reject: a condition that is not `TRUE` or `FALSE` (`if(NA)`, `if(logical(0))`) or a vector that is not a constant. */
|
|
1324
|
+
function testsValue(node) {
|
|
1325
|
+
if (r_if_then_else_1.RIfThenElse.is(node) || r_while_loop_1.RWhileLoop.is(node)) {
|
|
1326
|
+
return !r_logical_1.RLogical.is(node.condition);
|
|
1327
|
+
}
|
|
1328
|
+
return r_for_loop_1.RForLoop.is(node) && !model_1.RConstant.is(node.vector);
|
|
1329
|
+
}
|
|
988
1330
|
/** The handlers of a `withCallingHandlers` whose first handler muffles every `warning` of its `expr`, `undefined` otherwise. */
|
|
989
1331
|
function muffledHandlers(call, graph, data) {
|
|
990
1332
|
const vertex = graph.getVertex(call.info.id);
|
|
@@ -1010,12 +1352,12 @@ function callsBuiltIn(call, name, origin, graph, data) {
|
|
|
1010
1352
|
return targets !== undefined && targets.length > 0 && targets.every(t => t.nodeId === node_id_1.NodeId.toBuiltIn(name));
|
|
1011
1353
|
}
|
|
1012
1354
|
/** what may warn in the body of the closure `definition`, cached in `bodies` */
|
|
1013
|
-
function bodySites(definition, graph, data, bodies) {
|
|
1355
|
+
function bodySites(definition, graph, data, bodies, mode) {
|
|
1014
1356
|
let sites = bodies.get(definition.info.id);
|
|
1015
1357
|
if (sites === undefined) {
|
|
1016
1358
|
/* a recursive call adds nothing to what the body may warn about */
|
|
1017
1359
|
bodies.set(definition.info.id, []);
|
|
1018
|
-
sites = warningSites(definition.body, graph, data, bodies);
|
|
1360
|
+
sites = warningSites(definition.body, graph, data, bodies, mode);
|
|
1019
1361
|
bodies.set(definition.info.id, sites);
|
|
1020
1362
|
}
|
|
1021
1363
|
return sites;
|