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

Functions / closures are not Hashable #167

Closed
rakudrama opened this issue Oct 18, 2011 · 15 comments
Closed

Functions / closures are not Hashable #167

rakudrama opened this issue Oct 18, 2011 · 15 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@rakudrama
Copy link
Member

I have a program that walks a datastructure that contains various objects including functions and needs to detect if the same object / function (f1 === f2) occurs twice.

I can't do this with HashMap for several reasons:

  1. Closures don't implement Hashable and don't have a hashCode() method.
  2. Even if they did, some objects that do implement Hashable also implement ==, but I want to hash on object identity, not object-defined equivalence.

I would be happy with
(a) A HashMap that takes the hash function and equivalence as a parameter
(b) a way of generating a hash code for closures.

@DartBot
Copy link

DartBot commented Oct 20, 2011

This comment was originally written by [email protected]


Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Oct 20, 2011

Set owner to @gbracha.
Added Accepted label.

@DartBot
Copy link

DartBot commented Apr 20, 2012

This comment was originally written by [email protected]


This would be very useful when implementing observable objects.

@anders-sandholm
Copy link
Contributor

Added apr30-triage label.

@anders-sandholm
Copy link
Contributor

Removed apr30-triage label.

@anders-sandholm
Copy link
Contributor

Added triage1 label.

@anders-sandholm
Copy link
Contributor

Removed triage1 label.
Added Duplicate label.
Marked as being merged into #144.

@gbracha
Copy link
Contributor

gbracha commented May 29, 2012

Resurrecting this as a library question, since 144 of which this was considered a duplicate) is closed.


Removed Area-Language label.
Added Area-Library, Triaged labels.
Marked as being merged into #.

@gbracha
Copy link
Contributor

gbracha commented May 29, 2012

Removed the owner.

@lrhn
Copy link
Member

lrhn commented Jun 14, 2012

The request is for either
 1. Making closures hashable
 2. Adding a way to create a hash for any object (aka. identityHash) and make HashSet/Map able to use an external hash/equality strategy instead of using the objects' own hashCode and operator==.

I agree that making the Hash-containers able to take a strategy is a good idea.
I would like an identityHash function, but it's important that it doesn't affect performance on the VM if you don't use it, and not too much if you do use it.

I would prefer these two to just making closures Hashable, since it's a more general solution.

@DartBot
Copy link

DartBot commented Jun 29, 2012

This comment was originally written by @bgourlie


It seems this issue is making it difficult to implement a sane model for user-defined events.

@larsbak
Copy link

larsbak commented Aug 14, 2012

We should make closures hashable and provide an easy to understand equals behavior.
There are three forms of closures:

  1. From static methods. Since closures from static methods are canonicalized, identity check can be used for equality. Hash code should be identity hash code.
  2. From instance methods. These closures are in essence pairs (method, this). Here the hash code can be computed from identity hash codes for "method" and "this". For equality we simply check methods and receivers match.
  3. From inner functions. Use identity hash for hash code and identity check for equality. Any refinement in this area is hard to specify since it will depend on what in the lexical scope is being captured by the closure.

This in turn will make it possible to solve the problem with removing event handlers in the DOM without language guarantees for canonicalizing closures from instance methods.

@DartBot
Copy link

DartBot commented Aug 14, 2012

This comment was originally written by [email protected]


To be clear about #­2: if I have a type that overrides the equality operator, with instances 'a' and 'b' where a == b, would 'a.someMethod' compare equal to 'b.someMethod'? I'm guessing no, but clarity is good.

@sethladd
Copy link
Contributor

I believe that a recent language review meeting decided that all objects shall be hashable. If so, this might now be a language issue.


Set owner to @gbracha.
Removed Area-Library label.
Added Area-Language label.

@sethladd
Copy link
Contributor

Added Duplicate label.
Marked as being merged into #3369.

@rakudrama rakudrama added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report labels Aug 27, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
copybara-service bot pushed a commit that referenced this issue Nov 28, 2022
Revisions updated by `dart tools/rev_sdk_deps.dart`.

ffi (https://github.com/dart-lang/ffi/compare/3ede231..17a8142):
  17a8142  2022-11-21  Daco Harkes  Add links to API reference and examples to README (#167)

fixnum (https://github.com/dart-lang/fixnum/compare/bca3816..62916f2):
  62916f2  2022-11-24  Lasse R.H. Nielsen  Split into separate libraries instead of using parts. (#97)
  14d4827  2022-11-23  Lasse R.H. Nielsen  Add `tryParse` methods. (#96)

http (https://github.com/dart-lang/http/compare/d56141d..047d6ed):
  047d6ed  2022-11-22  Brian Quinlan  Fixes a bug where requests made in different Clients would fail (#827)
  9dbbafb  2022-11-17  Brian Quinlan  Add tests for compressed responses (#823)

markdown (https://github.com/dart-lang/markdown/compare/37951d1..ee3f4e9):
  ee3f4e9  2022-11-24  Zhiguang Chen  Fix a blockquote issue (#496)
  c9048c0  2022-11-16  Zhiguang Chen  Optimise DelimiterSyntax (#492)

protobuf (https://github.com/dart-lang/protobuf/compare/ae90e53..c181573):
  c181573  2022-11-23  Kevin Moore  [api_benchmark] migrate to null-safety (#776)
  648deaf  2022-11-23  Kevin Moore  Standardize and fix lints (#775)
  bfa4c0d  2022-11-23  Kevin Moore  Fix `///` at the top of generated Dart files (#774)
  ed68426  2022-11-17  Devon Carew  Remove duplicate consts (#773)

sse (https://github.com/dart-lang/sse/compare/283568d..8d018dd):
  8d018dd  2022-11-23  Elliott Brooks (she/her)  Format markdown files (#68)
  2f6f151  2022-11-23  Elliott Brooks (she/her)  Add optional `debugKey` parameter to SSE client (#67)
  eaee6a8  2022-11-23  Elliott Brooks (she/her)  Use Fetch API in SSE Client (#66)

test (https://github.com/dart-lang/test/compare/7756833..b25dac9):
  b25dac99  2022-11-21  Kevin Moore  checks: finish async tests (#1793)
  3166163e  2022-11-18  Devon Carew  Update scorecards-analysis.yml (#1792)
  d930d5b0  2022-11-18  Nate Bosch  Add support for async soft checks (#1789)
  b1411a21  2022-11-18  Devon Carew  blast_repo fixes (#1788)
  a6aa04e0  2022-11-18  Jacob MacDonald  disable wasm tests for now as they are failing (#1791)
  8b5174c1  2022-11-17  Kevin Moore  Starting on async tests (#1787)

Change-Id: Ic361fce7753d08d43fc827f13cb1bfa1738cc16e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272343
Auto-Submit: Devon Carew <[email protected]>
Reviewed-by: Kevin Moore <[email protected]>
Commit-Queue: Devon Carew <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 6, 2023
…ev, boolean_selector_rev, browser_launcher_rev, characters_rev, cli_util_rev, clock_rev, collection_rev, convert_rev, crypto_rev, csslib_rev

Revisions updated by `dart tools/rev_sdk_deps.dart`.

args (https://github.com/dart-lang/args/compare/a23ea85..bd3ac85):
  bd3ac85  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#234)
  86dacb3  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#233)

async (https://github.com/dart-lang/async/compare/f700e9a..8deaa40):
  8deaa40  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#234)
  b28604f  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#233)

bazel_worker (https://github.com/dart-lang/bazel_worker/compare/b35c25e..1124692):
  1124692  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#67)
  1e57757  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#68)

benchmark_harness (https://github.com/dart-lang/benchmark_harness/compare/76881df..b1efcf7):
  b1efcf7  2023-02-02  Devon Carew  add a publishing workflow action to dart-lang/benchmark_harness (#81)
  4e0c4e8  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#83)
  010ea89  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#82)

boolean_selector (https://github.com/dart-lang/boolean_selector/compare/ba7d86b..16e6ad3):
  16e6ad3  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#42)
  c8874cc  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#43)

browser_launcher (https://github.com/dart-lang/browser_launcher/compare/f2f01e4..bc2dc4e):
  bc2dc4e  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#38)
  00a57fa  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#39)

characters (https://github.com/dart-lang/characters/compare/4526aa8..29f3a3e):
  29f3a3e  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#73)
  6516030  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#74)

cli_util (https://github.com/dart-lang/cli_util/compare/32bc077..fd38b5f):
  fd38b5f  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#74)
  166fbac  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#75)

clock (https://github.com/dart-lang/clock/compare/65e8a13..5abb481):
  5abb481  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#43)
  11b18ed  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#44)

collection (https://github.com/dart-lang/collection/compare/a566328..0d0e184):
  0d0e184  2023-02-01  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#268)
  d0897af  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#269)

convert (https://github.com/dart-lang/convert/compare/20d136c..83886e3):
  83886e3  2023-02-01  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#75)
  a522506  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#74)

crypto (https://github.com/dart-lang/crypto/compare/f854f2f..03eb2c9):
  03eb2c9  2023-01-31  dependabot[bot]  Bump actions/checkout from 3.2.0 to 3.3.0 (#139)
  b6d6b33  2023-01-31  dependabot[bot]  Bump dart-lang/setup-dart from 1.3 to 1.4 (#140)

csslib (https://github.com/dart-lang/csslib/compare/f33d632..e6c8308):
  e6c8308  2023-01-31  Devon Carew  fix the reported span for expressions (#167)
  a190358  2023-01-31  Devon Carew  add a repro for #136 (#160)
  fa3e221  2023-01-31  Devon Carew  correct the logic in isPredefinedName (#166)

Change-Id: I68bc236d4e0b5c31b5d629f2b89f82f56d30a28e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281260
Auto-Submit: Devon Carew <[email protected]>
Commit-Queue: Nate Bosch <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
copybara-service bot pushed a commit that referenced this issue Sep 14, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

ecosystem (https://github.com/dart-lang/ecosystem/compare/e96fbdb..babf5d1):
  babf5d1  2023-09-13  Devon Carew  add additional lints to dart_flutter_team_lints (#167)
  7740bef  2023-09-13  Moritz  Write comments on forks for `firehose` (#165)

http (https://github.com/dart-lang/http/compare/de19214..e19094a):
  e19094a  2023-09-14  Brian Quinlan  Use efficient operations when copying bytes between Dart and Java (#1019)
  d7e4375  2023-09-13  Parker Lougheed  Cleanup `package:http` utils (#1011)
  eafbbb0  2023-09-12  Brian Quinlan  Separate the cronet callbacks from the `send` method (#1017)
  2cbb703  2023-09-12  Brian Quinlan  Switch `cronet_http` to use jnigen (#1016)

native (https://github.com/dart-lang/native/compare/bbcbc1f..7faf62c):
  7faf62c  2023-09-14  Gabriel Terwesten  Add `includes`, `flags`, `std`, `language`, `cppLinkStdLib` options (#125)

shelf (https://github.com/dart-lang/shelf/compare/2926f76..e2a02b7):
  e2a02b7  2023-09-13  Kevin Moore  Move to latest pkg:dart_flutter_team_lints, bump min sdk to Dart 3 (#378)

tools (https://github.com/dart-lang/tools/compare/fa01f9b..1512f3d):
  1512f3d  2023-09-13  Elias Yishak  Add Fake Analytics instance that uses list to save events sent (#149)

webdev (https://github.com/dart-lang/webdev/compare/6b21ecf..501ccc2):
  501ccc28  2023-09-12  Elliott Brooks  Update DCM triggers to match Dart DevTools (#2230)

Change-Id: Ic3dc1924da48454a28e4c0d8705244ac1565e74a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325967
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Devon Carew <[email protected]>
copybara-service bot pushed a commit that referenced this issue Oct 31, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

lints (https://github.com/dart-lang/lints/compare/2cf8403..5c60f48):
  5c60f48  2023-10-30  Michael Goderbauer  Update README.md to use new syntax for adding dev dependencies (#167)

mockito (https://github.com/dart-lang/mockito/compare/4edf86f..b7d752e):
  b7d752e  2023-10-26  Ilya Yanok  Use Dart SDK 3.1.0 for format check
  ca537db  2023-10-26  Ilya Yanok  Remove unneeded deprecation warning disable comment
  1a0d0e7  2023-10-26  Ilya Yanok  Remove deprecated `returnNullOnMissingStub` and `OnMissingStub.returnNull`

native (https://github.com/dart-lang/native/compare/757f503..279094d):
  279094d  2023-10-30  Pierrick Bouvier  [native_toolchain_c] Support MSVC arm64 toolchain (#167)
  9629a55  2023-10-27  Parker Lougheed  Allow modification of a BuildOutput's raw dependencies (#169)
  762b4da  2023-10-27  Ryan Macnak  [native_assets_cli] Add Android RISCV64 target. (#166)
  18bff8c  2023-10-25  Ryan Macnak  [native_toolchain_c] Setup Linux X64 toolchain for non-X64 hosts. (#164)
  d79a7cd  2023-10-25  Ryan Macnak  [native_toolchain_c] Setup Linux RISCV64 toolchain. (#163)
  ce26f75  2023-10-25  Parker Lougheed  Update all lints and dart_flutter_team_lints dependencies (#161)

protobuf (https://github.com/dart-lang/protobuf/compare/3528fad..3f567b2):
  3f567b2  2023-10-27  Ömer Sinan Ağacan  Remove the dynamic call in `CodedBufferWriter` (#895)
  42436cd  2023-10-26  Ömer Sinan Ağacan  Keep a `ByteData` around in `CodedBufferReader` to avoid repeated `ByteData` allocs (#890)
  9a73936  2023-10-26  Ömer Sinan Ağacan  Avoid adding empty splices in `CodedBufferWriter` (#886)
  23dffde  2023-10-26  Ömer Sinan Ağacan  Update a bug link in a comment (#892)
  19903f0  2023-10-26  Ömer Sinan Ağacan  Make `CodedBufferWriter.writeRawByte` argument type more accurate (#891)
  2ce3e14  2023-10-26  Ömer Sinan Ağacan  Update `FieldInfo._ensureRepeatedField` return type (#893)
  e146515  2023-10-25  Ömer Sinan Ağacan  Avoid redundant ByteData allocation when decoding sfixed64 (#889)
  1b1d549  2023-10-25  Ömer Sinan Ağacan  Avoid allocating temporary views in when decoding strings in `CodedBufferReader` (#888)

tools (https://github.com/dart-lang/tools/compare/da6bb18..e828d45):
  e828d45  2023-10-27  Elias Yishak  Create tests for each event constructor (#186)

webdev (https://github.com/dart-lang/webdev/compare/25f17cd..50534a1):
  50534a12  2023-10-30  Elliott Brooks  Cider passes an app ID instead of a workspace name to connect to the Dart Debug Extension (#2272)
  b3d6ef14  2023-10-27  Elliott Brooks  Expose a keyboard shortcut to copy the Dart app ID (#2271)
  c26b4e5f  2023-10-27  Elliott Brooks  Reset Webdev to 3.3.0-wip after release (#2269)
  982b955b  2023-10-26  Elliott Brooks  Prepare webdev for 3.2.0  (#2268)
  62361fbf  2023-10-26  Elliott Brooks  Reset DWDS after release (#2267)
  50b8ae86  2023-10-26  Elliott Brooks  Prepare DWDS for release to version 22.1.0 (#2266)

Change-Id: Ia02db3bc66bac55b637ed5e173fe5c5d50bcca52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332748
Auto-Submit: Devon Carew <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

8 participants