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

Should Union types record whether they came from a defining typealias? #18924

Closed
timholy opened this issue Oct 14, 2016 · 4 comments
Closed

Should Union types record whether they came from a defining typealias? #18924

timholy opened this issue Oct 14, 2016 · 4 comments

Comments

@timholy
Copy link
Member

timholy commented Oct 14, 2016

There's now a number of issues open for thoughts about how to make the printing of types more readable. Here's another notion: it would be nice if printing could replace Unions with appropriate typealiases. For example:

julia> methods(permutedims)
#2 methods for generic function "permutedims":
permutedims(B::Union{Base.ReshapedArray{T<:Any,N<:Any,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray{T<:Any,N<:Any},SubArray{T<:Any,N<:Any,A<:Union{Base.ReshapedArray{T<:Any,N<:Any,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray},I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex,Colon,Int64,Range{Int64}},N<:Any}},L<:Any}}, perm) at multidimensional.jl:959
permutedims{T,N}(A::AbstractArray{T,N}, perm) at permuteddimsarray.jl:47

But the first method is actually defined as permutedims(B::StridedArray, perm) which is rather simpler to read.

This is easy to point out, but actually implementing it seems likely to be hard starting from the jl_uniontype_t itself. Unless Union types get modified to record whether they come from a typealias.

@JeffBezanson
Copy link
Member

The printing code could search for globals === to a particular union type. We could potentially have an ObjectIdDict mapping unions to their "names". Not sure if that's necessary, but it could even be part of the lowering of typealias, giving that syntax a bit of extra value over const assignment.

Showing names for instantiations of these unions is of course harder, but after #8974 it will at least be possible to brute-force search globals for supertypes of a given union type.

@timholy
Copy link
Member Author

timholy commented Oct 14, 2016

I was worried that brute-force search would be too inefficient, but maybe we wouldn't typically have that many typealiases. JuliaMath/FixedPointNumbers.jl#51 exports a few hundred typealiases, but none of those are Unions.

@mbauman
Copy link
Member

mbauman commented Oct 14, 2016

Duplicate of #14946?

@timholy
Copy link
Member Author

timholy commented Oct 15, 2016

Yup.

@timholy timholy closed this as completed Oct 15, 2016
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

3 participants