| ... |
... |
@@ -815,8 +815,9 @@ doFloatFromRhs fe lvl rec strict_bind (SimplFloats { sfLetFloats = LetFloats fs |
|
815
|
815
|
&& want_to_float
|
|
816
|
816
|
&& can_float
|
|
817
|
817
|
where
|
|
818
|
|
- want_to_float = isTopLevel lvl || exprIsCheap rhs || exprIsExpandable rhs
|
|
819
|
|
- -- See Note [Float when cheap or expandable]
|
|
|
818
|
+ want_to_float = isTopLevel lvl || exprIsExpandable rhs
|
|
|
819
|
+ -- See Note [Float when expandable]
|
|
|
820
|
+
|
|
820
|
821
|
can_float = case ff of
|
|
821
|
822
|
FltLifted -> True
|
|
822
|
823
|
FltOkSpec -> isNotTopLevel lvl && isNonRec rec
|
| ... |
... |
@@ -828,16 +829,29 @@ doFloatFromRhs fe lvl rec strict_bind (SimplFloats { sfLetFloats = LetFloats fs |
|
828
|
829
|
floatEnabled lvl FloatNestedOnly = not (isTopLevel lvl)
|
|
829
|
830
|
floatEnabled _ FloatEnabled = True
|
|
830
|
831
|
|
|
831
|
|
-{-
|
|
832
|
|
-Note [Float when cheap or expandable]
|
|
833
|
|
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
834
|
|
-We want to float a let from a let if the residual RHS is
|
|
835
|
|
- a) cheap, such as (\x. blah)
|
|
836
|
|
- b) expandable, such as (f b) if f is CONLIKE
|
|
837
|
|
-But there are
|
|
838
|
|
- - cheap things that are not expandable (eg \x. expensive)
|
|
839
|
|
- - expandable things that are not cheap (eg (f b) where b is CONLIKE)
|
|
840
|
|
-so we must take the 'or' of the two.
|
|
|
832
|
+{- Note [Float when expandable]
|
|
|
833
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
834
|
+We float when that would leave us with a RHS that is /expandable/ (#26854).
|
|
|
835
|
+The whole purpose of the local-let-floating is to end up with
|
|
|
836
|
+ let x = rhs
|
|
|
837
|
+where rhs has an expandable unfolding, so that `exprIsConApp_maybe` will look
|
|
|
838
|
+inside `x`.
|
|
|
839
|
+
|
|
|
840
|
+Historical aside:
|
|
|
841
|
+
|
|
|
842
|
+ In the long-distant (2011) past, we made `want_to_float` true if
|
|
|
843
|
+ EITHER exprIsExpandable OR exprIsCheap
|
|
|
844
|
+ But that seems wrong: there is no point in floating for expressions that are
|
|
|
845
|
+ cheap but not expandable:
|
|
|
846
|
+ * It costs more to test
|
|
|
847
|
+ * It gives no benefit
|
|
|
848
|
+ * Very few expressions are cheap but not expandable (e.g. error calls)
|
|
|
849
|
+ We justified this OR by saying that there may be:
|
|
|
850
|
+ - cheap things that are not expandable (eg \x. expensive)
|
|
|
851
|
+ - expandable things that are not cheap (eg (f b) where b is CONLIKE)
|
|
|
852
|
+ But that's not true: (\x.expensive) is certainly expandable.
|
|
|
853
|
+
|
|
|
854
|
+End of historial aside
|
|
841
|
855
|
-}
|
|
842
|
856
|
|
|
843
|
857
|
emptyLetFloats :: LetFloats
|