mirror of
https://github.com/grin-compiler/grin.git
synced 2024-10-26 16:51:12 +03:00
Arity: move regression test under arity spec.
This commit is contained in:
parent
586c458401
commit
20a64a6225
@ -1,56 +0,0 @@
|
||||
{-
|
||||
run
|
||||
stack exec -- grin -t --ar -p --llvm arity-raising-bug-06.grin
|
||||
|
||||
error
|
||||
grin: src/Transformations/Optimising/ArityRaising.hs:(90,24)-(92,47): Non-exhaustive patterns in case
|
||||
-}
|
||||
|
||||
grinMain =
|
||||
p1 <- store (CInt 0)
|
||||
p2 <- store (CInt 1)
|
||||
p3 <- store (CInt 1000)
|
||||
p4 <- store (Fupto p2 p3)
|
||||
p5 <- store (Fsum p1 p4)
|
||||
e_v3.0' <- sum' p1 p4
|
||||
e_v3.0 <- pure (CInt e_v3.0')
|
||||
update p5 e_v3.0
|
||||
_prim_int_print e_v3.0'
|
||||
|
||||
upto p6 p7 =
|
||||
e_v1.1 <- fetch p6
|
||||
(CInt n2') <- pure e_v1.1
|
||||
e_v1.2 <- fetch p7
|
||||
(CInt n3') <- pure e_v1.2
|
||||
b1' <- _prim_int_gt n2' n3'
|
||||
case b1' of
|
||||
#True ->
|
||||
pure (CNil)
|
||||
#False ->
|
||||
n4' <- _prim_int_add n2' 1
|
||||
p8 <- store (CInt n4')
|
||||
p9 <- store (Fupto p8 p7)
|
||||
pure (CCons p6 p9)
|
||||
|
||||
sum' p10 p11 =
|
||||
e_v1.3 <- fetch p11
|
||||
v1 <- case e_v1.3 of
|
||||
#default ->
|
||||
pure e_v1.3
|
||||
(Fupto e_p2.3 e_p3.3) ->
|
||||
e_v2.3 <- upto e_p2.3 e_p3.3
|
||||
update p11 e_v2.3 -- HINT: it works without this update (without the update it's call by name)
|
||||
pure e_v2.3
|
||||
case v1 of
|
||||
(CNil) ->
|
||||
e_v1.4 <- fetch p10
|
||||
(CInt e_v1.4') <- pure e_v1.4
|
||||
pure e_v1.4'
|
||||
(CCons p12 p13) ->
|
||||
e_v1.5 <- fetch p10
|
||||
(CInt n5') <- pure e_v1.5
|
||||
e_v1.6 <- fetch p12
|
||||
(CInt n6') <- pure e_v1.6
|
||||
n7' <- _prim_int_add n5' n6'
|
||||
p14 <- store (CInt n7')
|
||||
sum' p14 p13
|
@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE OverloadedStrings, QuasiQuotes, ViewPatterns #-}
|
||||
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
|
||||
module Transformations.Optimising.ArityRaisingSpec where
|
||||
|
||||
import Transformations.Optimising.ArityRaising
|
||||
@ -357,3 +357,105 @@ spec = do
|
||||
|]
|
||||
snd (arityRaising (inferTypeEnv before, before)) `sameAs` after
|
||||
|
||||
it "bugfix - update" $ do
|
||||
let before = [prog|
|
||||
grinMain =
|
||||
p1 <- store (CInt 0)
|
||||
p2 <- store (CInt 1)
|
||||
p3 <- store (CInt 1000)
|
||||
p4 <- store (Fupto p2 p3)
|
||||
p5 <- store (Fsum p1 p4)
|
||||
e_v3.0' <- sum' p1 p4
|
||||
e_v3.0 <- pure (CInt e_v3.0')
|
||||
update p5 e_v3.0
|
||||
_prim_int_print e_v3.0'
|
||||
|
||||
upto p6 p7 =
|
||||
e_v1.1 <- fetch p6
|
||||
(CInt n2') <- pure e_v1.1
|
||||
e_v1.2 <- fetch p7
|
||||
(CInt n3') <- pure e_v1.2
|
||||
b1' <- _prim_int_gt n2' n3'
|
||||
case b1' of
|
||||
#True ->
|
||||
pure (CNil)
|
||||
#False ->
|
||||
n4' <- _prim_int_add n2' 1
|
||||
p8 <- store (CInt n4')
|
||||
p9 <- store (Fupto p8 p7)
|
||||
pure (CCons p6 p9)
|
||||
|
||||
sum' p10 p11 =
|
||||
e_v1.3 <- fetch p11
|
||||
v1 <- case e_v1.3 of
|
||||
#default ->
|
||||
pure e_v1.3
|
||||
(Fupto e_p2.3 e_p3.3) ->
|
||||
e_v2.3 <- upto e_p2.3 e_p3.3
|
||||
update p11 e_v2.3
|
||||
pure e_v2.3
|
||||
case v1 of
|
||||
(CNil) ->
|
||||
e_v1.4 <- fetch p10
|
||||
(CInt e_v1.4') <- pure e_v1.4
|
||||
pure e_v1.4'
|
||||
(CCons p12 p13) ->
|
||||
e_v1.5 <- fetch p10
|
||||
(CInt n5') <- pure e_v1.5
|
||||
e_v1.6 <- fetch p12
|
||||
(CInt n6') <- pure e_v1.6
|
||||
n7' <- _prim_int_add n5' n6'
|
||||
p14 <- store (CInt n7')
|
||||
sum' p14 p13
|
||||
|]
|
||||
let after = [prog|
|
||||
grinMain =
|
||||
p1 <- store (CInt 0)
|
||||
p2 <- store (CInt 1)
|
||||
p3 <- store (CInt 1000)
|
||||
p4 <- store (Fupto p2 p3)
|
||||
p5 <- store (Fsum p1 p4)
|
||||
e_v3.0' <- sum' 0 p4
|
||||
e_v3.0 <- pure (CInt e_v3.0')
|
||||
update p5 e_v3.0
|
||||
_prim_int_print e_v3.0'
|
||||
|
||||
upto p6 p7 =
|
||||
e_v1.1 <- fetch p6
|
||||
(CInt n2') <- pure e_v1.1
|
||||
e_v1.2 <- fetch p7
|
||||
(CInt n3') <- pure e_v1.2
|
||||
b1' <- _prim_int_gt n2' n3'
|
||||
case b1' of
|
||||
#True ->
|
||||
pure (CNil)
|
||||
#False ->
|
||||
n4' <- _prim_int_add n2' 1
|
||||
p8 <- store (CInt n4')
|
||||
p9 <- store (Fupto p8 p7)
|
||||
pure (CCons p6 p9)
|
||||
|
||||
sum' p10 p11 =
|
||||
e_v1.3 <- fetch p11
|
||||
v1 <- case e_v1.3 of
|
||||
#default ->
|
||||
pure e_v1.3
|
||||
(Fupto e_p2.3 e_p3.3) ->
|
||||
e_v2.3 <- upto e_p2.3 e_p3.3
|
||||
update p11 e_v2.3
|
||||
pure e_v2.3
|
||||
case v1 of
|
||||
(CNil) ->
|
||||
e_v1.4 <- pure (CInt p10)
|
||||
(CInt e_v1.4') <- pure e_v1.4
|
||||
pure e_v1.4'
|
||||
(CCons p12 p13) ->
|
||||
e_v1.5 <- pure (CInt p10)
|
||||
(CInt n5') <- pure e_v1.5
|
||||
e_v1.6 <- fetch p12
|
||||
(CInt n6') <- pure e_v1.6
|
||||
n7' <- _prim_int_add n5' n6'
|
||||
p14 <- store (CInt n7')
|
||||
sum' n7' p13
|
||||
|]
|
||||
snd (arityRaising (inferTypeEnv before, before)) `sameAs` after
|
||||
|
Loading…
Reference in New Issue
Block a user