self.assertNotIn("_GUARD_NOS_TUPLE", uops)
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
+ def test_remove_guard_for_known_type_slice(self):
+ def f(n):
+ x = 0
+ for _ in range(n):
+ l = [1, 2, 3]
+ slice_obj = slice(0, 1)
+ x += l[slice_obj][0] # guarded
+ x += l[slice_obj][0] # unguarded
+ return x
+ res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
+ self.assertEqual(res, TIER2_THRESHOLD * 2)
+ uops = get_opnames(ex)
+
+ count = count_ops(ex, "_GUARD_TOS_SLICE")
+ self.assertEqual(count, 1)
+ self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
+
def test_remove_guard_for_tuple_bounds_check(self):
def f(n):
x = 0
}
}
+ op(_GUARD_TOS_SLICE, (tos -- tos)) {
+ if (sym_matches_type(tos, &PySlice_Type)) {
+ ADD_OP(_NOP, 0, 0);
+ }
+ sym_set_type(tos, &PySlice_Type);
+ }
+
op(_GUARD_NOS_NULL, (null, unused -- null, unused)) {
if (sym_is_null(null)) {
ADD_OP(_NOP, 0, 0);
}
case _GUARD_TOS_SLICE: {
+ JitOptRef tos;
+ tos = stack_pointer[-1];
+ if (sym_matches_type(tos, &PySlice_Type)) {
+ ADD_OP(_NOP, 0, 0);
+ }
+ sym_set_type(tos, &PySlice_Type);
break;
}