You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Sema] Switch synthesized hashing to use the new resilient hasher interface
Force-derive Hashable._hash(into:) whenever we need to derive hashValue. Do all the actual work there.
_hash(into:) has a default implementation, so it wouldn’t normally be considered a requirement in need of synthesized conformance. However, for types that synthesize their hashability, we want to replace the default with a custom implementation.
A better option would be to remove the default implementation and synthesize it (and/or hashValue) as needed:
1. If a witness hashValue cannot be resolved, synthesize one that simply returns _hashValue(for: self). (I.e., express hashValue in terms of _hash(into:).)
2. If a witness for _hash(into:) cannot be resolved:
a) if there is an explicit witness for hashValue, synthesize _hash(into:) such that it simply feeds the hashValue to the hasher.
b) otherwise if the parent context is not a struct or enum decl, then fail and produce a diagnostic. We can’t fully synthesize Hashable for classes or in extensions.
c) if the components of the type aren’t all Hashable, then fail and produce a diagnostic about a missing hashValue implementation.
c) otherwise synthesize _hash(into:) by feeding the type’s components into the hasher.
However, the DerivedConformance is not yet a great fit for such complicated derivation rules, so we’d need to pretend Hashable is always derivable, and manually provide diagnostics in cases 2/b and 2/c. Providing high-quality, non-duplicated diagnostics is a challenge.
Even worse, case 2/a would require us to support synthesizing _hash(into:) into extensions, classes, synthesized structs and imported types — and unfortunately, compiler support for doing this is currently limited.
0 commit comments