-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Improve precision of abstract_iteration #36524
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
a8b1eb5 to
e272548
Compare
Some numbers on this: Before After: |
|
Something I long had on my to do list, but a half-hearted attempt didn't work out, so it stayed there. Glad you tackled it! I wouldn't worry too much about the high MAX_TUPLE_SPLAT: For those cases where this PR makes a difference, i.e. where |
martinholters
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.
I have a proposal for fixing the (1:33...,) case which also fixes the abstractarray test, see suggestions.
|
I've noticed something else funny going on here: After E.g. julia> f() = (()...,)
f (generic function with 1 method)
julia> f();
julia> f()
Internal error: encountered unexpected error in runtime:
TypeError(func=:Tuple, context="parameter", expected=Type, got=Core.Compiler.Const(val=2, actual=false))
[...]
()
julia> @code_typed f() # also here
CodeInfo(
1 ─ return Internal error: encountered unexpected error in runtime:
TypeError(func=:Tuple, context="parameter", expected=Type, got=Core.Compiler.Const(val=2, actual=false))
[...]
()
) => Tuple{}
The Array{Any, (3,)}[
Core.Compiler.Const(val=typeof(Base.iterate)(), actual=false),
Core.Compiler.Const(val=("#= circular reference @-", 1, " =#"), actual=false),
Core.Compiler.Const(val=2, actual=false)]and get widened to Array{Any, (3,)}[
typeof(Base.iterate),
Tuple{String, Int64, String},
Core.Compiler.Const(val=2, actual=false)]No idea what to make of this... EDIT: This doesn't depend on how the value to show produced, just what is show, e.g. julia> ()
TypeError(func=:Tuple, context="parameter", expected=Type, got=Core.Compiler.Const(val=2, actual=false))
[...]
() |
|
Ah, maybe the |
e272548 to
a1bdc2f
Compare
I can't reproduce this. I usually just use |
|
Anyway, I rotated the second loop, which I think should address the bug you found. |
martinholters
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.
LGTM. Should we add an explicit test for (1:N...,) with N > MAX_TUPLE_SPLAT?
This will be fixed by #36570 |
Currently abstract iteration works fine for length-1 iterators, but
fails over for other small length iterators, such as Pair{Int, Int},
or common patterns where `iterate` iterates over the fields of a
small struct. Other examples include StaticVectors and constant
iterators, which should all now unroll properly up to the
MAX_TUPLE_SPLAT limit. That said, MAX_TUPLE_SPLAT is quite high
at the moment, but because abstract_iteration isn't very precise,
it's unlikely to be limiting. With this increase in precision,
we may find that MAX_TUPLE_SPLAT is too high and we should lower it.
Also note that while this is a nice improvement, performance is still
not great, since we currently can't inline these apply calls. However,
fixing that is in progress in a parallel PR and with both changes
put together, the performance improvement of splatting of small
iterators is quite sizeable.
a1bdc2f to
3531e2a
Compare
Currently abstract iteration works fine for length-1 iterators, but
fails over for other small length iterators, such as Pair{Int, Int},
or common patterns where `iterate` iterates over the fields of a
small struct. Other examples include StaticVectors and constant
iterators, which should all now unroll properly up to the
MAX_TUPLE_SPLAT limit. That said, MAX_TUPLE_SPLAT is quite high
at the moment, but because abstract_iteration isn't very precise,
it's unlikely to be limiting. With this increase in precision,
we may find that MAX_TUPLE_SPLAT is too high and we should lower it.
Also note that while this is a nice improvement, performance is still
not great, since we currently can't inline these apply calls. However,
fixing that is in progress in a parallel PR and with both changes
put together, the performance improvement of splatting of small
iterators is quite sizeable.
Currently abstract iteration works fine for length-1 iterators, but
fails over for other small length iterators, such as Pair{Int, Int},
or common patterns where
iterateiterates over the fields of asmall struct. Other examples include StaticVectors and constant
iterators, which should all now unroll properly up to the
MAX_TUPLE_SPLAT limit. That said, MAX_TUPLE_SPLAT is quite high
at the moment, but because abstract_iteration isn't very precise,
it's unlikely to be limiting. With this increase in precision,
we may find that MAX_TUPLE_SPLAT is too high and we should lower it.
Also note that while this is a nice improvement, performance is still
not great, since we currently can't inline these apply calls. However,
fixing that is in progress in a parallel PR and with both changes
put together, the performance improvement of splatting of small
iterators is quite sizeable.