Commit Graph
16399 Commits
Author SHA1 Message Date
Jeong, YunWon a04189fa34 Align bytecode codegen structure with CPython 3.14 (#7588)
* Align bytecode codegen structure with CPython 3.14

* Bytecode parity - constant folding, annotation ordering, superinstruction alignment

- Add BoolOp constant folding with short-circuit semantics in compile_expression
- Add constant truthiness evaluation for assert statement optimization
- Disable const collection/boolop folding in starred unpack and assignment contexts
- Move annotation block generation after body with AnnotationsPlaceholder splicing
- Reorder insert_superinstructions to run before push_cold_blocks (matching flowgraph.c)
- Lower LOAD_CLOSURE after superinstructions to avoid false LOAD_FAST_LOAD_FAST
- Add ToBool before PopJumpIf in comparisons and chained compare cleanup blocks
- Unify annotation dict building to always use incremental BuildMap + StoreSubscr
- Add TrueDivide constant folding for integer operands
- Fold constant sets to Frozenset (not Tuple) in try_fold_constant_collection
- Add PyVmBag for frozenset constant materialization in code objects
- Add remove_redundant_const_pop_top_pairs pass and peephole const+branch folding
- Emit Nop for skipped constant expressions and constant-true asserts
- Preserve comprehension local ordering by source-order bound name collection
- Simplify annotation scanning in symboltable (remove simple-name gate)

* Fix CI regressions in marshal and fast-local ops

* impl more

* Align bytecode codegen with CPython structure

* Bytecode parity - comprehension/except scope ordering, load_fast_borrow fixes

- Reorder comprehension symbol-table walk so the outermost iterator
  registers its sub_tables in the enclosing scope before the comp
  scope, and rescan elt/ifs in CPython's order. Codegen peeks past the
  outermost iterator's nested scopes to find the comprehension table.
- For plain try/except, emit handler sub_tables before the else block
  so codegen's linear sub_table cursor stays aligned.
- Rename `collect_simple_annotations` to `collect_annotations` and
  evaluate non-simple annotations during __annotate__ compilation to
  preserve source-order side effects while keeping the simple-name
  index stable.
- Dedupe equivalent code constants in `arg_constant` and add a
  structural equality check on `CodeObject`.
- Disable LOAD_FAST_BORROW for the tail end block when a try has a
  bare `except:` clause, and have `new_block` inherit the flag from
  the current block.
- Remove `cfg!(debug_assertions)` guard around the
  `optimize_load_fast_borrow` start-depth check so mismatches are
  handled (return instead of assert) in release builds.
- Collapse nop-only blocks that precede a return epilogue and hoist
  the prior line number into the next real instruction so the
  line table matches.
- Unmark now-passing `test_consts_in_conditionals`,
  `test_load_fast_unknown_simple`,
  `test_load_fast_known_because_already_loaded`, and PEP 646 f3/f4
  annotation checks.

* Bytecode parity - try/except line tracking, assert 0 shape

- In `compile_try_except`, drop the leading Nop and set the end
  block's source range from the last orelse/body statement so line
  events after the try fall on the right line.
- Recognise constant-false asserts as the direct-raise shape (no
  ToBool/PopJumpIfFalse) and flip the test assertion accordingly.
- Extend `remove_redundant_nops_in_blocks` to also look through a
  trailing nop before a return-epilogue pair (LoadConst/ReturnValue
  or LoadSmallInt/ReturnValue) so the epilogue keeps the correct
  line number.
- Rename `preds` to `predecessor_blocks` in the LOAD_FAST_BORROW
  disable pass and add a test-only `debug_late_cfg_trace` helper.
- Regenerate the `nested_double_async_with` snapshot: the tail
  reference to `stop_exc` now emits LOAD_FAST instead of
  LOAD_FAST_BORROW.

* Bytecode parity - iter folding, break/continue line, cold inlining

- Fold a constant list iterable into a constant tuple in for-loop
  iterable position, matching the CPython optimizer, and strip a
  redundant LIST_TO_TUPLE immediately before GET_ITER in the IR
  peephole pass.
- Emit a Nop at the break/continue source range before unwinding
  so line events land on the break/continue statement instead of
  the following instruction.
- Drop `propagate_disable_load_fast_borrow`; the forward propagation
  was over-zealous and the per-block inheritance in `new_block` plus
  the bare-except marker are enough.
- Relax `inline_small_or_no_lineno_blocks` so small exit blocks at
  the tail of a cold block are always inlined, not just return
  epilogues.
- Add codegen tests covering the LIST_TO_TUPLE/GET_ITER peephole and
  the late-CFG trace helper for a for-loop list-literal iterable.
2026-04-18 09:19:11 +09:00
Shahar Naveh a61d2e81c0 Fix reviewdog permissions (#7619) 2026-04-17 20:07:19 +09:00
Shahar Naveh b42bfdc93d Update test_itertools.py from 3.14.4 (#7618) 2026-04-17 20:06:48 +09:00
Shahar Naveh 11493eb56b Add const methods for oparg enums (#7617)
* Add const methods for oparg enums

* Shorten doc link
2026-04-17 20:06:30 +09:00
Shahar Naveh 930a07b7df Constify OpArgState methods (#7616) 2026-04-17 20:05:37 +09:00
Shahar Naveh 8d1000d485 Simplify Intruction.deopt() (#7615)
* Simplify `Instruction.deopt()`

* Adjust `scripts/generate_opcode_metadata.py`
2026-04-17 20:04:22 +09:00
Joshua Megnauth 6ae61bd4f2 fix: Python-Rust combining char diff in isalnum (#7612)
* fix: Python-Rust combining char diff in isalnum

Related to: #7518

Rust and Python differ on alphanumeric characters. Rust follows the
Unicode standard closer than Python. This means that is_alphanumeric
(char function in Rust) is different from isalnum (Python). To fix the
discrepancy, RustPython needs to mimic Python by rejecting certain
characters. Some classes of combining characters count as alphanumeric
in Rust but not Python. Combining characters are accent marks
that are combined with other characters to create a single grapheme.

It's possible that this PR is not exhaustive. I fixed the combining
character issue BUT I don't know the full range of discrepancies.

* fix: Ignore combining characters in SRE

Closes: #7518
2026-04-17 18:45:43 +09:00
Joshua Megnauth ddfa379ce2 Fix compiling with OpenSSL (#7621) 2026-04-17 18:27:49 +09:00
Noa a65dee10bd Merge pull request #7620 from ShaharNaveh/ci-fix-clippy
CI: fix clippy lints
2026-04-16 15:15:27 -05:00
ShaharNaveh 57cb4f4ff8 Clippy lints 2026-04-16 16:54:28 +02:00
Shahar Naveh d3e12a6fe0 Update test_struct.py from 3.14.4 (#7614) 2026-04-16 08:52:37 +09:00
Shahar Naveh e52e698d36 Simplify cache_entries match statement (#7613)
* Simplify cache_entries method

* Use `Opcode`
2026-04-16 08:52:11 +09:00
dependabot[bot] 79172e6832 Bump follow-redirects from 1.15.9 to 1.16.0 in /wasm/demo (#7596)
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.9 to 1.16.0.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.9...v1.16.0)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-16 03:18:33 +09:00
Shahar Naveh 63fa928074 Macro for defining opcode & instruction enums (#7573)
* Macro for defining opcode & instruction enums

* Convert `Instruction` as well

* revert `#[repr(...)]` changes
2026-04-16 03:18:14 +09:00
Shahar Naveh 84d74e4bca Unify CI caches (reduce total cache size by 75% ±) (#7610)
* Singular job for creating caches

* Use shared cache
2026-04-15 14:19:17 +09:00
Shahar Naveh a02fae38cb Update test_bisect.py from 3.14.4 (#7609) 2026-04-15 14:17:48 +09:00
Shahar Naveh e195d742af Update test_bz2.py from 3.14.4 (#7608)
* Update `test_bz2.py` from 3.14.4

* Mark failing test
2026-04-15 14:17:27 +09:00
Shahar Naveh 30323d5a52 Update seq tests from 3.14.4 (#7606)
* Update seq related tests
2026-04-15 14:17:01 +09:00
Shahar Naveh 38f5cbc9a9 Update test_compile.py from 3.14.4 (#7607) 2026-04-15 14:15:48 +09:00
Shahar Naveh 4673fb8b4a Update test_range.py from 3.14.4 (#7605) 2026-04-15 14:15:27 +09:00
dependabot[bot] 6bc7250b8c Bump reviewdog/action-actionlint from 1.71.0 to 1.72.0
Bumps [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) from 1.71.0 to 1.72.0.
- [Release notes](https://github.com/reviewdog/action-actionlint/releases)
- [Commits](https://github.com/reviewdog/action-actionlint/compare/0d952c597ef8459f634d7145b0b044a9699e5e43...6fb7acc99f4a1008869fa8a0f09cfca740837d9d)

---
updated-dependencies:
- dependency-name: reviewdog/action-actionlint
  dependency-version: 1.72.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-15 14:14:09 +09:00
ShaharNaveh a40cad8920 Udpate http from 3.14.4 2026-04-14 21:02:25 +09:00
ShaharNaveh 3acab100f4 Update test_http_cookies.py from 3.14.3 2026-04-14 21:02:25 +09:00
Jeong, YunWon 6cf3cc7715 Merge pull request #7600 from ShaharNaveh/update-test-urllib 2026-04-14 21:02:07 +09:00
Jeong, YunWon df4fa43a56 Merge pull request #7597 from RustPython/dependabot/cargo/rand-0.9.3 2026-04-14 21:01:45 +09:00
ShaharNaveh 64415f596c Update libc to 0.2.185 2026-04-14 21:00:12 +09:00
Jeong, YunWon 66f3dc031a Merge pull request #7599 from ShaharNaveh/update-test-pyexpat 2026-04-14 20:59:41 +09:00
ShaharNaveh 5b4547f074 Marking failing test 2026-04-14 13:04:50 +02:00
ShaharNaveh 2f45d79e44 Add XMLParserType 2026-04-14 13:03:59 +02:00
ShaharNaveh 9e12f82846 Merge remote-tracking branch 'upstream/main' into update-test-pyexpat 2026-04-14 12:15:22 +02:00
dependabot[bot] 243604a1ab Bump the wasmtime group with 2 updates (#7591)
Bumps the wasmtime group with 2 updates: [cranelift-jit](https://github.com/bytecodealliance/wasmtime) and [cranelift-module](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift-jit` from 0.130.0 to 0.130.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.130.0 to 0.130.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.130.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.130.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-14 16:08:35 +09:00
github-actions[bot]andgithub-actions[bot] 4a8415d543 Update doc DB for CPython 3.14.4 (#7598)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-04-14 16:07:22 +09:00
ShaharNaveh 9b47266fe6 Remove newlines from test_urllib2_localnet.py 2026-04-14 08:58:51 +02:00
ShaharNaveh b01ea23988 Udpate test_pyexpat.py from 3.14.4 2026-04-14 08:57:35 +02:00
dependabot[bot] a4d5ee96a1 Bump rand from 0.9.2 to 0.9.3
Bumps [rand](https://github.com/rust-random/rand) from 0.9.2 to 0.9.3.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/0.9.3/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/rand_core-0.9.2...0.9.3)

---
updated-dependencies:
- dependency-name: rand
  dependency-version: 0.9.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-14 01:22:41 +00:00
Joshua Megnauth 1584276b5e fix: Handle char expansion in islower, isupper (#7583)
* fix: Handle char expansion in islower, isupper

Closes: #7526

`py_islower` and `py_isupper` need to handle expansions for letter
casing. Comparing chars directly can miss edge cases in certain
languages. Unfortunately, like the last PR, this allocates to handle
potential expansions.

I also had to add `icu_casemap` as a dependency.
RustPython is already using parts of icu4x so this doesn't add many
transitive dependencies.

* Ensure islower/isupper handles strs without chars

This fixes a regression mentioned by CodeRabbit. I also figured out how
to check a string's case without allocation using Unicode properties.
Thus, this commit removes `icu_casemap` again. `icu_casemap` and my old
solution is required for a robust case check, but it seems like the
current code is fine for Python.
2026-04-14 10:19:31 +09:00
Bas Schoenmaeckers 4875323705 Allow creating PyCapsule objects (#7595) 2026-04-14 09:44:02 +09:00
Copilotandyouknowone 76755524df Add __callback__ property to weakref type (#7590)
* Initial plan

* Add __callback__ property to PyWeak for weakref compatibility

Add get_callback() method to PyWeak in core.rs that safely reads the
callback field under the stripe lock. Expose it as a read-only
__callback__ property on the weakref type, matching CPython behavior:
- Returns the callback function when one was provided and referent is alive
- Returns None when no callback was provided
- Returns None after the referent has been collected
- Raises AttributeError on assignment (read-only)

Remove @unittest.expectedFailure from test_callback_attribute and
test_callback_attribute_after_deletion in test_weakref.py.

Add regression tests to extra_tests/snippets/stdlib_weakref.py.

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/a8689daa-4476-4645-a935-0e13c7f7bb42

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Fix ruff formatting in stdlib_weakref.py snippet

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/4995198f-e083-4dac-823a-166fcf54adc4

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-04-13 23:58:58 +09:00
Jeong, YunWon 030da76d4e Add InstructionMetadata::stack_effect_jump for branch stack effects (#7585)
* Add InstructionMetadata::stack_effect_jump for branch stack effects

CPython's compile.c provides stack_effect(opcode, oparg, jump) where the
jump parameter selects between fallthrough and branch effects. The existing
stack_effect() only returns the fallthrough effect.

Add stack_effect_jump() that returns the branch effect. Most instructions
have identical fallthrough/branch effects; ForIter and Send are the
exceptions (ForIter: fallthrough=+1, branch=-1; Send: fallthrough=0,
branch=-1).

* apply review
2026-04-13 17:25:26 +09:00
🍌Shawn a6c2f72407 Update LICENSE (#7581) 2026-04-13 12:49:32 +09:00
Jeong, YunWon 7abf8cc247 Bytecode parity - for-loop cleanup, return duplication, late jump threading fix (#7580)
- Use POP_TOP instead of POP_ITER for for-loop break/return cleanup
- Expand duplicate_end_returns to clone final return for jump predecessors
- Restrict late jump threading pass to unconditional jumps only
- Skip exception blocks in inline/reorder passes
- Simplify threaded_jump_instr NoInterrupt handling
2026-04-12 22:43:35 +09:00
Shahar Naveh cb976b411f Fail if prek fails (#7574) 2026-04-10 18:50:03 +09:00
Shahar Naveh c98b6d85de Remove overly broad permissions from release.yml (#7577) 2026-04-10 18:49:37 +09:00
Jeong, YunWon 4e2ce58693 Bytecode parity - direct loop backedges (#7578) 2026-04-10 18:48:57 +09:00
Shahar Naveh 98de82c5f0 Revert "Only run cargo check when rust code is changed (#7572)" (#7579) 2026-04-10 18:07:11 +09:00
Jeong, YunWon 0b7e0f007b Bytecode parity - exception (#7557)
* Fix exception handling: except* chaining, finally cleanup, RERAISE

- Align except* bytecode chaining
- Fix exception state model and finally handler cleanup
- Fix RERAISE to only pop exception, preserve values below

* Port IR optimization passes from flowgraph.c

- BUILD_TUPLE n + UNPACK_SEQUENCE n elimination
- Dead store elimination within basic blocks
- apply_static_swaps for SWAP reduction

* Add bytecode comparison and disassembly dump scripts

- compare_bytecode.py: compare CPython vs RustPython bytecode output
- dis_dump.py: extract disassembly in normalized JSON format
2026-04-10 12:51:48 +09:00
Shahar Naveh dcae8f0d53 Update some libs and tests from 3.14.3 to 3.14.4 (#7576)
* Update some libs and tests to 3.14.4

* Update `pydoc_data`
2026-04-10 09:16:10 +09:00
Shahar Naveh f937cde7af Only run cargo check when rust code is changed (#7572) 2026-04-10 02:40:15 +09:00
Shahar Naveh c4c28a4449 Unify python version used by CI. Update to 3.14.4 (#7571)
* Add `.python-version` file

* Modify CI to use `.python-version` file

* Use correct path for `.python-version` file
2026-04-10 02:38:14 +09:00
dependabot[bot] 1012626bbb Bump cargo-bins/cargo-binstall from 1.17.8 to 1.17.9 (#7566)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.17.8 to 1.17.9.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](https://github.com/cargo-bins/cargo-binstall/compare/113a77a4ce971c41332f2129c3d995df993cf746...0b24824336e2b3800b0f89d9e08b2c08bfa3dcdd)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.17.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-06 23:30:13 +09:00