-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make repr(::Ptr)
parsable Julia code.
#54305
Conversation
Out of curiosity, how does |
Good question julia> pointer(Int[])
Ptr{Int64} @0x0000fffed19aa550
julia> Base.delete_method(@which show(stdout, pointer([])))
julia> pointer(Int[])
Ptr{Int64}(0x0000fffed19aa550) |
I like this, but given the historical legacy the current behaviour has, I feel like somebody else should approve this PR. For what it's worth though, this LGTM. |
I'm torn on this - on one hand, the current printing annoyed me in the past when inspecting generated LLVM IR of a live session, on the other hand I don't really feel comfortable with having a copy-pasteable |
Two comments:
|
It gives the illusion that the value behind that pointer is alive, when that's not necessarily the case. Case in point - the cases where I tried to inspect generated LLVM IR of a live session more often than not led to me crashing my Julia session because the underlying object wasn't actually alive 😅 Since Julia is generally more high level than raw pointer wrangling, I think it's better to print raw pointers with some special representation.
Possibly? I don't know OTOH of all cases where the 3-arg method would be chosen over the 2-arg method. As an aside, I tried looking into the printing of this through the commit history. The current printing has been this way since 2010, the commit that introduced this is 18f4562, which also introduced the |
The reasoning for this is to make
The problem isn't that What you're talking about "we should show humans something special" seems much more appropriate as the 3-arg show:
|
Yes, I'm aware of that. My point is that it's sometimes really difficult to know when 2-arg vs. 3-arg actually happens, and reproducing/recreating pointers in particular like that is seldom a good idea in either case. Note that the docstring also states:
Implying that even 2-arg I don't mean to block this PR; as mentioned above, I'm torn on this and gave my reasoning for why so that a future person that does merge it has some additional input to consider. |
Yea, it is a bit of a mess. Particularly in usage, it seems that the delineation between parsable and pretty methods isn't clear. Multiple dispatch is great and all, but if we could time travel I almost wonder if it would have been better to have This said, I do think parsibility is worth prioritising, for cases like when a test fails and you want to copy-paste the value into the REPL to inspect the value (e.g. taking |
Right, for regular values I 100% unequivocally agree - but not for pointers, because those are invalid as soon as the object being pointed to is dead (which is almost assuredly the case when you inspect a test case involving pointers). Recreating the semantic that the It's the same reason why the |
Mmmm, a pointer may or may not still be "alive" depending on the particular situation, and so I see the motivation for doing something based on that. I don't think making the representation of anything with a pointer involved un-parsable is the right solution though. |
Yeah, at that point you might as well just hide the pointer value and show it as |
There is nothing "unsafe" about the bits of a pointer value. They do not have "liveness". If someone is doing calls to the "unsafe" functions, then those are what is unsafe and that is what should be avoided anyways. |
Right, the issue is that evaluating a string-representation from |
It seems to me that Timothy and I are in agreement that this is a good change, with Timothy's reason for wanting to hold of on merging before hearing more people's thoughts that someone added this method explicitly in the past. Sukera is hesitant because pointers can be used unsafely and Sukera thinks a good way to communicate that to users is to make their display representation unparsable, but doesn't want to block this PR. Jameson, Kristoffer, Timothy, and I all think that unparsability is not a good way to dissuade users form performing unsafe operations in this case, and Jameson further (correctly) noted that I see this as consensus to merge. [Edited based @Seelengrab's response] |
I object to the framing that I object - I have explicitly said that I don't mean to block this PR:
There's no need to frame this as a me-against-you kind of thing. Similarly, I don't claim that |
I simply changed the default display which also adjusts the "text/plain" representation. I did this because I don't think the current text/plain representation is any more canonical / human readable than this PR's display, so I don't think it warrants added display diversity. The on the wikipedia page, the
@
sign only appears in reference to BASIC syntax.