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

v0.6 precompile error: new UnionAll type breaks things #65

Closed
ghost opened this issue Jan 17, 2017 · 24 comments
Closed

v0.6 precompile error: new UnionAll type breaks things #65

ghost opened this issue Jan 17, 2017 · 24 comments

Comments

@ghost
Copy link

ghost commented Jan 17, 2017

INFO: Precompiling module ColorTypes.
ERROR: LoadError: LoadError: MethodError: no method matching subtypes(::Type{ColorTypes.Color})
Closest candidates are:
  subtypes(::Module, ::DataType) at reflection.jl:316
  subtypes(::DataType) at reflection.jl:333
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:532
 [2] include(::String) at ./sysimg.jl:14
 [3] include_from_node1(::String) at ./loading.jl:532
 [4] include(::String) at ./sysimg.jl:14
 [5] anonymous at ./<missing>:2
while loading /home/joe/.julia/v0.6/ColorTypes/src/types.jl, in expression starting on line 417
while loading /home/joe/.julia/v0.6/ColorTypes/src/ColorTypes.jl, in expression starting on line 56

can be fixed with:

const color3types = filter(x->(!x.abstract && length(fieldnames(x))>1), union(subtypes(Color{T,N}) where T where N, subtypes(AbstractRGB{T}) where T))

but then it fails again on

INFO: Precompiling module ColorTypes.
ERROR: LoadError: LoadError: type UnionAll has no field name
Stacktrace:
 [1] macro expansion; at /home/joe/.julia/v0.6/ColorTypes/src/types.jl:555 [inlined]
 [2] anonymous at ./<missing>:?
 [3] include_from_node1(::String) at ./loading.jl:532
 [4] include(::String) at ./sysimg.jl:14
 [5] include_from_node1(::String) at ./loading.jl:532
 [6] include(::String) at ./sysimg.jl:14
 [7] anonymous at ./<missing>:2
while loading /home/joe/.julia/v0.6/ColorTypes/src/types.jl, in expression starting on line 532
while loading /home/joe/.julia/v0.6/ColorTypes/src/ColorTypes.jl, in expression starting on line 56
@ghost
Copy link
Author

ghost commented Jan 17, 2017

can be fixed with

for (C, acol, cola) in [(DIN99d{T}, :ADIN99d, :DIN99dA),
                        (DIN99o{T}, :ADIN99o, :DIN99oA),
                        (DIN99{T}, :ADIN99, :DIN99A),
                        (HSI{T}, :AHSI, :HSIA),
                        (HSL{T}, :AHSL, :HSLA),
                        (HSV{T}, :AHSV, :HSVA),
                        (LCHab{T}, :ALCHab, :LCHabA),
                        (LCHuv{T}, :ALCHuv, :LCHuvA),
                        (LMS{T}, :ALMS, :LMSA),
                        (Lab{T}, :ALab, :LabA),
                        (Luv{T}, :ALuv, :LuvA),
                        (XYZ{T}, :AXYZ, :XYZA),
                        (YCbCr{T}, :AYCbCr, :YCbCrA),
                        (YIQ{T}, :AYIQ, :YIQA),
                        (xyY{T}, :AxyY, :xyYA),
                        (BGR{T}, :ABGR, :BGRA),
                        (RGB{T}, :ARGB, :RGBA),
                        (Gray{T}, :AGray, :GrayA)] where T

but then fails in color_type and base_colorant_type

@ghost
Copy link
Author

ghost commented Jan 17, 2017

