
A purity tag is something I’ve been wanting to do/have for quite some time too (with the same caveats as yours :wink: ). With automatic propagation by the compiler when feasible. It seems to me that this should enable a number of automatic optimizations. For other cases where mutation or local side effects are involved, one unsafe possibility is to rely on the designer to tag functions as “pure” when it can’t be inferred by the compiler. Maybe a raco test
command could challenge these tags, somehow.

cp0 already analyzes purity in programs and optimize it accordingly. Allowing programmers to annotate would turn inference problem into checking problem, but I don’t think it makes the problem easier in this case.

cp0 = compiler pass 0? Is what it’s doing documented or did you look at the code?

Here’s what cp0 does: https://legacy.cs.indiana.edu/~dyb/pubs/inlining.pdf

Though after skimming the paper really quick it doesn’t seem to mention purity (I read this paper a couple of years ago, so I forgot details already)

However, the actual implementation of cp0 does analyze purity


I can remember this very clearly because of the function named ivory?


“99.44% pure”

Thanks!

Now this ivory actually rings a bell, but i haven’t read the paper.

The simple
tag seems to be the closest as it mentions “can allocate mutable structures”.

But its use seems to be limited to “mostly used to determine if we can discard an expression.” Also, I haven’t checked how these tags are propagated.

The paper you mention and the code you cite don’t seem to do the same thing. The paper is about inlining and the code is about moving or discarding. Maybe the code is at a different pass?

The paper should be a subset of the code.

The code definitely does inlining, constant folding, etc.