File tree Expand file tree Collapse file tree 3 files changed +92
-0
lines changed
test/Transformations/ExtendedSyntax/Optimising Expand file tree Collapse file tree 3 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -299,6 +299,8 @@ test-suite grin-test
299299 Transformations.ExtendedSyntax.ConversionSpec
300300 Transformations.ExtendedSyntax.MangleNamesSpec
301301 Transformations.ExtendedSyntax.StaticSingleAssignmentSpec
302+ Transformations.ExtendedSyntax.Optimising.EvaluatedCaseEliminationSpec
303+ Transformations.ExtendedSyntax.Optimising.TrivialCaseEliminationSpec
302304
303305 Transformations.Simplifying.RegisterIntroductionSpec
304306 Transformations.Simplifying.CaseSimplificationSpec
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE OverloadedStrings, QuasiQuotes, ViewPatterns #-}
2+ module Transformations.ExtendedSyntax.Optimising.EvaluatedCaseEliminationSpec where
3+
4+ import Transformations.Optimising.EvaluatedCaseElimination
5+
6+ import Test.Hspec
7+ import Grin.TH
8+ import Test.Test hiding (newVar )
9+ import Test.Assertions
10+
11+
12+ runTests :: IO ()
13+ runTests = hspec spec
14+
15+ spec :: Spec
16+ spec = do
17+ testExprContextE $ \ ctx -> do
18+ it " Figure 4.22" $ do
19+ let before = [expr |
20+ case v of
21+ (CLeft l) -> pure v
22+ (CRight r) -> pure v
23+ |]
24+ let after = [expr |
25+ pure v
26+ |]
27+ evaluatedCaseElimination (ctx before) `sameAs` (ctx after)
28+
29+ it " default case" $ do
30+ let before = [expr |
31+ case v of
32+ (CLeft l) -> pure v
33+ #default -> pure v
34+ |]
35+ let after = [expr |
36+ pure v
37+ |]
38+ evaluatedCaseElimination (ctx before) `sameAs` (ctx after)
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE OverloadedStrings, QuasiQuotes, ViewPatterns #-}
2+ module Transformations.ExtendedSyntax.Optimising.TrivialCaseEliminationSpec where
3+
4+ import Transformations.Optimising.TrivialCaseElimination
5+
6+ import Test.Hspec
7+ import Grin.TH
8+ import Test.Test hiding (newVar )
9+ import Test.Assertions
10+
11+
12+ runTests :: IO ()
13+ runTests = hspec spec
14+
15+ spec :: Spec
16+ spec = do
17+ testExprContextE $ \ ctx -> do
18+ it " Figure 4.24" $ do
19+ let before = [expr |
20+ case v of
21+ (Ffun a1 a2 a3) -> fun a1 a2 a3
22+ |]
23+ let after = [expr |
24+ do
25+ (Ffun a1 a2 a3) <- pure v
26+ fun a1 a2 a3
27+ |]
28+ trivialCaseElimination (ctx before) `sameAs` (ctx after)
29+
30+ it " bypass" $ do
31+ let before = [expr |
32+ case v of
33+ (Ffun1 a1 a2 a3) -> fun1 a1 a2 a3
34+ #default -> pure 2
35+ |]
36+ let after = [expr |
37+ case v of
38+ (Ffun1 a1 a2 a3) -> fun1 a1 a2 a3
39+ #default -> pure 2
40+ |]
41+ trivialCaseElimination (ctx before) `sameAs` (ctx after)
42+
43+ it " default alternative" $ do
44+ let before = [expr |
45+ case v of
46+ #default -> pure 2
47+ |]
48+ let after = [expr |
49+ do
50+ pure 2
51+ |]
52+ trivialCaseElimination (ctx before) `sameAs` (ctx after)
You can’t perform that action at this time.
0 commit comments