Skip to content
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

Clarify what "no program" means in egal docs #54887

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ false
julia> a === a
true
```

# Extended help
It might be possible to construct a program that is actually able to distinguish
two egal values. For example, one could heap-allocate two integers,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is actually able to distinguish two egal values

I think this is not an idea formulation because the program doesn't actually distinguish two egal values.

then compare the value of a pointer pointing to their heap address.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to realize that example with "heap allocated integers".

How about talking about strings instead, were this is quite easy to demonstrate in practice? E.g.

julia> a = "x" ; b = "x" ; a === b
true

julia> pointer_from_objref.([a,b])
2-element Vector{Ptr{Nothing}}:
 Ptr{Nothing} @0x000000010cf60748
 Ptr{Nothing} @0x000000010cf60780

However, all such programs rely on observing behaviour outside Julia's allowed
semantics, and so happen to work due to implementation details and/or triggering
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this my first thought was: What are "Julia's allowed semantics", and where can I find out more.

I.e.: To me this doesn't clarify much. Mainly I am left with this message: "You can't distinguish egal values by the rules, which I am not telling you, just so you know: if you found a way it is cheating and you should not rely on it in any way."

But is that really helpful? Honest open question, I don't know. Since you opened the PR, presumably you feel this text (or at least parts of it) would have been helpful for you to know when you run into this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair summary. On the other hand, the current message is "you can't distinguish egal values", which is just false - you absolutely can, e.g. by comparing pointers to strings, as you did in the example above.
When I first read that docstring I tried the same thing as was confused - I then had to ask on Slack what was up with that. Since then, I've seen twice that people have asked the same question - those have been lost to the slack hole, but searching for the docstring of === on Discourse brings this post up, with the same question.
I.e. as I see it, the confusing thing is that the claim "you can't distinguish these two values with any program" appears superficially simple, but the statement's truth relies on complex language semantics which almost no user knows about.

So, I think either that statement should be removed from the docs, or else it should be properly explained what it means.
I would prefer explaining it, and possibly linking to the devdocs on UB which explains it in more detail.

undefined behaviour.
In the example, it is invalid to assume that a value on the heap has a single
unique pointer referencing it, and that any such pointer references no other value.
"""
===
const ≡ = ===
Expand Down