-
Notifications
You must be signed in to change notification settings - Fork 323
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
All Enso objects are hasheable #3878
Conversation
bb75b62
to
7e1c03f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the proposal, Pavel! Finally something material to base our discussion on.
One of my suggestions is to separate API from SPI. In Java hashCode
is both - something to call & something to override - that's wrong as it doesn't allow the language/runtime enforce any behavior of the SPI. I'd like to avoid that and thus I am proposing to remove Any.hash_code
.
However, according to @kustosz, we want people to override Any.==
as well as hash_code
in some situations. Marcin suggested to have compute_hash_code
method - OK, that would mean - if a Type
finds there is compute_hash_code
method defined in it, then it calls it from Meta.hash_code
rather than computing the default value.
In both cases the once computed hash_code
shall be cached in the Atom
.
I suggest to get more feedback from involved parties and then evolve the proposal a bit. In any case thanks a lot for starting this PR. It is great to see real (hash) code!
...runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/GetHashCodeNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/Atom.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/Atom.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/Atom.java
Outdated
Show resolved
Hide resolved
Based on the feedback in this PR I prepared an inception review document please take a look and modify it/add comments here, etc. My current feeling is that we could split the work into three (or even more) independent PRs and deliver this piece by piece. |
@JaroslavTulach FYI: I modified the PR so that it is more in line with the current idea of hashing - added
|
# Conflicts: # engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Type.java
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Hash_Map.enso
Outdated
Show resolved
Hide resolved
53af48e
to
2381712
Compare
There is a windows engine failure probably related to ordering of keys in a map:
|
There is a failure in Visualization tests - probably we can modify the test to accept the values in any order.
|
668684d
to
52bad4e
Compare
Failures in Table tests:
Probably not related to Pavel's code, but to some infrastructure problem. CCing @mwu-tow. |
It could be related to maps. It is failing in |
19c6cb4
to
1085f66
Compare
@JaroslavTulach @Akirathan |
Turns out that this issue is, indeed, caused by my changes. I tried logging how I manipulate with
|
8b7979b
to
060650a
Compare
Last(?) failure on windows:
you need to shield the python tests by a check for a presence of that language. |
java_props.remove pair.first | ||
case pair.second of | ||
Nothing -> Polyglot.invoke java_props "remove" [pair.first] | ||
_ -> Polyglot.invoke java_props "setProperty" [pair.first, pair.second] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am glad the Polyglot.invoke
works and workarounds the perception of java.util.Properties
being a Map
.
Pull Request Description
Implement
hash_code
for all Enso objects.Map
is now a builtin type with a proper hash map implementation. This PR is a follow-up of Convert Any.== to a builtin PR.Important Notes
Map
implementation with proper hash map implementation.Map
, except for:to_vector
no longer returns vector sorted by keyskeys
returns unsorted vectorfirst
andlast
methods are removedMap
supports any object as keys - primitives, atoms, polyglot values, another maps, ...java.util.Map
, etc.) are treated as Enso maps seamlessly, just how foreign arrays are treated.o1
,o2
: ifo1 == o2
thenhash(o1) == hash(o2)
and ifhash(o1) != hash(o2)
theno1 != o2
.ValueGenerator
.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.