zig
zig copied to clipboard
Sema: avoid breaking hash contract when instantiating generic functions
- Add
tagName
toValue
which behaves like@tagName
. - Add
hashUncoerced
toValue
as an alternative to hash when we want to produce the same hash for value that can coerce to each other. - Hash
owner_decl
instead ofmodule_fn
inSema.instantiateGenericCall
sinceModule.Decl.Index
is not affected by ASLR like*Module.Fn
was, and also becauseGenericCallAdapter.eql
was already doing this. - Use
Value.hashUncoerced
inSema.instantiateGenericCall
becauseGenericCallAdapter.eql
usesValue.eqlAdvanced
to compare args, which ignores coersions.
Without these changes, we were breaking the hash contract for monomorphed_funcs
, and were generating different hashes for values that compared equal. This resulted in a 0.2% chance when compiling self-hosted of producing a different output, which depended on fingerprint collisions of hashes that were affected by ASLR. Normally, the different hashes would have resulted in equal checks being skipped, but in the case of a fingerprint collision, the truth would be revealed and the compiler's behavior would diverge.