cfsolve 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/THIRD_PARTY_LICENSES/README.md +71 -254
  4. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  5. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  6. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  7. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  8. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  9. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  11. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  12. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  13. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  14. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  15. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  16. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  17. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  18. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  19. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  21. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  22. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  24. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  30. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  32. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  34. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  36. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  38. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  40. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  42. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  43. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  45. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  47. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  49. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  51. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  53. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  55. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  56. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  57. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  58. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  59. data/UPSTREAM.md +7 -5
  60. data/ext/cfsolve/Cargo.lock +534 -1727
  61. data/ext/cfsolve/Cargo.toml +4 -0
  62. data/ext/cfsolve/src/main.rs +1 -1
  63. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  64. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  65. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  66. data/lib/cfsolve/version.rb +2 -2
  67. data/vendor/cfsolve/Cargo.lock +561 -1729
  68. data/vendor/cfsolve/Cargo.toml +26 -8
  69. data/vendor/cfsolve/README.md +4 -0
  70. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  71. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  72. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  73. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  74. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  75. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  76. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  77. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  78. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  79. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  80. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  81. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  82. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  83. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  84. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  85. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  86. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  87. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  88. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  89. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  90. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  91. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  92. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  93. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  94. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  95. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  96. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  97. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  98. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  99. data/vendor/cfsolve/src/challenge.rs +1 -0
  100. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  101. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  102. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  103. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  104. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  105. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  106. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  107. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  108. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  109. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  110. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  111. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  112. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  113. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  114. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  115. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  116. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  117. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  118. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  119. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  120. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  121. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  122. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  123. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  124. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  125. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  126. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  127. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  128. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  129. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  130. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  131. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  132. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  133. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  134. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  135. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  136. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
  137. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  138. data/vendor/cfsolve/src/error.rs +40 -5
  139. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  140. data/vendor/cfsolve/src/http/client.rs +7 -10
  141. data/vendor/cfsolve/src/http/requests.rs +2 -2
  142. data/vendor/cfsolve/src/js/ast.rs +479 -263
  143. data/vendor/cfsolve/src/lib.rs +1 -0
  144. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  145. data/vendor/cfsolve/src/listing/query.rs +1 -47
  146. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  147. data/vendor/cfsolve/src/profiling.rs +49 -0
  148. data/vendor/cfsolve/src/script.rs +35 -24
  149. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  150. data/vendor/cfsolve/src/session/channel.rs +2 -2
  151. data/vendor/cfsolve/src/session/initial.rs +5 -5
  152. data/vendor/cfsolve/src/session/sink.rs +26 -1
  153. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  154. data/vendor/cfsolve/src/session.rs +1 -1
  155. data/vendor/cfsolve/src/solver.rs +3 -1
  156. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  157. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  158. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  159. data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
  160. data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
  161. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  162. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  163. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  164. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  165. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  166. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  167. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  168. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  169. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  170. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  171. data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
  172. data/vendor/cfsolve/src/stage2.rs +2 -0
  173. data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
  174. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  175. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  176. data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
  177. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  178. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  179. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  180. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  181. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  182. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  183. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  184. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  185. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  186. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
  187. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  188. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  189. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  190. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  191. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  192. data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
  193. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  194. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  195. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  196. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  197. data/vendor/cfsolve/src/vm/machine.rs +56 -49
  198. data/vendor/cfsolve/src/vm/output.rs +13 -5
  199. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  200. data/vendor/cfsolve/src/vm/session.rs +185 -120
  201. data/vendor/cfsolve/src/vm/value.rs +22 -19
  202. data/vendor/cfsolve/src/vm.rs +2 -1
  203. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  204. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  205. metadata +94 -178
  206. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  207. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  208. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  209. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  210. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  211. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  212. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  213. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  214. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  215. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  216. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  217. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  218. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  219. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  220. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  221. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  222. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  223. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  224. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  225. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  226. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  227. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  228. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  229. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  230. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  231. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  232. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  233. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  234. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  235. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  237. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  238. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  239. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  240. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  241. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  242. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  243. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  244. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  245. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  246. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  247. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  248. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  249. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  250. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  251. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  252. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  253. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  255. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  256. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  257. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  258. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  259. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  260. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  261. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  262. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  263. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  264. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  265. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  266. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  268. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  269. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  270. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  271. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  272. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  273. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  274. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  277. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  278. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  279. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  280. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  281. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  282. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  283. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  284. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  286. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  288. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  290. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  292. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  293. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  294. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  295. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  296. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  297. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  298. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  299. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  300. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  301. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  302. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  303. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  305. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  329. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  330. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  331. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  332. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  333. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  334. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  335. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  336. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  337. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  338. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  339. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  340. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  341. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  342. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  343. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  344. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  345. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  346. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  347. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  348. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  349. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  350. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  351. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  352. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  353. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  354. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  355. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  356. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  357. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  358. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  359. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  360. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  361. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  362. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  363. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  364. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  365. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  366. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  367. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  368. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -0,0 +1,197 @@
