-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[mypyc] Implement builtins.len primitive for list #9271
Conversation
for this function: def f(a: List[int]) -> int:
return len(a) originally: CPyTagged CPyDef_f(PyObject *cpy_r_a) {
CPyTagged cpy_r_r0;
Py_ssize_t __tmp1;
CPyL0: ;
__tmp1 = PyList_GET_SIZE(cpy_r_a);
cpy_r_r0 = CPyTagged_ShortFromSsize_t(__tmp1);
return cpy_r_r0;
} now: CPyTagged CPyDef_f(PyObject *cpy_r_a) {
CPyPtr cpy_r_r0;
int64_t cpy_r_r1;
CPyTagged cpy_r_r2;
CPyL0: ;
cpy_r_r0 = (CPyPtr)&((PyVarObject *)cpy_r_a)->ob_size;
cpy_r_r1 = *(int64_t *)cpy_r_r0;
cpy_r_r2 = CPyTagged_ShortFromSsize_t(cpy_r_r1);
return cpy_r_r2;
} 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.
Here's my first quick review pass (not a full review).
@JukkaL I find a potential problem when fixing the IR tests: although we implement |
That's a good idea. |
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 for the updates! Looks mostly good, but there's one call op that I want to get rid of.
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, looks good now! I left one comment -- feel free to merge this yourself once you've addressed it.
I just updated that, I'll merge this once all tests go green. |
In this PR,
pointer_rprimitive
is introduced to represent pointer typePyVarObject
is registerdsize_t_to_short_int
custom op is addedGetElementPtr
's codegen is largely changed.I am marking this as a draft now and I expect tests to fail. Tests will be fixed once we decide the final design.