Skip to content

Commit

Permalink
fix for #1363
Browse files Browse the repository at this point in the history
  • Loading branch information
nikivazou committed Oct 18, 2018
1 parent d801fe4 commit 9e7a590
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Language/Haskell/Liquid/Transforms/CoreToLogic.hs
Expand Up @@ -515,6 +515,13 @@ mkC = Just . ECon . (`F.L` F.charSort) . repr
ignoreVar :: Id -> Bool
ignoreVar i = simpleSymbolVar i `elem` ["I#", "D#"]

isBangInteger :: [C.CoreAlt] -> Bool
isBangInteger [(C.DataAlt s, _, _), (C.DataAlt jp,_,_), (C.DataAlt jn,_,_)]
= symbol s == "GHC.Integer.Type.S#"
&& symbol jp == "GHC.Integer.Type.Jp#"
&& symbol jn == "GHC.Integer.Type.Jn#"
isBangInteger _ = False

isErasable :: Id -> Bool
isErasable v = F.notracepp msg $ isGhcSplId v && not (isDCId v)
where
Expand Down Expand Up @@ -570,7 +577,10 @@ instance Simplify C.CoreExpr where
= simplify e
simplify (C.Let xes e)
= C.Let (simplify xes) (simplify e)
simplify (C.Case e x t alts)
simplify (C.Case e x t alts@[(_,_,ee),_,_]) | isBangInteger alts
= Misc.traceShow ("To simplify case") $
sub (M.singleton x (simplify e)) (simplify ee)
simplify ce@(C.Case e x t alts)
= C.Case (simplify e) x t (filter (not . isUndefined) (simplify <$> alts))
simplify (C.Cast e c)
= C.Cast (simplify e) c
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/T1363.hs
@@ -0,0 +1,17 @@
{-# LANGUAGE BangPatterns #-}
{-@ LIQUID "--exact-data-cons" @-}

{-@ mySum :: Integer -> xs:[Integer] -> Integer / [len xs] @-}
mySum :: Integer -> [Integer] -> Integer
mySum z [] = z
mySum z (x:xs) = mySum (z + x) xs

{-@ reflect mySum @-}

{-@ mySum' :: Integer -> xs:[Integer] -> Integer / [len xs] @-}
mySum' :: Integer -> [Integer] -> Integer
mySum' z [] = z
mySum' z (x:xs) = let !z' = z + x
in mySum' z' xs

{-@ reflect mySum' @-}

0 comments on commit 9e7a590

Please sign in to comment.