Skip to content

Commit 2a97f15

Browse files
Merge pull request #2236 from ucsd-progsys/fd/fix-anormalise
Fix A normalization when type binder and lets are mixed in the input
2 parents fe1c99a + 6820de2 commit 2a97f15

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

liquid-prelude/liquid-prelude.cabal

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ library
2525
Language.Haskell.Liquid.Equational
2626
Language.Haskell.Liquid.Bag
2727
Language.Haskell.Liquid.ProofCombinators
28-
KMeansHelper
2928
hs-source-dirs: src
3029
build-depends: base < 5
3130
, ghc-prim

liquidhaskell-boot/src/Language/Haskell/Liquid/Transforms/ANF.hs

+15-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,21 @@ stitch γ e
249249
e' <- normalize γ e
250250
bs <- st_binds <$> get
251251
put bs'
252-
return $ mkCoreLets bs e'
252+
-- See Note [Shape of normalized terms]
253+
let (tvs, e'') = collectTyBinders e'
254+
return $ mkLams tvs (mkCoreLets bs e'')
255+
256+
-- Note [Shape of normalized terms]
257+
--
258+
-- The termination checker in Termination.collectArguments expects the type
259+
-- binders to come before lets:
260+
--
261+
-- > \ (@a) -> let ... in \ b c d -> ...
262+
--
263+
-- Therefore, stitch makes sure to insert new lets after the type binders
264+
--
265+
-- > \ (@a) -> let lqanf... = ... in let ... in \ b c d -> ...
266+
--
253267

254268
_mkCoreLets' :: [CoreBind] -> CoreExpr -> CoreExpr
255269
_mkCoreLets' bs e = mkCoreLets bs1 e1
File renamed without changes.

tests/pos/T2235.hs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{-# OPTIONS_GHC -ddump-ds #-}
2+
-- | Tests that liquid haskell can deal fine with HasCallStack.
3+
--
4+
-- See https://github.com/ucsd-progsys/liquidhaskell/issues/2235
5+
module T2235 where
6+
7+
import Language.Haskell.Liquid.Prelude (liquidError)
8+
import GHC.Stack
9+
10+
{-@ myhead :: {xs:[a] | len xs > 0} -> a @-}
11+
myhead :: HasCallStack => [a] -> a
12+
myhead (x:_) = x
13+
14+
{-@ type PosInt = {v: Int | v > 0 } @-}
15+
{-@ type List a N = {v : [a] | (len v) = N} @-}
16+
{-@ type Matrix a Rows Cols = (List (List a Cols) Rows) @-}
17+
{-@ transpose :: c:Int -> r:PosInt -> Matrix a r c -> Matrix a c r @-}
18+
19+
transpose :: Int -> Int -> [[a]] -> [[a]]
20+
transpose 0 _ _ = []
21+
transpose c r ((x:xs) : xss) = (x : map myhead xss) : transpose (c-1) r (xs : map tail xss)
22+
transpose c r ([] : _) = liquidError "dead code"
23+
transpose c r [] = error "dead code"
24+

tests/tests.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@ executable unit-pos-1
16141614
, T2091
16151615
, T2093
16161616
, T2096
1617+
, T2235
16171618
, T385
16181619
, T531
16191620
, T595a
@@ -1901,6 +1902,7 @@ executable unit-pos-2
19011902
, Ite1
19021903
, Ite
19031904
, Jeff
1905+
, KMeansHelper
19041906
, Keys
19051907
, Kmp
19061908
, KmpIO

0 commit comments

Comments
 (0)