8000 Add back SELF_OR_NULL :( · python/cpython@54e2f64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54e2f64

Browse files
Add back SELF_OR_NULL :(
1 parent 2805755 commit 54e2f64

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

Python/abstract_interp_cases.c.h

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

Python/optimizer_analysis.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ typedef enum {
8888
NULL_TYPE = 6,
8989
PYMETHOD_TYPE = 7,
9090
GUARD_DORV_VALUES_TYPE = 8,
91+
// This is a non-ideal fix. Once all _LOAD_ATTR is properly annotated
92+
// with proper type information (at least, that `self` is present), this
93+
// can be removed. Otherwise, for now, this is used to distinguish
94+
// _LOAD_ATTR (self/null unknown) and
95+
// _LOAD_ATTR (unknown, but type cannot be captured in our current type system).
96+
SELF_OR_NULL = 9,
9197

9298
// Represents something from LOAD_CONST which is truly constant.
9399
TRUE_CONST = 30,
@@ -491,11 +497,6 @@ sym_matches_pytype(_Py_UOpsSymType *sym, PyTypeObject *typ, uint64_t refinement)
491497
return sym_matches_type(sym, pytype_to_type(typ), refinement);
492498
}
493499

494-
static inline bool
495-
sym_is_unknown_type(_Py_UOpsSymType *sym)
496-
{
497-
return sym->types == 0 || (sym->types == 1U << INVALID_TYPE);
498-
}
499500

500501
static uint64_t
501502
sym_type_get_refinement(_Py_UOpsSymType *sym, _Py_UOpsSymExprTypeEnum typ)

Python/tier2_redundancy_eliminator_bytecodes.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ dummy_func(void) {
152152
top, unused[oparg-2], bottom)) {
153153
}
154154

155+
op(_LOAD_ATTR, (owner -- attr, self_or_null if (oparg & 1))) {
156+
self_or_null = sym_init_unknown(ctx);
157+
if (self_or_null == NULL) {
158+
goto error;
159+
}
160+
sym_set_type(self_or_null, SELF_OR_NULL, 0);
161+
(void)owner;
162+
attr = sym_init_unknown(ctx);
163+
if (attr == NULL) {
164+
goto error;
165+
}
166+
}
167+
155168
op(_CHECK_FUNCTION_EXACT_ARGS, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
156169
sym_set_pytype(callable, &PyFunction_Type, func_version);
157170
(void)self_or_null;
@@ -174,7 +187,7 @@ dummy_func(void) {
174187
assert(self_or_null != NULL);
175188
assert(args != NULL);
176189
if (!sym_matches_pytype(self_or_null, NULL, 0) &&
177-
!sym_is_unknown_type(self_or_null)) {
190+
!sym_matches_type(self_or_null, SELF_OR_NULL, 0)) {
178191
// Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in
179192
// VM
180193
args--;
@@ -186,7 +199,7 @@ dummy_func(void) {
186199
// Can determine statically, so we interleave the new locals
187200
// and make the current stack the new locals.
188201
// This also sets up for true call inlining.
189-
if (!sym_is_unknown_type(self_or_null)) {
202+
if (!sym_matches_type(self_or_null, SELF_OR_NULL, 0)) {
190203
localsplus_start = args;
191204
n_locals_already_filled = argcount;
192205
}

0 commit comments

Comments
 (0)
0