diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2015-12-21 16:11:25 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-12-21 19:09:55 +0100 |
commit | ee6fba89b066fdf8408e6a18db343a4177e613f6 (patch) | |
tree | f60d6c0495bbfdaf29ff642caaf4deefb717b25d /testsuite/tests/generics | |
parent | 99b956ef1d4bbb2252c0bbaa956094c2f837d111 (diff) | |
download | haskell-ee6fba89b066fdf8408e6a18db343a4177e613f6.tar.gz |
Encode strictness in GHC generics metadata
This augments `MetaSel` with a `Bang` field, which gives generic
programmers access to the following information about each field
selector:
* `SourceUnpackedness`: whether a field was marked `{-# NOUNPACK #-}`,
`{-# UNPACK #-}`, or not
* `SourceStrictness`: whether a field was given a strictness (`!`) or
laziness (`~`) annotation
* `DecidedStrictness`: what strictness GHC infers for a field during
compilation, which may be influenced by optimization levels,
`-XStrictData`, `-funbox-strict-fields`, etc.
Unlike in Phab:D1603, generics does not grant a programmer the ability
to "splice" in metadata, so there is no issue including
`DecidedStrictness` with `Bang` (whereas in Template Haskell, it had to
be split off).
One consequence of this is that `MetaNoSel` had to be removed, since it
became redundant. The `NoSelector` empty data type was also removed for
similar reasons.
Fixes #10716.
Test Plan: ./validate
Reviewers: dreixel, goldfire, kosmikus, austin, hvr, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1646
GHC Trac Issues: #10716
Diffstat (limited to 'testsuite/tests/generics')
-rw-r--r-- | testsuite/tests/generics/GFullyStrict.hs | 57 | ||||
-rw-r--r-- | testsuite/tests/generics/GFullyStrict.stdout | 2 | ||||
-rw-r--r-- | testsuite/tests/generics/GenDerivOutput.stderr | 50 | ||||
-rw-r--r-- | testsuite/tests/generics/GenDerivOutput1_0.stderr | 28 | ||||
-rw-r--r-- | testsuite/tests/generics/GenDerivOutput1_1.stderr | 200 | ||||
-rw-r--r-- | testsuite/tests/generics/all.T | 2 |
6 files changed, 253 insertions, 86 deletions
diff --git a/testsuite/tests/generics/GFullyStrict.hs b/testsuite/tests/generics/GFullyStrict.hs new file mode 100644 index 0000000000..7c879d9877 --- /dev/null +++ b/testsuite/tests/generics/GFullyStrict.hs @@ -0,0 +1,57 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeOperators #-} +module Main where + +import Data.Proxy (Proxy(..)) +import GHC.Generics + +main :: IO () +main = do + print (fullyStrict (Proxy :: Proxy (StrictMaybe Bool))) + print (fullyStrict (Proxy :: Proxy (Maybe Bool))) + +data StrictMaybe a = StrictNothing | StrictJust !a + deriving (FullyStrict, Generic) + +instance FullyStrict Bool +instance FullyStrict a => FullyStrict (Maybe a) + +class FullyStrict a where + fullyStrict :: proxy a -> Bool + default fullyStrict :: (GFullyStrict (Rep a)) => proxy a -> Bool + fullyStrict _ = gfullyStrict (Proxy :: Proxy (Rep a p)) + +class GFullyStrict f where + gfullyStrict :: proxy (f p) -> Bool + +instance GFullyStrict V1 where + gfullyStrict _ = True + +instance GFullyStrict U1 where + gfullyStrict _ = True + +instance FullyStrict c => GFullyStrict (Rec0 c) where + gfullyStrict _ = fullyStrict (Proxy :: Proxy c) + +instance GFullyStrict f => GFullyStrict (D1 c f) where + gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p)) + +instance GFullyStrict f => GFullyStrict (C1 c f) where + gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p)) + +instance (GFullyStrict f, Selector c) => GFullyStrict (S1 c f) where + gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p)) + && selDecidedStrictness (undefined :: S1 c f p) /= DecidedLazy + +instance (GFullyStrict f, GFullyStrict g) => GFullyStrict (f :+: g) where + gfullyStrict _ = + gfullyStrict (Proxy :: Proxy (f p)) && gfullyStrict (Proxy :: Proxy (g p)) + +instance (GFullyStrict f, GFullyStrict g) => GFullyStrict (f :*: g) where + gfullyStrict _ = + gfullyStrict (Proxy :: Proxy (f p)) && gfullyStrict (Proxy :: Proxy (g p)) diff --git a/testsuite/tests/generics/GFullyStrict.stdout b/testsuite/tests/generics/GFullyStrict.stdout new file mode 100644 index 0000000000..1cc8b5e10d --- /dev/null +++ b/testsuite/tests/generics/GFullyStrict.stdout @@ -0,0 +1,2 @@ +True +False diff --git a/testsuite/tests/generics/GenDerivOutput.stderr b/testsuite/tests/generics/GenDerivOutput.stderr index 6197da3d03..de11f431e9 100644 --- a/testsuite/tests/generics/GenDerivOutput.stderr +++ b/testsuite/tests/generics/GenDerivOutput.stderr @@ -109,11 +109,19 @@ GHC.Generics representation types: 'GHC.Types.True) (GHC.Generics.S1 ('GHC.Generics.MetaSel - "element") + ('GHC.Base.Just + "element") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec0 a) GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "rest") + ('GHC.Base.Just + "rest") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec0 (GenDerivOutput.List a)))) @@ -131,11 +139,19 @@ GHC.Generics representation types: 'GHC.Types.True) (GHC.Generics.S1 ('GHC.Generics.MetaSel - "element") + ('GHC.Base.Just + "element") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) GHC.Generics.Par1 GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "rest") + ('GHC.Base.Just + "rest") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec1 GenDerivOutput.List))) type GHC.Generics.Rep (GenDerivOutput.Rose a) = GHC.Generics.D1 @@ -156,10 +172,18 @@ GHC.Generics representation types: 'GHC.Generics.PrefixI 'GHC.Types.False) (GHC.Generics.S1 - 'GHC.Generics.MetaNoSel + ('GHC.Generics.MetaSel + 'GHC.Base.Nothing + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec0 a) GHC.Generics.:*: GHC.Generics.S1 - 'GHC.Generics.MetaNoSel + ('GHC.Generics.MetaSel + 'GHC.Base.Nothing + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec0 (GenDerivOutput.List (GenDerivOutput.Rose @@ -179,10 +203,20 @@ GHC.Generics representation types: 'GHC.Generics.PrefixI 'GHC.Types.False) (GHC.Generics.S1 - 'GHC.Generics.MetaNoSel + ('GHC.Generics.MetaSel + 'GHC.Base.Nothing + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) GHC.Generics.Par1 GHC.Generics.:*: GHC.Generics.S1 - 'GHC.Generics.MetaNoSel + ('GHC.Generics.MetaSel + 'GHC.Base.Nothing + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) (GenDerivOutput.List GHC.Generics.:.: GHC.Generics.Rec1 GenDerivOutput.Rose))) + + diff --git a/testsuite/tests/generics/GenDerivOutput1_0.stderr b/testsuite/tests/generics/GenDerivOutput1_0.stderr index 0757b128ca..0f4df6275a 100644 --- a/testsuite/tests/generics/GenDerivOutput1_0.stderr +++ b/testsuite/tests/generics/GenDerivOutput1_0.stderr @@ -23,31 +23,39 @@ Derived instances: GHC.Generics representation types: - type GHC.Generics.Rep1 GenDerivOutput1_0.List = GHC.Generics.D1 + type GHC.Generics.Rep1 GenDerivOutput1_0.List = GHC.Generics.D1 ('GHC.Generics.MetaData "List" "GenDerivOutput1_0" "main" 'GHC.Types.False) - (GHC.Generics.C1 + (GHC.Generics.C1 ('GHC.Generics.MetaCons "Nil" 'GHC.Generics.PrefixI 'GHC.Types.False) GHC.Generics.U1 - GHC.Generics.:+: GHC.Generics.C1 + GHC.Generics.:+: GHC.Generics.C1 ('GHC.Generics.MetaCons "Cons" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 + (GHC.Generics.S1 ('GHC.Generics.MetaSel - "element") - GHC.Generics.Par1 - GHC.Generics.:*: GHC.Generics.S1 + ('GHC.Base.Just + "element") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + GHC.Generics.Par1 + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "rest") - (GHC.Generics.Rec1 - GenDerivOutput1_0.List))) + ('GHC.Base.Just + "rest") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + GenDerivOutput1_0.List))) diff --git a/testsuite/tests/generics/GenDerivOutput1_1.stderr b/testsuite/tests/generics/GenDerivOutput1_1.stderr index 736637f6c2..d76d6bb593 100644 --- a/testsuite/tests/generics/GenDerivOutput1_1.stderr +++ b/testsuite/tests/generics/GenDerivOutput1_1.stderr @@ -155,7 +155,7 @@ Derived instances: GHC.Generics representation types: - type GHC.Generics.Rep1 CanDoRep1_1.Dd = GHC.Generics.D1 + type GHC.Generics.Rep1 CanDoRep1_1.Dd = GHC.Generics.D1 ('GHC.Generics.MetaData "Dd" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -167,15 +167,23 @@ GHC.Generics representation types: "D1d" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11d") - GHC.Generics.Par1 - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11d") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + GHC.Generics.Par1 + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12d") - (GHC.Generics.Rec1 - CanDoRep1_1.Dd))) - type GHC.Generics.Rep (CanDoRep1_1.Dd a) = GHC.Generics.D1 + ('GHC.Base.Just + "d12d") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + CanDoRep1_1.Dd))) + type GHC.Generics.Rep (CanDoRep1_1.Dd a) = GHC.Generics.D1 ('GHC.Generics.MetaData "Dd" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -187,16 +195,24 @@ GHC.Generics representation types: "D1d" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11d") - (GHC.Generics.Rec0 a) - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11d") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 a) + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12d") - (GHC.Generics.Rec0 - (CanDoRep1_1.Dd - a)))) - type GHC.Generics.Rep (CanDoRep1_1.Dc a) = GHC.Generics.D1 + ('GHC.Base.Just + "d12d") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 + (CanDoRep1_1.Dd + a)))) + type GHC.Generics.Rep (CanDoRep1_1.Dc a) = GHC.Generics.D1 ('GHC.Generics.MetaData "Dc" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -208,16 +224,24 @@ GHC.Generics representation types: "D1c" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11c") - (GHC.Generics.Rec0 a) - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11c") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 a) + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12c") - (GHC.Generics.Rec0 - (CanDoRep1_1.Dc - a)))) - type GHC.Generics.Rep1 CanDoRep1_1.Db = GHC.Generics.D1 + ('GHC.Base.Just + "d12c") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 + (CanDoRep1_1.Dc + a)))) + type GHC.Generics.Rep1 CanDoRep1_1.Db = GHC.Generics.D1 ('GHC.Generics.MetaData "Db" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -229,15 +253,23 @@ GHC.Generics representation types: "D1b" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11b") - GHC.Generics.Par1 - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11b") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + GHC.Generics.Par1 + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12b") - (GHC.Generics.Rec1 - CanDoRep1_1.Db))) - type GHC.Generics.Rep (CanDoRep1_1.Da a) = GHC.Generics.D1 + ('GHC.Base.Just + "d12b") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + CanDoRep1_1.Db))) + type GHC.Generics.Rep (CanDoRep1_1.Da a) = GHC.Generics.D1 ('GHC.Generics.MetaData "Da" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -249,16 +281,24 @@ GHC.Generics representation types: "D1" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11a") - (GHC.Generics.Rec0 a) - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11a") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 a) + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12a") - (GHC.Generics.Rec0 - (CanDoRep1_1.Da - a)))) - type GHC.Generics.Rep1 CanDoRep1_1.Da = GHC.Generics.D1 + ('GHC.Base.Just + "d12a") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 + (CanDoRep1_1.Da + a)))) + type GHC.Generics.Rep1 CanDoRep1_1.Da = GHC.Generics.D1 ('GHC.Generics.MetaData "Da" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -270,15 +310,23 @@ GHC.Generics representation types: "D1" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11a") - GHC.Generics.Par1 - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11a") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + GHC.Generics.Par1 + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12a") - (GHC.Generics.Rec1 - CanDoRep1_1.Da))) - type GHC.Generics.Rep (CanDoRep1_1.Db a) = GHC.Generics.D1 + ('GHC.Base.Just + "d12a") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + CanDoRep1_1.Da))) + type GHC.Generics.Rep (CanDoRep1_1.Db a) = GHC.Generics.D1 ('GHC.Generics.MetaData "Db" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -290,16 +338,24 @@ GHC.Generics representation types: "D1b" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11b") - (GHC.Generics.Rec0 a) - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11b") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 a) + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12b") - (GHC.Generics.Rec0 - (CanDoRep1_1.Db - a)))) - type GHC.Generics.Rep1 CanDoRep1_1.Dc = GHC.Generics.D1 + ('GHC.Base.Just + "d12b") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec0 + (CanDoRep1_1.Db + a)))) + type GHC.Generics.Rep1 CanDoRep1_1.Dc = GHC.Generics.D1 ('GHC.Generics.MetaData "Dc" "CanDoRep1_1" "main" 'GHC.Types.False) (GHC.Generics.C1 @@ -311,13 +367,21 @@ GHC.Generics representation types: "D1c" 'GHC.Generics.PrefixI 'GHC.Types.True) - (GHC.Generics.S1 - ('GHC.Generics.MetaSel "d11c") - GHC.Generics.Par1 - GHC.Generics.:*: GHC.Generics.S1 + (GHC.Generics.S1 + ('GHC.Generics.MetaSel + ('GHC.Base.Just "d11c") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + GHC.Generics.Par1 + GHC.Generics.:*: GHC.Generics.S1 ('GHC.Generics.MetaSel - "d12c") - (GHC.Generics.Rec1 - CanDoRep1_1.Dc))) + ('GHC.Base.Just + "d12c") + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + CanDoRep1_1.Dc))) diff --git a/testsuite/tests/generics/all.T b/testsuite/tests/generics/all.T index cbf70cf8bf..32534834f2 100644 --- a/testsuite/tests/generics/all.T +++ b/testsuite/tests/generics/all.T @@ -17,6 +17,8 @@ test('GenCannotDoRep1_6', normal, compile_fail, ['']) test('GenCannotDoRep1_7', normal, compile_fail, ['']) test('GenCannotDoRep1_8', normal, compile_fail, ['']) +test('GFullyStrict', normal, compile_and_run, ['']) + test('T5462Yes1', outputdir('out_T5462Yes1') , multimod_compile_and_run, ['T5462Yes1', '-iGEq -iGEnum -iGFunctor']) test('T5462Yes2', outputdir('out_T5462Yes2') |