Closed rasmushenningsson closed 1 day ago
I think it would make sense to make it hash in a stable manner by default. Do you agree?
Yes, that sounds useful to me. I am wrapping up some work in #55 to improve the stability of hashes with a new API design for customizing how types get hashed. I think this improvement makes sense to make after that merges.
In the meantime, I believe the following should be an effective workaround. (Though I haven't tested it).
StableHashTraits.hash_method(::Regex) = FnHash(x -> (x.pattern, x.compile_options, r.match_options))
Or, for a specific context, you could do
struct HashRegex{T}
parent::T
end
StableHashTraits.parent_context(x::HashRegex) = x.parent
StableHashTraits.hash_method(::Regex, ::HashRegex) = FnHash(x -> (x.pattern, x.compile_options, r.match_options))
stable_hash(r"a*b*", HashRegex(HashVersion{3}()))
Resolved by #58
Regex
is amutable struct
which causes it tostable_hash
differently each time.I think it would make sense to make it hash in a stable manner by default. Do you agree? (The reason why it is a
mutable struct
is so it can interact with the GC to free the pointer to the compiled regex.)Here's the corresponding
hash
function inBase
, indicating that we should takepattern
,compile_options
andmatch_options
into account.