GH-131798: Skip self/NULL checks for some known non-methods#132278
GH-131798: Skip self/NULL checks for some known non-methods#132278brandtbucher wants to merge 3 commits intopython:mainfrom
self/NULL checks for some known non-methods#132278Conversation
|
What about this: def call_x(a, b):
return a.x(b)
class C: pass
c = C()
c.x = type
call_x(c, 1); call_x(c, 1)
f = types.MethodType(type, 3)
class D:
x = f
d = D()
call_x(d, "string") |
|
I'll try, but I'm pretty sure those are fine, since At any rate, I'll add a test. |
|
@markshannon, I went ahead and added a bunch of tests for weird method patterns like that. |
|
I'm still reluctant to make this change, as it makes the behavior of individual instructions depend on implicit context. def f(x, a, b):
return x(a, b)currently compiles as but it could be correctly compiled as: which would not work with this PR. |
|
IIRC, we use do just something like that. When compiling |
CALL_TYPE_1,CALL_STR_1,CALL_TUPLE_1,CALL_LEN, andCALL_ISINSTANCEwill never call a method descriptor, which means that we can just assert thatself_or_nullisNULLinstead of checking and "adjusting" the arguments each time.CALL_BUILTIN_CLASSshould never call a method descriptor, but I'm not sure that we can gurantee it. So I've just made this aDEOPT_IFinstead.