Skip to content

Commit 55bf43a

Browse files
Revert "constant fold on classes as well"
This reverts commit ac515b8.
1 parent ac515b8 commit 55bf43a

File tree

6 files changed

+19
-54
lines changed

6 files changed

+19
-54
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,12 +3196,10 @@ def f(n):
31963196
x += e.m() # _LOAD_ATTR_METHOD_LAZY_DICT
31973197
x += f.class_method() # _LOAD_ATTR
31983198
x += f.static_method() # _LOAD_ATTR
3199-
x += F.class_method() # _LOAD_ATTR
3200-
x += F.static_method() # _LOAD_ATTR
32013199
return x
32023200

32033201
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
3204-
self.assertEqual(res, 10 * TIER2_THRESHOLD)
3202+
self.assertEqual(res, 8 * TIER2_THRESHOLD)
32053203
self.assertIsNotNone(ex)
32063204
uops = get_opnames(ex)
32073205
self.assertNotIn("_LOAD_ATTR", uops)

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,7 @@ dummy_func(
27282728

27292729
macro(LOAD_ATTR) =
27302730
_SPECIALIZE_LOAD_ATTR +
2731-
_RECORD_TOS +
2731+
_RECORD_TOS_TYPE +
27322732
unused/8 +
27332733
_LOAD_ATTR;
27342734

Python/optimizer_bytecodes.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,7 @@ dummy_func(void) {
873873
}
874874

875875
op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
876-
PyObject *value = sym_get_probable_value(owner);
877-
PyTypeObject *type = NULL;
878-
if (value != NULL && PyType_Check(value)) {
879-
type = (PyTypeObject *)value;
880-
}
881-
else {
882-
type = sym_get_probable_type(owner);
883-
}
884-
876+
PyTypeObject *type = sym_get_probable_type(owner);
885877
if (oparg & 1 && type != NULL) {
886878
PyObject *name = get_co_name(ctx, oparg >> 1);
887879
PyObject *descr = _PyType_Lookup(type, name);
@@ -898,32 +890,24 @@ dummy_func(void) {
898890
}
899891
assert(callable);
900892
bool immortal = _Py_IsImmortal(callable) || (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE);
901-
if (PyType_Check(value)) {
902-
ADD_OP(_CHECK_ATTR_CLASS, 0, type->tp_version_tag);
903-
}
904-
else {
905-
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
906-
}
893+
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
907894
ADD_OP(_POP_TOP, 0, 0);
908895
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE, 0, (uintptr_t)callable);
909896
if (class_method) {
910897
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)type);
911898
self_or_null[0] = sym_new_const(ctx, (PyObject *)type);
912-
}
913-
else {
899+
} else if (static_method) {
914900
ADD_OP(_PUSH_NULL, 0, 0);
915901
self_or_null[0] = sym_new_null(ctx);
916902
}
917903
attr = sym_new_const(ctx, callable);
918904
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
919905
_Py_BloomFilter_Add(dependencies, (PyTypeObject *)type);
920-
}
921-
else {
906+
} else {
922907
attr = sym_new_not_null(ctx);
923908
self_or_null[0] = sym_new_unknown(ctx);
924909
}
925-
}
926-
else {
910+
} else {
927911
attr = sym_new_not_null(ctx);
928912
}
929913
}

Python/optimizer_cases.c.h

Lines changed: 5 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/record_functions.c.h

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)