Skip to content

Commit 7bcc1c4

Browse files
gh-131798: relax GUARD_CALLABLE checks for self type checks (#148069)
1 parent 7e275d4 commit 7bcc1c4

File tree

2 files changed

+64
-56
lines changed

2 files changed

+64
-56
lines changed

Python/optimizer_bytecodes.c

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,19 +1323,20 @@ dummy_func(void) {
13231323
PyObject *callable_o = sym_get_const(ctx, callable);
13241324
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
13251325
int total_args = oparg;
1326-
if (!sym_is_null(self_or_null)) {
1326+
if (sym_is_not_null(self_or_null)) {
13271327
total_args++;
13281328
}
1329-
PyObject *self = NULL;
1330-
if (!sym_is_null(self_or_null)) {
1331-
self = sym_get_const(ctx, self_or_null);
1332-
} else {
1333-
self = sym_get_const(ctx, args[0]);
1329+
PyTypeObject *self_type = NULL;
1330+
if (sym_is_not_null(self_or_null)) {
1331+
self_type = sym_get_type(self_or_null);
1332+
}
1333+
else {
1334+
self_type = sym_get_type(args[0]);
13341335
}
13351336
PyTypeObject *d_type = ((PyMethodDescrObject *)callable_o)->d_common.d_type;
13361337
if (total_args == 2 &&
13371338
((PyMethodDescrObject *)callable_o)->d_method->ml_flags == METH_O &&
1338-
self && Py_IS_TYPE(self, d_type)) {
1339+
self_type == d_type) {
13391340
ADD_OP(_NOP, 0, 0);
13401341
}
13411342
}
@@ -1348,19 +1349,20 @@ dummy_func(void) {
13481349
PyObject *callable_o = sym_get_const(ctx, callable);
13491350
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
13501351
int total_args = oparg;
1351-
if (!sym_is_null(self_or_null)) {
1352+
if (sym_is_not_null(self_or_null)) {
13521353
total_args++;
13531354
}
1354-
PyObject *self = NULL;
1355-
if (!sym_is_null(self_or_null)) {
1356-
self = sym_get_const(ctx, self_or_null);
1357-
} else {
1358-
self = sym_get_const(ctx, args[0]);
1355+
PyTypeObject *self_type = NULL;
1356+
if (sym_is_not_null(self_or_null)) {
1357+
self_type = sym_get_type(self_or_null);
1358+
}
1359+
else {
1360+
self_type = sym_get_type(args[0]);
13591361
}
13601362
PyTypeObject *d_type = ((PyMethodDescrObject *)callable_o)->d_common.d_type;
13611363
if (total_args != 0 &&
13621364
((PyMethodDescrObject *)callable_o)->d_method->ml_flags == (METH_FASTCALL|METH_KEYWORDS) &&
1363-
self && Py_IS_TYPE(self, d_type)) {
1365+
self_type == d_type) {
13641366
ADD_OP(_NOP, 0, 0);
13651367
}
13661368
}
@@ -1373,19 +1375,20 @@ dummy_func(void) {
13731375
PyObject *callable_o = sym_get_const(ctx, callable);
13741376
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
13751377
int total_args = oparg;
1376-
if (!sym_is_null(self_or_null)) {
1378+
if (sym_is_not_null(self_or_null)) {
13771379
total_args++;
13781380
}
1379-
PyObject *self = NULL;
1380-
if (!sym_is_null(self_or_null)) {
1381-
self = sym_get_const(ctx, self_or_null);
1382-
} else {
1383-
self = sym_get_const(ctx, args[0]);
1381+
PyTypeObject *self_type = NULL;
1382+
if (sym_is_not_null(self_or_null)) {
1383+
self_type = sym_get_type(self_or_null);
1384+
}
1385+
else {
1386+
self_type = sym_get_type(args[0]);
13841387
}
13851388
PyTypeObject *d_type = ((PyMethodDescrObject *)callable_o)->d_common.d_type;
13861389
if (total_args == 1 &&
13871390
((PyMethodDescrObject *)callable_o)->d_method->ml_flags == METH_NOARGS &&
1388-
self && Py_IS_TYPE(self, d_type)) {
1391+
self_type == d_type) {
13891392
ADD_OP(_NOP, 0, 0);
13901393
}
13911394
}
@@ -1431,19 +1434,20 @@ dummy_func(void) {
14311434
PyObject *callable_o = sym_get_const(ctx, callable);
14321435
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
14331436
int total_args = oparg;
1434-
if (!sym_is_null(self_or_null)) {
1437+
if (sym_is_not_null(self_or_null)) {
14351438
total_args++;
14361439
}
1437-
PyObject *self = NULL;
1438-
if (!sym_is_null(self_or_null)) {
1439-
self = sym_get_const(ctx, self_or_null);
1440-
} else {
1441-
self = sym_get_const(ctx, args[0]);
1440+
PyTypeObject *self_type = NULL;
1441+
if (sym_is_not_null(self_or_null)) {
1442+
self_type = sym_get_type(self_or_null);
1443+
}
1444+
else {
1445+
self_type = sym_get_type(args[0]);
14421446
}
14431447
PyTypeObject *d_type = ((PyMethodDescrObject *)callable_o)->d_common.d_type;
14441448
if (total_args != 0 &&
14451449
((PyMethodDescrObject *)callable_o)->d_method->ml_flags == METH_FASTCALL &&
1446-
self && Py_IS_TYPE(self, d_type)) {
1450+
self_type == d_type) {
14471451
ADD_OP(_NOP, 0, 0);
14481452
}
14491453
}

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)