cfsolve 0.1.1 → 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 +18 -0
- data/README.md +10 -9
- 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 +10 -8
- 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 +2570 -1894
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
- 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 -35
- data/vendor/cfsolve/examples/build_profile.rs +17 -15
- data/vendor/cfsolve/examples/capture_session.rs +37 -0
- data/vendor/cfsolve/examples/check_answers.rs +66 -0
- data/vendor/cfsolve/examples/compare_session.rs +189 -0
- 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 +6 -3
- 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 +2570 -1894
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
- data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
- data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
- 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/profile.rs +7 -18
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/recorded.rs +42 -7
- 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 +132 -0
- data/vendor/cfsolve/src/challenge/installed.rs +127 -269
- 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 +175 -35
- 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 +236 -122
- 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 +201 -205
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
- 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 +361 -322
- 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 -32
- data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
- 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 +9 -1
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -254
- data/vendor/cfsolve/src/js/objects.rs +9 -2
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -92
- data/vendor/cfsolve/src/listing/query.rs +26 -291
- data/vendor/cfsolve/src/listing.rs +0 -1
- 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 +19 -10
- data/vendor/cfsolve/src/session/probes.rs +160 -125
- 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/timing.rs +58 -53
- data/vendor/cfsolve/src/session/widget.rs +5 -6
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
- data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
- data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
- data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
- data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
- 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/native.rs +2 -1
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
- data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
- data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
- data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
- data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
- data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/records.rs +4 -13
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +98 -100
- data/vendor/cfsolve/src/stage2/registry.rs +41 -34
- data/vendor/cfsolve/src/stage2/replay.rs +182 -254
- data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +152 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
- data/vendor/cfsolve/src/stage2.rs +4 -1
- data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
- 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 +67 -68
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
- data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
- data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
- data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
- data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
- 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 +605 -330
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
- 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 +16 -3
- data/vendor/cfsolve/src/vm/machine.rs +58 -47
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
- data/vendor/cfsolve/src/vm/session.rs +197 -110
- data/vendor/cfsolve/src/vm/value.rs +35 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
- metadata +106 -183
- 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/vendor/cfsolve/src/listing/normalize.rs +0 -264
- data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
- data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
- data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
- data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
- /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,50 +8,58 @@
|
|
|
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.
|
|
15
15
|
//!
|
|
16
16
|
//! Undefined slots need no assignment if the literal runs at most once per call, in the
|
|
17
|
-
//! declaring function and outside loops. The replacement locals already start undefined.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
use
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
//! declaring function and outside loops. The replacement locals already start undefined. A
|
|
18
|
+
//! `void` element there keeps only its operand, so a constant hidden as `void (k ^ x ^ (k ^ x))`
|
|
19
|
+
//! leaves the slot's later write as its local's only one, which copy propagation can inline.
|
|
20
|
+
|
|
21
|
+
use std::mem;
|
|
22
|
+
|
|
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,
|
|
26
30
|
};
|
|
27
|
-
use
|
|
28
|
-
|
|
29
|
-
use
|
|
30
|
-
use
|
|
31
|
-
use
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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();
|
|
36
43
|
let mut uses = Uses {
|
|
37
|
-
|
|
44
|
+
analysis,
|
|
38
45
|
created: HashMap::default(),
|
|
39
46
|
slots: HashMap::default(),
|
|
40
|
-
|
|
41
|
-
function: 0,
|
|
42
|
-
functions: 0,
|
|
47
|
+
function: root,
|
|
43
48
|
loops: 0,
|
|
49
|
+
discarded: false,
|
|
44
50
|
};
|
|
45
|
-
|
|
51
|
+
uses.visit_program(program);
|
|
52
|
+
let mut slots = uses.slots;
|
|
46
53
|
let mut arrays = HashMap::default();
|
|
47
54
|
for (id, created) in uses.created {
|
|
48
|
-
let
|
|
49
|
-
let [creation] = &created[..] else {
|
|
55
|
+
let [creation] = created.as_slice() else {
|
|
50
56
|
continue;
|
|
51
57
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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)
|
|
55
63
|
|| bindings.is_parameter(&id)
|
|
56
64
|
|| slots.opaque
|
|
57
65
|
|| slots.accesses != bindings.references(&id)
|
|
@@ -59,408 +67,435 @@ pub(super) fn run(program: &mut Program, analysis: &mut Analysis) -> bool {
|
|
|
59
67
|
.read
|
|
60
68
|
.iter()
|
|
61
69
|
.chain(&slots.written)
|
|
62
|
-
.any(|&
|
|
70
|
+
.any(|&index| index >= creation.length)
|
|
63
71
|
{
|
|
64
72
|
continue;
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
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)
|
|
73
80
|
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
assign_undefined: !creation.once,
|
|
82
|
-
},
|
|
83
|
-
);
|
|
81
|
+
});
|
|
82
|
+
let array = Array {
|
|
83
|
+
locals: locals.collect(),
|
|
84
|
+
read: slots.read,
|
|
85
|
+
reset: !creation.once,
|
|
86
|
+
};
|
|
87
|
+
arrays.insert(id, array);
|
|
84
88
|
}
|
|
85
89
|
if arrays.is_empty() {
|
|
86
90
|
return false;
|
|
87
91
|
}
|
|
88
|
-
|
|
92
|
+
Split {
|
|
93
|
+
analysis,
|
|
89
94
|
arrays: &arrays,
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
}
|
|
96
|
+
.visit_program(program);
|
|
92
97
|
true
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
///
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
match element {
|
|
99
|
-
None => true,
|
|
100
|
-
// Constant arithmetic has no side effects, even when nested.
|
|
101
|
-
Some(Expr::Unary(unary)) => {
|
|
102
|
-
unary.op == UnaryOp::Void
|
|
103
|
-
&& (ast::fold_number(&unary.arg, &|_| None).is_some()
|
|
104
|
-
|| !effects::may_have_effects(&unary.arg, globals))
|
|
105
|
-
}
|
|
106
|
-
Some(Expr::Ident(identifier)) => globals.is(identifier, "undefined"),
|
|
107
|
-
Some(_) => false,
|
|
108
|
-
}
|
|
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))
|
|
109
103
|
}
|
|
110
104
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
))
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let index = &member.prop.as_computed()?.expr;
|
|
123
|
-
let slot = ast::array_index(ast::fold_number(index, &|_| None)?)?;
|
|
124
|
-
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)
|
|
125
122
|
}
|
|
126
123
|
|
|
124
|
+
/// An array-literal creation and the context that executes it.
|
|
127
125
|
struct Creation {
|
|
128
126
|
length: usize,
|
|
129
|
-
/// Slots initialized to values other than undefined.
|
|
127
|
+
/// Slots initialized to values other than effect-free undefined.
|
|
130
128
|
defined: HashSet<usize>,
|
|
131
|
-
function:
|
|
132
|
-
///
|
|
129
|
+
function: ScopeId,
|
|
130
|
+
/// Creation runs outside loops and at most once per invocation of its declaring function.
|
|
133
131
|
once: bool,
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
#[derive(Default)]
|
|
137
135
|
struct Slots {
|
|
138
|
-
///
|
|
136
|
+
/// Compared with the binding's reference count to detect other uses.
|
|
139
137
|
accesses: usize,
|
|
140
|
-
/// Slots read, updated, or assigned with an operator other than `=`.
|
|
138
|
+
/// Slots read, updated, or assigned with an operator other than plain `=`.
|
|
141
139
|
read: HashSet<usize>,
|
|
142
140
|
written: HashSet<usize>,
|
|
143
|
-
///
|
|
141
|
+
/// A slot is called, tagged, or deleted; these uses depend on the array itself.
|
|
144
142
|
opaque: bool,
|
|
145
143
|
}
|
|
146
144
|
|
|
147
|
-
/// Collects array assignments
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
globals: Globals,
|
|
145
|
+
/// Collects discarded array assignments, declared initializers, and slot accesses.
|
|
146
|
+
struct Uses<'b, 'a> {
|
|
147
|
+
analysis: &'b Analysis<'a>,
|
|
151
148
|
created: HashMap<Id, Vec<Creation>>,
|
|
152
149
|
slots: HashMap<Id, Slots>,
|
|
153
|
-
|
|
154
|
-
/// Current function number in traversal order; 0 denotes the script.
|
|
155
|
-
function: usize,
|
|
156
|
-
functions: usize,
|
|
150
|
+
function: ScopeId,
|
|
157
151
|
loops: usize,
|
|
152
|
+
/// The visited expression's value is discarded.
|
|
153
|
+
discarded: bool,
|
|
158
154
|
}
|
|
159
155
|
|
|
160
|
-
impl Uses {
|
|
161
|
-
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
|
+
}
|
|
162
161
|
let mut defined = HashSet::default();
|
|
163
|
-
for (
|
|
164
|
-
if element
|
|
165
|
-
.
|
|
166
|
-
.is_some_and(|element| element.spread.is_some())
|
|
167
|
-
{
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if !is_undefined(element.as_ref().map(|element| &*element.expr), self.globals) {
|
|
171
|
-
defined.insert(slot);
|
|
162
|
+
for (index, element) in array.elements.iter().enumerate() {
|
|
163
|
+
if !undefined(element.as_expression(), self.analysis) {
|
|
164
|
+
defined.insert(index);
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
|
-
|
|
175
|
-
length: array.
|
|
167
|
+
self.created.entry(id).or_default().push(Creation {
|
|
168
|
+
length: array.elements.len(),
|
|
176
169
|
defined,
|
|
177
170
|
function: self.function,
|
|
178
171
|
once: self.loops == 0,
|
|
179
|
-
};
|
|
180
|
-
self.created.entry(id).or_default().push(creation);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/// Records an array assignment whose value is discarded by a statement. Sequence expressions
|
|
184
|
-
/// handle their other operands separately.
|
|
185
|
-
fn statement(&mut self, expression: &Expr) {
|
|
186
|
-
let last = expression
|
|
187
|
-
.as_seq()
|
|
188
|
-
.and_then(|sequence| sequence.exprs.last());
|
|
189
|
-
self.discarded(last.map_or(expression, |last| &**last));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/// Records `binding = [...]`.
|
|
193
|
-
fn discarded(&mut self, expression: &Expr) {
|
|
194
|
-
if let Some((id, Expr::Array(array))) = ast::assignment(expression) {
|
|
195
|
-
self.create(id, array);
|
|
196
|
-
}
|
|
172
|
+
});
|
|
197
173
|
}
|
|
198
174
|
|
|
199
|
-
fn access(&mut self, member:
|
|
200
|
-
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) {
|
|
201
177
|
let slots = self.slots.entry(id).or_default();
|
|
202
178
|
slots.accesses += 1;
|
|
203
179
|
if read {
|
|
204
|
-
slots.read.insert(
|
|
180
|
+
slots.read.insert(index);
|
|
205
181
|
} else {
|
|
206
|
-
slots.written.insert(
|
|
182
|
+
slots.written.insert(index);
|
|
207
183
|
}
|
|
208
184
|
}
|
|
209
185
|
}
|
|
210
186
|
|
|
211
|
-
fn opaque(&mut self, expression: &
|
|
212
|
-
if let Some(
|
|
213
|
-
|
|
214
|
-
{
|
|
215
|
-
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
|
|
216
190
|
}
|
|
217
191
|
}
|
|
218
192
|
|
|
219
|
-
fn
|
|
220
|
-
self.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
visit(self);
|
|
224
|
-
self.function = function;
|
|
225
|
-
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;
|
|
226
197
|
}
|
|
227
198
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
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;
|
|
232
207
|
}
|
|
233
208
|
}
|
|
234
209
|
|
|
235
|
-
impl Visit for Uses {
|
|
236
|
-
fn
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
for expression in discarded {
|
|
244
|
-
self.discarded(expression);
|
|
245
|
-
}
|
|
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)
|
|
246
218
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
self.declared.insert(name.to_id(), self.function);
|
|
253
|
-
if let Some(Expr::Array(array)) = declarator.init.as_deref() {
|
|
254
|
-
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)
|
|
255
224
|
}
|
|
225
|
+
} else {
|
|
226
|
+
walk::walk_expression(self, expression)
|
|
256
227
|
}
|
|
257
|
-
|
|
228
|
+
self.discarded = discarded;
|
|
258
229
|
}
|
|
259
230
|
|
|
260
|
-
fn
|
|
261
|
-
|
|
262
|
-
self.access(member, /* read= */ true);
|
|
263
|
-
}
|
|
264
|
-
expression.visit_children_with(self);
|
|
231
|
+
fn visit_expression_statement(&mut self, statement: &ExpressionStatement<'a>) {
|
|
232
|
+
self.expression(&statement.expression, true)
|
|
265
233
|
}
|
|
266
234
|
|
|
267
|
-
fn
|
|
268
|
-
if let
|
|
269
|
-
|
|
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)
|
|
270
240
|
}
|
|
271
|
-
|
|
241
|
+
walk::walk_variable_declarator(self, declarator)
|
|
272
242
|
}
|
|
273
243
|
|
|
274
|
-
fn
|
|
275
|
-
|
|
276
|
-
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)
|
|
277
255
|
}
|
|
278
|
-
|
|
256
|
+
self.visit_expression(&assignment.right)
|
|
279
257
|
}
|
|
280
258
|
|
|
281
|
-
fn
|
|
282
|
-
self.
|
|
283
|
-
|
|
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)
|
|
284
262
|
}
|
|
285
263
|
|
|
286
|
-
fn
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
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)
|
|
291
267
|
}
|
|
292
268
|
|
|
293
|
-
fn
|
|
294
|
-
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)
|
|
295
272
|
}
|
|
296
273
|
|
|
297
|
-
fn
|
|
298
|
-
|
|
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)
|
|
299
279
|
}
|
|
300
280
|
|
|
301
|
-
fn
|
|
302
|
-
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
|
+
})
|
|
303
285
|
}
|
|
304
286
|
|
|
305
|
-
fn
|
|
306
|
-
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
|
+
})
|
|
307
291
|
}
|
|
308
292
|
|
|
309
|
-
fn
|
|
310
|
-
|
|
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;
|
|
311
304
|
}
|
|
312
305
|
|
|
313
|
-
///
|
|
314
|
-
fn
|
|
315
|
-
if let Some(
|
|
316
|
-
|
|
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
|
+
}
|
|
317
313
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
fn visit_stmt(&mut self, statement: &Stmt) {
|
|
327
|
-
if matches!(
|
|
328
|
-
statement,
|
|
329
|
-
Stmt::ForIn(_) | Stmt::ForOf(_) | Stmt::While(_) | Stmt::DoWhile(_)
|
|
330
|
-
) {
|
|
331
|
-
self.in_loop(|uses| statement.visit_children_with(uses));
|
|
332
|
-
} else {
|
|
333
|
-
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)
|
|
334
320
|
}
|
|
321
|
+
self.visit_statement(&for_loop.body);
|
|
322
|
+
self.loops -= 1;
|
|
335
323
|
}
|
|
336
324
|
}
|
|
337
325
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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>>>,
|
|
341
330
|
read: HashSet<usize>,
|
|
342
|
-
|
|
331
|
+
/// Creation can repeat, so even undefined slots need explicit assignments.
|
|
332
|
+
reset: bool,
|
|
343
333
|
}
|
|
344
334
|
|
|
345
|
-
struct Split<'
|
|
346
|
-
|
|
347
|
-
|
|
335
|
+
struct Split<'b, 'a> {
|
|
336
|
+
analysis: &'b mut Analysis<'a>,
|
|
337
|
+
arrays: &'b HashMap<Id, Array<'a>>,
|
|
348
338
|
}
|
|
349
339
|
|
|
350
|
-
impl Split<'
|
|
351
|
-
///
|
|
352
|
-
fn
|
|
353
|
-
let
|
|
354
|
-
|
|
355
|
-
let element = element.take().map(|element| element.expr);
|
|
356
|
-
if let Some(local) = local
|
|
357
|
-
&& (array.assign_undefined || !is_undefined(element.as_deref(), self.globals))
|
|
358
|
-
{
|
|
359
|
-
let value = element.unwrap_or_else(|| Box::new(undefined()));
|
|
360
|
-
assignments.push((local.clone(), value));
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
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()
|
|
364
345
|
}
|
|
365
346
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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;
|
|
388
379
|
}
|
|
389
|
-
// The array binding is assigned only when the array is created.
|
|
390
|
-
let array = self.arrays.get(&assignment.left.as_ident()?.to_id())?;
|
|
391
|
-
let Expr::Array(literal) = &mut *assignment.right else {
|
|
392
|
-
return None;
|
|
393
|
-
};
|
|
394
|
-
let mut assignments: Vec<Box<Expr>> = self
|
|
395
|
-
.initial(array, literal)
|
|
396
|
-
.into_iter()
|
|
397
|
-
.map(|(local, value)| {
|
|
398
|
-
Box::new(Expr::Assign(AssignExpr {
|
|
399
|
-
span: DUMMY_SP,
|
|
400
|
-
op: AssignOp::Assign,
|
|
401
|
-
left: AssignTarget::Simple(SimpleAssignTarget::Ident(local.into())),
|
|
402
|
-
right: value,
|
|
403
|
-
}))
|
|
404
|
-
})
|
|
405
|
-
.collect();
|
|
406
|
-
Some(match assignments.len() {
|
|
407
|
-
0 => undefined(),
|
|
408
|
-
1 => *assignments.remove(0),
|
|
409
|
-
_ => Expr::Seq(SeqExpr {
|
|
410
|
-
span: assignment.span,
|
|
411
|
-
exprs: assignments,
|
|
412
|
-
}),
|
|
413
|
-
})
|
|
414
380
|
}
|
|
415
|
-
|
|
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
|
+
));
|
|
416
398
|
}
|
|
399
|
+
initial
|
|
417
400
|
}
|
|
418
401
|
}
|
|
419
402
|
|
|
420
|
-
impl VisitMut for Split<'_> {
|
|
421
|
-
fn
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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);
|
|
426
410
|
}
|
|
427
411
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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);
|
|
434
419
|
}
|
|
435
420
|
|
|
436
|
-
fn
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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);
|
|
446
462
|
continue;
|
|
447
463
|
};
|
|
448
|
-
|
|
449
|
-
Some(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
+
}
|
|
462
487
|
}
|
|
463
|
-
|
|
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
|
+
});
|
|
464
499
|
}
|
|
465
500
|
}
|
|
466
501
|
|
|
@@ -470,7 +505,7 @@ mod tests {
|
|
|
470
505
|
|
|
471
506
|
#[test]
|
|
472
507
|
fn splits_arrays_reached_only_through_constant_slots() {
|
|
473
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
508
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
474
509
|
let output = transform(
|
|
475
510
|
"function f(x) {
|
|
476
511
|
var r, a, s = [1, void 0];
|
|
@@ -481,7 +516,6 @@ mod tests {
|
|
|
481
516
|
);
|
|
482
517
|
testing::assert_contains(
|
|
483
518
|
&output,
|
|
484
|
-
&[],
|
|
485
519
|
&[
|
|
486
520
|
"var r_0, a, s_0 = 1, s_1;",
|
|
487
521
|
"a = g(); g(r_0++, s_0, s_1); h();",
|
|
@@ -493,12 +527,17 @@ mod tests {
|
|
|
493
527
|
let output = transform(
|
|
494
528
|
"function f() { var r, i; for (r = [void 0], i = 0; i < 2; i++) { h(r[0]); r[0] = i; } }",
|
|
495
529
|
);
|
|
496
|
-
testing::assert_contains(&output, &[
|
|
530
|
+
testing::assert_contains(&output, &["h(r_0);", "r_0 = i;"]);
|
|
497
531
|
testing::assert_lacks(&output, &["r_0 = void 0", "["]);
|
|
532
|
+
// A `void` element runs its operand without writing the local.
|
|
533
|
+
let output =
|
|
534
|
+
transform("function f() { var r; r = [void (7 ^ k ^ (7 ^ k))]; r[0] = 1; g(r[0]); }");
|
|
535
|
+
testing::assert_contains(&output, &["7 ^ k ^ (7 ^ k);", "r_0 = 1;", "g(r_0);"]);
|
|
536
|
+
testing::assert_lacks(&output, &["r_0 = void"]);
|
|
498
537
|
// A creation in a loop resets the slots on every iteration.
|
|
499
538
|
let output =
|
|
500
539
|
transform("function f() { var r; while (g()) { r = [void 0]; h(r[0]); r[0] = 1; } }");
|
|
501
|
-
testing::assert_contains(&output, &[
|
|
540
|
+
testing::assert_contains(&output, &["r_0 = void 0;", "h(r_0);", "r_0 = 1;"]);
|
|
502
541
|
for kept in [
|
|
503
542
|
"function f() { var r; r = [1]; g(r); }",
|
|
504
543
|
"function f() { var r; r = [1]; r[0](); }",
|