Skip to content

[mypyc] Optimize int()/float()/complex() on native classes#14450

Merged
JukkaL merged 5 commits intopython:masterfrom
ichard26:optimize-native-class-conversion-to-int-and-float
Jan 18, 2023
Merged

[mypyc] Optimize int()/float()/complex() on native classes#14450
JukkaL merged 5 commits intopython:masterfrom
ichard26:optimize-native-class-conversion-to-int-and-float

Conversation

@ichard26
Copy link
Copy Markdown
Collaborator

int() and float() calls on native classes can simply call the associated dunder if the RInstance defines it, no need to load the type and call it.

bool() calls were already optimized merely a few days ago, but there wasn't an IRbuild test verifying this so I added one.


Follow up to #14422. I saw the PR and it reminded me that I had this old patch laying around :)

int() and float() calls on native classes can simply call the associated
dunder if the RInstance defines it, no need to load the type and call it.

bool() calls were already optimized merely a few days ago, but there
wasn't an IRbuild test verifying this so I added one.
@ichard26 ichard26 force-pushed the optimize-native-class-conversion-to-int-and-float branch from 36a4d78 to c094384 Compare January 15, 2023 01:18
Comment thread mypyc/irbuild/specialize.py
@ichard26
Copy link
Copy Markdown
Collaborator Author

Hmm, I just discovered the __complex__ dunder. I'll see if I can optimize it too.

Copy link
Copy Markdown
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good. I'll keep this open for a while in case you will add support for __complex__.

Comment thread mypyc/irbuild/specialize.py
@github-actions

This comment has been minimized.

Comment thread mypyc/test-data/irbuild-dunders.test Outdated
@ichard26 ichard26 changed the title [mypyc] Optimize int()/float() on native classes [mypyc] Optimize int()/float()/complex() on native classes Jan 17, 2023
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JukkaL JukkaL merged commit acf26f4 into python:master Jan 18, 2023
@ichard26 ichard26 deleted the optimize-native-class-conversion-to-int-and-float branch January 18, 2023 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants