# Sema: avoid breaking hash contract when instantiating generic functions · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/b931889c652b4763e9ac674cd01abcd7f3311e83)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: b931889c652b4763e9ac674cd01abcd7f3311e83

Requested commit: b931889c652b4763e9ac674cd01abcd7f3311e83

Commit: b931889c652b4763e9ac674cd01abcd7f3311e83

Tree: ab0828e0d69e84801f507554849d0eac18fa57ac

Author: Jacob Young

Committer: Andrew Kelley

## Message

```
Sema: avoid breaking hash contract when instantiating generic functions

 * Add tagName to Value which behaves like @tagName.
 * Add hashUncoerced to Value 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 of module_fn in Sema.instantiateGenericCall
   since Module.Decl.Index is not affected by ASLR like *Module.Fn was,
   and also because GenericCallAdapter.eql was already doing this.
 * Use Value.hashUncoerced in Sema.instantiateGenericCall because
   GenericCallAdapter.eql uses Value.eqlAdvanced to compare args, which
   ignores coersions.
 * Add revealed missing cases to Value.eqlAdvanced.

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.

```

## Parents

- [52f8de0194b4648078c2eb8d09bc3329677a80ec](https://git.cafe/gitcafe/zig/commit/52f8de0194b4648078c2eb8d09bc3329677a80ec?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/b931889c652b4763e9ac674cd01abcd7f3311e83?format=markdown)
