Skip to content

Commit b1702f2

Browse files
committed
address code review. remove commented code. better names.
1 parent a1139cf commit b1702f2

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,19 +1441,19 @@ def test_narrow_type_to_constant_int_zero(self):
14411441
def f(n):
14421442
trace = []
14431443
for i in range(n):
1444-
# f is always (int) 0, but we can only prove that it's a integer:
1445-
f = i - i # at this point python knows f is an int, but doesnt know that it is 0 (we know it is 0 though)
1444+
# zero is always (int) 0, but we can only prove that it's a integer:
1445+
zero = i - i # at this point python knows f is an int, but doesnt know that it is 0 (we know it is 0 though)
14461446
trace.append("A")
1447-
if not f: # Kept.
1447+
if not zero: # Kept.
14481448
trace.append("B")
1449-
if not f: # Removed!
1449+
if not zero: # Removed!
14501450
trace.append("C")
14511451
trace.append("D")
1452-
if f: # Removed!
1452+
if zero: # Removed!
14531453
trace.append("X")
14541454
trace.append("E")
14551455
trace.append("F")
1456-
if f: # Removed!
1456+
if zero: # Removed!
14571457
trace.append("X")
14581458
trace.append("G")
14591459
return trace
@@ -1468,36 +1468,6 @@ def f(n):
14681468
# But all of the appends we care about are still there:
14691469
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
14701470

1471-
# def test_narrow_type_to_constant_bool_true(self):
1472-
# def f(n):
1473-
# trace = []
1474-
# for i in range(n):
1475-
# # f is always True, but we can only prove that it's a bool:
1476-
# f = i != TIER2_THRESHOLD
1477-
# trace.append("A")
1478-
# if f: # Kept.
1479-
# trace.append("B")
1480-
# if not f: # Removed!
1481-
# trace.append("X")
1482-
# trace.append("C")
1483-
# if f: # Removed!
1484-
# trace.append("D")
1485-
# trace.append("E")
1486-
# trace.append("F")
1487-
# if not f: # Removed!
1488-
# trace.append("X")
1489-
# trace.append("G")
1490-
# return trace
1491-
1492-
# trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
1493-
# self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD)
1494-
# self.assertIsNotNone(ex)
1495-
# uops = get_opnames(ex)
1496-
# # Only one guard remains:
1497-
# self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 0)
1498-
# self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 1)
1499-
# # But all of the appends we care about are still there:
1500-
# self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
15011471

15021472
def global_identity(x):
15031473
return x

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,8 @@ dummy_func(void) {
417417
// removed and the narrowed value to be invalid:
418418
if (next_opcode == _GUARD_IS_FALSE_POP) {
419419
sym_set_const(value, Py_GetConstant(Py_CONSTANT_ZERO));
420-
res = sym_new_type(ctx, &PyLong_Type);
420+
res = sym_new_type(ctx, &PyBool_Type);
421421
}
422-
// else if (next_opcode == _GUARD_IS_TRUE_POP) {
423-
// sym_set_const(value, Py_True);
424-
// res = sym_new_type(ctx, &PyBool_Type);
425-
// }
426422
}
427423
}
428424

0 commit comments

Comments
 (0)