-
Notifications
You must be signed in to change notification settings - Fork 244
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
remove eltype piracy from SortedDict #854
Conversation
Could someone explain how this is type piracy? The offending statements refer to types that are defined in this module, namely, SortedDict, etc., so they would not affect someone else's eltype. |
The meaning of |
I think the argument is that you don't own |
You could own some of |
Could you give me an example how this declaration could cause problems for some other code? I tried below to cause trouble unsuccessfully. julia> VERSION
v"1.8.2"
julia> using DataStructures
julia> s = SortedDict("a" => 4)
SortedDict{String, Int64, Base.Order.ForwardOrdering} with 1 entry:
"a" => 4
julia> eltype(s)
Pair{String, Int64}
julia> @which eltype(s)
eltype(m::SortedDict{K, D, Ord}) where {K, D, Ord<:Base.Order.Ordering} in DataStructures at C:\Users\vavasis\.julia\packages\DataStructures\59MD0\src\sorted_dict.jl:280
julia> struct C{S,T} <: AbstractDict{S,T}
end
julia> Base.iterate(::C{S,T}, state=0) where S where T = nothing
julia> v = C{String,Int}()
C{String, Int64}()
julia> eltype(v)
Pair{String, Int64}
julia> @which eltype(v)
eltype(x) in Base at abstractarray.jl:206
julia> eltype(C{String,Int})
Pair{String, Int64}
julia> @which eltype(C{String,Int})
eltype(::Type{<:AbstractDict{K, V}}) where {K, V} in Base at abstractdict.jl:479 |
I think one issue is that all code that has previously inferred |
Correct. You are force it to inject an inference barrier here, so that the compiler can handle the piracy. It knows how to keep working, even though it will cost users performance after it is pushed off the fast path. |
Are any of those eltype/keytype/valtype methods required? Doesn't mutable struct SortedDict{K, D, Ord <: Ordering} <: AbstractDict{K,D}
bt::BalancedTree23{K,D,Ord}
end mean that everything would work if you deleted all six of them? (I.e., deleting even the ones that Jameson didn't delete.) A reason to consider that is that defining new |
Looks like there is another similar one on
(Tim is also right, but I previously left them because they cause fewer problems. But it still would make sense to delete them also and DRY the code.) |
Thanks for the explanation-- I understand better now. Yes, all of those can be deleted. You can also get rid of the eltype in sorted_set.jl for the same reason (inherited from AbstractSet). |
Can this be merged? |
Before this is merged, is the OP okay with making a similar edit to sorted_set.jl in order to fix the problem more thoroughly? |
I don't generally have a ton of time to improve packages unfortunately, since I am spread rather thin among a lot of them |
FYI I made an attempt on this in #863. |
No description provided.