Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-150587: Guard specialized list-int subscript indices#153004

Closed
KRRT7 wants to merge 3 commits into
python:mainpython/cpython:mainfrom
KRRT7:list-int-compact-guardKRRT7/cpython:list-int-compact-guardCopy head branch name to clipboard
Closed

gh-150587: Guard specialized list-int subscript indices#153004
KRRT7 wants to merge 3 commits into
python:mainpython/cpython:mainfrom
KRRT7:list-int-compact-guardKRRT7/cpython:list-int-compact-guardCopy head branch name to clipboard

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 4, 2026

Copy link
Copy Markdown

Fixes gh-150587.

This supersedes the earlier closed PR gh-150588. That patch was moved into gh-150425 at the time, but the broad performance PR has not landed, so this keeps the correctness fix as a focused standalone change.

This makes the runtime invariant explicit for the specialized list/int subscript and store-subscript paths. Both opcodes are selected only after seeing a compact non-negative int index, but their runtime guard only ensures an exact int. If the same specialized code later sees a non-compact exact int, it must fall back before calling _PyLong_CompactValue().

Changes:

  • Add compact non-negative int fallback checks before _PyLong_CompactValue() in BINARY_OP_SUBSCR_LIST_INT and STORE_SUBSCR_LIST_INT.
  • Regenerate the tier-1, tier-2, and _testinternalcapi generated case headers.
  • Add regression coverage that warms the specialized opcode with index 0, then calls it with 2**30 + 2 and verifies generic IndexError behavior instead of using the low digit as the list index.

Tests:

  • ./python.exe -m test test_opcache -v
  • ./python.exe -m test test_opcache -m test_binary_subscr -m test_store_subscr -v
  • env PYTHON_JIT=1 ./python.exe -m test test_opcache -m test_binary_subscr -m test_store_subscr -v

@KRRT7 KRRT7 force-pushed the list-int-compact-guard branch from 24dd20d to f1a230b Compare July 4, 2026 07:45
@KRRT7 KRRT7 changed the title gh-153002: Guard specialized list-int subscript indices gh-150587: Guard specialized list-int subscript indices Jul 4, 2026

@Fidget-Spinner Fidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for catching this bug, just one request.

Comment thread Python/bytecodes.c Outdated
@markshannon

Copy link
Copy Markdown
Member

This PR is marked as fixing #150587, but that issue is closed as not planned.

What is this fixing?

@KRRT7

KRRT7 commented Jul 6, 2026

Copy link
Copy Markdown
Author

@markshannon that is my own issue, the original issue was for a much bigger PR and I've since then, scoped it down, will update the body / title.

@KRRT7 KRRT7 requested a review from Fidget-Spinner July 7, 2026 20:33
@Fidget-Spinner

Copy link
Copy Markdown
Member

Wait upon closer inspection, the current code already deopts in the subscript op if it sees a negative index. I think there's no bug here? Correct me if I'm wrong.

Also GUARD_TOS_INT checks for a compact long already, then the subscript op itself checks for the range .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BINARY_OP_SUBSCR_LIST_INT / STORE_SUBSCR_LIST_INT silently depend on _GUARD_TOS_INT enforcing compactness

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.