[mypyc] Implement builtins.len primitive for list#9271
[mypyc] Implement builtins.len primitive for list#9271TH3CHARLie merged 9 commits intopython:masterfrom TH3CHARLie:list-len
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: |
JukkaL
left a comment
There was a problem hiding this comment.
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. |
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the updates! Looks mostly good, but there's one call op that I want to get rid of.
JukkaL
left a comment
There was a problem hiding this comment.
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_rprimitiveis introduced to represent pointer typePyVarObjectis registerdsize_t_to_short_intcustom 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.