Skip to content
Closed
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
12 changes: 12 additions & 0 deletions base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ function sym_to_string(sym)
end

function show(io::IO, m::Method)
is_opaque_closure_method(m) && return show_method_with_pointer(io, m)
tv, decls, file, line = arg_decl_parts(m)
sig = unwrap_unionall(m.sig)
if sig === Tuple
Expand Down Expand Up @@ -297,6 +298,17 @@ end
show(io::IO, ms::MethodList) = show_method_table(io, ms)
show(io::IO, mt::Core.MethodTable) = show_method_table(io, MethodList(mt))

function is_opaque_closure_method(m::Method)
sig = unwrap_unionall(m.sig)
return sig === Tuple && m.name === Symbol("opaque closure")
# ASK: what is the proper way to detect opaque closure?
end

function show_method_with_pointer(io::IO, m::Method)
hexstr = string(UInt(pointer_from_objref(m)), base = 16, pad = Sys.WORD_SIZE>>2)
print(io, m.name, " @0x", hexstr, " in ", m.module)
end

function inbase(m::Module)
if m == Base
true
Expand Down
3 changes: 3 additions & 0 deletions test/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ mk_va_opaque() = @opaque (x...)->x
# OpaqueClosure show method
@test repr(@opaque x->1) == "(::Any)::Any->◌"

# Opaque closure method show method
@test contains(repr((@opaque x->1).source), "opaque closure @0x")

# Opaque closure in CodeInfo returned from generated functions
function mk_ocg(args...)
ci = @code_lowered const_int()
Expand Down