Skip to content

Commit 53f2396

Browse files
Add test
1 parent 9d38c21 commit 53f2396

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,30 @@ def fn(a):
14811481

14821482
fn(A())
14831483

1484+
def test_func_guards_removed_or_reduced(self):
1485+
def testfunc(n):
1486+
for i in range(n):
1487+
# Only works on functions promoted to constants
1488+
global_identity(i)
1489+
1490+
opt = _testinternalcapi.new_uop_optimizer()
1491+
with temporary_optimizer(opt):
1492+
testfunc(20)
1493+
1494+
ex = get_first_executor(testfunc)
1495+
self.assertIsNotNone(ex)
1496+
uops = get_opnames(ex)
1497+
self.assertIn("_PUSH_FRAME", uops)
1498+
# Strength reduced version
1499+
self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops)
1500+
self.assertNotIn("_CHECK_FUNCTION_VERSION", uops)
1501+
# Removed guard
1502+
self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops)
1503+
1504+
1505+
def global_identity(x):
1506+
return x
1507+
14841508

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

0 commit comments

Comments
 (0)