I have been playing with the idea of automatically detecting type piracy.
https://discourse.julialang.org/t/pirate-hunter/20402
Here is the results of running it will the standard libraries loaded.
I'm not sure how many of these already have issues, eg #28234
and how many are harmless.
I am sure someone more knowledge-able than me can strike a bunch of them as not problematic.
But I figured I should share the list
Wow, a couple interesting items here.
(T::Union{Type{Int8}, Type{UInt8}})(c::Char) in Base at char.jl:170
That's entirely in base, seems like an incorrect result.
string(x::Vector{String}) = x
Pkg, are you kidding me? It doesn't even return a string...
- fetch(x) in Distributed
Yep, should be moved to Base. Not sure fetch
should be defined on Any
, but that's a separate question.
It looks like every useful method of kron
is in LinearAlgebra, so that's not so bad.
wait(::RawFD)
is ok since it strictly adds functionality.
You have the power to tick them (and other meanless ones and false positives) off right?
That is really cool. I worry about about people getting too worried about piracy (there are occasionally some very good reasons for it), but having a tool to detect seems like a clear win.
Pkg, are you kidding me? It doesn't even return a string...
Right; I look forward to wearing my "I'm a type pirate" T-shirt :) I think this is best seen as a heuristic for finding misplaced code, unintentional method extensions, etc.
- BigFloat(::Irrational{:SQRT_HALF}) in Random at irrationals.jl:158
This is kind of OK since it's the only way to make new irrational numbers. However, we should perhaps add a couple more like sqrt(2) to Base.
- apropos(io::IO, needle::Regex) in REPL at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/REPL/src/docview.jl:621
This is intentional, since we wanted to move doc viewing code out of Base. But I think it's still up in the air where all the Base.Docs code should go exactly.
- in(v::VersionNumber, r::VersionNumber)
Could maybe go in base, but VersionNumber isn't iterable. Maybe Pkg could arrange to wrap the argument in a VersionRange instead?
- isless(a::Base.UUID, b::Base.UUID)
Can move to Base.
- show(io::IO, ::MIME{Symbol("text/csv")}, a)
This might actually make sense in Base as well. The code for writing is much simpler than the code for parsing. We should maybe even use this as the output format of print
on matrices. It should probably also be specialized at least as a::AbstractArray
.
in(v::VersionNumber, r::VersionNumber)
[25] string(x::Array{String,1}) in Pkg.Types
Fix at JuliaLang/Pkg.jl#1036
• isless(a::Base.UUID, b::Base.UUID)
Can move to Base.
There's also vcat(::Vector...)
in SparseArrays.jl:
SparseArrays seems like a chronic offender: https://github.com/JuliaLang/julia/issues/32213
This is missing e.g
julia> @which rand(5,5) * rand(5,5)
*(A::AbstractArray{T,2} where T, B::AbstractArray{T,2} where T) in LinearAlgebra at ...julia/stdlib/v1.3/LinearAlgebra/src/matmul.jl:152
I worry about about people getting too worried about piracy (there are occasionally some very good reasons for it), but having a tool to detect seems like a clear win.
FWIW, type piracy means that it is impossible to look at the Project and know what stdlibs a package actually use. For example, you can do matrix multiplication or call rand()
without requiring LinearAlgebra
or Random
in your Project file. In the scenario where one wants to ship an app with a custom sysimage it would be desirable to exclude the stdlibs not needed by the app (for smaller file size and faster load times). Type-piracy now comes and puts a big stick in the wheel because there is no way to know what stdlibs the app actually need because the code might be filled with matrix multiplication but no trace of LinearAlgebra
is found.
Most helpful comment
Right; I look forward to wearing my "I'm a type pirate" T-shirt :) I think this is best seen as a heuristic for finding misplaced code, unintentional method extensions, etc.