Do not eta-reduce across Ticks in CorePrep
authorSimon Peyton Jones <simonpj@microsoft.com>
Fri, 25 Mar 2016 09:23:17 +0000 (09:23 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 25 Mar 2016 09:30:18 +0000 (09:30 +0000)
The function tryEtaReducePrep was being over-ambitious.
When Breakpoint ticks were involved (i.e. in GHCi), eta
reduction left an out-of-scope variable in the Tick.

Easily fixed. Fixes the original report in Trac #111728.

compiler/coreSyn/CorePrep.hs

index 58eda2f..fb00f2b 100644 (file)
@@ -967,8 +967,13 @@ tryEtaReducePrep bndrs (Let bind@(NonRec _ r) body)
   where
     fvs = exprFreeVars r
 
-tryEtaReducePrep bndrs (Tick tickish e)
-  = fmap (mkTick tickish) $ tryEtaReducePrep bndrs e
+-- NB: do not attempt to eta-reduce across ticks
+-- Otherwise we risk reducing
+--       \x. (Tick (Breakpoint {x}) f x)
+--   ==> Tick (breakpoint {x}) f
+-- which is bogus (Trac #17228)
+-- tryEtaReducePrep bndrs (Tick tickish e)
+--   = fmap (mkTick tickish) $ tryEtaReducePrep bndrs e
 
 tryEtaReducePrep _ _ = Nothing