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-127809: Fix the JIT's understanding of**#127844

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

Merged
brandtbucher merged 8 commits intopython:mainfrombrandtbucher:binary-op-pow
Jan 8, 2025

Conversation

@brandtbucher
Copy link
Member

@brandtbucherbrandtbucher commentedDec 11, 2024
edited by bedevere-appbot
Loading

It's more complex (ha) than we originally thought.

I think it'sprobably worth trying to do the "smart" thing here, since exponents with at least one constant part are reasonably common. But if others think the additional logic in the optimizer is too much, we can just say that the result of** an**= is unknown (even when it may technically be knowable):

if (oparg==NB_POWER||oparg==NB_INPLACE_POWER) {res=sym_new_unknown(ctx);        }elseif (oparg==NB_TRUE_DIVIDE||oparg==NB_INPLACE_TRUE_DIVIDE) {res=sym_new_type(ctx,&PyFloat_Type);        }elseif (sym_matches_type(left,&PyLong_Type)&&sym_matches_type(left,&PyLong_Type)) {res=sym_new_type(ctx,&PyLong_Type);        }else {res=sym_new_type(ctx,&PyFloat_Type);        }

The runtime cost would be an additional guard in JIT code following a** or**=.

@brandtbucherbrandtbucher added interpreter-core(Objects, Python, Grammar, and Parser dirs) type-crashA hard crash of the interpreter, possibly with a core dump topic-JIT labelsDec 11, 2024
@brandtbucherbrandtbucher self-assigned thisDec 11, 2024
gotobinary_op_done;
}
if (oparg==NB_POWER||oparg==NB_INPLACE_POWER) {
// This one's fun: the *type* of the result depends on the *values*
Copy link
Member

@markshannonmarkshannonDec 12, 2024
edited
Loading

Choose a reason for hiding this comment

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

I'm not convinced that this is worth the complexity for anything other than integer constant right hand sides.
It the rhs is an int constant, then the result is the type of the lhs (for ints and floats) otherwise, "not known".
Calculating any other result is so slow that the cost of the guard we could potentially remove is negligible.

brandtbucher reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't a negative int rhs produce a float?

>>> 3 ** -10.3333333333333333

Your point may still stand that it's too expensive, but unfortunately the assumption that if rhs is an int we can determine the result without looking at the value doesn't hold.

brandtbucher reacted with thumbs up emoji
@brandtbucher
Copy link
MemberAuthor

Alright, I added some more comments and made it quite a bit simpler (only covering the "easy" cases). Let me know if it looks good now.

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

Looks correct.
Still quite complex, but a lot more reasonable than the original version.

Let's see if the ASAN failure was just a glitch.

@brandtbucherbrandtbucher merged commit65ae3d5 intopython:mainJan 8, 2025
69 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mdboommdboommdboom left review comments

@markshannonmarkshannonmarkshannon approved these changes

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

Assignees

@brandtbucherbrandtbucher

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-crashA hard crash of the interpreter, possibly with a core dump

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@brandtbucher@mdboom@markshannon@Fidget-Spinner

[8]ページ先頭

©2009-2025 Movatter.jp