Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR inlines math literals such as
math.pi
andmath.e
. Previously Usingmath.pi
would emit a getattr, unbox, error check, then box op code, but now it just boxes the value directly.This PR is an improvement, but there are a few things that could be improved further:
math
is still being imported even if you only imported literal values such aspi
(which is now inlined and doesn't need to be imported).We are essentially boxing a literal which should be a
CPyLit_Float
value instead. I looked into this, but AFAICT there is no "float object" primitve, meaning Mypyc will emit the same amount of code as before (minus the getattr) which is not ideal. Is there any way to indicate in the IR that aCPyLit_Float
value is a boxed float as opposed to an unboxed float (double
)?Also, I added a test to ensure that the math literals are inlined properly and have the same value, but the test is failing saying that
pi
does not exist on modulemath
. There are no errors when running the same file through mypy, so I don't know why it is failing. I checked, and the issue still seems to be present onmaster
.Closes mypyc/mypyc#985