Pauan/rollup-plugin-purs

Drop partially applied and saturated Data_Function.apply

wegry opened this issue · 6 comments

wegry commented

Data_Function.apply(f) is the same as f and Data_Function.apply(f)(a) is the same as (f)(a). It is effectively a no op that adds two stack frames at each instance of its being called.

Pauan commented

Actually, I plan to add in a generic inliner that can handle a wide variety of situations, not just Data.Function.apply, but thanks for reminding me.

wegry commented

I didn't see your inliner yet. But looks like this issue is a bit of a moot point. Closing.

Pauan commented

I'd actually like to leave this open, since there might be some optimizations that can be applied specifically to apply

Just FYI, psc already does a fair few of these specific optimizations like inlining specific functions already, so it would be easy to add another one like this there, and I think a PR for that has a good chance of being accepted. A more general inliner is also planned for psc, although probably not for a while. I'm not sure how much effort an adding an inliner here would be but I just thought it might be worth mentioning, as I wouldn't want you to put a lot of effort in to implement an inliner here to find that psc is taking care of it in a few major releases' time and there's nothing left for this plugin to do.

Pauan commented

@hdgarrood Yeah, I think that optimizations like inlining/uncurrying should really be in psc, because then it works for all backends, and because psc has additional information that rollup-plugin-purs doesn't have.

So I always intended the optimizations in rollup-plugin-purs to be temporary, with the expectation that I would be removing them later. Thanks for mentioning it.

Pauan commented

@wegry Version 1.0.16 adds in an inliner. This inliner is generic and works with a wide variety of functions, including (but not limited to) Data.Function.apply

Consider this PureScript code:

import Data.Function (apply, flip, const)

id :: forall a. a -> a
id a = a

output = apply (apply (flip const) "3") (apply (apply id) (apply (const "2") "1"))

output gets compiled to just "2", there aren't any function calls at all because it fully inlines apply, flip, const, and id

So I didn't need to add in any optimizations specific to Data.Function.apply, because the generic inliner is good enough.

This essentially solves purescript/purescript#2345, except that I'd still prefer for optimizations to be in psc rather than rollup-plugin-purs