-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
GH-113710: Tier 2 optimizer: check the function instead of checking globals. #116410
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
GH-113710: Tier 2 optimizer: check the function instead of checking globals. #116410
Conversation
@markshannon, Is this correct? WhenI run a really simple test with debug output, I get a DEOPT message for Code: import _testinternalcapi
def cast(typ, val):
return val
def testfunc(n):
x = 0
for i in range(n):
x = cast(int, i)
return x
def main():
count = 20
a = testfunc(count)
assert a + 1 == count, (a, count)
old_opt = _testinternalcapi.get_optimizer()
opt = _testinternalcapi.new_uop_optimizer()
_testinternalcapi.set_optimizer(opt)
a = testfunc(count)
_testinternalcapi.set_optimizer(old_opt)
assert a + 1 == count, (a, count)
main() Before:
After:
That's the |
Yep, the bug is that this PR doesn't update the operand, just the opcode. So it's incorrectly comparing the function to the builtin or globals dicts. |
Since the globals and builtin fields of function objects are immutable, we can check the function instead of the globals and builtins.
This is:
_INIT_CALL_PY_EXACT_ARGS
implicitly checks the function, so no additional checks are needed._CHECK_GLOBALS
+_CHECK_BUILTINS
with_CHECK_FUNCTION
.