Skip to content

Commit

Permalink
Merge pull request #24651 from JuliaLang/rf/typeinfo
Browse files Browse the repository at this point in the history
IOContext: introduce the :typeinfo property
  • Loading branch information
rfourquet authored Dec 8, 2017
2 parents 1767963 + fe6709b commit 6eec805
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 428 deletions.
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)
print(io, ')')
end

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

0 comments on commit 6eec805

Please sign in to comment.