python / python/cpython

Specialized subscript guards should require non-negative compact ints

Open
#153,486 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core performance type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

The specialized int subscript fast paths currently assume a non-negative compact int, but that precondition is not expressed directly in the guard.

Make the guard explicit for the affected cases:

  • list[i]
  • tuple[i]
  • str[i]
  • list[i] = value

This aligns the guard with the existing specialization contract and removes redundant checks from the specialized bodies, without changing the fallback path for negative indices.

Linked PRs
  • gh-153487
  • gh-153523

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the specialized int subscript fast paths for list[i], tuple[i], str[i], and list[i] = value. Check how their guards express the compact-int precondition and how negative indices reach the fallback path. Done means the guards require non-negative compact ints, redundant specialized-body checks are removed, and negative-index behavior is unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.