Experimental flag -fdicts-cheap
authorsimonpj@microsoft.com <unknown>
Wed, 12 Jul 2006 15:32:04 +0000 (15:32 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 12 Jul 2006 15:32:04 +0000 (15:32 +0000)
commite1231b2bcb1c9294c2ecdf150e9aad72a0caa253
tree3cef724cdd21a14accba030348a88b7c80cb59ef
parent09c814ec2c4fa854165f98aff4d29a69cafdc92a
Experimental flag -fdicts-cheap

This experimental flag, -fdicts-cheap, makes a let-binding that bind a
value of dictionary type look cheap.  That in turn leads to more
eta expansion.  Instead of
f = /\a. \(d1:Ord a). let d2:Ord [a] = dfOrd a d1 in
                 \(x:a). <stuff>
which has arity 1, you get
f = /\a. \(d1:Ord a). \(x:a).
         let d2:Ord [a] = dfOrd a d1 in <stuff>
Now f has arity 2.

This can cretainly waste dictionary-construction work, if f is
partially applied to its dictionary argument.  However it has knock-on
effects.  Because f has arity 2, we won't float (f Int d) out of
\x. h (f Int d)
Floating f out of this lambda makes it impossible for an h/f fusion
rule to fire; and this unexpected loss of RULE application was the
immediate reason for implementing this flag. (Roman Leshchinskiy came
across this when working on array fusion.)

I've implemented the change only in CoreUtils.arityType, which
only affects eta expansion.  I thought of putting the change in
exprIsCheap, which is a more systematic place (the former calls
the latter) but

a) I wanted this under flag control, and the flags
are not readily available to all callers of exprIsCheap

b) I'm not 100% convinced that this change is a good
idea, so it's reasonable to do the narrowest change
that solves the immediate problem.
compiler/coreSyn/CoreUtils.lhs
compiler/main/DynFlags.hs
compiler/simplCore/SimplUtils.lhs