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

Derive hash value of struct instances not only from the instance's values, but also its class #2214

Closed
janlelis opened this issue Jan 8, 2021 · 2 comments

Comments

@janlelis
Copy link

janlelis commented Jan 8, 2021

Struct.new(:x).new.hash on TruffleRuby always creates the same hash, while on MRI/JRuby it creates a different hash for different struct classes.

@eregon: Actually Struct.new(:y).new.hash also has the same hash, the hash is only based on Struct values currently, which seems suboptimal.

@eregon
Copy link
Member

eregon commented Jan 8, 2021

Thanks for the report.

I think we should use something like val = Primitive.vm_hash_start(Truffle::Type.object_class(self).hash) in

val = Primitive.vm_hash_start(CLASS_SALT)

and also in
hash = Primitive.vm_hash_start CLASS_SALT

@bjfish Could you do that?

It seems a good idea to add a ruby/spec that Struct.new(:x).new(1).hash != Struct.new(:y).new(1).hash.

@eregon
Copy link
Member

eregon commented Jan 11, 2021

Fixed in d9235b8 by @bjfish, thanks for the report.

@eregon eregon closed this as completed Jan 11, 2021
@eregon eregon added this to the 21.1.0 milestone Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants