Hiya, I've encountered something I don't understand in E.Subst. The substitution routine is very eager to inline stuff. It inlines all the simple applications it can find. Consider the following example: (\a -> a+a) expensive The substitution routine will inline that to: expensive+expensive Wouldn't it be prudent to generate this instead: let a = expensive in a + a Whether to inline it further would be decided later on. -- Cheers, Lemmih
On Sat, Feb 23, 2008 at 3:52 PM, Lemmih
Hiya,
I've encountered something I don't understand in E.Subst. The substitution routine is very eager to inline stuff. It inlines all the simple applications it can find. Consider the following example: (\a -> a+a) expensive The substitution routine will inline that to: expensive+expensive Wouldn't it be prudent to generate this instead: let a = expensive in a + a
Whether to inline it further would be decided later on.
Actually, it might be wise not to do any optimizations in the substitution routine. I assume constant applications are handled elsewhere as well? -- Cheers, Lemmih
On Sat, Feb 23, 2008 at 03:54:39PM +0100, Lemmih wrote:
Actually, it might be wise not to do any optimizations in the substitution routine. I assume constant applications are handled elsewhere as well?
The atom invariant insures that beta reduction is a simple source transformation that does not change the behavior of the program, not an optimization. E normal form number 2 (a name I just made up :) ) says all arguments must be atomic, all applied things may only be simple variables or another application, and lambda expressions may only occur directly on the RHS of a let binding, the body of a let statment, or in a case branch body. normal form 3 (after lambda lifting) says lambda expressions may _only_ occur at the top level, no where else. John -- John Meacham - ⑆repetae.net⑆john⑈
On Sun, Feb 24, 2008 at 12:19 AM, John Meacham
On Sat, Feb 23, 2008 at 03:54:39PM +0100, Lemmih wrote:
Actually, it might be wise not to do any optimizations in the substitution routine. I assume constant applications are handled elsewhere as well?
The atom invariant insures that beta reduction is a simple source transformation that does not change the behavior of the program, not an optimization.
E normal form number 2 (a name I just made up :) ) says all arguments must be atomic, all applied things may only be simple variables or another application, and lambda expressions may only occur directly on the RHS of a let binding, the body of a let statment, or in a case branch body.
normal form 3 (after lambda lifting) says lambda expressions may _only_ occur at the top level, no where else.
Excellent, exactly what I needed to fix my test case. -- Cheers, Lemmih
On 2/23/08, John Meacham
On Sat, Feb 23, 2008 at 03:54:39PM +0100, Lemmih wrote:
Actually, it might be wise not to do any optimizations in the substitution routine. I assume constant applications are handled elsewhere as well?
The atom invariant insures that beta reduction is a simple source transformation that does not change the behavior of the program, not an optimization.
E normal form number 2 (a name I just made up :) ) says all arguments must be atomic, all applied things may only be simple variables or another application, and lambda expressions may only occur directly on the RHS of a let binding, the body of a let statment, or in a case branch body.
normal form 3 (after lambda lifting) says lambda expressions may _only_ occur at the top level, no where else.
Gee, maybe this should be documented somewhere?
On Sat, Feb 23, 2008 at 03:52:29PM +0100, Lemmih wrote:
I've encountered something I don't understand in E.Subst. The substitution routine is very eager to inline stuff. It inlines all the simple applications it can find. Consider the following example: (\a -> a+a) expensive The substitution routine will inline that to: expensive+expensive Wouldn't it be prudent to generate this instead: let a = expensive in a + a
An invariant is that the only things that may ever appear as arguments to functions or data constructors are atoms. This ensures that beta reduction is always beneficial and that 'let' statements are the one and only way to allocate thunks. GHC core has the same restriction for the same reason, it makes a whole lot of transformations a lot simpler. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (3)
-
John Meacham -
Lemmih -
Samuel Bronson