on master help sign in
Switch from ghc-proofs to inspection-testing (#15)

* Switch from ghc-proofs to inspection-testing While ghc-proofs is a nice hack, it is actually unsuitable for this kind of testing, as it optimizes the terms differently than GHC (and more aggressivley). Therefore I have created the inspection-testing package, which _really_ checks the output of GHC’s optimization pipeline, and is equivalent to manually checking the output of `-ddump-simpl`. It turns out that the tests in the test suite do not pass with GHC-8.0.2; I am not sure why that is. Insufficient inlining? CSE failure? With GHC-8.2 we get the desired result. I use CPP to disable the tests that do not work on GHC-8.0. If you can get it to work again, then just remove the `#if` stanzas. * Mention inspection-testing in the stack.yaml file

commit85974a2a1984133e02df56b3f371d214104fd161 authorJoachim Breitner <mail@joachim-breitner.de> dateFri 10 Nov 2017, 13:38 (9 years ago) parent126299c
3 files changed+29−16
generic-lens.cabal+1−1 stack.yaml+1−1 test/Spec.hs+27−14
generic-lens.cabal+1−1
@@ -68,7 +68,7 @@ test-suite generic-lens-test
6868
6969 build-depends: base >= 4.9 && <= 5.0
7070 , generic-lens
71− , ghc-proofs >= 0.1.1
71+ , inspection-testing >= 0.1
7272
7373 default-language: Haskell2010
7474 ghc-options: -Wall
stack.yaml+1−1
@@ -4,7 +4,7 @@ packages:
44- '.'
55
66extra-deps:
7−- 'ghc-proofs-0.1.1'
7+- 'inspection-testing-0.1'
88
99flags: {}
1010
test/Spec.hs+27−14
@@ -1,4 +1,4 @@
1−{-# OPTIONS_GHC -O -fplugin GHC.Proof.Plugin #-}
1+{-# OPTIONS_GHC -O -fplugin Test.Inspection.Plugin #-}
22
33{-# LANGUAGE AllowAmbiguousTypes #-}
44{-# LANGUAGE DataKinds #-}
@@ -8,12 +8,16 @@
88{-# LANGUAGE RankNTypes #-}
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE TemplateHaskell #-}
12+{-# LANGUAGE CPP #-}
1113
1214module Main where
1315
1416import GHC.Generics
1517import Data.Generics.Product
16−import GHC.Proof
18+#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
19+import Test.Inspection
20+#endif
1721
1822main :: IO ()
1923main = putStrLn "Hello world"
@@ -42,19 +46,28 @@ subtypeLensManual f record
4246
4347--------------------------------------------------------------------------------
4448-- * Tests
45−-- The ghc-proofs plugin checks that the following equalities hold, by checking
46−-- that the LHSs and the RHSs are CSEd. This also means that the runtime
47−-- characteristics of the derived lenses is the same as the manually written
48−-- ones above.
49+-- The inspection-testing plugin checks that the following equalities hold, by
50+-- checking that the LHSs and the RHSs are CSEd. This also means that the
51+-- runtime characteristics of the derived lenses is the same as the manually
52+-- written ones above.
4953
50−fieldP :: Proof
51−fieldP = L fieldALensManual === L (field @"fieldA")
54+fieldALensName :: Lens' Record Int
55+fieldALensName = field @"fieldA"
5256
53−typedP :: Proof
54−typedP = L fieldALensManual === L (typed @Int)
57+fieldALensType :: Lens' Record Int
58+fieldALensType = typed @Int
5559
56−posP :: Proof
57−posP = L fieldALensManual === L (position @1)
60+fieldALensPos :: Lens' Record Int
61+fieldALensPos = position @1
5862
59−subtypeP :: Proof
60−subtypeP = L subtypeLensManual === L super
63+subtypeLensGeneric :: Lens' Record Record2
64+subtypeLensGeneric = super
65+
66+#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
67+-- It turns out that these equalities only hold with ghc-8.2 or newer,
68+-- probably due to improvements to CSE
69+inspect $ 'fieldALensManual === 'fieldALensName
70+inspect $ 'fieldALensManual === 'fieldALensType
71+inspect $ 'fieldALensManual === 'fieldALensPos
72+inspect $ 'subtypeLensManual === 'subtypeLensGeneric
73+#endif