-
-
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
make printing of typealias env shorter using {<:T}
syntax, when possible
#39395
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I must have missed the has_typevar
intrinsic back when I tried to do this. Avoiding additional io context keys using the mutable wheres
is probably good too. It seems solid from my quick tests.
It would be nice if Ref{T} where T
and Ref{X} where X
both printed consistently, though I guess this requires non-trivial changes in how you build orig
for show_typeparams
.
elide = length(wheres) | ||
for i = n:-1:1 | ||
p = env[i] | ||
if p isa TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe reduce nesting: p isa TypeVar || continue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an else clause, so this is the right structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see this is the other loop. The reason is still the same though (keeping the general structure of the two loops in common)
base/show.jl
Outdated
elide -= 1 | ||
elseif p.lb === Union{} && show_can_elide(p, wheres, elide, env, i) | ||
elide -= 1 | ||
elseif p.ub === Any && show_can_elide(p, wheres, elide, env, i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can merge with Union{}
branch
7eed6f2
to
6ae1bb2
Compare
I agree those should do the same (as did CI). I've used the new |
I think we should put back the gensym heuristic; i.e. still print |
Inspired by #35710 Co-authored-by: Stephan Hilb <stephan@ecshi.net>
6ae1bb2
to
a2e7b46
Compare
Okay, top example is now:
with added gensym ( |
a2e7b46
to
e593839
Compare
Thinking to merge this tomorrow, since I haven't heard any concerns with this now |
I actually prefer the more aggressively normalized original form. It's easier to see what's happening, IMO. Parameter names aren't significant after all, so eliminating where possible seems good. |
There's some cases were readability was slightly lower. Like hiding parameter names to functions too–they are not a significant part of the call, but they can be useful. However, as Jeff mentioned, it is also slightly more preferable to print an egal copy when feasible. I still think we should merge this now, but partly because we can still easily make that choice later after getting some experience with this. |
Fair enough, although I think we should probably make a decision before 1.7 to minimize the number of disruptive changes to printing. Although otoh maybe it's good to get people to stop testing exact printing of types. |
We've made more drastic changes than this is in 1.5 and 1.6 already, so hopefully that's already having an influence 😬 |
Cool, thanks! :) |
Inspired by #35710, including taking the tests (though not any of the implementation) from there. Unlike the original PR, this also prefers the short form (eliding the TypeVar name), even in case where it is not a gensym.
Github: this closes #35710 and fixes #34887