# stage2: implement generic function memoization · gitcafe/zig

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

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

Visibility: public

Requested revision: e9e3a2994696a3131125ebc4b1f0eec7ca5306d9

Requested commit: e9e3a2994696a3131125ebc4b1f0eec7ca5306d9

Commit: e9e3a2994696a3131125ebc4b1f0eec7ca5306d9

Tree: de6bf27daddd48b9ab15144312f558d3cd0c53c2

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: implement generic function memoization

Module has a new field `monomorphed_funcs` which stores the set of
`*Module.Fn` objects which are generic function instantiations.
The hash is based on hashes of comptime values of parameters known to be
comptime based on an explicit comptime keyword or must-be-comptime
type expressions that can be evaluated without performing monomorphization.
This allows function calls to be semantically analyzed cheaply for
generic functions which are already instantiated.

The table is updated with a single `getOrPutAdapted` in the semantic
analysis of `call` instructions, by pre-allocating the `Fn` object and
passing it to the child `Sema`.

```

## Parents

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

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