OrderedCollections.jl icon indicating copy to clipboard operation
OrderedCollections.jl copied to clipboard

Type piracy?

Open dpo opened this issue 5 years ago • 11 comments

We're having an issue using Julia from the Juno REPL (which imports OrderedCollections), in which sort() of a Dict returns an OrderedDict even though the user didn't import OrderedCollections. The unexpected behavior is described here:

https://discourse.julialang.org/t/juno-repl-behaves-differently-than-terminal-repl/29469/2

The culprit appears to be :

julia> d = Dict(1 => "a", 3 => "b", 0 => "c")
Dict{Int64,String} with 3 entries:
  0 => "c"
  3 => "b"
  1 => "a"

julia> sort(d)
OrderedCollections.OrderedDict{Int64,String} with 3 entries:
  0 => "c"
  1 => "a"
  3 => "b"

julia> @which sort(d)
sort(d::Dict) in OrderedCollections at /Users/dpo/.julia/packages/OrderedCollections/E21Rb/src/dict_sorting.jl:21

Thanks.

dpo avatar Oct 04 '19 02:10 dpo

I was sure @ararslan removed that ages ago.

We should just delete it. Only question is if to tag a major or patch release.

oxinabox avatar Oct 04 '19 09:10 oxinabox

If I did remove it, it was probably before OrderedCollections was split out from DataStructures, or something like that. I don't really remember but I agree this is bad. Since this has the potential to break downstream code and OrderedCollections has declared its version to be > 1.0, I think it should be a major release.

ararslan avatar Oct 04 '19 16:10 ararslan

It might have happened during the period where the code existed in both places, and it got removed from DataStructures but not removed from OrderedCollections, and so it came back when DataStructures switched to just reexporting

oxinabox avatar Oct 04 '19 17:10 oxinabox

Seems like a good idea to remove it. It was there when I split this out. Maybe there was an unmerged PR or something?

timholy avatar Oct 07 '19 23:10 timholy

Should not have been closed. As only deprecated so far

oxinabox avatar Oct 08 '19 23:10 oxinabox

This came up again. The deprecation has been in place for about 16 months, although it only made it into a release 9 months ago. That seems more than long enough. Shall we delete it and release OrderedCollections v2? Or is the plan to reintegrate into DataStructures?

timholy avatar Feb 19 '21 11:02 timholy

While there is a full and concrete plan for exactly how to get DataStructures up to 1.0 I don't have time to work on it. So it is going to be a longtime before it is done, unless someone else finds time. https://github.com/JuliaCollections/DataStructures.jl/issues/479#issuecomment-682449805 And we can't merge OrderedCollections into DataStructures until that is done. So I would not let that block anything.

But also I am in no rush to remove this type-piracy. It is unlikely to be causing a problem for anyone; since it turns a method error into a non-method error. and when we remove it, and trigger a breaking change we are going to cause about 15 human-hours of work to be done for little gain, even with CompatHelper, PR still need to be reviewed, merged, tagged. So say 10 minutes. We have 84 public direct dependencies, and I am pretty sure at least 26 private ones. So call it 1000minutes is 16hr40min. probably more because some people will incorrectly tag a breaking change to their package after this, triggering another round of cascading changes. Doesn't seem worth it, unless we had more things to fix at the same time. Things that are actually going to break real code.

oxinabox avatar Feb 19 '21 13:02 oxinabox

It is arguably also introducing a bug:

julia> eltype(dict)
Pair{Int64, Int64}
julia> collect(dict)
80200-element Vector{Pair{Int64, Int64}}:
julia> sort(dict, by=x->x.second)
ERROR: type Int64 has no field second

mschauer avatar Apr 29 '21 20:04 mschauer

Following up from https://github.com/JuliaCollections/OrderedCollections.jl/pull/110

Conclusion is we remove it either:

  • Next major release of OrderedCollections.jl
  • Or some appropriate period of time after https://github.com/JuliaLang/julia/issues/49583 is fixed to show deprecations that are your fault during normal exectution.

Which ever comes first.

oxinabox avatar Dec 14 '23 06:12 oxinabox

This is getting worse with 1.10 now out and is actually a critical error in some advanced sysimage use cases

What would it take to push for a 2.0 release? Are there any other planned 2.0 changes?

krynju avatar Feb 19 '24 18:02 krynju

Data point: even though I commented above, I forgot about this issue and now I notice that I have code which relies on this observable behaviour.

mschauer avatar Feb 19 '24 18:02 mschauer