# stage2: comptime function with the same args is memoized · gitcafe/zig

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

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

Visibility: public

Requested revision: f378b0adce80aa6f85d9bf6bf97172426de2c719

Requested commit: f378b0adce80aa6f85d9bf6bf97172426de2c719

Commit: f378b0adce80aa6f85d9bf6bf97172426de2c719

Tree: 68a460620cb480de283afe9e64d4ea8b9a0fbd7d

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: comptime function with the same args is memoized

 * Introduce `memoized_calls` to `Module` which stores all the comptime
   function calls that are cached. It is keyed on the `*Fn` and the
   comptime arguments, but it does not yet properly detect comptime function
   pointers and avoid memoizing in this case. So it will have false
   positives for when a comptime function call mutates data through a
   pointer parameter.
 * Sema: Add a new helper function: `resolveConstMaybeUndefVal`
 * Value: add `enumToInt` method and use it in `zirEnumToInt`. It is
   also used by the hashing function.
 * Value: fix representation of optionals to match error unions.
   Previously it would not handle nested optionals correctly. Now it
   matches the memory layout of error unions and supports nested
   optionals properly. This required changes in all the backends for
   generating optional constants.
 * TypedValue gains `eql` and `hash` methods.
 * Value: Implement hashing for floats, optionals, and enums.
   Additionally, the zig type tag is added to the hash, where it was not
   previously, so that values of differing types will get different
   hashes.

```

## Parents

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

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