Subtypes() should accept UnionAll, not sure about everything else :(
JuliaLang/julia#20084

@JeffBezanson
Copy link

subtypes(AbstractRGB{T}) where T

This should not work --- an array of types is not a valid type. I'll add an error for this.

@timholy
Copy link
Member

timholy commented Jan 17, 2017

ColorTypes is basically a poster child for the kind of package that could benefit from the type revisions (e.g.,

ColorTypes.jl/src/traits.jl

Lines 177 to 257 in a0f9898

"""
`ccolor` ("concrete color") helps write flexible methods. The idea is
that users may write `convert(HSV, c)` or even `convert(Array{HSV},
A)` without specifying the element type explicitly (e.g.,
`convert(Array{HSV{Float32}}, A)`). `ccolor` implements the logic "choose the
user's eltype if specified, otherwise retain the eltype of the source
object." However, when the source object has FixedPoint element type,
and the destination only supports AbstractFloat, we choose Float32.
Usage:
ccolor(desttype, srctype) -> concrete desttype
Example:
convert{C<:Colorant}(::Type{C}, p::Colorant) = cnvt(ccolor(C,typeof(p)), p)
where `cnvt` is the function that performs explicit conversion.
"""
ccolor{ Csrc<:Colorant}(::Type{Colorant }, ::Type{Csrc}) = Csrc
ccolor{T, Csrc<:Colorant}(::Type{Colorant{T}}, ::Type{Csrc}) = base_colorant_type(Csrc){T}
ccolor{T, Csrc<:Color3 }(::Type{Colorant{T,3}}, ::Type{Csrc}) = Csrc
ccolor{T, Csrc<:Transparent3}(::Type{Colorant{T,3}}, ::Type{Csrc}) = base_color_type(Csrc)
ccolor{ Csrc<:Colorant}(::Type{Color }, ::Type{Csrc}) = color_type(Csrc)
ccolor{T, Csrc<:Colorant}(::Type{Color{T}}, ::Type{Csrc}) = base_color_type(Csrc){T}
ccolor{Csrc<:Color}(::Type{TransparentColor}, ::Type{Csrc}) =
error("Ambiguous storage order, choose AlphaColor or ColorAlpha")
ccolor{C<:Color, Csrc<:Color}(
::Type{TransparentColor{C }}, ::Type{Csrc}) =
error("Ambiguous storage order, choose AlphaColor or ColorAlpha")
ccolor{C<:Color,T, Csrc<:Color}(
::Type{TransparentColor{C,T }}, ::Type{Csrc}) =
error("Ambiguous storage order, choose AlphaColor or ColorAlpha")
ccolor{C<:Color,T,N,Csrc<:Color}(
::Type{TransparentColor{C,T,N}}, ::Type{Csrc}) =
error("Ambiguous storage order, choose AlphaColor or ColorAlpha")
ccolor{Csrc<:TransparentColor}(::Type{TransparentColor}, ::Type{Csrc}) = Csrc
ccolor{Csrc<:Colorant}(::Type{AlphaColor}, ::Type{Csrc}) = alphacolor(Csrc)
ccolor{C<:Color, Csrc<:Colorant}(
::Type{AlphaColor{C }}, ::Type{Csrc}) = ccolor(alphacolor(C), Csrc)
ccolor{C<:Color,T, Csrc<:Colorant}(
::Type{AlphaColor{C,T }}, ::Type{Csrc}) = ccolor(alphacolor(C){T}, Csrc)
ccolor{C<:Color,T,N,Csrc<:Colorant}(
::Type{AlphaColor{C,T,N}}, ::Type{Csrc}) = ccolor(alphacolor(C){T}, Csrc)
ccolor{Csrc<:Colorant}(::Type{ColorAlpha}, ::Type{Csrc}) = coloralpha(Csrc)
ccolor{C<:Color, Csrc<:Colorant}(
::Type{ColorAlpha{C }}, ::Type{Csrc}) = ccolor(coloralpha(C), Csrc)
ccolor{C<:Color,T, Csrc<:Colorant}(
::Type{ColorAlpha{C,T }}, ::Type{Csrc}) = ccolor(coloralpha(C){T}, Csrc)
ccolor{C<:Color,T,N,Csrc<:Colorant}(
::Type{ColorAlpha{C,T,N}}, ::Type{Csrc}) = ccolor(coloralpha(C){T}, Csrc)
ccolor{ Csrc<:AbstractRGB}(::Type{AbstractRGB}, ::Type{Csrc}) = Csrc
ccolor{T,Csrc<:AbstractRGB}(::Type{AbstractRGB{T}}, ::Type{Csrc}) = base_colorant_type(Csrc){T}
# Generic concrete types
ccolor{Cdest<:Colorant,Csrc<:Colorant}(::Type{Cdest}, ::Type{Csrc}) = _ccolor(Cdest, Csrc, pick_eltype(Cdest, eltype(Cdest), eltype(Csrc)))
ccolor{Cdest<:AbstractGray,T<:Number}(::Type{Cdest}, ::Type{T}) = _ccolor(Cdest, Gray, pick_eltype(Cdest, eltype(Cdest), T))
_ccolor{Cdest,Csrc,T<:Number}(::Type{Cdest}, ::Type{Csrc}, ::Type{T}) = base_colorant_type(Cdest){T}
_ccolor{Cdest,Csrc}( ::Type{Cdest}, ::Type{Csrc}, ::Any) = Cdest
# Specific concrete types
ccolor{Csrc<:Colorant}(::Type{RGB24}, ::Type{Csrc}) = RGB24
ccolor{Csrc<:Colorant}(::Type{ARGB32}, ::Type{Csrc}) = ARGB32
ccolor{Csrc<:Colorant}(::Type{Gray24}, ::Type{Csrc}) = Gray24
ccolor{Csrc<:Colorant}(::Type{AGray32}, ::Type{Csrc}) = AGray32
pick_eltype{C,T1<:Number,T2<:Number}(::Type{C}, ::Type{T1}, ::Type{T2}) = T1
pick_eltype{C}(::Type{C}, ::Any, ::Any) = eltypes_supported(C)
if VERSION >= v"0.5.0-dev+755"
pick_eltype{C,T2<:Number}(::Type{C}, ::Any, ::Type{T2}) = issupported(C, T2) ? T2 : eltype_default(C)
else
@generated function pick_eltype{C,T2<:Number}(::Type{C}, ::Any, ::Type{T2})
issupported(C, T2) ? :(T2) : :(eltype_default(C))
end
end
and https://github.com/JuliaGraphics/ColorTypes.jl/blob/master/src/conversions.jl). At some point it will be interesting to rewrite it for the new capabilities.

@Keno
Copy link
Collaborator

Keno commented Jan 17, 2017

I have a work in progress for this package.

@Keno
Copy link
Collaborator

Keno commented Jan 17, 2017

@Keno
Copy link
Collaborator

Keno commented Jan 17, 2017

The last status was that I hit JuliaLang/julia#18457 (comment).

@timholy
Copy link
Member

timholy commented Jan 17, 2017

I also remember (I think) there being a number of places that could have benefited from triangular dispatch, which I think I worked around by expanding the number of arguments in several places. E.g.,

foo{C<:Colorant}(::Type{C}) = _foo(C, eltype(C))
# and now _foo can dispatch on both C and T where e.g. C = RGB{Float32}, T = Float32

@tlnagy
Copy link
Member

tlnagy commented Jan 21, 2017

Any progress on this? This breaks all dependent packages on 0.6 (including gadfly).

@juliohm
Copy link
Contributor

juliohm commented Jan 23, 2017

This is also breaking ImageQuilting.jl on Julia v0.6.

@SimonDanisch
Copy link
Member

this breaks basically everything :P

julia> Pkg.dependents("Colors")
50-element Array{AbstractString,1}:
 "Luxor"           
 "Images"          
 "ImageFiltering"  
 "VoronoiDelaunay" 
 "NamedColors"     
 "PlotUtils"       
 "VLFeat"          
 "Qwt"             
 "ProteinEnsembles"
 "Cairo"           
                  
 "QuartzImageIO"   
 "GraphPlot"       
 "ImageView"       
 "Brim"            
 "ColorBrewer"     
 "Winston"         
 "Caesar"          
 "FaceDatasets"    
 "Bio"             

@Keno
Copy link
Collaborator

Keno commented Jan 24, 2017

I have a branch of julia/ColorTypes that passes here. However, I'll be traveling for the rest of the week, so I'm not gonna be able to clean this up. So here's the deal: I'll put up what I have in it's messy state (over the next hour or so), but with what I believe are all the tricky issues worked out and somebody can pick it up and finish it off. Otherwise, I'll get to it next week. I also have a PR for FixedPointNumbers, which this depends on. Same deal.

@timholy
Copy link
Member

timholy commented Jan 24, 2017

Sounds good to me. I can't promise to get to it very quickly, but I might, and of course there seem to be other volunteers in this thread who could tackle it.

Maybe easiest if you push as a branch rather than a gist?

@Keno
Copy link
Collaborator

Keno commented Jan 24, 2017

Pushed as kf/06 here and as a PR on FixedPointNumbers. This also requires my kf/newreflection branch of Julia itself.

@lobingera
Copy link

@Keno Any idea what will happen with JuliaLang/julia#20006? Simon is unfortunately right: ColorTypes.jl breaks an awful lot of testing on 0.6

@timholy
Copy link
Member

timholy commented Jan 31, 2017

Looks like it's actively being worked on. These type-system issues aren't simple. You could disable testing on nightly if the failures really bother you.

@Keno
Copy link
Collaborator

Keno commented Jan 31, 2017

It's through review. I'll merge it as soon as it's green on CI. Looks like the latest set of changes broke sth.

@timholy
Copy link
Member

timholy commented Jan 31, 2017

That's awesome. Don't worry about the breakages, I can take a peek. Really appreciate your help on this.

@Keno
Copy link
Collaborator

Keno commented Jan 31, 2017

Sorry, what I meant was that my latest changes on that branch broke something in base, which I'll have to investigate. I did already rebase the new ColorTypes on top of the changes in base (but haven't pushed that yet).

@timholy
Copy link
Member

timholy commented Jan 31, 2017

OK, just ping here when all is set (I am too swamped to follow what's happening with the type-system stuff).

@SimonDanisch
Copy link
Member

just to better track the progress here, this is the PR we are waiting for:
JuliaLang/julia#20006

@juliohm
Copy link
Contributor

juliohm commented Feb 8, 2017

It looks like the PR was merged, this means that the issue is solved in master?

@tlnagy
Copy link
Member

tlnagy commented Feb 8, 2017 via email

@timholy
Copy link
Member

timholy commented Feb 9, 2017

Closed by #68 and #69.

@timholy timholy closed this as completed Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants