- Notifications
You must be signed in to change notification settings - Fork3.1k
Mix in theproductPrefix hash statically in case classhashCode#11023
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lrytz commentedMar 20, 2025
The attemt to keep Not sure if that's a big issue... |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
classOf[C].getName instead ofproductPrefix in casehashCodeproductPrefix hash statically in case classhashCodeUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
11b1efa to37a12baCompare2ea7949 todedfce3CompareSince 2.13, case class `hashCode` mixes in the hash code of the`productPrefix` string. This is inconsistent with the `equals` method,subclasses of case classes that override `productPrefix` compareequal but have a different `hashCode`.This commit changes `hashCode` to mix in the `productPrefix.hashCode`statically instead of invoking `productPrefix` at runtime.For case classes without primitive fields, the synthetic `hashCode`invokes `ScalaRunTime._hashCode`, which mixes in the result of`productPrefix`. To fix that, the synthetic hashCode is changedto invoke `MurmurHash3.productHash` directly and mix in the nameto the seed statically. This works out with keeping `productHash`forwards and backwards compatible.The `MurmurHash3.productHash` method is deprecated / renamed to`caseClassHash`. This method computes the same hash as the synthetic`hashCode`, except for the corner case where a case class(or a subclass) override the `productPrefix`. In this case, thecase class name needs to be passed manually to `caseClassHash`.
| }else { | ||
| if (arr==0) | ||
| if (!ignorePrefix) x.productPrefix.hashCodeelse seed | ||
| else { |
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.
rare case where I would retain extra braces (Scala 2)
| defensureAccessible(m:JMethod):JMethod= scala.reflect.ensureAccessible(m) | ||
| // This is called by the synthetic case class `toString` method. | ||
| // It originally had a `CaseClass` parameter type which was changed to `Product`. |
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.
"originally" here means like first verse of Genesis
…22865)Since 2.13, case class `hashCode` mixes in the hash code of the`productPrefix` string. This is inconsistent with the `equals` method,subclasses of case classes that override `productPrefix` compare equalbut have a different `hashCode`(scala/bug#13033).This commit changes `hashCode` to mix in the `productPrefix.hashCode`statically instead of invoking `productPrefix` at runtime.For case classes without primitive fields, the synthetic `hashCode`invokes `ScalaRunTime._hashCode`, which mixes in the result of`productPrefix`. To fix that, the synthetic hashCode is changed toinvoke `MurmurHash3.productHash` directly and mix in the name to theseed statically.Scala 3 forward port ofscala/scala#11023
4345ced intoscala:2.13.xUh oh!
There was an error while loading.Please reload this page.
Mix in the `productPrefix` hash statically in case class `hashCode`
Mix in the `productPrefix` hash statically in case class `hashCode`
### What changes were proposed in this pull request?Upgrade to scala 2.13.17### Why are the changes needed?To bring the latest bug fixes and improvements like JDK 25 support. Note that Scala community announces two breaking changes due to the bug fixes.> Breaking changes> - Mix in the productPrefix hash statically in case class hashCode> - Improve scala.util.Using suppression order-https://github.com/scala/scala/releases/tag/v2.13.17 -scala/scala#11046 -scala/scala#10937 -scala/scala#10927 -scala/bug#13058 -scala/scala#11023 -scala/bug#13033 -scala/scala#11000### Does this PR introduce _any_ user-facing change?No### How was this patch tested?local and github builds### Was this patch authored or co-authored using generative AI tooling?NoCloses#52509 from vrozov/SPARK-53585.Authored-by: Vlad Rozov <vrozov@amazon.com>Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
### What changes were proposed in this pull request?Upgrade to scala 2.13.17### Why are the changes needed?To bring the latest bug fixes and improvements like JDK 25 support. Note that Scala community announces two breaking changes due to the bug fixes.> Breaking changes> - Mix in the productPrefix hash statically in case class hashCode> - Improve scala.util.Using suppression order-https://github.com/scala/scala/releases/tag/v2.13.17 -scala/scala#11046 -scala/scala#10937 -scala/scala#10927 -scala/bug#13058 -scala/scala#11023 -scala/bug#13033 -scala/scala#11000### Does this PR introduce _any_ user-facing change?No### How was this patch tested?local and github builds### Was this patch authored or co-authored using generative AI tooling?NoClosesapache#52509 from vrozov/SPARK-53585.Authored-by: Vlad Rozov <vrozov@amazon.com>Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Uh oh!
There was an error while loading.Please reload this page.
Since 2.13, case class
hashCodemixes in the hash code of theproductPrefixstring. This is inconsistent with theequalsmethod, subclasses of case classes that overrideproductPrefixcompare equal but have a differenthashCode.This commit changes
hashCodeto mix in theproductPrefix.hashCodestatically instead of invokingproductPrefixat runtime.For case classes without primitive fields, the synthetic
hashCodeinvokesScalaRunTime._hashCode, which mixes in the result ofproductPrefix. To fix that, the synthetic hashCode is changed to invokeMurmurHash3.productHashdirectly and mix in the name to the seed statically. This works out with keepingproductHashforwards and backwards compatible.The
MurmurHash3.productHashmethod is deprecated / renamed tocaseClassHash. This method computes the same hash as the synthetichashCode, except for the corner case where a case class (or a subclass) override theproductPrefix. In this case, the case class name needs to be passed manually tocaseClassHash.Fixesscala/bug#13033