diff options
Diffstat (limited to 'compiler/GHC/Hs/Decls.hs')
-rw-r--r-- | compiler/GHC/Hs/Decls.hs | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/compiler/GHC/Hs/Decls.hs b/compiler/GHC/Hs/Decls.hs index 9759225109..4dea3983a5 100644 --- a/compiler/GHC/Hs/Decls.hs +++ b/compiler/GHC/Hs/Decls.hs @@ -133,7 +133,7 @@ import Data.Data hiding (TyCon,Fixity, Infix) ************************************************************************ -} -type LHsDecl p = Located (HsDecl p) +type LHsDecl p = XRec p (HsDecl p) -- ^ When in a list this may have -- -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnSemi' @@ -411,13 +411,13 @@ instance (OutputableBndrId p) => Outputable (HsGroup (GhcPass p)) where vcat_mb gap (Just d : ds) = gap $$ d $$ vcat_mb blankLine ds -- | Located Splice Declaration -type LSpliceDecl pass = Located (SpliceDecl pass) +type LSpliceDecl pass = XRec pass (SpliceDecl pass) -- | Splice Declaration data SpliceDecl p = SpliceDecl -- Top level splice (XSpliceDecl p) - (Located (HsSplice p)) + (XRec p (HsSplice p)) SpliceExplicitFlag | XSpliceDecl !(XXSpliceDecl p) @@ -568,7 +568,7 @@ Interface file code: -} -- | Located Declaration of a Type or Class -type LTyClDecl pass = Located (TyClDecl pass) +type LTyClDecl pass = XRec pass (TyClDecl pass) -- | A type or class declaration. data TyClDecl pass @@ -592,7 +592,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation SynDecl { tcdSExt :: XSynDecl pass -- ^ Post renameer, FVs - , tcdLName :: Located (IdP pass) -- ^ Type constructor + , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an -- associated type these -- include outer binders @@ -609,16 +609,16 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation DataDecl { tcdDExt :: XDataDecl pass -- ^ Post renamer, CUSK flag, FVs - , tcdLName :: Located (IdP pass) -- ^ Type constructor + , tcdLName :: XRec pass (IdP pass) -- ^ Type constructor , tcdTyVars :: LHsQTyVars pass -- ^ Type variables -- See Note [TyVar binders for associated declarations] , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration , tcdDataDefn :: HsDataDefn pass } - | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs - tcdCtxt :: LHsContext pass, -- ^ Context... - tcdLName :: Located (IdP pass), -- ^ Name of the class - tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables + | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs + tcdCtxt :: LHsContext pass, -- ^ Context... + tcdLName :: XRec pass (IdP pass), -- ^ Name of the class + tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration tcdFDs :: [LHsFunDep pass], -- ^ Functional deps tcdSigs :: [LSig pass], -- ^ Methods' signatures @@ -637,7 +637,7 @@ data TyClDecl pass -- For details on above see note [Api annotations] in GHC.Parser.Annotation | XTyClDecl !(XXTyClDecl pass) -type LHsFunDep pass = Located (FunDep (Located (IdP pass))) +type LHsFunDep pass = XRec pass (FunDep (XRec pass (IdP pass))) data DataDeclRn = DataDeclRn { tcdDataCusk :: Bool -- ^ does this have a CUSK? @@ -764,6 +764,8 @@ tyClDeclLName (SynDecl { tcdLName = ln }) = ln tyClDeclLName (DataDecl { tcdLName = ln }) = ln tyClDeclLName (ClassDecl { tcdLName = ln }) = ln +-- FIXME: tcdName is commonly used by both GHC and third-party tools, so it +-- needs to be polymorphic in the pass tcdName :: TyClDecl (GhcPass p) -> IdP (GhcPass p) tcdName = unLoc . tyClDeclLName @@ -1095,7 +1097,7 @@ See also Note [Injective type families] in GHC.Core.TyCon -} -- | Located type Family Result Signature -type LFamilyResultSig pass = Located (FamilyResultSig pass) +type LFamilyResultSig pass = XRec pass (FamilyResultSig pass) -- | type Family Result Signature data FamilyResultSig pass = -- see Note [FamilyResultSig] @@ -1127,13 +1129,13 @@ type instance XXFamilyResultSig (GhcPass _) = NoExtCon -- | Located type Family Declaration -type LFamilyDecl pass = Located (FamilyDecl pass) +type LFamilyDecl pass = XRec pass (FamilyDecl pass) -- | type Family Declaration data FamilyDecl pass = FamilyDecl { fdExt :: XCFamilyDecl pass , fdInfo :: FamilyInfo pass -- type/data, closed/open - , fdLName :: Located (IdP pass) -- type constructor + , fdLName :: XRec pass (IdP pass) -- type constructor , fdTyVars :: LHsQTyVars pass -- type variables -- See Note [TyVar binders for associated declarations] , fdFixity :: LexicalFixity -- Fixity used in the declaration @@ -1155,7 +1157,7 @@ type instance XXFamilyDecl (GhcPass _) = NoExtCon -- | Located Injectivity Annotation -type LInjectivityAnn pass = Located (InjectivityAnn pass) +type LInjectivityAnn pass = XRec pass (InjectivityAnn pass) -- | If the user supplied an injectivity annotation it is represented using -- InjectivityAnn. At the moment this is a single injectivity condition - see @@ -1166,7 +1168,7 @@ type LInjectivityAnn pass = Located (InjectivityAnn pass) -- -- This will be represented as "InjectivityAnn `r` [`a`, `c`]" data InjectivityAnn pass - = InjectivityAnn (Located (IdP pass)) [Located (IdP pass)] + = InjectivityAnn (XRec pass (IdP pass)) [XRec pass (IdP pass)] -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : -- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar' @@ -1267,7 +1269,7 @@ data HsDataDefn pass -- The payload of a data type defn HsDataDefn { dd_ext :: XCHsDataDefn pass, dd_ND :: NewOrData, dd_ctxt :: LHsContext pass, -- ^ Context - dd_cType :: Maybe (Located CType), + dd_cType :: Maybe (XRec pass CType), dd_kindSig:: Maybe (LHsKind pass), -- ^ Optional kind signature. -- @@ -1295,7 +1297,7 @@ type instance XCHsDataDefn (GhcPass _) = NoExtField type instance XXHsDataDefn (GhcPass _) = NoExtCon -- | Haskell Deriving clause -type HsDeriving pass = Located [LHsDerivingClause pass] +type HsDeriving pass = XRec pass [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. @@ -1304,7 +1306,7 @@ type HsDeriving pass = Located [LHsDerivingClause pass] -- requested to derive, in order. If no deriving clauses were specified, -- the list is empty. -type LHsDerivingClause pass = Located (HsDerivingClause pass) +type LHsDerivingClause pass = XRec pass (HsDerivingClause pass) -- | A single @deriving@ clause of a data declaration. -- @@ -1319,7 +1321,7 @@ data HsDerivingClause pass , deriv_clause_strategy :: Maybe (LDerivStrategy pass) -- ^ The user-specified strategy (if any) to use when deriving -- 'deriv_clause_tys'. - , deriv_clause_tys :: Located [LHsSigType pass] + , deriv_clause_tys :: XRec pass [LHsSigType pass] -- ^ The types to derive. -- -- It uses 'LHsSigType's because, with @-XGeneralizedNewtypeDeriving@, @@ -1358,11 +1360,11 @@ instance OutputableBndrId p _ -> (ppDerivStrategy dcs, empty) -- | Located Standalone Kind Signature -type LStandaloneKindSig pass = Located (StandaloneKindSig pass) +type LStandaloneKindSig pass = XRec pass (StandaloneKindSig pass) data StandaloneKindSig pass = StandaloneKindSig (XStandaloneKindSig pass) - (Located (IdP pass)) -- Why a single binder? See #16754 + (XRec pass (IdP pass)) -- Why a single binder? See #16754 (LHsSigType pass) -- Why not LHsSigWcType? See Note [Wildcards in standalone kind signatures] | XStandaloneKindSig !(XXStandaloneKindSig pass) @@ -1399,7 +1401,7 @@ newOrDataToFlavour DataType = DataTypeFlavour -- | Located data Constructor Declaration -type LConDecl pass = Located (ConDecl pass) +type LConDecl pass = XRec pass (ConDecl pass) -- ^ May have 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnSemi' when -- in a GADT constructor list @@ -1433,13 +1435,13 @@ type LConDecl pass = Located (ConDecl pass) data ConDecl pass = ConDeclGADT { con_g_ext :: XConDeclGADT pass - , con_names :: [Located (IdP pass)] + , con_names :: [XRec pass (IdP pass)] -- The next four fields describe the type after the '::' -- See Note [GADT abstract syntax] -- The following field is Located to anchor API Annotations, -- AnnForall and AnnDot. - , con_forall :: Located Bool -- ^ True <=> explicit forall + , con_forall :: XRec pass Bool -- ^ True <=> explicit forall -- False => hsq_explicit is empty , con_qvars :: [LHsTyVarBndr Specificity pass] -- Whether or not there is an /explicit/ forall, we still @@ -1455,9 +1457,9 @@ data ConDecl pass | ConDeclH98 { con_ext :: XConDeclH98 pass - , con_name :: Located (IdP pass) + , con_name :: XRec pass (IdP pass) - , con_forall :: Located Bool + , con_forall :: XRec pass Bool -- ^ True <=> explicit user-written forall -- e.g. data T a = forall b. MkT b (b->a) -- con_ex_tvs = {b} @@ -1607,7 +1609,7 @@ or contexts in two parts: -- | Haskell data Constructor Declaration Details type HsConDeclDetails pass - = HsConDetails (HsScaled pass (LBangType pass)) (Located [LConDeclField pass]) + = HsConDetails (HsScaled pass (LBangType pass)) (XRec pass [LConDeclField pass]) getConNames :: ConDecl GhcRn -> [Located Name] getConNames ConDeclH98 {con_name = name} = [name] @@ -1616,7 +1618,7 @@ getConNames ConDeclGADT {con_names = names} = names getConArgs :: ConDecl GhcRn -> HsConDeclDetails GhcRn getConArgs d = con_args d -hsConDeclArgTys :: HsConDeclDetails pass -> [HsScaled pass (LBangType pass)] +hsConDeclArgTys :: HsConDeclDetails (GhcPass p) -> [HsScaled (GhcPass p) (LBangType (GhcPass p))] hsConDeclArgTys (PrefixCon tys) = tys hsConDeclArgTys (InfixCon ty1 ty2) = [ty1,ty2] hsConDeclArgTys (RecCon flds) = map (hsLinear . cd_fld_type . unLoc) (unLoc flds) @@ -1627,7 +1629,7 @@ hsConDeclArgTys (RecCon flds) = map (hsLinear . cd_fld_type . unLoc) (unLoc -- unrestricted). By the transfer property, projections are then correct in -- that all the non-projected fields have multiplicity Many, and can be dropped. -hsConDeclTheta :: Maybe (LHsContext pass) -> [LHsType pass] +hsConDeclTheta :: Maybe (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)] hsConDeclTheta Nothing = [] hsConDeclTheta (Just (L _ theta)) = theta @@ -1773,7 +1775,7 @@ free-standing `type instance` declaration. ----------------- Type synonym family instances ------------- -- | Located Type Family Instance Equation -type LTyFamInstEqn pass = Located (TyFamInstEqn pass) +type LTyFamInstEqn pass = XRec pass (TyFamInstEqn pass) -- ^ May have 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnSemi' -- when in a list @@ -1825,10 +1827,10 @@ type TyFamInstEqn pass = FamInstEqn pass (LHsType pass) type TyFamDefltDecl = TyFamInstDecl -- | Located type family default declarations. -type LTyFamDefltDecl pass = Located (TyFamDefltDecl pass) +type LTyFamDefltDecl pass = XRec pass (TyFamDefltDecl pass) -- | Located Type Family Instance Declaration -type LTyFamInstDecl pass = Located (TyFamInstDecl pass) +type LTyFamInstDecl pass = XRec pass (TyFamInstDecl pass) -- | Type Family Instance Declaration newtype TyFamInstDecl pass = TyFamInstDecl { tfid_eqn :: TyFamInstEqn pass } @@ -1841,7 +1843,7 @@ newtype TyFamInstDecl pass = TyFamInstDecl { tfid_eqn :: TyFamInstEqn pass } ----------------- Data family instances ------------- -- | Located Data Family Instance Declaration -type LDataFamInstDecl pass = Located (DataFamInstDecl pass) +type LDataFamInstDecl pass = XRec pass (DataFamInstDecl pass) -- | Data Family Instance Declaration newtype DataFamInstDecl pass @@ -1858,7 +1860,7 @@ newtype DataFamInstDecl pass ----------------- Family instances (common types) ------------- -- | Located Family Instance Equation -type LFamInstEqn pass rhs = Located (FamInstEqn pass rhs) +type LFamInstEqn pass rhs = XRec pass (FamInstEqn pass rhs) -- | Family Instance Equation type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) @@ -1874,7 +1876,7 @@ type FamInstEqn pass rhs = HsImplicitBndrs pass (FamEqn pass rhs) data FamEqn pass rhs = FamEqn { feqn_ext :: XCFamEqn pass rhs - , feqn_tycon :: Located (IdP pass) + , feqn_tycon :: XRec pass (IdP pass) , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars , feqn_pats :: HsTyPats pass , feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration @@ -1892,7 +1894,7 @@ type instance XXFamEqn (GhcPass _) r = NoExtCon ----------------- Class instances ------------- -- | Located Class Instance Declaration -type LClsInstDecl pass = Located (ClsInstDecl pass) +type LClsInstDecl pass = XRec pass (ClsInstDecl pass) -- | Class Instance Declaration data ClsInstDecl pass @@ -1905,7 +1907,7 @@ data ClsInstDecl pass , 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) + , cid_overlap_mode :: Maybe (XRec pass OverlapMode) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', -- 'GHC.Parser.Annotation.AnnClose', @@ -1925,7 +1927,7 @@ type instance XXClsInstDecl (GhcPass _) = NoExtCon ----------------- Instances of all kinds ------------- -- | Located Instance Declaration -type LInstDecl pass = Located (InstDecl pass) +type LInstDecl pass = XRec pass (InstDecl pass) -- | Instance Declaration data InstDecl pass -- Both class and family instances @@ -2082,7 +2084,7 @@ instDeclDataFamInsts inst_decls -} -- | Located stand-alone 'deriving instance' declaration -type LDerivDecl pass = Located (DerivDecl pass) +type LDerivDecl pass = XRec pass (DerivDecl pass) -- | Stand-alone 'deriving instance' declaration data DerivDecl pass = DerivDecl @@ -2100,7 +2102,7 @@ data DerivDecl pass = DerivDecl -- See Note [Inferring the instance context] in GHC.Tc.Deriv.Infer. , deriv_strategy :: Maybe (LDerivStrategy pass) - , deriv_overlap_mode :: Maybe (Located OverlapMode) + , deriv_overlap_mode :: Maybe (XRec pass OverlapMode) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDeriving', -- 'GHC.Parser.Annotation.AnnInstance', 'GHC.Parser.Annotation.AnnStock', -- 'GHC.Parser.Annotation.AnnAnyClass', 'Api.AnnNewtype', @@ -2133,7 +2135,7 @@ instance OutputableBndrId p -} -- | A 'Located' 'DerivStrategy'. -type LDerivStrategy pass = Located (DerivStrategy pass) +type LDerivStrategy pass = XRec pass (DerivStrategy pass) -- | Which technique the user explicitly requested when deriving an instance. data DerivStrategy pass @@ -2199,7 +2201,7 @@ syntax, and that restriction must be checked in the front end. -} -- | Located Default Declaration -type LDefaultDecl pass = Located (DefaultDecl pass) +type LDefaultDecl pass = XRec pass (DefaultDecl pass) -- | Default Declaration data DefaultDecl pass @@ -2233,19 +2235,19 @@ instance OutputableBndrId p -- has been used -- | Located Foreign Declaration -type LForeignDecl pass = Located (ForeignDecl pass) +type LForeignDecl pass = XRec pass (ForeignDecl pass) -- | Foreign Declaration data ForeignDecl pass = ForeignImport { fd_i_ext :: XForeignImport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: Located (IdP pass) -- defines this name + , fd_name :: XRec pass (IdP pass) -- defines this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fi :: ForeignImport } | ForeignExport { fd_e_ext :: XForeignExport pass -- Post typechecker, rep_ty ~ sig_ty - , fd_name :: Located (IdP pass) -- uses this name + , fd_name :: XRec pass (IdP pass) -- uses this name , fd_sig_ty :: LHsSigType pass -- sig_ty , fd_fe :: ForeignExport } -- ^ @@ -2370,7 +2372,7 @@ instance Outputable ForeignExport where -} -- | Located Rule Declarations -type LRuleDecls pass = Located (RuleDecls pass) +type LRuleDecls pass = XRec pass (RuleDecls pass) -- Note [Pragma source text] in GHC.Types.Basic -- | Rule Declarations @@ -2383,14 +2385,14 @@ type instance XCRuleDecls (GhcPass _) = NoExtField type instance XXRuleDecls (GhcPass _) = NoExtCon -- | Located Rule Declaration -type LRuleDecl pass = Located (RuleDecl pass) +type LRuleDecl pass = XRec pass (RuleDecl pass) -- | Rule Declaration data RuleDecl pass = HsRule -- Source rule { rd_ext :: XHsRule pass -- ^ After renamer, free-vars from the LHS and RHS - , rd_name :: Located (SourceText,RuleName) + , rd_name :: XRec pass (SourceText,RuleName) -- ^ Note [Pragma source text] in "GHC.Types.Basic" , rd_act :: Activation , rd_tyvs :: Maybe [LHsTyVarBndr () (NoGhcTc pass)] @@ -2398,8 +2400,8 @@ data RuleDecl pass , rd_tmvs :: [LRuleBndr pass] -- ^ Forall'd term vars, before typechecking; after typechecking -- this includes all forall'd vars - , rd_lhs :: Located (HsExpr pass) - , rd_rhs :: Located (HsExpr pass) + , rd_lhs :: XRec pass (HsExpr pass) + , rd_rhs :: XRec pass (HsExpr pass) } -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : @@ -2419,16 +2421,16 @@ type instance XHsRule GhcTc = HsRuleRn type instance XXRuleDecl (GhcPass _) = NoExtCon -flattenRuleDecls :: [LRuleDecls pass] -> [LRuleDecl pass] +flattenRuleDecls :: [LRuleDecls (GhcPass p)] -> [LRuleDecl (GhcPass p)] flattenRuleDecls decls = concatMap (rds_rules . unLoc) decls -- | Located Rule Binder -type LRuleBndr pass = Located (RuleBndr pass) +type LRuleBndr pass = XRec pass (RuleBndr pass) -- | Rule Binder data RuleBndr pass - = RuleBndr (XCRuleBndr pass) (Located (IdP pass)) - | RuleBndrSig (XRuleBndrSig pass) (Located (IdP pass)) (HsPatSigType pass) + = RuleBndr (XCRuleBndr pass) (XRec pass (IdP pass)) + | RuleBndrSig (XRuleBndrSig pass) (XRec pass (IdP pass)) (HsPatSigType pass) | XRuleBndr !(XXRuleBndr pass) -- ^ -- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', @@ -2513,7 +2515,7 @@ We use exported entities for things to deprecate. -} -- | Located Warning Declarations -type LWarnDecls pass = Located (WarnDecls pass) +type LWarnDecls pass = XRec pass (WarnDecls pass) -- Note [Pragma source text] in GHC.Types.Basic -- | Warning pragma Declarations @@ -2527,10 +2529,10 @@ type instance XWarnings (GhcPass _) = NoExtField type instance XXWarnDecls (GhcPass _) = NoExtCon -- | Located Warning pragma Declaration -type LWarnDecl pass = Located (WarnDecl pass) +type LWarnDecl pass = XRec pass (WarnDecl pass) -- | Warning pragma Declaration -data WarnDecl pass = Warning (XWarning pass) [Located (IdP pass)] WarningTxt +data WarnDecl pass = Warning (XWarning pass) [XRec pass (IdP pass)] WarningTxt | XWarnDecl !(XXWarnDecl pass) type instance XWarning (GhcPass _) = NoExtField @@ -2558,13 +2560,13 @@ instance OutputableBndr (IdP (GhcPass p)) -} -- | Located Annotation Declaration -type LAnnDecl pass = Located (AnnDecl pass) +type LAnnDecl pass = XRec pass (AnnDecl pass) -- | Annotation Declaration data AnnDecl pass = HsAnnotation (XHsAnnotation pass) SourceText -- Note [Pragma source text] in GHC.Types.Basic - (AnnProvenance (IdP pass)) (Located (HsExpr pass)) + (AnnProvenance (IdP pass)) (XRec pass (HsExpr pass)) -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen', -- 'GHC.Parser.Annotation.AnnType' -- 'GHC.Parser.Annotation.AnnModule' @@ -2610,15 +2612,15 @@ pprAnnProvenance (TypeAnnProvenance (L _ name)) -} -- | Located Role Annotation Declaration -type LRoleAnnotDecl pass = Located (RoleAnnotDecl pass) +type LRoleAnnotDecl pass = XRec pass (RoleAnnotDecl pass) -- See #8185 for more info about why role annotations are -- top-level declarations -- | Role Annotation Declaration data RoleAnnotDecl pass = RoleAnnotDecl (XCRoleAnnotDecl pass) - (Located (IdP pass)) -- type constructor - [Located (Maybe Role)] -- optional annotations + (XRec pass (IdP pass)) -- type constructor + [XRec pass (Maybe Role)] -- optional annotations -- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType', -- 'GHC.Parser.Annotation.AnnRole' |