File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -2501,6 +2501,55 @@ def testfunc(n):
25012501 # For now... until we constant propagate it away.
25022502 self .assertIn ("_BINARY_OP" , uops )
25032503
2504+ def test_strip_reference_information_through_str (self ):
2505+ # This test needs to be in another script due to Python's
2506+ # string interning details.
2507+ script_helper .assert_python_ok ('-c' , textwrap .dedent ("""
2508+ import _testinternalcapi
2509+ import _opcode
2510+
2511+ def get_first_executor(func):
2512+ code = func.__code__
2513+ co_code = code.co_code
2514+ for i in range(0, len(co_code), 2):
2515+ try:
2516+ return _opcode.get_executor(code, i)
2517+ except ValueError:
2518+ pass
2519+ return None
2520+
2521+ def iter_opnames(ex):
2522+ for item in ex:
2523+ yield item[0]
2524+
2525+ def get_opnames(ex):
2526+ return list(iter_opnames(ex))
2527+
2528+ def testfunc(n):
2529+ for _ in range(n):
2530+ str("abcde")
2531+
2532+
2533+ testfunc(_testinternalcapi.TIER2_THRESHOLD)
2534+ ex = get_first_executor(testfunc)
2535+ assert ex is not None
2536+ uops = get_opnames(ex)
2537+ assert "_POP_TOP_NOP" not in uops
2538+ """ ))
2539+
2540+ def test_strip_reference_information_through_tuple (self ):
2541+ def testfunc (n ):
2542+ for _ in range (n ):
2543+ tuple ((1 ,))
2544+
2545+ testfunc (TIER2_THRESHOLD * 2 )
2546+
2547+ ex = get_first_executor (testfunc )
2548+ self .assertIsNotNone (ex )
2549+ uops = get_opnames (ex )
2550+
2551+ self .assertNotIn ("_POP_TOP_NOP" , uops )
2552+
25042553
25052554def global_identity (x ):
25062555 return x
You can’t perform that action at this time.
0 commit comments