Skip to content

gh-131798: Optimize _UNARY_NEGATIVE #135223

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

noamcohen97
Copy link
Contributor

@noamcohen97 noamcohen97 commented Jun 6, 2025

@@ -467,6 +467,15 @@ dummy_func(void) {
res = sym_new_truthiness(ctx, value, false);
}

op(_UNARY_NEGATIVE, (value -- res)) {
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyFloat_Type)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can add a check for const, and we can setup the res by using sym_new_const. Not sure this is worth here cc @brandtbucher @Fidget-Spinner

Copy link
Member

Choose a reason for hiding this comment

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

I'd hold off on that, since our plan is to automatically constant-evaluate stuff like this. Let's stick with hand-writing type-based optimizations like this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not add a const clause for this since it felt more related to #132733.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Looks good, just some suggested improvements. Thanks!

@@ -467,6 +467,15 @@ dummy_func(void) {
res = sym_new_truthiness(ctx, value, false);
}

op(_UNARY_NEGATIVE, (value -- res)) {
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyFloat_Type)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd hold off on that, since our plan is to automatically constant-evaluate stuff like this. Let's stick with hand-writing type-based optimizations like this for now.

@noamcohen97
Copy link
Contributor Author

Thanks for the review! @brandtbucher @Zheaoli

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Awesome! Can you just fix the merge conflict in the test file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy