Skip to content

Commit

Permalink
Make repr(::Ptr) parsable Julia code. (#54305)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner committed May 9, 2024
1 parent d543508 commit 72e5525
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 0 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,6 @@ show(io::IO, n::Signed) = (write(io, string(n)); nothing)
show(io::IO, n::Unsigned) = print(io, "0x", string(n, pad = sizeof(n)<<1, base = 16))
print(io::IO, n::Unsigned) = print(io, string(n))

show(io::IO, p::Ptr) = print(io, typeof(p), " @0x$(string(UInt(p), base = 16, pad = Sys.WORD_SIZE>>2))")

has_tight_type(p::Pair) =
typeof(p.first) == typeof(p).parameters[1] &&
typeof(p.second) == typeof(p).parameters[2]
Expand Down
6 changes: 5 additions & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ end
repr == "Union{String, $(curmod_prefix)M30442.T}"
end
let repr = sprint(dump, Ptr{UInt8}(UInt(1)))
@test repr == "Ptr{UInt8} @$(Base.repr(UInt(1)))\n"
@test repr == "Ptr{UInt8}($(Base.repr(UInt(1))))\n"
end
let repr = sprint(dump, Core.svec())
@test repr == "empty SimpleVector\n"
Expand Down Expand Up @@ -2695,6 +2695,10 @@ let lowered = Meta.lower(Main, Expr(:let, Expr(:block), Expr(:block, Expr(:tople
@test contains(sprint(show, ci), "_1 = 1")
end

# Pointers should be reprable
@test is_juliarepr(pointer([1]))
@test is_juliarepr(Ptr{Vector{Complex{Float16}}}(UInt(0xdeadbeef)))

# Toplevel MethodInstance with undef :uninferred
let topmi = ccall(:jl_new_method_instance_uninit, Ref{Core.MethodInstance}, ());
topmi.specTypes = Tuple{}
Expand Down

0 comments on commit 72e5525

Please sign in to comment.