-
Notifications
You must be signed in to change notification settings - Fork 63
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
Make unpacking a Tuple or NamedTuple Composite type-inferrable #279
Conversation
Codecov Report
@@ Coverage Diff @@
## master #279 +/- ##
==========================================
- Coverage 89.58% 87.85% -1.74%
==========================================
Files 13 13
Lines 461 420 -41
==========================================
- Hits 413 369 -44
- Misses 48 51 +3
Continue to review full report at Codecov.
|
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.
That's really cool, thanks for the PR! It looks good (after version bump) to go but I am reluctant to approve anything I don't fully understand.
It is the function Base.indexed_iterate
, what is its purpose? There is no docstrings and I tried looking at the source. My understanding from that is that it iterates from the index i
onwards for Tuple
s and Array
s, but from state
onwards in the fallback case. I can' really see why this is needed?
julia> function foo(t)
a, b = t
return a, b
end
foo (generic function with 1 method)
julia> @code_lowered foo((1,2))
CodeInfo(
1 ─ %1 = Base.indexed_iterate(t, 1)
│ a = Core.getfield(%1, 1)
│ @_3 = Core.getfield(%1, 2)
│ %4 = Base.indexed_iterate(t, 2, @_3)
│ b = Core.getfield(%4, 1)
│ %6 = Core.tuple(a, b)
└── return %6 By default, |
Doesn't have to be in this PR, but might also make sense to overload |
Thanks for the explanation! I can't think of a better solution, and if this breaks in the future we can fix it then |
Just bump the version please |
I do recall reading a comment from a core developer that one shouldn't actually ever touch |
This PR resolves two issues that make unpacking a
Composite
uninferrable. On Julia 1.5, currently the following operations are uninferrable:These uninferrabilities came up in JuliaDiff/ChainRules.jl#193 and JuliaDiff/ChainRules.jl#323 (comment), respectively.
With this PR, these tests now pass.