Skip to content

GH-106008: Make implicit boolean conversions explicit#106003

Merged
brandtbucher merged 18 commits intopython:mainfrom
brandtbucher:to-bool
Jun 29, 2023
Merged

GH-106008: Make implicit boolean conversions explicit#106003
brandtbucher merged 18 commits intopython:mainfrom
brandtbucher:to-bool

Conversation

@brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Jun 23, 2023

...and specialize them!

This adds a new TO_BOOL bytecode that prefixes all UNARY_NOT, POP_JUMP_IF_TRUE, and POP_JUMP_IF_FALSE instructions, which now require an exact boolean. We also use a spare bit in COMPARE_OP's oparg to indicate whether the result should be converted to bool (this saves a TO_BOOL for most branches, and is a no-op for all COMPARE_OP specializations).

"0% faster". Stats show a 93.5% hit rate for the new instructions.


📚 Documentation preview 📚: https://cpython-previews--106003.org.readthedocs.build/

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

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants