Skip to content

Commit 4edba18

Browse files
committed
Add tests for truthiness symbol
1 parent 07697ed commit 4edba18

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Python/optimizer_symbols.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ _Py_uop_sym_is_immortal(JitOptSymbol *sym)
574574
if (sym->tag == JIT_SYM_KNOWN_CLASS_TAG) {
575575
return sym->cls.type == &PyBool_Type;
576576
}
577+
if (sym->tag == JIT_SYM_TRUTHINESS_TAG) {
578+
return true;
579+
}
577580
return false;
578581
}
579582

@@ -830,7 +833,21 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
830833
_Py_uop_sym_get_const(ctx, _Py_uop_sym_tuple_getitem(ctx, sym, 1)) == val_43,
831834
"tuple item does not match value used to create tuple"
832835
);
833-
836+
JitOptSymbol *value = _Py_uop_sym_new_type(ctx, &PyBool_Type);
837+
sym = _Py_uop_sym_new_truthiness(ctx, value, false);
838+
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyBool_Type), "truthiness is not boolean");
839+
TEST_PREDICATE(_Py_uop_sym_truthiness(ctx, sym) == -1, "truthiness is not unknown");
840+
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, sym) == false, "truthiness is constant");
841+
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, sym) == NULL, "truthiness is not NULL");
842+
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, value) == false, "value is constant");
843+
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, value) == NULL, "value is not NULL");
844+
_Py_uop_sym_set_const(ctx, sym, Py_False);
845+
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyBool_Type), "truthiness is not boolean");
846+
TEST_PREDICATE(_Py_uop_sym_truthiness(ctx, sym) == 0, "truthiness is not True");
847+
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, sym) == true, "truthiness is not constant");
848+
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, sym) == Py_False, "truthiness is not False");
849+
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, value) == true, "value is not constant");
850+
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, value) == Py_True, "value is not True");
834851
_Py_uop_abstractcontext_fini(ctx);
835852
Py_DECREF(val_42);
836853
Py_DECREF(val_43);

0 commit comments

Comments
 (0)