@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
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.claimBeyond = claimBeyond;
|
|
4
|
+
exports.relationsOf = relationsOf;
|
|
5
|
+
exports.conditionalClaimsOf = conditionalClaimsOf;
|
|
6
|
+
exports.casesOf = casesOf;
|
|
7
|
+
exports.impliedBy = impliedBy;
|
|
8
|
+
exports.claimsOf = claimsOf;
|
|
9
|
+
exports.returnedClaimOf = returnedClaimOf;
|
|
10
|
+
exports.returnsOf = returnsOf;
|
|
11
|
+
exports.returnedFormalOf = returnedFormalOf;
|
|
12
|
+
exports.readingOf = readingOf;
|
|
13
|
+
exports.claimConditions = claimConditions;
|
|
14
|
+
exports.claimWords = claimWords;
|
|
15
|
+
exports.caseConditions = caseConditions;
|
|
16
|
+
exports.returnWords = returnWords;
|
|
17
|
+
exports.returnConditions = returnConditions;
|
|
18
|
+
const interval_domain_1 = require("../../../abstract-interpretation/domains/interval-domain");
|
|
19
|
+
const bounded_set_domain_1 = require("../../../abstract-interpretation/domains/bounded-set-domain");
|
|
20
|
+
const guard_term_1 = require("./guard-term");
|
|
21
|
+
const guard_facts_1 = require("../../environments/guard-facts");
|
|
22
|
+
const set_1 = require("../../../util/collections/set");
|
|
23
|
+
const guard_knowledge_1 = require("./guard-knowledge");
|
|
24
|
+
const condition_grouping_1 = require("./condition-grouping");
|
|
25
|
+
const AllTypes = (0, guard_knowledge_1.typeNames)(guard_facts_1.AnyType).length;
|
|
26
|
+
/** The types as a set, which is top once it holds every one of them. */
|
|
27
|
+
function typeSet(types) {
|
|
28
|
+
return new bounded_set_domain_1.BoundedSetDomain(Array.from({ length: AllTypes }, (_, i) => 1 << i).filter(bit => (types & bit) !== 0), AllTypes - 1);
|
|
29
|
+
}
|
|
30
|
+
/** The types of the set, all of them for top. */
|
|
31
|
+
function typeBits(types) {
|
|
32
|
+
return types.isValue() ? types.value.values().reduce((acc, type) => acc | type, 0) : guard_facts_1.AnyType;
|
|
33
|
+
}
|
|
34
|
+
const NoValues = bounded_set_domain_1.BoundedSetDomain.top();
|
|
35
|
+
function ofValues(values) {
|
|
36
|
+
return values === undefined ? NoValues : NoValues.create(values);
|
|
37
|
+
}
|
|
38
|
+
const Unconstrained = { types: typeSet(guard_facts_1.AnyType), plain: typeSet(guard_facts_1.AnyType), values: NoValues, partial: false, classes: undefined, bounds: new Map(), notNA: false, callable: false, whole: false, resolves: new Map() };
|
|
39
|
+
function ofTypes(types, classed = false) {
|
|
40
|
+
return { ...Unconstrained, types: typeSet(types), plain: typeSet(classed ? 0 : types) };
|
|
41
|
+
}
|
|
42
|
+
function ofBound(measure, lower, upper) {
|
|
43
|
+
return { ...Unconstrained, bounds: new Map([[measure, new interval_domain_1.IntervalDomain([lower, upper])]]) };
|
|
44
|
+
}
|
|
45
|
+
function combineMaps(a, b, meet) {
|
|
46
|
+
const result = new Map();
|
|
47
|
+
for (const key of new Set([...a.keys(), ...b.keys()])) {
|
|
48
|
+
const [left, right] = [a.get(key), b.get(key)];
|
|
49
|
+
if (left !== undefined && right !== undefined) {
|
|
50
|
+
result.set(key, meet ? left.meet(right) : left.join(right));
|
|
51
|
+
}
|
|
52
|
+
else if (meet) {
|
|
53
|
+
result.set(key, (left ?? right));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/** Both hold. */
|
|
59
|
+
function both(a, b) {
|
|
60
|
+
const values = a.values.meet(b.values);
|
|
61
|
+
return {
|
|
62
|
+
types: a.types.meet(b.types),
|
|
63
|
+
plain: a.plain.meet(b.plain),
|
|
64
|
+
values,
|
|
65
|
+
/* whichever narrowed it last keeps the exact values, those always pass the partial ones as well */
|
|
66
|
+
partial: (a.values.isTop() || a.partial) && (b.values.isTop() || b.partial) && !values.isTop(),
|
|
67
|
+
/* each of them holds, and a class set says "at least one of these": either answer is true, the smaller says more */
|
|
68
|
+
classes: a.classes === undefined || (b.classes !== undefined && b.classes.size < a.classes.size) ? b.classes : a.classes,
|
|
69
|
+
bounds: combineMaps(a.bounds, b.bounds, true),
|
|
70
|
+
notNA: a.notNA || b.notNA,
|
|
71
|
+
callable: a.callable || b.callable,
|
|
72
|
+
whole: a.whole || b.whole,
|
|
73
|
+
resolves: new Map([...a.resolves, ...b.resolves])
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** At least one of the two holds. */
|
|
77
|
+
function either(a, b) {
|
|
78
|
+
const values = a.values.join(b.values);
|
|
79
|
+
return {
|
|
80
|
+
types: a.types.join(b.types),
|
|
81
|
+
plain: a.plain.join(b.plain),
|
|
82
|
+
values,
|
|
83
|
+
partial: !values.isTop() && (a.partial || b.partial),
|
|
84
|
+
classes: a.classes === undefined || b.classes === undefined ? undefined : a.classes.union(b.classes),
|
|
85
|
+
bounds: combineMaps(a.bounds, b.bounds, false),
|
|
86
|
+
notNA: a.notNA && b.notNA,
|
|
87
|
+
callable: a.callable && b.callable,
|
|
88
|
+
whole: a.whole && b.whole,
|
|
89
|
+
resolves: new Map([...a.resolves].filter(([expression]) => b.resolves.has(expression)))
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function isFormal(term, formal) {
|
|
93
|
+
return term?.kind === 'formal' && term.name === formal;
|
|
94
|
+
}
|
|
95
|
+
/** The value of a constant that is one, skipping `NA` and the like. */
|
|
96
|
+
function valuesOf(constants) {
|
|
97
|
+
const values = constants.map(c => c.value);
|
|
98
|
+
return values.every(v => v !== undefined) ? new Set(values) : undefined;
|
|
99
|
+
}
|
|
100
|
+
function ofPredicate(call, formal, holds, facts) {
|
|
101
|
+
const [first, second] = call.args.map(a => a.value);
|
|
102
|
+
const name = guard_term_1.GuardTerm.bareName(call.fn);
|
|
103
|
+
if (call.fn === 'isTRUE' || call.fn === 'isFALSE') {
|
|
104
|
+
return holds && isFormal(first, formal) ? both(ofTypes(guard_facts_1.RValueType.Logical), ofBound('length', 1, 1)) : Unconstrained;
|
|
105
|
+
}
|
|
106
|
+
const stated = facts(name);
|
|
107
|
+
const predicate = stated?.predicate;
|
|
108
|
+
if (predicate !== undefined && isFormal(first, formal)) {
|
|
109
|
+
if (holds) {
|
|
110
|
+
const types = { ...ofTypes(predicate.yes | (predicate.classedToo ?? 0), predicate.classed), ...(predicate.classed ? {} : { plain: typeSet(predicate.yes) }) };
|
|
111
|
+
const typed = predicate.callable ? { ...types, callable: true } : types;
|
|
112
|
+
return predicate.scalar ? both(typed, ofBound('length', 1, 1)) : typed;
|
|
113
|
+
}
|
|
114
|
+
const others = typeSet(guard_facts_1.AnyType & ~predicate.yes);
|
|
115
|
+
const ruledOut = predicate.exact === 'unclassed' ? { ...Unconstrained, plain: others } : predicate.exact ? { ...Unconstrained, types: others, plain: others } : Unconstrained;
|
|
116
|
+
/* whatever a string can be measured against, this is not one */
|
|
117
|
+
return call.fn === 'is.character' ? { ...ruledOut, values: NoValues.bottom() } : ruledOut;
|
|
118
|
+
}
|
|
119
|
+
else if (isFormal(first, formal) && (holds ? name === 'is.finite' : name === 'is.na' || name === 'anyNA')) {
|
|
120
|
+
return { ...Unconstrained, notNA: true };
|
|
121
|
+
}
|
|
122
|
+
else if (stated?.measures !== undefined && isFormal(first, formal) && call.args.length === 1) {
|
|
123
|
+
return holds ? boundOf(name, '>=', 1) : boundOf(name, '==', 0);
|
|
124
|
+
}
|
|
125
|
+
else if (holds && call.fn === 'inherits' && isFormal(first, formal) && call.args.length === 2) {
|
|
126
|
+
const classes = valuesOf(guard_term_1.GuardTerm.constantsOf(second) ?? []);
|
|
127
|
+
return classes?.size ? { ...Unconstrained, classes: new Set([...classes].map(String)) } : Unconstrained;
|
|
128
|
+
}
|
|
129
|
+
return Unconstrained;
|
|
130
|
+
}
|
|
131
|
+
/** The comparison operator read the other way around, `1 < x` being `x > 1`. */
|
|
132
|
+
const Swapped = { '<': '>', '>': '<', '<=': '>=', '>=': '<=', '==': '==', '!=': '!=' };
|
|
133
|
+
function boundOf(measure, op, value) {
|
|
134
|
+
/* what counts comes in whole numbers, so a bound between two of them, or a strict one, says more than it spells out */
|
|
135
|
+
const whole = measure !== 'value';
|
|
136
|
+
switch (op) {
|
|
137
|
+
case '==':
|
|
138
|
+
return ofBound(measure, value, value);
|
|
139
|
+
case '>':
|
|
140
|
+
return ofBound(measure, whole ? Math.floor(value) + 1 : value, Infinity);
|
|
141
|
+
case '>=':
|
|
142
|
+
return ofBound(measure, whole ? Math.ceil(value) : value, Infinity);
|
|
143
|
+
case '<':
|
|
144
|
+
return ofBound(measure, -Infinity, whole ? Math.ceil(value) - 1 : value);
|
|
145
|
+
case '<=':
|
|
146
|
+
return ofBound(measure, -Infinity, whole ? Math.floor(value) : value);
|
|
147
|
+
case '!=':
|
|
148
|
+
return measure !== 'value' && value === 0 ? ofBound(measure, 1, Infinity) : Unconstrained;
|
|
149
|
+
default:
|
|
150
|
+
return Unconstrained;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** What `read op constants` says, `read` being a term reading something off the formal. */
|
|
154
|
+
function ofComparison(read, op, right, formal, facts) {
|
|
155
|
+
const constants = guard_term_1.GuardTerm.constantsOf(right);
|
|
156
|
+
if (guard_term_1.GuardTerm.isCall(read) && read.known && isFormal(read.args[0]?.value, formal) && read.args.length === 1) {
|
|
157
|
+
const reader = facts(read.fn)?.reads;
|
|
158
|
+
const values = (op === '==' || op === '%in%') && constants !== undefined ? valuesOf(constants) : undefined;
|
|
159
|
+
if (reader !== undefined && values !== undefined) {
|
|
160
|
+
const types = [...values].map(v => reader[String(v)]);
|
|
161
|
+
return types.every(t => t !== undefined) ? ofTypes(types.reduce((acc, t) => acc | t, 0)) : Unconstrained;
|
|
162
|
+
}
|
|
163
|
+
else if (read.fn === 'class' && values !== undefined) {
|
|
164
|
+
return { ...Unconstrained, classes: new Set([...values].map(String)) };
|
|
165
|
+
}
|
|
166
|
+
const number = constants?.length === 1 ? constants[0].value : undefined;
|
|
167
|
+
return facts(read.fn)?.measures !== undefined && typeof number === 'number' ? boundOf(read.fn, op, number) : Unconstrained;
|
|
168
|
+
}
|
|
169
|
+
else if (!isFormal(read, formal) || constants === undefined) {
|
|
170
|
+
return Unconstrained;
|
|
171
|
+
}
|
|
172
|
+
const number = constants.length === 1 ? constants[0].value : undefined;
|
|
173
|
+
if (op === '%in%' || (op === '==' && typeof number !== 'number')) {
|
|
174
|
+
const values = valuesOf(constants);
|
|
175
|
+
return values === undefined ? Unconstrained : { ...Unconstrained, values: ofValues(values) };
|
|
176
|
+
}
|
|
177
|
+
return typeof number === 'number' ? boundOf('value', op, number) : Unconstrained;
|
|
178
|
+
}
|
|
179
|
+
function ofCheck(call, formal, facts) {
|
|
180
|
+
const name = guard_term_1.GuardTerm.bareName(call.fn);
|
|
181
|
+
if (name === 'UseMethod') {
|
|
182
|
+
const [{ value: generic }, { value: object }] = call.args;
|
|
183
|
+
return isFormal(object, formal) && generic.kind === 'constant' ? { ...Unconstrained, resolves: new Map([[`${generic.lexeme}.class(${formal})`, { expression: `paste0(${generic.lexeme}, ".", class(${formal}))`, prefix: `${String(generic.value)}.`, suffix: '' }]]) } : Unconstrained;
|
|
184
|
+
}
|
|
185
|
+
if ((0, guard_knowledge_1.appliesFormal)(facts(name)) && isFormal(call.args[0]?.value, formal)) {
|
|
186
|
+
return { ...Unconstrained, callable: true };
|
|
187
|
+
}
|
|
188
|
+
const check = facts(name)?.check;
|
|
189
|
+
if (check === undefined || !isFormal(call.args[0]?.value, formal)) {
|
|
190
|
+
return Unconstrained;
|
|
191
|
+
}
|
|
192
|
+
let types = check.types ?? guard_facts_1.AnyType;
|
|
193
|
+
let loosened = false;
|
|
194
|
+
for (const [option, adds] of Object.entries(check.loosens ?? {})) {
|
|
195
|
+
const given = call.args.find(a => a.name === option)?.value;
|
|
196
|
+
/* left out, it stays at its default of not loosening anything */
|
|
197
|
+
if (given !== undefined && !(given.kind === 'constant' && given.value === false)) {
|
|
198
|
+
types |= adds;
|
|
199
|
+
loosened ||= (adds & guard_facts_1.RValueType.Null) !== 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const choices = check.choices === undefined ? undefined : call.args.find((a, i) => a.name === check.choices || (a.name === undefined && i === 1))?.value;
|
|
203
|
+
const values = choices === undefined ? undefined : valuesOf(guard_term_1.GuardTerm.constantsOf(choices) ?? []);
|
|
204
|
+
const claim = { ...ofTypes(types, check.classed), values: ofValues(values), partial: values !== undefined && check.partial === true };
|
|
205
|
+
return check.scalar && !loosened ? both(claim, ofBound('length', 1, 1)) : claim;
|
|
206
|
+
}
|
|
207
|
+
/** What surrounds the formal in the `paste0`, `paste`, or `sprintf` that spells out a name, if that is all there is to it. */
|
|
208
|
+
function surroundings(term, formal) {
|
|
209
|
+
if (!guard_term_1.GuardTerm.isCall(term)) {
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
const texts = term.args.filter(a => a.name === undefined).map(a => a.value);
|
|
213
|
+
if (term.fn === 'sprintf') {
|
|
214
|
+
const [format, ...rest] = texts;
|
|
215
|
+
const parts = format?.kind === 'constant' && typeof format.value === 'string' ? format.value.split('%s') : [];
|
|
216
|
+
return parts.length === 2 && rest.length === 1 && isFormal(rest[0], formal) ? { prefix: parts[0], suffix: parts[1] } : {};
|
|
217
|
+
}
|
|
218
|
+
const separator = term.args.find(a => a.name === 'sep')?.value;
|
|
219
|
+
const glue = term.fn === 'paste0' ? '' : separator === undefined ? ' ' : separator.kind === 'constant' && typeof separator.value === 'string' ? separator.value : undefined;
|
|
220
|
+
const at = texts.findIndex(t => isFormal(t, formal));
|
|
221
|
+
const strings = texts.map(t => t.kind === 'constant' && typeof t.value === 'string' ? t.value : undefined);
|
|
222
|
+
if (glue === undefined || at < 0 || strings.some((t, i) => i !== at && t === undefined) || term.args.some(a => a.name === 'collapse')) {
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
const around = (from, outer) => from.length === 0 ? '' : outer(from.join(glue));
|
|
226
|
+
return { prefix: around(strings.slice(0, at), t => t + glue), suffix: around(strings.slice(at + 1), t => glue + t) };
|
|
227
|
+
}
|
|
228
|
+
function resolving(named, formal) {
|
|
229
|
+
const expression = guard_term_1.GuardTerm.render(named);
|
|
230
|
+
return { ...Unconstrained, resolves: new Map([[expression, { expression, ...surroundings(named, formal) }]]) };
|
|
231
|
+
}
|
|
232
|
+
function ofExists(call, formal) {
|
|
233
|
+
const [{ value: named }] = call.args;
|
|
234
|
+
const isFunctionMode = call.args.some(a => a.name === 'mode' && a.value.kind === 'constant' && a.value.value === 'function');
|
|
235
|
+
if (named.kind === 'constant' && named.value === formal) {
|
|
236
|
+
return { ...Unconstrained, callable: isFunctionMode };
|
|
237
|
+
}
|
|
238
|
+
if (!guard_term_1.GuardTerm.formalsOf(named).has(formal)) {
|
|
239
|
+
return Unconstrained;
|
|
240
|
+
}
|
|
241
|
+
return isFormal(named, formal) ? { ...Unconstrained, callable: isFunctionMode } : resolving(named, formal);
|
|
242
|
+
}
|
|
243
|
+
/** What `all` lets through unbounded: of no number at all, each one holds. */
|
|
244
|
+
function withoutNullable(abstract, facts) {
|
|
245
|
+
return { ...abstract, bounds: new Map([...abstract.bounds].filter(([measure]) => facts(measure)?.measures !== 'nullable')) };
|
|
246
|
+
}
|
|
247
|
+
function abstractOf(term, formal, facts) {
|
|
248
|
+
if (!guard_term_1.GuardTerm.isCall(term) || !term.known) {
|
|
249
|
+
return Unconstrained;
|
|
250
|
+
}
|
|
251
|
+
const operands = term.args.map(a => a.value);
|
|
252
|
+
const [first, second] = operands;
|
|
253
|
+
switch (term.fn) {
|
|
254
|
+
case '&&':
|
|
255
|
+
case '&':
|
|
256
|
+
return both(abstractOf(first, formal, facts), abstractOf(second, formal, facts));
|
|
257
|
+
case '||':
|
|
258
|
+
case '|':
|
|
259
|
+
return either(abstractOf(first, formal, facts), abstractOf(second, formal, facts));
|
|
260
|
+
case 'all':
|
|
261
|
+
return operands.length === 1 ? withoutNullable(abstractOf(first, formal, facts), facts) : Unconstrained;
|
|
262
|
+
case '!':
|
|
263
|
+
return guard_term_1.GuardTerm.isCall(first) && first.known ? ofPredicate(first, formal, false, facts) : Unconstrained;
|
|
264
|
+
case 'succeeds':
|
|
265
|
+
return guard_term_1.GuardTerm.isCall(first) ? ofCheck(first, formal, facts) : Unconstrained;
|
|
266
|
+
case 'exists':
|
|
267
|
+
return ofExists(term, formal);
|
|
268
|
+
case 'is.element':
|
|
269
|
+
case 'identical':
|
|
270
|
+
return operands.length === 2 ? ofComparison(first, term.fn === 'identical' ? '==' : '%in%', second, formal, facts) : Unconstrained;
|
|
271
|
+
case '%in%':
|
|
272
|
+
return ofComparison(first, '%in%', second, formal, facts);
|
|
273
|
+
default:
|
|
274
|
+
if (term.fn === '==' && operands.length === 2 && isWholeTest(first, second, formal)) {
|
|
275
|
+
return { ...Unconstrained, whole: true };
|
|
276
|
+
}
|
|
277
|
+
if (Swapped[term.fn] !== undefined && operands.length === 2) {
|
|
278
|
+
return first.kind === 'constant' ? ofComparison(second, Swapped[term.fn], first, formal, facts) : ofComparison(first, term.fn, second, formal, facts);
|
|
279
|
+
}
|
|
280
|
+
return ofPredicate(term, formal, true, facts);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** A bound the way {@link FormalClaim.bounds} states it, without one that is not known. */
|
|
284
|
+
function boundsOf(bounds) {
|
|
285
|
+
const kept = [...bounds].filter(([, domain]) => domain.isValue() && (Number.isFinite(domain.lower) || Number.isFinite(domain.upper)));
|
|
286
|
+
return kept.length === 0 ? undefined : Object.fromEntries(kept.map(([measure, { lower, upper }]) => {
|
|
287
|
+
const [low, high] = [lower, upper];
|
|
288
|
+
return [measure, [Number.isFinite(low) ? low : null, Number.isFinite(high) ? high : null]];
|
|
289
|
+
}));
|
|
290
|
+
}
|
|
291
|
+
const Numbers = guard_facts_1.RValueType.Integer | guard_facts_1.RValueType.Double;
|
|
292
|
+
/** Whether `==` tells the values apart for every value without a class, as R turns `TRUE == 1` and `"1" == 1` true, which only a string claim survives. */
|
|
293
|
+
function comparesExactly(plain, values) {
|
|
294
|
+
const kinds = new Set(values.isValue() ? [...values.value].map(v => typeof v) : []);
|
|
295
|
+
return kinds.size === 1 && (kinds.has('string') || plain.leq(typeSet(kinds.has('number') ? Numbers : guard_facts_1.RValueType.Logical)));
|
|
296
|
+
}
|
|
297
|
+
function toClaim(abstract) {
|
|
298
|
+
const { types, plain, partial, classes, notNA, callable, resolves } = abstract;
|
|
299
|
+
const values = comparesExactly(plain, abstract.values) ? abstract.values.value : undefined;
|
|
300
|
+
/* `"a" > 5` holds in R, so a bound on the value says something only of a number */
|
|
301
|
+
const bounds = plain.leq(typeSet(Numbers | guard_facts_1.RValueType.Logical)) ? abstract.bounds : new Map([...abstract.bounds].filter(([measure]) => measure !== 'value'));
|
|
302
|
+
const stated = boundsOf(bounds);
|
|
303
|
+
return {
|
|
304
|
+
...(types.isTop() ? {} : { types: (0, guard_knowledge_1.typeNames)(typeBits(types)) }),
|
|
305
|
+
...(plain.equals(types) || plain.isTop() ? {} : { unclassedTypes: (0, guard_knowledge_1.typeNames)(typeBits(plain)) }),
|
|
306
|
+
...(values === undefined || values.size === 0 ? {} : { values: [...values], ...(partial ? { partial } : {}) }),
|
|
307
|
+
...(classes === undefined ? {} : { classes: [...classes] }),
|
|
308
|
+
...(stated === undefined ? {} : { bounds: stated }),
|
|
309
|
+
...(notNA ? { notNA } : {}),
|
|
310
|
+
...(callable ? { callable } : {}),
|
|
311
|
+
...(abstract.whole ? { whole: true } : {}),
|
|
312
|
+
...(resolves.size === 0 ? {} : { resolves: [...resolves.values()] })
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** What `claim` says beyond `known`, each part `known` already makes sure of left out, so a case does not repeat its condition or what always holds. */
|
|
316
|
+
function claimBeyond(claim, known) {
|
|
317
|
+
const within = (a, b) => a !== undefined && b !== undefined && a.every(x => b.includes(x));
|
|
318
|
+
const narrower = ([lower, upper], [low, high]) => (low === null || (lower !== null && lower >= low)) && (high === null || (upper !== null && upper <= high));
|
|
319
|
+
const bounds = Object.entries(claim.bounds ?? {}).filter(([measure, range]) => known.bounds?.[measure] === undefined || !narrower(known.bounds[measure], range));
|
|
320
|
+
const resolves = (claim.resolves ?? []).filter(r => !known.resolves?.some(k => k.expression === r.expression));
|
|
321
|
+
const { types, unclassedTypes, values, partial, classes, notNA, callable, whole, cases } = claim;
|
|
322
|
+
return {
|
|
323
|
+
...types === undefined || within(known.types, types) ? {} : { types },
|
|
324
|
+
...unclassedTypes === undefined || within(known.unclassedTypes ?? known.types, unclassedTypes) ? {} : { unclassedTypes },
|
|
325
|
+
...values === undefined || (within(known.values, values) && (partial === true || known.partial !== true)) ? {} : { values, ...partial ? { partial } : {} },
|
|
326
|
+
...classes === undefined || within(known.classes, classes) ? {} : { classes },
|
|
327
|
+
...bounds.length === 0 ? {} : { bounds: Object.fromEntries(bounds) },
|
|
328
|
+
...notNA && !known.notNA ? { notNA } : {},
|
|
329
|
+
...callable && !known.callable ? { callable } : {},
|
|
330
|
+
...whole && !known.whole ? { whole } : {},
|
|
331
|
+
...resolves.length === 0 ? {} : { resolves },
|
|
332
|
+
...cases === undefined ? {} : { cases }
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/** The functions that drop the fraction of a number, so `trunc(x) == x` holds only for a whole `x`. */
|
|
336
|
+
const Rounding = new Set(['trunc', 'round', 'floor', 'ceiling', 'as.integer']);
|
|
337
|
+
/** Whether `a == b` asks the formal to be a whole number: `trunc(x) == x` either way around, or `x %% 1 == 0`. */
|
|
338
|
+
function isWholeTest(a, b, formal) {
|
|
339
|
+
const rounds = (r, x) => guard_term_1.GuardTerm.isCall(r) && r.known === true && Rounding.has(r.fn) && r.args.length === 1 && isFormal(r.args[0].value, formal) && isFormal(x, formal);
|
|
340
|
+
const modulo = (m, zero) => guard_term_1.GuardTerm.isCall(m, '%%') && m.known === true && isFormal(m.args[0]?.value, formal) && m.args[1]?.value.kind === 'constant' && m.args[1].value.value === 1 && zero.kind === 'constant' && zero.value === 0;
|
|
341
|
+
return rounds(a, b) || rounds(b, a) || modulo(a, b) || modulo(b, a);
|
|
342
|
+
}
|
|
343
|
+
/** The comparison within `term`, also within the `all` that `stopifnot` spells a vector of them with, `undefined` if it is none. */
|
|
344
|
+
function comparisonOf(term) {
|
|
345
|
+
const inner = guard_term_1.GuardTerm.isCall(term, 'all') && term.known && term.args.length === 1 ? term.args[0].value : term;
|
|
346
|
+
return guard_term_1.GuardTerm.isCall(inner) && inner.known && Swapped[inner.fn] !== undefined && inner.args.length === 2 ? inner : undefined;
|
|
347
|
+
}
|
|
348
|
+
/** The relations between formals the given conditions state, each one a comparison of two sides that read different formals. */
|
|
349
|
+
function relationsOf(conditions, facts) {
|
|
350
|
+
return conditions.flatMap(condition => {
|
|
351
|
+
const alternatives = guard_term_1.GuardTerm.disjuncts(condition);
|
|
352
|
+
const relating = alternatives.filter(alternative => {
|
|
353
|
+
const sides = comparisonOf(alternative)?.args.map(a => guard_term_1.GuardTerm.formalsOf(a.value));
|
|
354
|
+
return sides !== undefined && sides.every(side => side.size > 0) && !(0, set_1.setEquals)(sides[0], sides[1]);
|
|
355
|
+
});
|
|
356
|
+
if (relating.length !== 1) {
|
|
357
|
+
return [];
|
|
358
|
+
}
|
|
359
|
+
const [relation] = relating;
|
|
360
|
+
const others = alternatives.filter(alternative => alternative !== relation);
|
|
361
|
+
const unless = guard_term_1.GuardTerm.any(...others);
|
|
362
|
+
const [only, ...more] = guard_term_1.GuardTerm.formalsOf(unless);
|
|
363
|
+
const unlessClaim = only === undefined || more.length > 0 ? undefined : toClaim(abstractOf(unless, only, facts));
|
|
364
|
+
return [{
|
|
365
|
+
holds: guard_term_1.GuardTerm.render(relation),
|
|
366
|
+
formals: [...guard_term_1.GuardTerm.formalsOf(relation)],
|
|
367
|
+
...(others.length === 0 ? {} : { unless: guard_term_1.GuardTerm.render(unless) }),
|
|
368
|
+
...(unlessClaim === undefined || Object.keys(unlessClaim).length === 0 ? {} : { unlessClaim: { formal: only, claim: unlessClaim } })
|
|
369
|
+
}];
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
/** The claims the given conditions make on a formal unless something not about that formal holds, see {@link ConditionalClaim}. */
|
|
373
|
+
function conditionalClaimsOf(conditions, formals, facts) {
|
|
374
|
+
return conditions.flatMap(condition => {
|
|
375
|
+
const alternatives = guard_term_1.GuardTerm.disjuncts(condition);
|
|
376
|
+
return formals.flatMap(formal => {
|
|
377
|
+
const about = alternatives.filter(a => (0, set_1.setEquals)(guard_term_1.GuardTerm.formalsOf(a), new Set([formal])));
|
|
378
|
+
const others = alternatives.filter(a => !guard_term_1.GuardTerm.formalsOf(a).has(formal));
|
|
379
|
+
if (about.length === 0 || others.length === 0 || about.length + others.length !== alternatives.length) {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
const claim = toClaim(about.map(a => abstractOf(a, formal, facts)).reduce(either));
|
|
383
|
+
/* that a formal has to have a class unless another one passes is all dispatching leaves, not a claim */
|
|
384
|
+
const onlyClassed = Object.keys(claim).length === 1 && claim.unclassedTypes?.length === 0;
|
|
385
|
+
return Object.keys(claim).length === 0 || onlyClassed ? [] : [{ formal, claim, unless: guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.any(...others)) }];
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/** The conditions that hold in the case `when`: a clause offering what the case rules out loses that alternative, one offering the case itself asks nothing. */
|
|
390
|
+
function inCase(clauses, when, otherwise) {
|
|
391
|
+
const [yes, no] = [guard_term_1.GuardTerm.render(when), new Set(guard_term_1.GuardTerm.disjuncts(otherwise).map(d => guard_term_1.GuardTerm.render(d)))];
|
|
392
|
+
const all = [...guard_term_1.GuardTerm.conjuncts(when)];
|
|
393
|
+
const own = [];
|
|
394
|
+
for (const { requires } of clauses) {
|
|
395
|
+
const alternatives = guard_term_1.GuardTerm.disjuncts(requires);
|
|
396
|
+
if (alternatives.some(a => guard_term_1.GuardTerm.render(a) === yes)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const kept = alternatives.filter(a => !no.has(guard_term_1.GuardTerm.render(a)));
|
|
400
|
+
if (kept.length + no.size === alternatives.length) {
|
|
401
|
+
own.push(guard_term_1.GuardTerm.any(...kept));
|
|
402
|
+
}
|
|
403
|
+
all.push(guard_term_1.GuardTerm.any(...kept));
|
|
404
|
+
}
|
|
405
|
+
return { all, own };
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The cases of each formal: the first branch on it alone that the conditions were found under, as `if(is.logical(center)) ... else ...`,
|
|
409
|
+
* where both ways something more is asked of it, each with what a normal return makes sure of in it.
|
|
410
|
+
*/
|
|
411
|
+
function casesOf(clauses, formals, facts) {
|
|
412
|
+
const cases = {};
|
|
413
|
+
const branches = [...new Map(clauses.flatMap(c => c.under ?? []).map(term => [guard_term_1.GuardTerm.render(term), term])).values()];
|
|
414
|
+
for (const formal of formals) {
|
|
415
|
+
for (const when of branches.filter(b => (0, set_1.setEquals)(guard_term_1.GuardTerm.formalsOf(b), new Set([formal])))) {
|
|
416
|
+
const otherwise = guard_term_1.GuardTerm.truth(when, false, facts);
|
|
417
|
+
const split = [[when, inCase(clauses, when, otherwise)], [otherwise, inCase(clauses, otherwise, when)]];
|
|
418
|
+
if (!split.every(([, { own }]) => own.some(c => guard_term_1.GuardTerm.formalsOf(c).has(formal)))) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
cases[formal] = split.map(([term, { all }]) => {
|
|
422
|
+
const relations = relationsOf(all, facts).filter(r => r.formals.includes(formal));
|
|
423
|
+
const claimOf = (conditions) => toClaim(conditions.reduce((acc, c) => both(acc, abstractOf(c, formal, facts)), Unconstrained));
|
|
424
|
+
return { when: guard_term_1.GuardTerm.render(term), claim: claimBeyond(claimOf(all), claimOf(guard_term_1.GuardTerm.conjuncts(term))), ...(relations.length > 0 ? { relations } : {}) };
|
|
425
|
+
});
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return cases;
|
|
430
|
+
}
|
|
431
|
+
/** Whether every value passing `conditions` passes `implied` as far as the types can tell; as a wrong guess only loses a clause, not what is left. */
|
|
432
|
+
function impliedBy(implied, conditions, formals, facts) {
|
|
433
|
+
const alternatives = guard_term_1.GuardTerm.disjuncts(implied);
|
|
434
|
+
/* what implies one of the alternatives implies all of them together */
|
|
435
|
+
if (alternatives.length > 1) {
|
|
436
|
+
return alternatives.some(alternative => impliedBy(alternative, conditions, formals, facts));
|
|
437
|
+
}
|
|
438
|
+
const mentioned = formals.filter(formal => guard_term_1.GuardTerm.formalsOf(implied).has(formal));
|
|
439
|
+
return mentioned.length === 1 && guard_term_1.GuardTerm.isCall(implied) && mentioned.every(formal => {
|
|
440
|
+
const known = conditions.reduce((acc, c) => both(acc, abstractOf(c, formal, facts)), Unconstrained);
|
|
441
|
+
const { plain } = abstractOf(implied, formal, facts);
|
|
442
|
+
return !known.types.isTop() && !plain.isTop() && known.types.leq(plain);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/** What the given conditions, all of which hold on a normal return, claim about each of the given formals; a formal without any claim is left out. */
|
|
446
|
+
function claimsOf(conditions, formals, facts) {
|
|
447
|
+
const claims = {};
|
|
448
|
+
for (const formal of formals) {
|
|
449
|
+
const claim = toClaim(conditions.reduce((acc, c) => both(acc, abstractOf(c, formal, facts)), Unconstrained));
|
|
450
|
+
if (Object.keys(claim).length > 0) {
|
|
451
|
+
claims[formal] = claim;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return claims;
|
|
455
|
+
}
|
|
456
|
+
/** What a function states of the values it returns, also by being a predicate, a measure, or a reader of the type. */
|
|
457
|
+
function returnedBy(facts) {
|
|
458
|
+
if (facts?.returns !== undefined) {
|
|
459
|
+
return facts.returns;
|
|
460
|
+
}
|
|
461
|
+
else if (facts?.predicate !== undefined) {
|
|
462
|
+
return { types: guard_facts_1.RValueType.Logical, scalar: true, notNA: true };
|
|
463
|
+
}
|
|
464
|
+
else if (facts?.reads !== undefined) {
|
|
465
|
+
return { types: guard_facts_1.RValueType.Character, scalar: true, notNA: true };
|
|
466
|
+
}
|
|
467
|
+
switch (facts?.measures) {
|
|
468
|
+
case 'single':
|
|
469
|
+
return { types: Numbers, scalar: true, notNA: true, count: true };
|
|
470
|
+
/* `ncol` of a table of one dimension is `NA` */
|
|
471
|
+
case 'nullable':
|
|
472
|
+
return { types: guard_facts_1.RValueType.Integer | guard_facts_1.RValueType.Null, count: true };
|
|
473
|
+
case 'elementwise':
|
|
474
|
+
return { types: guard_facts_1.RValueType.Integer };
|
|
475
|
+
default:
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function ofReturned({ types, scalar, notNA, count, nonEmpty }) {
|
|
480
|
+
const typed = { ...ofTypes(types), notNA: notNA === true, whole: count === true };
|
|
481
|
+
const counted = count ? both(typed, ofBound('value', 0, Infinity)) : typed;
|
|
482
|
+
return scalar ? both(counted, ofBound('length', 1, 1)) : nonEmpty ? both(counted, ofBound('length', 1, Infinity)) : counted;
|
|
483
|
+
}
|
|
484
|
+
/** What a function is stated to return, a classed value bringing a method of its own making it a case of the unclassed one, see {@link ReturnedValue.dispatchesOn}. */
|
|
485
|
+
function returnedClaimOf(returned) {
|
|
486
|
+
const claim = toClaim(ofReturned(returned));
|
|
487
|
+
if (Object.keys(claim).length === 0) {
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
return returned.dispatchesOn === undefined ? claim : { cases: [{ when: `!is.object(${returned.dispatchesOn})`, claim }] };
|
|
491
|
+
}
|
|
492
|
+
/** The types `c` turns its elements into, from the weakest to the strongest. */
|
|
493
|
+
const Coerced = [guard_facts_1.RValueType.Logical, guard_facts_1.RValueType.Integer, guard_facts_1.RValueType.Double, guard_facts_1.RValueType.Complex, guard_facts_1.RValueType.Character];
|
|
494
|
+
const TypeOfSymbol = { NULL: guard_facts_1.RValueType.Null, NA: guard_facts_1.RValueType.Logical, NaN: guard_facts_1.RValueType.Double, Inf: guard_facts_1.RValueType.Double, NA_integer_: guard_facts_1.RValueType.Integer, NA_real_: guard_facts_1.RValueType.Double, NA_character_: guard_facts_1.RValueType.Character, NA_complex_: guard_facts_1.RValueType.Complex };
|
|
495
|
+
function typeOfConstant({ lexeme, value }) {
|
|
496
|
+
switch (typeof value) {
|
|
497
|
+
case 'string':
|
|
498
|
+
return guard_facts_1.RValueType.Character;
|
|
499
|
+
case 'boolean':
|
|
500
|
+
return guard_facts_1.RValueType.Logical;
|
|
501
|
+
case 'number':
|
|
502
|
+
return lexeme.endsWith('L') ? guard_facts_1.RValueType.Integer : lexeme.endsWith('i') ? guard_facts_1.RValueType.Complex : guard_facts_1.RValueType.Double;
|
|
503
|
+
default:
|
|
504
|
+
return TypeOfSymbol[lexeme];
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
/** What `c` of the constants is, a single one being itself. */
|
|
508
|
+
function ofConstants(constants) {
|
|
509
|
+
const types = constants.map(typeOfConstant);
|
|
510
|
+
if (types.includes(undefined)) {
|
|
511
|
+
return Unconstrained;
|
|
512
|
+
}
|
|
513
|
+
const elements = constants.filter((_, at) => types[at] !== guard_facts_1.RValueType.Null);
|
|
514
|
+
const ranks = types.filter(t => t !== guard_facts_1.RValueType.Null).map(t => Coerced.indexOf(t));
|
|
515
|
+
if (ranks.length === 0) {
|
|
516
|
+
return both(ofTypes(guard_facts_1.RValueType.Null), ofBound('length', 0, 0));
|
|
517
|
+
}
|
|
518
|
+
const type = Coerced[Math.max(...ranks)];
|
|
519
|
+
const values = elements.map(c => c.value);
|
|
520
|
+
/* `NaN` and `Inf` are numbers to the parser */
|
|
521
|
+
const known = values.every(v => v !== undefined && (typeof v !== 'number' || Number.isFinite(v)));
|
|
522
|
+
const numbers = (type & Numbers) !== 0 && known ? values : undefined;
|
|
523
|
+
const counted = both(ofTypes(type), ofBound('length', elements.length, elements.length));
|
|
524
|
+
return {
|
|
525
|
+
...(numbers === undefined ? counted : both(counted, ofBound('value', Math.min(...numbers), Math.max(...numbers)))),
|
|
526
|
+
values: known ? ofValues(new Set(values)) : NoValues,
|
|
527
|
+
notNA: values.every(v => v !== undefined && !Number.isNaN(v)),
|
|
528
|
+
whole: numbers?.every(n => Number.isInteger(n)) ?? false
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/** What the value of the term is, `conditions` holding of the formals. */
|
|
532
|
+
function ofValue(term, conditions, facts) {
|
|
533
|
+
if (term?.kind === 'formal') {
|
|
534
|
+
return conditions.reduce((acc, c) => both(acc, abstractOf(c, term.name, facts)), Unconstrained);
|
|
535
|
+
}
|
|
536
|
+
const constants = guard_term_1.GuardTerm.constantsOf(term);
|
|
537
|
+
if (constants !== undefined && (!guard_term_1.GuardTerm.isCall(term) || term.args.every(a => a.name === undefined))) {
|
|
538
|
+
return ofConstants(constants);
|
|
539
|
+
}
|
|
540
|
+
else if (!guard_term_1.GuardTerm.isCall(term) || !term.known) {
|
|
541
|
+
return Unconstrained;
|
|
542
|
+
}
|
|
543
|
+
const [only] = term.args;
|
|
544
|
+
/* the internal code of a function of R returns what that function does, as in `.Internal(toupper(x))` */
|
|
545
|
+
if (term.fn === '.Internal' && term.args.length === 1 && guard_term_1.GuardTerm.isCall(only.value)) {
|
|
546
|
+
return ofValue({ ...only.value, known: true }, conditions, facts);
|
|
547
|
+
}
|
|
548
|
+
const returned = returnedBy(facts(guard_term_1.GuardTerm.bareName(term.fn)));
|
|
549
|
+
if (returned === 'argument') {
|
|
550
|
+
return term.args.length === 0 ? ofConstants([]) : term.args.length === 1 ? ofValue(only.value, conditions, facts) : Unconstrained;
|
|
551
|
+
}
|
|
552
|
+
/* a method for a classed argument may return anything */
|
|
553
|
+
return returned === undefined || returned.dispatchesOn !== undefined ? Unconstrained : ofReturned(returned);
|
|
554
|
+
}
|
|
555
|
+
/** What holds of the value of every normal return, given what holds of the formals on every one of them, `undefined` if that is nothing. */
|
|
556
|
+
function returnsOf(returned, conditions, facts) {
|
|
557
|
+
const claim = returned.length === 0 ? {} : toClaim(returned.map(r => ofValue(r.value, [...conditions, ...r.holds], facts)).reduce(either));
|
|
558
|
+
return Object.keys(claim).length === 0 ? undefined : claim;
|
|
559
|
+
}
|
|
560
|
+
/** The formal the term hands back as it is. */
|
|
561
|
+
function passedOn(term, facts) {
|
|
562
|
+
if (term?.kind === 'formal') {
|
|
563
|
+
return term.name;
|
|
564
|
+
}
|
|
565
|
+
return guard_term_1.GuardTerm.isCall(term) && term.known && term.args.length === 1 && returnedBy(facts(guard_term_1.GuardTerm.bareName(term.fn))) === 'argument' ? passedOn(term.args[0].value, facts) : undefined;
|
|
566
|
+
}
|
|
567
|
+
/** The formal every normal return hands back unchanged, if there is one. */
|
|
568
|
+
function returnedFormalOf(returned, facts) {
|
|
569
|
+
const [first, ...rest] = returned.map(r => passedOn(r.value, facts));
|
|
570
|
+
return rest.every(f => f === first) ? first : undefined;
|
|
571
|
+
}
|
|
572
|
+
/** `succeeds(f(x, ...))` in words: what the check `f` states of `x`, or that the call runs without an error. */
|
|
573
|
+
function succeedsInWords(call, facts) {
|
|
574
|
+
const checked = call.args[0]?.value;
|
|
575
|
+
const claim = checked?.kind === 'formal' && facts(guard_term_1.GuardTerm.bareName(call.fn))?.check !== undefined ? toClaim(ofCheck(call, checked.name, facts)) : undefined;
|
|
576
|
+
/* the choices say what the type adds for anyone reading it */
|
|
577
|
+
const said = claim === undefined || checked?.kind !== 'formal' ? [] : claimConditions(String(checked.name), claim.values === undefined ? claim : { values: claim.values, ...(claim.partial ? { partial: true } : {}) });
|
|
578
|
+
return said.length > 0 ? said.join(' && ') : `${guard_term_1.GuardTerm.render(call)} runs without an error`;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* A condition as a reader without flowR's notation reads it, `undefined` if it reads as written: each `succeeds` stated by what it checks,
|
|
582
|
+
* and, for a condition of a call of a member of a group generic, a class letting the call through as the method it may bring.
|
|
583
|
+
* @param group - the group generic the failing call dispatches through, like `Math`
|
|
584
|
+
*/
|
|
585
|
+
function readingOf(condition, facts, group) {
|
|
586
|
+
const alternatives = guard_term_1.GuardTerm.disjuncts(condition);
|
|
587
|
+
const read = (term) => {
|
|
588
|
+
if (guard_term_1.GuardTerm.isCall(term, 'succeeds') && term.known && guard_term_1.GuardTerm.isCall(term.args[0]?.value)) {
|
|
589
|
+
return succeedsInWords(term.args[0].value, facts);
|
|
590
|
+
}
|
|
591
|
+
const [of] = guard_term_1.GuardTerm.isCall(term, 'is.object') && term.known ? term.args : [];
|
|
592
|
+
return group !== undefined && of !== undefined ? `${guard_term_1.GuardTerm.render(of.value)} may have a ${group} method` : undefined;
|
|
593
|
+
};
|
|
594
|
+
const readings = alternatives.map(read);
|
|
595
|
+
return readings.every(r => r === undefined) ? undefined : alternatives.map((a, at) => readings[at] ?? guard_term_1.GuardTerm.render(a)).join(' || ');
|
|
596
|
+
}
|
|
597
|
+
/** `a`, `a or b`, `a, b, or c`. */
|
|
598
|
+
function listed(words) {
|
|
599
|
+
return words.length <= 2 ? words.join(' or ') : `${words.slice(0, -1).join(', ')}, or ${words[words.length - 1]}`;
|
|
600
|
+
}
|
|
601
|
+
/** The given types, by what they leave out if that is the shorter way of saying it. */
|
|
602
|
+
function typesInWords(types) {
|
|
603
|
+
const left = (0, guard_knowledge_1.typeNames)(guard_facts_1.AnyType).filter(t => !types.includes(t));
|
|
604
|
+
return left.length < types.length ? `anything but ${listed(left)}` : listed(types);
|
|
605
|
+
}
|
|
606
|
+
/** `{a, b}`, or the one value itself. */
|
|
607
|
+
function setOf(words) {
|
|
608
|
+
return words.length === 1 ? String(words[0]) : `{${words.join(', ')}}`;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Reads a claim on `formal` as conditions written the way R would test them, all of which hold, like
|
|
612
|
+
* `typeof(m) in {integer, double}`, `length(m) == 1`, and `m >= 0`.
|
|
613
|
+
*/
|
|
614
|
+
function claimConditions(formal, { types, unclassedTypes, values, partial, classes, bounds, notNA, callable, whole, resolves }) {
|
|
615
|
+
const ofTypes = (named, unclassed) => {
|
|
616
|
+
const left = (0, guard_knowledge_1.typeNames)(guard_facts_1.AnyType).filter(t => !named.includes(t));
|
|
617
|
+
/* NULL is the one value of its type, which R asks for by name */
|
|
618
|
+
const said = named.length === 1 && named[0] === 'NULL' ? `is.null(${formal})`
|
|
619
|
+
: left.length === 1 && left[0] === 'NULL' ? `!is.null(${formal})`
|
|
620
|
+
: left.length < named.length ? `typeof(${formal}) not in ${setOf(left)}` : `typeof(${formal}) in ${setOf(named)}`;
|
|
621
|
+
return unclassed ? `${said} unless is.object(${formal})` : said;
|
|
622
|
+
};
|
|
623
|
+
/* NULL has no elements, so a length bound says nothing more of it */
|
|
624
|
+
const onlyNull = types?.length === 1 && types[0] === 'NULL';
|
|
625
|
+
const range = (measure, [lower, upper]) => {
|
|
626
|
+
const of = measure === 'value' ? formal : `${measure}(${formal})`;
|
|
627
|
+
return lower !== null && lower === upper ? [`${of} == ${lower}`]
|
|
628
|
+
: [...lower === null ? [] : [`${of} >= ${lower}`], ...upper === null ? [] : [`${of} <= ${upper}`]];
|
|
629
|
+
};
|
|
630
|
+
return [
|
|
631
|
+
...types === undefined ? [] : [ofTypes(types, false)],
|
|
632
|
+
...unclassedTypes === undefined ? [] : [ofTypes(unclassedTypes, true)],
|
|
633
|
+
...values === undefined ? [] : [`${formal} ${partial ? 'pmatches' : 'in'} ${setOf(values.map(v => JSON.stringify(v)))}`],
|
|
634
|
+
...classes === undefined ? [] : [classes.length === 1 ? `inherits(${formal}, ${JSON.stringify(classes[0])})` : `inherits(${formal}, c(${classes.map(c => JSON.stringify(c)).join(', ')}))`],
|
|
635
|
+
...Object.entries(bounds ?? {}).filter(([measure]) => !onlyNull || measure !== 'length').flatMap(([measure, bound]) => range(measure, bound)),
|
|
636
|
+
...notNA && !onlyNull ? [`!anyNA(${formal})`] : [],
|
|
637
|
+
...callable ? [`is.function(match.fun(${formal}))`] : [],
|
|
638
|
+
...whole ? [`trunc(${formal}) == ${formal}`] : [],
|
|
639
|
+
...(resolves ?? []).map(r => `exists(${r.expression})`)
|
|
640
|
+
];
|
|
641
|
+
}
|
|
642
|
+
/** Reads a claim in a few words each, as a page or a terminal shows it. */
|
|
643
|
+
function claimWords(claim) {
|
|
644
|
+
const { types, unclassedTypes, values, partial, classes, bounds, notNA, callable, whole, resolves } = claim;
|
|
645
|
+
const range = (what, [lower, upper]) => lower !== null && lower === upper ? `${what} = ${lower}`
|
|
646
|
+
: [lower === null ? '' : `${what} >= ${lower}`, upper === null ? '' : `${what} <= ${upper}`].filter(w => w !== '').join(', ');
|
|
647
|
+
const onlyNull = types?.length === 1 && types[0] === 'NULL';
|
|
648
|
+
return [
|
|
649
|
+
types === undefined ? '' : typesInWords(types),
|
|
650
|
+
unclassedTypes === undefined ? '' : `${typesInWords(unclassedTypes)}, unless classed`,
|
|
651
|
+
values === undefined ? '' : `one of ${values.join(', ')}${partial ? ' (or a prefix)' : ''}`,
|
|
652
|
+
classes === undefined ? '' : `class ${listed(classes)}`,
|
|
653
|
+
...Object.entries(bounds ?? {}).filter(([measure]) => !onlyNull || measure !== 'length').map(([measure, bound]) => range(measure, bound)),
|
|
654
|
+
notNA ? 'not NA' : '',
|
|
655
|
+
callable ? 'callable' : '',
|
|
656
|
+
whole ? 'whole number' : '',
|
|
657
|
+
...(resolves ?? []).map(r => `${r.expression} exists`),
|
|
658
|
+
...shownCases(claim).map(([when, said, relations]) => `if ${when}: ${[...claimWords(said), ...relations].join(', ')}`)
|
|
659
|
+
].filter(w => w !== '');
|
|
660
|
+
}
|
|
661
|
+
/** The cases of a claim with what each adds to the claim itself, a relation already stated elsewhere left out, and no case that adds nothing. */
|
|
662
|
+
function shownCases({ cases, ...always }, stated = []) {
|
|
663
|
+
return (cases ?? []).map((c) => [c.when, claimBeyond(c.claim, always), (c.relations ?? []).map(r => r.holds).filter(h => !stated.includes(h))])
|
|
664
|
+
.filter(([, claim, relations]) => Object.keys(claim).length > 0 || relations.length > 0);
|
|
665
|
+
}
|
|
666
|
+
/** Each case of a claim as its condition and what holds in it, see {@link claimConditions}; `stated` are the relations said of the formals on their own. */
|
|
667
|
+
function caseConditions(formal, claim, stated = []) {
|
|
668
|
+
return shownCases(claim, stated).map(([when, said, relations]) => `if (${when}): ${(0, condition_grouping_1.allOf)([...claimConditions(formal, said), ...relations])}`);
|
|
669
|
+
}
|
|
670
|
+
/** What a call returns in a few words, see {@link claimWords}: what holds of it, and the formal it hands back. */
|
|
671
|
+
function returnWords(returns, passes) {
|
|
672
|
+
return [...passes === undefined ? [] : [`the value of ${passes}`], ...claimWords(returns ?? {})];
|
|
673
|
+
}
|
|
674
|
+
/** The same as {@link claimConditions}, of the value a call returns, named `result`. */
|
|
675
|
+
function returnConditions(returns, passes) {
|
|
676
|
+
return [...passes === undefined ? [] : [`identical(result, ${passes})`], ...claimConditions('result', returns ?? {})];
|
|
677
|
+
}
|
|
678
|
+
//# sourceMappingURL=guard-claims.js.map
|