diff options
author | Tomas R. <tomas.roun8@gmail.com> | 2025-05-19 13:19:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-19 13:19:24 -0400 |
commit | 8d490b368766ee7b28d2ccf47704b1d4b5f1ea23 (patch) | |
tree | 96b68a7059967e8555f84fd0e27ea5ae70581efe /Python/optimizer_cases.c.h | |
parent | 9859791f9e116c827468f307ac0770286c975c8b (diff) | |
download | cpython-8d490b368766ee7b28d2ccf47704b1d4b5f1ea23.tar.gz cpython-8d490b368766ee7b28d2ccf47704b1d4b5f1ea23.zip |
GH-131798: Narrow the return type of isinstance for some known arguments in the JIT (GH-133172)
Diffstat (limited to 'Python/optimizer_cases.c.h')
-rw-r--r-- | Python/optimizer_cases.c.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index deb912662e4..5d469765203 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -2124,8 +2124,22 @@ } case _CALL_ISINSTANCE: { + JitOptSymbol *cls; + JitOptSymbol *instance; JitOptSymbol *res; - res = sym_new_not_null(ctx); + cls = stack_pointer[-1]; + instance = stack_pointer[-2]; + res = sym_new_type(ctx, &PyBool_Type); + PyTypeObject *inst_type = sym_get_type(instance); + PyTypeObject *cls_o = (PyTypeObject *)sym_get_const(ctx, cls); + if (inst_type && cls_o && sym_matches_type(cls, &PyType_Type)) { + if (inst_type == cls_o || PyType_IsSubtype(inst_type, cls_o)) { + sym_set_const(res, Py_True); + } + else { + sym_set_const(res, Py_False); + } + } stack_pointer[-4] = res; stack_pointer += -3; assert(WITHIN_STACK_BOUNDS()); |