Skip to content
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

Merged
merged 2 commits into from
Jul 27, 2020
Merged

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Jul 27, 2020

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

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
@bkamins bkamins added this to the 1.0 milestone Jul 27, 2020
Copy link
Member

@bkamins bkamins left a 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,
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@quinnj quinnj merged commit 45284e9 into master Jul 27, 2020
@quinnj quinnj deleted the jq/fixcrash branch July 27, 2020 22:27
@bkamins
Copy link
Member

bkamins commented Jul 27, 2020

I understand it would be good to backport it to 0.21 branch - right? If yes I will do it.

@quinnj
Copy link
Member Author

quinnj commented Jul 27, 2020

Yeah, I think that's a good idea.

@bkamins
Copy link
Member

bkamins commented Jul 27, 2020

(a small note: as a rule we typically squash-merge the PRs in DataFrames.jl)

bkamins pushed a commit that referenced this pull request Jul 27, 2020
Don't specialize groupreduce! on result array element type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants