-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: ForMap generator helper for builtins.map
#19649
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
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.
Nice, map
is a commonly used builtin.
s += x * 10 + y | ||
return s | ||
|
||
[file driver.py] |
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.
Please merge all the run tests into a single test without a [file driver.py]
section. Use assertions instead of [out]
sections for checking things. This way tests will run faster and they will be easier to maintain.
r14 = box(int, _mypyc_map_arg_0) | ||
r15 = box(int, _mypyc_map_arg_1) | ||
r16 = unbox(int, r14) | ||
r17 = unbox(int, r15) |
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.
The boxing followed by unboxing seems pointless. It would be great if we didn't need this (it might be a pre-existing issue though).
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.
Agreed. I'll take a look. Does mypyc currently perform any optimization over the IR before generating the actual C code? I looked briefly at the transform module, which seems like it might play some role here, but I couldn't figure out the entrypoint, or if that section even works as I think it does
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.
After looking, I'm not entirely sure what causes this.
The fake NameExpr that I created is using the correct rtype in the IR, and from reading the code in for_helpers I can't figure out why (or where) r14 thru r17 are being emitted.
What I see is that we create a CallExpr using the NameExpr directly as the input, which implies to me there wouldn't be any intermediate values involved in the actual call.
mypyc/test-data/irbuild-basic.test
Outdated
L6: | ||
return s | ||
|
||
[case testForMapThreeArgs] |
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.
The number of irbuild tests is perhaps a bit much? I wonder if 1-2 irbuild test cases would be sufficient, with the remaining cases only covered by run tests.
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.
I picked 3 to keep, one-arg, 3-arg, and comprehension
for more information, see https://pre-commit.ci
This PR adds a
ForMap
helper class forfor
loops overbuiltins.map
which allows mypyc to maintain control of the function calling, so it can call native functions and primitive ops, and to avoid allocation of iterators in many cases.