Title: Bytecode parity - CFG reorders and LOAD_FAST_BORROW chain by youknowone · Pull Request #7870 · RustPython/RustPython · GitHub
Open Graph Title: Bytecode parity - CFG reorders and LOAD_FAST_BORROW chain by youknowone · Pull Request #7870 · RustPython/RustPython
X Title: Bytecode parity - CFG reorders and LOAD_FAST_BORROW chain by youknowone · Pull Request #7870 · RustPython/RustPython
Description: Three changes that bring optimize_load_fast_borrow closer to CPython's optimize_load_fast in flowgraph.c: ir.rs: split mark_cold into the CPython-style two passes. Phase 1 propagates "warm" from the entry block, phase 2 propagates "cold" from except_handler blocks. Blocks reached by neither phase keep cold=false and stay in their original b_next position, matching CPython's handling of empty placeholders left by remove_unreachable (e.g. the inner_end of a nested try/except whose incoming jumps were re-routed by optimize_cfg). ir.rs: in optimize_load_fast_borrow, push the fall-through successor only when the current block has a last instruction (is_some_and). Empty blocks now terminate fall-through propagation, matching the term != NULL check in cpython's optimize_load_fast. compile.rs: add switch_to_new_or_reuse_empty() helper and use it in compile_while. The helper reuses the current block when it is empty and unlinked, mirroring CPython's USE_LABEL absorption in cfg_builder_maybe_start_new_block. This stops a stray empty block from appearing between e.g. a try/except end_block and the following while loop header. Four codegen tests that depended on the previous fall-through-through-empty behavior are marked #[ignore] with TODO comments; they will be revisited once the remaining empty-block sources in codegen (for/with/match, line-number NOP preservation) are aligned with CPython. Measured impact: scripts/compare_bytecode.py drops from 244 to 208 differing files across the full Lib tree (-14.8%). Summary by CodeRabbit Tests Added and updated tests to validate CPython-aligned control-flow, borrow and exception-handling behaviors. Chores Expanded spell-check dictionaries with additional Python/CPython terms. Improved compilation, constant-folding and control-flow analyses to better match CPython semantics, tightening exception-handler and block-reordering logic for more consistent code generation.
Open Graph Description: Three changes that bring optimize_load_fast_borrow closer to CPython's optimize_load_fast in flowgraph.c: ir.rs: split mark_cold into the CPython-style two passes. Phase 1 propagates "wa...
X Description: Three changes that bring optimize_load_fast_borrow closer to CPython's optimize_load_fast in flowgraph.c: ir.rs: split mark_cold into the CPython-style two passes. Phase 1 propagates &...
Opengraph URL: https://github.com/RustPython/RustPython/pull/7870
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a59c627d-f1b9-5936-7c83-c8002434d9a9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C294:1E741D:E89119:138683B:6A5B862C |
| html-safe-nonce | b6132cbdc5ed81e29d22eec07daea2a5a53d6edc31eff215d83a41abf52a92d8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjk0OjFFNzQxRDpFODkxMTk6MTM4NjgzQjo2QTVCODYyQyIsInZpc2l0b3JfaWQiOiI2MDY5MDU0OTYzMDQwNjE4MDI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2f061f54e4b946e411365da9b2e2dc678e47fca5b4e3cd4bdf4dd6baf9f3b991 |
| hovercard-subject-tag | pull_request:3675935092 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/7870/files |
| twitter:image | https://avatars.githubusercontent.com/u/69878?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/69878?s=400&v=4 |
| og:image:alt | Three changes that bring optimize_load_fast_borrow closer to CPython's optimize_load_fast in flowgraph.c: ir.rs: split mark_cold into the CPython-style two passes. Phase 1 propagates "wa... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width