Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "constant fold on classes as well"
This reverts commit ac515b8.
  • Loading branch information
kumaraditya303 committed Apr 12, 2026
commit 55bf43a569bd99e52343d4fdb4780ef569bb5d2a
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3196,12 +3196,10 @@ def f(n):
x += e.m() # _LOAD_ATTR_METHOD_LAZY_DICT
x += f.class_method() # _LOAD_ATTR
x += f.static_method() # _LOAD_ATTR
x += F.class_method() # _LOAD_ATTR
x += F.static_method() # _LOAD_ATTR
return x

res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
self.assertEqual(res, 10 * TIER2_THRESHOLD)
self.assertEqual(res, 8 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertNotIn("_LOAD_ATTR", uops)
Expand Down
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ dummy_func(

macro(LOAD_ATTR) =
_SPECIALIZE_LOAD_ATTR +
_RECORD_TOS +
_RECORD_TOS_TYPE +
unused/8 +
_LOAD_ATTR;

Expand Down
26 changes: 5 additions & 21 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,7 @@ dummy_func(void) {
}

op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
PyObject *value = sym_get_probable_value(owner);
PyTypeObject *type = NULL;
if (value != NULL && PyType_Check(value)) {
type = (PyTypeObject *)value;
}
else {
type = sym_get_probable_type(owner);
}

PyTypeObject *type = sym_get_probable_type(owner);
if (oparg & 1 && type != NULL) {
PyObject *name = get_co_name(ctx, oparg >> 1);
PyObject *descr = _PyType_Lookup(type, name);
Expand All @@ -898,32 +890,24 @@ dummy_func(void) {
}
assert(callable);
bool immortal = _Py_IsImmortal(callable) || (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE);
if (PyType_Check(value)) {
ADD_OP(_CHECK_ATTR_CLASS, 0, type->tp_version_tag);
}
else {
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
}
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
ADD_OP(_POP_TOP, 0, 0);
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE, 0, (uintptr_t)callable);
if (class_method) {
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)type);
self_or_null[0] = sym_new_const(ctx, (PyObject *)type);
}
else {
} else if (static_method) {
ADD_OP(_PUSH_NULL, 0, 0);
self_or_null[0] = sym_new_null(ctx);
}
attr = sym_new_const(ctx, callable);
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
_Py_BloomFilter_Add(dependencies, (PyTypeObject *)type);
}
else {
} else {
attr = sym_new_not_null(ctx);
self_or_null[0] = sym_new_unknown(ctx);
}
}
else {
} else {
attr = sym_new_not_null(ctx);
}
}
Expand Down
25 changes: 5 additions & 20 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions Python/record_functions.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading