-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc] feat: use get_expr_length_value in translate_len
#20074
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
Currently, `translate_len` can determine the length of an RTuple at compile time This PR extends this capability to all expressions supported by `get_expr_length_value`
| def get_length(): | ||
| r0 :: str | ||
| L0: | ||
| r0 = 'https://w3id.org/cwl/salad#' |
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.
It would be nice to figure out how to avoid loading the constant at all, but I couldn't figure it out when I was implementing this PR
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.
We can add an optimization pass at some point that removes unused pure values.
JukkaL
left a comment
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 PR! Looks good.
| def get_length(): | ||
| r0 :: str | ||
| L0: | ||
| r0 = 'https://w3id.org/cwl/salad#' |
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.
We can add an optimization pass at some point that removes unused pure values.
Currently,
translate_lencan determine the length of an RTuple at compile timeThis PR extends this capability to all expressions supported by
get_expr_length_valueThis will constant fold the code example displayed in mypyc/mypyc#1152 without waiting for the implementation of #19886 which has a few steps ahead of it
Before:
After:
Even after #19986, this will also work for some situations that constant folding cannot handle but
get_expr_lengthcan