summaryrefslogtreecommitdiff
path: root/compiler/Language/Haskell
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2021-02-21 21:23:40 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-20 07:48:38 -0400
commit95275a5f25a2e70b71240d4756109180486af1b1 (patch)
treeeb4801bb0e00098b8b9d513479de4fbbd779ddac /compiler/Language/Haskell
parentf940fd466a86c2f8e93237b36835797be3f3c898 (diff)
downloadhaskell-95275a5f25a2e70b71240d4756109180486af1b1.tar.gz
GHC Exactprint main commit
Metric Increase: T10370 parsing001 Updates haddock submodule
Diffstat (limited to 'compiler/Language/Haskell')
-rw-r--r--compiler/Language/Haskell/Syntax/Decls.hs71
-rw-r--r--compiler/Language/Haskell/Syntax/Expr.hs60
-rw-r--r--compiler/Language/Haskell/Syntax/Extension.hs74
-rw-r--r--compiler/Language/Haskell/Syntax/Pat.hs33
-rw-r--r--compiler/Language/Haskell/Syntax/Type.hs23
5 files changed, 166 insertions, 95 deletions
diff --git a/compiler/Language/Haskell/Syntax/Decls.hs b/compiler/Language/Haskell/Syntax/Decls.hs
index 0df44e8016..81369c3b09 100644
--- a/compiler/Language/Haskell/Syntax/Decls.hs
+++ b/compiler/Language/Haskell/Syntax/Decls.hs
@@ -10,6 +10,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow]
-- in module Language.Haskell.Syntax.Extension
+{-# LANGUAGE ViewPatterns #-}
{-
(c) The University of Glasgow 2006
@@ -27,7 +28,7 @@
-- @InstDecl@, @DefaultDecl@ and @ForeignDecl@.
module Language.Haskell.Syntax.Decls (
-- * Toplevel declarations
- HsDecl(..), LHsDecl, HsDataDefn(..), HsDeriving, LHsFunDep,
+ HsDecl(..), LHsDecl, HsDataDefn(..), HsDeriving, LHsFunDep, FunDep(..),
HsDerivingClause(..), LHsDerivingClause, DerivClauseTys(..), LDerivClauseTys,
NewOrData(..), newOrDataToFlavour,
StandaloneKindSig(..), LStandaloneKindSig,
@@ -108,7 +109,6 @@ import GHC.Types.Name.Set
import GHC.Types.Fixity
-- others:
-import GHC.Core.Class
import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Types.SrcLoc
@@ -229,7 +229,7 @@ data HsGroup p
hs_annds :: [LAnnDecl p],
hs_ruleds :: [LRuleDecls p],
- hs_docs :: [LDocDecl]
+ hs_docs :: [LDocDecl p]
}
| XHsGroup !(XXHsGroup p)
@@ -445,7 +445,7 @@ data TyClDecl pass
tcdMeths :: LHsBinds pass, -- ^ Default methods
tcdATs :: [LFamilyDecl pass], -- ^ Associated types;
tcdATDefs :: [LTyFamDefltDecl pass], -- ^ Associated type defaults
- tcdDocs :: [LDocDecl] -- ^ Haddock docs
+ tcdDocs :: [LDocDecl pass] -- ^ Haddock docs
}
-- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnClass',
-- 'GHC.Parser.Annotation.AnnWhere','GHC.Parser.Annotation.AnnOpen',
@@ -457,7 +457,13 @@ data TyClDecl pass
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
| XTyClDecl !(XXTyClDecl pass)
-type LHsFunDep pass = XRec pass (FunDep (LIdP pass))
+data FunDep pass
+ = FunDep (XCFunDep pass)
+ [LIdP pass]
+ [LIdP pass]
+ | XFunDep !(XXFunDep pass)
+
+type LHsFunDep pass = XRec pass (FunDep pass)
data DataDeclRn = DataDeclRn
{ tcdDataCusk :: Bool -- ^ does this have a CUSK?
@@ -818,6 +824,7 @@ type LFamilyDecl pass = XRec pass (FamilyDecl pass)
data FamilyDecl pass = FamilyDecl
{ fdExt :: XCFamilyDecl pass
, fdInfo :: FamilyInfo pass -- type/data, closed/open
+ , fdTopLevel :: TopLevelFlag -- used for printing only
, fdLName :: LIdP pass -- type constructor
, fdTyVars :: LHsQTyVars pass -- type variables
-- See Note [TyVar binders for associated declarations]
@@ -848,11 +855,13 @@ type LInjectivityAnn pass = XRec pass (InjectivityAnn pass)
--
-- This will be represented as "InjectivityAnn `r` [`a`, `c`]"
data InjectivityAnn pass
- = InjectivityAnn (LIdP pass) [LIdP pass]
+ = InjectivityAnn (XCInjectivityAnn pass)
+ (LIdP pass) [LIdP pass]
-- ^ - 'GHC.Parser.Annotation.AnnKeywordId' :
-- 'GHC.Parser.Annotation.AnnRarrow', 'GHC.Parser.Annotation.AnnVbar'
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
+ | XInjectivityAnn !(XXInjectivityAnn pass)
data FamilyInfo pass
= DataFamily
@@ -916,7 +925,7 @@ data HsDataDefn pass -- The payload of a data type defn
| XHsDataDefn !(XXHsDataDefn pass)
-- | Haskell Deriving clause
-type HsDeriving pass = XRec pass [LHsDerivingClause pass]
+type HsDeriving 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.
@@ -1063,7 +1072,7 @@ data ConDecl pass
{ con_ext :: XConDeclH98 pass
, con_name :: LIdP pass
- , con_forall :: XRec pass Bool
+ , con_forall :: Bool
-- ^ True <=> explicit user-written forall
-- e.g. data T a = forall b. MkT b (b->a)
-- con_ex_tvs = {b}
@@ -1302,12 +1311,15 @@ type LTyFamDefltDecl pass = XRec pass (TyFamDefltDecl pass)
type LTyFamInstDecl pass = XRec pass (TyFamInstDecl pass)
-- | Type Family Instance Declaration
-newtype TyFamInstDecl pass = TyFamInstDecl { tfid_eqn :: TyFamInstEqn pass }
+data TyFamInstDecl pass
+ = TyFamInstDecl { tfid_xtn :: XCTyFamInstDecl pass
+ , tfid_eqn :: TyFamInstEqn pass }
-- ^
-- - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnType',
-- 'GHC.Parser.Annotation.AnnInstance',
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
+ | XTyFamInstDecl !(XXTyFamInstDecl pass)
----------------- Data family instances -------------
@@ -1448,13 +1460,14 @@ type LDerivStrategy pass = XRec pass (DerivStrategy pass)
-- | Which technique the user explicitly requested when deriving an instance.
data DerivStrategy pass
-- See Note [Deriving strategies] in GHC.Tc.Deriv
- = StockStrategy -- ^ GHC's \"standard\" strategy, which is to implement a
+ = StockStrategy (XStockStrategy pass)
+ -- ^ 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.)
- | AnyclassStrategy -- ^ @-XDeriveAnyClass@
- | NewtypeStrategy -- ^ @-XGeneralizedNewtypeDeriving@
+ | AnyclassStrategy (XAnyClassStrategy pass) -- ^ @-XDeriveAnyClass@
+ | NewtypeStrategy (XNewtypeStrategy pass) -- ^ @-XGeneralizedNewtypeDeriving@
| ViaStrategy (XViaStrategy pass)
-- ^ @-XDerivingVia@
@@ -1462,10 +1475,10 @@ data DerivStrategy pass
derivStrategyName :: DerivStrategy a -> SDoc
derivStrategyName = text . go
where
- go StockStrategy = "stock"
- go AnyclassStrategy = "anyclass"
- go NewtypeStrategy = "newtype"
- go (ViaStrategy {}) = "via"
+ go StockStrategy {} = "stock"
+ go AnyclassStrategy {} = "anyclass"
+ go NewtypeStrategy {} = "newtype"
+ go ViaStrategy {} = "via"
{-
************************************************************************
@@ -1693,7 +1706,7 @@ pprFullRuleName (L _ (st, n)) = pprWithSourceText st (doubleQuotes $ ftext n)
-}
-- | Located Documentation comment Declaration
-type LDocDecl = Located (DocDecl)
+type LDocDecl pass = XRec pass (DocDecl)
-- | Documentation comment Declaration
data DocDecl
@@ -1756,7 +1769,7 @@ type LAnnDecl pass = XRec pass (AnnDecl pass)
data AnnDecl pass = HsAnnotation
(XHsAnnotation pass)
SourceText -- Note [Pragma source text] in GHC.Types.SourceText
- (AnnProvenance (IdP pass)) (XRec pass (HsExpr pass))
+ (AnnProvenance pass) (XRec pass (HsExpr pass))
-- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnOpen',
-- 'GHC.Parser.Annotation.AnnType'
-- 'GHC.Parser.Annotation.AnnModule'
@@ -1766,18 +1779,18 @@ data AnnDecl pass = HsAnnotation
| XAnnDecl !(XXAnnDecl pass)
-- | Annotation Provenance
-data AnnProvenance name = ValueAnnProvenance (Located name)
- | TypeAnnProvenance (Located name)
+data AnnProvenance pass = ValueAnnProvenance (LIdP pass)
+ | TypeAnnProvenance (LIdP pass)
| ModuleAnnProvenance
-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
-annProvenanceName_maybe (TypeAnnProvenance (L _ name)) = Just name
-annProvenanceName_maybe ModuleAnnProvenance = Nothing
+-- deriving instance Functor AnnProvenance
+-- deriving instance Foldable AnnProvenance
+-- deriving instance Traversable AnnProvenance
+-- deriving instance (Data pass) => Data (AnnProvenance pass)
+
+annProvenanceName_maybe :: forall p. UnXRec p => AnnProvenance p -> Maybe (IdP p)
+annProvenanceName_maybe (ValueAnnProvenance (unXRec @p -> name)) = Just name
+annProvenanceName_maybe (TypeAnnProvenance (unXRec @p -> name)) = Just name
+annProvenanceName_maybe ModuleAnnProvenance = Nothing
{-
************************************************************************
diff --git a/compiler/Language/Haskell/Syntax/Expr.hs b/compiler/Language/Haskell/Syntax/Expr.hs
index 9967a78314..cb84d25489 100644
--- a/compiler/Language/Haskell/Syntax/Expr.hs
+++ b/compiler/Language/Haskell/Syntax/Expr.hs
@@ -143,26 +143,37 @@ values (see function @mkRdrRecordUpd@ in 'GHC.Parser.PostProcess').
-- | RecordDotSyntax field updates
-newtype FieldLabelStrings =
- FieldLabelStrings [Located FieldLabelString]
- deriving (Data)
+newtype FieldLabelStrings p =
+ FieldLabelStrings [Located (HsFieldLabel p)]
-instance Outputable FieldLabelStrings where
+instance Outputable (FieldLabelStrings p) where
ppr (FieldLabelStrings flds) =
hcat (punctuate dot (map (ppr . unLoc) flds))
+instance OutputableBndr (FieldLabelStrings p) where
+ pprInfixOcc = pprFieldLabelStrings
+ pprPrefixOcc = pprFieldLabelStrings
+
+pprFieldLabelStrings :: FieldLabelStrings p -> SDoc
+pprFieldLabelStrings (FieldLabelStrings flds) =
+ hcat (punctuate dot (map (ppr . unLoc) flds))
+
+instance Outputable (HsFieldLabel p) where
+ ppr (HsFieldLabel _ s) = ppr s
+ ppr XHsFieldLabel{} = text "XHsFieldLabel"
+
-- Field projection updates (e.g. @foo.bar.baz = 1@). See Note
-- [RecordDotSyntax field updates].
-type RecProj arg = HsRecField' FieldLabelStrings arg
+type RecProj p arg = HsRecField' (FieldLabelStrings p) arg
-- The phantom type parameter @p@ is for symmetry with @LHsRecField p
-- arg@ in the definition of @data Fbind@ (see GHC.Parser.Process).
-type LHsRecProj p arg = Located (RecProj arg)
+type LHsRecProj p arg = XRec p (RecProj p arg)
-- These two synonyms are used in the definition of syntax @RecordUpd@
-- below.
-type RecUpdProj p = RecProj (LHsExpr p)
-type LHsRecUpdProj p = Located (RecUpdProj p)
+type RecUpdProj p = RecProj p (LHsExpr p)
+type LHsRecUpdProj p = XRec p (RecUpdProj p)
{-
************************************************************************
@@ -366,7 +377,7 @@ data HsExpr p
-- Note [ExplicitTuple]
| ExplicitTuple
(XExplicitTuple p)
- [LHsTupArg p]
+ [HsTupArg p]
Boxity
-- | Used for unboxed sum types
@@ -419,7 +430,7 @@ data HsExpr p
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
| HsLet (XLet p)
- (LHsLocalBinds p)
+ (HsLocalBinds p)
(LHsExpr p)
-- | - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnDo',
@@ -483,7 +494,7 @@ data HsExpr p
| HsGetField {
gf_ext :: XGetField p
, gf_expr :: LHsExpr p
- , gf_field :: Located FieldLabelString
+ , gf_field :: Located (HsFieldLabel p)
}
-- | Record field selector. e.g. @(.x)@ or @(.x.y)@
@@ -496,7 +507,7 @@ data HsExpr p
| HsProjection {
proj_ext :: XProjection p
- , proj_flds :: [Located FieldLabelString]
+ , proj_flds :: [Located (HsFieldLabel p)]
}
-- | Expression with an explicit type signature. @e :: type@
@@ -611,6 +622,15 @@ type family PendingTcSplice' p
-- ---------------------------------------------------------------------
+data HsFieldLabel p
+ = HsFieldLabel
+ { hflExt :: XCHsFieldLabel p
+ , hflLabel :: Located FieldLabelString
+ }
+ | XHsFieldLabel !(XXHsFieldLabel p)
+
+-- ---------------------------------------------------------------------
+
-- | A pragma, written as {-# ... #-}, that may appear within an expression.
data HsPragE p
= HsPragSCC (XSCC p)
@@ -790,7 +810,7 @@ See also #13680, which requested [] @Int to work.
-----------------------
pprExternalSrcLoc :: (StringLiteral,(Int,Int),(Int,Int)) -> SDoc
-pprExternalSrcLoc (StringLiteral _ src,(n1,n2),(n3,n4))
+pprExternalSrcLoc (StringLiteral _ src _,(n1,n2),(n3,n4))
= ppr (src,(n1,n2),(n3,n4))
{-
@@ -897,7 +917,7 @@ data HsCmd id
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
| HsCmdLet (XCmdLet id)
- (LHsLocalBinds id) -- let(rec)
+ (HsLocalBinds id) -- let(rec)
(LHsCmd id)
-- ^ - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnLet',
-- 'GHC.Parser.Annotation.AnnOpen' @'{'@,
@@ -1057,8 +1077,8 @@ isInfixMatch match = case m_ctxt match of
data GRHSs p body
= GRHSs {
grhssExt :: XCGRHSs p body,
- grhssGRHSs :: [LGRHS p body], -- ^ Guarded RHSs
- grhssLocalBinds :: LHsLocalBinds p -- ^ The where clause
+ grhssGRHSs :: [LGRHS p body], -- ^ Guarded RHSs
+ grhssLocalBinds :: HsLocalBinds p -- ^ The where clause
}
| XGRHSs !(XXGRHSs p body)
@@ -1175,7 +1195,7 @@ data StmtLR idL idR body -- body should always be (LHs**** idR)
-- 'GHC.Parser.Annotation.AnnOpen' @'{'@,'GHC.Parser.Annotation.AnnClose' @'}'@,
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
- | LetStmt (XLetStmt idL idR body) (LHsLocalBindsLR idL idR)
+ | LetStmt (XLetStmt idL idR body) (HsLocalBindsLR idL idR)
-- ParStmts only occur in a list/monad comprehension
| ParStmt (XParStmt idL idR body) -- Post typecheck,
@@ -1215,7 +1235,8 @@ data StmtLR idL idR body -- body should always be (LHs**** idR)
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
| RecStmt
{ recS_ext :: XRecStmt idL idR body
- , recS_stmts :: [LStmtLR idL idR body]
+ , recS_stmts :: XRec idR [LStmtLR idL idR body]
+ -- Assume XRec is the same for idL and idR, pick one arbitrarily
-- The next two fields are only valid after renaming
, recS_later_ids :: [IdP idR]
@@ -1562,7 +1583,8 @@ data HsBracket p
| DecBrL (XDecBrL p) [LHsDecl p] -- [d| decls |]; result of parser
| DecBrG (XDecBrG p) (HsGroup p) -- [d| decls |]; result of renamer
| TypBr (XTypBr p) (LHsType p) -- [t| type |]
- | VarBr (XVarBr p) Bool (IdP p) -- True: 'x, False: ''T
+ | VarBr (XVarBr p) Bool (LIdP p)
+ -- True: 'x, False: ''T
-- (The Bool flag is used only in pprHsBracket)
| TExpBr (XTExpBr p) (LHsExpr p) -- [|| expr ||]
| XBracket !(XXBracket p) -- Note [Trees that Grow] extension point
diff --git a/compiler/Language/Haskell/Syntax/Extension.hs b/compiler/Language/Haskell/Syntax/Extension.hs
index f843bee1a2..cd9804b7f9 100644
--- a/compiler/Language/Haskell/Syntax/Extension.hs
+++ b/compiler/Language/Haskell/Syntax/Extension.hs
@@ -10,7 +10,6 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow]
-- in module Language.Haskell.Syntax.Extension
@@ -105,6 +104,8 @@ noExtCon x = case x of {}
-- See Note [XRec and SrcSpans in the AST]
type family XRec p a = r | r -> a
+type family Anno a = b -- See Note [XRec and Anno in the AST] in GHC.Parser.Annotation
+
{-
Note [XRec and SrcSpans in the AST]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -134,13 +135,16 @@ class UnXRec p where
-- | We can map over the underlying type contained in an @XRec@ while preserving
-- the annotation as is.
--- See Note [XRec and SrcSpans in the AST]
class MapXRec p where
- mapXRec :: (a -> b) -> XRec p a -> XRec p b
+ mapXRec :: (Anno a ~ Anno b) => (a -> b) -> XRec p a -> XRec p b
+-- See Note [XRec and SrcSpans in the AST]
+-- See Note [XRec and Anno in the AST] in GHC.Parser.Annotation
+-- AZ: Is there a way to not have Anno in this file, but still have MapXRec?
+-- Perhaps define XRec with an additional b parameter, only used in Hs as (Anno b)?
-- | The trivial wrapper that carries no additional information
-- See Note [XRec and SrcSpans in the AST]
-class WrapXRec p where
+class WrapXRec p a where
wrapXRec :: a -> XRec p a
-- | Maps the "normal" id type for a given pass
@@ -246,6 +250,11 @@ type family XClassDecl x
type family XXTyClDecl x
-- -------------------------------------
+-- FunDep type families
+type family XCFunDep x
+type family XXFunDep x
+
+-- -------------------------------------
-- TyClGroup type families
type family XCTyClGroup x
type family XXTyClGroup x
@@ -290,6 +299,11 @@ type family XCFamEqn x r
type family XXFamEqn x r
-- -------------------------------------
+-- TyFamInstDecl type families
+type family XCTyFamInstDecl x
+type family XXTyFamInstDecl x
+
+-- -------------------------------------
-- ClsInstDecl type families
type family XCClsInstDecl x
type family XXClsInstDecl x
@@ -308,7 +322,10 @@ type family XXDerivDecl x
-- -------------------------------------
-- DerivStrategy type family
-type family XViaStrategy x
+type family XStockStrategy x
+type family XAnyClassStrategy x
+type family XNewtypeStrategy x
+type family XViaStrategy x
-- -------------------------------------
-- DefaultDecl type families
@@ -357,6 +374,11 @@ type family XXAnnDecl x
type family XCRoleAnnotDecl x
type family XXRoleAnnotDecl x
+-- -------------------------------------
+-- InjectivityAnn type families
+type family XCInjectivityAnn x
+type family XXInjectivityAnn x
+
-- =====================================================================
-- Type families for the HsExpr extension points
@@ -403,6 +425,11 @@ type family XPragE x
type family XXExpr x
-- -------------------------------------
+-- FieldLabel type families
+type family XCHsFieldLabel x
+type family XXHsFieldLabel x
+
+-- -------------------------------------
-- HsPragE type families
type family XSCC x
type family XXPragE x
@@ -535,24 +562,25 @@ type family XXOverLit x
-- =====================================================================
-- Type families for the HsPat extension points
-type family XWildPat x
-type family XVarPat x
-type family XLazyPat x
-type family XAsPat x
-type family XParPat x
-type family XBangPat x
-type family XListPat x
-type family XTuplePat x
-type family XSumPat x
-type family XConPat x
-type family XViewPat x
-type family XSplicePat x
-type family XLitPat x
-type family XNPat x
-type family XNPlusKPat x
-type family XSigPat x
-type family XCoPat x
-type family XXPat x
+type family XWildPat x
+type family XVarPat x
+type family XLazyPat x
+type family XAsPat x
+type family XParPat x
+type family XBangPat x
+type family XListPat x
+type family XTuplePat x
+type family XSumPat x
+type family XConPat x
+type family XViewPat x
+type family XSplicePat x
+type family XLitPat x
+type family XNPat x
+type family XNPlusKPat x
+type family XSigPat x
+type family XCoPat x
+type family XXPat x
+type family XHsRecField x
-- =====================================================================
-- Type families for the HsTypes type families
diff --git a/compiler/Language/Haskell/Syntax/Pat.hs b/compiler/Language/Haskell/Syntax/Pat.hs
index 8de0cc96d3..8c3309f477 100644
--- a/compiler/Language/Haskell/Syntax/Pat.hs
+++ b/compiler/Language/Haskell/Syntax/Pat.hs
@@ -45,7 +45,6 @@ import GHC.Core.Ppr ( {- instance OutputableBndr TyVar -} )
import GHC.Utils.Outputable
import GHC.Types.SrcLoc
-- libraries:
-import Data.Data hiding (TyCon,Fixity)
type LPat p = XRec p (Pat p)
@@ -227,9 +226,9 @@ type family ConLikeP x
-- | Haskell Constructor Pattern Details
type HsConPatDetails p = HsConDetails (HsPatSigType (NoGhcTc p)) (LPat p) (HsRecFields p (LPat p))
-hsConPatArgs :: HsConPatDetails p -> [LPat p]
+hsConPatArgs :: forall p . (UnXRec p) => HsConPatDetails p -> [LPat p]
hsConPatArgs (PrefixCon _ ps) = ps
-hsConPatArgs (RecCon fs) = map (hsRecFieldArg . unLoc) (rec_flds fs)
+hsConPatArgs (RecCon fs) = map (hsRecFieldArg . unXRec @p) (rec_flds fs)
hsConPatArgs (InfixCon p1 p2) = [p1,p2]
-- | Haskell Record Fields
@@ -241,7 +240,8 @@ data HsRecFields p arg -- A bunch of record fields
-- Used for both expressions and patterns
= HsRecFields { rec_flds :: [LHsRecField p arg],
rec_dotdot :: Maybe (Located Int) } -- Note [DotDot fields]
- deriving (Functor, Foldable, Traversable)
+ -- AZ:The XRec for LHsRecField makes the derivings fail.
+ -- deriving (Functor, Foldable, Traversable)
-- Note [DotDot fields]
@@ -259,13 +259,13 @@ data HsRecFields p arg -- A bunch of record fields
-- and the remainder being 'filled in' implicitly
-- | Located Haskell Record Field
-type LHsRecField' p arg = Located (HsRecField' p arg)
+type LHsRecField' p id arg = XRec p (HsRecField' id arg)
-- | Located Haskell Record Field
-type LHsRecField p arg = Located (HsRecField p arg)
+type LHsRecField p arg = XRec p (HsRecField p arg)
-- | Located Haskell Record Update Field
-type LHsRecUpdField p = Located (HsRecUpdField p)
+type LHsRecUpdField p = XRec p (HsRecUpdField p)
-- | Haskell Record Field
type HsRecField p arg = HsRecField' (FieldOcc p) arg
@@ -279,10 +279,11 @@ type HsRecUpdField p = HsRecField' (AmbiguousFieldOcc p) (LHsExpr p)
--
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
data HsRecField' id arg = HsRecField {
+ hsRecFieldAnn :: XHsRecField id,
hsRecFieldLbl :: Located id,
hsRecFieldArg :: arg, -- ^ Filled in by renamer when punning
hsRecPun :: Bool -- ^ Note [Punning]
- } deriving (Data, Functor, Foldable, Traversable)
+ } deriving (Functor, Foldable, Traversable)
-- Note [Punning]
@@ -339,12 +340,12 @@ data HsRecField' id arg = HsRecField {
--
-- See also Note [Disambiguating record fields] in GHC.Tc.Gen.Head.
-hsRecFields :: HsRecFields p arg -> [XCFieldOcc p]
-hsRecFields rbinds = map (unLoc . hsRecFieldSel . unLoc) (rec_flds rbinds)
+hsRecFields :: forall p arg. UnXRec p => HsRecFields p arg -> [XCFieldOcc p]
+hsRecFields rbinds = map (unLoc . hsRecFieldSel . unXRec @p) (rec_flds rbinds)
-- Probably won't typecheck at once, things have changed :/
-hsRecFieldsArgs :: HsRecFields p arg -> [arg]
-hsRecFieldsArgs rbinds = map (hsRecFieldArg . unLoc) (rec_flds rbinds)
+hsRecFieldsArgs :: forall p arg. UnXRec p => HsRecFields p arg -> [arg]
+hsRecFieldsArgs rbinds = map (hsRecFieldArg . unXRec @p) (rec_flds rbinds)
hsRecFieldSel :: HsRecField pass arg -> Located (XCFieldOcc pass)
hsRecFieldSel = fmap extFieldOcc . hsRecFieldLbl
@@ -358,7 +359,7 @@ hsRecFieldSel = fmap extFieldOcc . hsRecFieldLbl
************************************************************************
-}
-instance (Outputable arg)
+instance (Outputable arg, Outputable (XRec p (HsRecField p arg)))
=> Outputable (HsRecFields p arg) where
ppr (HsRecFields { rec_flds = flds, rec_dotdot = Nothing })
= braces (fsep (punctuate comma (map ppr flds)))
@@ -367,8 +368,8 @@ instance (Outputable arg)
where
dotdot = text ".." <+> whenPprDebug (ppr (drop n flds))
-instance (Outputable p, Outputable arg)
+instance (Outputable p, OutputableBndr p, Outputable arg)
=> Outputable (HsRecField' p arg) where
- ppr (HsRecField { hsRecFieldLbl = f, hsRecFieldArg = arg,
+ ppr (HsRecField { hsRecFieldLbl = L _ f, hsRecFieldArg = arg,
hsRecPun = pun })
- = ppr f <+> (ppUnless pun $ equals <+> ppr arg)
+ = pprPrefixOcc f <+> (ppUnless pun $ equals <+> ppr arg)
diff --git a/compiler/Language/Haskell/Syntax/Type.hs b/compiler/Language/Haskell/Syntax/Type.hs
index f0114403d8..6dc312859d 100644
--- a/compiler/Language/Haskell/Syntax/Type.hs
+++ b/compiler/Language/Haskell/Syntax/Type.hs
@@ -432,7 +432,7 @@ data HsPSRn = HsPSRn
deriving Data
-- | Located Haskell Signature Type
-type LHsSigType pass = Located (HsSigType pass) -- Implicit only
+type LHsSigType pass = XRec pass (HsSigType pass) -- Implicit only
-- | Located Haskell Wildcard Type
type LHsWcType pass = HsWildCardBndrs pass (LHsType pass) -- Wildcard only
@@ -893,7 +893,7 @@ data HsType pass
-- For adding new constructors via Trees that Grow
| XHsType
- (XXType pass)
+ !(XXType pass)
-- An escape hatch for tunnelling a Core 'Type' through 'HsType'.
-- For more details on how this works, see:
@@ -917,9 +917,9 @@ data HsTyLit
data HsArrow pass
= HsUnrestrictedArrow IsUnicodeSyntax
-- ^ a -> b or a → b
- | HsLinearArrow IsUnicodeSyntax
+ | HsLinearArrow IsUnicodeSyntax (Maybe AddApiAnn)
-- ^ a %1 -> b or a %1 → b, or a ⊸ b
- | HsExplicitMult IsUnicodeSyntax (LHsType pass)
+ | HsExplicitMult IsUnicodeSyntax (Maybe AddApiAnn) (LHsType pass)
-- ^ a %m -> b or a %m → b (very much including `a %Many -> b`!
-- This is how the programmer wrote it). It is stored as an
-- `HsType` so as to preserve the syntax as written in the
@@ -939,7 +939,7 @@ hsScaledThing (HsScaled _ t) = t
-- the shorthands work trivially at each pass.
hsUnrestricted, hsLinear :: a -> HsScaled pass a
hsUnrestricted = HsScaled (HsUnrestrictedArrow NormalSyntax)
-hsLinear = HsScaled (HsLinearArrow NormalSyntax)
+hsLinear = HsScaled (HsLinearArrow NormalSyntax Nothing)
instance Outputable a => Outputable (HsScaled pass a) where
ppr (HsScaled _cnt t) = -- ppr cnt <> ppr t
@@ -1258,7 +1258,7 @@ type LFieldOcc pass = XRec pass (FieldOcc pass)
-- We store both the 'RdrName' the user originally wrote, and after the renamer,
-- the selector function.
data FieldOcc pass = FieldOcc { extFieldOcc :: XCFieldOcc pass
- , rdrNameFieldOcc :: Located RdrName
+ , rdrNameFieldOcc :: LocatedN RdrName
-- ^ See Note [Located RdrNames] in "GHC.Hs.Expr"
}
@@ -1270,6 +1270,13 @@ deriving instance (Eq (XCFieldOcc pass), Eq (XXFieldOcc pass)) => Eq (FieldOcc p
instance Outputable (FieldOcc pass) where
ppr = ppr . rdrNameFieldOcc
+instance OutputableBndr (FieldOcc pass) where
+ pprInfixOcc = pprInfixOcc . unLoc . rdrNameFieldOcc
+ pprPrefixOcc = pprPrefixOcc . unLoc . rdrNameFieldOcc
+
+instance OutputableBndr (GenLocated SrcSpan (FieldOcc pass)) where
+ pprInfixOcc = pprInfixOcc . unLoc
+ pprPrefixOcc = pprPrefixOcc . unLoc
-- | Ambiguous Field Occurrence
--
@@ -1284,8 +1291,8 @@ instance Outputable (FieldOcc pass) where
-- Note [Disambiguating record fields] in "GHC.Tc.Gen.Head".
-- See Note [Located RdrNames] in "GHC.Hs.Expr"
data AmbiguousFieldOcc pass
- = Unambiguous (XUnambiguous pass) (Located RdrName)
- | Ambiguous (XAmbiguous pass) (Located RdrName)
+ = Unambiguous (XUnambiguous pass) (LocatedN RdrName)
+ | Ambiguous (XAmbiguous pass) (LocatedN RdrName)
| XAmbiguousFieldOcc !(XXAmbiguousFieldOcc pass)