File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1437,6 +1437,38 @@ def crash_addition():
14371437
14381438 crash_addition ()
14391439
1440+ def test_narrow_type_to_constant_str_empty (self ):
1441+ def f (n ):
1442+ trace = []
1443+ for i in range (n ):
1444+ empty = ""
1445+ # Hopefully the optimizer can't guess what the value is.
1446+ # f is always "", but we can only prove that it's a string:
1447+ f = empty + empty
1448+ trace .append ("A" )
1449+ if not f : # Kept.
1450+ trace .append ("B" )
1451+ if not f : # Removed!
1452+ trace .append ("C" )
1453+ trace .append ("D" )
1454+ if f : # Removed!
1455+ trace .append ("X" )
1456+ trace .append ("E" )
1457+ trace .append ("F" )
1458+ if f : # Removed!
1459+ trace .append ("X" )
1460+ trace .append ("G" )
1461+ return trace
1462+
1463+ trace , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
1464+ self .assertEqual (trace , list ("ABCDEFG" ) * TIER2_THRESHOLD )
1465+ self .assertIsNotNone (ex )
1466+ uops = get_opnames (ex )
1467+ # Only one guard remains:
1468+ self .assertEqual (uops .count ("_GUARD_IS_FALSE_POP" ), 1 )
1469+ self .assertEqual (uops .count ("_GUARD_IS_TRUE_POP" ), 0 )
1470+ # But all of the appends we care about are still there:
1471+ self .assertEqual (uops .count ("_CALL_LIST_APPEND" ), len ("ABCDEFG" ))
14401472
14411473def global_identity (x ):
14421474 return x
You can’t perform that action at this time.
0 commit comments