Commit Graph

16106 Commits

Author SHA1 Message Date
Jeong, YunWon
3865fdbf5b Revert class lookup (#7306)
* Revert __class__ lookup skip in object_isinstance

The optimization to skip __class__ lookup based on getattro check
was incorrect: a class can override __class__ as a property while
still using standard __getattribute__. Revert to always performing
the lookup, matching CPython's object_isinstance behavior.

* Collapse nested if in object_isinstance for clippy
2026-03-02 19:41:43 +09:00
Jeong, YunWon
baba1f9447 Fix symbol table sub_table desync for non-simple annotation targets (#7300)
* Fix symbol table sub_table desync for non-simple annotation targets

Non-simple annotations (subscript/attribute/parenthesized targets like
`a[0]: expr`) were scanned in the annotation scope during symbol table
analysis, creating sub_tables for any comprehensions. But codegen only
compiles simple name annotations into __annotate__, so those sub_tables
were never consumed. This caused subsequent simple annotations'
comprehension sub_tables to get the wrong index, resulting in
"the symbol 'X' must be present in the symbol table" errors.

Fix: skip entering annotation scope for non-simple annotations since
they are never compiled into __annotate__.

* Validate forbidden expressions in non-simple annotation targets

Fix cspell "desynchronize" warning and validate yield/await/named/async
comprehension expressions in non-simple annotations without creating
annotation scopes.

* Restore in_annotation flag before propagating error
2026-03-02 16:47:16 +09:00
Jeong, YunWon
c315033091 Implement LOAD_ATTR inline caching with adaptive specialization (#7292)
* Implement LOAD_ATTR inline caching with adaptive specialization

Add type version counter (tp_version_tag) to PyType with subclass
invalidation cascade. Add cache read/write methods (u16/u32/u64)
to CodeUnits. Implement adaptive specialization in load_attr that
replaces the opcode with specialized variants on first execution:

- LoadAttrMethodNoDict: cached method lookup for slotted types
- LoadAttrMethodWithValues: cached method with dict shadow check
- LoadAttrInstanceValue: direct dict lookup skipping descriptors

Specialized opcodes guard on type_version_tag and deoptimize back
to generic LOAD_ATTR with backoff counter on cache miss.

* Add BINARY_OP and CALL adaptive specialization

BINARY_OP: Specialize int add/subtract/multiply and float
add/subtract/multiply with type guards and deoptimization.

CALL: Add func_version to PyFunction, specialize simple
function calls (CallPyExactArgs, CallBoundMethodExactArgs)
with invoke_exact_args fast path that skips FuncArgs
allocation and fill_locals_from_args.

* Lazy quickening for adaptive specialization counters

Move counter initialization from compile-time to RESUME execution,
matching CPython's _PyCode_Quicken pattern. Store counter in CACHE
entry's arg byte to preserve op=Instruction::Cache for dis/JIT.
Add PyCode.quickened flag for one-time initialization.

* Add Instruction::deoptimize() and CodeUnits::original_bytes()

- deoptimize() maps specialized opcodes back to their base adaptive variant
- original_bytes() produces deoptimized bytecode with zeroed CACHE entries
- co_code now returns deoptimized bytes, _co_code_adaptive returns current bytes
- Marshal serialization uses original_bytes() instead of raw transmute

* Fix monitoring and specialization interaction

- cache_entries() returns correct count for instrumented opcodes
- deoptimize() maps instrumented opcodes back to base
- quicken() skips adaptive counter for instrumented opcodes
- instrument_code Phase 3 deoptimizes specialized opcodes and
  clears CACHE entries to prevent stale pointer dereferences

* Address review: bounds checks, UB fix, version overflow, error handling

- Add bounds checks to read_cache_u16/u32/u64
- Fix quicken() aliasing UB by using &mut directly
- Add JumpBackwardJit/JumpBackwardNoJit to deoptimize()
- Guard can_specialize_call with NEWLOCALS flag check
- Use compare_exchange_weak for version tag to prevent wraparound
- Propagate dict lookup errors in LoadAttrMethodWithValues
- Apply adaptive backoff on version tag assignment failure
- Remove duplicate imports in frame.rs
2026-03-02 16:36:57 +09:00
Jeong, YunWon
b1cddc4e0c Merge pull request #7296 from youknowone/sysconfig
Update sysconfig from v3.14.3 and also fix _sysconfig
2026-03-02 13:13:20 +09:00
Jeong, YunWon
3a81f94aa8 Optimize unpack, str.__add__ and fastlocals (#7293)
* Remove intermediate Vec allocation in unpack_sequence fast path

Push elements directly from tuple/list slice in reverse order
instead of cloning into a temporary Vec first.

* Use read-only atomic load before swap in check_signals

Add Relaxed load guard before the Acquire swap to avoid cache-line
invalidation on every instruction dispatch when no signal is pending.

* Cache builtins downcast in ExecutingFrame for LOAD_GLOBAL

Pre-compute builtins.downcast_ref::<PyDict>() at frame entry and reuse
the cached reference in load_global_or_builtin and LoadBuildClass.
Also add get_chain_exact to skip redundant exact_dict type checks.

* Add number Add slot to PyStr for direct str+str dispatch

binary_op1 can now resolve str+str addition directly via the number
slot instead of falling through to the sequence concat path.

* Guard FastLocals access in locals() with try_lock on state mutex

Address CodeRabbit review: f_locals() could access fastlocals without
synchronization when called from another thread. Use try_lock on the
state mutex so concurrent access is properly serialized.

* Use exact type check for builtins_dict cache

downcast_ref::<PyDict>() matches dict subclasses, causing
get_chain_exact to bypass custom __getitem__ overrides.
Use downcast_ref_if_exact to only fast-path exact dict types.

* Consolidate with_recursion in _cmp to single guard

Move the recursion depth check to wrap the entire _cmp body
instead of each individual call_cmp direction, reducing Cell
read/write pairs and scopeguard overhead per comparison.

* Add opcode-level fast paths for FOR_ITER, COMPARE_OP, BINARY_OP

- FOR_ITER: detect PyRangeIterator and bypass generic iterator
  protocol (atomic slot load + indirect call)
- COMPARE_OP: inline int/float comparison for exact types,
  skip rich_compare dispatch and with_recursion overhead
- BINARY_OP: inline int add/sub with i64 checked arithmetic
  to avoid BigInt heap allocation and binary_op1 dispatch

* Also check globals is exact dict for LOAD_GLOBAL fast path

get_chain_exact bypasses __missing__ on dict subclasses.
Move get_chain_exact to PyExact<PyDict> impl with debug_assert,
and have get_chain delegate to it. Store builtins_dict as
Option<&PyExact<PyDict>> to enforce exact type at compile time.

Use PyRangeIterator::next_fast() instead of pub(crate) fields.
Fix comment style issues.
2026-03-02 12:37:43 +09:00
dependabot[bot]
7b89d8252e Bump github/gh-aw from 0.51.2 to 0.51.4 (#7305)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.51.2 to 0.51.4.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](cccf96100f...e422993ded)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.51.4
  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-03-02 11:08:22 +09:00
Jeong, YunWon
888e0eeccb Add str(int) and repr(int) fast path using i64 conversion (#7302)
* Add str(int) and repr(int) fast path using i64 conversion

- Skip __str__ method resolution for exact PyInt in PyObject::str()
- Use i64::to_string() for small integers, BigInt::to_string() for large ones
- ~36% improvement in str(int) benchmarks

* Extract PyInt::to_str_radix_10() to deduplicate i64 fast path logic
2026-03-02 11:02:49 +09:00
Jeong, YunWon
69fc75b22d Skip __class__ lookup in object_isinstance for standard getattro (#7303)
In object_isinstance(), when is_subtype() returns false, the __class__
attribute lookup via get_attribute_opt is redundant for objects using
standard __getattribute__, since __class__ is a data descriptor on
object that always returns obj.class().
2026-03-02 10:18:45 +09:00
fanninpm
f443226e46 Add crypto group to dependabot config (#7304) 2026-03-02 10:18:01 +09:00
CPython Developers
5a11f33751 Update sysconfig from v3.14.3 2026-03-02 01:24:15 +09:00
Jeong, YunWon
d0b5a5af50 [update_lib] fast date lookup for todo (#7299)
* [update_lib] fast date lookup for todo

* add deps

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-02 01:23:52 +09:00
Shahar Naveh
ca390dc5fb io.TextIoWrapper.reconfigure to always flush (#7281)
* Always flush on reconfigure (io.TextWrapper)

* Add test
2026-03-02 01:03:44 +09:00
dependabot[bot]
a6b3a5b6bc Bump github/gh-aw from 0.50.7 to 0.51.2 (#7295)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.50.7 to 0.51.2.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](9cbca3cd9b...cccf96100f)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.51.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 23:39:56 +09:00
Jeong, YunWon
5eadae8c2e Implement PyStackRef borrowed stack references for LOAD_FAST_BORROW (#7290)
* Implement PyStackRef borrowed stack references for LOAD_FAST_BORROW

* Fix PyStackRef: use NonZeroUsize for niche optimization, revert borrowed refs

- Change PyStackRef.bits from usize to NonZeroUsize so Option<PyStackRef>
  has the same size as Option<PyObjectRef> via niche optimization
- Revert LoadFastBorrow to use clone instead of actual borrowed refs
  to avoid borrowed refs remaining on stack at yield points
- Add static size assertions for Option<PyStackRef>
- Add stackref, fastlocal to cspell dictionary
- Remove debug eprintln statements
- Fix clippy warning for unused push_borrowed

* Add borrowed ref debug_assert to InstrumentedYieldValue, clean up comments
2026-03-01 23:32:56 +09:00
dependabot[bot]
58a0f74c76 Bump aws-lc-rs from 1.15.4 to 1.16.0 (#7298)
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.15.4 to 1.16.0.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/v1.15.4...v1.16.0)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.16.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 23:27:40 +09:00
Shahar Naveh
707135f851 Add npm to dependabot (#7291) 2026-03-01 21:55:34 +09:00
Jeong, YunWon
d23eb4af6c Add sysconfig build vars and fix value types
- Add prefix, exec_prefix, BINDIR to sysconfigdata build_time_vars
- Add Py_DEBUG and ABIFLAGS to sysconfigdata
- Fix Py_GIL_DISABLED/Py_DEBUG to use int (1/0) instead of bool
- Gitignore generated _sysconfig_vars*.json
2026-03-01 21:53:42 +09:00
Jeong, YunWon
2b084457ef Optimize fast_locals and atomic ordering (#7289)
* Relax RefCount atomic ordering from SeqCst to Arc pattern

- inc/inc_by/get: SeqCst → Relaxed
- safe_inc CAS: SeqCst → Relaxed + compare_exchange_weak
- dec: SeqCst → Release + Acquire fence when count drops to 0
- leak CAS: SeqCst → AcqRel/Relaxed + compare_exchange_weak

* Reuse existing Vec via prepend_arg in execute_call

Replace vec![self_val] + extend(args.args) with
FuncArgs::prepend_arg() to avoid a second heap allocation
on every method call.

* Skip downcast_ref checks in invoke when tracing is disabled

Early return in PyCallable::invoke() when use_tracing is false,
avoiding two downcast_ref type checks on every function call.

* Replace fastlocals PyMutex with UnsafeCell-based FastLocals

Eliminate per-instruction mutex lock/unlock overhead for local
variable access. FastLocals uses UnsafeCell with safety guaranteed
by the frame's state mutex and sequential same-thread execution.

Affects 14+ lock() call sites in hot instruction paths (LoadFast,
StoreFast, DeleteFast, and their paired variants).

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-01 20:53:12 +09:00
CPython Developers
333ce69374 Update zoneinfo from v3.14.3 2026-03-01 20:51:10 +09:00
CPython Developers
e68fac8655 Update tempfile from v3.14.3 2026-03-01 20:50:21 +09:00
ShaharNaveh
367aff93f0 Update test_dynamicclassattribute.py from 3.14.3 2026-03-01 19:27:33 +09:00
Jeong, YunWon
ae8c0b3a93 skip flaky weakref test (#7286) 2026-03-01 15:28:23 +09:00
Jeong, YunWon
ccd377cc47 instruction CACHE (#7251)
* Emit CACHE code units in bytecode to match CPython 3.14

- Add cache_entries() method to Instruction enum
- Emit CACHE code units after opcodes in finalize_code
- Handle NO_LOCATION (line=-1) in linetable for CACHE entries
- Account for CACHE entries in exception table generation
- Skip CACHE entries in VM execution loop (with jump detection)
- Handle CACHE in InstrumentedLine/InstrumentedInstruction/InstrumentedForIter/InstrumentedNotTaken
- Skip CACHE in monitoring instrumentation phases
- Update co_branches() for cache-adjusted offsets
- Restore _cache_format in Lib/opcode.py
- Remove expectedFailure from test_c_call, test_start_offset

* Use relative jump offsets and fix bytecode layout

- Convert jump arguments from absolute to relative offsets
  in frame.rs, monitoring.rs, and stack_analysis
- Add jump_relative_forward/backward helpers to ExecutingFrame
- Resolve pseudo jump instructions before offset fixpoint loop
- Emit NOP for break, continue, pass to match line-tracing
- Fix async for: emit EndAsyncFor with correct target, add NotTaken
- Fix comprehension if-cleanup to use separate block
- Fix super() source range for multi-line calls
- Fix NOP removal to preserve line-marker NOPs
- Fix InstrumentedLine cache skipping after re-dispatch
- Match InstrumentedResume/YieldValue in yield_from_target
- Remove CALL_FUNCTION_EX cache entry from opcode.py
- Remove resolved expectedFailure markers

* Align CPython 3.14 LOAD_GLOBAL null-bit and RERAISE semantics

* Remove redundant CPython-referencing comments

Clean up comments that unnecessarily mention CPython per project
convention. Replace with concise descriptions of the behavior itself.
2026-03-01 14:51:54 +09:00
Jeong, YunWon
e4938cf61e Merge pull request #7283 from youknowone/ssl
Update ssl from v3.14.3 and add _ssl.HAS_PHA
2026-03-01 14:49:08 +09:00
Jeong, YunWon
130c771538 Update random from v3.14.3 and fix getrandbits (#7270)
* Update random from v3.14.3

* getrandbits and itertools.repeat now accept __index__ protocol.

---------

Co-authored-by: CPython Developers <>
2026-03-01 13:20:32 +09:00
Jeong, YunWon
dd6cf74fd7 Implement trace/profile events and opcode tracing for generators (#7268)
- Add TraceEvent::Exception and Opcode variants with profile filtering
- Extract dispatch_traced_frame helper for Call/Return trace events
- Fire exception trace on new raises, SEND StopIteration, FOR_ITER StopIteration
- Fire opcode trace events gated by f_trace_opcodes
- Move prev_line to FrameState for persistence across generator suspend/resume
- Reset prev_line in gen_throw for correct LINE monitoring after yield
- Add per-code event mask (events_for_code) to prevent unrelated code instrumentation
- Remove expectedFailure markers from test_bdb (5) and test_sys_setprofile (14)
2026-03-01 13:18:37 +09:00
github-actions[bot]
3e3165bc42 Auto-format: cargo fmt --all 2026-03-01 02:38:15 +00:00
Jeong, YunWon
c29b96d09e Fix ssl options setter to raise ValueError for negative values and mark still-failing tests 2026-03-01 11:37:19 +09:00
CPython Developers
4d0f52adc9 Update ssl from v3.14.3 2026-03-01 11:36:46 +09:00
fanninpm
919a14623d Remove test_importlib from polluters (#7279) 2026-03-01 10:58:47 +09:00
Shahar Naveh
5a56a76fad Update test_set.py from 3.14.3 (#7282)
* Update `test_set.py` from 3.14.3

* Cleanup code a bit

* Mark failing tests
2026-03-01 10:58:23 +09:00
Jeong, YunWon
28299e3136 Add missing HAS_PHA constant to _ssl module 2026-03-01 10:57:44 +09:00
Jiseok CHOI
be29462087 Fix _hashlib.compare_digest to reject non-ASCII strings (#7280)
Add non-ASCII string check to _hashlib.compare_digest, matching the
behavior of _operator._compare_digest. When both arguments are strings,
non-ASCII characters now correctly raise TypeError.

Also replace the non-constant-time == comparison with constant_time_eq
for proper timing-attack resistance, and return PyResult<bool> instead
of PyResult<PyObjectRef>.
2026-03-01 10:51:39 +09:00
Jiseok CHOI
7b7c7a1b6e sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() propagation (#7278)
Add #[pygetset] getter/setter for Cursor.row_factory so that Python-level
attribute access reads/writes the Rust struct field instead of the
instance dict.

Fix Connection.cursor() to only propagate the connection's row_factory
to the cursor when the connection's row_factory is not None, matching
CPython behavior. Previously it unconditionally overwrote the cursor's
row_factory, discarding any factory set by a cursor subclass __init__.
2026-03-01 10:44:50 +09:00
Jiseok CHOI
be39a67f27 Handle reentrant detach in TextIOWrapper.close() (#7277)
When a custom `closed` property on the underlying buffer calls
`detach()` during the `file_closed()` check in `close()`, the
wrapper's internal buffer becomes None. Subsequent flush/close
operations then fail with AttributeError on NoneType.

Add a guard after the `file_closed()` check to detect if the buffer
was detached reentrantly, and return early in that case (detach has
already flushed the stream).

This mirrors the fix applied in CPython
(https://github.com/python/cpython/issues/142594\).
2026-03-01 10:44:13 +09:00
Shahar Naveh
bef46f17d5 Fix list.__repr__ deadlock (#7275)
* Fix list repr deadlock

* Unmark apssing test
2026-03-01 10:43:23 +09:00
ShaharNaveh
11ddf6e065 Mark failing tests 2026-03-01 10:42:37 +09:00
ShaharNaveh
9fad2c0b1d Update test_format.py from 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
48d574f90f Update test_strtod.py 2026-03-01 10:42:37 +09:00
ShaharNaveh
3b0be19b10 Update test_string_literals.py from 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
1731984393 Update test_str.py to 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
d6adfb0b59 Update test_dynamic.py to 3.14.3 2026-03-01 10:39:06 +09:00
Shahar Naveh
b05e74b78e Don't return frozenset for modules (#7276) 2026-03-01 09:43:34 +09:00
Jiseok CHOI
2833cd8896 add isatty() method in BytesIO (#7243) 2026-02-28 15:55:12 +00:00
dependabot[bot]
a4a9b29687 Bump env_logger from 0.11.8 to 0.11.9 (#7267)
Bumps [env_logger](https://github.com/rust-cli/env_logger) from 0.11.8 to 0.11.9.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.8...v0.11.9)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-version: 0.11.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-03-01 00:36:06 +09:00
dependabot[bot]
cc5f9edd43 Bump junction from 1.4.1 to 1.4.2 (#7266)
Bumps [junction](https://github.com/tesuji/junction) from 1.4.1 to 1.4.2.
- [Release notes](https://github.com/tesuji/junction/releases)
- [Changelog](https://github.com/tesuji/junction/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tesuji/junction/compare/v1.4.1...v1.4.2)

---
updated-dependencies:
- dependency-name: junction
  dependency-version: 1.4.2
  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-03-01 00:35:48 +09:00
dependabot[bot]
85d4c42a6b Bump actions/upload-artifact from 6.0.0 to 7.0.0 (#7264)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:18:04 +09:00
dependabot[bot]
dd84a19b5b Bump github/gh-aw from 0.49.4 to 0.50.7 (#7262)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.49.4 to 0.50.7.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](bf34f99475...9cbca3cd9b)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.50.7
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:17:53 +09:00
dependabot[bot]
5861393ad8 Bump actions/download-artifact from 7.0.0 to 8.0.0 (#7263)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7.0.0 to 8.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v7...v8)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:17:38 +09:00
Jeong, YunWon
8676ba9128 getrandbits and itertools.repeat now accept __index__ protocol. 2026-02-28 22:58:56 +09:00