-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use typealiases in method printing? #14946
Comments
a couple of things that would make this one slightly less horrible but are much easier to do right now :
the general problem of which type alias to pick for a given expanded type is as you say much harder |
an infix version (using unicode ?) of Union{} would also help but I feel this will be more controversial |
+1. I've thought/wanted this several times. Right now, it seems that the typealias expansion happens immediately; I wonder if it would make sense or even be possible to do the expanding at a later time, like only for compilation or something. |
I think there is a special case in the |
This is a dream of mine too, as it would make JuMP errors much more succinct |
For simple (non-parametric) type aliases, we could just have a hash table from the expanded type back to the alias name. But for parametric types it's not so simple. There's also the issue that the same type can have various different names and we could end up printing a different/confusing one. The only approach that seems like it would do what one expects is to remember how the type name was spelled at method definition and use that specific spelling when printing things. |
Worth pointing out that saving some variant of the source text would be an alternative way of solving this. Demo: julia> using LinearAlgebra, CodeTracking, Revise
julia> Revise.track(LinearAlgebra)
julia> m = @which eigen!(rand(3,3));
julia> ex = definition(m);
julia> ex.args[end].args[1]
:(eigen!(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true, sortby::Union{Function, Nothing}=eigsortby) where T <: BlasReal) |
I think this was fixed by #36107. |
I'd like to request some speculative brain cells spent on how we print method signatures to the REPL.
Currently, we expand out all typealiases. While this policy has the advantage of producing unambiguous output, the composition of type aliases through type parameters leads to combinatorially long string representations.
A particularly egregious example in Base is
eigfact!
:I estimate that only three people in the world can read the first method signature and immediately recognize that the original calling signature was
and it would take an eagle eye to realize that the first method takes one argument whereas the other two take two inputs each.
It would be much nicer to print something like the original method signature instead of feeling overwhelmed by C++ expression template-like verbal diarrhea. It's clear, though, that the additional bookkeeping of typealiases and matching of typealiases to method signatures is a hard problem.
The text was updated successfully, but these errors were encountered: