Skip to content

Commit fbc4e0d

Browse files
committed
ES: as-pat tests
1 parent 264159c commit fbc4e0d

File tree

8 files changed

+13
-126
lines changed

8 files changed

+13
-126
lines changed

grin/test/AbstractInterpretation/ExtendedSyntax/CreatedBySpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,12 @@ spec = do
456456
producerN0 = mkProducerSet [(cNil, ["n0"])]
457457
(calcProducers exp) `shouldBe` expected
458458

459-
it "variable as-patterns" $ do
459+
it "variable copies" $ do
460460
let exp = [prog|
461461
grinMain =
462462
z0 <- pure 0
463-
a2 @ a1 <- pure (CInt z0)
463+
a1 <- pure (CInt z0)
464+
a2 <- pure a1
464465
b1 <- pure a1
465466
b2 <- pure a2
466467
c1 <- pure b1

grin/test/AbstractInterpretation/ExtendedSyntax/HptSpec.hs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,6 @@ spec = do
4444
}
4545
result `shouldBe` exptected
4646

47-
it "handles as-patterns with variables correctly" $ do
48-
let code = withPrimPrelude [prog|
49-
grinMain =
50-
k0 <- pure 0
51-
x0 <- pure (CInt k0)
52-
x2@x1 <- pure x0
53-
54-
pure ()
55-
|]
56-
let result = inferTypeEnv code
57-
exptected = emptyTypeEnv
58-
{ TypeEnv._variable = Map.fromList
59-
[ ("k0", int64_t)
60-
-- , ("k1", int64_t)
61-
-- , ("k2", int64_t)
62-
-- , ("_v", unit_t)
63-
, ("x0", T_NodeSet $ cnode_t "Int" [TypeEnv.T_Int64])
64-
, ("x1", T_NodeSet $ cnode_t "Int" [TypeEnv.T_Int64])
65-
, ("x2", T_NodeSet $ cnode_t "Int" [TypeEnv.T_Int64])
66-
]
67-
, TypeEnv._function = mconcat
68-
[ fun_t "grinMain" [] unit_t
69-
-- , fun_t "_prim_int_add" [int64_t, int64_t] int64_t
70-
-- , fun_t "_prim_int_print" [int64_t] unit_t
71-
]
72-
}
73-
result `shouldBe` exptected
74-
7547
it "handles as-patterns with nodes correctly" $ do
7648
let code = withPrimPrelude [prog|
7749
grinMain =

grin/test/AbstractInterpretation/ExtendedSyntax/IRSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ testProgram = [prog|
9999
pure v
100100
(Fupto a b) @ alt.7 ->
101101
w <- upto $ a b
102-
() @ p.5 <- update q w
102+
p.5 <- update q w
103103
pure w
104104
(Fsum c) @ alt.8 ->
105105
z <- sum $ c
106-
() @ p.6 <- update q z
106+
p.6 <- update q z
107107
pure z
108108
|]

grin/test/AbstractInterpretation/ExtendedSyntax/LiveVariableSpec.hs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,6 @@ spec = describe "Live Variable Analysis" $ do
6565
calculated = (calcLiveness exp) { _registerEff = mempty, _functionEff = mempty }
6666
calculated `sameAs` variableAliasExpected
6767

68-
it "variable_alias_with_as_pattern" $ do
69-
let exp = withPrimPrelude [prog|
70-
grinMain =
71-
x <- pure 0
72-
y@z <- pure x
73-
_prim_int_print y
74-
|]
75-
let variableAliasWithAsPatternExpected = emptyLVAResult
76-
{ _memory = []
77-
, _registerLv = [ ("x", liveVal)
78-
, ("y", liveVal)
79-
, ("z", deadVal)
80-
]
81-
, _functionLv = mkFunctionLivenessMap []
82-
}
83-
calculated = (calcLiveness exp) { _registerEff = mempty, _functionEff = mempty }
84-
calculated `sameAs` variableAliasWithAsPatternExpected
85-
8668
it "as_pattern_with_node_1" $ do
8769
let exp = withPrimPrelude [prog|
8870
grinMain =
@@ -1019,29 +1001,6 @@ spec = describe "Live Variable Analysis" $ do
10191001
calculated = (calcLiveness exp) { _registerEff = mempty, _functionEff = mempty }
10201002
calculated `sameAs` heapUpdateLocalExpected
10211003

1022-
it "lit_pat" $ do
1023-
let exp = [prog|
1024-
grinMain =
1025-
y <- pure 0
1026-
5 @ _1 <- f y
1027-
pure 0
1028-
1029-
f x = pure x
1030-
|]
1031-
let litPatExpected = emptyLVAResult
1032-
{ _memory = []
1033-
, _registerLv = [ ("y", liveVal)
1034-
, ("x", liveVal)
1035-
1036-
, ("_1", deadVal)
1037-
]
1038-
, _functionLv = litPatExpectedFunctions
1039-
}
1040-
litPatExpectedFunctions = mkFunctionLivenessMap
1041-
[ ("f", fun (liveVal, [liveVal])) ]
1042-
calculated = (calcLiveness exp) { _registerEff = mempty, _functionEff = mempty }
1043-
calculated `sameAs` litPatExpected
1044-
10451004
it "var_pat" $ do
10461005
let exp = [prog|
10471006
grinMain =

grin/test/AbstractInterpretation/ExtendedSyntax/OptimiseAbstractProgramSpec.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ testProgram = withPrimPrelude [prog|
9898
pure v
9999
(Fupto a b) @ alt.7 ->
100100
w <- upto $ a b
101-
() @ p.5 <- update q w
101+
p.5 <- update q w
102102
pure w
103103
(Fsum c) @ alt.8 ->
104104
z <- sum $ c
105-
() @ p.6 <- update q z
105+
p.6 <- update q z
106106
pure z
107-
108107
|]

grin/test/AbstractInterpretation/ExtendedSyntax/SharingSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ testProgram = withPrimPrelude [prog|
161161
pure v
162162
(Fupto a b) @ alt.7 ->
163163
w <- upto $ a b
164-
() @ p.5 <- update q w
164+
p.5 <- update q w
165165
pure w
166166
(Fsum c) @ alt.8 ->
167167
z <- sum $ c
168-
() @ p.6 <- update q z
168+
p.6 <- update q z
169169
pure z
170170
|]

grin/test/ExtendedSyntax/ParserSpec.hs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,6 @@ spec = do
6060
]
6161
before `sameAs` after
6262

63-
it "as-pat-unit" $ do
64-
let before = [prog|
65-
grinMain =
66-
()@v <- pure ()
67-
pure v
68-
|]
69-
let after = Program []
70-
[ Def "grinMain" [] $
71-
EBind (SReturn Unit) (AsPat "v" Unit) (SReturn $ Var "v")
72-
]
73-
before `sameAs` after
74-
75-
it "as-pat-lit" $ do
76-
let before = [prog|
77-
grinMain =
78-
5@v <- pure ()
79-
pure v
80-
|]
81-
let after = Program []
82-
[ Def "grinMain" [] $
83-
EBind (SReturn Unit) (AsPat "v" (Lit $ LInt64 5)) (SReturn $ Var "v")
84-
]
85-
before `sameAs` after
86-
8763
it "as-pat-nullary-node" $ do
8864
let before = [prog|
8965
grinMain =
@@ -92,7 +68,7 @@ spec = do
9268
|]
9369
let after = Program []
9470
[ Def "grinMain" [] $
95-
EBind (SReturn Unit) (AsPat "v" (ConstTagNode (Tag C "Nil") [])) (SReturn $ Var "v")
71+
EBind (SReturn Unit) (AsPat (Tag C "Nil") [] "v") (SReturn $ Var "v")
9672
]
9773
before `sameAs` after
9874

@@ -104,14 +80,14 @@ spec = do
10480
|]
10581
let after = Program []
10682
[ Def "grinMain" [] $
107-
EBind (SReturn Unit) (AsPat "v" (ConstTagNode (Tag C "Cons") ["x", "xs"])) (SReturn $ Var "v")
83+
EBind (SReturn Unit) (AsPat (Tag C "Cons") ["x", "xs"] "v") (SReturn $ Var "v")
10884
]
10985
before `sameAs` after
11086

11187
it "case" $ do
11288
let before = [prog|
11389
test p =
114-
()@_unit <- case p of
90+
(CNil)@_cNil <- case p of
11591
#default @ _1 ->
11692
pure ()
11793
case p of
@@ -120,7 +96,7 @@ spec = do
12096
|]
12197
let after = Program []
12298
[ Def "test"[ "p" ]
123-
( EBind ( ECase "p" [ Alt DefaultPat "_1" ( SReturn Unit ) ] ) (AsPat "_unit" Unit)
99+
( EBind ( ECase "p" [ Alt DefaultPat "_1" ( SReturn Unit ) ] ) (AsPat (Tag C "Nil") [] "_cNil")
124100
( ECase "p" [ Alt DefaultPat "_2" ( SReturn (Var "p") ) ] )
125101
)
126102
]
@@ -325,7 +301,6 @@ spec = do
325301
#"" @ _1 -> pure 1
326302
#"a" @ _2 -> pure 2
327303
#default @ _3 -> pure 3
328-
#"a" @ _x <- pure v2
329304
pure ()
330305
|]
331306
let after = Program []
@@ -337,7 +312,6 @@ spec = do
337312
,Alt (LitPat (LString "a")) "_2" (SReturn (Lit (LInt64 2)))
338313
,Alt DefaultPat "_3" (SReturn (Lit (LInt64 3)))
339314
]) (VarPat "v3") $
340-
EBind (SReturn $ Var "v2") (AsPat "_x" $ (Lit (LString "a"))) $
341315
SReturn Unit
342316
]
343317
before `sameAs` after
@@ -350,7 +324,6 @@ spec = do
350324
#'b' @ _1 -> pure 1
351325
#'c' @ _2 -> pure 2
352326
#default @ _3 -> pure 3
353-
#'a' @ _c <- pure v2
354327
pure ()
355328
|]
356329
let after = Program []
@@ -361,7 +334,6 @@ spec = do
361334
,Alt (LitPat (LChar 'c')) "_2" (SReturn (Lit (LInt64 2)))
362335
,Alt DefaultPat "_3" (SReturn (Lit (LInt64 3)))
363336
]) (VarPat "v3") $
364-
EBind (SReturn $ Var "v2") (AsPat "_c" $ Lit (LChar 'a')) $
365337
SReturn Unit
366338
]
367339
before `sameAs` after

grin/test/Transformations/ExtendedSyntax/Optimising/CopyPropagationSpec.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ spec = do
5959
|]
6060
copyPropagation (ctx before) `sameAs` (ctx after)
6161

62-
it "does not propagate literal values" $ do
63-
let before = [expr|
64-
a1 <- pure 1
65-
a2 <- pure a1
66-
0 @ _1 <- pure a2
67-
1 @ _2 <- pure a2
68-
pure a2
69-
|]
70-
let after = [expr|
71-
a1 <- pure 1
72-
0 @ _1 <- pure a1
73-
1 @ _2 <- pure a1
74-
pure a1
75-
|]
76-
copyPropagation (ctx before) `sameAs` (ctx after)
77-
7862
it "node value - node pattern" $ do
7963
let before = [expr|
8064
a1 <- pure 1

0 commit comments

Comments
 (0)