Skip to content

Include address in opaque method's show output #39780

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

Closed
wants to merge 1 commit into from

Conversation

tkf
Copy link
Member

@tkf tkf commented Feb 22, 2021

This PR tweaks show for Opaque Closure method to include the address.

Before:

julia> (Base.Experimental.@opaque () -> 123).source
opaque closure(...) in Main

After:

julia> (Base.Experimental.@opaque () -> 123).source
opaque closure @0x00007fb20cb211f0 in Main

julia> m = Base.unsafe_pointer_to_objref(Base.reinterpret(Ptr{Cvoid}, 0x00007fb20cb211f0))
opaque closure @0x00007fb20cb211f0 in Main

julia> Base.uncompressed_ir(m)
CodeInfo(
    @ REPL[7]:1 within `opaque closure'
1 ─     return 123
)

This is something I find it useful in #39773 while hacking with Opaque Closures. So, I thought it might make sense to extract it out from #39773.

This PR lets us see the pointer to Opaque Closure in :new_opaque_closure IR so that the body of Opaque Closure can be revealed by m = Base.unsafe_pointer_to_objref(Base.reinterpret(Ptr{Cvoid}, $THE_ADDRESS)) (as in the example above and in #39773). This is handy when you want to know what is happening inside the Opaque Closure.

I just realized that @Keno is already started working on introspection for Opaque Closures with Cthulhu.jl JuliaDebug/Cthulhu.jl#126. But maybe it's also nice to have a very "low tech" way to get Opaque Closure methods?

@tkf tkf requested a review from Keno February 22, 2021 04:06
@Keno
Copy link
Member

Keno commented Feb 22, 2021

We do need identity for these methods, but i don't think this is the way to go about it. We don't really ever expose the internal address of an object in regular show output and this doesn't seem like it should warrant an exception.

@tkf
Copy link
Member Author

tkf commented Feb 22, 2021

This is for introspection and all about seeing the guts. IIUC, since the user is not supposed to touch the fields of opaque closure, there is no way to get to opaque closure method using the public API. So, I don't think this PR exposes anything at API level. Also, we do see pointers all over the places in @code_llvm and I feel there is no particular reason why it cannot happen in @code_typed. Both of these interfaces already reveal internal details.

That said, I'm totally fine with closing this PR if you think it's not the right way to do it.

@Keno
Copy link
Member

Keno commented Feb 22, 2021

Yeah, I don't think this is the way to do it. We'll need some form of identity for these, but pointers are too unstable. We don't really want printout to keep changing if nothing about the structure changed. You've just jumped onto these too quickly before they're fully fleshed out ;).

@Keno Keno closed this Feb 22, 2021
@tkf tkf deleted the tkf/show-opaque-closure branch February 22, 2021 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants