@scriptc/compiler 0.3.1 → 0.3.3
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/ambient/scriptc-node-fallback.d.ts +832 -55
- package/dist/backend/cycle-analysis.js +6 -1
- package/dist/backend/cycle-analysis.js.map +1 -1
- package/dist/backend/executable-features.js +1 -0
- package/dist/backend/executable-features.js.map +1 -1
- package/dist/backend/literals.d.ts +7 -0
- package/dist/backend/literals.js +32 -0
- package/dist/backend/literals.js.map +1 -1
- package/dist/backend/literals.test.js +17 -1
- package/dist/backend/literals.test.js.map +1 -1
- package/dist/backend/llvm/alloc.d.ts +15 -4
- package/dist/backend/llvm/alloc.js +63 -25
- package/dist/backend/llvm/alloc.js.map +1 -1
- package/dist/backend/llvm/alloc.test.js +62 -2
- package/dist/backend/llvm/alloc.test.js.map +1 -1
- package/dist/backend/llvm/appended-array-literals.d.ts +2 -0
- package/dist/backend/llvm/appended-array-literals.js +109 -0
- package/dist/backend/llvm/appended-array-literals.js.map +1 -0
- package/dist/backend/llvm/appended-array-literals.test.d.ts +1 -0
- package/dist/backend/llvm/appended-array-literals.test.js +90 -0
- package/dist/backend/llvm/appended-array-literals.test.js.map +1 -0
- package/dist/backend/llvm/array-search.d.ts +8 -0
- package/dist/backend/llvm/array-search.js +52 -0
- package/dist/backend/llvm/array-search.js.map +1 -0
- package/dist/backend/llvm/array-search.test.d.ts +1 -0
- package/dist/backend/llvm/array-search.test.js +72 -0
- package/dist/backend/llvm/array-search.test.js.map +1 -0
- package/dist/backend/llvm/call-lifetimes.d.ts +11 -1
- package/dist/backend/llvm/call-lifetimes.js +74 -4
- package/dist/backend/llvm/call-lifetimes.js.map +1 -1
- package/dist/backend/llvm/call-lifetimes.test.js +54 -0
- package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/classes.js +97 -38
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +2 -2
- package/dist/backend/llvm/common.d.ts +1 -1
- package/dist/backend/llvm/common.js +1 -1
- package/dist/backend/llvm/dense-array-access.d.ts +5 -0
- package/dist/backend/llvm/dense-array-access.js +18 -13
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +15 -2
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +6 -0
- package/dist/backend/llvm/dyn.js +84 -11
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +108 -16
- package/dist/backend/llvm/emitter.js +598 -108
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +26 -3
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +174 -7
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.js +11 -0
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.d.ts +8 -0
- package/dist/backend/llvm/expr-callbacks.js +96 -2
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-calls.d.ts +12 -1
- package/dist/backend/llvm/expr-calls.js +133 -54
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.d.ts +7 -0
- package/dist/backend/llvm/expr-containers.js +80 -22
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +2 -0
- package/dist/backend/llvm/expr-control.d.ts +8 -0
- package/dist/backend/llvm/expr-control.js +103 -69
- package/dist/backend/llvm/expr-control.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +21 -10
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +7 -0
- package/dist/backend/llvm/expr-primitives.js +53 -51
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-records.js +19 -5
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.d.ts +8 -0
- package/dist/backend/llvm/expr-stream-bridges.js +111 -39
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js +49 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +13 -2
- package/dist/backend/llvm/expr-stream-callbacks.js +80 -5
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/inline-unions.d.ts +48 -0
- package/dist/backend/llvm/inline-unions.js +134 -0
- package/dist/backend/llvm/inline-unions.js.map +1 -0
- package/dist/backend/llvm/inline-unions.test.d.ts +1 -0
- package/dist/backend/llvm/inline-unions.test.js +124 -0
- package/dist/backend/llvm/inline-unions.test.js.map +1 -0
- package/dist/backend/llvm/int32-abi.d.ts +18 -2
- package/dist/backend/llvm/int32-abi.js +23 -2
- package/dist/backend/llvm/int32-abi.js.map +1 -1
- package/dist/backend/llvm/int32-abi.test.js +75 -1
- package/dist/backend/llvm/int32-abi.test.js.map +1 -1
- package/dist/backend/llvm/integer-remainder.d.ts +28 -5
- package/dist/backend/llvm/integer-remainder.js +80 -9
- package/dist/backend/llvm/integer-remainder.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +170 -28
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +181 -5
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +9 -6
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +2 -2
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +208 -9
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +97 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +12 -6
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.test.js +6 -3
- package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.d.ts +26 -2
- package/dist/backend/llvm/local-union-storage.js +132 -12
- package/dist/backend/llvm/local-union-storage.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.test.js +107 -1
- package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
- package/dist/backend/llvm/loop-array-borrows.d.ts +8 -2
- package/dist/backend/llvm/loop-array-borrows.js +93 -13
- package/dist/backend/llvm/loop-array-borrows.js.map +1 -1
- package/dist/backend/llvm/map-number-lookup.d.ts +20 -0
- package/dist/backend/llvm/map-number-lookup.js +66 -0
- package/dist/backend/llvm/map-number-lookup.js.map +1 -1
- package/dist/backend/llvm/map-number-lookup.test.d.ts +1 -0
- package/dist/backend/llvm/map-number-lookup.test.js +102 -0
- package/dist/backend/llvm/map-number-lookup.test.js.map +1 -0
- package/dist/backend/llvm/map-read-lifetimes.js +1 -0
- package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
- package/dist/backend/llvm/publish.d.ts +4 -0
- package/dist/backend/llvm/publish.js +3 -1
- package/dist/backend/llvm/publish.js.map +1 -1
- package/dist/backend/llvm/record-results.d.ts +29 -0
- package/dist/backend/llvm/record-results.js +260 -0
- package/dist/backend/llvm/record-results.js.map +1 -0
- package/dist/backend/llvm/reference-effects.js +15 -0
- package/dist/backend/llvm/reference-effects.js.map +1 -1
- package/dist/backend/llvm/reference-writes.js +29 -9
- package/dist/backend/llvm/reference-writes.js.map +1 -1
- package/dist/backend/llvm/regions.d.ts +68 -0
- package/dist/backend/llvm/regions.js +314 -0
- package/dist/backend/llvm/regions.js.map +1 -0
- package/dist/backend/llvm/regions.test.d.ts +1 -0
- package/dist/backend/llvm/regions.test.js +173 -0
- package/dist/backend/llvm/regions.test.js.map +1 -0
- package/dist/backend/llvm/serialized-ir-emission.test.js +2 -0
- package/dist/backend/llvm/serialized-ir-emission.test.js.map +1 -1
- package/dist/backend/llvm/shapes.d.ts +86 -13
- package/dist/backend/llvm/shapes.js +208 -54
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/shapes.test.js +68 -9
- package/dist/backend/llvm/shapes.test.js.map +1 -1
- package/dist/backend/llvm/split-loops.js +1 -1
- package/dist/backend/llvm/split-loops.js.map +1 -1
- package/dist/backend/llvm/stack-objects.d.ts +29 -0
- package/dist/backend/llvm/stack-objects.js +142 -0
- package/dist/backend/llvm/stack-objects.js.map +1 -0
- package/dist/backend/llvm/stack-objects.test.d.ts +1 -0
- package/dist/backend/llvm/stack-objects.test.js +255 -0
- package/dist/backend/llvm/stack-objects.test.js.map +1 -0
- package/dist/backend/llvm/string-reads.d.ts +4 -1
- package/dist/backend/llvm/string-reads.js +89 -9
- package/dist/backend/llvm/string-reads.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.js +5 -4
- package/dist/backend/llvm/switch-dispatch.js.map +1 -1
- package/dist/backend/llvm/walkers.d.ts +13 -0
- package/dist/backend/llvm/walkers.js +108 -10
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/may-throw.js +10 -4
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/native/contracts.d.ts +7 -2
- package/dist/backend/native/executable.js +28 -2
- package/dist/backend/native/executable.js.map +1 -1
- package/dist/backend/native/library.js +1 -1
- package/dist/backend/native/library.js.map +1 -1
- package/dist/backend/native/runtime-inputs.d.ts +1 -1
- package/dist/backend/native/runtime-inputs.js +3 -0
- package/dist/backend/native/runtime-inputs.js.map +1 -1
- package/dist/backend/native-link-info-core.d.ts +1 -0
- package/dist/backend/native-link-info-core.js.map +1 -1
- package/dist/backend/native-toolchain.test.js +1 -1
- package/dist/backend/native-toolchain.test.js.map +1 -1
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-core.d.ts +1 -0
- package/dist/backend/runtime-pack-core.js +1 -0
- package/dist/backend/runtime-pack-core.js.map +1 -1
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack.test.js +1 -1
- package/dist/backend/target-diagnostics.js +17 -0
- package/dist/backend/target-diagnostics.js.map +1 -1
- package/dist/backend/target-diagnostics.test.js +16 -0
- package/dist/backend/target-diagnostics.test.js.map +1 -1
- package/dist/compat/fetch-profile.js +4 -4
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/contracts/check.js +2 -0
- package/dist/contracts/check.js.map +1 -1
- package/dist/coverage/report.js +1 -1
- package/dist/coverage/report.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +6 -5
- package/dist/diagnostics/diagnostic.js +7 -6
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +1 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/frontend/builtin-modules.d.ts +1 -1
- package/dist/frontend/builtin-modules.js +1 -0
- package/dist/frontend/builtin-modules.js.map +1 -1
- package/dist/frontend/comptime-node.js +2 -2
- package/dist/frontend/comptime-node.js.map +1 -1
- package/dist/frontend/experimental-import.d.ts +12 -0
- package/dist/frontend/experimental-import.js +63 -0
- package/dist/frontend/experimental-import.js.map +1 -0
- package/dist/frontend/lowering/binding-analysis.d.ts +1 -1
- package/dist/frontend/lowering/binding-analysis.js +1 -1
- package/dist/frontend/lowering/builtin-calls.d.ts +6 -1
- package/dist/frontend/lowering/builtin-calls.js +36 -0
- package/dist/frontend/lowering/builtin-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/arguments.d.ts +4 -0
- package/dist/frontend/lowering/builtins/arguments.js +8 -4
- package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
- package/dist/frontend/lowering/builtins/blob.d.ts +20 -0
- package/dist/frontend/lowering/builtins/blob.js +167 -0
- package/dist/frontend/lowering/builtins/blob.js.map +1 -0
- package/dist/frontend/lowering/builtins/child-process-async.d.ts +2 -2
- package/dist/frontend/lowering/builtins/child-process-async.js +2 -2
- package/dist/frontend/lowering/builtins/child-process-methods.js +1 -1
- package/dist/frontend/lowering/builtins/child-process-methods.js.map +1 -1
- package/dist/frontend/lowering/builtins/child-process-sync.js +1 -1
- package/dist/frontend/lowering/builtins/child-process-sync.js.map +1 -1
- package/dist/frontend/lowering/builtins/compression.js +3 -2
- package/dist/frontend/lowering/builtins/compression.js.map +1 -1
- package/dist/frontend/lowering/builtins/console.d.ts +16 -6
- package/dist/frontend/lowering/builtins/console.js +33 -9
- package/dist/frontend/lowering/builtins/console.js.map +1 -1
- package/dist/frontend/lowering/builtins/crypto.js +415 -120
- package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
- package/dist/frontend/lowering/builtins/errors.js +20 -0
- package/dist/frontend/lowering/builtins/errors.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.d.ts +10 -0
- package/dist/frontend/lowering/builtins/filesystem-calls.js +89 -1
- package/dist/frontend/lowering/builtins/filesystem-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/filesystem.d.ts +16 -7
- package/dist/frontend/lowering/builtins/filesystem.js +97 -15
- package/dist/frontend/lowering/builtins/filesystem.js.map +1 -1
- package/dist/frontend/lowering/builtins/fs-glob.d.ts +23 -0
- package/dist/frontend/lowering/builtins/fs-glob.js +224 -0
- package/dist/frontend/lowering/builtins/fs-glob.js.map +1 -0
- package/dist/frontend/lowering/builtins/json.d.ts +2 -2
- package/dist/frontend/lowering/builtins/json.js +13 -4
- package/dist/frontend/lowering/builtins/json.js.map +1 -1
- package/dist/frontend/lowering/builtins/key-object.d.ts +13 -0
- package/dist/frontend/lowering/builtins/key-object.js +56 -0
- package/dist/frontend/lowering/builtins/key-object.js.map +1 -0
- package/dist/frontend/lowering/builtins/module-calls.js +60 -12
- package/dist/frontend/lowering/builtins/module-calls.js.map +1 -1
- package/dist/frontend/lowering/builtins/numbers.d.ts +1 -0
- package/dist/frontend/lowering/builtins/numbers.js +17 -0
- package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
- package/dist/frontend/lowering/builtins/operating-system.d.ts +18 -0
- package/dist/frontend/lowering/builtins/operating-system.js +361 -1
- package/dist/frontend/lowering/builtins/operating-system.js.map +1 -1
- package/dist/frontend/lowering/builtins/performance.d.ts +25 -3
- package/dist/frontend/lowering/builtins/performance.js +340 -5
- package/dist/frontend/lowering/builtins/performance.js.map +1 -1
- package/dist/frontend/lowering/builtins/process.d.ts +2 -2
- package/dist/frontend/lowering/builtins/process.js +122 -17
- package/dist/frontend/lowering/builtins/process.js.map +1 -1
- package/dist/frontend/lowering/builtins/promises.js +109 -2
- package/dist/frontend/lowering/builtins/promises.js.map +1 -1
- package/dist/frontend/lowering/builtins/properties.d.ts +0 -7
- package/dist/frontend/lowering/builtins/properties.js +39 -11
- package/dist/frontend/lowering/builtins/properties.js.map +1 -1
- package/dist/frontend/lowering/builtins/readline.d.ts +23 -8
- package/dist/frontend/lowering/builtins/readline.js +266 -90
- package/dist/frontend/lowering/builtins/readline.js.map +1 -1
- package/dist/frontend/lowering/builtins/text-codecs.d.ts +3 -4
- package/dist/frontend/lowering/builtins/text-codecs.js +3 -4
- package/dist/frontend/lowering/builtins/text-codecs.js.map +1 -1
- package/dist/frontend/lowering/builtins/url.d.ts +8 -0
- package/dist/frontend/lowering/builtins/url.js +36 -0
- package/dist/frontend/lowering/builtins/url.js.map +1 -1
- package/dist/frontend/lowering/call-arguments.js +1 -1
- package/dist/frontend/lowering/call-arguments.js.map +1 -1
- package/dist/frontend/lowering/call-signatures.js +20 -2
- package/dist/frontend/lowering/call-signatures.js.map +1 -1
- package/dist/frontend/lowering/checked-promise-all.d.ts +10 -3
- package/dist/frontend/lowering/checked-promise-all.js +52 -6
- package/dist/frontend/lowering/checked-promise-all.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +8 -3
- package/dist/frontend/lowering/class-dynamic-dispatch.js +159 -32
- package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
- package/dist/frontend/lowering/class-dynamic-dispatch.test.js +1 -0
- package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
- package/dist/frontend/lowering/class-protocol-dispatch.d.ts +45 -0
- package/dist/frontend/lowering/class-protocol-dispatch.js +516 -0
- package/dist/frontend/lowering/class-protocol-dispatch.js.map +1 -0
- package/dist/frontend/lowering/coercions/structural-plans.js +2 -1
- package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
- package/dist/frontend/lowering/coercions/structural.js +3 -3
- package/dist/frontend/lowering/coercions/structural.js.map +1 -1
- package/dist/frontend/lowering/collation-repertoire.js +6 -5
- package/dist/frontend/lowering/collation-repertoire.js.map +1 -1
- package/dist/frontend/lowering/containers/array-callbacks.js +33 -6
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-construction.js +8 -4
- package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
- package/dist/frontend/lowering/containers/array-methods.d.ts +0 -7
- package/dist/frontend/lowering/containers/array-methods.js +43 -2
- package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
- package/dist/frontend/lowering/containers/array-pipelines.js +1 -1
- package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.js +38 -26
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/containers/for-of.d.ts +1 -1
- package/dist/frontend/lowering/containers/for-of.js +5 -1
- package/dist/frontend/lowering/containers/for-of.js.map +1 -1
- package/dist/frontend/lowering/containers/indexed-objects.js +1 -1
- package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
- package/dist/frontend/lowering/containers/string-and-regexp.js +91 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/crypto-tables.d.ts +3 -3
- package/dist/frontend/lowering/crypto-tables.js +77 -12
- package/dist/frontend/lowering/crypto-tables.js.map +1 -1
- package/dist/frontend/lowering/cycle-initialization.d.ts +18 -2
- package/dist/frontend/lowering/cycle-initialization.js +166 -12
- package/dist/frontend/lowering/cycle-initialization.js.map +1 -1
- package/dist/frontend/lowering/deferred-module-initializers.js +7 -2
- package/dist/frontend/lowering/deferred-module-initializers.js.map +1 -1
- package/dist/frontend/lowering/deferred-module-initializers.test.js +28 -0
- package/dist/frontend/lowering/deferred-module-initializers.test.js.map +1 -1
- package/dist/frontend/lowering/expressions/nullish-assignment.js +10 -0
- package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
- package/dist/frontend/lowering/expressions/object-literals.js +21 -68
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
- package/dist/frontend/lowering/generator-delegation.d.ts +8 -0
- package/dist/frontend/lowering/generator-delegation.js +231 -10
- package/dist/frontend/lowering/generator-delegation.js.map +1 -1
- package/dist/frontend/lowering/generic-functions.d.ts +2 -2
- package/dist/frontend/lowering/generic-functions.js +2 -2
- package/dist/frontend/lowering/generic-functions.js.map +1 -1
- package/dist/frontend/lowering/http2-constants.js +1 -1
- package/dist/frontend/lowering/lifetime-regions.d.ts +11 -0
- package/dist/frontend/lowering/lifetime-regions.js +216 -0
- package/dist/frontend/lowering/lifetime-regions.js.map +1 -0
- package/dist/frontend/lowering/lower-array-sort.d.ts +40 -3
- package/dist/frontend/lowering/lower-array-sort.js +661 -194
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.test.js +103 -4
- package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +2 -2
- package/dist/frontend/lowering/lower-async-iteration.d.ts +6 -3
- package/dist/frontend/lowering/lower-async-iteration.js +248 -2
- package/dist/frontend/lowering/lower-async-iteration.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +173 -111
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +12 -5
- package/dist/frontend/lowering/lower-classes.js +156 -11
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.d.ts +1 -1
- package/dist/frontend/lowering/lower-comptime.js +4 -4
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-console.d.ts +13 -0
- package/dist/frontend/lowering/lower-console.js +460 -4
- package/dist/frontend/lowering/lower-console.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.d.ts +6 -0
- package/dist/frontend/lowering/lower-event-emitter.js +124 -38
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-event-target.d.ts +63 -0
- package/dist/frontend/lowering/lower-event-target.js +362 -0
- package/dist/frontend/lowering/lower-event-target.js.map +1 -0
- package/dist/frontend/lowering/lower-expando.js +2 -2
- package/dist/frontend/lowering/lower-exprs.js +247 -42
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +15 -7
- package/dist/frontend/lowering/lower-generators.js +183 -99
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +8 -1
- package/dist/frontend/lowering/lower-inspect.js +247 -28
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.js +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +1 -1
- package/dist/frontend/lowering/lower-modules.js +27 -17
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.d.ts +2 -2
- package/dist/frontend/lowering/lower-namespaces.js +2 -2
- package/dist/frontend/lowering/lower-server.js +39 -14
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stdlib.d.ts +11 -1
- package/dist/frontend/lowering/lower-stdlib.js +45 -4
- package/dist/frontend/lowering/lower-stdlib.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +2 -2
- package/dist/frontend/lowering/lower-stmts.js +112 -23
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.js +234 -22
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-timers.js +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +45 -6
- package/dist/frontend/lowering/lowerer.js +360 -48
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/native-ffi.js +2 -2
- package/dist/frontend/lowering/native-ffi.js.map +1 -1
- package/dist/frontend/lowering/regex-span-reads.d.ts +12 -0
- package/dist/frontend/lowering/regex-span-reads.js +164 -0
- package/dist/frontend/lowering/regex-span-reads.js.map +1 -0
- package/dist/frontend/lowering/runtime-optional-records.d.ts +115 -0
- package/dist/frontend/lowering/runtime-optional-records.js +715 -0
- package/dist/frontend/lowering/runtime-optional-records.js.map +1 -0
- package/dist/frontend/lowering/runtime-optional-records.test.d.ts +1 -0
- package/dist/frontend/lowering/runtime-optional-records.test.js +175 -0
- package/dist/frontend/lowering/runtime-optional-records.test.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +7 -3
- package/dist/frontend/lowering/surfaces.js +385 -32
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/var-hoisting.d.ts +3 -0
- package/dist/frontend/lowering/var-hoisting.js +261 -0
- package/dist/frontend/lowering/var-hoisting.js.map +1 -0
- package/dist/frontend/module-syntax.d.ts +1 -1
- package/dist/frontend/module-syntax.js +1 -1
- package/dist/frontend/npm-static-prune.js +1 -1
- package/dist/frontend/npm-static-prune.js.map +1 -1
- package/dist/frontend/npm-static-rewrite-syntax.js +4 -3
- package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -1
- package/dist/frontend/pipeline.js +6 -4
- package/dist/frontend/pipeline.js.map +1 -1
- package/dist/frontend/program.d.ts +6 -5
- package/dist/frontend/program.js +42 -22
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/program.test.js +13 -0
- package/dist/frontend/program.test.js.map +1 -1
- package/dist/frontend/resolve.js +1 -1
- package/dist/frontend/ts7/adapter.js +1 -1
- package/dist/frontend/ts7/ast-bytes.d.ts +1 -1
- package/dist/frontend/ts7/ast-bytes.js +1 -1
- package/dist/frontend/ts7/semantic-json.d.ts +1 -1
- package/dist/frontend/ts7/semantic-json.js +1 -1
- package/dist/frontend/ts7/semantic-json.js.map +1 -1
- package/dist/frontend/ts7/world-check.js +1 -1
- package/dist/frontend/tsc-codes.js +2 -2
- package/dist/frontend/tsc-codes.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +28 -1
- package/dist/frontend/type-mapper.js +288 -30
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +12 -6
- package/dist/ir/analysis.js +26 -10
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/analysis.test.js +15 -3
- package/dist/ir/analysis.test.js.map +1 -1
- package/dist/ir/builtin-effects.js +108 -2
- package/dist/ir/builtin-effects.js.map +1 -1
- package/dist/ir/builtin-signatures.d.ts +1 -1
- package/dist/ir/builtin-signatures.js +436 -53
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/function-references.test.js +1 -0
- package/dist/ir/function-references.test.js.map +1 -1
- package/dist/ir/int32-slots.js +2 -0
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/intrinsic-signatures.js +2 -0
- package/dist/ir/intrinsic-signatures.js.map +1 -1
- package/dist/ir/ir.d.ts +129 -36
- package/dist/ir/ir.js +42 -1
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/runtime-features.d.ts +1 -0
- package/dist/ir/runtime-features.js +116 -5
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/scalar-records.js +1 -2
- package/dist/ir/scalar-records.js.map +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/traverse.js +1 -0
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/validate.js +250 -34
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +125 -0
- package/dist/ir/validate.test.js.map +1 -1
- package/dist/library/fence-eval.d.ts +1 -1
- package/dist/library/fence-eval.js +5 -4
- package/dist/library/fence-eval.js.map +1 -1
- package/dist/library/ir-policy.js +11 -4
- package/dist/library/ir-policy.js.map +1 -1
- package/dist/library/library-profile.js +13 -13
- package/dist/library/library-profile.js.map +1 -1
- package/dist/library/prepare.js +1 -1
- package/dist/library/prepare.js.map +1 -1
- package/dist/library/sidecar.js +3 -3
- package/dist/library/sidecar.js.map +1 -1
- package/dist/native/prepare.js +3 -2
- package/dist/native/prepare.js.map +1 -1
- package/dist/native/sanitizer.test.js +1 -0
- package/dist/native/sanitizer.test.js.map +1 -1
- package/package.json +20 -20
- package/surface-manifest.json +537 -142
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import * as ts from "../ts7/adapter.js";
|
|
2
|
+
/** Calls that read a record without keeping or converting it. */
|
|
3
|
+
const READING_CALLS = new Map([
|
|
4
|
+
["console", new Set(["log", "info", "warn", "error", "debug", "dir"])],
|
|
5
|
+
["JSON", new Set(["stringify"])],
|
|
6
|
+
["Object", new Set(["keys", "values", "entries", "hasOwn", "getOwnPropertyNames"])],
|
|
7
|
+
["Reflect", new Set(["has", "ownKeys"])],
|
|
8
|
+
["Array", new Set(["isArray"])],
|
|
9
|
+
]);
|
|
10
|
+
/** Method names the runtime calls without a visible call site. */
|
|
11
|
+
const PROTOCOL_METHODS = new Set([
|
|
12
|
+
"handleEvent",
|
|
13
|
+
"toJSON",
|
|
14
|
+
"toString",
|
|
15
|
+
"toLocaleString",
|
|
16
|
+
"valueOf",
|
|
17
|
+
"then",
|
|
18
|
+
"next",
|
|
19
|
+
"return",
|
|
20
|
+
"throw",
|
|
21
|
+
]);
|
|
22
|
+
/** Global functions that read a record without keeping it. */
|
|
23
|
+
const READING_FUNCTIONS = new Set(["String", "structuredClone"]);
|
|
24
|
+
/** Record values that flow between local bindings, the parameters and the
|
|
25
|
+
* returns of functions whose every call site is visible, grouped into
|
|
26
|
+
* classes that must share one layout. Widening a record field to hold
|
|
27
|
+
* undefined changes the layout, so a class can take the widened layout only
|
|
28
|
+
* when it is closed: every value entering it is a fresh object literal or
|
|
29
|
+
* comes from another member, every use of a member reads or writes its
|
|
30
|
+
* fields, passes it to another member, or only inspects it, and every
|
|
31
|
+
* member declares the same shape. A record that reaches any other storage
|
|
32
|
+
* keeps the declared layout, since converting it there would copy the
|
|
33
|
+
* object. */
|
|
34
|
+
export class RecordFlowClasses {
|
|
35
|
+
files;
|
|
36
|
+
host;
|
|
37
|
+
parent = [];
|
|
38
|
+
open = [];
|
|
39
|
+
/** The declaration each slot reads its shape from: a binding or
|
|
40
|
+
* parameter name, or a function for its result. */
|
|
41
|
+
slotNodes = [];
|
|
42
|
+
slotReturns = [];
|
|
43
|
+
shapeChecked = new Map();
|
|
44
|
+
bindingSlots = new Map();
|
|
45
|
+
returnSlots = new Map();
|
|
46
|
+
/** Visible functions by symbol: plain declarations called only by name,
|
|
47
|
+
* and methods whose dispatch slot only direct calls reach. */
|
|
48
|
+
functions = new Map();
|
|
49
|
+
/** Members sharing each visible method's dispatch slot. */
|
|
50
|
+
families = new Map();
|
|
51
|
+
/** String keys of `x["name"]` accesses. */
|
|
52
|
+
literalKeys = new Set();
|
|
53
|
+
/** Identifiers by name; symbols resolve only for the names of slots and
|
|
54
|
+
* functions, so the scan asks the checker about few nodes. */
|
|
55
|
+
names = new Map();
|
|
56
|
+
references = new Map();
|
|
57
|
+
/** Names written as shorthand properties (`{ p }`): the checker resolves
|
|
58
|
+
* those to the property, so a binding of that name stays open. */
|
|
59
|
+
shorthandNames = new Set();
|
|
60
|
+
constructor(files, host) {
|
|
61
|
+
this.files = files;
|
|
62
|
+
this.host = host;
|
|
63
|
+
this.index();
|
|
64
|
+
this.collectFunctions();
|
|
65
|
+
this.collectSlots();
|
|
66
|
+
this.connect();
|
|
67
|
+
}
|
|
68
|
+
/** The class id of a binding or parameter slot, or null when the symbol
|
|
69
|
+
* is not a tracked record slot. */
|
|
70
|
+
bindingClass(symbol) {
|
|
71
|
+
const slot = this.bindingSlots.get(symbol);
|
|
72
|
+
return slot === undefined ? null : this.find(slot);
|
|
73
|
+
}
|
|
74
|
+
/** The binding or parameter is in a class that reaches other storage. */
|
|
75
|
+
opened(symbol) {
|
|
76
|
+
const slot = this.bindingSlots.get(symbol);
|
|
77
|
+
return slot !== undefined && this.open[this.find(slot)];
|
|
78
|
+
}
|
|
79
|
+
/** Every tracked binding and parameter with its class id. */
|
|
80
|
+
bindings() {
|
|
81
|
+
const out = [];
|
|
82
|
+
for (const [symbol, slot] of this.bindingSlots)
|
|
83
|
+
out.push([symbol, this.find(slot)]);
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** Every tracked parameter: its symbol, function and position. */
|
|
87
|
+
parameters() {
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const [fn, decl] of this.functions) {
|
|
90
|
+
for (let index = 0; index < decl.parameters.length; index++) {
|
|
91
|
+
const symbol = this.host.symbolOf(decl.parameters[index].name);
|
|
92
|
+
if (symbol && this.bindingSlots.has(symbol))
|
|
93
|
+
out.push({ symbol, fn, index });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** The class id of a visible function's record return, or null. */
|
|
99
|
+
returnClass(symbol) {
|
|
100
|
+
const slot = this.returnSlots.get(symbol);
|
|
101
|
+
return slot === undefined ? null : this.find(slot);
|
|
102
|
+
}
|
|
103
|
+
/** The declaration of a visible function or method, whose parameters
|
|
104
|
+
* and return are tracked slots. */
|
|
105
|
+
visibleFunction(symbol) {
|
|
106
|
+
return this.functions.get(symbol);
|
|
107
|
+
}
|
|
108
|
+
/** A class can take a widened layout: nothing outside it reaches its
|
|
109
|
+
* members and they all declare one record shape. */
|
|
110
|
+
closed(classId) {
|
|
111
|
+
const root = this.find(classId);
|
|
112
|
+
if (this.open[root])
|
|
113
|
+
return false;
|
|
114
|
+
const cached = this.shapeChecked.get(root);
|
|
115
|
+
if (cached !== undefined)
|
|
116
|
+
return cached;
|
|
117
|
+
let shape;
|
|
118
|
+
let uniform = true;
|
|
119
|
+
for (let slot = 0; slot < this.parent.length && uniform; slot++) {
|
|
120
|
+
if (this.find(slot) !== root)
|
|
121
|
+
continue;
|
|
122
|
+
const node = this.slotNodes[slot];
|
|
123
|
+
const own = this.slotReturns[slot]
|
|
124
|
+
? this.host.returnShape(node)
|
|
125
|
+
: this.host.recordShape(node);
|
|
126
|
+
// Members of different shapes convert between each other.
|
|
127
|
+
if (own === null || (shape !== undefined && own !== shape))
|
|
128
|
+
uniform = false;
|
|
129
|
+
shape = own;
|
|
130
|
+
}
|
|
131
|
+
this.shapeChecked.set(root, uniform);
|
|
132
|
+
return uniform;
|
|
133
|
+
}
|
|
134
|
+
newSlot(node, isReturn = false) {
|
|
135
|
+
const id = this.parent.length;
|
|
136
|
+
this.parent.push(id);
|
|
137
|
+
this.open.push(false);
|
|
138
|
+
this.slotNodes.push(node);
|
|
139
|
+
this.slotReturns.push(isReturn);
|
|
140
|
+
return id;
|
|
141
|
+
}
|
|
142
|
+
find(slot) {
|
|
143
|
+
let root = slot;
|
|
144
|
+
while (this.parent[root] !== root)
|
|
145
|
+
root = this.parent[root];
|
|
146
|
+
while (this.parent[slot] !== root) {
|
|
147
|
+
const next = this.parent[slot];
|
|
148
|
+
this.parent[slot] = root;
|
|
149
|
+
slot = next;
|
|
150
|
+
}
|
|
151
|
+
return root;
|
|
152
|
+
}
|
|
153
|
+
union(a, b) {
|
|
154
|
+
const ra = this.find(a);
|
|
155
|
+
const rb = this.find(b);
|
|
156
|
+
if (ra === rb)
|
|
157
|
+
return;
|
|
158
|
+
this.parent[rb] = ra;
|
|
159
|
+
this.open[ra] = this.open[ra] || this.open[rb];
|
|
160
|
+
}
|
|
161
|
+
markOpen(slot) {
|
|
162
|
+
this.open[this.find(slot)] = true;
|
|
163
|
+
}
|
|
164
|
+
index() {
|
|
165
|
+
for (const file of this.files) {
|
|
166
|
+
ts.walkPreorder(file, (node) => {
|
|
167
|
+
if (ts.isElementAccessExpression(node)) {
|
|
168
|
+
const key = peel(node.argumentExpression);
|
|
169
|
+
if (ts.isStringLiteral(key) || ts.isNoSubstitutionTemplateLiteral(key))
|
|
170
|
+
this.literalKeys.add(key.text);
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
if (!ts.isIdentifier(node))
|
|
174
|
+
return undefined;
|
|
175
|
+
if (node.parent && ts.isShorthandPropertyAssignment(node.parent))
|
|
176
|
+
this.shorthandNames.add(node.text);
|
|
177
|
+
const list = this.names.get(node.text);
|
|
178
|
+
if (list)
|
|
179
|
+
list.push(node);
|
|
180
|
+
else
|
|
181
|
+
this.names.set(node.text, [node]);
|
|
182
|
+
return undefined;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** The identifiers that name `symbol`, its declaration included. */
|
|
187
|
+
referencesOf(symbol) {
|
|
188
|
+
let list = this.references.get(symbol);
|
|
189
|
+
if (!list) {
|
|
190
|
+
list = (this.names.get(symbol.name) ?? []).filter((node) => this.host.symbolOf(node) === symbol);
|
|
191
|
+
this.references.set(symbol, list);
|
|
192
|
+
}
|
|
193
|
+
return list;
|
|
194
|
+
}
|
|
195
|
+
collectFunctions() {
|
|
196
|
+
for (const file of this.files) {
|
|
197
|
+
if (file.isDeclarationFile || isJsFile(file))
|
|
198
|
+
continue;
|
|
199
|
+
ts.walkPreorder(file, (node) => {
|
|
200
|
+
if (!ts.isFunctionDeclaration(node) || !node.name || !node.body)
|
|
201
|
+
return undefined;
|
|
202
|
+
if (node.asteriskToken || node.typeParameters?.length)
|
|
203
|
+
return undefined;
|
|
204
|
+
const flags = ts.getCombinedModifierFlags(node);
|
|
205
|
+
if (flags & (ts.ModifierFlags.Export | ts.ModifierFlags.Async | ts.ModifierFlags.Ambient))
|
|
206
|
+
return undefined;
|
|
207
|
+
if (node.parameters.some((p) => p.dotDotDotToken || !ts.isIdentifier(p.name)))
|
|
208
|
+
return undefined;
|
|
209
|
+
if (usesArguments(node.body))
|
|
210
|
+
return undefined;
|
|
211
|
+
const symbol = this.host.symbolOf(node.name);
|
|
212
|
+
if (!symbol || (symbol.declarations?.length ?? 0) !== 1)
|
|
213
|
+
return undefined;
|
|
214
|
+
const calledByName = this.referencesOf(symbol).every((reference) => {
|
|
215
|
+
if (reference === node.name)
|
|
216
|
+
return true;
|
|
217
|
+
const call = reference.parent;
|
|
218
|
+
return (!!call &&
|
|
219
|
+
ts.isCallExpression(call) &&
|
|
220
|
+
call.expression === reference &&
|
|
221
|
+
!call.arguments.some(ts.isSpreadElement));
|
|
222
|
+
});
|
|
223
|
+
if (calledByName) {
|
|
224
|
+
this.functions.set(symbol, node);
|
|
225
|
+
this.families.set(symbol, [symbol]);
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
this.collectMethods();
|
|
231
|
+
}
|
|
232
|
+
/** Methods whose every member is a plain body and whose name no other
|
|
233
|
+
* declaration, dynamic access or literal key shares: then every call that
|
|
234
|
+
* can dispatch to the slot names a member directly. */
|
|
235
|
+
/** The class extends, directly or through its bases, a class not
|
|
236
|
+
* declared in the program's own sources. */
|
|
237
|
+
extendsForeignClass(decl) {
|
|
238
|
+
const seen = new Set();
|
|
239
|
+
let current = decl;
|
|
240
|
+
for (;;) {
|
|
241
|
+
if (seen.has(current))
|
|
242
|
+
return true;
|
|
243
|
+
seen.add(current);
|
|
244
|
+
const heritage = current.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword);
|
|
245
|
+
const base = heritage?.types[0]?.expression;
|
|
246
|
+
if (!base)
|
|
247
|
+
return false;
|
|
248
|
+
const symbol = ts.isIdentifier(base) ? this.host.symbolOf(base) : null;
|
|
249
|
+
const target = symbol ? this.host.declarationOf(symbol) : undefined;
|
|
250
|
+
if (!target || !ts.isClassDeclaration(target))
|
|
251
|
+
return true;
|
|
252
|
+
const file = target.getSourceFile();
|
|
253
|
+
if (file.isDeclarationFile || isJsFile(file))
|
|
254
|
+
return true;
|
|
255
|
+
current = target;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
collectMethods() {
|
|
259
|
+
const candidates = new Map();
|
|
260
|
+
for (const file of this.files) {
|
|
261
|
+
if (file.isDeclarationFile || isJsFile(file))
|
|
262
|
+
continue;
|
|
263
|
+
ts.walkPreorder(file, (node) => {
|
|
264
|
+
if (!ts.isMethodDeclaration(node) || !ts.isIdentifier(node.name) || !node.body)
|
|
265
|
+
return undefined;
|
|
266
|
+
const owner = node.parent;
|
|
267
|
+
if (!owner || !ts.isClassDeclaration(owner))
|
|
268
|
+
return undefined;
|
|
269
|
+
if (ts.getCombinedModifierFlags(owner) &
|
|
270
|
+
(ts.ModifierFlags.Export | ts.ModifierFlags.Ambient))
|
|
271
|
+
return undefined;
|
|
272
|
+
// The runtime calls protocol methods and the overrides of its own
|
|
273
|
+
// classes (`_read`, `handleEvent`) with no call site to see.
|
|
274
|
+
if (PROTOCOL_METHODS.has(node.name.text) || this.extendsForeignClass(owner))
|
|
275
|
+
return undefined;
|
|
276
|
+
if (node.asteriskToken || node.typeParameters?.length)
|
|
277
|
+
return undefined;
|
|
278
|
+
if (ts.getCombinedModifierFlags(node) &
|
|
279
|
+
(ts.ModifierFlags.Async | ts.ModifierFlags.Abstract))
|
|
280
|
+
return undefined;
|
|
281
|
+
if (node.parameters.some((p) => p.dotDotDotToken || !ts.isIdentifier(p.name)))
|
|
282
|
+
return undefined;
|
|
283
|
+
if (usesArguments(node.body))
|
|
284
|
+
return undefined;
|
|
285
|
+
const symbol = this.host.symbolOf(node.name);
|
|
286
|
+
if (symbol && (symbol.declarations?.length ?? 0) === 1)
|
|
287
|
+
candidates.set(symbol, node);
|
|
288
|
+
return undefined;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const decided = new Set();
|
|
292
|
+
for (const [symbol, decl] of candidates) {
|
|
293
|
+
if (decided.has(symbol))
|
|
294
|
+
continue;
|
|
295
|
+
const family = this.host.familyOf(symbol) ?? [symbol];
|
|
296
|
+
for (const member of family)
|
|
297
|
+
decided.add(member);
|
|
298
|
+
if (!family.every((member) => candidates.has(member)))
|
|
299
|
+
continue;
|
|
300
|
+
const name = decl.name.text;
|
|
301
|
+
if (this.literalKeys.has(name))
|
|
302
|
+
continue;
|
|
303
|
+
const members = new Set(family);
|
|
304
|
+
const direct = (this.names.get(name) ?? []).every((id) => {
|
|
305
|
+
const parent = id.parent;
|
|
306
|
+
const owner = this.host.symbolOf(id);
|
|
307
|
+
if (owner && members.has(owner)) {
|
|
308
|
+
if (parent && ts.isMethodDeclaration(parent) && parent.name === id)
|
|
309
|
+
return true;
|
|
310
|
+
const call = parent?.parent;
|
|
311
|
+
return (!!parent &&
|
|
312
|
+
ts.isPropertyAccessExpression(parent) &&
|
|
313
|
+
parent.name === id &&
|
|
314
|
+
!!call &&
|
|
315
|
+
ts.isCallExpression(call) &&
|
|
316
|
+
call.expression === parent &&
|
|
317
|
+
!call.arguments.some(ts.isSpreadElement));
|
|
318
|
+
}
|
|
319
|
+
// Any other member, property or key of this name could reach the
|
|
320
|
+
// slot through a structural or dynamic view of an instance.
|
|
321
|
+
return !parent || !isMemberName(id, parent);
|
|
322
|
+
});
|
|
323
|
+
if (!direct)
|
|
324
|
+
continue;
|
|
325
|
+
for (const member of family) {
|
|
326
|
+
this.functions.set(member, candidates.get(member));
|
|
327
|
+
this.families.set(member, family);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
collectSlots() {
|
|
332
|
+
const names = [];
|
|
333
|
+
for (const file of this.files) {
|
|
334
|
+
if (file.isDeclarationFile || isJsFile(file))
|
|
335
|
+
continue;
|
|
336
|
+
ts.walkPreorder(file, (node) => {
|
|
337
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name))
|
|
338
|
+
names.push(node.name);
|
|
339
|
+
return undefined;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
// The scan runs before reachability is known, so it asks about bodies
|
|
343
|
+
// lowering may skip; one batch answers them.
|
|
344
|
+
this.host.prefetchTypes(names);
|
|
345
|
+
for (const name of names) {
|
|
346
|
+
if (!this.host.mayBeRecord(name))
|
|
347
|
+
continue;
|
|
348
|
+
const symbol = this.host.symbolOf(name);
|
|
349
|
+
if (symbol)
|
|
350
|
+
this.bindingSlots.set(symbol, this.newSlot(name));
|
|
351
|
+
}
|
|
352
|
+
for (const [symbol, decl] of this.functions) {
|
|
353
|
+
for (const parameter of decl.parameters) {
|
|
354
|
+
if (!this.host.mayBeRecord(parameter.name))
|
|
355
|
+
continue;
|
|
356
|
+
const bound = this.host.symbolOf(parameter.name);
|
|
357
|
+
if (bound)
|
|
358
|
+
this.bindingSlots.set(bound, this.newSlot(parameter.name));
|
|
359
|
+
}
|
|
360
|
+
if (this.host.mayReturnRecord(decl))
|
|
361
|
+
this.returnSlots.set(symbol, this.newSlot(decl, true));
|
|
362
|
+
}
|
|
363
|
+
// A dispatch slot has one ABI: members share each parameter's and the
|
|
364
|
+
// result's layout.
|
|
365
|
+
for (const [symbol, family] of this.families) {
|
|
366
|
+
if (family[0] !== symbol || family.length < 2)
|
|
367
|
+
continue;
|
|
368
|
+
const decls = family.map((member) => this.functions.get(member));
|
|
369
|
+
const first = decls[0];
|
|
370
|
+
for (let i = 0; i < first.parameters.length; i++) {
|
|
371
|
+
const head = this.slotOf(first.parameters[i].name);
|
|
372
|
+
for (const decl of decls.slice(1)) {
|
|
373
|
+
const other = decl.parameters[i] ? this.slotOf(decl.parameters[i].name) : undefined;
|
|
374
|
+
if (head !== undefined && other !== undefined)
|
|
375
|
+
this.union(head, other);
|
|
376
|
+
else if (head !== undefined)
|
|
377
|
+
this.markOpen(head);
|
|
378
|
+
else if (other !== undefined)
|
|
379
|
+
this.markOpen(other);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const results = family.map((member) => this.returnSlots.get(member));
|
|
383
|
+
for (const result of results.slice(1)) {
|
|
384
|
+
if (results[0] !== undefined && result !== undefined)
|
|
385
|
+
this.union(results[0], result);
|
|
386
|
+
else if (results[0] !== undefined)
|
|
387
|
+
this.markOpen(results[0]);
|
|
388
|
+
else if (result !== undefined)
|
|
389
|
+
this.markOpen(result);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
slotOf(name) {
|
|
394
|
+
const symbol = this.host.symbolOf(name);
|
|
395
|
+
return symbol ? this.bindingSlots.get(symbol) : undefined;
|
|
396
|
+
}
|
|
397
|
+
/** The calls that can reach a visible function or method, with the
|
|
398
|
+
* callee expression each one names. */
|
|
399
|
+
callsOf(fn) {
|
|
400
|
+
const out = [];
|
|
401
|
+
for (const member of this.families.get(fn) ?? [fn]) {
|
|
402
|
+
for (const reference of this.referencesOf(member)) {
|
|
403
|
+
const parent = reference.parent;
|
|
404
|
+
if (!parent)
|
|
405
|
+
continue;
|
|
406
|
+
const callee = ts.isPropertyAccessExpression(parent) && parent.name === reference ? parent : reference;
|
|
407
|
+
const call = callee.parent;
|
|
408
|
+
if (call && ts.isCallExpression(call) && call.expression === callee)
|
|
409
|
+
out.push(call);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
connect() {
|
|
415
|
+
for (const [symbol, slot] of this.bindingSlots) {
|
|
416
|
+
const declaration = this.host.declarationOf(symbol);
|
|
417
|
+
if (declaration && ts.isVariableDeclaration(declaration)) {
|
|
418
|
+
const list = declaration.parent;
|
|
419
|
+
const statement = list?.parent;
|
|
420
|
+
if (!list ||
|
|
421
|
+
!ts.isVariableDeclarationList(list) ||
|
|
422
|
+
!statement ||
|
|
423
|
+
!ts.isVariableStatement(statement) ||
|
|
424
|
+
ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export) {
|
|
425
|
+
this.markOpen(slot);
|
|
426
|
+
}
|
|
427
|
+
else if (declaration.initializer) {
|
|
428
|
+
this.source(declaration.initializer, slot);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (declaration && ts.isParameter(declaration)) {
|
|
432
|
+
if (declaration.questionToken)
|
|
433
|
+
this.markOpen(slot);
|
|
434
|
+
if (declaration.initializer)
|
|
435
|
+
this.source(declaration.initializer, slot);
|
|
436
|
+
const fn = declaration.parent;
|
|
437
|
+
const index = fn.parameters.indexOf(declaration);
|
|
438
|
+
const fnSymbol = fn.name ? this.host.symbolOf(fn.name) : null;
|
|
439
|
+
for (const call of fnSymbol ? this.callsOf(fnSymbol) : []) {
|
|
440
|
+
const arg = call.arguments[index];
|
|
441
|
+
if (arg)
|
|
442
|
+
this.source(arg, slot);
|
|
443
|
+
else if (!declaration.initializer)
|
|
444
|
+
this.markOpen(slot);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
this.markOpen(slot);
|
|
449
|
+
}
|
|
450
|
+
if (this.shorthandNames.has(symbol.name))
|
|
451
|
+
this.markOpen(slot);
|
|
452
|
+
for (const reference of this.referencesOf(symbol)) {
|
|
453
|
+
if (declaration && declaration.name === reference)
|
|
454
|
+
continue;
|
|
455
|
+
if (!this.use(reference, slot))
|
|
456
|
+
this.markOpen(slot);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
for (const [symbol, slot] of this.returnSlots) {
|
|
460
|
+
const decl = this.functions.get(symbol);
|
|
461
|
+
for (const expression of returnExpressions(decl))
|
|
462
|
+
this.source(expression, slot);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/** Joins the slot with the class a value comes from, or opens the slot
|
|
466
|
+
* when the value can be an object some other storage already holds. */
|
|
467
|
+
source(node, slot) {
|
|
468
|
+
const e = peel(node);
|
|
469
|
+
if (ts.isObjectLiteralExpression(e))
|
|
470
|
+
return;
|
|
471
|
+
if (ts.isIdentifier(e)) {
|
|
472
|
+
const symbol = this.host.symbolOf(e);
|
|
473
|
+
const other = symbol ? this.bindingSlots.get(symbol) : undefined;
|
|
474
|
+
if (other !== undefined)
|
|
475
|
+
this.union(slot, other);
|
|
476
|
+
else
|
|
477
|
+
this.markOpen(slot);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (ts.isCallExpression(e) &&
|
|
481
|
+
(ts.isIdentifier(e.expression) || ts.isPropertyAccessExpression(e.expression))) {
|
|
482
|
+
const callee = ts.isIdentifier(e.expression) ? e.expression : e.expression.name;
|
|
483
|
+
const symbol = this.host.symbolOf(callee);
|
|
484
|
+
const other = symbol ? this.returnSlots.get(symbol) : undefined;
|
|
485
|
+
if (other !== undefined)
|
|
486
|
+
this.union(slot, other);
|
|
487
|
+
else
|
|
488
|
+
this.markOpen(slot);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (ts.isConditionalExpression(e)) {
|
|
492
|
+
this.source(e.whenTrue, slot);
|
|
493
|
+
this.source(e.whenFalse, slot);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (ts.isBinaryExpression(e)) {
|
|
497
|
+
const op = e.operatorToken.kind;
|
|
498
|
+
if (op === ts.SyntaxKind.QuestionQuestionToken ||
|
|
499
|
+
op === ts.SyntaxKind.BarBarToken ||
|
|
500
|
+
op === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
501
|
+
this.source(e.left, slot);
|
|
502
|
+
this.source(e.right, slot);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (op === ts.SyntaxKind.CommaToken) {
|
|
506
|
+
this.source(e.right, slot);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
this.markOpen(slot);
|
|
511
|
+
}
|
|
512
|
+
/** True when this reference to a member only reads or writes its fields,
|
|
513
|
+
* passes the record to another member (a flow `source` joins), or
|
|
514
|
+
* inspects it without keeping or converting it. */
|
|
515
|
+
use(reference, slot) {
|
|
516
|
+
let value = reference;
|
|
517
|
+
for (;;) {
|
|
518
|
+
const user = value.parent;
|
|
519
|
+
if (!user)
|
|
520
|
+
return false;
|
|
521
|
+
if (ts.isParenthesizedExpression(user) ||
|
|
522
|
+
ts.isNonNullExpression(user) ||
|
|
523
|
+
ts.isAsExpression(user) ||
|
|
524
|
+
ts.isSatisfiesExpression(user) ||
|
|
525
|
+
ts.isTypeAssertion(user)) {
|
|
526
|
+
value = user;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (ts.isPropertyAccessExpression(user) && user.expression === value)
|
|
530
|
+
return true;
|
|
531
|
+
if (ts.isElementAccessExpression(user) && user.expression === value)
|
|
532
|
+
return true;
|
|
533
|
+
if (ts.isSpreadAssignment(user))
|
|
534
|
+
return true;
|
|
535
|
+
if (ts.isTemplateSpan(user) || ts.isTypeOfExpression(user))
|
|
536
|
+
return true;
|
|
537
|
+
if (ts.isExpressionStatement(user))
|
|
538
|
+
return true;
|
|
539
|
+
if (ts.isPrefixUnaryExpression(user) && user.operator === ts.SyntaxKind.ExclamationToken)
|
|
540
|
+
return true;
|
|
541
|
+
if ((ts.isIfStatement(user) || ts.isWhileStatement(user) || ts.isDoStatement(user)) &&
|
|
542
|
+
user.expression === value)
|
|
543
|
+
return true;
|
|
544
|
+
if (ts.isForInStatement(user) && user.expression === value)
|
|
545
|
+
return true;
|
|
546
|
+
if (ts.isConditionalExpression(user)) {
|
|
547
|
+
if (user.condition === value)
|
|
548
|
+
return true;
|
|
549
|
+
value = user;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (ts.isBinaryExpression(user)) {
|
|
553
|
+
const op = user.operatorToken.kind;
|
|
554
|
+
if (op === ts.SyntaxKind.QuestionQuestionToken ||
|
|
555
|
+
op === ts.SyntaxKind.BarBarToken ||
|
|
556
|
+
op === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
557
|
+
// The record can become the result: follow the result's use.
|
|
558
|
+
value = user;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (op === ts.SyntaxKind.CommaToken) {
|
|
562
|
+
if (user.left === value)
|
|
563
|
+
return true;
|
|
564
|
+
value = user;
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (op === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
568
|
+
op === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
569
|
+
op === ts.SyntaxKind.EqualsEqualsToken ||
|
|
570
|
+
op === ts.SyntaxKind.ExclamationEqualsToken) {
|
|
571
|
+
const other = user.left === value ? user.right : user.left;
|
|
572
|
+
const e = peel(other);
|
|
573
|
+
if (e.kind === ts.SyntaxKind.NullKeyword || isUndefined(e))
|
|
574
|
+
return true;
|
|
575
|
+
// Comparing identity needs both records in one layout.
|
|
576
|
+
this.source(other, slot);
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
const assigns = op === ts.SyntaxKind.EqualsToken ||
|
|
580
|
+
op === ts.SyntaxKind.QuestionQuestionEqualsToken ||
|
|
581
|
+
op === ts.SyntaxKind.BarBarEqualsToken ||
|
|
582
|
+
op === ts.SyntaxKind.AmpersandAmpersandEqualsToken;
|
|
583
|
+
// A record assigned to a member joins it when the member's own
|
|
584
|
+
// reference is visited, below.
|
|
585
|
+
if (assigns && user.right === value)
|
|
586
|
+
return this.isMember(user.left);
|
|
587
|
+
if (assigns && user.left === value && value === reference) {
|
|
588
|
+
this.source(user.right, slot);
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
if (op === ts.SyntaxKind.InKeyword || op === ts.SyntaxKind.InstanceOfKeyword)
|
|
592
|
+
return true;
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
if (ts.isVariableDeclaration(user) && user.initializer === value) {
|
|
596
|
+
if (ts.isObjectBindingPattern(user.name))
|
|
597
|
+
return true;
|
|
598
|
+
return this.isMember(user.name);
|
|
599
|
+
}
|
|
600
|
+
if (ts.isReturnStatement(user)) {
|
|
601
|
+
const fn = enclosingFunction(user);
|
|
602
|
+
const symbol = fn && (ts.isFunctionDeclaration(fn) || ts.isMethodDeclaration(fn)) && fn.name
|
|
603
|
+
? this.host.symbolOf(fn.name)
|
|
604
|
+
: null;
|
|
605
|
+
return !!symbol && this.returnSlots.has(symbol);
|
|
606
|
+
}
|
|
607
|
+
if (ts.isCallExpression(user) && user.expression !== value) {
|
|
608
|
+
const callee = peel(user.expression);
|
|
609
|
+
if (ts.isIdentifier(callee)) {
|
|
610
|
+
if (READING_FUNCTIONS.has(callee.text) && this.host.isGlobal(callee, callee.text))
|
|
611
|
+
return true;
|
|
612
|
+
const symbol = this.host.symbolOf(callee);
|
|
613
|
+
const fn = symbol ? this.functions.get(symbol) : undefined;
|
|
614
|
+
if (!fn)
|
|
615
|
+
return false;
|
|
616
|
+
const parameter = fn.parameters[user.arguments.indexOf(value)];
|
|
617
|
+
return !!parameter && this.isMember(parameter.name);
|
|
618
|
+
}
|
|
619
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
620
|
+
const symbol = this.host.symbolOf(callee.name);
|
|
621
|
+
const method = symbol ? this.functions.get(symbol) : undefined;
|
|
622
|
+
if (method) {
|
|
623
|
+
const parameter = method.parameters[user.arguments.indexOf(value)];
|
|
624
|
+
return !!parameter && this.isMember(parameter.name);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) {
|
|
628
|
+
const methods = READING_CALLS.get(callee.expression.text);
|
|
629
|
+
return (!!methods &&
|
|
630
|
+
methods.has(callee.name.text) &&
|
|
631
|
+
this.host.isGlobal(callee.expression, callee.expression.text));
|
|
632
|
+
}
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
isMember(node) {
|
|
639
|
+
if (!ts.isIdentifier(node))
|
|
640
|
+
return false;
|
|
641
|
+
const symbol = this.host.symbolOf(node);
|
|
642
|
+
return !!symbol && this.bindingSlots.has(symbol);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/** The return expressions of a function body, excluding nested functions. */
|
|
646
|
+
export function returnExpressions(fn) {
|
|
647
|
+
const out = [];
|
|
648
|
+
const visit = (node) => {
|
|
649
|
+
if (ts.isReturnStatement(node)) {
|
|
650
|
+
if (node.expression)
|
|
651
|
+
out.push(node.expression);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (ts.isFunctionLike(node) || ts.isClassDeclaration(node) || ts.isClassExpression(node))
|
|
655
|
+
return;
|
|
656
|
+
node.forEachChild(visit);
|
|
657
|
+
};
|
|
658
|
+
fn.body?.forEachChild(visit);
|
|
659
|
+
return out;
|
|
660
|
+
}
|
|
661
|
+
/** The identifier names a member: a property, method or accessor in a
|
|
662
|
+
* class, interface, type or object literal, a property read, or an object
|
|
663
|
+
* pattern key. */
|
|
664
|
+
function isMemberName(id, parent) {
|
|
665
|
+
if (ts.isPropertyAccessExpression(parent))
|
|
666
|
+
return parent.name === id;
|
|
667
|
+
if (ts.isBindingElement(parent))
|
|
668
|
+
return (parent.propertyName === id ||
|
|
669
|
+
(!parent.propertyName && parent.name === id && ts.isObjectBindingPattern(parent.parent)));
|
|
670
|
+
return ((ts.isMethodDeclaration(parent) ||
|
|
671
|
+
ts.isPropertyDeclaration(parent) ||
|
|
672
|
+
ts.isMethodSignatureDeclaration(parent) ||
|
|
673
|
+
ts.isPropertySignatureDeclaration(parent) ||
|
|
674
|
+
ts.isGetAccessorDeclaration(parent) ||
|
|
675
|
+
ts.isSetAccessorDeclaration(parent) ||
|
|
676
|
+
ts.isPropertyAssignment(parent) ||
|
|
677
|
+
ts.isShorthandPropertyAssignment(parent)) &&
|
|
678
|
+
parent.name === id);
|
|
679
|
+
}
|
|
680
|
+
function enclosingFunction(node) {
|
|
681
|
+
for (let n = node.parent; n; n = n.parent)
|
|
682
|
+
if (ts.isFunctionLike(n))
|
|
683
|
+
return n;
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
function usesArguments(body) {
|
|
687
|
+
let found = false;
|
|
688
|
+
const visit = (node) => {
|
|
689
|
+
if (found)
|
|
690
|
+
return;
|
|
691
|
+
if (ts.isIdentifier(node) && node.text === "arguments")
|
|
692
|
+
found = true;
|
|
693
|
+
else if (!ts.isFunctionDeclaration(node) && !ts.isFunctionExpression(node))
|
|
694
|
+
node.forEachChild(visit);
|
|
695
|
+
};
|
|
696
|
+
body.forEachChild(visit);
|
|
697
|
+
return found;
|
|
698
|
+
}
|
|
699
|
+
function isUndefined(node) {
|
|
700
|
+
return ts.isIdentifier(node) && node.text === "undefined";
|
|
701
|
+
}
|
|
702
|
+
function isJsFile(file) {
|
|
703
|
+
return /\.(c|m)?jsx?$/.test(file.fileName);
|
|
704
|
+
}
|
|
705
|
+
function peel(node) {
|
|
706
|
+
let e = node;
|
|
707
|
+
while (ts.isParenthesizedExpression(e) ||
|
|
708
|
+
ts.isAsExpression(e) ||
|
|
709
|
+
ts.isTypeAssertion(e) ||
|
|
710
|
+
ts.isSatisfiesExpression(e) ||
|
|
711
|
+
ts.isNonNullExpression(e))
|
|
712
|
+
e = e.expression;
|
|
713
|
+
return e;
|
|
714
|
+
}
|
|
715
|
+
//# sourceMappingURL=runtime-optional-records.js.map
|