-
-
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
Fix type-instability of ∘ and Some when wrapping types #35980
Conversation
base/operators.jl
Outdated
show(io, c.g) | ||
end | ||
|
||
show(io::IO, ::MIME"text/plain", c::ComposedFunction) = show(io, c) |
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 already a fallback for this.
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.
Without this, text/plain output is rather ugly:
julia> uppercase∘first
(::Base.ComposedFunction{typeof(uppercase),typeof(first)}) (generic function with 1 method)
I think this is due to show(io::IO, ::MIME"text/plain", f::Function)
.
But defining show
here was incorrect because MIME is not defined here. I moved it to show.jl where show(io::IO, ::MIME"text/plain", f::Function)
is defined.
With this definition, I get
julia> uppercase∘first
uppercase ∘ first
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, I was missing that it's a subtype of Function.
Yes I think this is a reasonable approach for now. For example we already do this for Generators. |
This is clearly and improvement for composed functions, but is it so clear for |
It is somewhat unfortunate that
Is type-stability not enough to justify the change? |
It looks fixing type instability of closure is hard (#35970). So, can we add a workaround for cases like
Float64 ∘ first
?fix #34849
I also added a similar fix for
Some
Before
After