cfsolve 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +7 -5
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -0
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +69 -31
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +180 -148
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +5 -5
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
- data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
- data/vendor/cfsolve/src/stage2.rs +2 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +56 -49
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/session.rs +185 -120
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +2 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +94 -178
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
//! a = f(); g(r_0++); h();
|
|
9
9
|
//! ```
|
|
10
10
|
//!
|
|
11
|
-
//! The array must be local to a function and assigned once from a literal without spreads.
|
|
11
|
+
//! The array must be local to a function and initialized or assigned once from a literal without spreads.
|
|
12
12
|
//! That assignment must discard its value. All other uses must access constant indices within
|
|
13
13
|
//! bounds, without calling or deleting slots. Writes to unread slots keep only the assigned
|
|
14
14
|
//! expression so its side effects still run.
|
|
@@ -18,42 +18,48 @@
|
|
|
18
18
|
//! `void` element there keeps only its operand, so a constant hidden as `void (k ^ x ^ (k ^ x))`
|
|
19
19
|
//! leaves the slot's later write as its local's only one, which copy propagation can inline.
|
|
20
20
|
|
|
21
|
-
use
|
|
22
|
-
use swc_core::common::{DUMMY_SP, Mark, SyntaxContext};
|
|
23
|
-
use swc_core::ecma::ast::{
|
|
24
|
-
ArrayLit, ArrowExpr, AssignExpr, AssignOp, AssignTarget, BindingIdent, CallExpr, Callee,
|
|
25
|
-
Constructor, Expr, ExprStmt, ForStmt, Function, GetterProp, Id, Ident, MemberExpr, Pat,
|
|
26
|
-
Program, SeqExpr, SetterProp, SimpleAssignTarget, Stmt, TaggedTpl, UnaryExpr, UnaryOp,
|
|
27
|
-
VarDeclOrExpr, VarDeclarator,
|
|
28
|
-
};
|
|
29
|
-
use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
|
|
30
|
-
|
|
31
|
-
use super::analysis::{Analysis, Globals, effects};
|
|
32
|
-
use super::{HashMap, HashSet, removal};
|
|
33
|
-
use crate::js::ast;
|
|
21
|
+
use std::mem;
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
use oxc::allocator::{Box, CloneIn, GetAllocator, TakeIn, Vec as ArenaVec};
|
|
24
|
+
use oxc::ast::ast::{
|
|
25
|
+
ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AssignmentTarget,
|
|
26
|
+
BindingIdentifier, BindingPattern, CallExpression, Expression, ExpressionStatement,
|
|
27
|
+
ForStatement, Function, IdentifierReference, MemberExpression, Program, SimpleAssignmentTarget,
|
|
28
|
+
Statement, TaggedTemplateExpression, UnaryExpression, UpdateExpression, VariableDeclaration,
|
|
29
|
+
VariableDeclarator,
|
|
30
|
+
};
|
|
31
|
+
use oxc::ast::builder::AstBuilder;
|
|
32
|
+
use oxc::ast_visit::{Visit, VisitMut, walk, walk_mut};
|
|
33
|
+
use oxc::span::{GetSpan, Span};
|
|
34
|
+
use oxc::syntax::operator::{AssignmentOperator, UnaryOperator};
|
|
35
|
+
use oxc::syntax::reference::ReferenceFlags;
|
|
36
|
+
use oxc::syntax::scope::{ScopeFlags, ScopeId};
|
|
37
|
+
|
|
38
|
+
use super::analysis::{Analysis, Id};
|
|
39
|
+
use super::{HashMap, HashSet, ast};
|
|
40
|
+
|
|
41
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
42
|
+
let root = analysis.scoping.root_scope_id();
|
|
38
43
|
let mut uses = Uses {
|
|
39
|
-
|
|
44
|
+
analysis,
|
|
40
45
|
created: HashMap::default(),
|
|
41
46
|
slots: HashMap::default(),
|
|
42
|
-
|
|
43
|
-
function: 0,
|
|
44
|
-
functions: 0,
|
|
47
|
+
function: root,
|
|
45
48
|
loops: 0,
|
|
49
|
+
discarded: false,
|
|
46
50
|
};
|
|
47
|
-
|
|
51
|
+
uses.visit_program(program);
|
|
52
|
+
let mut slots = uses.slots;
|
|
48
53
|
let mut arrays = HashMap::default();
|
|
49
54
|
for (id, created) in uses.created {
|
|
50
|
-
let
|
|
51
|
-
let [creation] = &created[..] else {
|
|
55
|
+
let [creation] = created.as_slice() else {
|
|
52
56
|
continue;
|
|
53
57
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
let slots = slots.remove(&id).unwrap_or_default();
|
|
59
|
+
let bindings = &analysis.bindings;
|
|
60
|
+
if creation.function == root
|
|
61
|
+
|| analysis.scope(id) != creation.function
|
|
62
|
+
|| !bindings.is_written_once(&id)
|
|
57
63
|
|| bindings.is_parameter(&id)
|
|
58
64
|
|| slots.opaque
|
|
59
65
|
|| slots.accesses != bindings.references(&id)
|
|
@@ -61,414 +67,435 @@ pub(super) fn run(program: &mut Program, analysis: &mut Analysis) -> bool {
|
|
|
61
67
|
.read
|
|
62
68
|
.iter()
|
|
63
69
|
.chain(&slots.written)
|
|
64
|
-
.any(|&
|
|
70
|
+
.any(|&index| index >= creation.length)
|
|
65
71
|
{
|
|
66
72
|
continue;
|
|
67
73
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
needed.then(|| Ident::new(format!("{}_{slot}", id.0).into(), DUMMY_SP, context))
|
|
74
|
+
let base = analysis.name(id).to_owned();
|
|
75
|
+
let span = analysis.span(id);
|
|
76
|
+
let locals = (0..creation.length).map(|index| {
|
|
77
|
+
let used = slots.read.contains(&index) || creation.defined.contains(&index);
|
|
78
|
+
used.then(|| {
|
|
79
|
+
analysis.fresh_binding(&format!("{base}_{index}"), creation.function, span)
|
|
75
80
|
})
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
assign_undefined: !creation.once,
|
|
84
|
-
},
|
|
85
|
-
);
|
|
81
|
+
});
|
|
82
|
+
let array = Array {
|
|
83
|
+
locals: locals.collect(),
|
|
84
|
+
read: slots.read,
|
|
85
|
+
reset: !creation.once,
|
|
86
|
+
};
|
|
87
|
+
arrays.insert(id, array);
|
|
86
88
|
}
|
|
87
89
|
if arrays.is_empty() {
|
|
88
90
|
return false;
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
Split {
|
|
93
|
+
analysis,
|
|
91
94
|
arrays: &arrays,
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
}
|
|
96
|
+
.visit_program(program);
|
|
94
97
|
true
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
///
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
match element {
|
|
101
|
-
None => true,
|
|
102
|
-
// Constant arithmetic has no side effects, even when nested.
|
|
103
|
-
Some(Expr::Unary(unary)) => {
|
|
104
|
-
unary.op == UnaryOp::Void
|
|
105
|
-
&& (ast::fold_number(&unary.arg, &|_| None).is_some()
|
|
106
|
-
|| !effects::may_have_effects(&unary.arg, globals))
|
|
107
|
-
}
|
|
108
|
-
Some(Expr::Ident(identifier)) => globals.is(identifier, "undefined"),
|
|
109
|
-
Some(_) => false,
|
|
110
|
-
}
|
|
100
|
+
/// Recognizes a hole or an [`Analysis::is_undefined`] value.
|
|
101
|
+
fn undefined(value: Option<&Expression<'_>>, analysis: &Analysis<'_>) -> bool {
|
|
102
|
+
value.is_none_or(|value| analysis.is_undefined(value))
|
|
111
103
|
}
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
105
|
+
/// Extracts `array[index]` with a constant non-negative integer index, rejecting optional access.
|
|
106
|
+
fn slot(member: Option<&MemberExpression<'_>>, analysis: &Analysis<'_>) -> Option<(Id, usize)> {
|
|
107
|
+
let Some(MemberExpression::ComputedMemberExpression(member)) = member else {
|
|
108
|
+
return None;
|
|
109
|
+
};
|
|
110
|
+
if member.optional {
|
|
111
|
+
return None;
|
|
112
|
+
}
|
|
113
|
+
Some((
|
|
114
|
+
analysis.expression_id(&member.object)?,
|
|
115
|
+
ast::index(&member.expression)?,
|
|
116
|
+
))
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
let index = &member.prop.as_computed()?.expr;
|
|
125
|
-
let slot = ast::array_index(ast::fold_number(index, &|_| None)?)?;
|
|
126
|
-
Some((member.obj.as_ident()?.to_id(), slot))
|
|
119
|
+
fn void_zero<'a>(span: Span, builder: &AstBuilder<'a>) -> Expression<'a> {
|
|
120
|
+
let zero = ast::number_literal(span, 0.0, builder);
|
|
121
|
+
Expression::new_unary_expression(span, UnaryOperator::Void, zero, builder)
|
|
127
122
|
}
|
|
128
123
|
|
|
124
|
+
/// An array-literal creation and the context that executes it.
|
|
129
125
|
struct Creation {
|
|
130
126
|
length: usize,
|
|
131
|
-
/// Slots initialized to values other than undefined.
|
|
127
|
+
/// Slots initialized to values other than effect-free undefined.
|
|
132
128
|
defined: HashSet<usize>,
|
|
133
|
-
function:
|
|
134
|
-
///
|
|
129
|
+
function: ScopeId,
|
|
130
|
+
/// Creation runs outside loops and at most once per invocation of its declaring function.
|
|
135
131
|
once: bool,
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
#[derive(Default)]
|
|
139
135
|
struct Slots {
|
|
140
|
-
///
|
|
136
|
+
/// Compared with the binding's reference count to detect other uses.
|
|
141
137
|
accesses: usize,
|
|
142
|
-
/// Slots read, updated, or assigned with an operator other than `=`.
|
|
138
|
+
/// Slots read, updated, or assigned with an operator other than plain `=`.
|
|
143
139
|
read: HashSet<usize>,
|
|
144
140
|
written: HashSet<usize>,
|
|
145
|
-
///
|
|
141
|
+
/// A slot is called, tagged, or deleted; these uses depend on the array itself.
|
|
146
142
|
opaque: bool,
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
/// Collects array assignments
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
globals: Globals,
|
|
145
|
+
/// Collects discarded array assignments, declared initializers, and slot accesses.
|
|
146
|
+
struct Uses<'b, 'a> {
|
|
147
|
+
analysis: &'b Analysis<'a>,
|
|
153
148
|
created: HashMap<Id, Vec<Creation>>,
|
|
154
149
|
slots: HashMap<Id, Slots>,
|
|
155
|
-
|
|
156
|
-
/// Current function number in traversal order; 0 denotes the script.
|
|
157
|
-
function: usize,
|
|
158
|
-
functions: usize,
|
|
150
|
+
function: ScopeId,
|
|
159
151
|
loops: usize,
|
|
152
|
+
/// The visited expression's value is discarded.
|
|
153
|
+
discarded: bool,
|
|
160
154
|
}
|
|
161
155
|
|
|
162
|
-
impl Uses {
|
|
163
|
-
fn create(&mut self, id: Id, array: &
|
|
156
|
+
impl<'a> Uses<'_, 'a> {
|
|
157
|
+
fn create(&mut self, id: Id, array: &ArrayExpression<'a>) {
|
|
158
|
+
if array.elements.iter().any(|element| element.is_spread()) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
164
161
|
let mut defined = HashSet::default();
|
|
165
|
-
for (
|
|
166
|
-
if element
|
|
167
|
-
.
|
|
168
|
-
.is_some_and(|element| element.spread.is_some())
|
|
169
|
-
{
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if !is_undefined(element.as_ref().map(|element| &*element.expr), self.globals) {
|
|
173
|
-
defined.insert(slot);
|
|
162
|
+
for (index, element) in array.elements.iter().enumerate() {
|
|
163
|
+
if !undefined(element.as_expression(), self.analysis) {
|
|
164
|
+
defined.insert(index);
|
|
174
165
|
}
|
|
175
166
|
}
|
|
176
|
-
|
|
177
|
-
length: array.
|
|
167
|
+
self.created.entry(id).or_default().push(Creation {
|
|
168
|
+
length: array.elements.len(),
|
|
178
169
|
defined,
|
|
179
170
|
function: self.function,
|
|
180
171
|
once: self.loops == 0,
|
|
181
|
-
};
|
|
182
|
-
self.created.entry(id).or_default().push(creation);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/// Records an array assignment whose value is discarded by a statement. Sequence expressions
|
|
186
|
-
/// handle their other operands separately.
|
|
187
|
-
fn statement(&mut self, expression: &Expr) {
|
|
188
|
-
let last = expression
|
|
189
|
-
.as_seq()
|
|
190
|
-
.and_then(|sequence| sequence.exprs.last());
|
|
191
|
-
self.discarded(last.map_or(expression, |last| &**last));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/// Records `binding = [...]`.
|
|
195
|
-
fn discarded(&mut self, expression: &Expr) {
|
|
196
|
-
if let Some((id, Expr::Array(array))) = ast::assignment(expression) {
|
|
197
|
-
self.create(id, array);
|
|
198
|
-
}
|
|
172
|
+
});
|
|
199
173
|
}
|
|
200
174
|
|
|
201
|
-
fn access(&mut self, member:
|
|
202
|
-
if let Some((id,
|
|
175
|
+
fn access(&mut self, member: Option<&MemberExpression<'a>>, read: bool) {
|
|
176
|
+
if let Some((id, index)) = slot(member, self.analysis) {
|
|
203
177
|
let slots = self.slots.entry(id).or_default();
|
|
204
178
|
slots.accesses += 1;
|
|
205
179
|
if read {
|
|
206
|
-
slots.read.insert(
|
|
180
|
+
slots.read.insert(index);
|
|
207
181
|
} else {
|
|
208
|
-
slots.written.insert(
|
|
182
|
+
slots.written.insert(index);
|
|
209
183
|
}
|
|
210
184
|
}
|
|
211
185
|
}
|
|
212
186
|
|
|
213
|
-
fn opaque(&mut self, expression: &
|
|
214
|
-
if let Some(
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
self.slots.entry(id).or_default().opaque = true;
|
|
187
|
+
fn opaque(&mut self, expression: &Expression<'a>) {
|
|
188
|
+
if let Some((id, _)) = slot(expression.as_member_expression(), self.analysis) {
|
|
189
|
+
self.slots.entry(id).or_default().opaque = true
|
|
218
190
|
}
|
|
219
191
|
}
|
|
220
192
|
|
|
221
|
-
fn
|
|
222
|
-
self.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
visit(self);
|
|
226
|
-
self.function = function;
|
|
227
|
-
self.loops = loops;
|
|
193
|
+
fn expression(&mut self, expression: &Expression<'a>, discarded: bool) {
|
|
194
|
+
let outer = mem::replace(&mut self.discarded, discarded);
|
|
195
|
+
self.visit_expression(expression);
|
|
196
|
+
self.discarded = outer;
|
|
228
197
|
}
|
|
229
198
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
self.
|
|
199
|
+
/// Visits a function body with its own scope and outside the enclosing loops.
|
|
200
|
+
fn function(&mut self, scope: Option<ScopeId>, walk: impl FnOnce(&mut Self)) {
|
|
201
|
+
let scope = scope.expect("semantic analysis assigns function scopes");
|
|
202
|
+
let outer = mem::replace(&mut self.function, scope);
|
|
203
|
+
let loops = mem::take(&mut self.loops);
|
|
204
|
+
walk(self);
|
|
205
|
+
self.function = outer;
|
|
206
|
+
self.loops = loops;
|
|
234
207
|
}
|
|
235
208
|
}
|
|
236
209
|
|
|
237
|
-
impl Visit for Uses {
|
|
238
|
-
fn
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
for expression in discarded {
|
|
246
|
-
self.discarded(expression);
|
|
247
|
-
}
|
|
210
|
+
impl<'a> Visit<'a> for Uses<'_, 'a> {
|
|
211
|
+
fn visit_expression(&mut self, expression: &Expression<'a>) {
|
|
212
|
+
let discarded = mem::replace(&mut self.discarded, false);
|
|
213
|
+
if discarded
|
|
214
|
+
&& let Some((id, Expression::ArrayExpression(array))) =
|
|
215
|
+
self.analysis.assignment(expression)
|
|
216
|
+
{
|
|
217
|
+
self.create(id, array)
|
|
248
218
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
self.declared.insert(name.to_id(), self.function);
|
|
255
|
-
if let Some(Expr::Array(array)) = declarator.init.as_deref() {
|
|
256
|
-
self.create(name.to_id(), array);
|
|
219
|
+
self.access(expression.as_member_expression(), true);
|
|
220
|
+
if let Expression::SequenceExpression(sequence) = expression {
|
|
221
|
+
let length = sequence.expressions.len();
|
|
222
|
+
for (index, expression) in sequence.expressions.iter().enumerate() {
|
|
223
|
+
self.expression(expression, index + 1 < length || discarded)
|
|
257
224
|
}
|
|
225
|
+
} else {
|
|
226
|
+
walk::walk_expression(self, expression)
|
|
258
227
|
}
|
|
259
|
-
|
|
228
|
+
self.discarded = discarded;
|
|
260
229
|
}
|
|
261
230
|
|
|
262
|
-
fn
|
|
263
|
-
|
|
264
|
-
self.access(member, /* read= */ true);
|
|
265
|
-
}
|
|
266
|
-
expression.visit_children_with(self);
|
|
231
|
+
fn visit_expression_statement(&mut self, statement: &ExpressionStatement<'a>) {
|
|
232
|
+
self.expression(&statement.expression, true)
|
|
267
233
|
}
|
|
268
234
|
|
|
269
|
-
fn
|
|
270
|
-
if let
|
|
271
|
-
|
|
235
|
+
fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
|
|
236
|
+
if let Some(id) = ast::pattern_id(&declarator.id)
|
|
237
|
+
&& let Some(Expression::ArrayExpression(array)) = &declarator.init
|
|
238
|
+
{
|
|
239
|
+
self.create(id, array)
|
|
272
240
|
}
|
|
273
|
-
|
|
241
|
+
walk::walk_variable_declarator(self, declarator)
|
|
274
242
|
}
|
|
275
243
|
|
|
276
|
-
fn
|
|
277
|
-
|
|
278
|
-
self
|
|
244
|
+
fn visit_assignment_expression(&mut self, assignment: &AssignmentExpression<'a>) {
|
|
245
|
+
let Some(member) = assignment.left.as_member_expression() else {
|
|
246
|
+
return walk::walk_assignment_expression(self, assignment);
|
|
247
|
+
};
|
|
248
|
+
self.access(
|
|
249
|
+
Some(member),
|
|
250
|
+
assignment.operator != AssignmentOperator::Assign,
|
|
251
|
+
);
|
|
252
|
+
self.visit_expression(member.object());
|
|
253
|
+
if let MemberExpression::ComputedMemberExpression(computed) = member {
|
|
254
|
+
self.visit_expression(&computed.expression)
|
|
279
255
|
}
|
|
280
|
-
|
|
256
|
+
self.visit_expression(&assignment.right)
|
|
281
257
|
}
|
|
282
258
|
|
|
283
|
-
fn
|
|
284
|
-
self.
|
|
285
|
-
|
|
259
|
+
fn visit_update_expression(&mut self, update: &UpdateExpression<'a>) {
|
|
260
|
+
self.access(update.argument.as_member_expression(), true);
|
|
261
|
+
walk::walk_update_expression(self, update)
|
|
286
262
|
}
|
|
287
263
|
|
|
288
|
-
fn
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
unary.visit_children_with(self);
|
|
264
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
265
|
+
self.opaque(&call.callee);
|
|
266
|
+
walk::walk_call_expression(self, call)
|
|
293
267
|
}
|
|
294
268
|
|
|
295
|
-
fn
|
|
296
|
-
self.
|
|
269
|
+
fn visit_tagged_template_expression(&mut self, template: &TaggedTemplateExpression<'a>) {
|
|
270
|
+
self.opaque(&template.tag);
|
|
271
|
+
walk::walk_tagged_template_expression(self, template)
|
|
297
272
|
}
|
|
298
273
|
|
|
299
|
-
fn
|
|
300
|
-
|
|
274
|
+
fn visit_unary_expression(&mut self, unary: &UnaryExpression<'a>) {
|
|
275
|
+
if unary.operator == UnaryOperator::Delete {
|
|
276
|
+
self.opaque(&unary.argument)
|
|
277
|
+
}
|
|
278
|
+
walk::walk_unary_expression(self, unary)
|
|
301
279
|
}
|
|
302
280
|
|
|
303
|
-
fn
|
|
304
|
-
self.
|
|
281
|
+
fn visit_function(&mut self, function: &Function<'a>, flags: ScopeFlags) {
|
|
282
|
+
self.function(function.scope_id.get(), |uses| {
|
|
283
|
+
walk::walk_function(uses, function, flags)
|
|
284
|
+
})
|
|
305
285
|
}
|
|
306
286
|
|
|
307
|
-
fn
|
|
308
|
-
self.
|
|
287
|
+
fn visit_arrow_function_expression(&mut self, arrow: &ArrowFunctionExpression<'a>) {
|
|
288
|
+
self.function(arrow.scope_id.get(), |uses| {
|
|
289
|
+
walk::walk_arrow_function_expression(uses, arrow)
|
|
290
|
+
})
|
|
309
291
|
}
|
|
310
292
|
|
|
311
|
-
fn
|
|
312
|
-
|
|
293
|
+
fn visit_statement(&mut self, statement: &Statement<'a>) {
|
|
294
|
+
let is_loop = usize::from(matches!(
|
|
295
|
+
statement,
|
|
296
|
+
Statement::WhileStatement(_)
|
|
297
|
+
| Statement::DoWhileStatement(_)
|
|
298
|
+
| Statement::ForInStatement(_)
|
|
299
|
+
| Statement::ForOfStatement(_)
|
|
300
|
+
));
|
|
301
|
+
self.loops += is_loop;
|
|
302
|
+
walk::walk_statement(self, statement);
|
|
303
|
+
self.loops -= is_loop;
|
|
313
304
|
}
|
|
314
305
|
|
|
315
|
-
///
|
|
316
|
-
fn
|
|
317
|
-
if let Some(
|
|
318
|
-
|
|
306
|
+
/// The initializer runs once, unlike the rest of the loop.
|
|
307
|
+
fn visit_for_statement(&mut self, for_loop: &ForStatement<'a>) {
|
|
308
|
+
if let Some(init) = &for_loop.init {
|
|
309
|
+
match init.as_expression() {
|
|
310
|
+
Some(expression) => self.expression(expression, true),
|
|
311
|
+
None => self.visit_for_statement_init(init),
|
|
312
|
+
}
|
|
319
313
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
fn visit_stmt(&mut self, statement: &Stmt) {
|
|
329
|
-
if matches!(
|
|
330
|
-
statement,
|
|
331
|
-
Stmt::ForIn(_) | Stmt::ForOf(_) | Stmt::While(_) | Stmt::DoWhile(_)
|
|
332
|
-
) {
|
|
333
|
-
self.in_loop(|uses| statement.visit_children_with(uses));
|
|
334
|
-
} else {
|
|
335
|
-
statement.visit_children_with(self);
|
|
314
|
+
self.loops += 1;
|
|
315
|
+
if let Some(test) = &for_loop.test {
|
|
316
|
+
self.visit_expression(test)
|
|
317
|
+
}
|
|
318
|
+
if let Some(update) = &for_loop.update {
|
|
319
|
+
self.visit_expression(update)
|
|
336
320
|
}
|
|
321
|
+
self.visit_statement(&for_loop.body);
|
|
322
|
+
self.loops -= 1;
|
|
337
323
|
}
|
|
338
324
|
}
|
|
339
325
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
326
|
+
/// A split array.
|
|
327
|
+
struct Array<'a> {
|
|
328
|
+
/// Replacement binding for each slot that is read or initialized with a value.
|
|
329
|
+
locals: Vec<Option<BindingIdentifier<'a>>>,
|
|
343
330
|
read: HashSet<usize>,
|
|
344
|
-
|
|
331
|
+
/// Creation can repeat, so even undefined slots need explicit assignments.
|
|
332
|
+
reset: bool,
|
|
345
333
|
}
|
|
346
334
|
|
|
347
|
-
struct Split<'
|
|
348
|
-
|
|
349
|
-
|
|
335
|
+
struct Split<'b, 'a> {
|
|
336
|
+
analysis: &'b mut Analysis<'a>,
|
|
337
|
+
arrays: &'b HashMap<Id, Array<'a>>,
|
|
350
338
|
}
|
|
351
339
|
|
|
352
|
-
impl Split<'
|
|
353
|
-
///
|
|
354
|
-
fn
|
|
355
|
-
let
|
|
356
|
-
|
|
357
|
-
let element = element.take().map(|element| element.expr);
|
|
358
|
-
if let Some(local) = local
|
|
359
|
-
&& (array.assign_undefined || !is_undefined(element.as_deref(), self.globals))
|
|
360
|
-
{
|
|
361
|
-
let value = element.unwrap_or_else(|| Box::new(undefined()));
|
|
362
|
-
assignments.push((local.clone(), value));
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
assignments
|
|
340
|
+
impl<'b, 'a> Split<'b, 'a> {
|
|
341
|
+
/// Returns the replacement local of a split array's slot.
|
|
342
|
+
fn local(&self, member: Option<&MemberExpression<'a>>) -> Option<&'b BindingIdentifier<'a>> {
|
|
343
|
+
let (id, index) = slot(member, self.analysis)?;
|
|
344
|
+
self.arrays.get(&id)?.locals[index].as_ref()
|
|
366
345
|
}
|
|
367
346
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
347
|
+
fn reference(
|
|
348
|
+
&mut self,
|
|
349
|
+
local: &BindingIdentifier<'a>,
|
|
350
|
+
span: Span,
|
|
351
|
+
flags: ReferenceFlags,
|
|
352
|
+
) -> Box<'a, IdentifierReference<'a>> {
|
|
353
|
+
let reference = self.analysis.reference(local.symbol_id(), span, flags);
|
|
354
|
+
Box::new_in(reference, &self.analysis.ast)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/// Builds scalar assignments in the array literal's element order. Locals already start
|
|
358
|
+
/// undefined on each function call, so a once-only `void` element keeps just its operand;
|
|
359
|
+
/// creations inside loops must reset undefined slots on every iteration.
|
|
360
|
+
fn initial(
|
|
361
|
+
&mut self,
|
|
362
|
+
array: &Array<'a>,
|
|
363
|
+
literal: &ArrayExpression<'a>,
|
|
364
|
+
) -> ArenaVec<'a, Expression<'a>> {
|
|
365
|
+
let allocator = self.analysis.allocator();
|
|
366
|
+
let span = literal.span;
|
|
367
|
+
let mut initial = ArenaVec::new_in(&self.analysis.ast);
|
|
368
|
+
for (index, element) in literal.elements.iter().enumerate() {
|
|
369
|
+
let value = element.as_expression();
|
|
370
|
+
if !array.reset {
|
|
371
|
+
if undefined(value, self.analysis) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if let Some(Expression::UnaryExpression(unary)) = value
|
|
375
|
+
&& unary.operator == UnaryOperator::Void
|
|
376
|
+
{
|
|
377
|
+
initial.push(unary.argument.clone_in_with_semantic_ids(allocator));
|
|
378
|
+
continue;
|
|
390
379
|
}
|
|
391
|
-
// The array binding is assigned only when the array is created.
|
|
392
|
-
let array = self.arrays.get(&assignment.left.as_ident()?.to_id())?;
|
|
393
|
-
let Expr::Array(literal) = &mut *assignment.right else {
|
|
394
|
-
return None;
|
|
395
|
-
};
|
|
396
|
-
let mut assignments: Vec<Box<Expr>> = self
|
|
397
|
-
.initial(array, literal)
|
|
398
|
-
.into_iter()
|
|
399
|
-
.map(|(local, value)| match *value {
|
|
400
|
-
// The local already starts undefined, so only the operand runs.
|
|
401
|
-
Expr::Unary(UnaryExpr {
|
|
402
|
-
op: UnaryOp::Void,
|
|
403
|
-
arg,
|
|
404
|
-
..
|
|
405
|
-
}) if !array.assign_undefined => arg,
|
|
406
|
-
value => Box::new(Expr::Assign(AssignExpr {
|
|
407
|
-
span: DUMMY_SP,
|
|
408
|
-
op: AssignOp::Assign,
|
|
409
|
-
left: AssignTarget::Simple(SimpleAssignTarget::Ident(local.into())),
|
|
410
|
-
right: Box::new(value),
|
|
411
|
-
})),
|
|
412
|
-
})
|
|
413
|
-
.collect();
|
|
414
|
-
Some(match assignments.len() {
|
|
415
|
-
0 => undefined(),
|
|
416
|
-
1 => *assignments.remove(0),
|
|
417
|
-
_ => Expr::Seq(SeqExpr {
|
|
418
|
-
span: assignment.span,
|
|
419
|
-
exprs: assignments,
|
|
420
|
-
}),
|
|
421
|
-
})
|
|
422
380
|
}
|
|
423
|
-
|
|
381
|
+
let value = match value {
|
|
382
|
+
Some(value) => value.clone_in_with_semantic_ids(allocator),
|
|
383
|
+
None => void_zero(span, &self.analysis.ast),
|
|
384
|
+
};
|
|
385
|
+
let Some(local) = &array.locals[index] else {
|
|
386
|
+
initial.push(value);
|
|
387
|
+
continue;
|
|
388
|
+
};
|
|
389
|
+
let reference = self.reference(local, span, ReferenceFlags::Write);
|
|
390
|
+
let target = AssignmentTarget::AssignmentTargetIdentifier(reference);
|
|
391
|
+
initial.push(Expression::new_assignment_expression(
|
|
392
|
+
span,
|
|
393
|
+
AssignmentOperator::Assign,
|
|
394
|
+
target,
|
|
395
|
+
value,
|
|
396
|
+
&self.analysis.ast,
|
|
397
|
+
));
|
|
424
398
|
}
|
|
399
|
+
initial
|
|
425
400
|
}
|
|
426
401
|
}
|
|
427
402
|
|
|
428
|
-
impl VisitMut for Split<'_> {
|
|
429
|
-
fn
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
403
|
+
impl<'a> VisitMut<'a> for Split<'_, 'a> {
|
|
404
|
+
fn visit_assignment_target(&mut self, target: &mut AssignmentTarget<'a>) {
|
|
405
|
+
let Some(local) = self.local(target.as_member_expression()) else {
|
|
406
|
+
return walk_mut::walk_assignment_target(self, target);
|
|
407
|
+
};
|
|
408
|
+
let reference = self.reference(local, target.span(), ReferenceFlags::Write);
|
|
409
|
+
*target = AssignmentTarget::AssignmentTargetIdentifier(reference);
|
|
434
410
|
}
|
|
435
411
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
412
|
+
fn visit_simple_assignment_target(&mut self, target: &mut SimpleAssignmentTarget<'a>) {
|
|
413
|
+
let Some(local) = self.local(target.as_member_expression()) else {
|
|
414
|
+
return walk_mut::walk_simple_assignment_target(self, target);
|
|
415
|
+
};
|
|
416
|
+
let flags = ReferenceFlags::Read | ReferenceFlags::Write;
|
|
417
|
+
let reference = self.reference(local, target.span(), flags);
|
|
418
|
+
*target = SimpleAssignmentTarget::AssignmentTargetIdentifier(reference);
|
|
442
419
|
}
|
|
443
420
|
|
|
444
|
-
fn
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
.
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
421
|
+
fn visit_expression(&mut self, expression: &mut Expression<'a>) {
|
|
422
|
+
if let Expression::AssignmentExpression(assignment) = expression {
|
|
423
|
+
// A write to a slot that is never read keeps only its value.
|
|
424
|
+
if let Some((id, index)) = slot(assignment.left.as_member_expression(), self.analysis)
|
|
425
|
+
&& let Some(array) = self.arrays.get(&id)
|
|
426
|
+
&& !array.read.contains(&index)
|
|
427
|
+
{
|
|
428
|
+
let mut value = assignment.right.take_in(&self.analysis.ast);
|
|
429
|
+
self.visit_expression(&mut value);
|
|
430
|
+
*expression = value;
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if let Some(id) = self.analysis.target_id(&assignment.left)
|
|
434
|
+
&& let Some(array) = self.arrays.get(&id)
|
|
435
|
+
&& let Expression::ArrayExpression(literal) = &assignment.right
|
|
436
|
+
{
|
|
437
|
+
let mut initial = self.initial(array, literal);
|
|
438
|
+
*expression = if initial.len() > 1 {
|
|
439
|
+
Expression::new_sequence_expression(assignment.span, initial, self.analysis)
|
|
440
|
+
} else {
|
|
441
|
+
initial
|
|
442
|
+
.pop()
|
|
443
|
+
.unwrap_or_else(|| void_zero(assignment.span, &self.analysis.ast))
|
|
444
|
+
};
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
walk_mut::walk_expression(self, expression);
|
|
449
|
+
if let Some(local) = self.local(expression.as_member_expression()) {
|
|
450
|
+
let reference = self.reference(local, expression.span(), ReferenceFlags::Read);
|
|
451
|
+
*expression = Expression::Identifier(reference);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
fn visit_variable_declaration(&mut self, declaration: &mut VariableDeclaration<'a>) {
|
|
456
|
+
let allocator = self.analysis.allocator();
|
|
457
|
+
let mut declarators = ArenaVec::new_in(&self.analysis.ast);
|
|
458
|
+
for declarator in declaration.declarations.take_in(&self.analysis.ast) {
|
|
459
|
+
let array = ast::pattern_id(&declarator.id).and_then(|id| self.arrays.get(&id));
|
|
460
|
+
let Some(array) = array else {
|
|
461
|
+
declarators.push(declarator);
|
|
454
462
|
continue;
|
|
455
463
|
};
|
|
456
|
-
|
|
457
|
-
Some(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
for (index, local) in array.locals.iter().enumerate() {
|
|
465
|
+
let Some(local) = local else { continue };
|
|
466
|
+
let init = match &declarator.init {
|
|
467
|
+
Some(Expression::ArrayExpression(literal)) => literal.elements[index]
|
|
468
|
+
.as_expression()
|
|
469
|
+
.filter(|value| array.reset || !undefined(Some(value), self.analysis))
|
|
470
|
+
.map(|value| value.clone_in_with_semantic_ids(allocator)),
|
|
471
|
+
_ => None,
|
|
472
|
+
};
|
|
473
|
+
let local = Box::new_in(
|
|
474
|
+
local.clone_in_with_semantic_ids(allocator),
|
|
475
|
+
&self.analysis.ast,
|
|
476
|
+
);
|
|
477
|
+
let pattern = BindingPattern::BindingIdentifier(local);
|
|
478
|
+
declarators.push(VariableDeclarator::new(
|
|
479
|
+
declarator.span,
|
|
480
|
+
pattern,
|
|
481
|
+
None,
|
|
482
|
+
init,
|
|
483
|
+
false,
|
|
484
|
+
&self.analysis.ast,
|
|
485
|
+
));
|
|
486
|
+
}
|
|
470
487
|
}
|
|
471
|
-
|
|
488
|
+
declaration.declarations = declarators;
|
|
489
|
+
walk_mut::walk_variable_declaration(self, declaration);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/// Drops the statements left by removed undefined writes.
|
|
493
|
+
fn visit_statements(&mut self, statements: &mut ArenaVec<'a, Statement<'a>>) {
|
|
494
|
+
walk_mut::walk_statements(self, statements);
|
|
495
|
+
statements.retain(|statement| {
|
|
496
|
+
!matches!(statement, Statement::ExpressionStatement(statement)
|
|
497
|
+
if undefined(Some(&statement.expression), self.analysis))
|
|
498
|
+
});
|
|
472
499
|
}
|
|
473
500
|
}
|
|
474
501
|
|
|
@@ -478,7 +505,7 @@ mod tests {
|
|
|
478
505
|
|
|
479
506
|
#[test]
|
|
480
507
|
fn splits_arrays_reached_only_through_constant_slots() {
|
|
481
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
508
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
482
509
|
let output = transform(
|
|
483
510
|
"function f(x) {
|
|
484
511
|
var r, a, s = [1, void 0];
|
|
@@ -489,7 +516,6 @@ mod tests {
|
|
|
489
516
|
);
|
|
490
517
|
testing::assert_contains(
|
|
491
518
|
&output,
|
|
492
|
-
&[],
|
|
493
519
|
&[
|
|
494
520
|
"var r_0, a, s_0 = 1, s_1;",
|
|
495
521
|
"a = g(); g(r_0++, s_0, s_1); h();",
|
|
@@ -501,17 +527,17 @@ mod tests {
|
|
|
501
527
|
let output = transform(
|
|
502
528
|
"function f() { var r, i; for (r = [void 0], i = 0; i < 2; i++) { h(r[0]); r[0] = i; } }",
|
|
503
529
|
);
|
|
504
|
-
testing::assert_contains(&output, &[
|
|
530
|
+
testing::assert_contains(&output, &["h(r_0);", "r_0 = i;"]);
|
|
505
531
|
testing::assert_lacks(&output, &["r_0 = void 0", "["]);
|
|
506
532
|
// A `void` element runs its operand without writing the local.
|
|
507
533
|
let output =
|
|
508
534
|
transform("function f() { var r; r = [void (7 ^ k ^ (7 ^ k))]; r[0] = 1; g(r[0]); }");
|
|
509
|
-
testing::assert_contains(&output, &[
|
|
535
|
+
testing::assert_contains(&output, &["7 ^ k ^ (7 ^ k);", "r_0 = 1;", "g(r_0);"]);
|
|
510
536
|
testing::assert_lacks(&output, &["r_0 = void"]);
|
|
511
537
|
// A creation in a loop resets the slots on every iteration.
|
|
512
538
|
let output =
|
|
513
539
|
transform("function f() { var r; while (g()) { r = [void 0]; h(r[0]); r[0] = 1; } }");
|
|
514
|
-
testing::assert_contains(&output, &[
|
|
540
|
+
testing::assert_contains(&output, &["r_0 = void 0;", "h(r_0);", "r_0 = 1;"]);
|
|
515
541
|
for kept in [
|
|
516
542
|
"function f() { var r; r = [1]; g(r); }",
|
|
517
543
|
"function f() { var r; r = [1]; r[0](); }",
|