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
|
@@ -2,595 +2,418 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! ```js
|
|
4
4
|
//! h = { add: function (a, b) { return a + b; }, key: "name" };
|
|
5
|
-
//! h.add(x, 1); h.key; // becomes
|
|
5
|
+
//! h.add(x, 1); h.key; // becomes x + 1; "name"
|
|
6
6
|
//! ```
|
|
7
7
|
//!
|
|
8
8
|
//! Requires each property to be defined once on an object that does not escape (see
|
|
9
|
-
//! [`Properties::
|
|
10
|
-
//! [`
|
|
9
|
+
//! [`Properties::stable`]), and calls that preserve argument evaluation and order (see
|
|
10
|
+
//! [`substitute`]). Hoisted function bodies use only objects known wherever they can be called
|
|
11
11
|
//! (see [`hoisting`]).
|
|
12
12
|
|
|
13
|
-
use std::iter;
|
|
14
13
|
use std::rc::Rc;
|
|
14
|
+
use std::{iter, mem};
|
|
15
15
|
|
|
16
|
-
use
|
|
17
|
-
use
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
FnExpr, ForStmt, Function, Id, Ident, Lit, MemberExpr, MemberProp, MetaPropExpr, Number,
|
|
21
|
-
ObjectLit, Program, ReturnStmt, SeqExpr, SimpleAssignTarget, Stmt, Super, ThisExpr, UnaryOp,
|
|
22
|
-
VarDeclOrExpr,
|
|
16
|
+
use oxc::allocator::{CloneIn, GetAllocator, Vec as ArenaVec};
|
|
17
|
+
use oxc::ast::ast::{
|
|
18
|
+
Argument, AssignmentExpression, BlockStatement, Expression, Function, IdentifierReference,
|
|
19
|
+
ObjectPropertyKind, Program, SequenceExpression, Statement, VariableDeclarator,
|
|
23
20
|
};
|
|
24
|
-
use
|
|
25
|
-
|
|
26
|
-
use
|
|
27
|
-
use
|
|
28
|
-
|
|
29
|
-
use super::analysis::
|
|
30
|
-
use
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let mut inline = InlineHelpers {
|
|
38
|
-
bindings,
|
|
39
|
-
properties,
|
|
40
|
-
globals,
|
|
41
|
-
hoisting: Hoisting::default(),
|
|
42
|
-
lists: 0,
|
|
43
|
-
defined_in: HashMap::default(),
|
|
44
|
-
changed: false,
|
|
45
|
-
};
|
|
46
|
-
program.visit_mut_with(&mut inline);
|
|
47
|
-
inline.changed
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/// Properties of one helper object that can replace property reads.
|
|
21
|
+
use oxc::ast_visit::{Visit, VisitMut, walk, walk_mut};
|
|
22
|
+
use oxc::syntax::operator::{AssignmentOperator, UnaryOperator};
|
|
23
|
+
use oxc::syntax::scope::ScopeFlags;
|
|
24
|
+
use oxc_ecmascript::side_effects::MayHaveSideEffects;
|
|
25
|
+
|
|
26
|
+
use super::analysis::effects::Effects;
|
|
27
|
+
use super::analysis::hoisting::{self, Facts, Hoisted, Hoisting, List};
|
|
28
|
+
use super::analysis::properties::Properties;
|
|
29
|
+
use super::analysis::unconditional::Unconditional;
|
|
30
|
+
use super::analysis::{Analysis, Id};
|
|
31
|
+
use super::{HashMap, ast};
|
|
32
|
+
|
|
33
|
+
/// The helper objects and functions known at one point, indexed by binding identity.
|
|
51
34
|
#[derive(Clone, Default)]
|
|
52
|
-
struct
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
impl ObjectProperties {
|
|
58
|
-
/// Every inlinable property of a helper object literal.
|
|
59
|
-
fn collect(object: &ObjectLit) -> Self {
|
|
60
|
-
let mut properties = Self::default();
|
|
61
|
-
for property in ast::key_values(object) {
|
|
62
|
-
if let Some(name) = analysis::prop_key(&property.key) {
|
|
63
|
-
properties.insert(name, &property.value);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
properties
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// Records substitutable properties. Leaves unsupported properties as object reads.
|
|
70
|
-
fn insert(&mut self, name: Atom, value: &Expr) {
|
|
71
|
-
match value {
|
|
72
|
-
Expr::Fn(function) => {
|
|
73
|
-
self.functions.insert(name, function.clone());
|
|
74
|
-
}
|
|
75
|
-
// A regular expression carries state and identity, so it cannot
|
|
76
|
-
// stand in for every read.
|
|
77
|
-
Expr::Lit(literal) if !matches!(literal, Lit::Regex(_)) => {
|
|
78
|
-
self.literals.insert(name, value.clone());
|
|
79
|
-
}
|
|
80
|
-
Expr::Tpl(template) if template.exprs.is_empty() => {
|
|
81
|
-
self.literals.insert(name, value.clone());
|
|
82
|
-
}
|
|
83
|
-
_ => {}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
35
|
+
struct Helpers<'a> {
|
|
36
|
+
/// Known object properties, shared between snapshots until a new definition extends them.
|
|
37
|
+
objects: HashMap<Id, Rc<HashMap<&'a str, &'a Expression<'a>>>>,
|
|
38
|
+
/// Single-return functions assigned to bindings with exactly one write.
|
|
39
|
+
functions: HashMap<Id, &'a Function<'a>>,
|
|
86
40
|
}
|
|
87
41
|
|
|
88
|
-
|
|
89
|
-
#[derive(Clone, Default)]
|
|
90
|
-
struct Helpers {
|
|
91
|
-
objects: HashMap<Id, Rc<ObjectProperties>>,
|
|
92
|
-
/// Functions assigned to a binding written once.
|
|
93
|
-
functions: HashMap<Id, Rc<FnExpr>>,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/// At a control-flow join, keeps the objects and properties known on both paths.
|
|
97
|
-
impl HoistFacts for Helpers {
|
|
42
|
+
impl Facts for Helpers<'_> {
|
|
98
43
|
fn meet(&mut self, other: &Self) {
|
|
99
44
|
self.objects.retain(|id, properties| {
|
|
100
|
-
let Some(
|
|
45
|
+
let Some(other) = other.objects.get(id) else {
|
|
101
46
|
return false;
|
|
102
47
|
};
|
|
103
|
-
if !Rc::ptr_eq(properties,
|
|
104
|
-
|
|
105
|
-
properties
|
|
106
|
-
.functions
|
|
107
|
-
.retain(|name, _| theirs.functions.contains_key(name));
|
|
108
|
-
properties
|
|
109
|
-
.literals
|
|
110
|
-
.retain(|name, _| theirs.literals.contains_key(name));
|
|
48
|
+
if !Rc::ptr_eq(properties, other) {
|
|
49
|
+
Rc::make_mut(properties).retain(|key, _| other.contains_key(key))
|
|
111
50
|
}
|
|
112
51
|
true
|
|
113
52
|
});
|
|
114
|
-
self.functions.meet(&other.functions)
|
|
53
|
+
self.functions.meet(&other.functions)
|
|
115
54
|
}
|
|
116
55
|
}
|
|
117
56
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
properties
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
57
|
+
/// Tracks helper objects and aliases only while their bindings have exactly one write.
|
|
58
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
59
|
+
let properties = Properties::collect(program, analysis);
|
|
60
|
+
let mut inline = Inline {
|
|
61
|
+
analysis,
|
|
62
|
+
properties: &properties,
|
|
63
|
+
hoisting: Hoisting::default(),
|
|
64
|
+
lists: 0,
|
|
65
|
+
list: 0,
|
|
66
|
+
defined_in: HashMap::default(),
|
|
67
|
+
changed: false,
|
|
68
|
+
};
|
|
69
|
+
inline.visit_program(program);
|
|
70
|
+
inline.changed
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
struct Inline<'b, 'a> {
|
|
74
|
+
analysis: &'b Analysis<'a>,
|
|
75
|
+
properties: &'b Properties<'a>,
|
|
76
|
+
/// Aliases receive the properties known when their assignment runs.
|
|
77
|
+
hoisting: Hoisting<Rc<Helpers<'a>>>,
|
|
78
|
+
/// Counts entered statement lists and sequences, to identify each one.
|
|
125
79
|
lists: usize,
|
|
126
|
-
/// The statement list or sequence
|
|
80
|
+
/// The innermost statement list or sequence being visited.
|
|
81
|
+
list: usize,
|
|
82
|
+
/// The list or sequence that defines each object; only definitions in that same list may
|
|
83
|
+
/// extend it.
|
|
127
84
|
defined_in: HashMap<Id, usize>,
|
|
128
85
|
changed: bool,
|
|
129
86
|
}
|
|
130
87
|
|
|
131
|
-
impl
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
88
|
+
impl<'a> Hoisted<'a> for Inline<'_, 'a> {
|
|
89
|
+
type Facts = Rc<Helpers<'a>>;
|
|
90
|
+
|
|
91
|
+
fn analysis(&self) -> &Analysis<'a> {
|
|
92
|
+
self.analysis
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fn hoisting(&mut self) -> &mut Hoisting<Self::Facts> {
|
|
96
|
+
&mut self.hoisting
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
impl<'a> Inline<'_, 'a> {
|
|
101
|
+
fn save_function(&mut self, id: Id, function: &Function<'a>) {
|
|
102
|
+
let function = self.analysis.save(function);
|
|
103
|
+
self.facts_mut().functions.insert(id, function);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// Unshares the current facts before a change.
|
|
107
|
+
fn facts_mut(&mut self) -> &mut Helpers<'a> {
|
|
108
|
+
Rc::make_mut(&mut self.hoisting.facts)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Records a single-write object, function, or alias with the properties known at this
|
|
112
|
+
/// assignment.
|
|
113
|
+
fn record(&mut self, id: Id, value: &Expression<'a>) {
|
|
114
|
+
if !self.analysis.bindings.is_written_once(&id) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
match value.get_inner_expression() {
|
|
118
|
+
Expression::ObjectExpression(object) => {
|
|
119
|
+
let mut properties = HashMap::default();
|
|
120
|
+
for property in &object.properties {
|
|
121
|
+
if let ObjectPropertyKind::ObjectProperty(property) = property
|
|
122
|
+
&& let Some(key) = ast::key(&property.key, property.computed)
|
|
123
|
+
{
|
|
124
|
+
properties.insert(key, self.analysis.save(&property.value));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
self.facts_mut().objects.insert(id, Rc::new(properties));
|
|
147
128
|
}
|
|
148
|
-
|
|
149
|
-
self.
|
|
150
|
-
statement.cases.visit_mut_with(self);
|
|
129
|
+
Expression::FunctionExpression(function) if ast::returned(function).is_some() => {
|
|
130
|
+
self.save_function(id, function)
|
|
151
131
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
132
|
+
Expression::Identifier(identifier) => {
|
|
133
|
+
if let Some(source) = self.analysis.id(identifier)
|
|
134
|
+
&& let Some(object) = self.hoisting.facts.objects.get(&source).cloned()
|
|
135
|
+
{
|
|
136
|
+
self.facts_mut().objects.insert(id, object);
|
|
158
137
|
}
|
|
159
138
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
body,
|
|
165
|
-
..
|
|
166
|
-
}) => {
|
|
167
|
-
self.top_level(init, list);
|
|
168
|
-
test.visit_mut_with(self);
|
|
169
|
-
update.visit_mut_with(self);
|
|
170
|
-
body.visit_mut_with(self);
|
|
139
|
+
_ => {
|
|
140
|
+
if let Some(Expression::FunctionExpression(function)) = self.stable_value(value) {
|
|
141
|
+
self.save_function(id, function)
|
|
142
|
+
}
|
|
171
143
|
}
|
|
172
|
-
statement => statement.visit_mut_with(self),
|
|
173
144
|
}
|
|
174
145
|
}
|
|
175
146
|
|
|
176
|
-
///
|
|
177
|
-
///
|
|
178
|
-
fn
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
expression.visit_mut_with(self);
|
|
186
|
-
let Expr::Assign(assignment) = expression else {
|
|
187
|
-
return;
|
|
188
|
-
};
|
|
189
|
-
if let Some(target) = assignment.left.as_ident()
|
|
190
|
-
&& self.hoisting.facts.objects.contains_key(&target.to_id())
|
|
191
|
-
{
|
|
192
|
-
self.defined_in.insert(target.to_id(), list);
|
|
193
|
-
} else if assignment.op == AssignOp::Assign
|
|
194
|
-
&& let AssignTarget::Simple(SimpleAssignTarget::Member(member)) = &assignment.left
|
|
195
|
-
&& let Some(identifier) = member.obj.as_ident()
|
|
196
|
-
&& let Some(property) = analysis::member_key(&member.prop)
|
|
197
|
-
&& self.defined_in.get(&identifier.to_id()) == Some(&list)
|
|
198
|
-
&& let Some(object) = self.hoisting.facts.objects.get_mut(&identifier.to_id())
|
|
199
|
-
{
|
|
200
|
-
// Only property assignments beside the object's definition safely extend it.
|
|
201
|
-
// Elsewhere, a read might run before the assignment.
|
|
202
|
-
Rc::make_mut(object).insert(property, &assignment.right);
|
|
147
|
+
/// Resolves a static member read only when both property stability and execution-order
|
|
148
|
+
/// facts hold.
|
|
149
|
+
fn stable_value(&self, expression: &Expression<'a>) -> Option<&'a Expression<'a>> {
|
|
150
|
+
let member = expression.as_member_expression()?;
|
|
151
|
+
let id = self.analysis.expression_id(member.object())?;
|
|
152
|
+
let key = member.static_property_name()?.as_str()?;
|
|
153
|
+
if !self.properties.stable(id, key, self.analysis) {
|
|
154
|
+
return None;
|
|
203
155
|
}
|
|
156
|
+
self.hoisting.facts.objects.get(&id)?.get(key).copied()
|
|
204
157
|
}
|
|
205
158
|
|
|
206
|
-
///
|
|
207
|
-
fn
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
159
|
+
/// Returns a known helper function that a call can inline.
|
|
160
|
+
fn callee(&self, callee: &Expression<'a>) -> Option<&'a Function<'a>> {
|
|
161
|
+
let Some(reference) = callee.get_identifier_reference() else {
|
|
162
|
+
return match self.stable_value(callee)? {
|
|
163
|
+
Expression::FunctionExpression(function) => Some(&**function),
|
|
164
|
+
_ => None,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
let id = self.analysis.id(reference)?;
|
|
168
|
+
let function = *self.hoisting.facts.functions.get(&id)?;
|
|
169
|
+
names_only(function, id, self.analysis).then_some(function)
|
|
214
170
|
}
|
|
215
171
|
}
|
|
216
172
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
173
|
+
/// Only property definitions in the object's defining list extend its known properties.
|
|
174
|
+
impl<'a> Unconditional<'a> for Inline<'_, 'a> {
|
|
175
|
+
fn assigned(&mut self, assignment: &AssignmentExpression<'a>) {
|
|
176
|
+
if let Some(id) = self.analysis.target_id(&assignment.left) {
|
|
177
|
+
self.record(id, &assignment.right);
|
|
178
|
+
self.defined_in.insert(id, self.list);
|
|
179
|
+
} else if let Some(member) = assignment.left.as_member_expression()
|
|
180
|
+
&& let Some(id) = self.analysis.expression_id(member.object())
|
|
181
|
+
&& let Some(key) = member.static_property_name().and_then(|key| key.as_str())
|
|
182
|
+
&& self.defined_in.get(&id) == Some(&self.list)
|
|
183
|
+
&& self.hoisting.facts.objects.contains_key(&id)
|
|
184
|
+
{
|
|
185
|
+
let value = self.analysis.save(&assignment.right);
|
|
186
|
+
let objects = &mut self.facts_mut().objects;
|
|
187
|
+
let properties = objects.get_mut(&id).expect("the object is known");
|
|
188
|
+
Rc::make_mut(properties).insert(key, value);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
220
191
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
&&
|
|
192
|
+
fn declared(&mut self, declarator: &VariableDeclarator<'a>) {
|
|
193
|
+
if let Some(id) = ast::pattern_id(&declarator.id)
|
|
194
|
+
&& let Some(value) = &declarator.init
|
|
224
195
|
{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.right
|
|
228
|
-
.as_member()
|
|
229
|
-
.and_then(|member| self.stable(member))
|
|
230
|
-
.and_then(|(object, property)| object.functions.get(&property))
|
|
231
|
-
.cloned();
|
|
232
|
-
// Track object definitions, helper functions, and copies of objects and helper methods
|
|
233
|
-
// by binding.
|
|
234
|
-
let helpers = &mut self.hoisting.facts;
|
|
235
|
-
if let Some(method) = method {
|
|
236
|
-
helpers.functions.insert(target, Rc::new(method));
|
|
237
|
-
} else if let Some(object) = assignment.right.as_object() {
|
|
238
|
-
let properties = Rc::new(ObjectProperties::collect(object));
|
|
239
|
-
helpers.objects.insert(target, properties);
|
|
240
|
-
} else if let Some(function) = assignment.right.as_fn_expr() {
|
|
241
|
-
helpers.functions.insert(target, Rc::new(function.clone()));
|
|
242
|
-
} else if let Some(alias) = assignment.right.as_ident()
|
|
243
|
-
&& let Some(object) = helpers.objects.get(&alias.to_id()).cloned()
|
|
244
|
-
{
|
|
245
|
-
helpers.objects.insert(target, object);
|
|
246
|
-
}
|
|
196
|
+
self.record(id, value);
|
|
197
|
+
self.defined_in.insert(id, self.list);
|
|
247
198
|
}
|
|
248
199
|
}
|
|
200
|
+
}
|
|
249
201
|
|
|
250
|
-
|
|
251
|
-
fn
|
|
202
|
+
impl<'a> VisitMut<'a> for Inline<'_, 'a> {
|
|
203
|
+
fn visit_statements(&mut self, statements: &mut ArenaVec<'a, Statement<'a>>) {
|
|
252
204
|
self.lists += 1;
|
|
253
|
-
let
|
|
254
|
-
// Function declarations are available from the start of a function body. Top-level
|
|
255
|
-
// declarations can be replaced by other scripts.
|
|
205
|
+
let outer = mem::replace(&mut self.list, self.lists);
|
|
256
206
|
if self.hoisting.list == List::FunctionBody {
|
|
257
207
|
for statement in statements.iter() {
|
|
258
|
-
if let
|
|
259
|
-
&&
|
|
208
|
+
if let Statement::FunctionDeclaration(function) = statement
|
|
209
|
+
&& let Some(id) = ast::function_id(function)
|
|
210
|
+
&& self.analysis.bindings.is_written_once(&id)
|
|
211
|
+
&& ast::returned(function).is_some()
|
|
260
212
|
{
|
|
261
|
-
|
|
262
|
-
self.hoisting
|
|
263
|
-
.facts
|
|
264
|
-
.functions
|
|
265
|
-
.insert(declaration.ident.to_id(), function);
|
|
213
|
+
self.save_function(id, function)
|
|
266
214
|
}
|
|
267
215
|
}
|
|
268
216
|
}
|
|
269
|
-
hoisting::
|
|
270
|
-
|
|
271
|
-
});
|
|
217
|
+
hoisting::statements(self, statements, Self::unconditional_statement);
|
|
218
|
+
self.list = outer;
|
|
272
219
|
}
|
|
273
220
|
|
|
274
|
-
fn
|
|
275
|
-
hoisting
|
|
221
|
+
fn visit_function(&mut self, function: &mut Function<'a>, _: ScopeFlags) {
|
|
222
|
+
let outer = self.hoisting.facts.clone();
|
|
223
|
+
hoisting::function(self, function);
|
|
224
|
+
self.hoisting.facts = outer;
|
|
276
225
|
}
|
|
277
226
|
|
|
278
|
-
fn
|
|
279
|
-
hoisting::
|
|
227
|
+
fn visit_block_statement(&mut self, block: &mut BlockStatement<'a>) {
|
|
228
|
+
hoisting::block(self, block)
|
|
280
229
|
}
|
|
281
230
|
|
|
282
|
-
fn
|
|
283
|
-
hoisting::reference(self,
|
|
231
|
+
fn visit_identifier_reference(&mut self, reference: &mut IdentifierReference<'a>) {
|
|
232
|
+
hoisting::reference(self, reference)
|
|
284
233
|
}
|
|
285
234
|
|
|
286
|
-
|
|
287
|
-
fn visit_mut_seq_expr(&mut self, sequence: &mut SeqExpr) {
|
|
235
|
+
fn visit_sequence_expression(&mut self, sequence: &mut SequenceExpression<'a>) {
|
|
288
236
|
self.lists += 1;
|
|
289
|
-
let
|
|
290
|
-
for
|
|
291
|
-
self.
|
|
237
|
+
let outer = mem::replace(&mut self.list, self.lists);
|
|
238
|
+
for expression in &mut sequence.expressions {
|
|
239
|
+
self.unconditional_expression(expression)
|
|
292
240
|
}
|
|
241
|
+
self.list = outer;
|
|
293
242
|
}
|
|
294
243
|
|
|
295
|
-
fn
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if let Expr::Call(call) = expression
|
|
300
|
-
&& let Callee::Expr(callee) = &call.callee
|
|
301
|
-
&& let Expr::Member(member) = &**callee
|
|
302
|
-
&& let Some((object, property)) = self.stable(member)
|
|
303
|
-
&& let Some(function) = object.functions.get(&property)
|
|
304
|
-
&& let Some(result) = ast::returned(&function.function)
|
|
305
|
-
&& can_inline(function, result, &call.args, self.globals)
|
|
306
|
-
&& let Some(replacement) = substitute(function, result, &call.args)
|
|
244
|
+
fn visit_assignment_expression(&mut self, assignment: &mut AssignmentExpression<'a>) {
|
|
245
|
+
walk_mut::walk_assignment_expression(self, assignment);
|
|
246
|
+
if assignment.operator == AssignmentOperator::Assign
|
|
247
|
+
&& let Some(id) = self.analysis.target_id(&assignment.left)
|
|
307
248
|
{
|
|
308
|
-
|
|
309
|
-
self.changed = true;
|
|
249
|
+
self.record(id, &assignment.right)
|
|
310
250
|
}
|
|
251
|
+
}
|
|
311
252
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if let
|
|
315
|
-
&& let Some(function) = self.
|
|
316
|
-
&& let Some(
|
|
317
|
-
&&
|
|
318
|
-
&& can_inline(function, result, args, self.globals)
|
|
319
|
-
&& let Some(replacement) = substitute(function, result, args)
|
|
253
|
+
fn visit_expression(&mut self, expression: &mut Expression<'a>) {
|
|
254
|
+
walk_mut::walk_expression(self, expression);
|
|
255
|
+
if let Expression::CallExpression(call) = expression
|
|
256
|
+
&& let Some(function) = self.callee(&call.callee)
|
|
257
|
+
&& let Some(value) = ast::returned(function)
|
|
258
|
+
&& let Some(replacement) = substitute(function, value, &call.arguments, self.analysis)
|
|
320
259
|
{
|
|
321
260
|
*expression = replacement;
|
|
322
261
|
self.changed = true;
|
|
262
|
+
return;
|
|
323
263
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if let Some(member) = expression.as_member()
|
|
327
|
-
&& let Some((object, property)) = self.stable(member)
|
|
328
|
-
&& let Some(value) = object.literals.get(&property)
|
|
264
|
+
if let Some(value) = self.stable_value(expression)
|
|
265
|
+
&& ast::is_constant(value)
|
|
329
266
|
{
|
|
330
|
-
*expression = value.
|
|
267
|
+
*expression = value.clone_in_with_semantic_ids(self.analysis.allocator());
|
|
331
268
|
self.changed = true;
|
|
332
269
|
}
|
|
333
270
|
}
|
|
334
271
|
}
|
|
335
272
|
|
|
336
|
-
/// Checks that
|
|
337
|
-
///
|
|
338
|
-
fn names_only(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
all_allowed: bool,
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
impl Visit for Names {
|
|
346
|
-
fn visit_ident(&mut self, identifier: &Ident) {
|
|
347
|
-
self.all_allowed &= self.scopes.contains(&identifier.ctxt)
|
|
348
|
-
|| self.parameters.contains(&identifier.to_id());
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
let mut names = Names {
|
|
353
|
-
parameters: function
|
|
354
|
-
.params
|
|
355
|
-
.iter()
|
|
356
|
-
.filter_map(|parameter| Some(parameter.pat.as_ident()?.to_id()))
|
|
357
|
-
.collect(),
|
|
358
|
-
scopes: [scope, globals.unresolved],
|
|
359
|
-
all_allowed: true,
|
|
273
|
+
/// Checks that a direct helper's result names only parameters, globals, or bindings visible to
|
|
274
|
+
/// callers.
|
|
275
|
+
fn names_only(function: &Function<'_>, binding: Id, analysis: &Analysis<'_>) -> bool {
|
|
276
|
+
let (Some(parameters), Some(value)) = (ast::parameters(function), ast::returned(function))
|
|
277
|
+
else {
|
|
278
|
+
return false;
|
|
360
279
|
};
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
&mut self.hoisting
|
|
370
|
-
}
|
|
280
|
+
let scope = analysis.scope(binding);
|
|
281
|
+
let uses = Effects::expression(value, analysis);
|
|
282
|
+
uses.reads.iter().chain(&uses.writes).all(|id| {
|
|
283
|
+
let mut ancestors = analysis.scoping.scope_ancestors(scope);
|
|
284
|
+
id.is_global()
|
|
285
|
+
|| parameters.contains(id)
|
|
286
|
+
|| ancestors.any(|scope| scope == analysis.scope(*id))
|
|
287
|
+
})
|
|
371
288
|
}
|
|
372
289
|
|
|
373
|
-
/// Checks
|
|
374
|
-
|
|
375
|
-
fn
|
|
376
|
-
function.function.params.len() >= args.len()
|
|
377
|
-
&& trailing_parameters_unused(function, result, args.len())
|
|
378
|
-
&& args.iter().all(|argument| argument.spread.is_none())
|
|
379
|
-
&& !function.function.is_async
|
|
380
|
-
&& !function.function.is_generator
|
|
381
|
-
&& !uses_own_context(result)
|
|
382
|
-
&& (evaluates_arguments_safely(function, result, args, globals)
|
|
383
|
-
|| args
|
|
384
|
-
.iter()
|
|
385
|
-
.all(|argument| !effects::may_have_effects(&argument.expr, globals)))
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/// Parameters without arguments disappear when the call is inlined. Allow this only for unused
|
|
389
|
-
/// plain identifiers. Destructuring may evaluate defaults, and referenced parameters would have
|
|
390
|
-
/// no binding after substitution.
|
|
391
|
-
fn trailing_parameters_unused(function: &FnExpr, result: &Expr, argument_count: usize) -> bool {
|
|
392
|
-
let params = &function.function.params;
|
|
393
|
-
let trailing = names::parameter_ids(¶ms[argument_count.min(params.len())..]);
|
|
394
|
-
trailing.is_some_and(|trailing| !names::mentions(result, &trailing))
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/// Checks for `this`, `arguments`, `new.target`, or `super` outside nested functions, which
|
|
398
|
-
/// inlining would resolve in the caller instead.
|
|
399
|
-
fn uses_own_context(result: &Expr) -> bool {
|
|
290
|
+
/// Checks for `this`, `arguments`, `new.target`, or `super` outside ordinary nested functions.
|
|
291
|
+
/// Inlining would otherwise resolve these names in the caller instead of the helper.
|
|
292
|
+
fn own_context(expression: &Expression<'_>) -> bool {
|
|
400
293
|
struct Context(bool);
|
|
401
294
|
|
|
402
|
-
impl Visit for Context {
|
|
403
|
-
fn
|
|
404
|
-
self.0
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
self.0 = true;
|
|
295
|
+
impl<'a> Visit<'a> for Context {
|
|
296
|
+
fn visit_expression(&mut self, expression: &Expression<'a>) {
|
|
297
|
+
self.0 |= match expression {
|
|
298
|
+
Expression::ThisExpression(_) | Expression::Super(_) | Expression::NewTarget(_) => {
|
|
299
|
+
true
|
|
300
|
+
}
|
|
301
|
+
Expression::Identifier(identifier) => ast::is_arguments(identifier),
|
|
302
|
+
_ => false,
|
|
303
|
+
};
|
|
304
|
+
walk::walk_expression(self, expression)
|
|
413
305
|
}
|
|
414
306
|
|
|
415
|
-
fn visit_function(&mut self, _: &Function) {}
|
|
307
|
+
fn visit_function(&mut self, _: &Function<'a>, _: ScopeFlags) {}
|
|
416
308
|
}
|
|
417
309
|
|
|
418
310
|
let mut context = Context(false);
|
|
419
|
-
|
|
420
|
-
context.0
|
|
311
|
+
context.visit_expression(expression);
|
|
312
|
+
context.0
|
|
421
313
|
}
|
|
422
314
|
|
|
423
|
-
///
|
|
424
|
-
///
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
.function
|
|
439
|
-
.params
|
|
440
|
-
.iter()
|
|
441
|
-
.take(args.len())
|
|
442
|
-
.map(|parameter| Some(parameter.pat.as_ident()?.to_id()))
|
|
443
|
-
.collect();
|
|
444
|
-
// The parameter each operand reads, in evaluation order.
|
|
445
|
-
let mut order = Vec::with_capacity(args.len());
|
|
446
|
-
for operand in operands {
|
|
447
|
-
let operand = operand.as_ident().map(Ident::to_id);
|
|
448
|
-
let Some(index) = unread
|
|
449
|
-
.iter()
|
|
450
|
-
.position(|parameter| parameter.is_some() && *parameter == operand)
|
|
451
|
-
else {
|
|
452
|
-
return false;
|
|
453
|
-
};
|
|
454
|
-
unread[index] = None;
|
|
455
|
-
order.push(index);
|
|
456
|
-
}
|
|
457
|
-
for (position, &first) in order.iter().enumerate() {
|
|
458
|
-
for &second in &order[position + 1..] {
|
|
459
|
-
if first > second && !commutes(&args[first].expr, &args[second].expr, globals) {
|
|
460
|
-
return false;
|
|
461
|
-
}
|
|
315
|
+
/// Lists operands that always run, in evaluation order. Looks through outer unary operators
|
|
316
|
+
/// that run after their operands. Excludes `delete`, which does not evaluate a value read.
|
|
317
|
+
fn operands<'b, 'a>(expression: &'b Expression<'a>) -> Option<Vec<&'b Expression<'a>>> {
|
|
318
|
+
match expression.get_inner_expression() {
|
|
319
|
+
Expression::UnaryExpression(unary) if unary.operator != UnaryOperator::Delete => {
|
|
320
|
+
operands(&unary.argument).or_else(|| Some(vec![&unary.argument]))
|
|
321
|
+
}
|
|
322
|
+
Expression::BinaryExpression(binary) => Some(vec![&binary.left, &binary.right]),
|
|
323
|
+
Expression::StaticMemberExpression(member) => Some(vec![&member.object]),
|
|
324
|
+
Expression::ComputedMemberExpression(member) => {
|
|
325
|
+
Some(vec![&member.object, &member.expression])
|
|
326
|
+
}
|
|
327
|
+
Expression::CallExpression(call) if !call.optional => {
|
|
328
|
+
let arguments = call.arguments.iter().map(Argument::as_expression);
|
|
329
|
+
iter::once(Some(&call.callee)).chain(arguments).collect()
|
|
462
330
|
}
|
|
331
|
+
_ => None,
|
|
463
332
|
}
|
|
464
|
-
true
|
|
465
333
|
}
|
|
466
334
|
|
|
467
|
-
/// Two arguments may swap if both have no effects, or one
|
|
468
|
-
/// the other writes.
|
|
469
|
-
///
|
|
470
|
-
fn commutes(
|
|
471
|
-
let
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
)
|
|
335
|
+
/// Two arguments may swap if both have no effects, or one is effect-free and reads no binding
|
|
336
|
+
/// the other writes. Opaque operations may write through closures, so local reads cannot cross
|
|
337
|
+
/// them.
|
|
338
|
+
fn commutes(left: &Expression<'_>, right: &Expression<'_>, analysis: &Analysis<'_>) -> bool {
|
|
339
|
+
let effects = (
|
|
340
|
+
left.may_have_side_effects(analysis),
|
|
341
|
+
right.may_have_side_effects(analysis),
|
|
342
|
+
);
|
|
343
|
+
let (pure, impure) = match effects {
|
|
475
344
|
(false, false) => return true,
|
|
476
|
-
(false, true) => (
|
|
477
|
-
(true, false) => (
|
|
345
|
+
(false, true) => (left, right),
|
|
346
|
+
(true, false) => (right, left),
|
|
478
347
|
(true, true) => return false,
|
|
479
348
|
};
|
|
480
|
-
let pure = Effects::
|
|
481
|
-
pure.reads.is_empty()
|
|
482
|
-
|
|
483
|
-
!impure.opaque && impure.writes.is_disjoint(&pure.reads)
|
|
349
|
+
let pure = Effects::expression(pure, analysis);
|
|
350
|
+
if pure.reads.is_empty() {
|
|
351
|
+
return true;
|
|
484
352
|
}
|
|
353
|
+
let impure = Effects::expression(impure, analysis);
|
|
354
|
+
!impure.opaque && impure.writes.is_disjoint(&pure.reads)
|
|
485
355
|
}
|
|
486
356
|
|
|
487
|
-
///
|
|
488
|
-
///
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
{
|
|
506
|
-
Some(
|
|
507
|
-
iter::once(&**callee)
|
|
508
|
-
.chain(call.args.iter().map(|argument| &*argument.expr))
|
|
509
|
-
.collect(),
|
|
510
|
-
)
|
|
511
|
-
}
|
|
512
|
-
_ => None,
|
|
357
|
+
/// Checks argument evaluation before substituting a helper's single return expression.
|
|
358
|
+
/// Parameters must be plain identifiers; missing arguments are allowed only for unused trailing
|
|
359
|
+
/// parameters. Async functions, generators, helper-context reads, and parameter stores are kept.
|
|
360
|
+
/// Effectful arguments must occur exactly once in eager operands, with only commuting arguments
|
|
361
|
+
/// reordered. Nested arithmetic and short-circuit expressions need the stricter effect-free path.
|
|
362
|
+
fn substitute<'a>(
|
|
363
|
+
function: &Function<'a>,
|
|
364
|
+
value: &Expression<'a>,
|
|
365
|
+
arguments: &[Argument<'a>],
|
|
366
|
+
analysis: &Analysis<'a>,
|
|
367
|
+
) -> Option<Expression<'a>> {
|
|
368
|
+
let parameters = ast::parameters(function)?;
|
|
369
|
+
if function.r#async
|
|
370
|
+
|| function.generator
|
|
371
|
+
|| own_context(value)
|
|
372
|
+
|| arguments.len() > parameters.len()
|
|
373
|
+
{
|
|
374
|
+
return None;
|
|
513
375
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
376
|
+
let arguments: Vec<&Expression<'a>> = arguments
|
|
377
|
+
.iter()
|
|
378
|
+
.map(Argument::as_expression)
|
|
379
|
+
.collect::<Option<_>>()?;
|
|
380
|
+
let used = Effects::expression(value, analysis);
|
|
381
|
+
// Parameter stores need a fresh local environment, which expression substitution cannot
|
|
382
|
+
// supply.
|
|
383
|
+
if parameters.iter().any(|id| used.writes.contains(id))
|
|
384
|
+
|| parameters[arguments.len()..]
|
|
385
|
+
.iter()
|
|
386
|
+
.any(|id| used.reads.contains(id))
|
|
387
|
+
{
|
|
388
|
+
return None;
|
|
389
|
+
}
|
|
390
|
+
if arguments
|
|
391
|
+
.iter()
|
|
392
|
+
.any(|argument| argument.may_have_side_effects(analysis))
|
|
393
|
+
{
|
|
394
|
+
let operands = operands(value)?;
|
|
395
|
+
if operands.len() != arguments.len() {
|
|
528
396
|
return None;
|
|
529
397
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
let mut replacement = expression.clone();
|
|
539
|
-
replacement.visit_mut_with(&mut ParameterReplacer { parameters });
|
|
540
|
-
ast::parenthesized(Box::new(replacement))
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
struct ParameterReplacer<'arguments> {
|
|
544
|
-
parameters: HashMap<Id, &'arguments Expr>,
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
impl VisitMut for ParameterReplacer<'_> {
|
|
548
|
-
fn visit_mut_call_expr(&mut self, call: &mut CallExpr) {
|
|
549
|
-
use swc_core::common::Spanned;
|
|
550
|
-
|
|
551
|
-
let parameter_callee = matches!(&call.callee, Callee::Expr(callee)
|
|
552
|
-
if callee.as_ident().is_some_and(|id| self.parameters.contains_key(&id.to_id())));
|
|
553
|
-
call.visit_mut_children_with(self);
|
|
554
|
-
if parameter_callee
|
|
555
|
-
&& let Callee::Expr(callee) = &mut call.callee
|
|
556
|
-
&& needs_detaching(callee.unwrap_parens())
|
|
557
|
-
{
|
|
558
|
-
// The wrapper calls a parameter as a value. Substituting `obj.method`
|
|
559
|
-
// must not bind `obj` as `this`, or turn a passed `eval` into direct eval.
|
|
560
|
-
**callee = Expr::Seq(SeqExpr {
|
|
561
|
-
span: callee.span(),
|
|
562
|
-
exprs: vec![
|
|
563
|
-
Box::new(Expr::Lit(Lit::Num(Number {
|
|
564
|
-
span: callee.span(),
|
|
565
|
-
value: 0.0,
|
|
566
|
-
raw: None,
|
|
567
|
-
}))),
|
|
568
|
-
callee.clone(),
|
|
569
|
-
],
|
|
570
|
-
});
|
|
398
|
+
let mut order = vec![];
|
|
399
|
+
for operand in operands {
|
|
400
|
+
let id = analysis.expression_id(operand)?;
|
|
401
|
+
let index = parameters.iter().position(|parameter| *parameter == id)?;
|
|
402
|
+
if order.contains(&index) || index >= arguments.len() {
|
|
403
|
+
return None;
|
|
404
|
+
}
|
|
405
|
+
order.push(index)
|
|
571
406
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
&& let Some(value) = self.parameters.get(&identifier.to_id())
|
|
579
|
-
{
|
|
580
|
-
*expression = ast::parenthesized(Box::new((*value).clone()));
|
|
407
|
+
for (position, &first) in order.iter().enumerate() {
|
|
408
|
+
for &second in &order[position + 1..] {
|
|
409
|
+
if first > second && !commutes(arguments[first], arguments[second], analysis) {
|
|
410
|
+
return None;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
581
413
|
}
|
|
582
414
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
/// Checks whether a substituted callee needs `(0, callee)` to preserve call behavior. Member
|
|
586
|
-
/// references would otherwise receive `this`, and `eval` could become a direct eval call. A
|
|
587
|
-
/// local named `eval` may also hold the built-in function.
|
|
588
|
-
fn needs_detaching(callee: &Expr) -> bool {
|
|
589
|
-
match callee {
|
|
590
|
-
Expr::Member(_) | Expr::SuperProp(_) | Expr::OptChain(_) => true,
|
|
591
|
-
Expr::Ident(identifier) => identifier.sym == "eval",
|
|
592
|
-
_ => false,
|
|
593
|
-
}
|
|
415
|
+
let values = parameters.into_iter().zip(arguments).collect();
|
|
416
|
+
Some(ast::replace_parameters(value, &values, analysis))
|
|
594
417
|
}
|
|
595
418
|
|
|
596
419
|
#[cfg(test)]
|
|
@@ -600,42 +423,42 @@ mod tests {
|
|
|
600
423
|
/// Helper-call test cases and expected results. Calls remain unchanged when inlining could
|
|
601
424
|
/// alter evaluation or its order. `set()` writes the parameters read by the arguments;
|
|
602
425
|
/// `first()` and `second()` have unknown effects.
|
|
603
|
-
const CALLS: [(&str, &str, &str);
|
|
604
|
-
// Inlined results
|
|
426
|
+
const CALLS: [(&str, &str, &str); 28] = [
|
|
427
|
+
// Inlined results keep the precedence of their substituted arguments.
|
|
605
428
|
(
|
|
606
429
|
"function(a, b) { return a & b; }",
|
|
607
430
|
"h.op(local >>> 16, 65535) * 8133",
|
|
608
|
-
"(
|
|
431
|
+
"(local >>> 16 & 65535) * 8133",
|
|
609
432
|
),
|
|
610
433
|
// Eager operators evaluate their operands in argument order.
|
|
611
434
|
(
|
|
612
435
|
"function(a, b) { return a + b; }",
|
|
613
436
|
"h.op(values[i++], first())",
|
|
614
|
-
"
|
|
437
|
+
"values[i++] + first()",
|
|
615
438
|
),
|
|
616
439
|
// Reordering is safe when only one operand has effects and the other reads no affected
|
|
617
440
|
// binding.
|
|
618
441
|
(
|
|
619
442
|
"function(a, b) { return b - a; }",
|
|
620
443
|
"h.op(values[i++], 2)",
|
|
621
|
-
"
|
|
444
|
+
"2 - values[i++]",
|
|
622
445
|
),
|
|
623
446
|
(
|
|
624
447
|
"function(a, b) { return b === a; }",
|
|
625
448
|
"h.op(typeof values, 'object')",
|
|
626
|
-
"
|
|
449
|
+
r#""object" === typeof values"#,
|
|
627
450
|
),
|
|
628
451
|
(
|
|
629
452
|
"function(a, b) { return b | a; }",
|
|
630
453
|
"h.op(first(), 2)",
|
|
631
|
-
"
|
|
454
|
+
"2 | first()",
|
|
632
455
|
),
|
|
633
456
|
// An effect-free operand may move past a write only if it does not read the written
|
|
634
457
|
// binding.
|
|
635
458
|
(
|
|
636
459
|
"function(a, b) { return b | a; }",
|
|
637
460
|
"h.op(values[i++], local)",
|
|
638
|
-
"
|
|
461
|
+
"local | values[i++]",
|
|
639
462
|
),
|
|
640
463
|
(
|
|
641
464
|
"function(a, b) { return b | a; }",
|
|
@@ -657,17 +480,22 @@ mod tests {
|
|
|
657
480
|
"h.op(first(), second())",
|
|
658
481
|
"h.op(first(), second())",
|
|
659
482
|
),
|
|
483
|
+
(
|
|
484
|
+
"function(a, b) { return b + a; }",
|
|
485
|
+
"h.op(v, [v] = [2])",
|
|
486
|
+
"h.op(v, [v] = [2])",
|
|
487
|
+
),
|
|
660
488
|
// An outer unary operator runs after both operands, so `!(b !== a)` permits the same
|
|
661
489
|
// reordering as `b === a`. `delete` has different operand evaluation rules.
|
|
662
490
|
(
|
|
663
491
|
"function(aX, ae) { return !(ae !== aX); }",
|
|
664
492
|
"h.op(q._cf_chl_opt.EcMJs8, 1)",
|
|
665
|
-
"!(
|
|
493
|
+
"!(1 !== q._cf_chl_opt.EcMJs8)",
|
|
666
494
|
),
|
|
667
495
|
(
|
|
668
496
|
"function(a, b) { return -(b - a); }",
|
|
669
497
|
"h.op(q.x, 2)",
|
|
670
|
-
"-(
|
|
498
|
+
"-(2 - q.x)",
|
|
671
499
|
),
|
|
672
500
|
(
|
|
673
501
|
"function(aX, ae) { return !(ae !== aX); }",
|
|
@@ -683,7 +511,7 @@ mod tests {
|
|
|
683
511
|
(
|
|
684
512
|
"function(a) { return a.key; }",
|
|
685
513
|
"h.op(first())",
|
|
686
|
-
"
|
|
514
|
+
"first().key",
|
|
687
515
|
),
|
|
688
516
|
(
|
|
689
517
|
"function(a, b) { return b[a]; }",
|
|
@@ -694,12 +522,12 @@ mod tests {
|
|
|
694
522
|
(
|
|
695
523
|
"function(rn, rw, ri, ru, KA) { return rn(rw, ri, ru); }",
|
|
696
524
|
"h.op(local, 1, 2, 3)",
|
|
697
|
-
"
|
|
525
|
+
"local(1, 2, 3)",
|
|
698
526
|
),
|
|
699
527
|
(
|
|
700
528
|
"function(a, b, extra) { return b | a; }",
|
|
701
529
|
"h.op(local, 2, 3)",
|
|
702
|
-
"
|
|
530
|
+
"2 | local",
|
|
703
531
|
),
|
|
704
532
|
(
|
|
705
533
|
"function(a, b, extra) { return extra + b; }",
|
|
@@ -718,7 +546,7 @@ mod tests {
|
|
|
718
546
|
"h.op(missing, 1)",
|
|
719
547
|
"h.op(missing, 1)",
|
|
720
548
|
),
|
|
721
|
-
("function(a, b) { return b; }", "h.op(Math, 1)", "
|
|
549
|
+
("function(a, b) { return b; }", "h.op(Math, 1)", "return 1;"),
|
|
722
550
|
// Tests bodies that skip, repeat, or reorder operands within larger expressions.
|
|
723
551
|
(
|
|
724
552
|
"function(a, b) { return a + a; }",
|
|
@@ -748,7 +576,7 @@ mod tests {
|
|
|
748
576
|
];
|
|
749
577
|
|
|
750
578
|
fn transform(source: &str) -> String {
|
|
751
|
-
testing::rewrite(source, super::run
|
|
579
|
+
testing::rewrite(source, super::run)
|
|
752
580
|
}
|
|
753
581
|
|
|
754
582
|
#[test]
|
|
@@ -770,47 +598,29 @@ mod tests {
|
|
|
770
598
|
return h.invoke(eval, "typeof local");
|
|
771
599
|
}"#,
|
|
772
600
|
);
|
|
773
|
-
testing::assert_contains(&output, &["(0, obj.method)(effect())", "plain(1);"]
|
|
601
|
+
testing::assert_contains(&output, &["(0, obj.method)(effect())", "plain(1);"]);
|
|
774
602
|
let expected = ["(0, eval)(\"typeof local\")", "Number(obj.value);"];
|
|
775
|
-
testing::assert_contains(&output, &expected
|
|
603
|
+
testing::assert_contains(&output, &expected);
|
|
776
604
|
assert!(!output.contains("(0, plain)"), "{output}");
|
|
777
605
|
}
|
|
778
606
|
|
|
779
|
-
#[test]
|
|
780
|
-
fn inlines_static_template_properties_without_evaluating_interpolation() {
|
|
781
|
-
let output = transform(
|
|
782
|
-
r"function f() {
|
|
783
|
-
var helper;
|
|
784
|
-
helper = { first: `fixed` };
|
|
785
|
-
helper.second = `line\n\u{1f600}\ud800`;
|
|
786
|
-
helper.dynamic = `value:${read()}`;
|
|
787
|
-
return function() { return [helper.first, helper.second, helper.dynamic]; };
|
|
788
|
-
}",
|
|
789
|
-
);
|
|
790
|
-
testing::assert_contains(
|
|
791
|
-
&output,
|
|
792
|
-
&[],
|
|
793
|
-
&[r"return [`fixed`, `line\n\u{1f600}\ud800`, helper.dynamic]"],
|
|
794
|
-
);
|
|
795
|
-
let output = transform(
|
|
796
|
-
r"function f() {
|
|
797
|
-
var helper;
|
|
798
|
-
helper = { name: `before` };
|
|
799
|
-
helper.name = `after`;
|
|
800
|
-
return helper.name;
|
|
801
|
-
}",
|
|
802
|
-
);
|
|
803
|
-
assert!(output.contains("return helper.name;"), "{output}");
|
|
804
|
-
}
|
|
805
|
-
|
|
806
607
|
#[test]
|
|
807
608
|
fn inlines_member_assigned_properties_and_helper_functions() {
|
|
808
609
|
let output = transform(
|
|
809
610
|
"function f(h, p) { h = {}; h.op = function (a, b) { return a + b; }; \
|
|
810
611
|
h.name = \"n\"; p = h; return [p.op(1, 2), p.name, h.name]; }",
|
|
811
612
|
);
|
|
812
|
-
assert!(output.contains("
|
|
613
|
+
assert!(output.contains("1 + 2"), "{output}");
|
|
813
614
|
testing::assert_lacks(&output, &["p.name", "h.name]"]);
|
|
615
|
+
// Static templates inline into later callbacks, as in a payload built after a delay.
|
|
616
|
+
let output = transform(
|
|
617
|
+
"function f(h, g) { h = { key: `_field` }; g(function () { return w[h.key]; }); }",
|
|
618
|
+
);
|
|
619
|
+
assert!(output.contains("w[`_field`]"), "{output}");
|
|
620
|
+
// A unary helper evaluates its argument first either way, even a member read.
|
|
621
|
+
let output =
|
|
622
|
+
transform("function f(n) { n = function (a) { return !a; }; if (n(w.x)) g(); }");
|
|
623
|
+
assert!(output.contains("!w.x"), "{output}");
|
|
814
624
|
// Helper functions inline when they name only what callers see.
|
|
815
625
|
let output = transform(
|
|
816
626
|
"function f(add, call, read, g) { add = function(a, b) { return a + b; }; \
|
|
@@ -818,21 +628,21 @@ mod tests {
|
|
|
818
628
|
g = function(local) { read = function() { return local; }; }; \
|
|
819
629
|
g(5); return [call(2), add(3, 4), read()]; }",
|
|
820
630
|
);
|
|
821
|
-
let expected = ["
|
|
822
|
-
testing::assert_contains(&output, &
|
|
631
|
+
let expected = ["2 + 1", "Math.max(2)", "3 + 4", "read()]"];
|
|
632
|
+
testing::assert_contains(&output, &expected);
|
|
823
633
|
// Function declarations inside function bodies are also stable; top-level declarations are
|
|
824
634
|
// not.
|
|
825
635
|
let output = transform(
|
|
826
636
|
"function f(x) { return g(x, 1); function g(a, b) { return a + b; } } \
|
|
827
637
|
function h(a) { return a; } k(h(2));",
|
|
828
638
|
);
|
|
829
|
-
testing::assert_contains(&output, &[
|
|
639
|
+
testing::assert_contains(&output, &["return x + 1;", "k(h(2));"]);
|
|
830
640
|
// Copies of helper methods are stable too.
|
|
831
641
|
let output = transform(
|
|
832
642
|
"function f(h, m) { h = { shr: function (a, b) { return a >> b; } }; m = h.shr; \
|
|
833
643
|
return m(8, 1); }",
|
|
834
644
|
);
|
|
835
|
-
assert!(output.contains("
|
|
645
|
+
assert!(output.contains("8 >> 1"), "{output}");
|
|
836
646
|
}
|
|
837
647
|
|
|
838
648
|
#[test]
|
|
@@ -852,11 +662,11 @@ mod tests {
|
|
|
852
662
|
return [alias.add(1, 2), alias.name, h.add(1, 2)];
|
|
853
663
|
}"#,
|
|
854
664
|
);
|
|
855
|
-
testing::assert_contains(&output, &["h.add(1, 2)", "h.add(3, 4)"]
|
|
665
|
+
testing::assert_contains(&output, &["h.add(1, 2)", "h.add(3, 4)"]);
|
|
856
666
|
assert!(output.matches("h.name").count() == 2, "{output}");
|
|
857
|
-
testing::assert_contains(&output, &["alias.add(1, 2)", "alias.name"]
|
|
667
|
+
testing::assert_contains(&output, &["alias.add(1, 2)", "alias.name"]);
|
|
858
668
|
assert!(
|
|
859
|
-
!output.contains("
|
|
669
|
+
!output.contains("1 + 2"),
|
|
860
670
|
"`h` is copied into a binding that is assigned again, which could change it before \
|
|
861
671
|
that, so its properties are not trusted either: {output}"
|
|
862
672
|
);
|