-\begin{code}
-tryEtaExpansion :: OutExpr
- -> (Arity -> OutExpr -> SimplM (OutStuff a))
- -> SimplM (OutStuff a)
-tryEtaExpansion rhs thing_inside
- | not opt_SimplDoLambdaEtaExpansion
- || null y_tys -- No useful expansion
- || not (is_case1 || is_case2) -- Neither case matches
- = thing_inside final_arity rhs -- So, no eta expansion, but
- -- return a good arity
-
- | is_case1
- = make_y_bndrs $ \ y_bndrs ->
- thing_inside final_arity
- (mkLams x_bndrs $ mkLams y_bndrs $
- mkApps body (map Var y_bndrs))
-
- | otherwise -- Must be case 2
- = mapAndUnzipSmpl bind_z_arg arg_infos `thenSmpl` \ (maybe_z_binds, z_args) ->
- addAuxiliaryBinds (catMaybes maybe_z_binds) $
- make_y_bndrs $ \ y_bndrs ->
- thing_inside final_arity
- (mkLams y_bndrs $
- mkApps (mkApps fun z_args) (map Var y_bndrs))
- where
- all_trivial_args = all is_trivial arg_infos
- is_case1 = all_trivial_args
- is_case2 = null x_bndrs && not (any unlifted_non_trivial arg_infos)
-
- (x_bndrs, body) = collectBinders rhs -- NB: x_bndrs can include type variables
- x_arity = valBndrCount x_bndrs
+In Case 1, we may have to sandwich some coerces between the lambdas
+to make the types work. exprEtaExpandArity looks through coerces
+when computing arity; and etaExpand adds the coerces as necessary when
+actually computing the expansion.