Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

gh-131798: JIT: Further optimize_CALL_ISINSTANCE for class tuples#134543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tomasr8 wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromtomasr8:jit-tuple-isinstance

Conversation

tomasr8
Copy link
Member

@tomasr8tomasr8 commentedMay 22, 2025
edited by bedevere-appbot
Loading

We can already const evalisinstance(inst, cls) calls when both arguments are known, but only ifcls is a single class (e.g.int).
This PR adds support forisinstance(inst, (cls1, cls2, ..., clsN)). This allows us to optimize for example:

  • isinstance(42, (int, str)) (toTrue)
  • isinstance(42, (bool, str)) (toFalse)

We can narrow toTrue even when only some of the classes are known, as long asinst is an instance of one of the known classes.

@tomasr8tomasr8 changed the titlegh-134369: JIT: Further optimize_CALL_ISINSTANCE for class tuplesgh-131798: JIT: Further optimize_CALL_ISINSTANCE for class tuplesMay 22, 2025
Comment on lines +2124 to +2125
self.assertIn("_BUILD_TUPLE", uops)
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

_BUILD_TUPLE is preventing us from optimizing out_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW.
The bytecode is basically:

LOAD_CONSTLOAD_CONST_BUILD_TUPLE_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW

To optimize this, we'd need some special handling for_BUILD_TUPLE inremove_unneeded_uops.

@@ -938,6 +938,9 @@ dummy_func(void) {
}

op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) {
// The below define is equivalent to PyObject_TypeCheck(inst, cls)
#define sym_IS_SUBTYPE(inst, cls) ((inst) == (cls) || PyType_IsSubtype(inst, cls))
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm not sure about this define, maybe it's fine to duplicate this logic?

@tomasr8tomasr8 marked this pull request as ready for reviewMay 22, 2025 22:34
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-SpinnerFidget-Spinner is a code owner

@brandtbucherbrandtbucherAwaiting requested review from brandtbucher

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@tomasr8

[8]ページ先頭

©2009-2025 Movatter.jp