-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] handle negative_int_emit and Truncate op #9050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
With this PR, for the following python function: def foo(x: object) -> bool:
z = isinstance(x, str)
return z The C code before: char CPyDef_foo(PyObject *cpy_r_x) {
PyObject *cpy_r_r0;
char cpy_r_r1;
char cpy_r_z;
char cpy_r_r2;
CPyL0: ;
cpy_r_r0 = (PyObject *)&PyUnicode_Type;
int __tmp1 = PyObject_IsInstance(cpy_r_x, cpy_r_r0);
if (__tmp1 < 0)
cpy_r_r1 = 2;
else
cpy_r_r1 = __tmp1;
if (unlikely(cpy_r_r1 == 2)) {
CPy_AddTraceback("../foo.py", "foo", 2, CPyStatic_globals);
goto CPyL2;
} else
goto CPyL1;
CPyL1: ;
cpy_r_z = cpy_r_r1;
return cpy_r_z;
CPyL2: ;
cpy_r_r2 = 2;
return cpy_r_r2;
} after: char CPyDef_foo(PyObject *cpy_r_x) {
PyObject *cpy_r_r0;
int32_t cpy_r_r1;
char cpy_r_r2;
char cpy_r_z;
char cpy_r_r3;
CPyL0: ;
cpy_r_r0 = (PyObject *)&PyUnicode_Type;
cpy_r_r1 = PyObject_IsInstance(cpy_r_x, cpy_r_r0);
if (unlikely(cpy_r_r1 < 0)) {
CPy_AddTraceback("../foo.py", "foo", 2, CPyStatic_globals);
goto CPyL2;
} else
goto CPyL1;
CPyL1: ;
cpy_r_r2 = cpy_r_r1;
cpy_r_z = cpy_r_r2;
return cpy_r_z;
CPyL2: ;
cpy_r_r3 = 2;
return cpy_r_r3;
} We actually reduce the comparison by 1 even though we introduce a new op in its IR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left a few comments about documentation.
Once this is merged, I'd start to merge the remaining ops during the weekends. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
related mypyc/mypyc#734