Skip to content

add named hash functors and delegate DefaultHash to them - #899

Merged
MichaelRawson merged 1 commit into
vprover:masterfrom
shalashaska117:explicit-hash
Aug 12, 2026
Merged

add named hash functors and delegate DefaultHash to them#899
MichaelRawson merged 1 commit into
vprover:masterfrom
shalashaska117:explicit-hash

Conversation

@shalashaska117

Copy link
Copy Markdown
Contributor

First PR of the series in #898.

Adds named single-purpose hash functors to Lib/Hash.hpp: FnvHash (owns hashBytes/hashNulTerminated/hashIter and hashes scalars, non-Unit pointers and strings), UnitHash and UnitNumberHash (Units by their number), PtrIdentityHash (pointer address cast to unsigned), LengthHash (container length) and PairHash<HashFst,HashSnd>. Every dispatch branch of DefaultHash/DefaultHash2 is now a one-line delegation to one of these, so hash values are unchanged by construction and no call site changes yet.

FnvHash and PtrIdentityHash static_assert against Unit-derived pointers, so later stages cannot hand a Unit key the pointer-bytes hash by mistake.

A new unit test pins the FNV-1a reference vectors and the named-vs-DefaultHash equality; the equality half leaves with DefaultHash at the end of the series.

Tested: debug ctest 99/99, including the new Hash test.

FnvHash now owns the FNV-1a machinery (hashBytes, hashNulTerminated, hashIter) and hashes scalars, non-Unit pointers and strings. UnitHash and UnitNumberHash hash Units by their number, PtrIdentityHash casts a pointer's address to unsigned, LengthHash returns a container's length, PairHash<HashFst,HashSnd> combines the element hashes of a pair. Every dispatch branch of DefaultHash and DefaultHash2 is now a one-line delegation to one of these, so hash values are unchanged by construction and no call site changes yet.
FnvHash and PtrIdentityHash reject Unit-derived pointers with a static_assert: once call sites name their hashes directly, a Unit key cannot silently get the pointer-bytes hash instead of the hash by unit number.
tHash.cpp pins the FNV-1a reference vectors and the equality between the named functors and what DefaultHash/DefaultHash2 resolve to; the equality half leaves with DefaultHash at the end of the series.
Part of vprover#898.
@MichaelRawson

Copy link
Copy Markdown
Contributor

Nice - even if we don't end up completely removing DefaultHash this is worthwhile so that people can use these hash functions explicitly if they wish.

@MichaelRawson
MichaelRawson merged commit d14a1f2 into vprover:masterAug 12, 2026
1 check passed
@shalashaska117

Copy link
Copy Markdown
ContributorAuthor

Nice - even if we don't end up completely removing DefaultHash this is worthwhile so that people can use these hash functions explicitly if they wish.

It will be the last step deleting everything legacy, so that every step is not the default path meanwhile I continue developing each phases

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@shalashaska117@MichaelRawson