1
+ //! Preserves binding identity when rewrites move code across scope boundaries.
2
+ //!
3
+ //! ```js
4
+ //! function f(x) { var a; a = x; return function(x) { return a + x; }; }
5
+ //! // After copy propagation, hygiene keeps the captured and parameter bindings distinct:
6
+ //! function f(x) { return function(x_1) { return x + x_1; }; }
7
+ //! ```
8
+ //!
9
+ //! Finds references that another binding with the same spelling now hides, and locals with the
10
+ //! same spelling that arrow inlining moved into one function. Those locals get unused names while
11
+ //! references keep their symbols. Renamed shorthand properties keep their original keys.
12
+
13
+ use std::cell::Cell;
14
+
15
+ use oxc::ast::ast::{BindingIdentifier, IdentifierReference, ObjectProperty, Program};
16
+ use oxc::ast_visit::{Visit, VisitMut, walk_mut};
17
+ use oxc::str::Ident;
18
+ use oxc::syntax::scope::{ScopeFlags, ScopeId};
19
+
20
+ use super::analysis::{Analysis, Id};
21
+ use super::{HashMap, HashSet, ast};
22
+
23
+ /// The bindings declared in each scope, by name.
24
+ type Bindings<'a> = HashMap<ScopeId, HashMap<Ident<'a>, HashSet<Id>>>;
25
+
26
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) {
27
+ let mut declarations = Declarations {
28
+ analysis,
29
+ stack: vec![],
30
+ bindings: HashMap::default(),
31
+ };
32
+ declarations.visit_program(program);
33
+ let bindings = declarations.bindings;
34
+ // Every binding but the first of each name declared in one scope conflicts.
35
+ let mut conflicts = HashSet::default();
36
+ for names in bindings.values() {
37
+ for ids in names.values() {
38
+ let first = ids.iter().min();
39
+ conflicts.extend(ids.iter().filter(|&id| Some(id) != first));
40
+ }
41
+ }
42
+ let mut references = References {
43
+ analysis,
44
+ bindings: &bindings,
45
+ stack: vec![],
46
+ conflicts,
47
+ };
48
+ references.visit_program(program);
49
+ let mut conflicts: Vec<Id> = references.conflicts.into_iter().collect();
50
+ conflicts.sort_unstable();
51
+ let mut renamed = HashMap::default();
52
+ for id in conflicts {
53
+ let name = analysis.suffixed_name(analysis.name(id));
54
+ let name = Ident::from_str_in(&name, &analysis.ast);
55
+ let symbol = id.local().expect("a conflicting binding is declared");
56
+ analysis.scoping.set_symbol_name(symbol, name);
57
+ renamed.insert(id, name);
58
+ }
59
+ Rename {
60
+ analysis,
61
+ renamed: &renamed,
62
+ }
63
+ .visit_program(program);
64
+ }
65
+
66
+ /// Collects the bindings declared in each scope of the rewritten tree. A binding moved out of
67
+ /// its original scope belongs to the nearest enclosing function scope.
68
+ struct Declarations<'b, 'a> {
69
+ analysis: &'b Analysis<'a>,
70
+ /// The entered scopes and their flags.
71
+ stack: Vec<(ScopeId, ScopeFlags)>,
72
+ bindings: Bindings<'a>,
73
+ }
74
+
75
+ impl<'a> Visit<'a> for Declarations<'_, 'a> {
76
+ fn enter_scope(&mut self, flags: ScopeFlags, scope: &Cell<Option<ScopeId>>) {
77
+ let scope = scope.get().unwrap_or_else(|| {
78
+ let parent = self.stack.last();
79
+ parent.map_or(self.analysis.scoping.root_scope_id(), |&(parent, _)| parent)
80
+ });
81
+ self.stack.push((scope, flags))
82
+ }
83
+
84
+ fn leave_scope(&mut self) {
85
+ self.stack.pop();
86
+ }
87
+
88
+ fn visit_binding_identifier(&mut self, binding: &BindingIdentifier<'a>) {
89
+ let Some(symbol) = binding.symbol_id.get() else {
90
+ return;
91
+ };
92
+ let id = Id::Local(symbol);
93
+ let original = self.analysis.scope(id);
94
+ let scope = if self.stack.iter().any(|&(scope, _)| scope == original) {
95
+ original
96
+ } else {
97
+ let mut scopes = self.stack.iter().rev();
98
+ let function = scopes.find(|(_, flags)| flags.contains(ScopeFlags::Function));
99
+ function.map_or(self.analysis.scoping.root_scope_id(), |&(scope, _)| scope)
100
+ };
101
+ let names = self.bindings.entry(scope).or_default();
102
+ names.entry(binding.name).or_default().insert(id);
103
+ }
104
+ }
105
+
106
+ /// Collects the bindings that hide a reference's own binding.
107
+ struct References<'b, 'a> {
108
+ analysis: &'b Analysis<'a>,
109
+ bindings: &'b Bindings<'a>,
110
+ stack: Vec<ScopeId>,
111
+ conflicts: HashSet<Id>,
112
+ }
113
+
114
+ impl<'a> Visit<'a> for References<'_, 'a> {
115
+ fn enter_scope(&mut self, _: ScopeFlags, scope: &Cell<Option<ScopeId>>) {
116
+ let scope = scope.get().unwrap_or_else(|| {
117
+ let parent = self.stack.last().copied();
118
+ parent.unwrap_or(self.analysis.scoping.root_scope_id())
119
+ });
120
+ self.stack.push(scope)
121
+ }
122
+
123
+ fn leave_scope(&mut self) {
124
+ self.stack.pop();
125
+ }
126
+
127
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
128
+ let expected = self.analysis.id(reference);
129
+ for scope in self.stack.iter().rev() {
130
+ let names = self.bindings.get(scope);
131
+ if let Some(ids) = names.and_then(|names| names.get(&reference.name)) {
132
+ if expected.is_none_or(|id| !ids.contains(&id)) {
133
+ self.conflicts.extend(ids);
134
+ }
135
+ break;
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ struct Rename<'b, 'a> {
142
+ analysis: &'b Analysis<'a>,
143
+ renamed: &'b HashMap<Id, Ident<'a>>,
144
+ }
145
+
146
+ impl<'a> VisitMut<'a> for Rename<'_, 'a> {
147
+ fn visit_binding_identifier(&mut self, binding: &mut BindingIdentifier<'a>) {
148
+ if let Some(symbol) = binding.symbol_id.get()
149
+ && let Some(&name) = self.renamed.get(&Id::Local(symbol))
150
+ {
151
+ binding.name = name;
152
+ }
153
+ }
154
+
155
+ fn visit_object_property(&mut self, property: &mut ObjectProperty<'a>) {
156
+ walk_mut::walk_object_property(self, property);
157
+ ast::normalize_property(property, &self.analysis.ast)
158
+ }
159
+
160
+ fn visit_identifier_reference(&mut self, reference: &mut IdentifierReference<'a>) {
161
+ let id = self.analysis.id(reference);
162
+ if let Some(&name) = id.and_then(|id| self.renamed.get(&id)) {
163
+ reference.name = name;
164
+ }
165
+ }
166
+ }
167
+
168
+ #[cfg(test)]
169
+ mod tests {
170
+ use crate::deobfuscate::testing;
171
+
172
+ #[test]
173
+ fn preserves_references_moved_under_shadowing_parameters() {
174
+ let output = testing::transform("function f(x){var a;a=x;return function(x){return a+x;}}");
175
+ testing::assert_contains(&output, &["return x + x_1;"]);
176
+ }
177
+
178
+ #[test]
179
+ fn separates_bindings_when_an_arrow_body_moves_into_its_parent() {
180
+ let output = testing::transform(
181
+ "function f(){var x=g(),step;step=()=>{var x=h();use(x)};step();return x;}",
182
+ );
183
+ testing::assert_contains(
184
+ &output,
185
+ &["var x = g()", "var x_1 = h()", "use(x_1)", "return x;"],
186
+ );
187
+ }
188
+
189
+ #[test]
190
+ fn preserves_global_undefined_and_shorthand_keys() {
191
+ let output = testing::transform("function f(undefined){return [void 0,{undefined}];}");
192
+ testing::assert_contains(
193
+ &output,
194
+ &["function f(undefined_1)", "undefined: undefined_1"],
195
+ );
196
+ }
197
+ }
@@ -14,196 +14,162 @@
14
14
  //! already a 32-bit integer is returned unchanged. Requires a helper declared once. Removes the
15
15
  //! helper once no reads remain.
16
16
 
17
- use swc_core::ecma::ast::{
18
- BinExpr, BinaryOp, Decl, Expr, FnDecl, Function, Id, Lit, Number, Program, Stmt, UnaryOp,
19
- UpdateOp, VarDeclarator,
20
- };
21
- use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
17
+ use std::slice;
22
18
 
23
- use super::analysis::Analysis;
24
- use super::{HashMap, HashSet, bitwise, removal};
25
- use crate::js::ast;
19
+ use oxc::allocator::{CloneIn, GetAllocator};
20
+ use oxc::ast::ast::{Expression, Function, Program, SimpleAssignmentTarget, Statement};
21
+ use oxc::ast_visit::{VisitMut, walk_mut};
22
+ use oxc::syntax::operator::{BinaryOperator, UpdateOperator};
26
23
 
27
- pub(super) fn run(program: &mut Program, analysis: &mut Analysis) -> bool {
28
- let bindings = analysis.bindings(program);
29
- let mut helpers = Helpers::default();
30
- program.visit_with(&mut helpers);
31
- helpers.0.retain(|id| bindings.is_written_once(id));
32
- if helpers.0.is_empty() {
33
- return false;
34
- }
35
- let mut inline = InlineCalls {
36
- helpers: &helpers.0,
24
+ use super::analysis::{Analysis, Id};
25
+ use super::{HashMap, HashSet, ast, removal};
26
+ use crate::js;
27
+
28
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
29
+ let accept = |function: &Function<'_>| is_helper(function, analysis).unwrap_or(false);
30
+ let helpers: HashSet<Id> = ast::functions(program, analysis, &accept)
31
+ .into_keys()
32
+ .collect();
33
+ let mut inline = Inline {
34
+ analysis,
35
+ helpers: &helpers,
37
36
  replaced: HashMap::default(),
38
37
  };
39
- program.visit_mut_with(&mut inline);
40
- let uncalled = removal::unread(&inline.replaced, bindings);
41
- program.visit_mut_with(&mut RemoveHelpers(uncalled));
38
+ inline.visit_program(program);
39
+ let unread = removal::unread(&inline.replaced, analysis);
40
+ removal::remove_function_declarations(program, &unread);
42
41
  !inline.replaced.is_empty()
43
42
  }
44
43
 
45
- /// Declared helpers, by binding.
46
- #[derive(Default)]
47
- struct Helpers(Vec<Id>);
44
+ /// Matches `argument & mask` when the mask is an exactly representable signed 32-bit integer.
45
+ fn masked(expression: &Expression<'_>, argument: Id, analysis: &Analysis<'_>) -> Option<i32> {
46
+ let Expression::BinaryExpression(binary) = expression.get_inner_expression() else {
47
+ return None;
48
+ };
49
+ if binary.operator != BinaryOperator::BitwiseAnd
50
+ || analysis.expression_id(&binary.left) != Some(argument)
51
+ {
52
+ return None;
53
+ }
54
+ let mask = ast::number(&binary.right)?;
55
+ let exact = mask.fract() == 0.0 && (i32::MIN as f64..=i32::MAX as f64).contains(&mask);
56
+ exact.then_some(mask as i32)
57
+ }
48
58
 
49
- impl Visit for Helpers {
50
- fn visit_fn_decl(&mut self, declaration: &FnDecl) {
51
- if helper_mask(&declaration.function).is_some() {
52
- self.0.push(declaration.ident.to_id());
53
- }
54
- declaration.visit_children_with(self);
59
+ fn updated(
60
+ expression: &Expression<'_>,
61
+ operator: UpdateOperator,
62
+ analysis: &Analysis<'_>,
63
+ ) -> Option<Id> {
64
+ let Expression::UpdateExpression(update) = expression.get_inner_expression() else {
65
+ return None;
66
+ };
67
+ let SimpleAssignmentTarget::AssignmentTargetIdentifier(target) = &update.argument else {
68
+ return None;
69
+ };
70
+ if update.operator != operator {
71
+ return None;
55
72
  }
73
+ analysis.id(target)
56
74
  }
57
75
 
58
- /// The mask of a helper, or `None` if `function` is not one. Its declarations may be split:
59
- ///
60
- /// ```js
61
- /// function(x) {
62
- /// var low = x & mask, count = 0;
63
- /// for (; low; low--) count++;
64
- /// return x & ~mask | count;
65
- /// }
66
- /// ```
67
- fn helper_mask(function: &Function) -> Option<i32> {
68
- let [parameter] = &function.params[..] else {
76
+ /// Recognizes a single-parameter function that counts the low masked bits, then combines the
77
+ /// count with the complementary high-bit mask. Requires the expected decrement and increment
78
+ /// loop, and no other declarations or statements that could affect the result.
79
+ fn is_helper(function: &Function<'_>, analysis: &Analysis<'_>) -> Option<bool> {
80
+ let [argument] = ast::parameters(function)?[..] else {
69
81
  return None;
70
82
  };
71
83
  let [
72
84
  declarations @ ..,
73
- Stmt::For(counting),
74
- Stmt::Return(returned),
75
- ] = &function.body.as_ref()?.stmts[..]
85
+ Statement::ForStatement(counting),
86
+ Statement::ReturnStatement(returned),
87
+ ] = function.body.as_ref()?.statements.as_slice()
76
88
  else {
77
89
  return None;
78
90
  };
79
- let mut declarators: Vec<&VarDeclarator> = Vec::new();
91
+ let mut declarators = vec![];
80
92
  for statement in declarations {
81
- declarators.extend(&statement.as_decl()?.as_var()?.decls);
93
+ let Statement::VariableDeclaration(declaration) = statement else {
94
+ return None;
95
+ };
96
+ declarators.extend(&declaration.declarations)
82
97
  }
83
98
  let [low, count] = declarators[..] else {
84
99
  return None;
85
100
  };
86
- let argument = parameter.pat.as_ident()?.to_id();
87
- let low_name = low.name.as_ident()?.to_id();
88
- let count_name = count.name.as_ident()?.to_id();
89
- let mask = masked(low.init.as_deref()?, &argument)?;
90
- let combined = returned.arg.as_deref()?.unwrap_parens().as_bin()?;
91
- let increment = match &*counting.body {
92
- Stmt::Block(block) => match &block.stmts[..] {
93
- [statement] => statement,
94
- _ => return None,
95
- },
96
- statement => statement,
97
- };
98
- let reads = |expression: &Expr, id: &Id| {
99
- expression
100
- .as_ident()
101
- .is_some_and(|name| name.to_id() == *id)
102
- };
103
- let updates = |expression: &Expr, id: &Id, op: UpdateOp| {
104
- expression
105
- .as_update()
106
- .is_some_and(|update| update.op == op && reads(&update.arg, id))
107
- };
108
- let is_helper = mask >= 0
109
- && count.init.as_deref().and_then(ast::number) == Some(0.0)
110
- && counting.init.is_none()
111
- && counting
112
- .test
113
- .as_deref()
114
- .is_some_and(|test| reads(test, &low_name))
115
- && counting
116
- .update
117
- .as_deref()
118
- .is_some_and(|update| updates(update, &low_name, UpdateOp::MinusMinus))
119
- && increment
120
- .as_expr()
121
- .is_some_and(|statement| updates(&statement.expr, &count_name, UpdateOp::PlusPlus))
122
- && combined.op == BinaryOp::BitOr
123
- && masked(&combined.left, &argument) == Some(!mask)
124
- && reads(&combined.right, &count_name);
125
- is_helper.then_some(mask)
126
- }
127
-
128
- /// The `mask` of `argument & mask`, if it is a 32-bit integer.
129
- fn masked(expression: &Expr, argument: &Id) -> Option<i32> {
130
- let Expr::Bin(BinExpr {
131
- op: BinaryOp::BitAnd,
132
- left,
133
- right,
134
- ..
135
- }) = expression.unwrap_parens()
101
+ let low_id = ast::pattern_id(&low.id)?;
102
+ let count_id = ast::pattern_id(&count.id)?;
103
+ let mask = masked(low.init.as_ref()?, argument, analysis)?;
104
+ let Expression::BinaryExpression(combined) = returned.argument.as_ref()?.get_inner_expression()
136
105
  else {
137
106
  return None;
138
107
  };
139
- if left.as_ident()?.to_id() != *argument {
140
- return None;
141
- }
142
- let mask = ast::number(right)?;
143
- if mask.fract() != 0.0 {
108
+ let body = match &counting.body {
109
+ Statement::BlockStatement(block) => block.body.as_slice(),
110
+ statement => slice::from_ref(statement),
111
+ };
112
+ let [Statement::ExpressionStatement(increment)] = body else {
144
113
  return None;
145
- }
146
- i32::try_from(mask as i64).ok()
114
+ };
115
+ let tested = counting.test.as_ref()?;
116
+ let decrement = counting.update.as_ref()?;
117
+ Some(
118
+ mask >= 0
119
+ && count.init.as_ref().and_then(ast::number) == Some(0.0)
120
+ && counting.init.is_none()
121
+ && analysis.expression_id(tested) == Some(low_id)
122
+ && updated(decrement, UpdateOperator::Decrement, analysis) == Some(low_id)
123
+ && updated(&increment.expression, UpdateOperator::Increment, analysis)
124
+ == Some(count_id)
125
+ && combined.operator == BinaryOperator::BitwiseOR
126
+ && masked(&combined.left, argument, analysis) == Some(!mask)
127
+ && analysis.expression_id(&combined.right) == Some(count_id),
128
+ )
147
129
  }
148
130
 
149
- /// Whether `expression` always evaluates to a 32-bit signed integer. `>>>` yields an unsigned
150
- /// one.
151
- fn is_int32(expression: &Expr) -> bool {
152
- match expression.unwrap_parens() {
153
- Expr::Bin(binary) => {
154
- bitwise::is_bitwise(binary.op) && binary.op != BinaryOp::ZeroFillRShift
131
+ /// Checks whether an expression always evaluates to a signed 32-bit integer.
132
+ fn is_int32(expression: &Expression<'_>) -> bool {
133
+ match expression.get_inner_expression() {
134
+ Expression::BinaryExpression(binary) => {
135
+ binary.operator.is_bitwise() && binary.operator != BinaryOperator::ShiftRightZeroFill
155
136
  }
156
- Expr::Unary(unary) => unary.op == UnaryOp::Tilde,
157
- Expr::Lit(Lit::Num(number)) => f64::from(number.value as i32) == number.value,
158
- _ => false,
137
+ Expression::UnaryExpression(unary) => unary.operator.is_bitwise(),
138
+ _ => ast::number(expression).is_some_and(|number| number == js::int32(number) as f64),
159
139
  }
160
140
  }
161
141
 
162
- /// Replaces `helper(x)` with `x`, or `x | 0` when `x` may not be a 32-bit integer.
163
- struct InlineCalls<'helpers> {
164
- helpers: &'helpers [Id],
142
+ struct Inline<'b, 'a> {
143
+ analysis: &'b Analysis<'a>,
144
+ helpers: &'b HashSet<Id>,
165
145
  replaced: HashMap<Id, usize>,
166
146
  }
167
147
 
168
- impl VisitMut for InlineCalls<'_> {
169
- fn visit_mut_expr(&mut self, expression: &mut Expr) {
170
- expression.visit_mut_children_with(self);
171
- let Some((callee, [argument])) = ast::direct_call(expression) else {
172
- return;
173
- };
174
- if argument.spread.is_some() || !self.helpers.contains(&callee.to_id()) {
175
- return;
176
- }
177
- *self.replaced.entry(callee.to_id()).or_default() += 1;
178
- let span = callee.span;
179
- let argument = argument.expr.clone();
180
- *expression = if is_int32(&argument) {
181
- ast::parenthesized(argument)
182
- } else {
183
- Expr::Bin(BinExpr {
184
- span,
185
- op: BinaryOp::BitOr,
186
- left: Box::new(ast::parenthesized(argument)),
187
- right: Box::new(Expr::Lit(Lit::Num(Number {
148
+ impl<'a> VisitMut<'a> for Inline<'_, 'a> {
149
+ fn visit_expression(&mut self, expression: &mut Expression<'a>) {
150
+ walk_mut::walk_expression(self, expression);
151
+ if let Some((callee, [argument])) = ast::direct_call(expression)
152
+ && let Some(id) = self.analysis.id(callee)
153
+ && self.helpers.contains(&id)
154
+ && let Some(argument) = argument.as_expression()
155
+ {
156
+ let builder = &self.analysis.ast;
157
+ let span = callee.span;
158
+ let value = argument.clone_in_with_semantic_ids(builder.allocator());
159
+ *expression = if is_int32(&value) {
160
+ value
161
+ } else {
162
+ let zero = ast::number_literal(span, 0.0, builder);
163
+ Expression::new_binary_expression(
188
164
  span,
189
- value: 0.0,
190
- raw: None,
191
- }))),
192
- })
193
- };
194
- }
195
- }
196
-
197
- /// Removes the declarations of helpers nothing calls any longer.
198
- struct RemoveHelpers(HashSet<Id>);
199
-
200
- impl VisitMut for RemoveHelpers {
201
- fn visit_mut_stmts(&mut self, statements: &mut Vec<Stmt>) {
202
- statements.retain(|statement| {
203
- !matches!(statement, Stmt::Decl(Decl::Fn(declaration))
204
- if self.0.contains(&declaration.ident.to_id()))
205
- });
206
- statements.visit_mut_children_with(self);
165
+ value,
166
+ BinaryOperator::BitwiseOR,
167
+ zero,
168
+ builder,
169
+ )
170
+ };
171
+ *self.replaced.entry(id).or_default() += 1;
172
+ }
207
173
  }
208
174
  }
209
175
 
@@ -219,11 +185,11 @@ mod tests {
219
185
 
220
186
  #[test]
221
187
  fn inlines_helpers_whose_masks_complement() {
222
- let transform = |source: &str| testing::rewrite(source, super::run, /* fix= */ true);
188
+ let transform = |source: &str| testing::rewrite(source, super::run);
223
189
  let output = transform(&format!(
224
190
  "{HELPER}\nf(convert(a - b & 255), convert(a), convert(~a));"
225
191
  ));
226
- testing::assert_contains(&output, &[], &["f(a - b & 255, a | 0, ~a)"]);
192
+ testing::assert_contains(&output, &["f(a - b & 255, a | 0, ~a)"]);
227
193
  assert!(!output.contains("function convert"), "{output}");
228
194
  let helper = HELPER.replace("-8", "-16");
229
195
  let output = transform(&format!("{helper}\nf(convert(a & 255));"));