laurent.orseau
2020-12-10 10:37:48

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.


sorawee
2020-12-10 10:42:51

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.


laurent.orseau
2020-12-10 11:17:37

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


sorawee
2020-12-10 11:24:30

sorawee
2020-12-10 11:26:00

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)


sorawee
2020-12-10 11:26:17

However, the actual implementation of cp0 does analyze purity



sorawee
2020-12-10 11:26:36

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



sorawee
2020-12-10 11:26:54

“99.44% pure”


laurent.orseau
2020-12-10 12:23:38

Thanks!


laurent.orseau
2020-12-10 12:24:28

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


laurent.orseau
2020-12-10 13:29:36

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


laurent.orseau
2020-12-10 13:31:27

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.


laurent.orseau
2020-12-10 13:46:53

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?


sorawee
2020-12-10 13:51:43

The paper should be a subset of the code.


sorawee
2020-12-10 13:52:16

The code definitely does inlining, constant folding, etc.