-
Notifications
You must be signed in to change notification settings - Fork 372
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
Don't specialize groupreduce! on result array element type #2335
Conversation
Works around crash seen in #2326. The inferred return type of `groupreduce_init` is `Union{Vector{Any}, SentinelVector{Float64}}` and it seems the compiler then crashes when trying to correctly identify `U` from that union of types. Part of my conclusion here is based on the fact that if you remove all other argument type constraints and just make `groupreduce!` return `res` directly, it still crashes; thus, by deduction, the crash has something to do with the compiler having trouble with the `::AbstractVector{U}` argument type constraint/specialization. The work-around is pretty uncontroversial; we were already calling `eltype(res)` in several other places, and I've checked that it infers the same. I didn't add a test since this seems like such an obscure compiler bug that it doesn't really seem necessary for DataFrames to be testing core compiler behavior. Also note that this bug exists in Julia <= 1.5, so current Julia master (pending 1.6), which includes a number of compiler refactorings/changes, seems to have resolved whatever the issue was. cc: @Keno, @vtjnash, @JeffBezanson
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.
Looks good. I will wait for core-devs to comment but I always thought that eltype(res)
should work just fine in such cases.
@@ -962,8 +962,8 @@ function copyto_widen!(res::AbstractVector{T}, x::AbstractVector) where T | |||
return res | |||
end | |||
|
|||
function groupreduce!(res::AbstractVector{U}, f, op, condf, adjust, checkempty::Bool, | |||
incol::AbstractVector{T}, gd::GroupedDataFrame) where {U,T} | |||
function groupreduce!(res, f, op, condf, adjust, checkempty::Bool, |
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.
Just maybe leve res::AbstractVector
for documentation reasons. I understand it should be OK, or this also crashes?
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.
done
I understand it would be good to backport it to 0.21 branch - right? If yes I will do it. |
Yeah, I think that's a good idea. |
(a small note: as a rule we typically squash-merge the PRs in DataFrames.jl) |
Don't specialize groupreduce! on result array element type
Works around crash seen in #2326. The inferred return type of
groupreduce_init
isUnion{Vector{Any}, SentinelVector{Float64}}
andit seems the compiler then crashes when trying to correctly identify
U
from that union of types. Part of my conclusion here is based on the
fact that if you remove all other argument type constraints and just
make
groupreduce!
returnres
directly, it still crashes; thus, bydeduction, the crash has something to do with the compiler having
trouble with the
::AbstractVector{U}
argument typeconstraint/specialization.
The work-around is pretty uncontroversial; we were already calling
eltype(res)
in several other places, and I've checked that it infersthe same. I didn't add a test since this seems like such an obscure
compiler bug that it doesn't really seem necessary for DataFrames to be
testing core compiler behavior.
Also note that this bug exists in Julia <= 1.5, so current Julia master
(pending 1.6), which includes a number of compiler refactorings/changes,
seems to have resolved whatever the issue was.
cc: @Keno, @vtjnash, @JeffBezanson