-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Simplify lowering of typed comprehension #32709
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
See this 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.
yes. and to expand on that a little, we use this to make it possible to use comprehensions in reflection and inference. we wouldn't be able to use comprehensions there if it wasn't for this guarantee.
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.
OK, I guess that makes sense; I just noticed I can even return a typed comprehension from a
@generated
function (for obvious reasons). There seems to be a bunch ofAny[... for ...]
comprehensions in the compiler.On the other hand, it seems these days that
collect
is getting some overloads and therefore untyped comprehensions aren't so tied toArray
anymore. For example, is it bad that[f(x) for x in a::StaticArray] isa StaticArray
? This is juxtaposed with!(Float64[f(x) for x in a::StaticArray) isa StaticArray)
. I'm wondering if we can get a bit more consistency? (As in - maybe the solution we want is the opposite of this PR, and enforce the untyped version to always create anArray
?)I note that I don't see an aweful lot of typed comprehensions in user code (maybe I'm wrong and that's just me?) so do you know if outside of Julia internals does this lowering "optimization" has much of an impact on latency in the wild? If not, could the desired behavior be viewed as more of a bootstrap vs not bootstrap issue?
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.
Yes I definitely read this comment! At face value it says "this is a performance hack" and I wondered whether it was still necessary. Especially because comprehensions seem more common than typed comprehensions for user code.
Thanks @vtjnash for expanding. Here's what I think you're saying:
base/compiler
due to the call toreturn_type
here:julia/base/array.jl
Line 594 in 442d159
greatly reduce the # of functions and load on the compiler
refers to the performance of comprehensions in the compiler itself rather than the performance of user code (??)But I don't understand why lowering to
collect(T, gen)
is not ok - this doesn't callreturn_type
; it goes via the_collect
methods here:julia/base/array.jl
Line 519 in 442d159
If this is about compiler performance, what should I be measuring? Is the time to compile Base relevant?