Skip to content

GH-130415: Use boolean guards to narrow types to values in the JIT#130659

Merged
brandtbucher merged 13 commits intopython:mainfrom
brandtbucher:jit-narrow-to-bool-bool
Mar 2, 2025
Merged

GH-130415: Use boolean guards to narrow types to values in the JIT#130659
brandtbucher merged 13 commits intopython:mainfrom
brandtbucher:jit-narrow-to-bool-bool

Conversation

@brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Feb 28, 2025

This adds a symbolic "truth" type to the JIT optimizer, allowing tests like if not x: ... to narrow the value of x based on its type. Currently, it's only implemented for booleans, but I'm working with a few people to open PRs to narrow int and str values as well.

(The diff looks much worse than it is, since this requires adding ctx parameters to a couple of helper functions that are used everywhere. The "real" changes in optimizer_bytecodes.c are limited to _GUARD_IS_FALSE_POP, _GUARD_IS_NONE_POP, _GUARD_IS_TRUE_POP, _TO_BOOL, _TO_BOOL_BOOL, and _UNARY_NOT.

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 topic-JIT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants