From: "peterzhu2118 (Peter Zhu) via ruby-core" Date: 2024-11-05T15:55:41+00:00 Subject: [ruby-core:119738] [Ruby master Bug#20868] Method#hash changes after compaction Issue #20868 has been reported by peterzhu2118 (Peter Zhu). ---------------------------------------- Bug #20868: Method#hash changes after compaction https://bugs.ruby-lang.org/issues/20868 * Author: peterzhu2118 (Peter Zhu) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED ---------------------------------------- Fix: https://github.com/ruby/ruby/pull/12004 The hash value of a Method may change after a compaction but must remain constant because otherwise it may not work as the key in a hash table. For example: ```ruby def a; end # Need this method here because otherwise the iseq may be on the C stack # which would get pinned and not move during compaction def get_hash method(:a).hash end puts get_hash # => 2993401401091578131 GC.verify_compaction_references(expand_heap: true, toward: :empty) puts get_hash # => -2162775864511574135 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/