GH-131798: Narrow the return type of isinstance for some known arguments in the JIT (GH-133172)

This commit is contained in:
Tomas R. 2025-05-19 13:19:24 -04:00 committed by GitHub
parent 9859791f9e
commit 8d490b3687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 152 additions and 1 deletions

View file

@ -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());