Skip to content

gh-153486: Preserve negative indices in compact int subscript specializations#153523

Draft
KRRT7 wants to merge 8 commits into
python:mainfrom
KRRT7:compact-index-guard-followups-clean
Draft

gh-153486: Preserve negative indices in compact int subscript specializations#153523
KRRT7 wants to merge 8 commits into
python:mainfrom
KRRT7:compact-index-guard-followups-clean

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 10, 2026

Copy link
Copy Markdown

This follows up on gh-153486.

The base compact-int guard work tightened several specialized subscript paths to only stay specialized for non-negative compact integer indices. That kept the guards simple, but it also meant negative compact indices deoptimized even in cases where the specialized path could handle them correctly.

This PR restores negative-index handling in the specialized paths where it is valid and straightforward:

  • BINARY_OP_SUBSCR_LIST_INT
  • BINARY_OP_SUBSCR_TUPLE_INT
  • BINARY_OP_SUBSCR_STR_INT
  • BINARY_OP_SUBSCR_USTR_INT
  • STORE_SUBSCR_LIST_INT

It does this by:

  • keeping the specialization guards aligned with exact compact int indices
  • normalizing negative indices inside the specialized path
  • deopting only when the normalized index is still out of bounds

Tests are included to cover the negative-index specialized cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant