[Git][ghc/ghc][master] EPA: Remove ListBanana / ListParens from AnnListBrackets
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 130286e3 by Alan Zimmerman at 2026-09-11T08:34:08-04:00 EPA: Remove ListBanana / ListParens from AnnListBrackets This is a step towards making AnnList only represent lists of items which can have either braces or layout. - - - - - 8 changed files: - compiler/GHC/Hs/Expr.hs - compiler/GHC/Hs/Pat.hs - compiler/GHC/Parser.y - compiler/GHC/Parser/Annotation.hs - compiler/GHC/Parser/PostProcess.hs - testsuite/tests/ghc-api/T25121_status.stdout - utils/check-exact/ExactPrint.hs - utils/check-exact/Utils.hs Changes: ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -294,7 +294,7 @@ type instance XDo GhcPs = (AnnList, EpaLocation) type instance XDo GhcRn = NoExtField type instance XDo GhcTc = Type -type instance XExplicitList GhcPs = AnnList +type instance XExplicitList GhcPs = (EpToken "[", EpToken "]") type instance XExplicitList GhcRn = NoExtField type instance XExplicitList GhcTc = Type -- GhcPs: ExplicitList includes all source-level @@ -1440,7 +1440,7 @@ type instance XCmdArrApp GhcPs = (IsUnicodeSyntax, EpaLocation) type instance XCmdArrApp GhcRn = NoExtField type instance XCmdArrApp GhcTc = Type -type instance XCmdArrForm GhcPs = AnnList +type instance XCmdArrForm GhcPs = (EpUniToken "(|" "⦇", EpUniToken "|)" "⦈") -- | fixity (filled in by the renamer), for forms that were converted from -- OpApp's by the renamer type instance XCmdArrForm GhcRn = Maybe Fixity ===================================== compiler/GHC/Hs/Pat.hs ===================================== @@ -104,7 +104,7 @@ type instance XBangPat GhcPs = EpToken "!" type instance XBangPat GhcRn = NoExtField type instance XBangPat GhcTc = NoExtField -type instance XListPat GhcPs = AnnList +type instance XListPat GhcPs = (EpToken "[", EpToken "]") -- After parsing, ListPat can refer to a built-in Haskell list pattern -- or an overloaded list pattern. type instance XListPat GhcRn = NoExtField ===================================== compiler/GHC/Parser.y ===================================== @@ -3282,7 +3282,7 @@ aexp2 :: { ECP } -- arrow notation extension | '(|' aexp cmdargs '|)' {% runPV (unECP $2) >>= \ $2 -> fmap ecpFromCmd $ - amsA' (sLL $1 $> $ HsCmdArrForm (AnnList (glRM $1) (ListBanana (epUniTok $1) (epUniTok $4)) []) $2 Prefix + amsA' (sLL $1 $> $ HsCmdArrForm (epUniTok $1, epUniTok $4) $2 Prefix (reverse $3)) } projection :: { Located (NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs))) } @@ -3414,9 +3414,9 @@ tup_tail :: { forall b. DisambECP b => PV [Either (EpAnn Bool) (LocatedA b)] } -- Never empty. list :: { forall b. DisambECP b => SrcSpan -> (EpaLocation, EpaLocation) -> PV (LocatedA b) } : texp { \loc (ao,ac) -> unECP $1 >>= \ $1 -> - mkHsExplicitListPV loc [$1] (AnnList Nothing (ListSquare (EpTok ao) (EpTok ac)) []) } + mkHsExplicitListPV loc [$1] (EpTok ao, EpTok ac) } | lexps { \loc (ao,ac) -> $1 >>= \ $1 -> - mkHsExplicitListPV loc (reverse $1) (AnnList Nothing (ListSquare (EpTok ao) (EpTok ac)) []) } + mkHsExplicitListPV loc (reverse $1) (EpTok ao, EpTok ac) } | texp '..' { \loc (ao,ac) -> unECP $1 >>= \ $1 -> amsA' (L loc $ ArithSeq (AnnArithSeq (EpTok ao) Nothing (epTok $2) (EpTok ac)) Nothing (From $1)) >>= ecpFromExp' } ===================================== compiler/GHC/Parser/Annotation.hs ===================================== @@ -519,10 +519,8 @@ data AnnList } deriving (Data,Eq) data AnnListBrackets - = ListParens (EpToken "(") (EpToken ")") - | ListBraces (EpToken "{") (EpToken "}") + = ListBraces (EpToken "{") (EpToken "}") | ListSquare (EpToken "[") (EpToken "]") - | ListBanana (EpUniToken "(|" "⦇") (EpUniToken "|)" "⦈") | ListNone deriving (Data,Eq) @@ -1094,10 +1092,8 @@ instance Outputable AnnList where = text "AnnList" <+> ppr l <+> ppr p <+> ppr s instance Outputable AnnListBrackets where - ppr (ListParens o c) = text "ListParens" <+> ppr o <+> ppr c ppr (ListBraces o c) = text "ListBraces" <+> ppr o <+> ppr c ppr (ListSquare o c) = text "ListSquare" <+> ppr o <+> ppr c - ppr (ListBanana o c) = text "ListBanana" <+> ppr o <+> ppr c ppr ListNone = text "ListNone" instance Outputable AnnCType where ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -1827,7 +1827,7 @@ class (b ~ (Body b) GhcPs, AnnoBody b) => DisambECP b where mkHsTySigPV :: SrcSpanAnnA -> LocatedA b -> LHsType GhcPs -> TokDcolon -> PV (LocatedA b) -- | Disambiguate "[a,b,c]" (list syntax) - mkHsExplicitListPV :: SrcSpan -> [LocatedA b] -> AnnList -> PV (LocatedA b) + mkHsExplicitListPV :: SrcSpan -> [LocatedA b] -> (EpToken "[", EpToken "]") -> PV (LocatedA b) -- | Disambiguate "$(...)" and "[quasi|...|]" (TH splices) mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (LocatedA b) -- | Disambiguate "f { a = b, ... }" syntax (record construction and record updates) ===================================== testsuite/tests/ghc-api/T25121_status.stdout ===================================== @@ -15,7 +15,7 @@ X(FunArr) match = NoExtField X(ExprWithTySig) match = EpUniToken "::" "\8759" X(UntypedSplice) match = NoExtField X(ExplicitList) mismatch - >>> AnnList + >>> ((EpToken "["),(EpToken "]")) <<< ((EpToken "'"),(EpToken "["),(EpToken "]")) X(ExplicitTuple) mismatch
AnnParen
===================================== utils/check-exact/ExactPrint.hs ===================================== @@ -764,18 +764,12 @@ markLensBracketsO' :: (Monad m, Monoid w) => a -> Lens a AnnListBrackets -> EP w m a markLensBracketsO' a l = case view l a of - ListParens o c -> do - o' <- markEpToken o - return (set l (ListParens o' c) a) ListBraces o c -> do o' <- markEpToken o return (set l (ListBraces o' c) a) ListSquare o c -> do o' <- markEpToken o return (set l (ListSquare o' c) a) - ListBanana o c -> do - o' <- markEpUniToken o - return (set l (ListBanana o' c) a) ListNone -> return (set l ListNone a) markLensBracketsC :: (Monad m, Monoid w) @@ -786,18 +780,12 @@ markLensBracketsC' :: (Monad m, Monoid w) => a -> Lens a AnnListBrackets -> EP w m a markLensBracketsC' a l = case view l a of - ListParens o c -> do - c' <- markEpToken c - return (set l (ListParens o c') a) ListBraces o c -> do c' <- markEpToken c return (set l (ListBraces o c') a) ListSquare o c -> do c' <- markEpToken c return (set l (ListSquare o c') a) - ListBanana o c -> do - c' <- markEpUniToken c - return (set l (ListBanana o c') a) ListNone -> return (set l ListNone a) -- ------------------------------------- @@ -2919,13 +2907,13 @@ instance ExactPrint (HsExpr GhcPs) where (an',l',stmts') <- exactDo (an,l) do_or_list_comp stmts return (HsDo (an',l') do_or_list_comp stmts') - exact (ExplicitList an es) = do + exact (ExplicitList (o,c) es) = do debugM $ "ExplicitList start" - an0 <- markLensBracketsO' an lal_brackets + o' <- markEpToken o es' <- mapM markAnnotated es - an1 <- markLensBracketsC' an0 lal_brackets + c' <- markEpToken c debugM $ "ExplicitList end" - return (ExplicitList an1 es') + return (ExplicitList (o',c') es') exact (RecordCon x con_id binds) = do con_id' <- markAnnotated con_id binds' <- markAnnotated binds @@ -3335,8 +3323,8 @@ instance ExactPrint (HsCmd GhcPs) where arr' <- markAnnotated arr return (HsCmdArrApp (isU, l') arr' arg' HsHigherOrderApp False) - exact (HsCmdArrForm an e fixity cs) = do - an0 <- markLensBracketsO' an lal_brackets + exact (HsCmdArrForm (o,c) e fixity cs) = do + o' <- markEpUniToken o (e',cs') <- case (fixity, cs) of (Infix, (arg1:argrest)) -> do arg1' <- markAnnotated arg1 @@ -3348,8 +3336,8 @@ instance ExactPrint (HsCmd GhcPs) where cs' <- mapM markAnnotated cs return (e', cs') (Infix, []) -> error "Not possible" - an1 <- markLensBracketsC' an0 lal_brackets - return (HsCmdArrForm an1 e' fixity cs') + c' <- markEpUniToken c + return (HsCmdArrForm (o',c') e' fixity cs') exact (HsCmdApp an e1 e2) = do e1' <- markAnnotated e1 @@ -4671,9 +4659,11 @@ instance ExactPrint (Pat GhcPs) where pat' <- markAnnotated pat return (BangPat an0 pat') - exact (ListPat an pats) = do - (an', pats') <- markAnnList' an (mapM markAnnotated pats) - return (ListPat an' pats') + exact (ListPat (os,cs) pats) = do + os' <- markEpToken os + pats' <- mapM markAnnotated pats + cs' <- markEpToken cs + return (ListPat (os',cs') pats') exact (TuplePat an pats boxity) = do an0 <- markOpeningParen an ===================================== utils/check-exact/Utils.hs ===================================== @@ -342,10 +342,8 @@ insertTopLevelCppComments (HsModule (XModulePs an lo mdeprec mbDoc) mmn mexports (xs',rest') = allocPreceding xs rest annListBracketsLocs :: AnnListBrackets -> (EpaLocation,EpaLocation) -annListBracketsLocs (ListParens o c) = (getEpTokenLoc o, getEpTokenLoc c) annListBracketsLocs (ListBraces o c) = (getEpTokenLoc o, getEpTokenLoc c) annListBracketsLocs (ListSquare o c) = (getEpTokenLoc o, getEpTokenLoc c) -annListBracketsLocs (ListBanana o c) = (getEpUniTokenLoc o, getEpUniTokenLoc c) annListBracketsLocs ListNone = (noAnn, noAnn) data SplitWhere = Before | After View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/130286e3913601edcee7aeb5d2d00772... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/130286e3913601edcee7aeb5d2d00772... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Marge Bot (@marge-bot)