gh-131798: fold super method lookups in JIT (#148231)

This commit is contained in:
Kumar Aditya 2026-04-09 13:25:01 +05:30 committed by GitHub
parent ee5232782f
commit 458aca9237
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1762 additions and 1278 deletions

View file

@ -943,6 +943,34 @@ dummy_func(void) {
self = owner;
}
op(_GUARD_LOAD_SUPER_ATTR_METHOD, (global_super_st, class_st, unused -- global_super_st, class_st, unused)) {
if (sym_get_const(ctx, global_super_st) == (PyObject *)&PySuper_Type) {
PyTypeObject *probable = (PyTypeObject *)sym_get_probable_value(class_st);
PyTypeObject *known = (PyTypeObject *)sym_get_const(ctx, class_st);
// not known, but has a probable type, promote the probable type
if (known == NULL && probable != NULL && PyType_Check(probable)) {
ADD_OP(_GUARD_NOS_TYPE_VERSION, 0, probable->tp_version_tag);
known = probable;
}
sym_set_const(class_st, (PyObject *)known);
}
else {
sym_set_const(global_super_st, (PyObject *)&PySuper_Type);
sym_set_type(class_st, &PyType_Type);
}
}
op(_LOAD_SUPER_ATTR_METHOD, (global_super_st, class_st, self_st -- attr, self_or_null)) {
self_or_null = self_st;
PyTypeObject *su_type = (PyTypeObject *)sym_get_const(ctx, class_st);
PyTypeObject *obj_type = sym_get_type(self_st);
PyObject *name = get_co_name(ctx, oparg >> 2);
attr = lookup_super_attr(ctx, dependencies, this_instr,
su_type, obj_type, name,
_INSERT_1_LOAD_CONST_INLINE_BORROW,
_INSERT_1_LOAD_CONST_INLINE);
}
op(_LOAD_ATTR_PROPERTY_FRAME, (fget/4, owner -- new_frame)) {
// + 1 for _SAVE_RETURN_OFFSET
// FIX ME -- This needs a version check and function watcher