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-132732: Treatbytes as constants in_Py_uop_sym_is_safe_const#136033

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

Closed
sobolevn wants to merge2 commits intopython:mainfromsobolevn:issue-132732

Conversation

sobolevn
Copy link
Member

@sobolevnsobolevn commentedJun 27, 2025
edited
Loading

b'a'+b'b'# is a constant evaluation

@brandtbucher
Copy link
Member

One thing that slightly worries me about this is that comparingstr/int andbytes objects raisesUnicodeWarning if the-b option was passed on the command line. With this change, additional checks are required if we want to makeCOMPARE_OP able to constant-evaluate in the optimizer.

@Fidget-Spinner
Copy link
Member

One thing that slightly worries me about this is that comparingstr/int andbytes objects raisesUnicodeWarning if the-b option was passed on the command line. With this change, additional checks are required if we want to makeCOMPARE_OP able to constant-evaluate in the optimizer.

Ok let's not do this then. We still need to fix the long stuff though so@sobolevn are you open to that or do you want me to handle it?

@Fidget-Spinner
Copy link
Member

I opened PR#136040 to fix the compact ints issue.

@sobolevn
Copy link
MemberAuthor

With this change, additional checks are required if we want to make COMPARE_OP able to constant-evaluate in the optimizer.

Did you mean checking for_Py_GetConfig()->bytes_warning conditionally? I fear that this might be really slow :(

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commentedJun 27, 2025
edited
Loading

With this change, additional checks are required if we want to make COMPARE_OP able to constant-evaluate in the optimizer.

Did you mean checking for_Py_GetConfig()->bytes_warning conditionally? I fear that this might be really slow :(

You can fetch the value once at the start of optimization time inoptimizer_analysis.c, and store it somewhere.

@brandtbucher
Copy link
Member

Or, simpler, just explicitly disallow optimizing the problematic comparisons.

sobolevn reacted with thumbs up emoji

@brandtbucher
Copy link
Member

If one of the values is of type bytes, require the other to be as well.

@Fidget-Spinner
Copy link
Member

Or, simpler, just explicitly disallow optimizing the problematic comparisons.

Not just comparisons. BINARY_OP as well. This is a little annoying and more involved than I expected, so I'd say let's just ignore it for now?

@brandtbucher
Copy link
Member

brandtbucher commentedJun 27, 2025
edited
Loading

WhatBINARY_OP will raiseBytesWarning?

@Fidget-Spinner
Copy link
Member

WhatBINARY_OP will raiseBytesWarning?

Not BytesWarning. BINARY_OP (str, bytes) will throw.

@brandtbucher
Copy link
Member

That’s the case for many combinations of safe types. We should suppress the error and hit bottom in that case (in theerror label).

Fidget-Spinner reacted with thumbs up emoji

@brandtbucher
Copy link
Member

Same for42 / 0, etc. In general, errors in the optimizer should just be suppressed.

@brandtbucher
Copy link
Member

This is just different because it’s a warning, to clarify.

@Fidget-Spinner
Copy link
Member

That’s the case for many combinations of safe types. We should suppress the error and hit bottom in that case (in theerror label).

Yeah the optimizer currently doesn't do that. Opened a PR to do so#136048

@sobolevn
Copy link
MemberAuthor

I openedhttps://discuss.python.org/t/consider-deprecating-and-eventually-removing-b-cli-flag/96903 about possibly removing this warning in the future versions. It does not seem very useful :(

efimov-mikhail reacted with thumbs up emoji

@sobolevn
Copy link
MemberAuthor

sobolevn commentedJun 27, 2025
edited
Loading

I fixed the merge conflict. Sorry, I am rather new to the JIT internals, and I don't quite understand theCOMPARE_OP part._Py_uop_sym_is_safe_const is never called forCOMPARE_OP. So, I don't know how to interpret these comments :)

With this change, additional checks are required if we want to make COMPARE_OP able to constant-evaluate in the optimizer.

Or, simpler, just explicitly disallow optimizing the problematic comparisons.

Is there anything I need to do in this PR to address them?

@Fidget-Spinner
Copy link
Member

I fixed the merge conflict. Sorry, I am rather new to the JIT internals, and I don't quite understand theCOMPARE_OP part._Py_uop_sym_is_safe_const is never called forCOMPARE_OP. So, I don't know how to interpret these comments :)

We plan to follow up shortly with COMPARE_OP here#130415

@sobolevn
Copy link
MemberAuthor

Ok then :)
Let's close it for now.

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

@Fidget-SpinnerFidget-SpinnerFidget-Spinner left review comments

@tomasr8tomasr8tomasr8 approved these changes

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

4 participants
@sobolevn@brandtbucher@Fidget-Spinner@tomasr8

[8]ページ先頭

©2009-2025 Movatter.jp