Just as a counterbalance, improper @pure
annotations can introduce bugs. The optimizations it enables rely on an extremely strict definition of pure. It really should be named something like @hyperpure
. Some of the restrictions include:
- It must always return exactly (
===
) the same result for a given input. Watch out for mutable types. I think constant globals are okay, though. - The function it’s used on cannot be further extended by other methods after it gets called.
- It cannot recurse.
- It’s undocumented and not exported (for good reason), but this means the complete list of preconditions is really only in a few people’s heads.