Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Oct 1, 2024
1 parent 9d38c21 commit 53f2396
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,30 @@ def fn(a):

fn(A())

def test_func_guards_removed_or_reduced(self):
def testfunc(n):
for i in range(n):
# Only works on functions promoted to constants
global_identity(i)

opt = _testinternalcapi.new_uop_optimizer()
with temporary_optimizer(opt):
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_PUSH_FRAME", uops)
# Strength reduced version
self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops)
self.assertNotIn("_CHECK_FUNCTION_VERSION", uops)
# Removed guard
self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops)


def global_identity(x):
return x


if __name__ == "__main__":
unittest.main()

0 comments on commit 53f2396

Please sign in to comment.