summaryrefslogtreecommitdiff
path: root/compiler/basicTypes/BasicTypes.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2016-09-30 20:15:25 -0400
committerBen Gamari <ben@smart-cactus.org>2016-09-30 23:23:44 -0400
commit9e862765ffe161da8a4fd9cd67b0a600874feaa9 (patch)
tree235c1ba702b0101e1fa6a8fe7f8146e2c7ec9c69 /compiler/basicTypes/BasicTypes.hs
parentb3d55e20d20344bfc09f4ca4a554a819c4ecbfa8 (diff)
downloadhaskell-9e862765ffe161da8a4fd9cd67b0a600874feaa9.tar.gz
Implement deriving strategies
Allows users to explicitly request which approach to `deriving` to use via keywords, e.g., ``` newtype Foo = Foo Bar deriving Eq deriving stock Ord deriving newtype Show ``` Fixes #10598. Updates haddock submodule. Test Plan: ./validate Reviewers: hvr, kosmikus, goldfire, alanz, bgamari, simonpj, austin, erikd, simonmar Reviewed By: alanz, bgamari, simonpj Subscribers: thomie, mpickering, oerjan Differential Revision: https://phabricator.haskell.org/D2280 GHC Trac Issues: #10598
Diffstat (limited to 'compiler/basicTypes/BasicTypes.hs')
-rw-r--r--compiler/basicTypes/BasicTypes.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler/basicTypes/BasicTypes.hs b/compiler/basicTypes/BasicTypes.hs
index aab0528d1c..0429a43f5d 100644
--- a/compiler/basicTypes/BasicTypes.hs
+++ b/compiler/basicTypes/BasicTypes.hs
@@ -41,6 +41,8 @@ module BasicTypes(
TopLevelFlag(..), isTopLevel, isNotTopLevel,
+ DerivStrategy(..),
+
OverlapFlag(..), OverlapMode(..), setOverlapModeMaybe,
hasOverlappingFlag, hasOverlappableFlag, hasIncoherentFlag,
@@ -479,6 +481,30 @@ instance Outputable Origin where
{-
************************************************************************
* *
+ Deriving strategies
+* *
+************************************************************************
+-}
+
+-- | Which technique the user explicitly requested when deriving an instance.
+data DerivStrategy
+ -- See Note [Deriving strategies] in TcDeriv
+ = DerivStock -- ^ GHC's \"standard\" strategy, which is to implement a
+ -- custom instance for the data type. This only works for
+ -- certain types that GHC knows about (e.g., 'Eq', 'Show',
+ -- 'Functor' when @-XDeriveFunctor@ is enabled, etc.)
+ | DerivAnyclass -- ^ @-XDeriveAnyClass@
+ | DerivNewtype -- ^ @-XGeneralizedNewtypeDeriving@
+ deriving (Eq, Data)
+
+instance Outputable DerivStrategy where
+ ppr DerivStock = text "stock"
+ ppr DerivAnyclass = text "anyclass"
+ ppr DerivNewtype = text "newtype"
+
+{-
+************************************************************************
+* *
Instance overlap flag
* *
************************************************************************