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

IOContext: introduce the :typeinfo property #24651

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 487 additions & 0 deletions base/arrayshow.jl

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions base/grisu/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,21 @@ function Base.show(io::IO, x::Union{Float64,Float32})
if get(io, :compact, false)
_show(io, x, PRECISION, 6, x isa Float64, true)
else
_show(io, x, SHORTEST, 0, true, false)
_show(io, x, SHORTEST, 0, get(io, :typeinfo, Any) !== typeof(x), false)
end
end

function Base.show(io::IO, x::Float16)
if get(io, :compact, false)
hastypeinfo = Float16 === get(io, :typeinfo, Any)
# if hastypeinfo, the printing would be more compact using `SHORTEST`
# while still retaining all the information
# BUT: we want to print all digits in `show`, not in display, so we rely
# on the :compact property to make the decision
# (cf. https://github.com/JuliaLang/julia/pull/24651#issuecomment-345535687)
if get(io, :compact, false) && !hastypeinfo
_show(io, x, PRECISION, 5, false, true)
else
_show(io, x, SHORTEST, 0, true, false)
_show(io, x, SHORTEST, 0, !hastypeinfo, false)
end
end

Expand Down
6 changes: 2 additions & 4 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,6 @@ precompile(Tuple{typeof(Base.indexed_next), Tuple{Array{Int64, 1}, Void}, Int64,
precompile(Tuple{typeof(Base.setdiff), Array{Int64, 1}, Array{Int64, 1}})
precompile(Tuple{typeof(Base.Multimedia.display), Array{Int64, 1}})
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}, Int64})
precompile(Tuple{typeof(Base.array_eltype_show_how), Array{Int64, 1}})
precompile(Tuple{typeof(Base.summary), Array{Int64, 1}, Tuple{Base.OneTo{Int64}}})
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}, Int64, Int64})
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}})
Expand All @@ -1608,9 +1607,8 @@ precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal},
precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal}, String, String})
precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal}, String, String, Char})
precompile(Tuple{typeof(Base.show_vector), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String, String})
precompile(Tuple{typeof(Base.print_matrix_repr), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
precompile(Tuple{typeof(Base.show_nd), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, typeof(Base.print_matrix_repr), Bool})
precompile(Tuple{typeof(Base.repremptyarray), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
precompile(Tuple{typeof(Base._show_nonempty), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String})
precompile(Tuple{typeof(Base._show_empty), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
precompile(Tuple{typeof(Base.print_matrix), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String, String, String})
precompile(Tuple{typeof(Base.getindex), Base.ImmutableDict{Symbol, Any}, Symbol})
precompile(Tuple{typeof(Base.vcat), Base.OneTo{Int64}})
Expand Down
4 changes: 2 additions & 2 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function show(io::IO, ::MIME"text/plain", t::Task)
end
end

show(io::IO, ::MIME"text/plain", X::AbstractArray) = showarray(io, X, false)
show(io::IO, ::MIME"text/plain", X::AbstractArray) = _display(io, X)
show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges

# display something useful even for strings containing arbitrary
Expand All @@ -146,7 +146,7 @@ function show(io::IO, ::MIME"text/plain", s::String)
show(io, s)
else
println(io, sizeof(s), "-byte String of invalid UTF-8 data:")
showarray(io, Vector{UInt8}(s), false; header=false)
print_array(io, Vector{UInt8}(s))
end
end

Expand Down
11 changes: 3 additions & 8 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ similar(s::Set{T}) where {T} = Set{T}()
similar(s::Set, T::Type) = Set{T}()

function show(io::IO, s::Set)
print(io, "Set")
if isempty(s)
print(io, "{", eltype(s), "}()")
return
end
print(io, "(")
show_vector(io, s, "[", "]")
print(io, ")")
print(io, "Set(")
show_vector(io, s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we have print_array but show_vector?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not good at naming, and I forged them on top of what was existing, but the print_array work for any array, while show_vector is a special method implemented only for 1-D collections, which is meant (as this example show) to be used beyond the array case. I just didn't change the original name for this one, and I can't think of a clearly better one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the discrepancy between "show" and "print" is weird, unless there's a reason for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean in those two lines? there I just kept it how it was, and showing a String will print the quotes. But you refered to print_array, which is just an internal name basically implementing the logic of display, so it's not so important (print_array comes from the pre-existing print_matrix function). Sorry I'm still not clear exactly what you think should be changed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I thought you had renamed one of them. Carry on...

print(io, ')')
end

isempty(s::Set) = isempty(s.dict)
Expand Down
Loading