Don't eta reduce something we just saturated. (D'oh!)
This fixes the problem which causes a bootstrapped HEAD compiler to
crash.
(bndrs, body) = collectBinders expr
eta expr@(App _ _)
- | n_remaining >= 0 &&
+ | ok_to_eta_reduce f &&
+ n_remaining >= 0 &&
and (zipWith ok bndrs last_args) &&
not (any (`elemVarSet` fvs_remaining) bndrs)
= Just remaining_expr
ok bndr (Var arg) = bndr == arg
ok bndr other = False
+ -- we can't eta reduce something which must be saturated.
+ ok_to_eta_reduce (Var f)
+ = case idFlavour f of
+ PrimOpId op -> False
+ DataConId dc -> False
+ other -> True
+ ok_to_eta_reduce _ = False --safe. ToDo: generalise
+
eta (Let bind@(NonRec b r) body)
| not (any (`elemVarSet` fvs) bndrs)
= case eta body of