-
-
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
show for UnionAll types prints non-syntactic identifiers for unnamed type variables #34887
Comments
Oh, i see now that it's more complicated than I had thought; i didn't realize those generated names are part of the type, not part of printing: julia> Vector{<:Vector{<:Bool}}.var.name
Symbol("#s17") I'm not sure if it's important that these remain non-standard identifiers for some reason? If so, perhaps the simplest fix would just be to print these via |
Okay, just changing to print as I'd still prefer to change to nicer names, like |
I guess we can leave this open for somebody to make the identifiers nicer. |
From #34888 (comment):
Does it make sense to change the names inside the type vars themselves? Is there any harm in them overlapping? It doesn't seem like it. I tried poking around in the scheme, but couldn't quite find the right place to do it. :'( |
fixes JuliaLang#34887 typevars with gensym symbols will now be printed inlined for `UnionAll` type arguments if their type bounds allow to do so (i.e. `<:UB` or `>:LB`). typevars with named symbols are printed as before since they are assumed to carry meaning and thus might be helpful. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
fixes JuliaLang#34887 typevars in unionall type arguments can now be printed inlined if their type bounds allow to do so (e.g. `<:UB` or `>:LB`). typevars with named symbols are printed verbosely as before unless `:compact => true` is set in the IOContext. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
fixes JuliaLang#34887 typevars in unionall type arguments can now be printed inlined if their type bounds allow to do so (e.g. `<:UB` or `>:LB`). typevars with named symbols are printed verbosely as before unless `:compact => true` is set in the IOContext. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
fixes JuliaLang#34887 typevars in unionall type arguments can now be printed inlined if their type bounds allow to do so (e.g. `<:UB` or `>:LB`). typevars with named symbols are printed verbosely as before unless `:compact => true` is set in the IOContext. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
fixes JuliaLang#34887 typevars in unionall type arguments can now be printed inlined if their type bounds allow to do so (e.g. `<:UB` or `>:LB`) and they are not referenced from elsewhere in the type hierarchy. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
fixes JuliaLang#34887 typevars in unionall type arguments can now be printed inlined if their type bounds allow to do so (e.g. `<:UB` or `>:LB`) and they are not referenced from elsewhere in the type hierarchy. Before: julia> Ref{<:Any} Ref{var"#s2"} where var"#s2" julia> Ref{<:Ref{<:Ref}} Ref{var"#s1"} where var"#s1"<:(Ref{var"#s2"} where var"#s2"<:Ref) After: julia> Ref{<:Any} Ref julia> Ref{<:Ref{<:Ref}} Ref{<:Ref{<:Ref}}
Calling
Base.show()
withUnionAll
types with unnamed type parameters prints those type parameters with non-syntactic generated names:This of course cannot be evaluated, which can be difficult when trying to understand a very large type that's printed in an error message, for example.
My first thought was that this should be fixed following the same approach as in #32408: we should change these to print via the
var""
syntax, a la:That seems like a fine approach, but then I noticed that if the variable does have a name, the printing mechanism seems to be able to tweak the user-provided name to prevent conflicts with other identifiers in the type! This leads me to wonder if we can use that same smarts to just pick a standard identifier name, rather than a purposefully non-standard identifier as above?
For example, notice how the user-provided name
T
gets renamed toT1
when there's a conflict:Can we similarly have julia just pick some arbitrary type names like
p1
,p2
,pN
... orP1
,P2
, ... or_T1
,_T2
, etc, rather than the#s16
,#s17
type names we're using now? And then if there's a conflict with an actual user-provided name, it can just adjust the name like it already does?In fact, the existing mechanism already handles conflicts even for the generated names, so this should be a very easy change: just simplifying the generated names to be valid identifiers.
The text was updated successfully, but these errors were encountered: