diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2022-10-23 23:31:55 +0100 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2022-10-23 23:31:55 +0100 |
commit | 42af525b29d8237b923181ce59440fd14d3efd2a (patch) | |
tree | 7772a1ece26f603b7076b7b98464f6e7118fcd5f | |
parent | 0e5a0c4c03ed8a74f7bfd459e23cb63eb751b10e (diff) | |
download | haskell-42af525b29d8237b923181ce59440fd14d3efd2a.tar.gz |
Start on making LocatedN more directwip/az/locatedn-epa-improve
52 files changed, 417 insertions, 303 deletions
diff --git a/compiler/GHC/Hs/Expr.hs b/compiler/GHC/Hs/Expr.hs index b24531f790..d3548b8eac 100644 --- a/compiler/GHC/Hs/Expr.hs +++ b/compiler/GHC/Hs/Expr.hs @@ -148,7 +148,7 @@ mkSyntaxExpr = SyntaxExprRn -- | Make a 'SyntaxExpr' from a 'Name' (the "rn" is because this is used in the -- renamer). mkRnSyntaxExpr :: Name -> SyntaxExprRn -mkRnSyntaxExpr name = SyntaxExprRn $ HsVar noExtField $ noLocA name +mkRnSyntaxExpr name = SyntaxExprRn $ HsVar noExtField $ noLocN name instance Outputable SyntaxExprRn where ppr (SyntaxExprRn expr) = ppr expr diff --git a/compiler/GHC/Hs/Extension.hs b/compiler/GHC/Hs/Extension.hs index 922288650f..2ae33f9466 100644 --- a/compiler/GHC/Hs/Extension.hs +++ b/compiler/GHC/Hs/Extension.hs @@ -105,7 +105,7 @@ type instance Anno RdrName = SrcSpanAnnN type instance Anno Name = SrcSpanAnnN type instance Anno Id = SrcSpanAnnN -type IsSrcSpanAnn p a = ( Anno (IdGhcP p) ~ SrcSpanAnn' (EpAnn a), +type IsSrcSpanAnn p a = ( Anno (IdGhcP p) ~ EpAnnS NameAnn, IsPass p) instance UnXRec (GhcPass p) where diff --git a/compiler/GHC/Hs/Pat.hs b/compiler/GHC/Hs/Pat.hs index 39a788aab5..9121918ba3 100644 --- a/compiler/GHC/Hs/Pat.hs +++ b/compiler/GHC/Hs/Pat.hs @@ -420,7 +420,7 @@ mkPrefixConPat :: DataCon -> [LPat GhcTc] -> [Type] -> LPat GhcTc -- Make a vanilla Prefix constructor pattern mkPrefixConPat dc pats tys - = noLocA $ ConPat { pat_con = noLocA (RealDataCon dc) + = noLocA $ ConPat { pat_con = noLocN (RealDataCon dc) , pat_args = PrefixCon [] pats , pat_con_ext = ConPatTc { cpt_tvs = [] diff --git a/compiler/GHC/Hs/Type.hs b/compiler/GHC/Hs/Type.hs index 5e614ff79d..e51a6d26e8 100644 --- a/compiler/GHC/Hs/Type.hs +++ b/compiler/GHC/Hs/Type.hs @@ -354,10 +354,10 @@ type instance XXTyLit (GhcPass _) = DataConCantHappen oneDataConHsTy :: HsType GhcRn -oneDataConHsTy = HsTyVar noAnn NotPromoted (noLocA oneDataConName) +oneDataConHsTy = HsTyVar noAnn NotPromoted (noLocN oneDataConName) manyDataConHsTy :: HsType GhcRn -manyDataConHsTy = HsTyVar noAnn NotPromoted (noLocA manyDataConName) +manyDataConHsTy = HsTyVar noAnn NotPromoted (noLocN manyDataConName) hsLinear :: a -> HsScaled (GhcPass p) a hsLinear = HsScaled (HsLinearArrow (HsPct1 noHsTok noHsUniTok)) @@ -436,7 +436,7 @@ hsAllLTyVarNames (HsQTvs { hsq_ext = kvs = kvs ++ hsLTyVarNames tvs hsLTyVarLocName :: LHsTyVarBndr flag (GhcPass p) -> LocatedN (IdP (GhcPass p)) -hsLTyVarLocName (L l a) = L (l2l l) (hsTyVarName a) +hsLTyVarLocName (L l a) = L (l2ln l) (hsTyVarName a) hsLTyVarLocNames :: LHsQTyVars (GhcPass p) -> [LocatedN (IdP (GhcPass p))] hsLTyVarLocNames qtvs = map hsLTyVarLocName (hsQTvExplicit qtvs) diff --git a/compiler/GHC/Hs/Utils.hs b/compiler/GHC/Hs/Utils.hs index eb708cd295..d03fd303cc 100644 --- a/compiler/GHC/Hs/Utils.hs +++ b/compiler/GHC/Hs/Utils.hs @@ -283,7 +283,7 @@ mkHsCaseAlt pat expr nlHsTyApp :: Id -> [Type] -> LHsExpr GhcTc nlHsTyApp fun_id tys - = noLocA (mkHsWrap (mkWpTyApps tys) (HsVar noExtField (noLocA fun_id))) + = noLocA (mkHsWrap (mkWpTyApps tys) (HsVar noExtField (noLocN fun_id))) nlHsTyApps :: Id -> [Type] -> [LHsExpr GhcTc] -> LHsExpr GhcTc nlHsTyApps fun_id tys xs = foldl' nlHsApp (nlHsTyApp fun_id tys) xs @@ -449,7 +449,7 @@ mkLetStmt anns binds = LetStmt anns binds -- | A useful function for building @OpApps@. The operator is always a -- variable, and we don't know the fixity yet. mkHsOpApp :: LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs -mkHsOpApp e1 op e2 = OpApp noAnn e1 (noLocA (HsVar noExtField (noLocA op))) e2 +mkHsOpApp e1 op e2 = OpApp noAnn e1 (noLocA (HsVar noExtField (noLocN op))) e2 mkHsString :: String -> HsLit (GhcPass p) mkHsString s = HsString NoSourceText (mkFastString s) @@ -473,11 +473,11 @@ mkConLikeTc con = XExpr (ConLikeTc con [] []) nlHsVar :: IsSrcSpanAnn p a => IdP (GhcPass p) -> LHsExpr (GhcPass p) -nlHsVar n = noLocA (HsVar noExtField (noLocA n)) +nlHsVar n = noLocA (HsVar noExtField (noLocN n)) nl_HsVar :: IsSrcSpanAnn p a => IdP (GhcPass p) -> HsExpr (GhcPass p) -nl_HsVar n = HsVar noExtField (noLocA n) +nl_HsVar n = HsVar noExtField (noLocN n) -- | NB: Only for 'LHsExpr' 'Id'. nlHsDataCon :: DataCon -> LHsExpr GhcTc @@ -491,7 +491,7 @@ nlHsIntLit n = noLocA (HsLit noComments (HsInt noExtField (mkIntegralLit n))) nlVarPat :: IsSrcSpanAnn p a => IdP (GhcPass p) -> LPat (GhcPass p) -nlVarPat n = noLocA (VarPat noExtField (noLocA n)) +nlVarPat n = noLocA (VarPat noExtField (noLocN n)) nlLitPat :: HsLit GhcPs -> LPat GhcPs nlLitPat l = noLocA (LitPat noExtField l) @@ -516,8 +516,8 @@ nlHsApps f xs = foldl' nlHsApp (nlHsVar f) xs nlHsVarApps :: IsSrcSpanAnn p a => IdP (GhcPass p) -> [IdP (GhcPass p)] -> LHsExpr (GhcPass p) -nlHsVarApps f xs = noLocA (foldl' mk (HsVar noExtField (noLocA f)) - (map ((HsVar noExtField) . noLocA) xs)) +nlHsVarApps f xs = noLocA (foldl' mk (HsVar noExtField (noLocN f)) + (map ((HsVar noExtField) . noLocN) xs)) where mk f a = HsApp noComments (noLocA f) (noLocA a) @@ -529,7 +529,7 @@ nlConVarPatName con vars = nlConPatName con (map nlVarPat vars) nlInfixConPat :: RdrName -> LPat GhcPs -> LPat GhcPs -> LPat GhcPs nlInfixConPat con l r = noLocA $ ConPat - { pat_con = noLocA con + { pat_con = noLocN con , pat_args = InfixCon (parenthesizePat opPrec l) (parenthesizePat opPrec r) , pat_con_ext = noAnn @@ -538,28 +538,28 @@ nlInfixConPat con l r = noLocA $ ConPat nlConPat :: RdrName -> [LPat GhcPs] -> LPat GhcPs nlConPat con pats = noLocA $ ConPat { pat_con_ext = noAnn - , pat_con = noLocA con + , pat_con = noLocN con , pat_args = PrefixCon [] (map (parenthesizePat appPrec) pats) } nlConPatName :: Name -> [LPat GhcRn] -> LPat GhcRn nlConPatName con pats = noLocA $ ConPat { pat_con_ext = noExtField - , pat_con = noLocA con + , pat_con = noLocN con , pat_args = PrefixCon [] (map (parenthesizePat appPrec) pats) } nlNullaryConPat :: RdrName -> LPat GhcPs nlNullaryConPat con = noLocA $ ConPat { pat_con_ext = noAnn - , pat_con = noLocA con + , pat_con = noLocN con , pat_args = PrefixCon [] [] } nlWildConPat :: DataCon -> LPat GhcPs nlWildConPat con = noLocA $ ConPat { pat_con_ext = noAnn - , pat_con = noLocA $ getRdrName con + , pat_con = noLocN $ getRdrName con , pat_args = PrefixCon [] $ replicate (dataConSourceArity con) nlWildPat @@ -606,7 +606,7 @@ nlHsFunTy :: LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p) nlHsParTy :: LHsType (GhcPass p) -> LHsType (GhcPass p) nlHsAppTy f t = noLocA (HsAppTy noExtField f (parenthesizeHsType appPrec t)) -nlHsTyVar p x = noLocA (HsTyVar noAnn p (noLocA x)) +nlHsTyVar p x = noLocA (HsTyVar noAnn p (noLocN x)) nlHsFunTy a b = noLocA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) (parenthesizeHsType funPrec a) b) nlHsParTy t = noLocA (HsParTy noAnn t) @@ -617,7 +617,7 @@ nlHsTyConApp :: IsSrcSpanAnn p a nlHsTyConApp prom fixity tycon tys | Infix <- fixity , HsValArg ty1 : HsValArg ty2 : rest <- tys - = foldl' mk_app (noLocA $ HsOpTy noAnn prom ty1 (noLocA tycon) ty2) rest + = foldl' mk_app (noLocA $ HsOpTy noAnn prom ty1 (noLocN tycon) ty2) rest | otherwise = foldl' mk_app (nlHsTyVar prom tycon) tys where @@ -896,8 +896,8 @@ spanHsLocaLBinds (HsIPBinds _ (IPBinds _ bs)) mkSimpleGeneratedFunBind :: SrcSpan -> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs mkSimpleGeneratedFunBind loc fun pats expr - = L (noAnnSrcSpan loc) $ mkFunBind Generated (L (noAnnSrcSpan loc) fun) - [mkMatch (mkPrefixFunRhs (L (noAnnSrcSpan loc) fun)) pats expr + = L (noAnnSrcSpan loc) $ mkFunBind Generated (L (noAnnSrcSpanN loc) fun) + [mkMatch (mkPrefixFunRhs (L (noAnnSrcSpanN loc) fun)) pats expr emptyLocalBinds] -- | Make a prefix, non-strict function 'HsMatchContext' @@ -1391,7 +1391,7 @@ hsForeignDeclsBinders :: forall p a. (UnXRec (GhcPass p), IsSrcSpanAnn p a) => [LForeignDecl (GhcPass p)] -> [LIdP (GhcPass p)] -- ^ See Note [SrcSpan for binders] hsForeignDeclsBinders foreign_decls - = [ L (noAnnSrcSpan (locA decl_loc)) n + = [ L (noAnnSrcSpanN (locA decl_loc)) n | L decl_loc (ForeignImport { fd_name = L _ n }) <- foreign_decls] @@ -1615,6 +1615,6 @@ lPatImplicits = hs_lpat , let pat_explicit = maybe True ((i<) . unRecFieldsDotDot . unLoc) (rec_dotdot fs)] - err_loc = maybe (getLocA n) getLoc (rec_dotdot fs) + err_loc = maybe (getLocN n) getLoc (rec_dotdot fs) details _ (InfixCon p1 p2) = hs_lpat p1 ++ hs_lpat p2 diff --git a/compiler/GHC/HsToCore/Docs.hs b/compiler/GHC/HsToCore/Docs.hs index a65ff1de69..4a5a7b95e9 100644 --- a/compiler/GHC/HsToCore/Docs.hs +++ b/compiler/GHC/HsToCore/Docs.hs @@ -327,12 +327,12 @@ getInstLoc = \case -- type instance Foo Int = Bool -- ^^^ DataFamInstD _ (DataFamInstDecl - { dfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> locA l + { dfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> locN l -- Since CoAxioms' Names refer to the whole line for type family instances -- in particular, we need to dig a bit deeper to pull out the entire -- equation. This does not happen for data family instances, for some reason. TyFamInstD _ (TyFamInstDecl - { tfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> locA l + { tfid_eqn = FamEqn { feqn_tycon = L l _ }}) -> locN l -- | Get all subordinate declarations inside a declaration, and their docs. -- A subordinate declaration is something like the associate type or data @@ -347,10 +347,10 @@ subordinates env instMap decl = case decl of DataFamInstDecl { dfid_eqn = FamEqn { feqn_tycon = L l _ , feqn_rhs = defn }} <- unLoc <$> cid_datafam_insts d - [ (n, [], IM.empty) | Just n <- [lookupSrcSpan (locA l) instMap] ] ++ dataSubs defn + [ (n, [], IM.empty) | Just n <- [lookupSrcSpan (locN l) instMap] ] ++ dataSubs defn ty_fams = do TyFamInstDecl { tfid_eqn = FamEqn { feqn_tycon = L l _ } } <- unLoc <$> cid_tyfam_insts d - [ (n, [], IM.empty) | Just n <- [lookupSrcSpan (locA l) instMap] ] + [ (n, [], IM.empty) | Just n <- [lookupSrcSpan (locN l) instMap] ] in data_fams ++ ty_fams InstD _ (DataFamInstD _ (DataFamInstDecl d)) diff --git a/compiler/GHC/HsToCore/Quote.hs b/compiler/GHC/HsToCore/Quote.hs index c707a29368..e8cd0b1b26 100644 --- a/compiler/GHC/HsToCore/Quote.hs +++ b/compiler/GHC/HsToCore/Quote.hs @@ -1496,7 +1496,7 @@ repE (HsVar _ (L _ x)) = repE (HsIPVar _ n) = rep_implicit_param_name n >>= repImplicitParamVar repE (HsOverLabel _ s) = repOverLabel s -repE (HsRecSel _ (FieldOcc x _)) = repE (HsVar noExtField (noLocA x)) +repE (HsRecSel _ (FieldOcc x _)) = repE (HsVar noExtField (noLocN x)) -- Remember, we're desugaring renamer output here, so -- HsOverlit can definitely occur diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs index e193684776..314885cafa 100644 --- a/compiler/GHC/Iface/Ext/Ast.hs +++ b/compiler/GHC/Iface/Ext/Ast.hs @@ -555,7 +555,7 @@ instance HasLoc (LocatedA a) where loc (L la _) = locA la instance HasLoc (LocatedN a) where - loc (L la _) = locA la + loc (L la _) = locN la instance HasLoc a => HasLoc [a] where loc [] = noSrcSpan @@ -618,7 +618,7 @@ instance ToHie (IEContext (LocatedA ModuleName)) where toHie _ = pure [] instance ToHie (Context (Located a)) => ToHie (Context (LocatedN a)) where - toHie (C c (L l a)) = toHie (C c (L (locA l) a)) + toHie (C c (L l a)) = toHie (C c (L (locN l) a)) instance ToHie (Context (Located a)) => ToHie (Context (LocatedA a)) where toHie (C c (L l a)) = toHie (C c (L (locA l) a)) diff --git a/compiler/GHC/Iface/Ext/Utils.hs b/compiler/GHC/Iface/Ext/Utils.hs index 5008b076c7..1533b5195b 100644 --- a/compiler/GHC/Iface/Ext/Utils.hs +++ b/compiler/GHC/Iface/Ext/Utils.hs @@ -540,7 +540,7 @@ mkLScopeA :: GenLocated (SrcSpanAnn' a) e -> Scope mkLScopeA = mkScope . locA . getLoc mkLScopeN :: LocatedN a -> Scope -mkLScopeN = mkScope . getLocA +mkLScopeN = mkScope . getLocN combineScopes :: Scope -> Scope -> Scope combineScopes ModuleScope _ = ModuleScope diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y index 7bfa16ba05..ba2a854fb7 100644 --- a/compiler/GHC/Parser.y +++ b/compiler/GHC/Parser.y @@ -1908,7 +1908,7 @@ rule_vars :: { [LRuleTyTmVar] } | {- empty -} { [] } rule_var :: { LRuleTyTmVar } - : varid { sL1l $1 (RuleTyTmVar noAnn $1 Nothing) } + : varid { sL1ln $1 (RuleTyTmVar noAnn $1 Nothing) } | '(' varid '::' ctype ')' {% acsA (\cs -> sLL $1 $> (RuleTyTmVar (EpAnn (glR $1) [mop $1,mu AnnDcolon $3,mcp $5] cs) $2 (Just $4))) } {- Note [Parsing explicit foralls in Rules] @@ -2185,7 +2185,7 @@ infixtype :: { forall b. DisambTD b => PV (LocatedA b) } | ftype tyop infixtype { $1 >>= \ $1 -> $3 >>= \ $3 -> do { let (op, prom) = $2 - ; when (looksLikeMult $1 op $3) $ hintLinear (getLocA op) + ; when (looksLikeMult $1 op $3) $ hintLinear (getLocN op) ; mkHsOpTyPV prom $1 op $3 } } | unpackedness infixtype { $2 >>= \ $2 -> mkUnpackednessPV $1 $2 } @@ -2205,10 +2205,10 @@ tyarg :: { LHsType GhcPs } tyop :: { (LocatedN RdrName, PromotionFlag) } : qtyconop { ($1, NotPromoted) } | tyvarop { ($1, NotPromoted) } - | SIMPLEQUOTE qconop {% do { op <- amsrn (sLL $1 (reLoc $>) (unLoc $2)) + | SIMPLEQUOTE qconop {% do { op <- amsrn (sLL $1 (reLocN $>) (unLoc $2)) (NameAnnQuote (glAA $1) (gl $2) []) ; return (op, IsPromoted) } } - | SIMPLEQUOTE varop {% do { op <- amsrn (sLL $1 (reLoc $>) (unLoc $2)) + | SIMPLEQUOTE varop {% do { op <- amsrn (sLL $1 (reLocN $>) (unLoc $2)) (NameAnnQuote (glAA $1) (gl $2) []) ; return (op, IsPromoted) } } @@ -2452,7 +2452,7 @@ fielddecl :: { LConDeclField GhcPs } : sig_vars '::' ctype {% acsA (\cs -> L (comb2 $1 (reLoc $3)) (ConDeclField (EpAnn (glR $1) [mu AnnDcolon $2] cs) - (reverse (map (\ln@(L l n) -> L (l2l l) $ FieldOcc noExtField ln) (unLoc $1))) $3 Nothing))} + (reverse (map (\ln@(L l n) -> L (nn2la l) $ FieldOcc noExtField ln) (unLoc $1))) $3 Nothing))} -- Reversed! maybe_derivings :: { Located (HsDeriving GhcPs) } @@ -2889,8 +2889,8 @@ aexp1 :: { ECP } | aexp1 TIGHT_INFIX_PROJ field {% runPV (unECP $1) >>= \ $1 -> fmap ecpFromExp $ acsa (\cs -> - let fl = sLLa $2 (reLoc $>) (DotFieldOcc ((EpAnn (glR $2) (AnnFieldLabel (Just $ glAA $2)) emptyComments)) $3) in - mkRdrGetField (noAnnSrcSpan $ comb2 (reLoc $1) (reLoc $>)) $1 fl (EpAnn (glAR $1) NoEpAnns cs)) } + let fl = sLLa $2 (reLocN $>) (DotFieldOcc ((EpAnn (glR $2) (AnnFieldLabel (Just $ glAA $2)) emptyComments)) $3) in + mkRdrGetField (noAnnSrcSpan $ comb2 (reLoc $1) (reLocN $>)) $1 fl (EpAnn (glAR $1) NoEpAnns cs)) } | aexp2 { $1 } @@ -2975,8 +2975,8 @@ projection :: { Located (NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs))) } projection -- See Note [Whitespace-sensitive operator parsing] in GHC.Parsing.Lexer : projection TIGHT_INFIX_PROJ field - {% acs (\cs -> sLL $1 (reLoc $>) ((sLLa $2 (reLoc $>) $ DotFieldOcc (EpAnn (glR $1) (AnnFieldLabel (Just $ glAA $2)) cs) $3) `NE.cons` unLoc $1)) } - | PREFIX_PROJ field {% acs (\cs -> sLL $1 (reLoc $>) ((sLLa $1 (reLoc $>) $ DotFieldOcc (EpAnn (glR $1) (AnnFieldLabel (Just $ glAA $1)) cs) $2) :| [])) } + {% acs (\cs -> sLL $1 (reLocN $>) ((sLLa $2 (reLocN $>) $ DotFieldOcc (EpAnn (glR $1) (AnnFieldLabel (Just $ glAA $2)) cs) $3) `NE.cons` unLoc $1)) } + | PREFIX_PROJ field {% acs (\cs -> sLL $1 (reLocN $>) ((sLLa $1 (reLocN $>) $ DotFieldOcc (EpAnn (glR $1) (AnnFieldLabel (Just $ glAA $1)) cs) $2) :| [])) } splice_exp :: { LHsExpr GhcPs } : splice_untyped { fmap (HsUntypedSplice noAnn) (reLocA $1) } @@ -3410,13 +3410,13 @@ fbinds1 :: { forall b. DisambECP b => PV ([Fbind b], Maybe SrcSpan) } fbind :: { forall b. DisambECP b => PV (Fbind b) } : qvar '=' texp { unECP $3 >>= \ $3 -> - fmap Left $ acsA (\cs -> sLL (reLocN $1) (reLoc $>) $ HsFieldBind (EpAnn (glNR $1) [mj AnnEqual $2] cs) (sL1l $1 $ mkFieldOcc $1) $3 False) } + fmap Left $ acsA (\cs -> sLL (reLocN $1) (reLoc $>) $ HsFieldBind (EpAnn (glNR $1) [mj AnnEqual $2] cs) (sL1ln $1 $ mkFieldOcc $1) $3 False) } -- RHS is a 'texp', allowing view patterns (#6038) -- and, incidentally, sections. Eg -- f (R { x = show -> s }) = ... | qvar { placeHolderPunRhs >>= \rhs -> - fmap Left $ acsa (\cs -> sL1a (reLocN $1) $ HsFieldBind (EpAnn (glNR $1) [] cs) (sL1l $1 $ mkFieldOcc $1) rhs True) } + fmap Left $ acsa (\cs -> sL1a (reLocN $1) $ HsFieldBind (EpAnn (glNR $1) [] cs) (sL1ln $1 $ mkFieldOcc $1) rhs True) } -- In the punning case, use a place-holder -- The renamer fills in the final value @@ -3424,15 +3424,15 @@ fbind :: { forall b. DisambECP b => PV (Fbind b) } -- AZ: need to pull out the let block into a helper | field TIGHT_INFIX_PROJ fieldToUpdate '=' texp { do - let top = sL1 (la2la $1) $ DotFieldOcc noAnn $1 + let top = sL1 (n2l $1) $ DotFieldOcc noAnn $1 ((L lf (DotFieldOcc _ f)):t) = reverse (unLoc $3) lf' = comb2 $2 (reLoc $ L lf ()) fields = top : L (noAnnSrcSpan lf') (DotFieldOcc (EpAnn (spanAsAnchor lf') (AnnFieldLabel (Just $ glAA $2)) emptyComments) f) : t final = last fields - l = comb2 (reLoc $1) $3 + l = comb2 (reLocN $1) $3 isPun = False $5 <- unECP $5 - fmap Right $ mkHsProjUpdatePV (comb2 (reLoc $1) (reLoc $5)) (L l fields) $5 isPun + fmap Right $ mkHsProjUpdatePV (comb2 (reLocN $1) (reLoc $5)) (L l fields) $5 isPun [mj AnnEqual $4] } @@ -3440,24 +3440,24 @@ fbind :: { forall b. DisambECP b => PV (Fbind b) } -- AZ: need to pull out the let block into a helper | field TIGHT_INFIX_PROJ fieldToUpdate { do - let top = sL1 (la2la $1) $ DotFieldOcc noAnn $1 + let top = sL1 (n2l $1) $ DotFieldOcc noAnn $1 ((L lf (DotFieldOcc _ f)):t) = reverse (unLoc $3) lf' = comb2 $2 (reLoc $ L lf ()) fields = top : L (noAnnSrcSpan lf') (DotFieldOcc (EpAnn (spanAsAnchor lf') (AnnFieldLabel (Just $ glAA $2)) emptyComments) f) : t final = last fields - l = comb2 (reLoc $1) $3 + l = comb2 (reLocN $1) $3 isPun = True - var <- mkHsVarPV (L (noAnnSrcSpan $ getLocA final) (mkRdrUnqual . mkVarOcc . unpackFS . field_label . unLoc . dfoLabel . unLoc $ final)) + var <- mkHsVarPV (L (noAnnSrcSpanN $ getLocA final) (mkRdrUnqual . mkVarOcc . unpackFS . field_label . unLoc . dfoLabel . unLoc $ final)) fmap Right $ mkHsProjUpdatePV l (L l fields) var isPun [] } fieldToUpdate :: { Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)] } fieldToUpdate -- See Note [Whitespace-sensitive operator parsing] in Lexer.x - : fieldToUpdate TIGHT_INFIX_PROJ field {% getCommentsFor (getLocA $3) >>= \cs -> - return (sLL $1 (reLoc $>) ((sLLa $2 (reLoc $>) (DotFieldOcc (EpAnn (glR $2) (AnnFieldLabel $ Just $ glAA $2) cs) $3)) : unLoc $1)) } - | field {% getCommentsFor (getLocA $1) >>= \cs -> - return (sL1 (reLoc $1) [sL1a (reLoc $1) (DotFieldOcc (EpAnn (glNR $1) (AnnFieldLabel Nothing) cs) $1)]) } + : fieldToUpdate TIGHT_INFIX_PROJ field {% getCommentsFor (getLocN $3) >>= \cs -> + return (sLL $1 (reLocN $>) ((sLLa $2 (reLocN $>) (DotFieldOcc (EpAnn (glR $2) (AnnFieldLabel $ Just $ glAA $2) cs) $3)) : unLoc $1)) } + | field {% getCommentsFor (getLocN $1) >>= \cs -> + return (sL1 (reLocN $1) [sL1a (reLocN $1) (DotFieldOcc (EpAnn (glNR $1) (AnnFieldLabel Nothing) cs) $1)]) } ----------------------------------------------------------------------------- -- Implicit Parameter Bindings @@ -4020,7 +4020,7 @@ comb3A a b c = a `seq` b `seq` c `seq` comb3N :: Located a -> Located b -> LocatedN c -> SrcSpan comb3N a b c = a `seq` b `seq` c `seq` - combineSrcSpans (getLoc a) (combineSrcSpans (getLoc b) (getLocA c)) + combineSrcSpans (getLoc a) (combineSrcSpans (getLoc b) (getLocN c)) comb4 :: Located a -> Located b -> Located c -> Located d -> SrcSpan comb4 a b c d = a `seq` b `seq` c `seq` d `seq` @@ -4054,7 +4054,7 @@ sL1A x = sL (getLocA x) -- #define sL1 sL (getLoc $1) {-# INLINE sL1N #-} sL1N :: LocatedN a -> b -> Located b -sL1N x = sL (getLocA x) -- #define sL1 sL (getLoc $1) +sL1N x = sL (getLocN x) -- #define sL1 sL (getLoc $1) {-# INLINE sL1a #-} sL1a :: Located a -> b -> LocatedAn t b @@ -4064,9 +4064,13 @@ sL1a x = sL (noAnnSrcSpan $ getLoc x) -- #define sL1 sL (getLoc $1) sL1l :: LocatedAn t a -> b -> LocatedAn u b sL1l x = sL (l2l $ getLoc x) -- #define sL1 sL (getLoc $1) +{-# INLINE sL1ln #-} +sL1ln :: LocatedN a -> b -> LocatedAn u b +sL1ln x = sL (noAnnSrcSpan $ getLocN x) -- #define sL1 sL (getLoc $1) + {-# INLINE sL1n #-} sL1n :: Located a -> b -> LocatedN b -sL1n x = L (noAnnSrcSpan $ getLoc x) -- #define sL1 sL (getLoc $1) +sL1n x = L (noAnnSrcSpanN $ getLoc x) -- #define sL1 sL (getLoc $1) {-# INLINE sLL #-} sLL :: Located a -> Located b -> c -> Located c @@ -4151,7 +4155,7 @@ looksLikeMult ty1 l_op ty2 | Unqual op_name <- unLoc l_op , occNameFS op_name == fsLit "%" , Strict.Just ty1_pos <- getBufSpan (getLocA ty1) - , Strict.Just pct_pos <- getBufSpan (getLocA l_op) + , Strict.Just pct_pos <- getBufSpan (getLocN l_op) , Strict.Just ty2_pos <- getBufSpan (getLocA ty2) , bufSpanEnd ty1_pos /= bufSpanStart pct_pos , bufSpanEnd pct_pos == bufSpanStart ty2_pos @@ -4247,7 +4251,7 @@ glA :: LocatedAn t a -> SrcSpan glA = getLocA glN :: LocatedN a -> SrcSpan -glN = getLocA +glN = getLocN glR :: Located a -> Anchor glR la = Anchor (realSrcSpan $ getLoc la) UnchangedAnchor @@ -4262,10 +4266,10 @@ glAR :: LocatedAn t a -> Anchor glAR la = Anchor (realSrcSpan $ getLocA la) UnchangedAnchor glNR :: LocatedN a -> Anchor -glNR ln = Anchor (realSrcSpan $ getLocA ln) UnchangedAnchor +glNR ln = Anchor (realSrcSpan $ getLocN ln) UnchangedAnchor glNRR :: LocatedN a -> EpaLocation -glNRR = EpaSpan <$> realSrcSpan . getLocA +glNRR = EpaSpan <$> realSrcSpan . getLocN anc :: RealSrcSpan -> Anchor anc r = Anchor r UnchangedAnchor @@ -4330,8 +4334,7 @@ amsrp a@(L l _) bs = do amsrn :: MonadP m => Located a -> NameAnn -> m (LocatedN a) amsrn (L l a) an = do cs <- getCommentsFor l - let ann = (EpAnn (spanAsAnchor l) an cs) - return (L (SrcSpanAnn ann l) a) + return (L (EpAnnS (spanAsAnchor l) an cs) a) -- |Synonyms for AddEpAnn versions of AnnOpen and AnnClose mo,mc :: Located Token -> AddEpAnn @@ -4360,7 +4363,7 @@ pvA a = do { av <- a pvN :: MonadP m => m (Located a) -> m (LocatedN a) pvN a = do { (L l av) <- a - ; return (L (noAnnSrcSpan l) av) } + ; return (L (noAnnSrcSpanN l) av) } pvL :: MonadP m => m (LocatedAn t a) -> m (Located a) pvL a = do { av <- a @@ -4453,14 +4456,15 @@ addTrailingAnnL (L (SrcSpanAnn anns l) a) ta = do -- Mostly use to add AnnComma, special case it to NOP if adding a zero-width annotation addTrailingCommaN :: MonadP m => LocatedN a -> SrcSpan -> m (LocatedN a) -addTrailingCommaN (L (SrcSpanAnn anns l) a) span = do +addTrailingCommaN (L anns a) span = do + let l = locN anns -- cs <- getCommentsFor l let cs = emptyComments -- AZ:TODO: generalise updating comments into an annotation let anns' = if isZeroWidthSpan span then anns else addTrailingCommaToN l anns (EpaSpan $ rs span) - return (L (SrcSpanAnn anns' l) a) + return (L anns' a) addTrailingCommaS :: Located StringLiteral -> EpaLocation -> Located StringLiteral addTrailingCommaS (L l sl) span = L l (sl { sl_tc = Just (epaLocationRealSrcSpan span) }) diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs index 56e9f87a2a..7440a7fab4 100644 --- a/compiler/GHC/Parser/Annotation.hs +++ b/compiler/GHC/Parser/Annotation.hs @@ -14,11 +14,14 @@ module GHC.Parser.Annotation ( -- * In-tree Exact Print Annotations AddEpAnn(..), EpaLocation(..), epaLocationRealSrcSpan, epaLocationFromSrcAnn, + epaLocationFromEpAnnS, TokenLocation(..), DeltaPos(..), deltaPos, getDeltaLine, EpAnn(..), Anchor(..), AnchorOperation(..), + EpAnnS(..), spanAsAnchor, realSpanAsAnchor, + spanFromAnchor, noAnn, -- ** Comments in Annotations @@ -49,6 +52,7 @@ module GHC.Parser.Annotation ( -- ** Utilities for converting between different 'GenLocated' when -- ** we do not care about the annotations. la2na, na2la, n2l, l2n, l2l, la2la, + na2ln, nn2la, locN, l2ln, reLoc, reLocA, reLocL, reLocC, reLocN, la2r, realSrcSpan, @@ -74,8 +78,9 @@ module GHC.Parser.Annotation ( -- ** Constructing 'GenLocated' annotation types when we do not care -- about annotations. noLocA, getLocA, - noSrcSpanA, - noAnnSrcSpan, + noLocN, getLocN, + noSrcSpanA, noSrcSpanN, + noAnnSrcSpan, noAnnSrcSpanN, -- ** Working with comments in annotations noComments, comment, addCommentsToSrcAnn, setCommentsSrcAnn, @@ -455,6 +460,10 @@ epaLocationFromSrcAnn :: SrcAnn ann -> EpaLocation epaLocationFromSrcAnn (SrcSpanAnn EpAnnNotUsed l) = EpaSpan (realSrcSpan l) epaLocationFromSrcAnn (SrcSpanAnn (EpAnn anc _ _) _) = EpaSpan (anchor anc) +epaLocationFromEpAnnS :: EpAnnS ann -> EpaLocation +epaLocationFromEpAnnS (EpAnnS anc _ _) = EpaSpan (anchor anc) + + instance Outputable EpaLocation where ppr (EpaSpan r) = text "EpaSpan" <+> ppr r ppr (EpaDelta d cs) = text "EpaDelta" <+> ppr d <+> ppr cs @@ -518,6 +527,18 @@ data EpAnn ann -- the element relative to its container. If it is moved, that -- relationship is tracked in the 'anchor_op' instead. +-- AZ: This is a temporary type until we get rid of EpAnnNotUsed, at +-- which time it replaces EpAnn +data EpAnnS ann + = EpAnnS { s_entry :: !Anchor + -- ^ Base location for the start of the syntactic element + -- holding the annotations. + , s_anns :: !ann -- ^ Annotations added by the Parser + , s_comments :: !EpAnnComments + -- ^ Comments enclosed in the SrcSpan of the element + -- this `EpAnn` is attached to + } deriving (Data, Eq, Functor) + data Anchor = Anchor { anchor :: !RealSrcSpan -- ^ Base location for the start of -- the syntactic element holding @@ -541,6 +562,9 @@ spanAsAnchor s = Anchor (realSrcSpan s) UnchangedAnchor realSpanAsAnchor :: RealSrcSpan -> Anchor realSpanAsAnchor s = Anchor s UnchangedAnchor +spanFromAnchor :: Anchor -> SrcSpan +spanFromAnchor (Anchor r _) = RealSrcSpan r + -- --------------------------------------------------------------------- -- | When we are parsing we add comments that belong a particular AST @@ -587,7 +611,7 @@ type LocatedP = GenLocated SrcSpanAnnP type LocatedC = GenLocated SrcSpanAnnC type SrcSpanAnnA = SrcAnn AnnListItem -type SrcSpanAnnN = SrcAnn NameAnn +type SrcSpanAnnN = EpAnnS NameAnn type SrcSpanAnnL = SrcAnn AnnList type SrcSpanAnnP = SrcAnn AnnPragma @@ -837,10 +861,8 @@ addTrailingAnnToA _ t cs n = n { anns = addTrailing (anns n) -- | Helper function used in the parser to add a comma location to an -- existing annotation. -addTrailingCommaToN :: SrcSpan -> EpAnn NameAnn -> EpaLocation -> EpAnn NameAnn -addTrailingCommaToN s EpAnnNotUsed l - = EpAnn (spanAsAnchor s) (NameAnnTrailing [AddCommaAnn l]) emptyComments -addTrailingCommaToN _ n l = n { anns = addTrailing (anns n) l } +addTrailingCommaToN :: SrcSpan -> EpAnnS NameAnn -> EpaLocation -> EpAnnS NameAnn +addTrailingCommaToN _ n l = n { s_anns = addTrailing (s_anns n) l } where -- See Note [list append in addTrailing*] addTrailing :: NameAnn -> EpaLocation -> NameAnn @@ -871,15 +893,15 @@ knowing that in most cases the original list is empty. -- |Helper function (temporary) during transition of names -- Discards any annotations l2n :: LocatedAn a1 a2 -> LocatedN a2 -l2n (L la a) = L (noAnnSrcSpan (locA la)) a +l2n (L la a) = L (noAnnSrcSpanN (locA la)) a -n2l :: LocatedN a -> LocatedA a -n2l (L la a) = L (na2la la) a +n2l :: LocatedN a -> LocatedAn ann a +n2l (L la a) = L (nn2la la) a -- |Helper function (temporary) during transition of names -- Discards any annotations la2na :: SrcSpanAnn' a -> SrcSpanAnnN -la2na l = noAnnSrcSpan (locA l) +la2na l = noAnnSrcSpanN (locA l) -- |Helper function (temporary) during transition of names -- Discards any annotations @@ -889,11 +911,27 @@ la2la (L la a) = L (noAnnSrcSpan (locA la)) a l2l :: SrcSpanAnn' a -> SrcAnn ann l2l l = noAnnSrcSpan (locA l) +l2ln :: SrcSpanAnn' a -> EpAnnS NameAnn +l2ln l = noAnnSrcSpanN (locA l) + -- |Helper function (temporary) during transition of names -- Discards any annotations na2la :: SrcSpanAnn' a -> SrcAnn ann na2la l = noAnnSrcSpan (locA l) +-- |Helper function (temporary) during transition of names +-- Discards any annotations +na2ln :: SrcSpanAnn' a -> EpAnnS NameAnn +na2ln l = noAnnSrcSpanN (locA l) + +-- |Helper function (temporary) during transition of names +-- Discards any annotations +nn2la :: EpAnnS NameAnn -> SrcAnn ann +nn2la l = noAnnSrcSpan (locN l) + +locN :: EpAnnS ann -> SrcSpan +locN a = RealSrcSpan $ anchor $ s_entry a + reLoc :: LocatedAn a e -> Located e reLoc (L (SrcSpanAnn _ l) a) = L l a @@ -901,13 +939,13 @@ reLocA :: Located e -> LocatedAn ann e reLocA (L l a) = (L (SrcSpanAnn EpAnnNotUsed l) a) reLocL :: LocatedN e -> LocatedA e -reLocL (L l a) = (L (na2la l) a) +reLocL (L l a) = (L (nn2la l) a) reLocC :: LocatedN e -> LocatedC e -reLocC (L l a) = (L (na2la l) a) +reLocC (L l a) = (L (nn2la l) a) reLocN :: LocatedN a -> Located a -reLocN (L (SrcSpanAnn _ l) a) = L l a +reLocN (L ln a) = L (locN ln) a -- --------------------------------------------------------------------- @@ -935,19 +973,30 @@ reAnnL anns cs (L l a) = L (SrcSpanAnn (EpAnn (spanAsAnchor l) anns cs) l) a getLocAnn :: Located a -> SrcSpanAnnA getLocAnn (L l _) = SrcSpanAnn EpAnnNotUsed l - getLocA :: GenLocated (SrcSpanAnn' a) e -> SrcSpan getLocA (L (SrcSpanAnn _ l) _) = l noLocA :: a -> LocatedAn an a noLocA = L (SrcSpanAnn EpAnnNotUsed noSrcSpan) +getLocN :: GenLocated (EpAnnS an) a -> SrcSpan +getLocN (L l _) = locN l + +noLocN :: a -> LocatedN a +noLocN = L (noAnnSrcSpanN noSrcSpan) + noAnnSrcSpan :: SrcSpan -> SrcAnn ann noAnnSrcSpan l = SrcSpanAnn EpAnnNotUsed l +noAnnSrcSpanN :: SrcSpan -> EpAnnS NameAnn +noAnnSrcSpanN l = EpAnnS (spanAsAnchor l) mempty emptyComments + noSrcSpanA :: SrcAnn ann noSrcSpanA = noAnnSrcSpan noSrcSpan +noSrcSpanN :: EpAnnS NameAnn +noSrcSpanN = noAnnSrcSpanN noSrcSpan + -- | Short form for 'EpAnnNotUsed' noAnn :: EpAnn a noAnn = EpAnnNotUsed @@ -1239,6 +1288,9 @@ instance Outputable EpAnnComments where instance (NamedThing (Located a)) => NamedThing (LocatedAn an a) where getName (L l a) = getName (L (locA l) a) +instance (NamedThing (Located a)) => NamedThing (LocatedN a) where + getName (L l a) = getName (L (locN l) a) + instance Outputable AnnContext where ppr (AnnContext a o c) = text "AnnContext" <+> ppr a <+> ppr o <+> ppr c @@ -1267,11 +1319,23 @@ instance (Outputable a, Outputable e) => Outputable (GenLocated (SrcSpanAnn' a) e) where ppr = pprLocated +instance (Outputable a) => Outputable (EpAnnS a) where + ppr (EpAnnS anc an cs) = text "EpAnnS" <+> ppr anc <+> ppr an <+> ppr cs + +instance (Outputable a, Outputable e) + => Outputable (GenLocated (EpAnnS a) e) where + ppr = pprLocated + instance (Outputable a, OutputableBndr e) => OutputableBndr (GenLocated (SrcSpanAnn' a) e) where pprInfixOcc = pprInfixOcc . unLoc pprPrefixOcc = pprPrefixOcc . unLoc +instance (Outputable a, OutputableBndr e) + => OutputableBndr (GenLocated (EpAnnS a) e) where + pprInfixOcc = pprInfixOcc . unLoc + pprPrefixOcc = pprPrefixOcc . unLoc + instance Outputable AnnListItem where ppr (AnnListItem ts) = text "AnnListItem" <+> ppr ts diff --git a/compiler/GHC/Parser/HaddockLex.x b/compiler/GHC/Parser/HaddockLex.x index 932ca8145b..d3aee9151c 100644 --- a/compiler/GHC/Parser/HaddockLex.x +++ b/compiler/GHC/Parser/HaddockLex.x @@ -195,7 +195,7 @@ validateIdentWith identParser mloc str0 = pstate = initParserState pflags buffer realSrcLc in case unP identParser pstate of POk _ name -> Just $ case mloc of - RealSrcSpan _ -> reLoc name + RealSrcSpan _ -> reLocN name UnhelpfulSpan _ -> L mloc (unLoc name) -- Preserve the original reason _ -> Nothing } diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 9fd20a4a67..6e71c6ad40 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -286,7 +286,7 @@ mkStandaloneKindSig loc lhs rhs anns = check_lhs_name v@(unLoc->name) = if isUnqual name && isTcOcc (rdrNameOcc name) then return v - else addFatalError $ mkPlainErrorMsgEnvelope (getLocA v) $ + else addFatalError $ mkPlainErrorMsgEnvelope (getLocN v) $ (PsErrUnexpectedQualifiedConstructor (unLoc v)) check_singular_lhs vs = case vs of @@ -675,7 +675,7 @@ tyConToDataCon (L loc tc) = return (L loc (setRdrNameSpace tc srcDataName)) | otherwise - = Left $ mkPlainErrorMsgEnvelope (locA loc) $ (PsErrNotADataCon tc) + = Left $ mkPlainErrorMsgEnvelope (locN loc) $ (PsErrNotADataCon tc) where occ = rdrNameOcc tc @@ -684,7 +684,7 @@ mkPatSynMatchGroup :: LocatedN RdrName -> P (MatchGroup GhcPs (LHsExpr GhcPs)) mkPatSynMatchGroup (L loc patsyn_name) (L ld decls) = do { matches <- mapM fromDecl (fromOL decls) - ; when (null matches) (wrongNumberErr (locA loc)) + ; when (null matches) (wrongNumberErr (locN loc)) ; return $ mkMatchGroup FromSource (L ld matches) } where fromDecl (L loc decl@(ValD _ (PatBind _ @@ -1023,7 +1023,7 @@ checkTyClHdr is_cls ty go _ (HsAppTy _ t1 t2) acc ops cps fix = goL t1 (HsValArg t2:acc) ops cps fix go _ (HsAppKindTy l ty ki) acc ops cps fix = goL ty (HsTypeArg l ki:acc) ops cps fix go l (HsTupleTy _ HsBoxedOrConstraintTuple ts) [] ops cps fix - = return (L (noAnnSrcSpan l) (nameRdrName tup_name) + = return (L (noAnnSrcSpanN l) (nameRdrName tup_name) , map HsValArg ts, fix, (reverse ops)++cps) where arity = length ts @@ -1040,14 +1040,12 @@ checkTyClHdr is_cls ty newAnns (SrcSpanAnn EpAnnNotUsed l) (EpAnn as (AnnParen _ o c) cs) = let lr = combineRealSrcSpans (realSrcSpan l) (anchor as) - an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c []) cs) - in SrcSpanAnn an (RealSrcSpan lr) + in (EpAnnS (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c []) cs) newAnns _ EpAnnNotUsed = panic "missing AnnParen" newAnns (SrcSpanAnn (EpAnn ap (AnnListItem ta) csp) l) (EpAnn as (AnnParen _ o c) cs) = let lr = combineRealSrcSpans (anchor ap) (anchor as) - an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c ta) (csp Semi.<> cs)) - in SrcSpanAnn an (RealSrcSpan lr) + in (EpAnnS (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c ta) (csp Semi.<> cs)) -- | Yield a parse error if we have a function applied directly to a do block -- etc. and BlockArguments is not enabled. @@ -1206,11 +1204,11 @@ checkAPat loc e0 = do (EpAnn anc _ cs) | nPlusKPatterns && (plus == plus_RDR) -> return (mkNPlusKPat (L nloc n) (L (l2l lloc) lit) - (EpAnn anc (epaLocationFromSrcAnn l) cs)) + (EpAnn anc (epaLocationFromEpAnnS l) cs)) -- Improve error messages for the @-operator when the user meant an @-pattern PatBuilderOpApp _ op _ _ | opIsAt (unLoc op) -> do - addError $ mkPlainErrorMsgEnvelope (getLocA op) PsErrAtInPatPos + addError $ mkPlainErrorMsgEnvelope (getLocN op) PsErrAtInPatPos return (WildPat noExtField) PatBuilderOpApp l (L cl c) r anns @@ -1235,7 +1233,7 @@ placeHolderPunRhs :: DisambECP b => PV (LocatedA b) -- The RHS of a punned record field will be filled in by the renamer -- It's better not to make it an error, in case we want to print it when -- debugging -placeHolderPunRhs = mkHsVarPV (noLocA pun_RDR) +placeHolderPunRhs = mkHsVarPV (noLocN pun_RDR) plus_RDR, pun_RDR :: RdrName plus_RDR = mkUnqual varName (fsLit "+") -- Hack @@ -1685,7 +1683,7 @@ instance DisambECP (HsCmd GhcPs) where mkHsParPV l lpar c rpar = do cs <- getCommentsFor l return $ L (noAnnSrcSpan l) (HsCmdPar (EpAnn (spanAsAnchor l) NoEpAnns cs) lpar c rpar) - mkHsVarPV (L l v) = cmdFail (locA l) (ppr v) + mkHsVarPV (L l v) = cmdFail (locN l) (ppr v) mkHsLitPV (L l a) = cmdFail l (ppr a) mkHsOverLitPV (L l a) = cmdFail (locA l) (ppr a) mkHsWildCardPV l = cmdFail l (text "_") @@ -1772,7 +1770,7 @@ instance DisambECP (HsExpr GhcPs) where mkHsParPV l lpar e rpar = do cs <- getCommentsFor l return $ L (noAnnSrcSpan l) (HsPar (EpAnn (spanAsAnchor l) NoEpAnns cs) lpar e rpar) - mkHsVarPV v@(L l _) = return $ L (na2la l) (HsVar noExtField v) + mkHsVarPV v@(L l _) = return $ L (nn2la l) (HsVar noExtField v) mkHsLitPV (L l a) = do cs <- getCommentsFor l return $ L l (HsLit (comment (realSrcSpan l) cs) a) @@ -1848,7 +1846,7 @@ instance DisambECP (PatBuilder GhcPs) where mkHsIfPV l _ _ _ _ _ _ = addFatalError $ mkPlainErrorMsgEnvelope l PsErrIfThenElseInPat mkHsDoPV l _ _ _ = addFatalError $ mkPlainErrorMsgEnvelope l PsErrDoNotationInPat mkHsParPV l lpar p rpar = return $ L (noAnnSrcSpan l) (PatBuilderPar lpar p rpar) - mkHsVarPV v@(getLoc -> l) = return $ L (na2la l) (PatBuilderVar v) + mkHsVarPV v@(getLoc -> l) = return $ L (nn2la l) (PatBuilderVar v) mkHsLitPV lit@(L l a) = do checkUnboxedLitPat lit return $ L l (PatBuilderPat (LitPat noExtField a)) @@ -2037,7 +2035,7 @@ tyToDataConBuilder (L l (HsTyVar _ prom v)) = do checkNotPromotedDataCon prom data_con return $ L l (PrefixDataConBuilder nilOL data_con) tyToDataConBuilder (L l (HsTupleTy _ HsBoxedOrConstraintTuple ts)) = do - let data_con = L (l2l l) (getRdrName (tupleDataCon Boxed (length ts))) + let data_con = L (l2ln l) (getRdrName (tupleDataCon Boxed (length ts))) return $ L l (PrefixDataConBuilder (toOL ts) data_con) tyToDataConBuilder t = addFatalError $ mkPlainErrorMsgEnvelope (getLocA t) $ @@ -2047,7 +2045,7 @@ tyToDataConBuilder t = checkNotPromotedDataCon :: PromotionFlag -> LocatedN RdrName -> PV () checkNotPromotedDataCon NotPromoted _ = return () checkNotPromotedDataCon IsPromoted (L l name) = - addError $ mkPlainErrorMsgEnvelope (locA l) $ + addError $ mkPlainErrorMsgEnvelope (locN l) $ PsErrIllegalPromotionQuoteDataCon name {- Note [Ambiguous syntactic categories] @@ -2564,15 +2562,15 @@ mkRdrRecordUpd overloaded_on exp@(L loc _) fbinds anns = do -- The idea here is to convert the label to a singleton [FastString]. let f = occNameFS . rdrNameOcc $ rdr fl = DotFieldOcc noAnn (L loc (FieldLabelString f)) - lf = locA loc - in mkRdrProjUpdate l (L lf [L (l2l loc) fl]) (punnedVar f) pun anns + lf = locN loc + in mkRdrProjUpdate l (L lf [L (nn2la loc) fl]) (punnedVar f) pun anns where -- If punning, compute HsVar "f" otherwise just arg. This -- has the effect that sentinel HsVar "pun-rhs" is replaced -- by HsVar "f" here, before the update is written to a -- setField expressions. punnedVar :: FastString -> LHsExpr GhcPs - punnedVar f = if not pun then arg else noLocA . HsVar noExtField . noLocA . mkRdrUnqual . mkVarOccFS $ f + punnedVar f = if not pun then arg else noLocA . HsVar noExtField . noLocN . mkRdrUnqual . mkVarOccFS $ f mkRdrRecordCon :: LocatedN RdrName -> HsRecordBinds GhcPs -> EpAnn [AddEpAnn] -> HsExpr GhcPs @@ -2839,7 +2837,7 @@ mkTypeImpExp :: LocatedN RdrName -- TcCls or Var name space -> P (LocatedN RdrName) mkTypeImpExp name = do allowed <- getBit ExplicitNamespacesBit - unless allowed $ addError $ mkPlainErrorMsgEnvelope (getLocA name) $ + unless allowed $ addError $ mkPlainErrorMsgEnvelope (getLocN name) $ PsErrIllegalExplicitNamespace return (fmap (`setRdrNameSpace` tcClsName) name) @@ -2888,7 +2886,7 @@ failOpFewArgs :: MonadP m => LocatedN RdrName -> m a failOpFewArgs (L loc op) = do { star_is_type <- getBit StarIsTypeBit ; let is_star_type = if star_is_type then StarIsType else StarIsNotType - ; addFatalError $ mkPlainErrorMsgEnvelope (locA loc) $ + ; addFatalError $ mkPlainErrorMsgEnvelope (locN loc) $ (PsErrOpFewArgs is_star_type op) } ----------------------------------------------------------------------------- @@ -3110,7 +3108,7 @@ mkSumOrTuplePat l Boxed a@Sum{} _ = mkLHsOpTy :: PromotionFlag -> LHsType GhcPs -> LocatedN RdrName -> LHsType GhcPs -> LHsType GhcPs mkLHsOpTy prom x op y = - let loc = getLoc x `combineSrcSpansA` (noAnnSrcSpan $ getLocA op) `combineSrcSpansA` getLoc y + let loc = getLoc x `combineSrcSpansA` (noAnnSrcSpan $ getLocN op) `combineSrcSpansA` getLoc y in L loc (mkHsOpTy prom x op y) mkMultTy :: LHsToken "%" GhcPs -> LHsType GhcPs -> LHsUniToken "->" "→" GhcPs -> HsArrow GhcPs diff --git a/compiler/GHC/Parser/PostProcess/Haddock.hs b/compiler/GHC/Parser/PostProcess/Haddock.hs index 2675921b04..90c2e837e1 100644 --- a/compiler/GHC/Parser/PostProcess/Haddock.hs +++ b/compiler/GHC/Parser/PostProcess/Haddock.hs @@ -431,7 +431,7 @@ instance HasHaddock (HsDecl GhcPs) where -- -> Bool -- ^ Comment on Bool -- addHaddock (SigD _ (TypeSig x names t)) = do - traverse_ registerHdkA names + traverse_ registerHdkN names t' <- addHaddock t pure (SigD noExtField (TypeSig x names t')) @@ -442,7 +442,7 @@ instance HasHaddock (HsDecl GhcPs) where -- -> Maybe Bool -- ^ Comment on Maybe Bool -- addHaddock (SigD _ (PatSynSig x names t)) = do - traverse_ registerHdkA names + traverse_ registerHdkN names t' <- addHaddock t pure (SigD noExtField (PatSynSig x names t')) @@ -458,7 +458,7 @@ instance HasHaddock (HsDecl GhcPs) where -- -> IO () -- ^ Comment on IO () -- addHaddock (SigD _ (ClassOpSig x is_dflt names t)) = do - traverse_ registerHdkA names + traverse_ registerHdkN names t' <- addHaddock t pure (SigD noExtField (ClassOpSig x is_dflt names t')) @@ -481,7 +481,7 @@ instance HasHaddock (HsDecl GhcPs) where addHaddock (TyClD x decl) | DataDecl { tcdDExt, tcdLName, tcdTyVars, tcdFixity, tcdDataDefn = defn } <- decl = do - registerHdkA tcdLName + registerHdkN tcdLName defn' <- addHaddock defn pure $ TyClD x (DataDecl { @@ -502,7 +502,7 @@ instance HasHaddock (HsDecl GhcPs) where tcdCtxt, tcdLName, tcdTyVars, tcdFixity, tcdFDs, tcdSigs, tcdMeths, tcdATs, tcdATDefs } <- decl = do - registerHdkA tcdLName + registerHdkN tcdLName -- todo: register keyword location of 'where', see Note [Register keyword location] where_cls' <- addHaddockInterleaveItems tcdLayout (mkDocHsDecl tcdLayout) $ @@ -530,7 +530,7 @@ instance HasHaddock (HsDecl GhcPs) where dfid_eqn' <- case dfid_eqn of FamEqn { feqn_ext, feqn_tycon, feqn_bndrs, feqn_pats, feqn_fixity, feqn_rhs } -> do - registerHdkA feqn_tycon + registerHdkN feqn_tycon feqn_rhs' <- addHaddock feqn_rhs pure $ FamEqn { feqn_ext, @@ -547,7 +547,7 @@ instance HasHaddock (HsDecl GhcPs) where addHaddock (TyClD _ decl) | SynDecl { tcdSExt, tcdLName, tcdTyVars, tcdFixity, tcdRhs } <- decl = do - registerHdkA tcdLName + registerHdkN tcdLName -- todo: register keyword location of '=', see Note [Register keyword location] tcdRhs' <- addHaddock tcdRhs pure $ @@ -563,7 +563,7 @@ instance HasHaddock (HsDecl GhcPs) where -- -> IO Float -- ^ The output float -- addHaddock (ForD _ decl) = do - registerHdkA (fd_name decl) + registerHdkN (fd_name decl) fd_sig_ty' <- addHaddock (fd_sig_ty decl) pure $ ForD noExtField (decl{ fd_sig_ty = fd_sig_ty' }) @@ -700,7 +700,7 @@ instance HasHaddock (LocatedA (ConDecl GhcPs)) where case con_decl of ConDeclGADT { con_g_ext, con_names, con_dcolon, con_bndrs, con_mb_cxt, con_g_args, con_res_ty } -> do -- discardHasInnerDocs is ok because we don't need this info for GADTs. - con_doc' <- discardHasInnerDocs $ getConDoc (getLocA (NE.head con_names)) + con_doc' <- discardHasInnerDocs $ getConDoc (getLocN (NE.head con_names)) con_g_args' <- case con_g_args of PrefixConGADT ts -> PrefixConGADT <$> addHaddock ts @@ -718,7 +718,7 @@ instance HasHaddock (LocatedA (ConDecl GhcPs)) where addConTrailingDoc (srcSpanEnd $ locA l_con_decl) $ case con_args of PrefixCon _ ts -> do - con_doc' <- getConDoc (getLocA con_name) + con_doc' <- getConDoc (getLocN con_name) ts' <- traverse addHaddockConDeclFieldTy ts pure $ L l_con_decl $ ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, @@ -726,14 +726,14 @@ instance HasHaddock (LocatedA (ConDecl GhcPs)) where con_args = PrefixCon noTypeArgs ts' } InfixCon t1 t2 -> do t1' <- addHaddockConDeclFieldTy t1 - con_doc' <- getConDoc (getLocA con_name) + con_doc' <- getConDoc (getLocN con_name) t2' <- addHaddockConDeclFieldTy t2 pure $ L l_con_decl $ ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, con_doc = lexLHsDocString <$> con_doc', con_args = InfixCon t1' t2' } RecCon (L l_rec flds) -> do - con_doc' <- getConDoc (getLocA con_name) + con_doc' <- getConDoc (getLocN con_name) flds' <- traverse addHaddockConDeclField flds pure $ L l_con_decl $ ConDeclH98 { con_ext, con_name, con_forall, con_ex_tvs, con_mb_cxt, @@ -1158,6 +1158,9 @@ registerLocHdkA l = HdkA (getBufSpan l) (pure ()) registerHdkA :: GenLocated (SrcSpanAnn' a) e -> HdkA () registerHdkA a = registerLocHdkA (getLocA a) +registerHdkN :: GenLocated (EpAnnS a) e -> HdkA () +registerHdkN a = registerLocHdkA (getLocN a) + -- Modify the action of a HdkA computation. hoistHdkA :: (HdkM a -> HdkM b) -> HdkA a -> HdkA b hoistHdkA f (HdkA l m) = HdkA l (f m) diff --git a/compiler/GHC/Rename/Bind.hs b/compiler/GHC/Rename/Bind.hs index 7f3edf841c..56248d5ef0 100644 --- a/compiler/GHC/Rename/Bind.hs +++ b/compiler/GHC/Rename/Bind.hs @@ -447,7 +447,7 @@ rnBindLHS name_maker _ bind@(FunBind { fun_id = rdr_name }) rnBindLHS name_maker _ (PatSynBind x psb@PSB{ psb_id = rdrname }) | isTopRecNameMaker name_maker - = do { addLocMA checkConName rdrname + = do { addLocMN checkConName rdrname ; name <- lookupLocatedTopConstructorRnN rdrname -- Should be in scope already ; return (PatSynBind x psb{ psb_ext = noAnn, psb_id = name }) } @@ -676,7 +676,7 @@ makeMiniFixityEnv decls = foldlM add_one_sig emptyFsEnv decls where add_one_sig :: MiniFixityEnv -> LFixitySig GhcPs -> RnM MiniFixityEnv add_one_sig env (L loc (FixitySig _ names fixity)) = - foldlM add_one env [ (locA loc,locA name_loc,name,fixity) + foldlM add_one env [ (locA loc,locN name_loc,name,fixity) | L name_loc name <- names ] add_one env (loc, name_loc, name,fixity) = do @@ -784,7 +784,7 @@ rnPatSynBind sig_fn bind@(PSB { psb_id = L l name } where -- See Note [Renaming pattern synonym variables] - lookupPatSynBndr = wrapLocMA lookupLocalOccRn + lookupPatSynBndr = wrapLocMN lookupLocalOccRn patternSynonymErr :: TcRnMessage patternSynonymErr @@ -936,7 +936,7 @@ rnMethodBindLHS :: Bool -> Name -> RnM (LHsBindsLR GhcRn GhcPs) rnMethodBindLHS _ cls (L loc bind@(FunBind { fun_id = name })) rest = setSrcSpanA loc $ do - do { sel_name <- wrapLocMA (lookupInstDeclBndr cls (text "method")) name + do { sel_name <- wrapLocMN (lookupInstDeclBndr cls (text "method")) name -- We use the selector name as the binder ; let bind' = bind { fun_id = sel_name, fun_ext = noExtField } ; return (L loc bind' `consBag` rest ) } @@ -1375,7 +1375,7 @@ rnSrcFixityDecl sig_ctxt = rn_decl lookup_one :: LocatedN RdrName -> RnM [LocatedN Name] lookup_one (L name_loc rdr_name) - = setSrcSpanA name_loc $ + = setSrcSpanN name_loc $ -- This lookup will fail if the name is not defined in the -- same binding group as this fixity declaration. do names <- lookupLocalTcNames sig_ctxt what rdr_name @@ -1392,11 +1392,11 @@ rnSrcFixityDecl sig_ctxt = rn_decl dupSigDeclErr :: NonEmpty (LocatedN RdrName, Sig GhcPs) -> RnM () dupSigDeclErr pairs@((L loc name, sig) :| _) - = addErrAt (locA loc) $ mkTcRnUnknownMessage $ mkPlainError noHints $ + = addErrAt (locN loc) $ mkTcRnUnknownMessage $ mkPlainError noHints $ vcat [ text "Duplicate" <+> what_it_is <> text "s for" <+> quotes (ppr name) , text "at" <+> vcat (map ppr $ sortBy SrcLoc.leftmost_smallest - $ map (getLocA . fst) + $ map (getLocN . fst) $ toList pairs) ] where diff --git a/compiler/GHC/Rename/Env.hs b/compiler/GHC/Rename/Env.hs index 3d3ded48f0..0d3f181d12 100644 --- a/compiler/GHC/Rename/Env.hs +++ b/compiler/GHC/Rename/Env.hs @@ -187,7 +187,7 @@ newTopSrcBinder (L loc rdr_name) if isExternalName name then do { this_mod <- getModule ; unless (this_mod == nameModule name) - (addErrAt (locA loc) (badOrigBinding rdr_name)) + (addErrAt (locN loc) (badOrigBinding rdr_name)) ; return name } else -- See Note [Binders in Template Haskell] in "GHC.ThToHs" do { this_mod <- getModule @@ -196,7 +196,7 @@ newTopSrcBinder (L loc rdr_name) | Just (rdr_mod, rdr_occ) <- isOrig_maybe rdr_name = do { this_mod <- getModule ; unless (rdr_mod == this_mod || rdr_mod == rOOT_MAIN) - (addErrAt (locA loc) (badOrigBinding rdr_name)) + (addErrAt (locN loc) (badOrigBinding rdr_name)) -- When reading External Core we get Orig names as binders, -- but they should agree with the module gotten from the monad -- @@ -214,11 +214,11 @@ newTopSrcBinder (L loc rdr_name) -- the RdrName, not from the environment. In principle, it'd be fine to -- have an arbitrary mixture of external core definitions in a single module, -- (apart from module-initialisation issues, perhaps). - ; newGlobalBinder rdr_mod rdr_occ (locA loc) } + ; newGlobalBinder rdr_mod rdr_occ (locN loc) } | otherwise = do { when (isQual rdr_name) - (addErrAt (locA loc) (badQualBndrErr rdr_name)) + (addErrAt (locN loc) (badQualBndrErr rdr_name)) -- Binders should not be qualified; if they are, and with a different -- module name, we get a confusing "M.T is not in scope" error later @@ -227,11 +227,11 @@ newTopSrcBinder (L loc rdr_name) -- We are inside a TH bracket, so make an *Internal* name -- See Note [Top-level Names in Template Haskell decl quotes] in GHC.Rename.Names do { uniq <- newUnique - ; return (mkInternalName uniq (rdrNameOcc rdr_name) (locA loc)) } + ; return (mkInternalName uniq (rdrNameOcc rdr_name) (locN loc)) } else do { this_mod <- getModule - ; traceRn "newTopSrcBinder" (ppr this_mod $$ ppr rdr_name $$ ppr (locA loc)) - ; newGlobalBinder this_mod (rdrNameOcc rdr_name) (locA loc) } + ; traceRn "newTopSrcBinder" (ppr this_mod $$ ppr rdr_name $$ ppr (locN loc)) + ; newGlobalBinder this_mod (rdrNameOcc rdr_name) (locN loc) } } {- @@ -290,13 +290,13 @@ lookupLocatedTopConstructorRn :: Located RdrName -> RnM (Located Name) lookupLocatedTopConstructorRn = wrapLocM (lookupTopBndrRn WL_Constructor) lookupLocatedTopConstructorRnN :: LocatedN RdrName -> RnM (LocatedN Name) -lookupLocatedTopConstructorRnN = wrapLocMA (lookupTopBndrRn WL_Constructor) +lookupLocatedTopConstructorRnN = wrapLocMN (lookupTopBndrRn WL_Constructor) lookupLocatedTopBndrRn :: Located RdrName -> RnM (Located Name) lookupLocatedTopBndrRn = wrapLocM (lookupTopBndrRn WL_Anything) lookupLocatedTopBndrRnN :: LocatedN RdrName -> RnM (LocatedN Name) -lookupLocatedTopBndrRnN = wrapLocMA (lookupTopBndrRn WL_Anything) +lookupLocatedTopBndrRnN = wrapLocMN (lookupTopBndrRn WL_Anything) -- | Lookup an @Exact@ @RdrName@. See Note [Looking up Exact RdrNames]. -- This never adds an error, but it may return one, see @@ -390,7 +390,7 @@ lookupFamInstName :: Maybe Name -> LocatedN RdrName -- Used for TyData and TySynonym family instances only, -- See Note [Family instance binders] lookupFamInstName (Just cls) tc_rdr -- Associated type; c.f GHC.Rename.Bind.rnMethodBind - = wrapLocMA (lookupInstDeclBndr cls (text "associated type")) tc_rdr + = wrapLocMN (lookupInstDeclBndr cls (text "associated type")) tc_rdr lookupFamInstName Nothing tc_rdr -- Family instance; tc_rdr is an *occurrence* = lookupLocatedOccRnConstr tc_rdr @@ -971,13 +971,13 @@ we'll miss the fact that the qualified import is redundant. -} -lookupLocatedOccRn :: GenLocated (SrcSpanAnn' ann) RdrName - -> TcRn (GenLocated (SrcSpanAnn' ann) Name) -lookupLocatedOccRn = wrapLocMA lookupOccRn +lookupLocatedOccRn :: LocatedN RdrName + -> TcRn (LocatedN Name) +lookupLocatedOccRn = wrapLocMN lookupOccRn -lookupLocatedOccRnConstr :: GenLocated (SrcSpanAnn' ann) RdrName - -> TcRn (GenLocated (SrcSpanAnn' ann) Name) -lookupLocatedOccRnConstr = wrapLocMA lookupOccRnConstr +lookupLocatedOccRnConstr :: LocatedN RdrName + -> TcRn (LocatedN Name) +lookupLocatedOccRnConstr = wrapLocMN lookupOccRnConstr lookupLocatedOccRnRecField :: GenLocated (SrcSpanAnn' ann) RdrName -> TcRn (GenLocated (SrcSpanAnn' ann) Name) @@ -1783,7 +1783,7 @@ lookupSigCtxtOccRnN :: HsSigCtxt -- like "type family" -> LocatedN RdrName -> RnM (LocatedN Name) lookupSigCtxtOccRnN ctxt what - = wrapLocMA $ \ rdr_name -> + = wrapLocMN $ \ rdr_name -> do { mb_name <- lookupBindGroupOcc ctxt what rdr_name ; case mb_name of Left err -> do { addErr (mkTcRnNotInScope rdr_name err) @@ -2029,11 +2029,11 @@ lookupSyntaxNames :: [Name] -- Standard names lookupSyntaxNames std_names = do { rebindable_on <- xoptM LangExt.RebindableSyntax ; if not rebindable_on then - return (map (HsVar noExtField . noLocA) std_names, emptyFVs) + return (map (HsVar noExtField . noLocN) std_names, emptyFVs) else do { usr_names <- mapM (lookupOccRnNone . mkRdrUnqual . nameOccName) std_names - ; return (map (HsVar noExtField . noLocA) usr_names, mkFVs usr_names) } } + ; return (map (HsVar noExtField . noLocN) usr_names, mkFVs usr_names) } } {- diff --git a/compiler/GHC/Rename/Expr.hs b/compiler/GHC/Rename/Expr.hs index 9e7decb2ff..3fc7e6b3c6 100644 --- a/compiler/GHC/Rename/Expr.hs +++ b/compiler/GHC/Rename/Expr.hs @@ -264,7 +264,7 @@ rnExpr (HsVar _ (L l v)) -> rnExpr (ExplicitList noAnn []) | otherwise - -> finishHsVar (L (na2la l) name) ; + -> finishHsVar (L (nn2la l) name) ; Just (FieldGreName fl) -> do { let sel_name = flSelector fl ; this_mod <- getModule @@ -471,7 +471,7 @@ rnExpr (RecordCon { rcon_con = con_id , rcon_con = con_lname, rcon_flds = rec_binds' } , fvs `plusFV` plusFVs fvss `addOneFV` con_name) } where - mk_hs_var l n = HsVar noExtField (L (noAnnSrcSpan l) n) + mk_hs_var l n = HsVar noExtField (L (noAnnSrcSpanN l) n) rn_field (L l fld) = do { (arg', fvs) <- rnLExpr (hfbRHS fld) ; return (L l (fld { hfbRHS = arg' }), fvs) } @@ -1338,12 +1338,12 @@ lookupStmtNamePoly ctxt name = do { rebindable_on <- xoptM LangExt.RebindableSyntax ; if rebindable_on then do { fm <- lookupOccRn (nameRdrName name) - ; return (HsVar noExtField (noLocA fm), unitFV fm) } + ; return (HsVar noExtField (noLocN fm), unitFV fm) } else not_rebindable } | otherwise = not_rebindable where - not_rebindable = return (HsVar noExtField (noLocA name), emptyFVs) + not_rebindable = return (HsVar noExtField (noLocN name), emptyFVs) -- | Is this a context where we respect RebindableSyntax? -- but ListComp are never rebindable @@ -2699,7 +2699,7 @@ getMonadFailOp ctxt nlHsApp (noLocA failExpr) (nlHsApp (noLocA $ fromStringExpr) arg_syn_expr) let failAfterFromStringExpr :: HsExpr GhcRn = - unLoc $ mkHsLam [noLocA $ VarPat noExtField $ noLocA arg_name] body + unLoc $ mkHsLam [noLocA $ VarPat noExtField $ noLocN arg_name] body let failAfterFromStringSynExpr :: SyntaxExpr GhcRn = mkSyntaxExpr failAfterFromStringExpr return (failAfterFromStringSynExpr, failFvs `plusFV` fromStringFvs) diff --git a/compiler/GHC/Rename/HsType.hs b/compiler/GHC/Rename/HsType.hs index 6e1418a130..fabb403f08 100644 --- a/compiler/GHC/Rename/HsType.hs +++ b/compiler/GHC/Rename/HsType.hs @@ -402,7 +402,7 @@ rnImplicitTvOccs mb_assoc implicit_vs_with_dups thing_inside -- Use the currently set SrcSpan as the new source location for each Name. -- See Note [Source locations for implicitly bound type variables]. ; loc <- getSrcSpanM - ; let loc' = noAnnSrcSpan loc + ; let loc' = noAnnSrcSpanN loc ; vars <- mapM (newTyVarNameRn mb_assoc . L loc' . unLoc) implicit_vs ; bindLocalNamesFV vars $ @@ -635,7 +635,7 @@ rnHsTyKi env (HsTyVar _ ip (L loc rdr_name)) ; return (HsTyVar noAnn ip (L loc name), unitFV name) } rnHsTyKi env ty@(HsOpTy _ prom ty1 l_op ty2) - = setSrcSpan (getLocA l_op) $ + = setSrcSpan (getLocN l_op) $ do { (l_op', fvs1) <- rnHsTyOp env (ppr ty) l_op ; let op_name = unLoc l_op' ; fix <- lookupTyFixityRn l_op' @@ -1023,7 +1023,7 @@ bindHsQTyVars doc mb_assoc body_kv_occs hsq_bndrs thing_inside -- -- class C (a :: j) (b :: k) where -- ^^^^^^^^^^^^^^^ - bndrs_loc = case map get_bndr_loc hs_tv_bndrs ++ map getLocA body_kv_occs of + bndrs_loc = case map get_bndr_loc hs_tv_bndrs ++ map getLocN body_kv_occs of [] -> panic "bindHsQTyVars.bndrs_loc" [loc] -> loc (loc:locs) -> loc `combineSrcSpans` last locs @@ -1032,9 +1032,9 @@ bindHsQTyVars doc mb_assoc body_kv_occs hsq_bndrs thing_inside -- include surrounding parens. for error messages to be -- compatible, we recreate the location from the contents get_bndr_loc :: LHsTyVarBndr () GhcPs -> SrcSpan - get_bndr_loc (L _ (UserTyVar _ _ ln)) = getLocA ln + get_bndr_loc (L _ (UserTyVar _ _ ln)) = getLocN ln get_bndr_loc (L _ (KindedTyVar _ _ ln lk)) - = combineSrcSpans (getLocA ln) (getLocA lk) + = combineSrcSpans (getLocN ln) (getLocA lk) {- Note [bindHsQTyVars examples] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/compiler/GHC/Rename/Module.hs b/compiler/GHC/Rename/Module.hs index 6748d60a56..bd57a3972c 100644 --- a/compiler/GHC/Rename/Module.hs +++ b/compiler/GHC/Rename/Module.hs @@ -275,7 +275,7 @@ rnSrcWarnDecls _ [] rnSrcWarnDecls bndr_set decls' = do { -- check for duplicates ; mapM_ (\ dups -> let ((L loc rdr) :| (lrdr':_)) = dups - in addErrAt (locA loc) (TcRnDuplicateWarningDecls lrdr' rdr)) + in addErrAt (locN loc) (TcRnDuplicateWarningDecls lrdr' rdr)) warn_rdr_dups ; pairs_s <- mapM (addLocMA rn_deprec) decls ; return (WarnSome ((concat pairs_s))) } @@ -838,7 +838,7 @@ rnFamEqn doc atfi extra_kvars -- -- type instance F a b c = Either a b -- ^^^^^ - lhs_loc = case map lhsTypeArgSrcSpan pats ++ map getLocA extra_kvars of + lhs_loc = case map lhsTypeArgSrcSpan pats ++ map getLocN extra_kvars of [] -> panic "rnFamEqn.lhs_loc" [loc] -> loc (loc:locs) -> loc `combineSrcSpans` last locs @@ -2377,7 +2377,7 @@ rnInjectivityAnn tvBndrs (L _ (TyVarSig _ resTv)) -- not-in-scope variables) don't check the validity of injectivity -- annotation. This gives better error messages. ; when (noRnErrors && not lhsValid) $ - addErrAt (getLocA injFrom) $ mkTcRnUnknownMessage $ mkPlainError noHints $ + addErrAt (getLocN injFrom) $ mkTcRnUnknownMessage $ mkPlainError noHints $ ( vcat [ text $ "Incorrect type variable on the LHS of " ++ "injectivity condition" , nest 5 @@ -2436,7 +2436,7 @@ rnConDecl :: ConDecl GhcPs -> RnM (ConDecl GhcRn, FreeVars) rnConDecl decl@(ConDeclH98 { con_name = name, con_ex_tvs = ex_tvs , con_mb_cxt = mcxt, con_args = args , con_doc = mb_doc, con_forall = forall_ }) - = do { _ <- addLocMA checkConName name + = do { _ <- addLocMN checkConName name ; new_name <- lookupLocatedTopConstructorRnN name -- We bind no implicit binders here; this is just like @@ -2473,7 +2473,7 @@ rnConDecl (ConDeclGADT { con_names = names , con_g_args = args , con_res_ty = res_ty , con_doc = mb_doc }) - = do { mapM_ (addLocMA checkConName) names + = do { mapM_ (addLocMN checkConName) names ; new_names <- mapM (lookupLocatedTopConstructorRnN) names ; let -- We must ensure that we extract the free tkvs in left-to-right @@ -2587,8 +2587,8 @@ extendPatSynEnv dup_fields_ok has_sel val_decls local_fix_env thing = do { | (L bind_loc (PatSynBind _ (PSB { psb_id = L _ n , psb_args = RecCon as }))) <- bind = do - bnd_name <- newTopSrcBinder (L (l2l bind_loc) n) - let field_occs = map ((\ f -> L (noAnnSrcSpan $ getLocA (foLabel f)) f) . recordPatSynField) as + bnd_name <- newTopSrcBinder (L (l2ln bind_loc) n) + let field_occs = map ((\ f -> L (noAnnSrcSpan $ getLocN (foLabel f)) f) . recordPatSynField) as flds <- mapM (newRecordSelector dup_fields_ok has_sel [bnd_name]) field_occs return ((bnd_name, flds): names) | L bind_loc (PatSynBind _ (PSB { psb_id = L _ n})) <- bind diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs index 6a98ba1893..aeec23aad7 100644 --- a/compiler/GHC/Rename/Names.hs +++ b/compiler/GHC/Rename/Names.hs @@ -949,7 +949,8 @@ getLocalNonValBinders fixity_env -- In a hs-boot file, the value binders come from the -- *signatures*, and there should be no foreign binders - hs_boot_sig_bndrs = [ L (l2l decl_loc) (unLoc n) + hs_boot_sig_bndrs :: [LocatedN RdrName] + hs_boot_sig_bndrs = [ L (l2ln decl_loc) (unLoc n) | L decl_loc (TypeSig _ ns _) <- val_sigs, n <- ns] -- the SrcSpan attached to the input should be the span of the @@ -1025,7 +1026,7 @@ getLocalNonValBinders fixity_env -- See (1) above L loc cls_rdr <- MaybeT $ pure $ getLHsInstDeclClass_maybe inst_ty -- See (2) above - MaybeT $ setSrcSpan (locA loc) $ lookupGlobalOccRn_maybe cls_rdr + MaybeT $ setSrcSpan (locN loc) $ lookupGlobalOccRn_maybe cls_rdr -- Assuming the previous step succeeded, process any associated data -- family instances. If the previous step failed, bail out. case mb_cls_nm of @@ -1054,7 +1055,7 @@ getLocalNonValBinders fixity_env newRecordSelector :: DuplicateRecordFields -> FieldSelectors -> [Name] -> LFieldOcc GhcPs -> RnM FieldLabel newRecordSelector _ _ [] _ = error "newRecordSelector: datatype has no constructors!" newRecordSelector dup_fields_ok has_sel (dc:_) (L loc (FieldOcc _ (L _ fld))) - = do { selName <- newTopSrcBinder $ L (l2l loc) $ field + = do { selName <- newTopSrcBinder $ L (l2ln loc) $ field ; return $ FieldLabel { flLabel = fieldLabelString , flHasDuplicateRecordFields = dup_fields_ok , flHasFieldSelector = has_sel diff --git a/compiler/GHC/Rename/Pat.hs b/compiler/GHC/Rename/Pat.hs index 7d8b54fa95..d17b6fca76 100644 --- a/compiler/GHC/Rename/Pat.hs +++ b/compiler/GHC/Rename/Pat.hs @@ -492,7 +492,7 @@ rnPatAndThen mk (BangPat _ pat) = do { pat' <- rnLPatAndThen mk pat ; return (BangPat noExtField pat') } rnPatAndThen mk (VarPat x (L l rdr)) = do { loc <- liftCps getSrcSpanM - ; name <- newPatName mk (L (noAnnSrcSpan loc) rdr) + ; name <- newPatName mk (L (noAnnSrcSpanN loc) rdr) ; return (VarPat x (L l name)) } -- we need to bind pattern variables for view pattern expressions -- (e.g. in the pattern (x, x -> y) x needs to be bound in the rhs of the tuple) @@ -541,14 +541,14 @@ rnPatAndThen _ (NPat x (L l lit) mb_neg _eq) ; return (NPat x (L l lit') mb_neg' eq') } rnPatAndThen mk (NPlusKPat _ rdr (L l lit) _ _ _ ) - = do { new_name <- newPatName mk (l2n rdr) + = do { new_name <- newPatName mk rdr ; (lit', _) <- liftCpsFV $ rnOverLit lit -- See Note [Negative zero] -- We skip negateName as -- negative zero doesn't make -- sense in n + k patterns ; minus <- liftCpsFV $ lookupSyntax minusName ; ge <- liftCpsFV $ lookupSyntax geName - ; return (NPlusKPat noExtField (L (noAnnSrcSpan $ nameSrcSpan new_name) new_name) + ; return (NPlusKPat noExtField (L (noAnnSrcSpanN $ nameSrcSpan new_name) new_name) (L l lit') lit' ge minus) } -- The Report says that n+k patterns must be in Integral @@ -688,7 +688,7 @@ rnHsRecPatsAndThen mk (L _ con) ; check_unused_wildcard (implicit_binders flds' <$> dd) ; return (HsRecFields { rec_flds = flds', rec_dotdot = dd }) } where - mkVarPat l n = VarPat noExtField (L (noAnnSrcSpan l) n) + mkVarPat l n = VarPat noExtField (L (noAnnSrcSpanN l) n) rn_field (L l fld, n') = do { arg' <- rnLPatAndThen (nested_mk dd mk (RecFieldsDotDot n')) (hfbRHS fld) ; return (L l (fld { hfbRHS = arg' })) } @@ -836,7 +836,7 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot }) ; return [ L (noAnnSrcSpan loc) (HsFieldBind { hfbAnn = noAnn , hfbLHS - = L (noAnnSrcSpan loc) (FieldOcc sel (L (noAnnSrcSpan loc) arg_rdr)) + = L (noAnnSrcSpan loc) (FieldOcc sel (L (noAnnSrcSpanN loc) arg_rdr)) , hfbRHS = L locn (mk_arg loc arg_rdr) , hfbPun = False }) | fl <- dot_dot_fields @@ -893,14 +893,14 @@ rnHsRecUpdFields flds -- Discard any module qualifier (#11662) ; let arg_rdr = mkRdrUnqual (rdrNameOcc lbl) ; return (L (l2l loc) (HsVar noExtField - (L (l2l loc) arg_rdr))) } + (L (l2ln loc) arg_rdr))) } else return arg ; (arg'', fvs) <- rnLExpr arg' ; let (lbl', fvs') = case mb_sel of UnambiguousGre gname -> let sel_name = greNameMangledName gname - in (Unambiguous sel_name (L (l2l loc) lbl), fvs `addOneFV` sel_name) - AmbiguousFields -> (Ambiguous noExtField (L (l2l loc) lbl), fvs) + in (Unambiguous sel_name (L (l2ln loc) lbl), fvs `addOneFV` sel_name) + AmbiguousFields -> (Ambiguous noExtField (L (l2ln loc) lbl), fvs) ; return (L l (HsFieldBind { hfbAnn = noAnn , hfbLHS = L loc lbl' @@ -997,7 +997,7 @@ rnOverLit origLit ; (from_thing_name, fvs1) <- lookupSyntaxName std_name ; let rebindable = from_thing_name /= std_name lit' = lit { ol_ext = OverLitRn { ol_rebindable = rebindable - , ol_from_fun = noLocA from_thing_name } } + , ol_from_fun = noLocN from_thing_name } } ; if isNegativeZeroOverLit lit' then do { (negate_name, fvs2) <- lookupSyntaxExpr negateName ; return ((lit' { ol_val = negateOverLitVal val }, Just negate_name) diff --git a/compiler/GHC/Rename/Splice.hs b/compiler/GHC/Rename/Splice.hs index 48a8aa807f..770cff7f6b 100644 --- a/compiler/GHC/Rename/Splice.hs +++ b/compiler/GHC/Rename/Splice.hs @@ -175,7 +175,7 @@ rn_utbracket outer_stage br@(VarBr x flg rdr_name) (quotedNameStageErr br) } } } - ; return (VarBr x flg (noLocA name), unitFV name) } + ; return (VarBr x flg (noLocN name), unitFV name) } rn_utbracket _ (ExpBr x e) = do { (e', fvs) <- rnLExpr e ; return (ExpBr x e', fvs) } @@ -307,7 +307,7 @@ rnUntypedSpliceGen run_splice pend_splice splice -> do { (splice', fvs) <- setStage pop_stage $ rnUntypedSplice splice ; loc <- getSrcSpanM - ; splice_name <- newLocalBndrRn (L (noAnnSrcSpan loc) unqualSplice) + ; splice_name <- newLocalBndrRn (L (noAnnSrcSpanN loc) unqualSplice) ; let (pending_splice, result) = pend_splice splice_name splice' ; ps <- readMutVar ps_var ; writeMutVar ps_var (pending_splice : ps) @@ -488,7 +488,7 @@ rnTypedSplice expr do { loc <- getSrcSpanM -- The renamer allocates a splice-point name to every typed splice -- (incl the top level ones for which it will not ultimately be used) - ; n' <- newLocalBndrRn (L (noAnnSrcSpan loc) unqualSplice) + ; n' <- newLocalBndrRn (L (noAnnSrcSpanN loc) unqualSplice) ; (expr', fvs) <- rnLExpr expr ; return (HsTypedSplice n' expr', fvs) } diff --git a/compiler/GHC/Rename/Utils.hs b/compiler/GHC/Rename/Utils.hs index 82f9623067..cb5a68c6c7 100644 --- a/compiler/GHC/Rename/Utils.hs +++ b/compiler/GHC/Rename/Utils.hs @@ -87,9 +87,9 @@ newLocalBndrRn (L loc rdr_name) -- See Note [Binders in Template Haskell] in "GHC.ThToHs" | otherwise = do { unless (isUnqual rdr_name) - (addErrAt (locA loc) (badQualBndrErr rdr_name)) + (addErrAt (locN loc) (badQualBndrErr rdr_name)) ; uniq <- newUnique - ; return (mkInternalName uniq (rdrNameOcc rdr_name) (locA loc)) } + ; return (mkInternalName uniq (rdrNameOcc rdr_name) (locN loc)) } newLocalBndrsRn :: [LocatedN RdrName] -> RnM [Name] newLocalBndrsRn = mapM newLocalBndrRn @@ -113,14 +113,14 @@ bindLocalNamesFV names enclosed_scope checkDupRdrNames :: [LocatedN RdrName] -> RnM () -- Check for duplicated names in a binding group checkDupRdrNames rdr_names_w_loc - = mapM_ (dupNamesErr getLocA) dups + = mapM_ (dupNamesErr getLocN) dups where (_, dups) = removeDups (\n1 n2 -> unLoc n1 `compare` unLoc n2) rdr_names_w_loc checkDupRdrNamesN :: [LocatedN RdrName] -> RnM () -- Check for duplicated names in a binding group checkDupRdrNamesN rdr_names_w_loc - = mapM_ (dupNamesErr getLocA) dups + = mapM_ (dupNamesErr getLocN) dups where (_, dups) = removeDups (\n1 n2 -> unLoc n1 `compare` unLoc n2) rdr_names_w_loc @@ -143,7 +143,7 @@ checkShadowedRdrNames loc_rdr_names where filtered_rdrs = filterOut (isExact . unLoc) loc_rdr_names -- See Note [Binders in Template Haskell] in "GHC.ThToHs" - get_loc_occ (L loc rdr) = (locA loc,rdrNameOcc rdr) + get_loc_occ (L loc rdr) = (locN loc,rdrNameOcc rdr) checkDupAndShadowedNames :: (GlobalRdrEnv, LocalRdrEnv) -> [Name] -> RnM () checkDupAndShadowedNames envs names @@ -438,7 +438,7 @@ check_unused flag bound_names used_names warnForallIdentifier :: LocatedN RdrName -> RnM () warnForallIdentifier (L l rdr_name@(Unqual occ)) | isKw (fsLit "forall") || isKw (fsLit "∀") - = addDiagnosticAt (locA l) (TcRnForallIdentifier rdr_name) + = addDiagnosticAt (locN l) (TcRnForallIdentifier rdr_name) where isKw = (occNameFS occ ==) warnForallIdentifier _ = return () @@ -669,6 +669,11 @@ wrapGenSpan :: a -> LocatedAn an a -- See Note [Rebindable syntax and HsExpansion] wrapGenSpan x = L (noAnnSrcSpan generatedSrcSpan) x +wrapGenSpanN :: a -> LocatedN a +-- Wrap something in a "generatedSrcSpan" +-- See Note [Rebindable syntax and HsExpansion] +wrapGenSpanN x = L (noAnnSrcSpanN generatedSrcSpan) x + genHsApps :: Name -> [LHsExpr GhcRn] -> HsExpr GhcRn genHsApps fun args = foldl genHsApp (genHsVar fun) args @@ -679,7 +684,7 @@ genLHsVar :: Name -> LHsExpr GhcRn genLHsVar nm = wrapGenSpan $ genHsVar nm genHsVar :: Name -> HsExpr GhcRn -genHsVar nm = HsVar noExtField $ wrapGenSpan nm +genHsVar nm = HsVar noExtField $ wrapGenSpanN nm genAppType :: HsExpr GhcRn -> HsType (NoGhcTc GhcRn) -> HsExpr GhcRn genAppType expr ty = HsAppType noExtField (wrapGenSpan expr) noHsTok (mkEmptyWildCardBndrs (wrapGenSpan ty)) @@ -694,11 +699,11 @@ genSimpleConPat :: Name -> [LPat GhcRn] -> LPat GhcRn -- The pattern (C p1 .. pn) genSimpleConPat con pats = wrapGenSpan $ ConPat { pat_con_ext = noExtField - , pat_con = wrapGenSpan con + , pat_con = wrapGenSpanN con , pat_args = PrefixCon [] pats } genVarPat :: Name -> LPat GhcRn -genVarPat n = wrapGenSpan $ VarPat noExtField (wrapGenSpan n) +genVarPat n = wrapGenSpan $ VarPat noExtField (wrapGenSpanN n) genWildPat :: LPat GhcRn genWildPat = wrapGenSpan $ WildPat noExtField @@ -706,11 +711,12 @@ genWildPat = wrapGenSpan $ WildPat noExtField genSimpleFunBind :: Name -> [LPat GhcRn] -> LHsExpr GhcRn -> LHsBind GhcRn genSimpleFunBind fun pats expr - = L gen $ genFunBind (L gen fun) - [mkMatch (mkPrefixFunRhs (L gen fun)) pats expr + = L gen $ genFunBind (L genN fun) + [mkMatch (mkPrefixFunRhs (L genN fun)) pats expr emptyLocalBinds] where gen = noAnnSrcSpan generatedSrcSpan + genN = noAnnSrcSpanN generatedSrcSpan genFunBind :: LocatedN Name -> [LMatch GhcRn (LHsExpr GhcRn)] -> HsBind GhcRn diff --git a/compiler/GHC/Tc/Deriv/Functor.hs b/compiler/GHC/Tc/Deriv/Functor.hs index 4b111f7a41..b69ab23211 100644 --- a/compiler/GHC/Tc/Deriv/Functor.hs +++ b/compiler/GHC/Tc/Deriv/Functor.hs @@ -156,7 +156,7 @@ gen_Functor_binds loc (DerivInstTys{dit_rep_tc = tycon}) | Phantom <- last (tyConRoles tycon) = (unitBag fmap_bind, emptyBag) where - fmap_name = L (noAnnSrcSpan loc) fmap_RDR + fmap_name = L (noAnnSrcSpanN loc) fmap_RDR fmap_bind = mkRdrFunBind fmap_name fmap_eqns fmap_eqns = [mkSimpleMatch fmap_match_ctxt [nlWildPat] @@ -168,7 +168,7 @@ gen_Functor_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon = (listToBag [fmap_bind, replace_bind], emptyBag) where data_cons = getPossibleDataCons tycon tycon_args - fmap_name = L (noAnnSrcSpan loc) fmap_RDR + fmap_name = L (noAnnSrcSpanN loc) fmap_RDR -- See Note [EmptyDataDecls with Functor, Foldable, and Traversable] fmap_bind = mkRdrFunBindEC 2 id fmap_name fmap_eqns @@ -207,7 +207,7 @@ gen_Functor_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon , ft_co_var = panic "contravariant in ft_fmap" } -- See Note [Deriving <$] - replace_name = L (noAnnSrcSpan loc) replace_RDR + replace_name = L (noAnnSrcSpanN loc) replace_RDR -- See Note [EmptyDataDecls with Functor, Foldable, and Traversable] replace_bind = mkRdrFunBindEC 2 id replace_name replace_eqns @@ -819,7 +819,7 @@ gen_Foldable_binds loc (DerivInstTys{dit_rep_tc = tycon}) | Phantom <- last (tyConRoles tycon) = (unitBag foldMap_bind, emptyBag) where - foldMap_name = L (noAnnSrcSpan loc) foldMap_RDR + foldMap_name = L (noAnnSrcSpanN loc) foldMap_RDR foldMap_bind = mkRdrFunBind foldMap_name foldMap_eqns foldMap_eqns = [mkSimpleMatch foldMap_match_ctxt [nlWildPat, nlWildPat] @@ -837,9 +837,9 @@ gen_Foldable_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon where data_cons = getPossibleDataCons tycon tycon_args - foldr_name = L (noAnnSrcSpan loc) foldable_foldr_RDR + foldr_name = L (noAnnSrcSpanN loc) foldable_foldr_RDR - foldr_bind = mkRdrFunBind (L (noAnnSrcSpan loc) foldable_foldr_RDR) eqns + foldr_bind = mkRdrFunBind (L (noAnnSrcSpanN loc) foldable_foldr_RDR) eqns eqns = map foldr_eqn data_cons foldr_eqn con = evalState (match_foldr z_Expr [f_Pat,z_Pat] con =<< parts) bs_RDRs @@ -847,7 +847,7 @@ gen_Foldable_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon parts = sequence $ foldDataConArgs ft_foldr con dit foldr_match_ctxt = mkPrefixFunRhs foldr_name - foldMap_name = L (noAnnSrcSpan loc) foldMap_RDR + foldMap_name = L (noAnnSrcSpanN loc) foldMap_RDR -- See Note [EmptyDataDecls with Functor, Foldable, and Traversable] foldMap_bind = mkRdrFunBindEC 2 (const mempty_Expr) @@ -871,7 +871,7 @@ gen_Foldable_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon go NotNull = Nothing go (NullM a) = Just (Just a) - null_name = L (noAnnSrcSpan loc) null_RDR + null_name = L (noAnnSrcSpanN loc) null_RDR null_match_ctxt = mkPrefixFunRhs null_name null_bind = mkRdrFunBind null_name null_eqns null_eqns = map null_eqn data_cons @@ -1053,7 +1053,7 @@ gen_Traversable_binds loc (DerivInstTys{dit_rep_tc = tycon}) | Phantom <- last (tyConRoles tycon) = (unitBag traverse_bind, emptyBag) where - traverse_name = L (noAnnSrcSpan loc) traverse_RDR + traverse_name = L (noAnnSrcSpanN loc) traverse_RDR traverse_bind = mkRdrFunBind traverse_name traverse_eqns traverse_eqns = [mkSimpleMatch traverse_match_ctxt @@ -1067,7 +1067,7 @@ gen_Traversable_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon where data_cons = getPossibleDataCons tycon tycon_args - traverse_name = L (noAnnSrcSpan loc) traverse_RDR + traverse_name = L (noAnnSrcSpanN loc) traverse_RDR -- See Note [EmptyDataDecls with Functor, Foldable, and Traversable] traverse_bind = mkRdrFunBindEC 2 (nlHsApp pure_Expr) diff --git a/compiler/GHC/Tc/Deriv/Generate.hs b/compiler/GHC/Tc/Deriv/Generate.hs index e51eee9841..ddbf5be91e 100644 --- a/compiler/GHC/Tc/Deriv/Generate.hs +++ b/compiler/GHC/Tc/Deriv/Generate.hs @@ -598,7 +598,7 @@ nlConWildPat :: DataCon -> LPat GhcPs -- The pattern (K {}) nlConWildPat con = noLocA $ ConPat { pat_con_ext = noAnn - , pat_con = noLocA $ getRdrName con + , pat_con = noLocN $ getRdrName con , pat_args = RecCon $ HsRecFields { rec_flds = [] , rec_dotdot = Nothing } @@ -854,7 +854,7 @@ gen_Ix_binds loc (DerivInstTys{dit_rep_tc = tycon}) = do enum_index = mkSimpleGeneratedFunBind loc unsafeIndex_RDR - [noLocA (AsPat noAnn (noLocA c_RDR) noHsTok + [noLocA (AsPat noAnn (noLocN c_RDR) noHsTok (nlTuplePat [a_Pat, nlWildPat] Boxed)), d_Pat] ( untag_Expr [(a_RDR, ah_RDR)] ( @@ -1990,7 +1990,7 @@ gen_Newtype_binds loc' cls inst_tvs inst_tys rhs_ty underlying_inst_tys :: [Type] underlying_inst_tys = changeLast inst_tys rhs_ty - locn = noAnnSrcSpan loc' + locn = noAnnSrcSpanN loc' loca = noAnnSrcSpan loc' -- For each class method, generate its derived binding and instance -- signature. Using the first example from @@ -2040,7 +2040,7 @@ gen_Newtype_binds loc' cls inst_tvs inst_tys rhs_ty mk_hs_tvb :: VarBndr TyVar flag -> LHsTyVarBndr flag GhcPs mk_hs_tvb (Bndr tv flag) = noLocA $ KindedTyVar noAnn flag - (noLocA (getRdrName tv)) + (noLocN (getRdrName tv)) (nlHsCoreTy (tyVarKind tv)) meth_RDR = getRdrName meth_id @@ -2078,7 +2078,7 @@ gen_Newtype_fam_insts loc' cls inst_tvs inst_tys rhs_ty underlying_inst_tys = changeLast inst_tys rhs_ty ats = classATs cls - locn = noAnnSrcSpan loc' + locn = noAnnSrcSpanN loc' cls_tvs = classTyVars cls in_scope = mkInScopeSetList inst_tvs lhs_env = zipTyEnv cls_tvs inst_tys @@ -2164,7 +2164,7 @@ genAuxBindSpecOriginal dflags loc spec (genAuxBindSpecSig loc spec))) where loca = noAnnSrcSpan loc - locn = noAnnSrcSpan loc + locn = noAnnSrcSpanN loc gen_bind :: AuxBindSpec -> LHsBind GhcPs gen_bind (DerivTag2Con _ tag2con_RDR) = mkFunBindSE 0 loc tag2con_RDR @@ -2220,7 +2220,7 @@ genAuxBindSpecDup loc original_rdr_name dup_spec (genAuxBindSpecSig loc dup_spec))) where loca = noAnnSrcSpan loc - locn = noAnnSrcSpan loc + locn = noAnnSrcSpanN loc dup_rdr_name = auxBindSpecRdrName dup_spec -- | Generate the type signature of an auxiliary binding. @@ -2289,9 +2289,9 @@ mkFunBindSE :: Arity -> SrcSpan -> RdrName -> [([LPat GhcPs], LHsExpr GhcPs)] -> LHsBind GhcPs mkFunBindSE arity loc fun pats_and_exprs - = mkRdrFunBindSE arity (L (noAnnSrcSpan loc) fun) matches + = mkRdrFunBindSE arity (L (noAnnSrcSpanN loc) fun) matches where - matches = [mkMatch (mkPrefixFunRhs (L (noAnnSrcSpan loc) fun)) + matches = [mkMatch (mkPrefixFunRhs (L (noAnnSrcSpanN loc) fun)) (map (parenthesizePat appPrec) p) e emptyLocalBinds | (p,e) <-pats_and_exprs] @@ -2299,7 +2299,7 @@ mkFunBindSE arity loc fun pats_and_exprs mkRdrFunBind :: LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs mkRdrFunBind fun@(L loc _fun_rdr) matches - = L (na2la loc) (mkFunBind Generated fun matches) + = L (nn2la loc) (mkFunBind Generated fun matches) -- | Make a function binding. If no equations are given, produce a function -- with the given arity that uses an empty case expression for the last @@ -2310,9 +2310,9 @@ mkFunBindEC :: Arity -> SrcSpan -> RdrName -> [([LPat GhcPs], LHsExpr GhcPs)] -> LHsBind GhcPs mkFunBindEC arity loc fun catch_all pats_and_exprs - = mkRdrFunBindEC arity catch_all (L (noAnnSrcSpan loc) fun) matches + = mkRdrFunBindEC arity catch_all (L (noAnnSrcSpanN loc) fun) matches where - matches = [ mkMatch (mkPrefixFunRhs (L (noAnnSrcSpan loc) fun)) + matches = [ mkMatch (mkPrefixFunRhs (L (noAnnSrcSpanN loc) fun)) (map (parenthesizePat appPrec) p) e emptyLocalBinds | (p,e) <- pats_and_exprs ] @@ -2327,7 +2327,7 @@ mkRdrFunBindEC :: Arity -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs mkRdrFunBindEC arity catch_all fun@(L loc _fun_rdr) matches - = L (na2la loc) (mkFunBind Generated fun matches') + = L (nn2la loc) (mkFunBind Generated fun matches') where -- Catch-all eqn looks like -- fmap _ z = case z of {} @@ -2351,7 +2351,7 @@ mkRdrFunBindEC arity catch_all fun@(L loc _fun_rdr) matches mkRdrFunBindSE :: Arity -> LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs mkRdrFunBindSE arity fun@(L loc fun_rdr) matches - = L (na2la loc) (mkFunBind Generated fun matches') + = L (nn2la loc) (mkFunBind Generated fun matches') where -- Catch-all eqn looks like -- compare _ _ = error "Void compare" diff --git a/compiler/GHC/Tc/Deriv/Generics.hs b/compiler/GHC/Tc/Deriv/Generics.hs index d35bac99a4..26e6e30c29 100644 --- a/compiler/GHC/Tc/Deriv/Generics.hs +++ b/compiler/GHC/Tc/Deriv/Generics.hs @@ -388,7 +388,7 @@ mkBindsRep dflags gk loc dit@(DerivInstTys{dit_rep_tc = tycon}) = (binds, sigs) from_matches = [mkHsCaseAlt pat rhs | (pat,rhs) <- from_alts] to_matches = [mkHsCaseAlt pat rhs | (pat,rhs) <- to_alts ] - loc' = noAnnSrcSpan loc + loc' = noAnnSrcSpanN loc loc'' = noAnnSrcSpan loc datacons = tyConDataCons tycon diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index 0c152b27b7..123fe5106c 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -168,7 +168,7 @@ instance Diagnostic TcRnMessage where TcRnDuplicateWarningDecls d rdr_name -> mkSimpleDecorated $ vcat [text "Multiple warning declarations for" <+> quotes (ppr rdr_name), - text "also at " <+> ppr (getLocA d)] + text "also at " <+> ppr (getLocN d)] TcRnSimplifierTooManyIterations simples limit wc -> mkSimpleDecorated $ hang (text "solveWanteds: too many iterations" @@ -1837,7 +1837,7 @@ dodgy_msg_insert :: forall p . (Anno (IdP (GhcPass p)) ~ SrcSpanAnnN) => IdP (Gh dodgy_msg_insert tc = IEThingAll noAnn ii where ii :: LIEWrappedName (GhcPass p) - ii = noLocA (IEName noExtField $ noLocA tc) + ii = noLocA (IEName noExtField $ noLocN tc) pprTypeDoesNotHaveFixedRuntimeRep :: Type -> FixedRuntimeRepProvenance -> SDoc pprTypeDoesNotHaveFixedRuntimeRep ty prov = diff --git a/compiler/GHC/Tc/Gen/Bind.hs b/compiler/GHC/Tc/Gen/Bind.hs index 10e665051d..543bb2f472 100644 --- a/compiler/GHC/Tc/Gen/Bind.hs +++ b/compiler/GHC/Tc/Gen/Bind.hs @@ -211,7 +211,7 @@ tcCompleteSigs sigs = -- compatible with the result type constructor 'mb_tc'. doOne (L loc c@(CompleteMatchSig (_ext, _src_txt) (L _ ns) mb_tc_nm)) = fmap Just $ setSrcSpanA loc $ addErrCtxt (text "In" <+> ppr c) $ do - cls <- mkUniqDSet <$> mapM (addLocMA tcLookupConLike) ns + cls <- mkUniqDSet <$> mapM (addLocMN tcLookupConLike) ns mb_tc <- traverse @Maybe tcLookupLocatedTyCon mb_tc_nm pure CompleteMatch { cmConLikes = cls, cmResultTyCon = mb_tc } doOne _ = return Nothing @@ -601,7 +601,7 @@ tcPolyCheck prag_fn , fun_matches = matches })) = do { traceTc "tcPolyCheck" (ppr poly_id $$ ppr sig_loc) - ; mono_name <- newNameAt (nameOccName name) (locA nm_loc) + ; mono_name <- newNameAt (nameOccName name) (locN nm_loc) ; (wrap_gen, (wrap_res, matches')) <- setSrcSpan sig_loc $ -- Sets the binding location for the skolems tcSkolemiseScoped ctxt (idType poly_id) $ \rho_ty -> @@ -631,7 +631,7 @@ tcPolyCheck prag_fn ; poly_id <- addInlinePrags poly_id prag_sigs ; mod <- getModule - ; tick <- funBindTicks (locA nm_loc) poly_id mod prag_sigs + ; tick <- funBindTicks (locN nm_loc) poly_id mod prag_sigs ; let bind' = FunBind { fun_id = L nm_loc poly_id2 , fun_matches = matches' @@ -1437,7 +1437,7 @@ tcLhs sig_fn no_gen (FunBind { fun_id = L nm_loc name -- Just g = ...f... -- Hence always typechecked with InferGen do { mono_info <- tcLhsSigId no_gen (name, sig) - ; return (TcFunBind mono_info (locA nm_loc) matches) } + ; return (TcFunBind mono_info (locN nm_loc) matches) } | otherwise -- No type signature = do { mono_ty <- newOpenFlexiTyVarTy @@ -1448,7 +1448,7 @@ tcLhs sig_fn no_gen (FunBind { fun_id = L nm_loc name ; let mono_info = MBI { mbi_poly_name = name , mbi_sig = Nothing , mbi_mono_id = mono_id } - ; return (TcFunBind mono_info (locA nm_loc) matches) } + ; return (TcFunBind mono_info (locN nm_loc) matches) } tcLhs sig_fn no_gen (PatBind { pat_lhs = pat, pat_rhs = grhss }) = -- See Note [Typechecking pattern bindings] @@ -1524,9 +1524,9 @@ tcRhs (TcFunBind info@(MBI { mbi_sig = mb_sig, mbi_mono_id = mono_id }) = tcExtendIdBinderStackForRhs [info] $ tcExtendTyVarEnvForRhs mb_sig $ do { traceTc "tcRhs: fun bind" (ppr mono_id $$ ppr (idType mono_id)) - ; (co_fn, matches') <- tcMatchesFun (L (noAnnSrcSpan loc) mono_id) + ; (co_fn, matches') <- tcMatchesFun (L (noAnnSrcSpanN loc) mono_id) matches (mkCheckExpType $ idType mono_id) - ; return ( FunBind { fun_id = L (noAnnSrcSpan loc) mono_id + ; return ( FunBind { fun_id = L (noAnnSrcSpanN loc) mono_id , fun_matches = matches' , fun_ext = (co_fn, []) } ) } diff --git a/compiler/GHC/Tc/Gen/Export.hs b/compiler/GHC/Tc/Gen/Export.hs index d42ee046b5..10830b9cd5 100644 --- a/compiler/GHC/Tc/Gen/Export.hs +++ b/compiler/GHC/Tc/Gen/Export.hs @@ -190,7 +190,7 @@ rnExports explicit_mod exports | explicit_mod = exports | has_main = Just (noLocA [noLocA (IEVar noExtField - (noLocA (IEName noExtField $ noLocA default_main)))]) + (noLocA (IEName noExtField $ noLocN default_main)))]) -- ToDo: the 'noLoc' here is unhelpful if 'main' -- turns out to be out of scope | otherwise = Nothing diff --git a/compiler/GHC/Tc/Gen/Expr.hs b/compiler/GHC/Tc/Gen/Expr.hs index c2a680b3d4..aaf5a4ced7 100644 --- a/compiler/GHC/Tc/Gen/Expr.hs +++ b/compiler/GHC/Tc/Gen/Expr.hs @@ -255,7 +255,7 @@ tcExpr e@(HsIPVar _ x) res_ty ; ipClass <- tcLookupClass ipClassName ; ip_var <- emitWantedEvVar origin (mkClassPred ipClass [ip_name, ip_ty]) ; tcWrapResult e - (fromDict ipClass ip_name ip_ty (HsVar noExtField (noLocA ip_var))) + (fromDict ipClass ip_name ip_ty (HsVar noExtField (noLocN ip_var))) ip_ty res_ty } where -- Coerces a dictionary for `IP "x" t` into `t`. @@ -1520,7 +1520,7 @@ disambiguateRecordBinds record_expr record_rho rbnds res_ty ; return $ L l HsFieldBind { hfbAnn = hfbAnn upd , hfbLHS - = L (l2l loc) (Unambiguous i (L (l2l loc) lbl)) + = L (l2l loc) (Unambiguous i (L (l2ln loc) lbl)) , hfbRHS = hfbRHS upd , hfbPun = hfbPun upd } diff --git a/compiler/GHC/Tc/Gen/Foreign.hs b/compiler/GHC/Tc/Gen/Foreign.hs index b8899e2431..570e580b59 100644 --- a/compiler/GHC/Tc/Gen/Foreign.hs +++ b/compiler/GHC/Tc/Gen/Foreign.hs @@ -402,7 +402,7 @@ tcFExport fo@(ForeignExport { fd_name = L loc nm, fd_sig_ty = hs_ty, fd_fe = spe -- We need to give a name to the new top-level binding that -- is *stable* (i.e. the compiler won't change it later), -- because this name will be referred to by the C code stub. - id <- mkStableIdFromName nm sig_ty (locA loc) mkForeignExportOcc + id <- mkStableIdFromName nm sig_ty (locN loc) mkForeignExportOcc return ( mkVarBind id rhs , ForeignExport { fd_name = L loc id , fd_sig_ty = undefined diff --git a/compiler/GHC/Tc/Gen/Head.hs b/compiler/GHC/Tc/Gen/Head.hs index b01c7ccb5d..83e0e51b81 100644 --- a/compiler/GHC/Tc/Gen/Head.hs +++ b/compiler/GHC/Tc/Gen/Head.hs @@ -1007,11 +1007,11 @@ tcInferOverLit lit@(OverLit { ol_val = val (1, []) from_ty ; co <- unifyType mb_thing (hsLitType hs_lit) (scaledThing sarg_ty) - ; let lit_expr = L (l2l loc) $ mkHsWrapCo co $ + ; let lit_expr = L (nn2la loc) $ mkHsWrapCo co $ HsLit noAnn hs_lit from_expr = mkHsWrap (wrap2 <.> wrap1) $ HsVar noExtField (L loc from_id) - witness = HsApp noAnn (L (l2l loc) from_expr) lit_expr + witness = HsApp noAnn (L (nn2la loc) from_expr) lit_expr lit' = lit { ol_ext = OverLitTc { ol_rebindable = rebindable , ol_witness = witness , ol_type = res_ty } } @@ -1030,7 +1030,7 @@ tcCheckId name res_ty ; addFunResCtxt rn_fun [] actual_res_ty res_ty $ tcWrapResultO (OccurrenceOf name) rn_fun expr actual_res_ty res_ty } where - rn_fun = HsVar noExtField (noLocA name) + rn_fun = HsVar noExtField (noLocN name) ------------------------ tcInferId :: Name -> TcM (HsExpr GhcTc, TcSigmaType) @@ -1055,7 +1055,7 @@ tc_infer_assert assert_name = do { assert_error_id <- tcLookupId assertErrorName ; (wrap, id_rho) <- topInstantiate (OccurrenceOf assert_name) (idType assert_error_id) - ; return (mkHsWrap wrap (HsVar noExtField (noLocA assert_error_id)), id_rho) + ; return (mkHsWrap wrap (HsVar noExtField (noLocN assert_error_id)), id_rho) } tc_infer_id :: Name -> TcM (HsExpr GhcTc, TcSigmaType) @@ -1113,7 +1113,7 @@ tc_infer_id id_name return $ unknownNameSuggestions WL_Anything dflags hpt curr_mod rdr_env lcl_env imp_info (mkRdrUnqual occ) - return_id id = return (HsVar noExtField (noLocA id), idType id) + return_id id = return (HsVar noExtField (noLocN id), idType id) check_local_id :: Id -> TcM () check_local_id id @@ -1324,7 +1324,7 @@ checkCrossStageLifting top_lvl id (Brack _ (TcPending ps_var lie_var q)) ; lift <- if isStringTy id_ty then do { sid <- tcLookupId GHC.Builtin.Names.TH.liftStringName -- See Note [Lifting strings] - ; return (HsVar noExtField (noLocA sid)) } + ; return (HsVar noExtField (noLocN sid)) } else setConstraintVar lie_var $ -- Put the 'lift' constraint into the right LIE diff --git a/compiler/GHC/Tc/Gen/HsType.hs b/compiler/GHC/Tc/Gen/HsType.hs index 19ea11f2d4..21c542c6c0 100644 --- a/compiler/GHC/Tc/Gen/HsType.hs +++ b/compiler/GHC/Tc/Gen/HsType.hs @@ -759,7 +759,7 @@ tcFamTyPats fam_tc hs_pats where fam_name = tyConName fam_tc fam_arity = tyConArity fam_tc - lhs_fun = noLocA (HsTyVar noAnn NotPromoted (noLocA fam_name)) + lhs_fun = noLocA (HsTyVar noAnn NotPromoted (noLocN fam_name)) {- Note [tcFamTyPats: zonking the result kind] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1516,7 +1516,7 @@ splitHsAppTys hs_ty go (L _ (HsAppKindTy l ty k)) as = go ty (HsTypeArg l k : as) go (L sp (HsParTy _ f)) as = go f (HsArgPar (locA sp) : as) go (L _ (HsOpTy _ prom l op@(L sp _) r)) as - = ( L (na2la sp) (HsTyVar noAnn prom op) + = ( L (nn2la sp) (HsTyVar noAnn prom op) , HsValArg l : HsValArg r : as ) go f as = (f, as) diff --git a/compiler/GHC/Tc/Gen/Pat.hs b/compiler/GHC/Tc/Gen/Pat.hs index c82a6ac1b5..01695e75ee 100644 --- a/compiler/GHC/Tc/Gen/Pat.hs +++ b/compiler/GHC/Tc/Gen/Pat.hs @@ -406,7 +406,7 @@ tc_pat pat_ty penv ps_pat thing_inside = case ps_pat of AsPat x (L nm_loc name) at pat -> do { mult_wrap <- checkManyPattern pat_ty -- See Note [Wrapper returned from tcSubMult] in GHC.Tc.Utils.Unify. - ; (wrap, bndr_id) <- setSrcSpanA nm_loc (tcPatBndr penv name pat_ty) + ; (wrap, bndr_id) <- setSrcSpanN nm_loc (tcPatBndr penv name pat_ty) ; (pat', res) <- tcExtendIdEnv1 name bndr_id $ tc_lpat (pat_ty `scaledSet`(mkCheckExpType $ idType bndr_id)) penv pat thing_inside @@ -653,7 +653,7 @@ AST is used for the subtraction operation. <- tcSyntaxOpGen orig minus [SynType pat_exp_ty, SynRho] SynAny $ \ [lit2_ty, var_ty] _ -> do { lit2' <- newOverloadedLit lit (mkCheckExpType lit2_ty) - ; (wrap, bndr_id) <- setSrcSpanA nm_loc $ + ; (wrap, bndr_id) <- setSrcSpanN nm_loc $ tcPatBndr penv name (unrestricted $ mkCheckExpType var_ty) -- co :: var_ty ~ idType bndr_id @@ -898,7 +898,7 @@ tcDataConPat penv (L con_span con_name) data_con pat_ty_scaled ; pat_ty <- readExpType (scaledThing pat_ty_scaled) -- Add the stupid theta - ; setSrcSpanA con_span $ addDataConStupidTheta data_con ctxt_res_tys + ; setSrcSpanN con_span $ addDataConStupidTheta data_con ctxt_res_tys -- Check that this isn't a GADT pattern match -- in situations in which that isn't allowed. diff --git a/compiler/GHC/Tc/Gen/Rule.hs b/compiler/GHC/Tc/Gen/Rule.hs index 38572d7341..8e8914a55f 100644 --- a/compiler/GHC/Tc/Gen/Rule.hs +++ b/compiler/GHC/Tc/Gen/Rule.hs @@ -182,7 +182,7 @@ tcRule (HsRule { rd_ext = ext , rd_name = rname , rd_act = act , rd_tyvs = ty_bndrs -- preserved for ppr-ing - , rd_tmvs = map (noLocA . RuleBndr noAnn . noLocA) + , rd_tmvs = map (noLocA . RuleBndr noAnn . noLocN) (qtkvs ++ tpl_ids) , rd_lhs = mkHsDictLet lhs_binds lhs' , rd_rhs = mkHsDictLet rhs_binds rhs' } } diff --git a/compiler/GHC/Tc/Gen/Splice.hs b/compiler/GHC/Tc/Gen/Splice.hs index c856523f4f..f15a275617 100644 --- a/compiler/GHC/Tc/Gen/Splice.hs +++ b/compiler/GHC/Tc/Gen/Splice.hs @@ -1008,7 +1008,7 @@ runAnnotation target expr = do ; let loc' = noAnnSrcSpan loc ; let specialised_to_annotation_wrapper_expr = L loc' (mkHsWrap wrapper - (HsVar noExtField (L (noAnnSrcSpan loc) to_annotation_wrapper_id))) + (HsVar noExtField (L (noAnnSrcSpanN loc) to_annotation_wrapper_id))) ; return (L loc' (HsApp noComments specialised_to_annotation_wrapper_expr expr')) }) diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index a38977b91e..ebd2ff8fad 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -1911,7 +1911,7 @@ generateMainBinding tcg_env main_name = do { traceTc "checkMain found" (ppr main_name) ; (io_ty, res_ty) <- getIOType ; let loc = getSrcSpan main_name - main_expr_rn = L (noAnnSrcSpan loc) (HsVar noExtField (L (noAnnSrcSpan loc) main_name)) + main_expr_rn = L (noAnnSrcSpan loc) (HsVar noExtField (L (noAnnSrcSpanN loc) main_name)) ; (ev_binds, main_expr) <- setMainCtxt main_name io_ty $ tcCheckMonoExpr main_expr_rn io_ty @@ -2247,7 +2247,7 @@ tcUserStmt (L loc (BodyStmt _ expr _ _)) -- Don't try to typecheck if the renamer fails! ; ghciStep <- getGhciStepIO ; uniq <- newUnique - ; let loc' = noAnnSrcSpan $ locA loc + ; let loc' = noAnnSrcSpanN $ locA loc ; interPrintName <- getInteractivePrintName ; let fresh_it = itName uniq (locA loc) matches = [mkMatch (mkPrefixFunRhs (L loc' fresh_it)) [] rn_expr @@ -2842,7 +2842,7 @@ tcRnLookupRdrName :: HscEnv -> LocatedN RdrName -- ^ Find all the Names that this RdrName could mean, in GHCi tcRnLookupRdrName hsc_env (L loc rdr_name) = runTcInteractive hsc_env $ - setSrcSpanA loc $ + setSrcSpanN loc $ do { -- If the identifier is a constructor (begins with an -- upper-case letter), then we need to consider both -- constructor and type class identifiers. diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs index ac5e336e65..8bd807379c 100644 --- a/compiler/GHC/Tc/TyCl.hs +++ b/compiler/GHC/Tc/TyCl.hs @@ -4350,7 +4350,7 @@ checkFieldCompat fld con1 con2 res1 res2 fty1 fty2 checkValidDataCon :: DynFlags -> Bool -> TyCon -> DataCon -> TcM () checkValidDataCon dflags existential_ok tc con = setSrcSpan con_loc $ - addErrCtxt (dataConCtxt (NE.singleton (L (noAnnSrcSpan con_loc) con_name))) $ + addErrCtxt (dataConCtxt (NE.singleton (L (noAnnSrcSpanN con_loc) con_name))) $ do { let tc_tvs = tyConTyVars tc res_ty_tmpl = mkFamilyTyConApp tc (mkTyVarTys tc_tvs) arg_tys = dataConOrigArgTys con diff --git a/compiler/GHC/Tc/TyCl/Class.hs b/compiler/GHC/Tc/TyCl/Class.hs index 4cb0e9d2c0..405d2137bc 100644 --- a/compiler/GHC/Tc/TyCl/Class.hs +++ b/compiler/GHC/Tc/TyCl/Class.hs @@ -173,7 +173,7 @@ tcClassSigs clas sigs def_methods -> IOEnv (Env TcGblEnv TcLclEnv) [(Name, (SrcSpan, Type))] -- AZ temp tc_gen_sig (op_names, gen_hs_ty) = do { gen_op_ty <- tcClassSigType op_names gen_hs_ty - ; return [ (op_name, (locA loc, gen_op_ty)) + ; return [ (op_name, (locN loc, gen_op_ty)) | L loc op_name <- op_names ] } {- @@ -190,8 +190,8 @@ tcClassDecl2 :: LTyClDecl GhcRn -- The class declaration tcClassDecl2 (L _ (ClassDecl {tcdLName = class_name, tcdSigs = sigs, tcdMeths = default_binds})) = recoverM (return emptyLHsBinds) $ - setSrcSpan (getLocA class_name) $ - do { clas <- tcLookupLocatedClass (n2l class_name) + setSrcSpan (getLocN class_name) $ + do { clas <- tcLookupLocatedClass class_name -- We make a separate binding for each default method. -- At one time I used a single AbsBinds for all of them, thus @@ -391,7 +391,7 @@ findMethodBind sel_name binds prag_fn f bind@(L _ (FunBind { fun_id = L bndr_loc op_name })) | op_name == sel_name - = Just (bind, locA bndr_loc, prags) + = Just (bind, locN bndr_loc, prags) f _other = Nothing --------------------------- @@ -504,7 +504,7 @@ tcATDefault loc inst_subst defined_ats (ATI fam_tc defs) (tv', cv') = partition isTyVar tcv' tvs' = scopedSort tv' cvs' = scopedSort cv' - ; rep_tc_name <- newFamInstTyConName (L (noAnnSrcSpan loc) (tyConName fam_tc)) pat_tys' + ; rep_tc_name <- newFamInstTyConName (L (noAnnSrcSpanN loc) (tyConName fam_tc)) pat_tys' ; let axiom = mkSingleCoAxiom Nominal rep_tc_name tvs' [] cvs' fam_tc pat_tys' rhs' -- NB: no validity check. We check validity of default instances diff --git a/compiler/GHC/Tc/TyCl/Instance.hs b/compiler/GHC/Tc/TyCl/Instance.hs index 8b3c34aa83..02e8f93891 100644 --- a/compiler/GHC/Tc/TyCl/Instance.hs +++ b/compiler/GHC/Tc/TyCl/Instance.hs @@ -597,7 +597,7 @@ tcTyFamInstDecl mb_clsinfo (L loc decl@(TyFamInstDecl { tfid_eqn = eqn })) -- For some reason we don't have a location for the equation -- itself, so we make do with the location of family name ; co_ax_branch <- tcTyFamInstEqn fam_tc mb_clsinfo - (L (na2la $ getLoc fam_lname) eqn) + (L (nn2la $ getLoc fam_lname) eqn) -- (2) check for validity ; checkConsistentFamInst mb_clsinfo fam_tc co_ax_branch @@ -1371,7 +1371,7 @@ addDFunPrags dfun_id sc_meth_ids is_newtype = isNewTyCon clas_tc wrapId :: HsWrapper -> Id -> HsExpr GhcTc -wrapId wrapper id = mkHsWrap wrapper (HsVar noExtField (noLocA id)) +wrapId wrapper id = mkHsWrap wrapper (HsVar noExtField (noLocN id)) {- Note [Typechecking plan for instance declarations] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1889,7 +1889,7 @@ tcMethodBody clas tyvars dfun_ev_vars inst_tys mkMethIds clas tyvars dfun_ev_vars inst_tys sel_id - ; let lm_bind = meth_bind { fun_id = L (noAnnSrcSpan bndr_loc) + ; let lm_bind = meth_bind { fun_id = L (noAnnSrcSpanN bndr_loc) (idName local_meth_id) } -- Substitute the local_meth_name for the binder -- NB: the binding is always a FunBind @@ -2120,7 +2120,7 @@ mkDefMethBind loc dfun_id clas sel_id dm_name -- Copy the inline pragma (if any) from the default method -- to this version. Note [INLINE and default methods] - fn = noLocA (idName sel_id) + fn = noLocN (idName sel_id) visible_inst_tys = [ ty | (tcb, ty) <- tyConBinders (classTyCon clas) `zip` inst_tys , tyConBinderArgFlag tcb /= Inferred ] rhs = foldl' mk_vta (nlHsVar dm_name) visible_inst_tys diff --git a/compiler/GHC/Tc/TyCl/PatSyn.hs b/compiler/GHC/Tc/TyCl/PatSyn.hs index 2e9b3c1809..b86878dee6 100644 --- a/compiler/GHC/Tc/TyCl/PatSyn.hs +++ b/compiler/GHC/Tc/TyCl/PatSyn.hs @@ -786,7 +786,7 @@ tcPatSynMatcher (L loc ps_name) lpat prag_fn (univ_tvs, req_theta, req_ev_binds, req_dicts) (ex_tvs, ex_tys, prov_theta, prov_dicts) (args, arg_tys) pat_ty - = do { let loc' = locA loc + = do { let loc' = locN loc ; rr_name <- newNameAt (mkTyVarOcc "rep") loc' ; tv_name <- newNameAt (mkTyVarOcc "r") loc' ; let rr_tv = mkTyVar rr_name runtimeRepTy @@ -982,7 +982,7 @@ tcPatSynBuilderBind prag_fn (PSB { psb_id = ps_lname@(L loc ps_name) mk_mg :: LHsExpr GhcRn -> MatchGroup GhcRn (LHsExpr GhcRn) mk_mg body = mkMatchGroup Generated (noLocA [builder_match]) where - builder_args = [L (na2la loc) (VarPat noExtField (L loc n)) + builder_args = [L (nn2la loc) (VarPat noExtField (L loc n)) | L loc n <- args] builder_match = mkMatch (mkPrefixFunRhs ps_lname) builder_args body @@ -1039,7 +1039,7 @@ tcPatToExpr name args pat = go pat -> Either SDoc (HsExpr GhcRn) mkPrefixConExpr lcon@(L loc _) pats = do { exprs <- mapM go pats - ; let con = L (l2l loc) (HsVar noExtField lcon) + ; let con = L (nn2la loc) (HsVar noExtField lcon) ; return (unLoc $ mkHsApps con exprs) } diff --git a/compiler/GHC/Tc/TyCl/Utils.hs b/compiler/GHC/Tc/TyCl/Utils.hs index e071a7c7a2..5f5b2d3922 100644 --- a/compiler/GHC/Tc/TyCl/Utils.hs +++ b/compiler/GHC/Tc/TyCl/Utils.hs @@ -889,7 +889,7 @@ mkOneRecordSelector all_cons idDetails fl has_sel where loc = getSrcSpan sel_name loc' = noAnnSrcSpan loc - locn = noAnnSrcSpan loc + locn = noAnnSrcSpanN loc locc = noAnnSrcSpan loc lbl = flLabel fl sel_name = flSelector fl diff --git a/compiler/GHC/Tc/Utils/Env.hs b/compiler/GHC/Tc/Utils/Env.hs index 5f73a56724..450ccd1245 100644 --- a/compiler/GHC/Tc/Utils/Env.hs +++ b/compiler/GHC/Tc/Utils/Env.hs @@ -314,11 +314,11 @@ tcLookupAxiom name = do tcLookupLocatedGlobalId :: LocatedA Name -> TcM Id tcLookupLocatedGlobalId = addLocMA tcLookupId -tcLookupLocatedClass :: LocatedA Name -> TcM Class -tcLookupLocatedClass = addLocMA tcLookupClass +tcLookupLocatedClass :: LocatedN Name -> TcM Class +tcLookupLocatedClass = addLocMN tcLookupClass tcLookupLocatedTyCon :: LocatedN Name -> TcM TyCon -tcLookupLocatedTyCon = addLocMA tcLookupTyCon +tcLookupLocatedTyCon = addLocMN tcLookupTyCon -- Find the instance that exactly matches a type class application. The class arguments must be precisely -- the same as in the instance declaration (modulo renaming & casts). @@ -1082,11 +1082,11 @@ newDFunName clas tys loc ; newGlobalBinder mod dfun_occ loc } newFamInstTyConName :: LocatedN Name -> [Type] -> TcM Name -newFamInstTyConName (L loc name) tys = mk_fam_inst_name id (locA loc) name [tys] +newFamInstTyConName (L loc name) tys = mk_fam_inst_name id (locN loc) name [tys] newFamInstAxiomName :: LocatedN Name -> [[Type]] -> TcM Name newFamInstAxiomName (L loc name) branches - = mk_fam_inst_name mkInstTyCoOcc (locA loc) name branches + = mk_fam_inst_name mkInstTyCoOcc (locN loc) name branches mk_fam_inst_name :: (OccName -> OccName) -> SrcSpan -> Name -> [[Type]] -> TcM Name mk_fam_inst_name adaptOcc loc tc_name tyss diff --git a/compiler/GHC/Tc/Utils/Instantiate.hs b/compiler/GHC/Tc/Utils/Instantiate.hs index 6aa02e4788..0bf4350053 100644 --- a/compiler/GHC/Tc/Utils/Instantiate.hs +++ b/compiler/GHC/Tc/Utils/Instantiate.hs @@ -132,7 +132,7 @@ newMethodFromName origin name ty_args ; wrap <- assert (not (isForAllTy ty) && isSingleton theta) $ instCall origin ty_args theta - ; return (mkHsWrap wrap (HsVar noExtField (noLocA id))) } + ; return (mkHsWrap wrap (HsVar noExtField (noLocN id))) } {- ************************************************************************ diff --git a/compiler/GHC/Tc/Utils/Monad.hs b/compiler/GHC/Tc/Utils/Monad.hs index 272701b6c3..9f1626ef90 100644 --- a/compiler/GHC/Tc/Utils/Monad.hs +++ b/compiler/GHC/Tc/Utils/Monad.hs @@ -61,9 +61,10 @@ module GHC.Tc.Utils.Monad( addDependentFiles, -- * Error management - getSrcSpanM, setSrcSpan, setSrcSpanA, addLocM, addLocMA, inGeneratedCode, + getSrcSpanM, setSrcSpan, setSrcSpanA, setSrcSpanN, addLocM, addLocMA, addLocMN, + inGeneratedCode, wrapLocM, wrapLocAM, wrapLocFstM, wrapLocFstMA, wrapLocSndM, wrapLocSndMA, wrapLocM_, - wrapLocMA_,wrapLocMA, + wrapLocMA_, wrapLocMA, wrapLocMN, getErrsVar, setErrsVar, addErr, failWith, failAt, @@ -987,12 +988,18 @@ setSrcSpan loc@(UnhelpfulSpan _) thing_inside setSrcSpanA :: SrcSpanAnn' ann -> TcRn a -> TcRn a setSrcSpanA l = setSrcSpan (locA l) +setSrcSpanN :: EpAnnS ann -> TcRn a -> TcRn a +setSrcSpanN l = setSrcSpan (locN l) + addLocM :: (a -> TcM b) -> Located a -> TcM b addLocM fn (L loc a) = setSrcSpan loc $ fn a addLocMA :: (a -> TcM b) -> GenLocated (SrcSpanAnn' ann) a -> TcM b addLocMA fn (L loc a) = setSrcSpanA loc $ fn a +addLocMN :: (a -> TcM b) -> LocatedN a -> TcM b +addLocMN fn (L loc a) = setSrcSpanN loc $ fn a + wrapLocM :: (a -> TcM b) -> Located a -> TcM (Located b) wrapLocM fn (L loc a) = setSrcSpan loc $ do { b <- fn a ; return (L loc b) } @@ -1004,6 +1011,10 @@ wrapLocMA :: (a -> TcM b) -> GenLocated (SrcSpanAnn' ann) a -> TcRn (GenLocated wrapLocMA fn (L loc a) = setSrcSpanA loc $ do { b <- fn a ; return (L loc b) } +wrapLocMN :: (a -> TcM b) -> LocatedN a -> TcRn (LocatedN b) +wrapLocMN fn (L loc a) = setSrcSpanN loc $ do { b <- fn a + ; return (L loc b) } + wrapLocFstM :: (a -> TcM (b,c)) -> Located a -> TcM (Located b, c) wrapLocFstM fn (L loc a) = setSrcSpan loc $ do diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs index 47e8b5758c..e03ee6b7aa 100644 --- a/compiler/GHC/ThToHs.hs +++ b/compiler/GHC/ThToHs.hs @@ -135,12 +135,18 @@ setL loc = CvtM (\_ _ -> Right (loc, ())) returnLA :: e -> CvtM (LocatedAn ann e) returnLA x = CvtM (\_ loc -> Right (loc, L (noAnnSrcSpan loc) x)) +returnLN :: e -> CvtM (LocatedN e) +returnLN x = CvtM (\_ loc -> Right (loc, L (noAnnSrcSpanN loc) x)) + returnJustLA :: a -> CvtM (Maybe (LocatedA a)) returnJustLA = fmap Just . returnLA wrapParLA :: (LocatedAn ann a -> b) -> a -> CvtM b wrapParLA add_par x = CvtM (\_ loc -> Right (loc, add_par (L (noAnnSrcSpan loc) x))) +wrapParLN :: (LocatedN a -> b) -> a -> CvtM b +wrapParLN add_par x = CvtM (\_ loc -> Right (loc, add_par (L (noAnnSrcSpanN loc) x))) + wrapMsg :: (Show a, TH.Ppr a) => String -> a -> CvtM b -> CvtM b -- E.g wrapMsg "declaration" dec thing wrapMsg what item (CvtM m) @@ -163,7 +169,7 @@ wrapL (CvtM m) = CvtM $ \origin loc -> case m origin loc of wrapLN :: CvtM a -> CvtM (LocatedN a) wrapLN (CvtM m) = CvtM $ \origin loc -> case m origin loc of Left err -> Left err - Right (loc', v) -> Right (loc', L (noAnnSrcSpan loc) v) + Right (loc', v) -> Right (loc', L (noAnnSrcSpanN loc) v) wrapLA :: CvtM a -> CvtM (LocatedA a) wrapLA (CvtM m) = CvtM $ \origin loc -> case m origin loc of @@ -738,7 +744,7 @@ cvt_id_arg (i, str, ty) ; returnLA $ ConDeclField { cd_fld_ext = noAnn , cd_fld_names - = [L (l2l li) $ FieldOcc noExtField (L li i')] + = [L (nn2la li) $ FieldOcc noExtField (L li i')] , cd_fld_type = ty' , cd_fld_doc = Nothing} } @@ -888,10 +894,10 @@ cvtPragmaD (AnnP target exp) ModuleAnnotation -> return ModuleAnnProvenance TypeAnnotation n -> do n' <- tconName n - wrapParLA TypeAnnProvenance n' + wrapParLN TypeAnnProvenance n' ValueAnnotation n -> do n' <- vcName n - wrapParLA ValueAnnProvenance n' + wrapParLN ValueAnnProvenance n' ; returnJustLA $ Hs.AnnD noExtField $ HsAnnotation (noAnn, (SourceText "{-# ANN")) target' exp' } @@ -977,8 +983,8 @@ cvtImplicitParamBind n e = do cvtl :: TH.Exp -> CvtM (LHsExpr GhcPs) cvtl e = wrapLA (cvt e) where - cvt (VarE s) = do { s' <- vName s; wrapParLA (HsVar noExtField) s' } - cvt (ConE s) = do { s' <- cName s; wrapParLA (HsVar noExtField) s' } + cvt (VarE s) = do { s' <- vName s; wrapParLN (HsVar noExtField) s' } + cvt (ConE s) = do { s' <- cName s; wrapParLN (HsVar noExtField) s' } cvt (LitE l) | overloadedLit l = go cvtOverLit (HsOverLit noComments) (hsOverLitNeedsParens appPrec) @@ -1093,11 +1099,11 @@ cvtl e = wrapLA (cvt e) ; let pe = parenthesizeHsExpr sigPrec e' ; return $ ExprWithTySig noAnn pe (mkHsWildCardBndrs t') } cvt (RecConE c flds) = do { c' <- cNameN c - ; flds' <- mapM (cvtFld (wrapParLA mkFieldOcc)) flds + ; flds' <- mapM (cvtFld (wrapParLN mkFieldOcc)) flds ; return $ mkRdrRecordCon c' (HsRecFields flds' Nothing) noAnn } cvt (RecUpdE e flds) = do { e' <- cvtl e ; flds' - <- mapM (cvtFld (wrapParLA mkAmbiguousFieldOcc)) + <- mapM (cvtFld (wrapParLN mkAmbiguousFieldOcc)) flds ; return $ RecordUpd noAnn e' (Left flds') } cvt (StaticE e) = fmap (HsStatic noAnn) $ cvtl e @@ -1105,14 +1111,14 @@ cvtl e = wrapLA (cvt e) -- important, because UnboundVarE may contain -- constructor names - see #14627. { s' <- vcName s - ; wrapParLA (HsVar noExtField) s' } + ; wrapParLN (HsVar noExtField) s' } cvt (LabelE s) = return $ HsOverLabel noComments (fsLit s) cvt (ImplicitParamVarE n) = do { n' <- ipName n; return $ HsIPVar noComments n' } cvt (GetFieldE exp f) = do { e' <- cvtl exp ; return $ HsGetField noComments e' - (L noSrcSpanA (DotFieldOcc noAnn (L noSrcSpanA (FieldLabelString (fsLit f))))) } + (L noSrcSpanA (DotFieldOcc noAnn (L noSrcSpanN (FieldLabelString (fsLit f))))) } cvt (ProjectionE xs) = return $ HsProjection noAnn $ fmap - (L noSrcSpanA . DotFieldOcc noAnn . L noSrcSpanA . FieldLabelString . fsLit) xs + (L noSrcSpanA . DotFieldOcc noAnn . L noSrcSpanN . FieldLabelString . fsLit) xs {- | #16895 Ensure an infix expression's operator is a variable/constructor. Consider this example: @@ -1376,7 +1382,7 @@ cvtp (TH.LitP l) -- need to think about that! | otherwise = do { l' <- cvtLit l; return $ Hs.LitPat noExtField l' } cvtp (TH.VarP s) = do { s' <- vName s - ; wrapParLA (Hs.VarPat noExtField) s' } + ; wrapParLN (Hs.VarPat noExtField) s' } cvtp (TupP ps) = do { ps' <- cvtPats ps ; return $ TuplePat noAnn ps' Boxed } cvtp (UnboxedTupP ps) = do { ps' <- cvtPats ps @@ -1438,7 +1444,7 @@ cvtPatFld (s,p) ; p' <- cvtPat p ; returnLA $ HsFieldBind { hfbAnn = noAnn , hfbLHS - = L (l2l ls) $ mkFieldOcc (L (l2l ls) s') + = L (nn2la ls) $ mkFieldOcc (L ls s') , hfbRHS = p' , hfbPun = False} } @@ -1557,14 +1563,14 @@ cvtTypeKind ty_str ty , normals `lengthIs` n -- Saturated -> returnLA (HsTupleTy noAnn HsBoxedOrConstraintTuple normals) | otherwise - -> do { tuple_tc <- returnLA $ getRdrName $ tupleTyCon Boxed n + -> do { tuple_tc <- returnLN $ getRdrName $ tupleTyCon Boxed n ; mk_apps (HsTyVar noAnn NotPromoted tuple_tc) tys' } UnboxedTupleT n | Just normals <- m_normals , normals `lengthIs` n -- Saturated -> returnLA (HsTupleTy noAnn HsUnboxedTuple normals) | otherwise - -> do { tuple_tc <- returnLA $ getRdrName $ tupleTyCon Unboxed n + -> do { tuple_tc <- returnLN $ getRdrName $ tupleTyCon Unboxed n ; mk_apps (HsTyVar noAnn NotPromoted tuple_tc) tys' } UnboxedSumT n | n < 2 @@ -1576,7 +1582,7 @@ cvtTypeKind ty_str ty , normals `lengthIs` n -- Saturated -> returnLA (HsSumTy noAnn normals) | otherwise - -> do { sum_tc <- returnLA $ getRdrName $ sumTyCon n + -> do { sum_tc <- returnLN $ getRdrName $ sumTyCon n ; mk_apps (HsTyVar noAnn NotPromoted sum_tc) tys' } ArrowT | Just normals <- m_normals @@ -1590,7 +1596,7 @@ cvtTypeKind ty_str ty let y'' = parenthesizeHsType sigPrec y' returnLA (HsFunTy noAnn (HsUnrestrictedArrow noHsUniTok) x'' y'') | otherwise - -> do { fun_tc <- returnLA $ getRdrName unrestrictedFunTyCon + -> do { fun_tc <- returnLN $ getRdrName unrestrictedFunTyCon ; mk_apps (HsTyVar noAnn NotPromoted fun_tc) tys' } MulArrowT | Just normals <- m_normals @@ -1605,21 +1611,21 @@ cvtTypeKind ty_str ty w'' = hsTypeToArrow w' returnLA (HsFunTy noAnn w'' x'' y'') | otherwise - -> do { fun_tc <- returnLA $ getRdrName funTyCon + -> do { fun_tc <- returnLN $ getRdrName funTyCon ; mk_apps (HsTyVar noAnn NotPromoted fun_tc) tys' } ListT | Just normals <- m_normals , [x'] <- normals -> returnLA (HsListTy noAnn x') | otherwise - -> do { list_tc <- returnLA $ getRdrName listTyCon + -> do { list_tc <- returnLN $ getRdrName listTyCon ; mk_apps (HsTyVar noAnn NotPromoted list_tc) tys' } VarT nm -> do { nm' <- tNameN nm ; mk_apps (HsTyVar noAnn NotPromoted nm') tys' } ConT nm -> do { nm' <- tconName nm ; let prom = name_promotedness nm' - ; lnm' <- returnLA nm' + ; lnm' <- returnLN nm' ; mk_apps (HsTyVar noAnn prom lnm') tys'} ForallT tvs cxt ty @@ -1661,7 +1667,7 @@ cvtTypeKind ty_str ty ; t1' <- cvtType t1 ; t2' <- cvtType t2 ; let prom = name_promotedness s' - ; ls' <- returnLA s' + ; ls' <- returnLN s' ; mk_apps (HsTyVar noAnn prom ls') ([HsValArg t1', HsValArg t2'] ++ tys') @@ -1705,7 +1711,7 @@ cvtTypeKind ty_str ty , normals `lengthIs` n -- Saturated -> returnLA (HsExplicitTupleTy noAnn normals) | otherwise - -> do { tuple_tc <- returnLA $ getRdrName $ tupleDataCon Boxed n + -> do { tuple_tc <- returnLN $ getRdrName $ tupleDataCon Boxed n ; mk_apps (HsTyVar noAnn IsPromoted tuple_tc) tys' } PromotedNilT @@ -1717,15 +1723,15 @@ cvtTypeKind ty_str ty , [ty1, L _ (HsExplicitListTy _ ip tys2)] <- normals -> returnLA (HsExplicitListTy noAnn ip (ty1:tys2)) | otherwise - -> do { cons_tc <- returnLA $ getRdrName consDataCon + -> do { cons_tc <- returnLN $ getRdrName consDataCon ; mk_apps (HsTyVar noAnn IsPromoted cons_tc) tys' } StarT - -> do { type_tc <- returnLA $ getRdrName liftedTypeKindTyCon + -> do { type_tc <- returnLN $ getRdrName liftedTypeKindTyCon ; mk_apps (HsTyVar noAnn NotPromoted type_tc) tys' } ConstraintT - -> do { constraint_tc <- returnLA $ getRdrName constraintKindTyCon + -> do { constraint_tc <- returnLN $ getRdrName constraintKindTyCon ; mk_apps (HsTyVar noAnn NotPromoted constraint_tc) tys' } EqualityT @@ -1733,14 +1739,14 @@ cvtTypeKind ty_str ty , [x',y'] <- normals -> let px = parenthesizeHsType opPrec x' py = parenthesizeHsType opPrec y' - in do { eq_tc <- returnLA eqTyCon_RDR + in do { eq_tc <- returnLN eqTyCon_RDR ; returnLA (HsOpTy noAnn NotPromoted px eq_tc py) } -- The long-term goal is to remove the above case entirely and -- subsume it under the case for InfixT. See #15815, comment:6, -- for more details. | otherwise -> - do { eq_tc <- returnLA eqTyCon_RDR + do { eq_tc <- returnLN eqTyCon_RDR ; mk_apps (HsTyVar noAnn NotPromoted eq_tc) tys' } ImplicitParamT n t -> do { n' <- wrapL $ ipName n diff --git a/ghc/GHCi/UI/Info.hs b/ghc/GHCi/UI/Info.hs index b2ec9a3101..25cc2e80bb 100644 --- a/ghc/GHCi/UI/Info.hs +++ b/ghc/GHCi/UI/Info.hs @@ -330,7 +330,7 @@ processAllTypeCheckedModule tcm -- | Extract 'Id', 'SrcSpan', and 'Type' for 'LHsBind's getTypeLHsBind :: LHsBind GhcTc -> Maybe (Maybe Id,SrcSpan,Type) getTypeLHsBind (L _spn FunBind{fun_id = pid,fun_matches = MG _ _}) - = Just (Just (unLoc pid), getLocA pid,varType (unLoc pid)) + = Just (Just (unLoc pid), getLocN pid,varType (unLoc pid)) getTypeLHsBind _ = Nothing -- | Extract 'Id', 'SrcSpan', and 'Type' for 'LHsExpr's diff --git a/utils/check-exact/ExactPrint.hs b/utils/check-exact/ExactPrint.hs index cfa50a9e3b..54606efd8f 100644 --- a/utils/check-exact/ExactPrint.hs +++ b/utils/check-exact/ExactPrint.hs @@ -231,6 +231,9 @@ instance HasEntry (EpAnn a) where fromAnn (EpAnn anchor _ cs) = mkEntry anchor cs fromAnn EpAnnNotUsed = NoEntryVal +instance HasEntry (EpAnnS a) where + fromAnn (EpAnnS anchor _ cs) = mkEntry anchor cs + -- --------------------------------------------------------------------- fromAnn' :: (HasEntry a) => a -> Entry @@ -4045,12 +4048,9 @@ instance ExactPrint (HsSigType GhcPs) where instance ExactPrint (LocatedN RdrName) where getAnnotationEntry (L sann _) = fromAnn sann - setAnnotationAnchor = setAnchorAn + setAnnotationAnchor = setAnchorAnN - exact x@(L (SrcSpanAnn EpAnnNotUsed l) n) = do - _ <- printUnicode (spanAsAnchor l) n - return x - exact (L (SrcSpanAnn (EpAnn anc ann cs) ll) n) = do + exact (L (EpAnnS anc ann cs) n) = do ann' <- case ann of NameAnn a o l c t -> do @@ -4092,7 +4092,7 @@ instance ExactPrint (LocatedN RdrName) where _anc' <- printUnicode anc n t' <- markTrailing t return (NameAnnTrailing t') - return (L (SrcSpanAnn (EpAnn anc ann' cs) ll) n) + return (L (EpAnnS anc ann' cs) n) locFromAdd :: AddEpAnn -> EpaLocation locFromAdd (AddEpAnn _ loc) = loc diff --git a/utils/check-exact/Main.hs b/utils/check-exact/Main.hs index 87921ac3e8..60e78255a2 100644 --- a/utils/check-exact/Main.hs +++ b/utils/check-exact/Main.hs @@ -417,7 +417,7 @@ rename newNameStr spans' a replaceRdr :: LocatedN RdrName -> LocatedN RdrName replaceRdr (L ln _) - | cond (locA ln) = L ln newName + | cond (locN ln) = L ln newName replaceRdr x = x -- --------------------------------------------------------------------- @@ -428,7 +428,7 @@ changeWhereIn4 _libdir parsed where replace :: LocatedN RdrName -> LocatedN RdrName replace (L ln _n) - | ss2range (locA ln) == ((12,16),(12,17)) = L ln (mkRdrUnqual (mkVarOcc "p_2")) + | ss2range (locN ln) == ((12,16),(12,17)) = L ln (mkRdrUnqual (mkVarOcc "p_2")) replace x = x -- --------------------------------------------------------------------- @@ -854,7 +854,7 @@ rmTypeSig1 _libdir lp = do let (s0:de1:d2) = tlDecs s1 = captureTypeSigSpacing s0 (L l (SigD x1 (TypeSig x2 [n1,n2] typ))) = s1 - n2' <- transferEntryDP n1 n2 + n2' <- transferEntryDPN n1 n2 let s1' = (L l (SigD x1 (TypeSig x2 [n2'] typ))) replaceDecls lp (s1':de1:d2) @@ -889,8 +889,8 @@ addHiding1 _libdir (L l p) = do l2 <- uniqueSrcSpanT let [L li imp1,imp2] = hsmodImports p - n1 = L (noAnnSrcSpanDP0 l1) (mkVarUnqual (mkFastString "n1")) - n2 = L (noAnnSrcSpanDP0 l2) (mkVarUnqual (mkFastString "n2")) + n1 = L (noAnnSrcSpanDP0N l1) (mkVarUnqual (mkFastString "n1")) + n2 = L (noAnnSrcSpanDP0N l2) (mkVarUnqual (mkFastString "n2")) v1 = L (addComma $ noAnnSrcSpanDP0 l1) (IEVar noExtField (L (noAnnSrcSpanDP0 l1) (IEName noExtField n1))) v2 = L ( noAnnSrcSpanDP0 l2) (IEVar noExtField (L (noAnnSrcSpanDP0 l2) (IEName noExtField n2))) impHiding = L (SrcSpanAnn (EpAnn (Anchor (realSrcSpan l0) m0) @@ -926,8 +926,8 @@ addHiding2 _libdir top = do [(AddEpAnn AnnHiding d1)] []) emptyComments) (locA lh)) - n1 = L (noAnnSrcSpanDP0 l1) (mkVarUnqual (mkFastString "n1")) - n2 = L (noAnnSrcSpanDP0 l2) (mkVarUnqual (mkFastString "n2")) + n1 = L (noAnnSrcSpanDP0N l1) (mkVarUnqual (mkFastString "n1")) + n2 = L (noAnnSrcSpanDP0N l2) (mkVarUnqual (mkFastString "n2")) v1 = L (addComma $ noAnnSrcSpanDP0 l1) (IEVar noExtField (L (noAnnSrcSpanDP0 l1) (IEName noExtField n1))) v2 = L ( noAnnSrcSpanDP0 l2) (IEVar noExtField (L (noAnnSrcSpanDP0 l2) (IEName noExtField n2))) L ln n = last ns diff --git a/utils/check-exact/Transform.hs b/utils/check-exact/Transform.hs index 797d089262..e6c06bd3ea 100644 --- a/utils/check-exact/Transform.hs +++ b/utils/check-exact/Transform.hs @@ -50,6 +50,7 @@ module Transform , noAnnSrcSpanDP0 , noAnnSrcSpanDP1 , noAnnSrcSpanDPn + , noAnnSrcSpanDP0N , d0, d1, dn , m0, m1, mn , addComma @@ -80,6 +81,7 @@ module Transform , setEntryDP , getEntryDP , transferEntryDP + , transferEntryDPN , transferEntryDP' , wrapSig, wrapDecl , decl2Sig, decl2Bind @@ -210,8 +212,7 @@ captureTypeSigSpacing (L l (SigD x (TypeSig (EpAnn anc (AnnSig dc rs') cs) ns (H -- AnnDColon, and to the start of the ty AddEpAnn kw dca = dc rd = case last ns of - L (SrcSpanAnn EpAnnNotUsed ll) _ -> realSrcSpan ll - L (SrcSpanAnn (EpAnn anc' _ _) _) _ -> anchor anc' -- TODO MovedAnchor? + L (EpAnnS anc' _ _) _ -> anchor anc' -- TODO MovedAnchor? dc' = case dca of EpaSpan r -> AddEpAnn kw (EpaDelta (ss2delta (ss2posEnd rd) r) []) EpaDelta _ _ -> AddEpAnn kw dca @@ -383,6 +384,14 @@ transferEntryDP (L (SrcSpanAnn EpAnnNotUsed _l1) _) (L (SrcSpanAnn (EpAnn anc2 a anc2' = case anc2 of Anchor _a op -> Anchor (realSrcSpan l2) op +transferEntryDPN :: (Monad m) + => LocatedN a -> LocatedN b -> TransformT m (LocatedN b) +transferEntryDPN (L (EpAnnS anca ana csa) a) (L (EpAnnS ancb anb csb) b) = do + r <- transferEntryDP (L (SrcSpanAnn (EpAnn anca ana csa) (spanFromAnchor anca)) a) + (L (SrcSpanAnn (EpAnn ancb anb csb) (spanFromAnchor ancb)) b) + case r of + L (SrcSpanAnn (EpAnn ancr annr csr) _) _ -> return (L (EpAnnS ancr annr csr) b) + _ -> error $ "Should not happen" -- |If a and b are the same type return first arg, else return second combine :: (Typeable a, Typeable b) => a -> b -> b @@ -772,9 +781,18 @@ noAnnSrcSpanDP :: (Monoid ann) => SrcSpan -> DeltaPos -> SrcSpanAnn' (EpAnn ann) noAnnSrcSpanDP l dp = SrcSpanAnn (EpAnn (Anchor (realSrcSpan l) (MovedAnchor dp)) mempty emptyComments) l +-- | Create a @SrcSpanAnn@ with a @MovedAnchor@ operation using the +-- given @DeltaPos@. +noAnnSrcSpanDPN :: (Monoid ann) => SrcSpan -> DeltaPos -> (EpAnnS ann) +noAnnSrcSpanDPN l dp + = (EpAnnS (Anchor (realSrcSpan l) (MovedAnchor dp)) mempty emptyComments) + noAnnSrcSpanDP0 :: (Monoid ann) => SrcSpan -> SrcSpanAnn' (EpAnn ann) noAnnSrcSpanDP0 l = noAnnSrcSpanDP l (SameLine 0) +noAnnSrcSpanDP0N :: (Monoid ann) => SrcSpan -> (EpAnnS ann) +noAnnSrcSpanDP0N l = noAnnSrcSpanDPN l (SameLine 0) + noAnnSrcSpanDP1 :: (Monoid ann) => SrcSpan -> SrcSpanAnn' (EpAnn ann) noAnnSrcSpanDP1 l = noAnnSrcSpanDP l (SameLine 1) diff --git a/utils/check-exact/Utils.hs b/utils/check-exact/Utils.hs index bad21d33a2..b79fb45c52 100644 --- a/utils/check-exact/Utils.hs +++ b/utils/check-exact/Utils.hs @@ -334,6 +334,9 @@ setAnchorAn (L (SrcSpanAnn (EpAnn _ an _) l) a) anc cs = (L (SrcSpanAnn (EpAnn anc an cs) l) a) -- `debug` ("setAnchorAn: anc=" ++ showAst anc) +setAnchorAnN :: LocatedN a -> Anchor -> EpAnnComments -> LocatedN a +setAnchorAnN (L (EpAnnS _ an _) a) anc cs = (L (EpAnnS anc an cs) a) + setAnchorEpa :: (Default an) => EpAnn an -> Anchor -> EpAnnComments -> EpAnn an setAnchorEpa EpAnnNotUsed anc cs = EpAnn anc Orphans.def cs setAnchorEpa (EpAnn _ an _) anc cs = EpAnn anc an cs diff --git a/utils/haddock b/utils/haddock -Subproject 644a4667f2dc9953f97b5783eddf1e5ad5c8f40 +Subproject df51e46138715b9c8f86acaf725ed50251b1326 |