GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-131798: JIT: Assign type to sliced string/list/tuple by fluhus · Pull Request #134671 · python/cpython

Conversation

@fluhus

@fluhus 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

  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
fluhus added 4 commits May 25, 2025 11:25
@fluhus
JIT: Assign type to sliced string
61207d2
@fluhus
Revert accidental whitespace change
e281791
@fluhus
JIT: Remove guard for slicing known type list
e45c280
@fluhus
JIT: Remove guard for slicing known type tuple
4eade4a
@fluhus
fluhus requested a review from Fidget-Spinner as a code owner May 25, 2025 19:29
@bedevere-app bedevere-app Bot added the awaiting review label May 25, 2025
@bedevere-app bedevere-app Bot mentioned this pull request May 25, 2025
Better uop coverage in the JIT optimizer #131798
Open
@blurb-it
📜🤖 Added by blurb_it.
a2bba45
eendebakpt
eendebakpt reviewed May 25, 2025
View reviewed changes
Comment thread Python/optimizer_bytecodes.c
// Slicing a string/list/tuple always returns the same type.
PyTypeObject *type = sym_get_type(container);
if (type == &PyUnicode_Type ||
type == &PyList_Type ||

@eendebakpt eendebakpt May 25, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brandtbucher brandtbucher Jun 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@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)!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
brandtbucher
brandtbucher approved these changes Jun 5, 2025
View reviewed changes

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great, just one style nitpick:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_capi/test_opt.py
for i in range(n):
false = i == TIER2_THRESHOLD
empty = "X"[:false]
empty += "" # Make JIT realize this is a string.

@brandtbucher brandtbucher Jun 1, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nice!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

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

@brandtbucher brandtbucher Jun 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@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)!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jun 5, 2025
brandtbucher
brandtbucher reviewed Jun 6, 2025
View reviewed changes
Comment thread Python/optimizer_cases.c.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
PEP 7
2bb095b
@brandtbucher
brandtbucher merged commit 8fdbbf8 into python:main Jun 7, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 7, 2025
@fluhus
fluhus deleted the amit branch June 17, 2025 17:38
lkollar pushed a commit to lkollar/cpython that referenced this pull request Jun 19, 2025
@fluhus @lkollar
pythonGH-131798: Type-propagate string/list/tuple slices (pythonGH-13…
a3b80c0
…4671)
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@fluhus @Pranjal095
pythonGH-131798: Type-propagate string/list/tuple slices (pythonGH-13…
8ebc5f6
…4671)
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@fluhus @taegyunkim
pythonGH-131798: Type-propagate string/list/tuple slices (pythonGH-13…
73b6b1d
…4671)
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@fluhus @Agent-Hellboy
pythonGH-131798: Type-propagate string/list/tuple slices (pythonGH-13…
1b5e5ca
…4671)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eendebakpt eendebakpt eendebakpt left review comments
@brandtbucher brandtbucher brandtbucher approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@fluhus @eendebakpt @brandtbucher
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.