diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2017-05-19 14:56:09 +0200 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2017-06-06 00:16:20 +0200 |
commit | 8e6ec0fa7431b0454b09c0011a615f0845df1198 (patch) | |
tree | d6b3604e0ceac3d81d0510669f7ccce9a2bf3ae2 /compiler/hsSyn/HsDecls.hs | |
parent | c9eb4385aad248118650725b7b699bb97ee21c0d (diff) | |
download | haskell-8e6ec0fa7431b0454b09c0011a615f0845df1198.tar.gz |
Udate hsSyn AST to use Trees that Grow
Summary:
See https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow
This commit prepares the ground for a full extensible AST, by replacing the type
parameter for the hsSyn data types with a set of indices into type families,
data GhcPs -- ^ Index for GHC parser output
data GhcRn -- ^ Index for GHC renamer output
data GhcTc -- ^ Index for GHC typechecker output
These are now used instead of `RdrName`, `Name` and `Id`/`TcId`/`Var`
Where the original name type is required in a polymorphic context, this is
accessible via the IdP type family, defined as
type family IdP p
type instance IdP GhcPs = RdrName
type instance IdP GhcRn = Name
type instance IdP GhcTc = Id
These types are declared in the new 'hsSyn/HsExtension.hs' module.
To gain a better understanding of the extension mechanism, it has been applied
to `HsLit` only, also replacing the `SourceText` fields in them with extension
types.
To preserve extension generality, a type class is introduced to capture the
`SourceText` interface, which must be honoured by all of the extension points
which originally had a `SourceText`. The class is defined as
class HasSourceText a where
-- Provide setters to mimic existing constructors
noSourceText :: a
sourceText :: String -> a
setSourceText :: SourceText -> a
getSourceText :: a -> SourceText
And the constraint is captured in `SourceTextX`, which is a constraint type
listing all the extension points that make use of the class.
Updating Haddock submodule to match.
Test Plan: ./validate
Reviewers: simonpj, shayan-najd, goldfire, austin, bgamari
Subscribers: rwbarton, thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D3609
Diffstat (limited to 'compiler/hsSyn/HsDecls.hs')
-rw-r--r-- | compiler/hsSyn/HsDecls.hs | 531 |
1 files changed, 281 insertions, 250 deletions
diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs index 7fcc3b8699..8b7d9c6a40 100644 --- a/compiler/hsSyn/HsDecls.hs +++ b/compiler/hsSyn/HsDecls.hs @@ -98,7 +98,8 @@ import Name import BasicTypes import Coercion import ForeignCall -import PlaceHolder ( PostTc,PostRn,PlaceHolder(..),DataId, OutputableBndrId ) +import PlaceHolder ( PlaceHolder(..) ) +import HsExtension import NameSet -- others: @@ -251,7 +252,8 @@ appendGroups hs_vects = vects1 ++ vects2, hs_docs = docs1 ++ docs2 } -instance (OutputableBndrId name) => Outputable (HsDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (HsDecl pass) where ppr (TyClD dcl) = ppr dcl ppr (ValD binds) = ppr binds ppr (DefD def) = ppr def @@ -267,7 +269,8 @@ instance (OutputableBndrId name) => Outputable (HsDecl name) where ppr (DocD doc) = ppr doc ppr (RoleAnnotD ra) = ppr ra -instance (OutputableBndrId name) => Outputable (HsGroup name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (HsGroup pass) where ppr (HsGroup { hs_valds = val_decls, hs_tyclds = tycl_decls, hs_derivds = deriv_decls, @@ -302,7 +305,7 @@ instance (OutputableBndrId name) => Outputable (HsGroup name) where vcat_mb gap (Just d : ds) = gap $$ d $$ vcat_mb blankLine ds -- | Located Splice Declaration -type LSpliceDecl name = Located (SpliceDecl name) +type LSpliceDecl pass = Located (SpliceDecl pass) -- | Splice Declaration data SpliceDecl id @@ -311,7 +314,8 @@ data SpliceDecl id SpliceExplicitFlag deriving instance (DataId id) => Data (SpliceDecl id) -instance (OutputableBndrId name) => Outputable (SpliceDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (SpliceDecl pass) where ppr (SpliceDecl (L _ e) f) = pprSpliceDecl e f {- @@ -454,10 +458,10 @@ Interface file code: -} -- | Located Declaration of a Type or Class -type LTyClDecl name = Located (TyClDecl name) +type LTyClDecl pass = Located (TyClDecl pass) -- | A type or class declaration. -data TyClDecl name +data TyClDecl pass = -- | @type/data family T :: *->*@ -- -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnType', @@ -469,7 +473,7 @@ data TyClDecl name -- 'ApiAnnotation.AnnVbar' -- For details on above see note [Api annotations] in ApiAnnotation - FamDecl { tcdFam :: FamilyDecl name } + FamDecl { tcdFam :: FamilyDecl pass } | -- | @type@ declaration -- @@ -477,12 +481,13 @@ data TyClDecl name -- 'ApiAnnotation.AnnEqual', -- For details on above see note [Api annotations] in ApiAnnotation - SynDecl { tcdLName :: Located name -- ^ Type constructor - , tcdTyVars :: LHsQTyVars name -- ^ Type variables; for an associated type - -- these include outer binders + SynDecl { tcdLName :: Located (IdP pass) -- ^ Type constructor + , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an + -- associated type these + -- include outer binders , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration - , tcdRhs :: LHsType name -- ^ RHS of type declaration - , tcdFVs :: PostRn name NameSet } + , tcdRhs :: LHsType pass -- ^ RHS of type declaration + , tcdFVs :: PostRn pass NameSet } | -- | @data@ declaration -- @@ -493,31 +498,33 @@ data TyClDecl name -- 'ApiAnnotation.AnnWhere', -- For details on above see note [Api annotations] in ApiAnnotation - DataDecl { tcdLName :: Located name -- ^ Type constructor - , tcdTyVars :: LHsQTyVars name -- ^ Type variables; for an associated type - -- these include outer binders - -- Eg class T a where - -- type F a :: * - -- type F a = a -> a - -- Here the type decl for 'f' includes 'a' - -- in its tcdTyVars + DataDecl { tcdLName :: Located (IdP pass) -- ^ Type constructor + , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an + -- associated type + -- these include outer binders + -- Eg class T a where + -- type F a :: * + -- type F a = a -> a + -- Here the type decl for 'f' + -- includes 'a' in its tcdTyVars , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration - , tcdDataDefn :: HsDataDefn name - , tcdDataCusk :: PostRn name Bool -- ^ does this have a CUSK? - , tcdFVs :: PostRn name NameSet } + , tcdDataDefn :: HsDataDefn pass + , tcdDataCusk :: PostRn pass Bool -- ^ does this have a CUSK? + , tcdFVs :: PostRn pass NameSet } - | ClassDecl { tcdCtxt :: LHsContext name, -- ^ Context... - tcdLName :: Located name, -- ^ Name of the class - tcdTyVars :: LHsQTyVars name, -- ^ Class type variables + | ClassDecl { tcdCtxt :: LHsContext pass, -- ^ Context... + tcdLName :: Located (IdP pass), -- ^ Name of the class + tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration - tcdFDs :: [Located (FunDep (Located name))], + tcdFDs :: [Located (FunDep (Located (IdP pass)))], -- ^ Functional deps - tcdSigs :: [LSig name], -- ^ Methods' signatures - tcdMeths :: LHsBinds name, -- ^ Default methods - tcdATs :: [LFamilyDecl name], -- ^ Associated types; - tcdATDefs :: [LTyFamDefltEqn name], -- ^ Associated type defaults + tcdSigs :: [LSig pass], -- ^ Methods' signatures + tcdMeths :: LHsBinds pass, -- ^ Default methods + tcdATs :: [LFamilyDecl pass], -- ^ Associated types; + tcdATDefs :: [LTyFamDefltEqn pass], + -- ^ Associated type defaults tcdDocs :: [LDocDecl], -- ^ Haddock docs - tcdFVs :: PostRn name NameSet + tcdFVs :: PostRn pass NameSet } -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnClass', -- 'ApiAnnotation.AnnWhere','ApiAnnotation.AnnOpen', @@ -536,27 +543,27 @@ deriving instance (DataId id) => Data (TyClDecl id) -- | @True@ <=> argument is a @data@\/@newtype@ -- declaration. -isDataDecl :: TyClDecl name -> Bool +isDataDecl :: TyClDecl pass -> Bool isDataDecl (DataDecl {}) = True isDataDecl _other = False -- | type or type instance declaration -isSynDecl :: TyClDecl name -> Bool +isSynDecl :: TyClDecl pass -> Bool isSynDecl (SynDecl {}) = True isSynDecl _other = False -- | type class -isClassDecl :: TyClDecl name -> Bool +isClassDecl :: TyClDecl pass -> Bool isClassDecl (ClassDecl {}) = True isClassDecl _ = False -- | type/data family declaration -isFamilyDecl :: TyClDecl name -> Bool +isFamilyDecl :: TyClDecl pass -> Bool isFamilyDecl (FamDecl {}) = True isFamilyDecl _other = False -- | type family declaration -isTypeFamilyDecl :: TyClDecl name -> Bool +isTypeFamilyDecl :: TyClDecl pass -> Bool isTypeFamilyDecl (FamDecl (FamilyDecl { fdInfo = info })) = case info of OpenTypeFamily -> True ClosedTypeFamily {} -> True @@ -564,42 +571,42 @@ isTypeFamilyDecl (FamDecl (FamilyDecl { fdInfo = info })) = case info of isTypeFamilyDecl _ = False -- | open type family info -isOpenTypeFamilyInfo :: FamilyInfo name -> Bool +isOpenTypeFamilyInfo :: FamilyInfo pass -> Bool isOpenTypeFamilyInfo OpenTypeFamily = True isOpenTypeFamilyInfo _ = False -- | closed type family info -isClosedTypeFamilyInfo :: FamilyInfo name -> Bool +isClosedTypeFamilyInfo :: FamilyInfo pass -> Bool isClosedTypeFamilyInfo (ClosedTypeFamily {}) = True isClosedTypeFamilyInfo _ = False -- | data family declaration -isDataFamilyDecl :: TyClDecl name -> Bool +isDataFamilyDecl :: TyClDecl pass -> Bool isDataFamilyDecl (FamDecl (FamilyDecl { fdInfo = DataFamily })) = True isDataFamilyDecl _other = False -- Dealing with names -tyFamInstDeclName :: TyFamInstDecl name -> name +tyFamInstDeclName :: TyFamInstDecl pass -> (IdP pass) tyFamInstDeclName = unLoc . tyFamInstDeclLName -tyFamInstDeclLName :: TyFamInstDecl name -> Located name +tyFamInstDeclLName :: TyFamInstDecl pass -> Located (IdP pass) tyFamInstDeclLName (TyFamInstDecl { tfid_eqn = (L _ (TyFamEqn { tfe_tycon = ln })) }) = ln -tyClDeclLName :: TyClDecl name -> Located name +tyClDeclLName :: TyClDecl pass -> Located (IdP pass) tyClDeclLName (FamDecl { tcdFam = FamilyDecl { fdLName = ln } }) = ln tyClDeclLName decl = tcdLName decl -tcdName :: TyClDecl name -> name +tcdName :: TyClDecl pass -> (IdP pass) tcdName = unLoc . tyClDeclLName -tyClDeclTyVars :: TyClDecl name -> LHsQTyVars name +tyClDeclTyVars :: TyClDecl pass -> LHsQTyVars pass tyClDeclTyVars (FamDecl { tcdFam = FamilyDecl { fdTyVars = tvs } }) = tvs tyClDeclTyVars d = tcdTyVars d -countTyClDecls :: [TyClDecl name] -> (Int, Int, Int, Int, Int) +countTyClDecls :: [TyClDecl pass] -> (Int, Int, Int, Int, Int) -- class, synonym decls, data, newtype, family decls countTyClDecls decls = (count isClassDecl decls, @@ -616,7 +623,7 @@ countTyClDecls decls -- | Does this declaration have a complete, user-supplied kind signature? -- See Note [Complete user-supplied kind signatures] -hsDeclHasCusk :: TyClDecl Name -> Bool +hsDeclHasCusk :: TyClDecl GhcRn -> Bool hsDeclHasCusk (FamDecl { tcdFam = fam_decl }) = famDeclHasCusk Nothing fam_decl hsDeclHasCusk (SynDecl { tcdTyVars = tyvars, tcdRhs = rhs }) -- NB: Keep this synchronized with 'getInitialKind' @@ -632,7 +639,8 @@ hsDeclHasCusk (ClassDecl { tcdTyVars = tyvars }) = hsTvbAllKinded tyvars -- Pretty-printing TyClDecl -- ~~~~~~~~~~~~~~~~~~~~~~~~ -instance (OutputableBndrId name) => Outputable (TyClDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (TyClDecl pass) where ppr (FamDecl { tcdFam = decl }) = ppr decl ppr (SynDecl { tcdLName = ltycon, tcdTyVars = tyvars, tcdFixity = fixity @@ -663,7 +671,8 @@ instance (OutputableBndrId name) => Outputable (TyClDecl name) where <+> pp_vanilla_decl_head lclas tyvars fixity (unLoc context) <+> pprFundeps (map unLoc fds) -instance (OutputableBndrId name) => Outputable (TyClGroup name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (TyClGroup pass) where ppr (TyClGroup { group_tyclds = tyclds , group_roles = roles , group_instds = instds @@ -673,10 +682,11 @@ instance (OutputableBndrId name) => Outputable (TyClGroup name) where ppr roles $$ ppr instds -pp_vanilla_decl_head :: (OutputableBndrId name) => Located name - -> LHsQTyVars name +pp_vanilla_decl_head :: (SourceTextX pass, OutputableBndrId pass) + => Located (IdP pass) + -> LHsQTyVars pass -> LexicalFixity - -> HsContext name + -> HsContext pass -> SDoc pp_vanilla_decl_head thing (HsQTvs { hsq_explicit = tyvars }) fixity context = hsep [pprHsContext context, pp_tyvars tyvars] @@ -762,25 +772,25 @@ in RnSource for more info. -} -- | Type or Class Group -data TyClGroup name -- See Note [TyClGroups and dependency analysis] - = TyClGroup { group_tyclds :: [LTyClDecl name] - , group_roles :: [LRoleAnnotDecl name] - , group_instds :: [LInstDecl name] } +data TyClGroup pass -- See Note [TyClGroups and dependency analysis] + = TyClGroup { group_tyclds :: [LTyClDecl pass] + , group_roles :: [LRoleAnnotDecl pass] + , group_instds :: [LInstDecl pass] } deriving instance (DataId id) => Data (TyClGroup id) -emptyTyClGroup :: TyClGroup name +emptyTyClGroup :: TyClGroup pass emptyTyClGroup = TyClGroup [] [] [] -tyClGroupTyClDecls :: [TyClGroup name] -> [LTyClDecl name] +tyClGroupTyClDecls :: [TyClGroup pass] -> [LTyClDecl pass] tyClGroupTyClDecls = concatMap group_tyclds -tyClGroupInstDecls :: [TyClGroup name] -> [LInstDecl name] +tyClGroupInstDecls :: [TyClGroup pass] -> [LInstDecl pass] tyClGroupInstDecls = concatMap group_instds -tyClGroupRoleDecls :: [TyClGroup name] -> [LRoleAnnotDecl name] +tyClGroupRoleDecls :: [TyClGroup pass] -> [LRoleAnnotDecl pass] tyClGroupRoleDecls = concatMap group_roles -mkTyClGroup :: [LTyClDecl name] -> [LInstDecl name] -> TyClGroup name +mkTyClGroup :: [LTyClDecl pass] -> [LInstDecl pass] -> TyClGroup pass mkTyClGroup decls instds = TyClGroup { group_tyclds = decls , group_roles = [] @@ -859,42 +869,42 @@ See also Note [Injective type families] in TyCon -} -- | Located type Family Result Signature -type LFamilyResultSig name = Located (FamilyResultSig name) +type LFamilyResultSig pass = Located (FamilyResultSig pass) -- | type Family Result Signature -data FamilyResultSig name = -- see Note [FamilyResultSig] +data FamilyResultSig pass = -- see Note [FamilyResultSig] NoSig -- ^ - 'ApiAnnotation.AnnKeywordId' : -- For details on above see note [Api annotations] in ApiAnnotation - | KindSig (LHsKind name) + | KindSig (LHsKind pass) -- ^ - 'ApiAnnotation.AnnKeywordId' : -- 'ApiAnnotation.AnnOpenP','ApiAnnotation.AnnDcolon', -- 'ApiAnnotation.AnnCloseP' -- For details on above see note [Api annotations] in ApiAnnotation - | TyVarSig (LHsTyVarBndr name) + | TyVarSig (LHsTyVarBndr pass) -- ^ - 'ApiAnnotation.AnnKeywordId' : -- 'ApiAnnotation.AnnOpenP','ApiAnnotation.AnnDcolon', -- 'ApiAnnotation.AnnCloseP', 'ApiAnnotation.AnnEqual' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (FamilyResultSig name) +deriving instance (DataId pass) => Data (FamilyResultSig pass) -- | Located type Family Declaration -type LFamilyDecl name = Located (FamilyDecl name) +type LFamilyDecl pass = Located (FamilyDecl pass) -- | type Family Declaration -data FamilyDecl name = FamilyDecl - { fdInfo :: FamilyInfo name -- type/data, closed/open - , fdLName :: Located name -- type constructor - , fdTyVars :: LHsQTyVars name -- type variables +data FamilyDecl pass = FamilyDecl + { fdInfo :: FamilyInfo pass -- type/data, closed/open + , fdLName :: Located (IdP pass) -- type constructor + , fdTyVars :: LHsQTyVars pass -- type variables , fdFixity :: LexicalFixity -- Fixity used in the declaration - , fdResultSig :: LFamilyResultSig name -- result signature - , fdInjectivityAnn :: Maybe (LInjectivityAnn name) -- optional injectivity ann + , fdResultSig :: LFamilyResultSig pass -- result signature + , fdInjectivityAnn :: Maybe (LInjectivityAnn pass) -- optional injectivity ann } -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnType', -- 'ApiAnnotation.AnnData', 'ApiAnnotation.AnnFamily', @@ -908,7 +918,7 @@ data FamilyDecl name = FamilyDecl deriving instance (DataId id) => Data (FamilyDecl id) -- | Located Injectivity Annotation -type LInjectivityAnn name = Located (InjectivityAnn name) +type LInjectivityAnn pass = Located (InjectivityAnn pass) -- | If the user supplied an injectivity annotation it is represented using -- InjectivityAnn. At the moment this is a single injectivity condition - see @@ -918,26 +928,26 @@ type LInjectivityAnn name = Located (InjectivityAnn name) -- type family Foo a b c = r | r -> a c where ... -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" -data InjectivityAnn name - = InjectivityAnn (Located name) [Located name] +data InjectivityAnn pass + = InjectivityAnn (Located (IdP pass)) [Located (IdP pass)] -- ^ - 'ApiAnnotation.AnnKeywordId' : -- 'ApiAnnotation.AnnRarrow', 'ApiAnnotation.AnnVbar' -- For details on above see note [Api annotations] in ApiAnnotation - deriving Data +deriving instance (DataId pass) => Data (InjectivityAnn pass) -data FamilyInfo name +data FamilyInfo pass = DataFamily | OpenTypeFamily -- | 'Nothing' if we're in an hs-boot file and the user -- said "type family Foo x where .." - | ClosedTypeFamily (Maybe [LTyFamInstEqn name]) -deriving instance (DataId name) => Data (FamilyInfo name) + | ClosedTypeFamily (Maybe [LTyFamInstEqn pass]) +deriving instance (DataId pass) => Data (FamilyInfo pass) -- | Does this family declaration have a complete, user-supplied kind signature? famDeclHasCusk :: Maybe Bool -- ^ if associated, does the enclosing class have a CUSK? - -> FamilyDecl name -> Bool + -> FamilyDecl pass -> Bool famDeclHasCusk _ (FamilyDecl { fdInfo = ClosedTypeFamily _ , fdTyVars = tyvars , fdResultSig = L _ resultSig }) @@ -952,15 +962,16 @@ hasReturnKindSignature (TyVarSig (L _ (UserTyVar _))) = False hasReturnKindSignature _ = True -- | Maybe return name of the result type variable -resultVariableName :: FamilyResultSig a -> Maybe a +resultVariableName :: FamilyResultSig a -> Maybe (IdP a) resultVariableName (TyVarSig sig) = Just $ hsLTyVarName sig resultVariableName _ = Nothing -instance (OutputableBndrId name) => Outputable (FamilyDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (FamilyDecl pass) where ppr = pprFamilyDecl TopLevel -pprFamilyDecl :: (OutputableBndrId name) - => TopLevelFlag -> FamilyDecl name -> SDoc +pprFamilyDecl :: (SourceTextX pass, OutputableBndrId pass) + => TopLevelFlag -> FamilyDecl pass -> SDoc pprFamilyDecl top_level (FamilyDecl { fdInfo = info, fdLName = ltycon , fdTyVars = tyvars , fdFixity = fixity @@ -991,12 +1002,12 @@ pprFamilyDecl top_level (FamilyDecl { fdInfo = info, fdLName = ltycon Just eqns -> vcat $ map ppr_fam_inst_eqn eqns ) _ -> (empty, empty) -pprFlavour :: FamilyInfo name -> SDoc +pprFlavour :: FamilyInfo pass -> SDoc pprFlavour DataFamily = text "data" pprFlavour OpenTypeFamily = text "type" pprFlavour (ClosedTypeFamily {}) = text "type" -instance Outputable (FamilyInfo name) where +instance Outputable (FamilyInfo pass) where ppr info = pprFlavour info <+> text "family" @@ -1008,7 +1019,7 @@ instance Outputable (FamilyInfo name) where ********************************************************************* -} -- | Haskell Data type Definition -data HsDataDefn name -- The payload of a data type defn +data HsDataDefn pass -- The payload of a data type defn -- Used *both* for vanilla data declarations, -- *and* for data family instances = -- | Declares a data type or newtype, giving its constructors @@ -1017,9 +1028,9 @@ data HsDataDefn name -- The payload of a data type defn -- data/newtype instance T [a] = <constrs> -- @ HsDataDefn { dd_ND :: NewOrData, - dd_ctxt :: LHsContext name, -- ^ Context + dd_ctxt :: LHsContext pass, -- ^ Context dd_cType :: Maybe (Located CType), - dd_kindSig:: Maybe (LHsKind name), + dd_kindSig:: Maybe (LHsKind pass), -- ^ Optional kind signature. -- -- @(Just k)@ for a GADT-style @data@, @@ -1027,7 +1038,7 @@ data HsDataDefn name -- The payload of a data type defn -- -- Always @Nothing@ for H98-syntax decls - dd_cons :: [LConDecl name], + dd_cons :: [LConDecl pass], -- ^ Data constructors -- -- For @data T a = T1 | T2 a@ @@ -1035,14 +1046,14 @@ data HsDataDefn name -- The payload of a data type defn -- For @data T a where { T1 :: T a }@ -- the 'LConDecls' all have 'ConDeclGADT'. - dd_derivs :: HsDeriving name -- ^ Optional 'deriving' claues + dd_derivs :: HsDeriving pass -- ^ Optional 'deriving' claues -- For details on above see note [Api annotations] in ApiAnnotation } deriving instance (DataId id) => Data (HsDataDefn id) -- | Haskell Deriving clause -type HsDeriving name = Located [LHsDerivingClause name] +type HsDeriving pass = Located [LHsDerivingClause pass] -- ^ The optional @deriving@ clauses of a data declaration. "Clauses" is -- plural because one can specify multiple deriving clauses using the -- @-XDerivingStrategies@ language extension. @@ -1051,7 +1062,7 @@ type HsDeriving name = Located [LHsDerivingClause name] -- requested to derive, in order. If no deriving clauses were specified, -- the list is empty. -type LHsDerivingClause name = Located (HsDerivingClause name) +type LHsDerivingClause pass = Located (HsDerivingClause pass) -- | A single @deriving@ clause of a data declaration. -- @@ -1059,13 +1070,13 @@ type LHsDerivingClause name = Located (HsDerivingClause name) -- 'ApiAnnotation.AnnDeriving', 'ApiAnnotation.AnnStock', -- 'ApiAnnotation.AnnAnyClass', 'Api.AnnNewtype', -- 'ApiAnnotation.AnnOpen','ApiAnnotation.AnnClose' -data HsDerivingClause name +data HsDerivingClause pass -- See Note [Deriving strategies] in TcDeriv = HsDerivingClause { deriv_clause_strategy :: Maybe (Located DerivStrategy) -- ^ The user-specified strategy (if any) to use when deriving -- 'deriv_clause_tys'. - , deriv_clause_tys :: Located [LHsSigType name] + , deriv_clause_tys :: Located [LHsSigType pass] -- ^ The types to derive. -- -- It uses 'LHsSigType's because, with @-XGeneralizedNewtypeDeriving@, @@ -1077,8 +1088,8 @@ data HsDerivingClause name } deriving instance (DataId id) => Data (HsDerivingClause id) -instance (OutputableBndrId name) - => Outputable (HsDerivingClause name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (HsDerivingClause pass) where ppr (HsDerivingClause { deriv_clause_strategy = dcs , deriv_clause_tys = L _ dct }) = hsep [ text "deriving" @@ -1098,7 +1109,7 @@ data NewOrData deriving( Eq, Data ) -- Needed because Demand derives Eq -- | Located data Constructor Declaration -type LConDecl name = Located (ConDecl name) +type LConDecl pass = Located (ConDecl pass) -- ^ May have 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnSemi' when -- in a GADT constructor list @@ -1129,57 +1140,57 @@ type LConDecl name = Located (ConDecl name) -- For details on above see note [Api annotations] in ApiAnnotation -- | data Constructor Declaration -data ConDecl name +data ConDecl pass = ConDeclGADT - { con_names :: [Located name] - , con_type :: LHsSigType name + { con_names :: [Located (IdP pass)] + , con_type :: LHsSigType pass -- ^ The type after the ‘::’ , con_doc :: Maybe LHsDocString -- ^ A possible Haddock comment. } | ConDeclH98 - { con_name :: Located name + { con_name :: Located (IdP pass) - , con_qvars :: Maybe (LHsQTyVars name) + , con_qvars :: Maybe (LHsQTyVars pass) -- User-written forall (if any), and its implicit -- kind variables -- Non-Nothing needs -XExistentialQuantification -- e.g. data T a = forall b. MkT b (b->a) -- con_qvars = {b} - , con_cxt :: Maybe (LHsContext name) + , con_cxt :: Maybe (LHsContext pass) -- ^ User-written context (if any) - , con_details :: HsConDeclDetails name + , con_details :: HsConDeclDetails pass -- ^ Arguments , con_doc :: Maybe LHsDocString -- ^ A possible Haddock comment. } -deriving instance (DataId name) => Data (ConDecl name) +deriving instance (DataId pass) => Data (ConDecl pass) -- | Haskell data Constructor Declaration Details -type HsConDeclDetails name - = HsConDetails (LBangType name) (Located [LConDeclField name]) +type HsConDeclDetails pass + = HsConDetails (LBangType pass) (Located [LConDeclField pass]) -getConNames :: ConDecl name -> [Located name] +getConNames :: ConDecl pass -> [Located (IdP pass)] getConNames ConDeclH98 {con_name = name} = [name] getConNames ConDeclGADT {con_names = names} = names -- don't call with RdrNames, because it can't deal with HsAppsTy -getConDetails :: ConDecl name -> HsConDeclDetails name +getConDetails :: ConDecl pass -> HsConDeclDetails pass getConDetails ConDeclH98 {con_details = details} = details getConDetails ConDeclGADT {con_type = ty } = details where (details,_,_,_) = gadtDeclDetails ty -- don't call with RdrNames, because it can't deal with HsAppsTy -gadtDeclDetails :: LHsSigType name - -> ( HsConDeclDetails name - , LHsType name - , LHsContext name - , [LHsTyVarBndr name] ) +gadtDeclDetails :: LHsSigType pass + -> ( HsConDeclDetails pass + , LHsType pass + , LHsContext pass + , [LHsTyVarBndr pass] ) gadtDeclDetails HsIB {hsib_body = lbody_ty} = (details,res_ty,cxt,tvs) where (tvs, cxt, tau) = splitLHsSigmaTy lbody_ty @@ -1189,14 +1200,14 @@ gadtDeclDetails HsIB {hsib_body = lbody_ty} = (details,res_ty,cxt,tvs) -> (RecCon (L l flds), res_ty') _other -> (PrefixCon [], tau) -hsConDeclArgTys :: HsConDeclDetails name -> [LBangType name] +hsConDeclArgTys :: HsConDeclDetails pass -> [LBangType pass] hsConDeclArgTys (PrefixCon tys) = tys hsConDeclArgTys (InfixCon ty1 ty2) = [ty1,ty2] hsConDeclArgTys (RecCon flds) = map (cd_fld_type . unLoc) (unLoc flds) -pp_data_defn :: (OutputableBndrId name) - => (HsContext name -> SDoc) -- Printing the header - -> HsDataDefn name +pp_data_defn :: (SourceTextX pass, OutputableBndrId pass) + => (HsContext pass -> SDoc) -- Printing the header + -> HsDataDefn pass -> SDoc pp_data_defn pp_hdr (HsDataDefn { dd_ND = new_or_data, dd_ctxt = L _ context , dd_cType = mb_ct @@ -1218,23 +1229,26 @@ pp_data_defn pp_hdr (HsDataDefn { dd_ND = new_or_data, dd_ctxt = L _ context Just kind -> dcolon <+> ppr kind pp_derivings (L _ ds) = vcat (map ppr ds) -instance (OutputableBndrId name) => Outputable (HsDataDefn name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (HsDataDefn pass) where ppr d = pp_data_defn (\_ -> text "Naked HsDataDefn") d instance Outputable NewOrData where ppr NewType = text "newtype" ppr DataType = text "data" -pp_condecls :: (OutputableBndrId name) => [LConDecl name] -> SDoc +pp_condecls :: (SourceTextX pass, OutputableBndrId pass) + => [LConDecl pass] -> SDoc pp_condecls cs@(L _ ConDeclGADT{} : _) -- In GADT syntax = hang (text "where") 2 (vcat (map ppr cs)) pp_condecls cs -- In H98 syntax = equals <+> sep (punctuate (text " |") (map ppr cs)) -instance (OutputableBndrId name) => Outputable (ConDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (ConDecl pass) where ppr = pprConDecl -pprConDecl :: (OutputableBndrId name) => ConDecl name -> SDoc +pprConDecl :: (SourceTextX pass, OutputableBndrId pass) => ConDecl pass -> SDoc pprConDecl (ConDeclH98 { con_name = L _ con , con_qvars = mtvs , con_cxt = mcxt @@ -1257,7 +1271,7 @@ pprConDecl (ConDeclGADT { con_names = cons, con_type = res_ty, con_doc = doc }) = sep [ppr_mbDoc doc <+> ppr_con_names cons <+> dcolon <+> ppr res_ty] -ppr_con_names :: (OutputableBndr name) => [Located name] -> SDoc +ppr_con_names :: (OutputableBndr a) => [Located a] -> SDoc ppr_con_names = pprWithCommas (pprPrefixOcc . unLoc) {- @@ -1289,17 +1303,17 @@ It is parameterised over its tfe_pats field: ----------------- Type synonym family instances ------------- -- | Located Type Family Instance Equation -type LTyFamInstEqn name = Located (TyFamInstEqn name) +type LTyFamInstEqn pass = Located (TyFamInstEqn pass) -- ^ May have 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnSemi' -- when in a list -- For details on above see note [Api annotations] in ApiAnnotation -- | Located Type Family Default Equation -type LTyFamDefltEqn name = Located (TyFamDefltEqn name) +type LTyFamDefltEqn pass = Located (TyFamDefltEqn pass) -- | Haskell Type Patterns -type HsTyPats name = HsImplicitBndrs name [LHsType name] +type HsTyPats pass = HsImplicitBndrs pass [LHsType pass] -- ^ Type patterns (with kind and type bndrs) -- See Note [Family instance declaration binders] @@ -1333,56 +1347,57 @@ type patterns, i.e. fv(pat_tys). Note in particular -} -- | Type Family Instance Equation -type TyFamInstEqn name = TyFamEqn name (HsTyPats name) +type TyFamInstEqn pass = TyFamEqn pass (HsTyPats pass) -- | Type Family Default Equation -type TyFamDefltEqn name = TyFamEqn name (LHsQTyVars name) +type TyFamDefltEqn pass = TyFamEqn pass (LHsQTyVars pass) -- See Note [Type family instance declarations in HsSyn] -- | Type Family Equation -- -- One equation in a type family instance declaration -- See Note [Type family instance declarations in HsSyn] -data TyFamEqn name pats +data TyFamEqn pass pats = TyFamEqn - { tfe_tycon :: Located name + { tfe_tycon :: Located (IdP pass) , tfe_pats :: pats , tfe_fixity :: LexicalFixity -- ^ Fixity used in the declaration - , tfe_rhs :: LHsType name } + , tfe_rhs :: LHsType pass } -- ^ -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnEqual' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name, Data pats) => Data (TyFamEqn name pats) +deriving instance (DataId pass, Data pats) => Data (TyFamEqn pass pats) -- | Located Type Family Instance Declaration -type LTyFamInstDecl name = Located (TyFamInstDecl name) +type LTyFamInstDecl pass = Located (TyFamInstDecl pass) -- | Type Family Instance Declaration -data TyFamInstDecl name +data TyFamInstDecl pass = TyFamInstDecl - { tfid_eqn :: LTyFamInstEqn name - , tfid_fvs :: PostRn name NameSet } + { tfid_eqn :: LTyFamInstEqn pass + , tfid_fvs :: PostRn pass NameSet } -- ^ -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnType', -- 'ApiAnnotation.AnnInstance', -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (TyFamInstDecl name) +deriving instance (DataId pass) => Data (TyFamInstDecl pass) ----------------- Data family instances ------------- -- | Located Data Family Instance Declaration -type LDataFamInstDecl name = Located (DataFamInstDecl name) +type LDataFamInstDecl pass = Located (DataFamInstDecl pass) -- | Data Family Instance Declaration -data DataFamInstDecl name +data DataFamInstDecl pass = DataFamInstDecl - { dfid_tycon :: Located name - , dfid_pats :: HsTyPats name -- LHS + { dfid_tycon :: Located (IdP pass) + , dfid_pats :: HsTyPats pass -- LHS , dfid_fixity :: LexicalFixity -- ^ Fixity used in the declaration - , dfid_defn :: HsDataDefn name -- RHS - , dfid_fvs :: PostRn name NameSet } -- Free vars for dependency analysis + , dfid_defn :: HsDataDefn pass -- RHS + , dfid_fvs :: PostRn pass NameSet } + -- Free vars for dependency analysis -- ^ -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnData', -- 'ApiAnnotation.AnnNewType','ApiAnnotation.AnnInstance', @@ -1391,24 +1406,24 @@ data DataFamInstDecl name -- 'ApiAnnotation.AnnClose' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (DataFamInstDecl name) +deriving instance (DataId pass) => Data (DataFamInstDecl pass) ----------------- Class instances ------------- -- | Located Class Instance Declaration -type LClsInstDecl name = Located (ClsInstDecl name) +type LClsInstDecl pass = Located (ClsInstDecl pass) -- | Class Instance Declaration -data ClsInstDecl name +data ClsInstDecl pass = ClsInstDecl - { cid_poly_ty :: LHsSigType name -- Context => Class Instance-type + { cid_poly_ty :: LHsSigType pass -- Context => Class Instance-type -- Using a polytype means that the renamer conveniently -- figures out the quantified type variables for us. - , cid_binds :: LHsBinds name -- Class methods - , cid_sigs :: [LSig name] -- User-supplied pragmatic info - , cid_tyfam_insts :: [LTyFamInstDecl name] -- Type family instances - , cid_datafam_insts :: [LDataFamInstDecl name] -- Data family instances + , cid_binds :: LHsBinds pass -- Class methods + , cid_sigs :: [LSig pass] -- User-supplied pragmatic info + , cid_tyfam_insts :: [LTyFamInstDecl pass] -- Type family instances + , cid_datafam_insts :: [LDataFamInstDecl pass] -- Data family instances , cid_overlap_mode :: Maybe (Located OverlapMode) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnClose', @@ -1427,23 +1442,24 @@ deriving instance (DataId id) => Data (ClsInstDecl id) ----------------- Instances of all kinds ------------- -- | Located Instance Declaration -type LInstDecl name = Located (InstDecl name) +type LInstDecl pass = Located (InstDecl pass) -- | Instance Declaration -data InstDecl name -- Both class and family instances +data InstDecl pass -- Both class and family instances = ClsInstD - { cid_inst :: ClsInstDecl name } + { cid_inst :: ClsInstDecl pass } | DataFamInstD -- data family instance - { dfid_inst :: DataFamInstDecl name } + { dfid_inst :: DataFamInstDecl pass } | TyFamInstD -- type family instance - { tfid_inst :: TyFamInstDecl name } + { tfid_inst :: TyFamInstDecl pass } deriving instance (DataId id) => Data (InstDecl id) -instance (OutputableBndrId name) => Outputable (TyFamInstDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (TyFamInstDecl pass) where ppr = pprTyFamInstDecl TopLevel -pprTyFamInstDecl :: (OutputableBndrId name) - => TopLevelFlag -> TyFamInstDecl name -> SDoc +pprTyFamInstDecl :: (SourceTextX pass, OutputableBndrId pass) + => TopLevelFlag -> TyFamInstDecl pass -> SDoc pprTyFamInstDecl top_lvl (TyFamInstDecl { tfid_eqn = eqn }) = text "type" <+> ppr_instance_keyword top_lvl <+> ppr_fam_inst_eqn eqn @@ -1451,14 +1467,16 @@ ppr_instance_keyword :: TopLevelFlag -> SDoc ppr_instance_keyword TopLevel = text "instance" ppr_instance_keyword NotTopLevel = empty -ppr_fam_inst_eqn :: (OutputableBndrId name) => LTyFamInstEqn name -> SDoc +ppr_fam_inst_eqn :: (SourceTextX pass, OutputableBndrId pass) + => LTyFamInstEqn pass -> SDoc ppr_fam_inst_eqn (L _ (TyFamEqn { tfe_tycon = tycon , tfe_pats = pats , tfe_fixity = fixity , tfe_rhs = rhs })) = pp_fam_inst_lhs tycon pats fixity [] <+> equals <+> ppr rhs -ppr_fam_deflt_eqn :: (OutputableBndrId name) => LTyFamDefltEqn name -> SDoc +ppr_fam_deflt_eqn :: (SourceTextX pass, OutputableBndrId pass) + => LTyFamDefltEqn pass -> SDoc ppr_fam_deflt_eqn (L _ (TyFamEqn { tfe_tycon = tycon , tfe_pats = tvs , tfe_fixity = fixity @@ -1466,11 +1484,12 @@ ppr_fam_deflt_eqn (L _ (TyFamEqn { tfe_tycon = tycon = text "type" <+> pp_vanilla_decl_head tycon tvs fixity [] <+> equals <+> ppr rhs -instance (OutputableBndrId name) => Outputable (DataFamInstDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (DataFamInstDecl pass) where ppr = pprDataFamInstDecl TopLevel -pprDataFamInstDecl :: (OutputableBndrId name) - => TopLevelFlag -> DataFamInstDecl name -> SDoc +pprDataFamInstDecl :: (SourceTextX pass, OutputableBndrId pass) + => TopLevelFlag -> DataFamInstDecl pass -> SDoc pprDataFamInstDecl top_lvl (DataFamInstDecl { dfid_tycon = tycon , dfid_pats = pats , dfid_fixity = fixity @@ -1480,14 +1499,15 @@ pprDataFamInstDecl top_lvl (DataFamInstDecl { dfid_tycon = tycon pp_hdr ctxt = ppr_instance_keyword top_lvl <+> pp_fam_inst_lhs tycon pats fixity ctxt -pprDataFamInstFlavour :: DataFamInstDecl name -> SDoc +pprDataFamInstFlavour :: DataFamInstDecl pass -> SDoc pprDataFamInstFlavour (DataFamInstDecl { dfid_defn = (HsDataDefn { dd_ND = nd }) }) = ppr nd -pp_fam_inst_lhs :: (OutputableBndrId name) => Located name - -> HsTyPats name +pp_fam_inst_lhs :: (SourceTextX pass, OutputableBndrId pass) + => Located (IdP pass) + -> HsTyPats pass -> LexicalFixity - -> HsContext name + -> HsContext pass -> SDoc pp_fam_inst_lhs thing (HsIB { hsib_body = typats }) fixity context -- explicit type patterns @@ -1501,7 +1521,8 @@ pp_fam_inst_lhs thing (HsIB { hsib_body = typats }) fixity context , hsep (map (pprHsType.unLoc) (patl:patsr))] pp_pats [] = empty -instance (OutputableBndrId name) => Outputable (ClsInstDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (ClsInstDecl pass) where ppr (ClsInstDecl { cid_poly_ty = inst_ty, cid_binds = binds , cid_sigs = sigs, cid_tyfam_insts = ats , cid_overlap_mode = mbOverlap @@ -1539,14 +1560,15 @@ ppOverlapPragma mb = maybe_stext (SourceText src) _ = text src <+> text "#-}" -instance (OutputableBndrId name) => Outputable (InstDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (InstDecl pass) where ppr (ClsInstD { cid_inst = decl }) = ppr decl ppr (TyFamInstD { tfid_inst = decl }) = ppr decl ppr (DataFamInstD { dfid_inst = decl }) = ppr decl -- Extract the declarations of associated data types from an instance -instDeclDataFamInsts :: [LInstDecl name] -> [DataFamInstDecl name] +instDeclDataFamInsts :: [LInstDecl pass] -> [DataFamInstDecl pass] instDeclDataFamInsts inst_decls = concatMap do_one inst_decls where @@ -1564,11 +1586,11 @@ instDeclDataFamInsts inst_decls -} -- | Located Deriving Declaration -type LDerivDecl name = Located (DerivDecl name) +type LDerivDecl pass = Located (DerivDecl pass) -- | Deriving Declaration -data DerivDecl name = DerivDecl - { deriv_type :: LHsSigType name +data DerivDecl pass = DerivDecl + { deriv_type :: LHsSigType pass , deriv_strategy :: Maybe (Located DerivStrategy) , deriv_overlap_mode :: Maybe (Located OverlapMode) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnDeriving', @@ -1578,9 +1600,10 @@ data DerivDecl name = DerivDecl -- For details on above see note [Api annotations] in ApiAnnotation } -deriving instance (DataId name) => Data (DerivDecl name) +deriving instance (DataId pass) => Data (DerivDecl pass) -instance (OutputableBndrId name) => Outputable (DerivDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (DerivDecl pass) where ppr (DerivDecl { deriv_type = ty , deriv_strategy = ds , deriv_overlap_mode = o }) @@ -1603,18 +1626,19 @@ syntax, and that restriction must be checked in the front end. -} -- | Located Default Declaration -type LDefaultDecl name = Located (DefaultDecl name) +type LDefaultDecl pass = Located (DefaultDecl pass) -- | Default Declaration -data DefaultDecl name - = DefaultDecl [LHsType name] +data DefaultDecl pass + = DefaultDecl [LHsType pass] -- ^ - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnDefault', -- 'ApiAnnotation.AnnOpen','ApiAnnotation.AnnClose' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (DefaultDecl name) +deriving instance (DataId pass) => Data (DefaultDecl pass) -instance (OutputableBndrId name) => Outputable (DefaultDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (DefaultDecl pass) where ppr (DefaultDecl tys) = text "default" <+> parens (interpp'SP tys) @@ -1634,20 +1658,20 @@ instance (OutputableBndrId name) => Outputable (DefaultDecl name) where -- has been used -- | Located Foreign Declaration -type LForeignDecl name = Located (ForeignDecl name) +type LForeignDecl pass = Located (ForeignDecl pass) -- | Foreign Declaration -data ForeignDecl name +data ForeignDecl pass = ForeignImport - { fd_name :: Located name -- defines this name - , fd_sig_ty :: LHsSigType name -- sig_ty - , fd_co :: PostTc name Coercion -- rep_ty ~ sig_ty + { fd_name :: Located (IdP pass) -- defines this name + , fd_sig_ty :: LHsSigType pass -- sig_ty + , fd_co :: PostTc pass Coercion -- rep_ty ~ sig_ty , fd_fi :: ForeignImport } | ForeignExport - { fd_name :: Located name -- uses this name - , fd_sig_ty :: LHsSigType name -- sig_ty - , fd_co :: PostTc name Coercion -- rep_ty ~ sig_ty + { fd_name :: Located (IdP pass) -- uses this name + , fd_sig_ty :: LHsSigType pass -- sig_ty + , fd_co :: PostTc pass Coercion -- rep_ty ~ sig_ty , fd_fe :: ForeignExport } -- ^ -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnForeign', @@ -1656,7 +1680,7 @@ data ForeignDecl name -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (ForeignDecl name) +deriving instance (DataId pass) => Data (ForeignDecl pass) {- In both ForeignImport and ForeignExport: sig_ty is the type given in the Haskell code @@ -1717,7 +1741,8 @@ data ForeignExport = CExport (Located CExportSpec) -- contains the calling -- pretty printing of foreign declarations -- -instance (OutputableBndrId name) => Outputable (ForeignDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (ForeignDecl pass) where ppr (ForeignImport { fd_name = n, fd_sig_ty = ty, fd_fi = fimport }) = hang (text "foreign import" <+> ppr fimport <+> ppr n) 2 (dcolon <+> ppr ty) @@ -1766,29 +1791,29 @@ instance Outputable ForeignExport where -} -- | Located Rule Declarations -type LRuleDecls name = Located (RuleDecls name) +type LRuleDecls pass = Located (RuleDecls pass) -- Note [Pragma source text] in BasicTypes -- | Rule Declarations -data RuleDecls name = HsRules { rds_src :: SourceText - , rds_rules :: [LRuleDecl name] } -deriving instance (DataId name) => Data (RuleDecls name) +data RuleDecls pass = HsRules { rds_src :: SourceText + , rds_rules :: [LRuleDecl pass] } +deriving instance (DataId pass) => Data (RuleDecls pass) -- | Located Rule Declaration -type LRuleDecl name = Located (RuleDecl name) +type LRuleDecl pass = Located (RuleDecl pass) -- | Rule Declaration -data RuleDecl name +data RuleDecl pass = HsRule -- Source rule (Located (SourceText,RuleName)) -- Rule name -- Note [Pragma source text] in BasicTypes Activation - [LRuleBndr name] -- Forall'd vars; after typechecking this + [LRuleBndr pass] -- Forall'd vars; after typechecking this -- includes tyvars - (Located (HsExpr name)) -- LHS - (PostRn name NameSet) -- Free-vars from the LHS - (Located (HsExpr name)) -- RHS - (PostRn name NameSet) -- Free-vars from the RHS + (Located (HsExpr pass)) -- LHS + (PostRn pass NameSet) -- Free-vars from the LHS + (Located (HsExpr pass)) -- RHS + (PostRn pass NameSet) -- Free-vars from the RHS -- ^ -- - 'ApiAnnotation.AnnKeywordId' : -- 'ApiAnnotation.AnnOpen','ApiAnnotation.AnnTilde', @@ -1798,37 +1823,39 @@ data RuleDecl name -- 'ApiAnnotation.AnnEqual', -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (RuleDecl name) +deriving instance (DataId pass) => Data (RuleDecl pass) -flattenRuleDecls :: [LRuleDecls name] -> [LRuleDecl name] +flattenRuleDecls :: [LRuleDecls pass] -> [LRuleDecl pass] flattenRuleDecls decls = concatMap (rds_rules . unLoc) decls -- | Located Rule Binder -type LRuleBndr name = Located (RuleBndr name) +type LRuleBndr pass = Located (RuleBndr pass) -- | Rule Binder -data RuleBndr name - = RuleBndr (Located name) - | RuleBndrSig (Located name) (LHsSigWcType name) +data RuleBndr pass + = RuleBndr (Located (IdP pass)) + | RuleBndrSig (Located (IdP pass)) (LHsSigWcType pass) -- ^ -- - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnDcolon','ApiAnnotation.AnnClose' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (RuleBndr name) +deriving instance (DataId pass) => Data (RuleBndr pass) -collectRuleBndrSigTys :: [RuleBndr name] -> [LHsSigWcType name] +collectRuleBndrSigTys :: [RuleBndr pass] -> [LHsSigWcType pass] collectRuleBndrSigTys bndrs = [ty | RuleBndrSig _ ty <- bndrs] pprFullRuleName :: Located (SourceText, RuleName) -> SDoc pprFullRuleName (L _ (st, n)) = pprWithSourceText st (doubleQuotes $ ftext n) -instance (OutputableBndrId name) => Outputable (RuleDecls name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (RuleDecls pass) where ppr (HsRules st rules) = pprWithSourceText st (text "{-# RULES") <+> vcat (punctuate semi (map ppr rules)) <+> text "#-}" -instance (OutputableBndrId name) => Outputable (RuleDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (RuleDecl pass) where ppr (HsRule name act ns lhs _fv_lhs rhs _fv_rhs) = sep [pprFullRuleName name <+> ppr act, nest 4 (pp_forall <+> pprExpr (unLoc lhs)), @@ -1837,7 +1864,8 @@ instance (OutputableBndrId name) => Outputable (RuleDecl name) where pp_forall | null ns = empty | otherwise = forAllLit <+> fsep (map ppr ns) <> dot -instance (OutputableBndrId name) => Outputable (RuleBndr name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (RuleBndr pass) where ppr (RuleBndr name) = ppr name ppr (RuleBndrSig name ty) = parens (ppr name <> dcolon <> ppr ty) @@ -1859,21 +1887,21 @@ A vectorisation pragma, one of -} -- | Located Vectorise Declaration -type LVectDecl name = Located (VectDecl name) +type LVectDecl pass = Located (VectDecl pass) -- | Vectorise Declaration -data VectDecl name +data VectDecl pass = HsVect SourceText -- Note [Pragma source text] in BasicTypes - (Located name) - (LHsExpr name) + (Located (IdP pass)) + (LHsExpr pass) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnEqual','ApiAnnotation.AnnClose' -- For details on above see note [Api annotations] in ApiAnnotation | HsNoVect SourceText -- Note [Pragma source text] in BasicTypes - (Located name) + (Located (IdP pass)) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnClose' @@ -1881,8 +1909,8 @@ data VectDecl name | HsVectTypeIn -- pre type-checking SourceText -- Note [Pragma source text] in BasicTypes Bool -- 'TRUE' => SCALAR declaration - (Located name) - (Maybe (Located name)) -- 'Nothing' => no right-hand side + (Located (IdP pass)) + (Maybe (Located (IdP pass))) -- 'Nothing' => no right-hand side -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnType','ApiAnnotation.AnnClose', -- 'ApiAnnotation.AnnEqual' @@ -1894,7 +1922,7 @@ data VectDecl name (Maybe TyCon) -- 'Nothing' => no right-hand side | HsVectClassIn -- pre type-checking SourceText -- Note [Pragma source text] in BasicTypes - (Located name) + (Located (IdP pass)) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnClass','ApiAnnotation.AnnClose', @@ -1902,12 +1930,12 @@ data VectDecl name | HsVectClassOut -- post type-checking Class | HsVectInstIn -- pre type-checking (always SCALAR) !!!FIXME: should be superfluous now - (LHsSigType name) + (LHsSigType pass) | HsVectInstOut -- post type-checking (always SCALAR) !!!FIXME: should be superfluous now ClsInst -deriving instance (DataId name) => Data (VectDecl name) +deriving instance (DataId pass) => Data (VectDecl pass) -lvectDeclName :: NamedThing name => LVectDecl name -> Name +lvectDeclName :: NamedThing (IdP pass) => LVectDecl pass -> Name lvectDeclName (L _ (HsVect _ (L _ name) _)) = getName name lvectDeclName (L _ (HsNoVect _ (L _ name))) = getName name lvectDeclName (L _ (HsVectTypeIn _ _ (L _ name) _)) = getName name @@ -1919,12 +1947,13 @@ lvectDeclName (L _ (HsVectInstIn _)) lvectDeclName (L _ (HsVectInstOut _)) = panic "HsDecls.lvectDeclName: HsVectInstOut" -lvectInstDecl :: LVectDecl name -> Bool +lvectInstDecl :: LVectDecl pass -> Bool lvectInstDecl (L _ (HsVectInstIn _)) = True lvectInstDecl (L _ (HsVectInstOut _)) = True lvectInstDecl _ = False -instance (OutputableBndrId name) => Outputable (VectDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (VectDecl pass) where ppr (HsVect _ v rhs) = sep [text "{-# VECTORISE" <+> ppr v, nest 4 $ @@ -1996,28 +2025,28 @@ We use exported entities for things to deprecate. -} -- | Located Warning Declarations -type LWarnDecls name = Located (WarnDecls name) +type LWarnDecls pass = Located (WarnDecls pass) -- Note [Pragma source text] in BasicTypes -- | Warning pragma Declarations -data WarnDecls name = Warnings { wd_src :: SourceText - , wd_warnings :: [LWarnDecl name] +data WarnDecls pass = Warnings { wd_src :: SourceText + , wd_warnings :: [LWarnDecl pass] } - deriving Data +deriving instance (DataId pass) => Data (WarnDecls pass) -- | Located Warning pragma Declaration -type LWarnDecl name = Located (WarnDecl name) +type LWarnDecl pass = Located (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl name = Warning [Located name] WarningTxt - deriving Data +data WarnDecl pass = Warning [Located (IdP pass)] WarningTxt +deriving instance (DataId pass) => Data (WarnDecl pass) -instance OutputableBndr name => Outputable (WarnDecls name) where +instance OutputableBndr (IdP pass) => Outputable (WarnDecls pass) where ppr (Warnings (SourceText src) decls) = text src <+> vcat (punctuate comma (map ppr decls)) <+> text "#-}" ppr (Warnings NoSourceText _decls) = panic "WarnDecls" -instance OutputableBndr name => Outputable (WarnDecl name) where +instance OutputableBndr (IdP pass) => Outputable (WarnDecl pass) where ppr (Warning thing txt) = hsep ( punctuate comma (map ppr thing)) <+> ppr txt @@ -2031,21 +2060,22 @@ instance OutputableBndr name => Outputable (WarnDecl name) where -} -- | Located Annotation Declaration -type LAnnDecl name = Located (AnnDecl name) +type LAnnDecl pass = Located (AnnDecl pass) -- | Annotation Declaration -data AnnDecl name = HsAnnotation +data AnnDecl pass = HsAnnotation SourceText -- Note [Pragma source text] in BasicTypes - (AnnProvenance name) (Located (HsExpr name)) + (AnnProvenance (IdP pass)) (Located (HsExpr pass)) -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnOpen', -- 'ApiAnnotation.AnnType' -- 'ApiAnnotation.AnnModule' -- 'ApiAnnotation.AnnClose' -- For details on above see note [Api annotations] in ApiAnnotation -deriving instance (DataId name) => Data (AnnDecl name) +deriving instance (DataId pass) => Data (AnnDecl pass) -instance (OutputableBndrId name) => Outputable (AnnDecl name) where +instance (SourceTextX pass, OutputableBndrId pass) + => Outputable (AnnDecl pass) where ppr (HsAnnotation _ provenance expr) = hsep [text "{-#", pprAnnProvenance provenance, pprExpr (unLoc expr), text "#-}"] @@ -2053,9 +2083,10 @@ instance (OutputableBndrId name) => Outputable (AnnDecl name) where data AnnProvenance name = ValueAnnProvenance (Located name) | TypeAnnProvenance (Located name) | ModuleAnnProvenance - deriving (Data, Functor) +deriving instance Functor AnnProvenance deriving instance Foldable AnnProvenance deriving instance Traversable AnnProvenance +deriving instance (Data pass) => Data (AnnProvenance pass) annProvenanceName_maybe :: AnnProvenance name -> Maybe name annProvenanceName_maybe (ValueAnnProvenance (L _ name)) = Just name @@ -2078,21 +2109,21 @@ pprAnnProvenance (TypeAnnProvenance (L _ name)) -} -- | Located Role Annotation Declaration -type LRoleAnnotDecl name = Located (RoleAnnotDecl name) +type LRoleAnnotDecl pass = Located (RoleAnnotDecl pass) -- See #8185 for more info about why role annotations are -- top-level declarations -- | Role Annotation Declaration -data RoleAnnotDecl name - = RoleAnnotDecl (Located name) -- type constructor +data RoleAnnotDecl pass + = RoleAnnotDecl (Located (IdP pass)) -- type constructor [Located (Maybe Role)] -- optional annotations -- ^ - 'ApiAnnotation.AnnKeywordId' : 'ApiAnnotation.AnnType', -- 'ApiAnnotation.AnnRole' -- For details on above see note [Api annotations] in ApiAnnotation - deriving Data +deriving instance (DataId pass) => Data (RoleAnnotDecl pass) -instance OutputableBndr name => Outputable (RoleAnnotDecl name) where +instance OutputableBndr (IdP pass) => Outputable (RoleAnnotDecl pass) where ppr (RoleAnnotDecl ltycon roles) = text "type role" <+> ppr ltycon <+> hsep (map (pp_role . unLoc) roles) @@ -2100,5 +2131,5 @@ instance OutputableBndr name => Outputable (RoleAnnotDecl name) where pp_role Nothing = underscore pp_role (Just r) = ppr r -roleAnnotDeclName :: RoleAnnotDecl name -> name +roleAnnotDeclName :: RoleAnnotDecl pass -> (IdP pass) roleAnnotDeclName (RoleAnnotDecl (L _ name) _) = name |