FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131798: JIT: Assign type to sliced string/list/tuple by fluhus · Pull Request #134671 · python/cpython · GitHub

Repository navigation

gh-131798: JIT: Assign type to sliced string/list/tuple - #134671

Merged
brandtbucher merged 6 commits into
python:mainfrom
fluhus:amit
Jun 7, 2025
Merged

brandtbucher merged 6 commits into
python:mainfrom
fluhus:amit

Conversation

fluhus commented May 25, 2025

Copy link
Copy Markdown
Contributor

Slicing a string/list/tuple always returns the same type.
Make the optimizer assign a string/list/tuple type to the result of slicing a string/list/tuple.

@brandtbucher

// Slicing a string/list/tuple always returns the same type.
PyTypeObject *type = sym_get_type(container);
if (type == &PyUnicode_Type ||
type == &PyList_Type ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
type == &PyList_Type ||
type == &PyBytes_Type ||
type == &PyList_Type ||

I do not know whether slicing a bytes object occurs often enough to add PyBytes_Type here (and whether the jit slows down if we add more cases here), but if I understand correctly slicing bytes (or bytearray) results in a bytes (or bytearray) so we could add them.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@fluhus, this PR is probably fine for now, but feel free to add other sequence types like this in a follow-up PR (with tests)!

brandtbucher 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks great, just one style nitpick:

for i in range(n):
false = i == TIER2_THRESHOLD
empty = "X"[:false]
empty += "" # Make JIT realize this is a string.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice!

Comment thread Python/optimizer_bytecodes.c Outdated
// Slicing a string/list/tuple always returns the same type.
PyTypeObject *type = sym_get_type(container);
if (type == &PyUnicode_Type ||
type == &PyList_Type ||

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@fluhus, this PR is probably fine for now, but feel free to add other sequence types like this in a follow-up PR (with tests)!

Comment thread Python/optimizer_cases.c.h Outdated
brandtbucher merged commit 8fdbbf8 into python:main Jun 7, 2025
fluhus deleted the amit branch June 17, 2025 17:38
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL