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

Conversation

jakobnissen
Copy link
Contributor

While the statement in the docstring is correct, it relies on an idiosyncratic definition of "no program", referencing Julia's semantics. Occasionally, a Julia user will point out that they can actually write a program that can distinguish two egal values.
This commit clarifies that while such programs may work, they rely on going outside the language's semantics.

While the statement in the docstring is correct, it relies on an idiosyncratic
definition of "no program", referencing Julia's semantics.
Occasionally, a Julia user will point out that they can actually write a program
that can distinguish two egal values.
This commit clarifies that while such programs may work, they rely on going outside
the language's semantics.
@ViralBShah ViralBShah added the docs This change adds or pertains to documentation label Jun 22, 2024
# 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,
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


# 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.

two egal values. For example, one could heap-allocate two integers,
then compare the value of a pointer pointing to their heap address.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants