@eagleoutice/flowr 2.17.5 → 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 +13 -51
- package/abstract-interpretation/absint-inference.d.ts +4 -4
- package/abstract-interpretation/absint-inference.js +11 -11
- package/abstract-interpretation/abstract-semantics.d.ts +2 -1
- package/abstract-interpretation/branch-paths-interpreter.d.ts +1 -0
- 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/dataframe-semantics.d.ts +6 -1
- package/abstract-interpretation/data-frame/dataframe-semantics.js +60 -1
- package/abstract-interpretation/data-frame/semantics.js +4 -10
- package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -1
- package/cli/repl/core.js +51 -0
- package/control-flow/cfg-dead-code.js +12 -7
- 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-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/environments/ambient-effect.d.ts +1000 -0
- package/dataflow/environments/ambient-effect.js +234 -0
- package/dataflow/environments/ambient-state-name.d.ts +45 -2
- package/dataflow/environments/ambient-state-name.js +61 -3
- package/dataflow/environments/apply-kill.js +11 -4
- package/dataflow/environments/built-in-kinds.d.ts +4 -46
- package/dataflow/environments/built-in-kinds.js +6 -2
- package/dataflow/environments/built-in-props.d.ts +16 -4
- package/dataflow/environments/built-in-props.js +11 -3
- package/dataflow/environments/built-in.d.ts +6 -1
- package/dataflow/environments/built-in.js +13 -36
- package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/base-functions.js +110 -52
- package/dataflow/environments/default-builtin-config/base-language.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/base-language.js +11 -8
- package/dataflow/environments/default-builtin-config/dev-tooling.js +1 -1
- package/dataflow/environments/default-builtin-config/file-io.js +6 -4
- package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/graphics-devices.js +24 -14
- 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 +3 -3
- package/dataflow/environments/default-builtin-config/index.js +22 -7
- package/dataflow/environments/default-builtin-config/media-formats.js +4 -4
- package/dataflow/environments/default-builtin-config/package-spatial.js +2 -1
- package/dataflow/environments/default-builtin-config/package-tidyverse.js +3 -2
- package/dataflow/environments/default-builtin-config/package-utils.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/package-utils.js +5 -2
- package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/parallel-execution.js +3 -1
- 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/shared-configs.d.ts +138 -77
- package/dataflow/environments/default-builtin-config/shared-configs.js +52 -88
- package/dataflow/environments/default-builtin-config/statistics.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/statistics.js +4 -1
- package/dataflow/environments/diff.js +5 -2
- package/dataflow/environments/environment.d.ts +20 -0
- package/dataflow/environments/environment.js +39 -4
- package/dataflow/environments/group-generics.d.ts +5 -1
- package/dataflow/environments/group-generics.js +13 -3
- package/dataflow/environments/guard-facts.d.ts +169 -0
- package/dataflow/environments/guard-facts.js +26 -0
- package/dataflow/environments/identifier.d.ts +9 -1
- package/dataflow/environments/identifier.js +5 -0
- package/dataflow/environments/pkg-name.d.ts +1 -0
- package/dataflow/environments/query-fn-props.d.ts +3 -5
- package/dataflow/environments/query-fn-props.js +44 -21
- package/dataflow/environments/removal-marker.d.ts +2 -0
- package/dataflow/environments/removal-marker.js +5 -0
- package/dataflow/eval/resolve/resolve-strings.d.ts +2 -5
- package/dataflow/eval/resolve/resolve-strings.js +2 -2
- package/dataflow/extractor.js +24 -15
- package/dataflow/fn/condition-handlers.d.ts +2 -0
- package/dataflow/fn/condition-handlers.js +3 -1
- package/dataflow/fn/frame-reflection.d.ts +4 -2
- package/dataflow/fn/frame-reflection.js +16 -0
- package/dataflow/fn/function-props.js +15 -22
- package/dataflow/fn/function-semantics.d.ts +31 -1
- package/dataflow/fn/function-semantics.js +15 -0
- 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 +1 -0
- package/dataflow/fn/strict-function.d.ts +4 -0
- package/dataflow/fn/strict-function.js +66 -17
- package/dataflow/graph/ambient-access.d.ts +4 -1
- package/dataflow/graph/ambient-access.js +8 -2
- package/dataflow/graph/closure-frames.js +1 -1
- package/dataflow/graph/dataflowgraph-builder.d.ts +1 -1
- package/dataflow/graph/dataflowgraph-builder.js +2 -2
- package/dataflow/graph/df-helper.d.ts +6 -0
- package/dataflow/graph/df-helper.js +15 -0
- package/dataflow/graph/graph.d.ts +12 -6
- package/dataflow/graph/graph.js +21 -28
- package/dataflow/info.d.ts +2 -1
- package/dataflow/info.js +3 -1
- package/dataflow/internal/dispatch-linking.d.ts +3 -1
- package/dataflow/internal/dispatch-linking.js +1 -0
- package/dataflow/internal/linker.d.ts +2 -0
- package/dataflow/internal/linker.js +115 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +5 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +19 -57
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +471 -295
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +13 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +106 -19
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +24 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +33 -11
- 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 +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +23 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +19 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +347 -46
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +110 -16
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +9 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +28 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +16 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +37 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +19 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +55 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +11 -10
- 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 +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +64 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +160 -20
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +5 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +6 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +142 -4
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +23 -4
- 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/wiki-dataflow-graph.js +10 -4
- package/documentation/wiki-linter.js +12 -0
- package/documentation/wiki-query.js +112 -1
- package/linter/linter-rules.d.ts +41 -1
- package/linter/linter-rules.js +5 -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.js +1 -1
- package/linter/rules/cmd-check/call-arguments.js +5 -6
- package/linter/rules/cmd-check/cmd-check-util.d.ts +0 -6
- package/linter/rules/cmd-check/cmd-check-util.js +0 -28
- package/linter/rules/cmd-check/package-hooks.js +2 -1
- package/linter/rules/cmd-check/s-three-method-consistency.js +1 -1
- package/linter/rules/interactive-functions.d.ts +30 -0
- package/linter/rules/interactive-functions.js +87 -0
- package/linter/rules/process-state-in-session.js +1 -1
- package/linter/rules/undefined-symbol-util.d.ts +1 -1
- package/linter/rules/undefined-symbol-util.js +8 -2
- package/linter/rules/undefined-symbol.js +18 -7
- package/linter/rules/useless-loop.d.ts +1 -1
- package/package.json +1 -1
- package/project/context/flowr-analyzer-dependencies-context.js +2 -1
- package/project/flowr-analyzer.d.ts +1 -0
- package/project/flowr-analyzer.js +5 -5
- package/project/sigdb/build.js +14 -4
- package/project/sigdb/decode.d.ts +3 -0
- package/project/sigdb/decode.js +10 -1
- package/project/sigdb/guarded-source.d.ts +6 -0
- package/project/sigdb/guarded-source.js +29 -0
- package/project/sigdb/reader.d.ts +5 -0
- package/project/sigdb/reader.js +27 -1
- package/project/sigdb/schema.d.ts +24 -2
- 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 +6 -2
- package/queries/catalog/ambient-access-query/ambient-access-query-format.js +48 -3
- 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 +5 -2
- package/queries/catalog/code-clones-query/code-clones-query-format.js +34 -2
- 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/dependencies-query-format.d.ts +1 -1
- package/queries/catalog/dependencies-query/dependencies-query-format.js +8 -3
- 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/dice-query/dice-query-format.d.ts +7 -2
- package/queries/catalog/dice-query/dice-query-format.js +34 -2
- package/queries/catalog/does-call-query/does-call-query-format.d.ts +7 -4
- package/queries/catalog/does-call-query/does-call-query-format.js +114 -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/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +6 -3
- 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 +8 -4
- package/queries/catalog/happens-before-query/happens-before-query-format.js +37 -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/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 +69 -4
- 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 +6 -3
- package/queries/catalog/origin-query/origin-query-format.js +29 -2
- package/queries/catalog/project-query/project-query-format.d.ts +6 -3
- package/queries/catalog/project-query/project-query-format.js +98 -2
- package/queries/catalog/provenance-query/provenance-query-format.d.ts +6 -3
- package/queries/catalog/provenance-query/provenance-query-format.js +30 -2
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +9 -2
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +38 -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.js +3 -1
- package/queries/catalog/signature-query/signature-query-format.d.ts +3 -0
- package/queries/catalog/signature-query/signature-query-render.js +23 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +13 -2
- package/queries/catalog/static-slice-query/static-slice-query-format.js +55 -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.d.ts +48 -27
- package/queries/query.js +6 -4
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +4 -0
- package/r-bridge/shell.js +7 -2
- package/reconstruct/reconstruct.js +18 -3
- package/slicing/static/removal-slice.js +4 -3
- package/slicing/static/slice-call.d.ts +11 -0
- package/slicing/static/slice-call.js +43 -2
- package/slicing/static/static-slicer.d.ts +2 -0
- package/slicing/static/static-slicer.js +137 -21
- package/slicing/static/visiting-queue.d.ts +2 -0
- package/slicing/static/visiting-queue.js +4 -0
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/objects.d.ts +2 -0
- package/util/objects.js +5 -0
- package/util/r-datasets.d.ts +27 -0
- package/util/r-datasets.js +45 -0
- package/util/text/playground-link.d.ts +2 -0
- package/util/text/playground-link.js +2 -0
- 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/ambient-access-query/ambient-access-query-executor.d.ts +0 -6
- package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +0 -50
- 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/code-clones-query/code-clones-query-executor.d.ts +0 -6
- package/queries/catalog/code-clones-query/code-clones-query-executor.js +0 -38
- 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 -116
- 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 -62
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrintingOptions = void 0;
|
|
3
|
+
exports.PrintWrites = exports.PrintingOptions = void 0;
|
|
4
4
|
exports.hidesBody = hidesBody;
|
|
5
5
|
exports.reachesBuiltInLate = reachesBuiltInLate;
|
|
6
6
|
exports.readsAllAmbientState = readsAllAmbientState;
|
|
@@ -9,10 +9,13 @@ exports.ambientWritesOfRelease = ambientWritesOfRelease;
|
|
|
9
9
|
exports.makeAmbientWritesMaybe = makeAmbientWritesMaybe;
|
|
10
10
|
exports.ambientWritesBetween = ambientWritesBetween;
|
|
11
11
|
exports.markForcing = markForcing;
|
|
12
|
+
exports.markLocking = markLocking;
|
|
13
|
+
exports.mayLock = mayLock;
|
|
12
14
|
exports.mayForce = mayForce;
|
|
13
15
|
exports.ambientAccessOfSymbol = ambientAccessOfSymbol;
|
|
16
|
+
exports.holds = holds;
|
|
14
17
|
exports.drawingWritesDevice = drawingWritesDevice;
|
|
15
|
-
exports.
|
|
18
|
+
exports.applyAmbientEffects = applyAmbientEffects;
|
|
16
19
|
exports.applyAmbientStateOfCallee = applyAmbientStateOfCallee;
|
|
17
20
|
exports.hiddenSideEffects = hiddenSideEffects;
|
|
18
21
|
exports.writesOfHiddenBuiltIn = writesOfHiddenBuiltIn;
|
|
@@ -23,11 +26,13 @@ exports.processAmbientScope = processAmbientScope;
|
|
|
23
26
|
exports.evaluatesCapturedCode = evaluatesCapturedCode;
|
|
24
27
|
exports.autoPrintReads = autoPrintReads;
|
|
25
28
|
exports.readsOfAutoPrint = readsOfAutoPrint;
|
|
29
|
+
exports.autoPrintsStatementsOf = autoPrintsStatementsOf;
|
|
26
30
|
exports.autoPrints = autoPrints;
|
|
27
31
|
exports.applyAmbientStateOfCalledBuiltIns = applyAmbientStateOfCalledBuiltIns;
|
|
28
32
|
exports.errorsOfWarnings = errorsOfWarnings;
|
|
29
33
|
exports.signalSites = signalSites;
|
|
30
34
|
exports.maySignal = maySignal;
|
|
35
|
+
exports.testsValue = testsValue;
|
|
31
36
|
const info_1 = require("../../../../../info");
|
|
32
37
|
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
33
38
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
@@ -36,6 +41,8 @@ const built_in_props_1 = require("../../../../../environments/built-in-props");
|
|
|
36
41
|
const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
37
42
|
const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
38
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");
|
|
39
46
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
40
47
|
const environment_1 = require("../../../../../environments/environment");
|
|
41
48
|
const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
|
|
@@ -46,6 +53,7 @@ const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast
|
|
|
46
53
|
const r_value_1 = require("../../../../../eval/values/r-value");
|
|
47
54
|
const match_args_1 = require("../../../../../graph/match-args");
|
|
48
55
|
const known_call_handling_1 = require("../known-call-handling");
|
|
56
|
+
const built_in_expression_list_1 = require("./built-in-expression-list");
|
|
49
57
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
50
58
|
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
51
59
|
const applied_arguments_1 = require("../../../../../graph/applied-arguments");
|
|
@@ -62,16 +70,22 @@ const arrays_1 = require("../../../../../../util/collections/arrays");
|
|
|
62
70
|
const ambient_access_1 = require("../../../../../graph/ambient-access");
|
|
63
71
|
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
64
72
|
const built_in_ambient_keys_1 = require("./built-in-ambient-keys");
|
|
73
|
+
const logic_1 = require("../../../../../../util/logic");
|
|
65
74
|
const base_operators_1 = require("../../../../../environments/default-builtin-config/base-operators");
|
|
66
75
|
const r_while_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-while-loop");
|
|
67
76
|
const r_for_loop_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
|
|
68
77
|
const built_in_kinds_1 = require("../../../../../environments/built-in-kinds");
|
|
78
|
+
const ambient_effect_1 = require("../../../../../environments/ambient-effect");
|
|
69
79
|
var built_in_kinds_2 = require("../../../../../environments/built-in-kinds");
|
|
70
80
|
Object.defineProperty(exports, "PrintingOptions", { enumerable: true, get: function () { return built_in_kinds_2.PrintingOptions; } });
|
|
71
81
|
const ListConstructors = new Set(['list', 'c']);
|
|
72
|
-
|
|
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();
|
|
73
87
|
const Accumulating = new Set([
|
|
74
|
-
...DeviceStates, ambient_state_name_1.AmbientStateName.canvas, 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,
|
|
75
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
|
|
76
90
|
]);
|
|
77
91
|
/** What a call does to the graphics devices. */
|
|
@@ -80,7 +94,9 @@ var DeviceAccess;
|
|
|
80
94
|
DeviceAccess["Open"] = "open";
|
|
81
95
|
DeviceAccess["Close"] = "close";
|
|
82
96
|
DeviceAccess["CloseAll"] = "close-all";
|
|
83
|
-
/** closes one that is not known to be the active one,
|
|
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 */
|
|
84
100
|
DeviceAccess["Switch"] = "switch";
|
|
85
101
|
})(DeviceAccess || (DeviceAccess = {}));
|
|
86
102
|
/** How a write differs from the default, see {@link AmbientWrite}. */
|
|
@@ -101,21 +117,33 @@ function maybe(name) {
|
|
|
101
117
|
function optionReads(keys) {
|
|
102
118
|
return keys === undefined ? [ambient_state_name_1.AmbientStateName.allOptions] : [...keys.map(ambient_state_name_1.AmbientStateName.option), ambient_state_name_1.AmbientStateName.unknownOption];
|
|
103
119
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
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))) {
|
|
107
127
|
return;
|
|
108
128
|
}
|
|
109
|
-
const defs = resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.
|
|
110
|
-
|
|
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 ?? [])))) {
|
|
111
138
|
return;
|
|
112
139
|
}
|
|
113
140
|
const values = [];
|
|
114
141
|
for (const { nodeId } of defs) {
|
|
115
142
|
const setter = data.completeAst.idMap.get(nodeId);
|
|
116
|
-
const named = r_function_call_1.RFunctionCall.is(setter) ? setter.arguments.filter(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && identifier_1.Identifier.getName(a.name.content) ===
|
|
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) : [];
|
|
117
144
|
const value = named.length === 1 ? r_argument_1.RArgument.valueOf(named[0]) : undefined;
|
|
118
|
-
|
|
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')) {
|
|
119
147
|
return;
|
|
120
148
|
}
|
|
121
149
|
values.push(value.info.id);
|
|
@@ -142,15 +170,15 @@ function readsAllAmbientState(res, rootId, data, graphics, draws = true) {
|
|
|
142
170
|
return withAccess(res, rootId, data, reads, draws ? [{ ...maybe(ambient_state_name_1.AmbientStateName.rng), assumed: true }] : []);
|
|
143
171
|
}
|
|
144
172
|
/** Adds the reads and writes of the ambient state to what a call does, see {@link AmbientStateName}. */
|
|
145
|
-
function withAccess(res, rootId, data, reads, writes = []) {
|
|
146
|
-
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) {
|
|
147
175
|
return res;
|
|
148
176
|
}
|
|
149
177
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
150
178
|
const maybeWritten = writes.flatMap(w => typeof w === 'object' && w.mode === AmbientWriteMode.Maybe ? [w.name] : []);
|
|
151
179
|
const read = (0, arrays_1.uniqueArrayMerge)(reads, maybeWritten);
|
|
152
180
|
const readRefs = read.map(name => ({ nodeId: rootId, name, type: identifier_1.ReferenceType.Variable, cds }));
|
|
153
|
-
recordAmbient(res.graph, rootId, res.environment, read, writes);
|
|
181
|
+
recordAmbient(res.graph, rootId, res.environment, read, writes, kills);
|
|
154
182
|
/* the writes stay out of `out`: an assignment reads whatever else its source writes (`x <- y <- 3`) */
|
|
155
183
|
return {
|
|
156
184
|
...res,
|
|
@@ -162,9 +190,9 @@ function withAccess(res, rootId, data, reads, writes = []) {
|
|
|
162
190
|
function writesLocally(environment, name, mode) {
|
|
163
191
|
return mode === AmbientWriteMode.Local || (environment.level > 0 && environment.current.memory.has(name));
|
|
164
192
|
}
|
|
165
|
-
/** Notes in `graph` what the call `rootId` reads and
|
|
166
|
-
function recordAmbient(graph, rootId, environment, reads, writes) {
|
|
167
|
-
if (reads.length === 0 && writes.length === 0) {
|
|
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) {
|
|
168
196
|
return;
|
|
169
197
|
}
|
|
170
198
|
const global = [];
|
|
@@ -174,7 +202,7 @@ function recordAmbient(graph, rootId, environment, reads, writes) {
|
|
|
174
202
|
const { name, mode, assumed: isAssumed } = typeof write === 'string' ? { name: write, mode: undefined, assumed: undefined } : write;
|
|
175
203
|
(writesLocally(environment, name, mode) ? local : isAssumed ? assumed : global).push(name);
|
|
176
204
|
}
|
|
177
|
-
graph.recordAmbientAccess(rootId, { reads, writes: global, assumed, local });
|
|
205
|
+
graph.recordAmbientAccess(rootId, { reads, writes: global, assumed, local, kills });
|
|
178
206
|
}
|
|
179
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. */
|
|
180
208
|
function boundByCode(environment, name) {
|
|
@@ -256,6 +284,14 @@ function ambientWritesBetween(after, before) {
|
|
|
256
284
|
function markForcing(environment) {
|
|
257
285
|
environment_1.REnvironment.findBuiltIn(environment.current).forcing = true;
|
|
258
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
|
+
}
|
|
259
295
|
/** Whether a definition seen so far binds a promise or a text connection, see {@link markForcing}. */
|
|
260
296
|
function mayForce(environment) {
|
|
261
297
|
return environment_1.REnvironment.findBuiltIn(environment.current).forcing === true;
|
|
@@ -264,8 +300,17 @@ function mayForce(environment) {
|
|
|
264
300
|
function ambientAccessOfSymbol(res, symbol, data) {
|
|
265
301
|
const forcing = mayForce(data.environment);
|
|
266
302
|
const definitions = forcing ? resolve_helper_1.Resolve.byName(symbol.content, data.environment) ?? [] : [];
|
|
267
|
-
const
|
|
268
|
-
|
|
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] };
|
|
269
314
|
}
|
|
270
315
|
/** Binds `name` (globally) to the given definitions, in addition to what it holds with `keep`, so `#graphics` can become what another state holds. */
|
|
271
316
|
function setAmbient(environment, name, definitions, keep = false) {
|
|
@@ -320,147 +365,263 @@ const GlobalEffectEnv = /^(TZ|LANG|LANGUAGE|LC_\w+|R_\w+|TMPDIR|TEMP|TMP|HOME|PA
|
|
|
320
365
|
function keyedReads(state, keys) {
|
|
321
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)];
|
|
322
367
|
}
|
|
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
|
+
}
|
|
323
471
|
/** Whether a call drawing on a device writes its canvas, see `semantics.ambient.drawingWritesDevice`. */
|
|
324
472
|
function drawingWritesDevice(config) {
|
|
325
473
|
return config.semantics.ambient?.drawingWritesDevice === true;
|
|
326
474
|
}
|
|
327
|
-
/** Wires the {@link
|
|
328
|
-
function
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
else if (args === UnknownArguments) {
|
|
333
|
-
return applyWithUnknownArguments(res, rootId, data, access);
|
|
334
|
-
}
|
|
335
|
-
const reads = [];
|
|
336
|
-
const writes = [];
|
|
337
|
-
switch (access.type) {
|
|
338
|
-
case "read-graphics" /* AmbientStateAccessType.ReadGraphics */:
|
|
339
|
-
reads.push(ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette);
|
|
340
|
-
if (drawingWritesDevice(data.ctx.config)) {
|
|
341
|
-
writes.push(ambient_state_name_1.AmbientStateName.canvas);
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
|
-
case "set-graphics" /* AmbientStateAccessType.SetGraphics */:
|
|
345
|
-
/* the call returns the previous state */
|
|
346
|
-
reads.push(ambient_state_name_1.AmbientStateName.graphics);
|
|
347
|
-
if (onlyQueries(access, args)) {
|
|
348
|
-
if (access.queryLinksTo) {
|
|
349
|
-
(0, unknown_side_effect_1.handleUnknownSideEffect)(res.graph, res.environment, rootId, access.queryLinksTo);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
writes.push(ambient_state_name_1.AmbientStateName.graphics, ...access.keys === undefined ? [] : (0, built_in_ambient_keys_1.keyedWrites)(ambient_state_name_1.KeyedState.Par, (0, built_in_ambient_keys_1.keysOf)(access.keys, args, data)));
|
|
354
|
-
}
|
|
355
|
-
break;
|
|
356
|
-
case "set-palette" /* AmbientStateAccessType.SetPalette */:
|
|
357
|
-
reads.push(ambient_state_name_1.AmbientStateName.palette);
|
|
358
|
-
if (!onlyQueries(access, args)) {
|
|
359
|
-
writes.push(ambient_state_name_1.AmbientStateName.palette);
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
case "read-options" /* AmbientStateAccessType.ReadOptions */: {
|
|
363
|
-
const dispatched = access.dispatchOn === undefined ? undefined : r_argument_1.RArgument.valueOf(args[access.dispatchOn]);
|
|
364
|
-
reads.push(...printingReads(dispatched, access.dispatchOn !== undefined, access.keys, data));
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
case "get-option" /* AmbientStateAccessType.GetOption */: {
|
|
368
|
-
const first = args.find(a => a !== r_function_call_1.EmptyArgument && (a.name === undefined || identifier_1.Identifier.getName(a.name.content) === 'x'));
|
|
369
|
-
const keys = (0, built_in_ambient_keys_1.stringValuesOf)(r_argument_1.RArgument.valueOf(first), data);
|
|
370
|
-
reads.push(...optionReads(keys));
|
|
371
|
-
if (args.length === 1) {
|
|
372
|
-
linkOptionValue(res, rootId, keys, data);
|
|
373
|
-
}
|
|
374
|
-
break;
|
|
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);
|
|
375
480
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
/* a variable R or a child process reads by itself is read by calls we cannot name */
|
|
381
|
-
if (access.state === ambient_state_name_1.KeyedState.Env && keys.some(k => k === ambient_state_name_1.UnknownKey || GlobalEffectEnv.test(k))) {
|
|
382
|
-
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);
|
|
383
485
|
}
|
|
384
|
-
writes.push(...(0, built_in_ambient_keys_1.keyedWrites)(access.state, keys));
|
|
385
|
-
break;
|
|
386
486
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
case
|
|
399
|
-
return
|
|
400
|
-
case
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
/* a new kind reseeds the generator from its current state, so it changes the stream as well */
|
|
412
|
-
if (args.some((a, i) => a !== r_function_call_1.EmptyArgument && (a.name === undefined ? i >= kindFrom : identifier_1.Identifier.getName(a.name.content) !== 'seed'))) {
|
|
413
|
-
reads.push(ambient_state_name_1.AmbientStateName.rng);
|
|
414
|
-
writes.push(ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.rng);
|
|
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]) };
|
|
415
511
|
}
|
|
416
512
|
break;
|
|
417
|
-
|
|
418
|
-
case
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
break;
|
|
422
|
-
case "read-files" /* AmbientStateAccessType.ReadFiles */: {
|
|
423
|
-
const stems = fileStems(res, rootId, data, access);
|
|
424
|
-
if (stems?.length === 0) {
|
|
425
|
-
break;
|
|
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);
|
|
426
517
|
}
|
|
427
|
-
reads
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files] : stems.map(ambient_state_name_1.AmbientStateName.file));
|
|
431
|
-
}
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
case "write-files" /* AmbientStateAccessType.WriteFiles */: {
|
|
435
|
-
const stems = fileStems(res, rootId, data, access);
|
|
436
|
-
if (stems?.length === 0) {
|
|
437
|
-
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);
|
|
438
521
|
}
|
|
439
|
-
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
|
|
440
|
-
writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files);
|
|
441
522
|
break;
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return withAccess(res, rootId, data, [ambient_state_name_1.AmbientStateName.finalizers], registered.flatMap(d => d.writes ?? []).map(maybe));
|
|
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);
|
|
461
541
|
}
|
|
462
542
|
}
|
|
463
|
-
|
|
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;
|
|
464
625
|
}
|
|
465
626
|
/** `reg.finalizer(e, f)` keeps the functions `f` may be, and the name holding `e`, whose release lets `gc()` run them. */
|
|
466
627
|
function registerFinalizer(res, args, rootId, data) {
|
|
@@ -581,133 +742,120 @@ function isPlainValue(node, data) {
|
|
|
581
742
|
}
|
|
582
743
|
/** The arguments of a call made on our behalf, like `do.call(par, args)`, which we cannot see. */
|
|
583
744
|
const UnknownArguments = Symbol('unknown-arguments');
|
|
584
|
-
function applyWithUnknownArguments(res, rootId, data,
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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) {
|
|
588
752
|
/* the arguments handed on (`do.call(readLines, list("a.txt"))`, `lapply(files, readLines)`) may still name the files */
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
res.graph.markIdForUnknownSideEffects(rootId);
|
|
597
|
-
}
|
|
598
|
-
const { reads, writes } = unknownArgumentAccess(access, drawingWritesDevice(data.ctx.config));
|
|
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));
|
|
599
760
|
return withAccess(res, rootId, data, reads, writes);
|
|
600
761
|
}
|
|
601
|
-
const Devices = { reads: [], writes: [ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.device] };
|
|
602
762
|
/* evaluated code may attach a package as well, which every call nothing else resolves reads */
|
|
603
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)] };
|
|
604
|
-
/** What
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
/** Graphics parameters are per device; within a function the open devices are unknown, so a device call only adds. */
|
|
643
|
-
function deviceAccess(res, rootId, data, kind) {
|
|
644
|
-
/* only a switch reads the state; what a closed device holds reaches its file through the plots on it (see LinkToLastPlot) */
|
|
645
|
-
const reads = kind === DeviceAccess.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;
|
|
646
801
|
/* closing writes the file of the device, which its opening names unless we do not know the device closed */
|
|
647
802
|
const unnamedFile = kind === DeviceAccess.Open ? [] : [ambient_state_name_1.AmbientStateName.anyFile, ambient_state_name_1.AmbientStateName.files];
|
|
648
803
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
649
804
|
if (data.environment.level > 0) {
|
|
650
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 */
|
|
651
|
-
const here = kind === DeviceAccess.Close ? res.environment.current.memory.get(
|
|
806
|
+
const here = kind === DeviceAccess.Close ? res.environment.current.memory.get(family.openedHere) ?? [] : [];
|
|
652
807
|
for (const open of here) {
|
|
653
808
|
res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
654
809
|
}
|
|
655
|
-
let environment = { ...res.environment, current: res.environment.current.removeAll([{ name:
|
|
810
|
+
let environment = { ...res.environment, current: res.environment.current.removeAll([{ name: family.openedHere }]) };
|
|
656
811
|
if (kind === DeviceAccess.Open) {
|
|
657
|
-
environment = defineAmbient(environment, rootId, cds, [{ name:
|
|
812
|
+
environment = defineAmbient(environment, rootId, cds, [{ name: family.openedHere, mode: AmbientWriteMode.Local }]);
|
|
658
813
|
}
|
|
659
|
-
|
|
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]);
|
|
660
816
|
}
|
|
661
817
|
const lookup = (name) => resolve_helper_1.Resolve.byName(name, res.environment) ?? [];
|
|
662
|
-
|
|
663
|
-
const
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const reset = (name) => defineAmbient(environment, rootId, cds, [{ name, mode: AmbientWriteMode.Reset }]);
|
|
668
|
-
/* 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 */
|
|
669
|
-
const closes = (openers) => {
|
|
670
|
-
for (const open of openers) {
|
|
671
|
-
res.graph.addEdge(open.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
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
|
+
}
|
|
674
823
|
/* in a loop, an earlier round may have opened a device this one leaves behind, or a close may leave one open */
|
|
675
824
|
const repeats = model_1.RLoopConstructs.encloses(rootId, data.completeAst.idMap);
|
|
676
|
-
const earlierRound = repeats ? [{ nodeId: rootId, name:
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
environment = setAmbient(environment, ambient_state_name_1.AmbientStateName.otherDevicesOpenedBy, opener, true);
|
|
701
|
-
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
|
+
}
|
|
702
849
|
}
|
|
703
|
-
|
|
704
|
-
const
|
|
705
|
-
|
|
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);
|
|
706
854
|
}
|
|
707
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. */
|
|
708
856
|
function applyAmbientStateOfCallee(res, callId, fn, data) {
|
|
709
857
|
const targets = resolve_helper_1.Resolve.byNameAndType(fn, data.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
710
|
-
res =
|
|
858
|
+
res = applyAmbientEffects(res, UnknownArguments, callId, data, targets.flatMap(hiddenAccess));
|
|
711
859
|
hiddenSideEffects(res.graph, res.environment, callId, targets);
|
|
712
860
|
const unknown = (targets.length === 0 && data.environment.level === 0) || targets.some(t => t.type !== identifier_1.ReferenceType.BuiltInFunction && hidesBody(t));
|
|
713
861
|
return unknown ? readsAllAmbientState(res, callId, data, true) : res;
|
|
@@ -735,8 +883,7 @@ function hiddenSideEffects(graph, environment, callId, targets) {
|
|
|
735
883
|
}
|
|
736
884
|
}
|
|
737
885
|
function hiddenAccess(target) {
|
|
738
|
-
|
|
739
|
-
return [access ?? []].flat();
|
|
886
|
+
return ambient_effect_1.Ambient.list(target.type === identifier_1.ReferenceType.BuiltInFunction ? target.config?.ambient : undefined);
|
|
740
887
|
}
|
|
741
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)`. */
|
|
742
889
|
function writesOfHiddenBuiltIn(target, callId, drawing = false) {
|
|
@@ -798,40 +945,34 @@ function setOptions(res, args, rootId, data) {
|
|
|
798
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. */
|
|
799
946
|
function callOnlyQueries(fn, args, environment) {
|
|
800
947
|
const targets = resolve_helper_1.Resolve.byNameAndType(fn, environment, identifier_1.ReferenceType.Function) ?? [];
|
|
801
|
-
return targets.length > 0 && targets.every(t => hiddenAccess(t)
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
case "set-options" /* AmbientStateAccessType.SetOptions */:
|
|
808
|
-
return isQuery(args);
|
|
809
|
-
case "set-palette" /* AmbientStateAccessType.SetPalette */:
|
|
810
|
-
return args.length === 0;
|
|
811
|
-
case "set-state" /* AmbientStateAccessType.SetState */:
|
|
812
|
-
return access.queryWithoutArguments === true && args.length === 0;
|
|
813
|
-
default:
|
|
814
|
-
return false;
|
|
815
|
-
}
|
|
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);
|
|
816
954
|
}
|
|
817
955
|
/** `par()`, `par("mar", "usr")`, and `par(no.readonly = TRUE)` only query the graphics state */
|
|
818
956
|
function isQuery(args) {
|
|
819
957
|
return args.every(a => a === r_function_call_1.EmptyArgument
|
|
820
958
|
|| (a.name === undefined ? r_string_1.RString.is(a.value) : identifier_1.Identifier.getName(a.name.content) === 'no.readonly'));
|
|
821
959
|
}
|
|
822
|
-
/** Whether the call's value may be used: anything but a non-final statement or
|
|
823
|
-
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) {
|
|
824
962
|
const node = data.completeAst.idMap.get(rootId);
|
|
825
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));
|
|
826
966
|
if (parent === undefined) {
|
|
827
967
|
return false;
|
|
828
968
|
}
|
|
829
969
|
else if (r_expression_list_1.RExpressionList.is(parent)) {
|
|
830
970
|
/* a block yields its last value, which is used where the block's is */
|
|
831
|
-
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);
|
|
832
973
|
}
|
|
833
974
|
else if (r_if_then_else_1.RIfThenElse.is(parent)) {
|
|
834
|
-
return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data);
|
|
975
|
+
return parent.condition.info.id === rootId || resultIsUsed(parent.info.id, data, printed);
|
|
835
976
|
}
|
|
836
977
|
/* a loop discards what its body yields */
|
|
837
978
|
return !(model_1.RLoopConstructs.is(parent) && parent.body.info.id === rootId);
|
|
@@ -852,22 +993,34 @@ function linkAmbientStateWithinLoop(graph, reads, body) {
|
|
|
852
993
|
function processAmbientScope(name, args, rootId, data, scope) {
|
|
853
994
|
const bound = match_args_1.MatchArgs.toNames(args, scope.params);
|
|
854
995
|
const code = scope.code === undefined ? undefined : bound.get(scope.code);
|
|
855
|
-
|
|
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);
|
|
856
1001
|
const local = code === undefined && data.environment.level > 0;
|
|
857
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);
|
|
858
1003
|
const cds = data.cds ? [...data.cds] : undefined;
|
|
859
|
-
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
|
|
860
1005
|
: defineAmbient(environment, rootId, cds, writes);
|
|
861
|
-
|
|
1006
|
+
let { information } = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
862
1007
|
name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Default,
|
|
863
|
-
patchData: (d, i) => i
|
|
1008
|
+
patchData: (d, i) => isCode(args[i]) ? { ...d, environment: apply(d.environment) } : d
|
|
864
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
|
+
}
|
|
865
1018
|
if (unknown) {
|
|
866
1019
|
information.graph.markIdForUnknownSideEffects(rootId);
|
|
867
1020
|
}
|
|
868
1021
|
/* the state a scope changes around its code is back afterward */
|
|
869
|
-
const changed =
|
|
870
|
-
recordAmbient(information.graph, rootId, information.environment, [], code === undefined && !(
|
|
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 })));
|
|
871
1024
|
if (code === undefined) {
|
|
872
1025
|
const applied = { ...information, environment: apply(information.environment) };
|
|
873
1026
|
/* the frame starts out with the state as it was */
|
|
@@ -876,13 +1029,13 @@ function processAmbientScope(name, args, rootId, data, scope) {
|
|
|
876
1029
|
/* afterward, what the scope changed is back to what it was before */
|
|
877
1030
|
let environment = information.environment;
|
|
878
1031
|
const keyed = keyedStateOf(scope);
|
|
879
|
-
const restored =
|
|
1032
|
+
const restored = family !== undefined ? family.states.flat()
|
|
880
1033
|
: scope.state === built_in_kinds_1.AmbientSingleState.Rng || scope.state === built_in_kinds_1.AmbientSingleState.WorkingDirectory ? [singleStateOf(scope.state)]
|
|
881
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));
|
|
882
1035
|
for (const state of restored) {
|
|
883
1036
|
const before = resolve_helper_1.Resolve.byName(state, data.environment);
|
|
884
1037
|
/* an entry nothing set before keeps the scope's definition, we cannot tell R's default apart */
|
|
885
|
-
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)) {
|
|
886
1039
|
environment = setAmbient(environment, state, before ?? []);
|
|
887
1040
|
}
|
|
888
1041
|
}
|
|
@@ -893,6 +1046,10 @@ function processAmbientScope(name, args, rootId, data, scope) {
|
|
|
893
1046
|
}
|
|
894
1047
|
return { ...information, environment };
|
|
895
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
|
+
}
|
|
896
1053
|
/** The keyed state an {@link AmbientScope} changes the entries of, `undefined` for a state without entries. */
|
|
897
1054
|
function keyedStateOf(scope) {
|
|
898
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;
|
|
@@ -961,22 +1118,28 @@ function evaluatesCapturedCode(res, rootId, data) {
|
|
|
961
1118
|
}
|
|
962
1119
|
/** What the implicit `print` of a top-level value reads (see {@link readsOfAutoPrint}): every option if a method may print it (`dispatched`). */
|
|
963
1120
|
function autoPrintReads(dispatched) {
|
|
964
|
-
return optionReads(dispatched ? undefined : built_in_kinds_1.PrintingOptions);
|
|
1121
|
+
return [...optionReads(dispatched ? undefined : built_in_kinds_1.PrintingOptions), ambient_state_name_1.AmbientStateName.sink];
|
|
965
1122
|
}
|
|
966
|
-
/**
|
|
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. */
|
|
967
1126
|
function readsOfAutoPrint(processed, expression, data) {
|
|
968
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) ?? [];
|
|
969
|
-
const reads = print.flatMap(hiddenAccess).flatMap(
|
|
970
|
-
? printingReads(expression,
|
|
971
|
-
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 : []]);
|
|
972
1131
|
}
|
|
973
1132
|
/** the processors whose calls return invisibly, although their configuration states no {@link CallProp.Invisible} */
|
|
974
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,
|
|
975
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
|
+
}
|
|
976
1139
|
/** whether the value of the top-level `expression` is visible, so that R prints it, decided on its vertex */
|
|
977
1140
|
function autoPrints(expression, processed, data) {
|
|
978
1141
|
const vertex = processed.graph.getVertex(expression.info.id);
|
|
979
|
-
if (vertex === undefined
|
|
1142
|
+
if (vertex === undefined) {
|
|
980
1143
|
return false;
|
|
981
1144
|
}
|
|
982
1145
|
else if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
@@ -985,9 +1148,16 @@ function autoPrints(expression, processed, data) {
|
|
|
985
1148
|
else if (Array.isArray(vertex.origin) && vertex.origin.some(o => InvisibleProcessors.has(o))) {
|
|
986
1149
|
return false;
|
|
987
1150
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
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));
|
|
991
1161
|
}
|
|
992
1162
|
/** A call through a variable bound to a built-in (`p <- par; p(...)`), only revealed when linking the statement's calls. */
|
|
993
1163
|
function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph, data) {
|
|
@@ -998,7 +1168,7 @@ function applyAmbientStateOfCalledBuiltIns(res, callId, builtIns, before, graph,
|
|
|
998
1168
|
const known = res.unknownReferences.length;
|
|
999
1169
|
for (const builtIn of builtIns) {
|
|
1000
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) ?? [] : [];
|
|
1001
|
-
res =
|
|
1171
|
+
res = applyAmbientEffects(res, call.arguments, callId, data, targets.flatMap(hiddenAccess));
|
|
1002
1172
|
hiddenSideEffects(graph, before, callId, targets);
|
|
1003
1173
|
}
|
|
1004
1174
|
const access = res.graph.ambientAccessOf(callId);
|
|
@@ -1088,12 +1258,16 @@ function rejectsArguments(definition, call) {
|
|
|
1088
1258
|
const given = call.arguments.filter(a => a !== r_function_call_1.EmptyArgument);
|
|
1089
1259
|
return given.length > names.length || given.some(a => a.name !== undefined && !names.some(n => n.startsWith(identifier_1.Identifier.getName(a.name?.content ?? ''))));
|
|
1090
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
|
+
}
|
|
1091
1265
|
/** what may warn when `root` runs, see {@link WarningSiteMode}, `bodies` holds what may in the bodies of the closures seen so far */
|
|
1092
1266
|
function warningSites(root, graph, data, bodies, mode) {
|
|
1093
1267
|
const sites = [];
|
|
1094
1268
|
const { signal } = mode;
|
|
1095
1269
|
model_1.RNode.visitAst(root, node => {
|
|
1096
|
-
if (r_function_definition_1.RFunctionDefinition.is(node)) {
|
|
1270
|
+
if (r_function_definition_1.RFunctionDefinition.is(node) || unanalyzed(node.info.id, graph, data)) {
|
|
1097
1271
|
return true;
|
|
1098
1272
|
}
|
|
1099
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)) {
|
|
@@ -1111,7 +1285,7 @@ function warningSites(root, graph, data, bodies, mode) {
|
|
|
1111
1285
|
}
|
|
1112
1286
|
return false;
|
|
1113
1287
|
}
|
|
1114
|
-
if (mode.muffled &&
|
|
1288
|
+
if (mode.muffled && targets.length > 0 && targets.every(t => t.type === identifier_1.ReferenceType.BuiltInFunction && t.config?.muffles?.includes('warning') === true)) {
|
|
1115
1289
|
return true;
|
|
1116
1290
|
}
|
|
1117
1291
|
const handlers = mode.muffled ? muffledHandlers(node, graph, data) : undefined;
|
|
@@ -1146,10 +1320,12 @@ function warningSites(root, graph, data, bodies, mode) {
|
|
|
1146
1320
|
});
|
|
1147
1321
|
return sites;
|
|
1148
1322
|
}
|
|
1149
|
-
/** Whether `node` branches or loops on a value
|
|
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. */
|
|
1150
1324
|
function testsValue(node) {
|
|
1151
|
-
|
|
1152
|
-
|
|
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);
|
|
1153
1329
|
}
|
|
1154
1330
|
/** The handlers of a `withCallingHandlers` whose first handler muffles every `warning` of its `expr`, `undefined` otherwise. */
|
|
1155
1331
|
function muffledHandlers(call, graph, data) {
|