@@ -1,6 +1,7 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE RecordWildCards #-}
4+{-# LANGUAGE TypeApplications #-}
45
56module Ormolu.Printer.Meat.Declaration.Value
67 ( p_valDecl,
@@ -65,12 +66,12 @@ data Placement
6566
6667p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
6768p_valDecl = \case
68− FunBind NoExt funId funMatches _ _ -> p_funBind funId funMatches
69− PatBind NoExt pat grhss _ -> p_match PatternBind False NoSrcStrict [pat] grhss
69+ FunBind NoExtField funId funMatches _ _ -> p_funBind funId funMatches
70+ PatBind NoExtField pat grhss _ -> p_match PatternBind False NoSrcStrict [pat] grhss
7071 VarBind {} -> notImplemented "VarBinds" -- introduced by the type checker
7172 AbsBinds {} -> notImplemented "AbsBinds" -- introduced by the type checker
72− PatSynBind NoExt psb -> p_patSynBind psb
73− XHsBindsLR NoExt -> notImplemented "XHsBindsLR"
73+ PatSynBind NoExtField psb -> p_patSynBind psb
74+ XHsBindsLR x -> noExtCon x
7475
7576p_funBind ::
7677 Located RdrName ->
@@ -114,8 +115,8 @@ p_matchGroup' placer render style MG {..} = do
114115 (matchStrictness m)
115116 m_pats
116117 m_grhss
117− p_Match _ = notImplemented "XMatch"
118−p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
118+ p_Match (XMatch x) = noExtCon x
119+p_matchGroup' _ _ _ (XMatchGroup x) = noExtCon x
119120
120121-- | Function id obtained through pattern matching on 'FunBind' should not
121122-- be used to print the actual equations because the different ‘RdrNames’
@@ -193,14 +194,14 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
193194 then id
194195 else inci
195196 switchLayout [combinedSpans] $ do
196− let stdCase = sep breakpoint p_pat m_pats
197+ let stdCase = sep breakpoint (located' p_pat) m_pats
197198 case style of
198199 Function name ->
199200 p_infixDefHelper
200201 isInfix
201202 inci'
202203 (p_rdrName name)
203− (p_pat <$> m_pats)
204+ (located' p_pat <$> m_pats)
204205 PatternBind -> stdCase
205206 Case -> stdCase
206207 Lambda -> do
@@ -266,7 +267,7 @@ p_match' placer render style isInfix strictness m_pats GRHSs {..} = do
266267 switchLayout [patGrhssSpan] $
267268 placeHanging placement p_body
268269 inci p_where
269−p_match' _ _ _ _ _ _ XGRHSs {} = notImplemented "XGRHSs"
270+p_match' _ _ _ _ _ _ (XGRHSs x) = noExtCon x
270271
271272p_grhs :: GroupStyle -> GRHS GhcPs (LHsExpr GhcPs) -> R ()
272273p_grhs = p_grhs' exprPlacement p_hsExpr
@@ -280,7 +281,7 @@ p_grhs' ::
280281 GroupStyle ->
281282 GRHS GhcPs (Located body) ->
282283 R ()
283−p_grhs' placer render style (GRHS NoExt guards body) =
284+p_grhs' placer render style (GRHS NoExtField guards body) =
284285 case guards of
285286 [] -> p_body
286287 xs -> do
@@ -305,11 +306,11 @@ p_grhs' placer render style (GRHS NoExt guards body) =
305306 Nothing -> Nothing
306307 Just gs -> (Just . srcSpanEnd . getLoc . NE.last) gs
307308 p_body = located body render
308−p_grhs' _ _ _ (XGRHS NoExt) = notImplemented "XGRHS"
309+p_grhs' _ _ _ (XGRHS x) = noExtCon x
309310
310311p_hsCmd :: HsCmd GhcPs -> R ()
311312p_hsCmd = \case
312− HsCmdArrApp NoExt body input arrType _ -> do
313+ HsCmdArrApp NoExtField body input arrType _ -> do
313314 located body p_hsExpr
314315 space
315316 case arrType of
@@ -317,42 +318,42 @@ p_hsCmd = \case
317318 HsHigherOrderApp -> txt "-<<"
318319 placeHanging (exprPlacement (unLoc input)) $
319320 located input p_hsExpr
320− HsCmdArrForm NoExt form Prefix _ cmds -> banana $ sitcc $ do
321+ HsCmdArrForm NoExtField form Prefix _ cmds -> banana $ sitcc $ do
321322 located form p_hsExpr
322323 unless (null cmds) $ do
323324 breakpoint
324325 inci (sequence_ (intersperse breakpoint (located' p_hsCmdTop <$> cmds)))
325− HsCmdArrForm NoExt form Infix _ [left, right] -> do
326+ HsCmdArrForm NoExtField form Infix _ [left, right] -> do
326327 located left p_hsCmdTop
327328 space
328329 located form p_hsExpr
329330 placeHanging (cmdTopPlacement (unLoc right)) $
330331 located right p_hsCmdTop
331− HsCmdArrForm NoExt _ Infix _ _ -> notImplemented "HsCmdArrForm"
332+ HsCmdArrForm NoExtField _ Infix _ _ -> notImplemented "HsCmdArrForm"
332333 HsCmdApp {} ->
333334 -- XXX Does this ever occur in the syntax tree? It does not seem like it
334335 -- does. Open an issue and ping @yumiova if this ever occurs in output.
335336 notImplemented "HsCmdApp"
336− HsCmdLam NoExt mgroup -> p_matchGroup' cmdPlacement p_hsCmd Lambda mgroup
337− HsCmdPar NoExt c -> parens N (located c p_hsCmd)
338− HsCmdCase NoExt e mgroup ->
337+ HsCmdLam NoExtField mgroup -> p_matchGroup' cmdPlacement p_hsCmd Lambda mgroup
338+ HsCmdPar NoExtField c -> parens N (located c p_hsCmd)
339+ HsCmdCase NoExtField e mgroup ->
339340 p_case cmdPlacement p_hsCmd e mgroup
340− HsCmdIf NoExt _ if' then' else' ->
341+ HsCmdIf NoExtField _ if' then' else' ->
341342 p_if cmdPlacement p_hsCmd if' then' else'
342− HsCmdLet NoExt localBinds c ->
343+ HsCmdLet NoExtField localBinds c ->
343344 p_let p_hsCmd localBinds c
344− HsCmdDo NoExt es -> do
345+ HsCmdDo NoExtField es -> do
345346 txt "do"
346347 newline
347348 inci . located es $
348349 sitcc . sep newline (located' (sitcc . p_stmt' cmdPlacement p_hsCmd))
349350 HsCmdWrap {} -> notImplemented "HsCmdWrap"
350− XCmd {} -> notImplemented "XCmd"
351+ XCmd x -> noExtCon x
351352
352353p_hsCmdTop :: HsCmdTop GhcPs -> R ()
353354p_hsCmdTop = \case
354− HsCmdTop NoExt cmd -> located cmd p_hsCmd
355− XCmdTop {} -> notImplemented "XHsCmdTop"
355+ HsCmdTop NoExtField cmd -> located cmd p_hsCmd
356+ XCmdTop x -> noExtCon x
356357
357358p_stmt :: Stmt GhcPs (LHsExpr GhcPs) -> R ()
358359p_stmt = p_stmt' exprPlacement p_hsExpr
@@ -367,16 +368,13 @@ p_stmt' ::
367368 Stmt GhcPs (Located body) ->
368369 R ()
369370p_stmt' placer render = \case
370− LastStmt NoExt body _ _ -> located body render
371− BindStmt NoExt p f _ _ -> do
372− p_pat p
371+ LastStmt NoExtField body _ _ -> located body render
372+ BindStmt NoExtField p f _ _ -> do
373+ located p p_pat
373374 space
374375 txt "<-"
375− -- https://gitlab.haskell.org/ghc/ghc/issues/17330
376− let loc = case p of
377− XPat pat -> getLoc pat
378− _ -> error "p_stmt': BindStmt: Pat does not contain a location"
379− let placement =
376+ let loc = getLoc p
377+ placement =
380378 case f of
381379 L l' x ->
382380 if isOneLineSpan
@@ -386,8 +384,8 @@ p_stmt' placer render = \case
386384 switchLayout [loc, getLoc f] $
387385 placeHanging placement (located f render)
388386 ApplicativeStmt {} -> notImplemented "ApplicativeStmt" -- generated by renamer
389− BodyStmt NoExt body _ _ -> located body render
390− LetStmt NoExt binds -> do
387+ BodyStmt NoExtField body _ _ -> located body render
388+ LetStmt NoExtField binds -> do
391389 txt "let"
392390 space
393391 sitcc $ located binds p_hsLocalBinds
@@ -429,10 +427,10 @@ p_stmt' placer render = \case
429427 txt "rec"
430428 space
431429 sitcc $ sepSemi (located' (p_stmt' placer render)) recS_stmts
432− XStmtLR {} -> notImplemented "XStmtLR"
430+ XStmtLR c -> noExtCon c
433431
434432gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
435−gatherStmt (L _ (ParStmt NoExt block _ _)) =
433+gatherStmt (L _ (ParStmt NoExtField block _ _)) =
436434 foldr ((<>) . gatherStmtBlock) [] block
437435gatherStmt (L s stmt@TransStmt {..}) =
438436 foldr liftAppend [] ((gatherStmt <$> trS_stmts) <> pure [[L s stmt]])
@@ -441,11 +439,11 @@ gatherStmt stmt = [[stmt]]
441439gatherStmtBlock :: ParStmtBlock GhcPs GhcPs -> [[ExprLStmt GhcPs]]
442440gatherStmtBlock (ParStmtBlock _ stmts _ _) =
443441 foldr (liftAppend . gatherStmt) [] stmts
444−gatherStmtBlock XParStmtBlock {} = notImplemented "XParStmtBlock"
442+gatherStmtBlock (XParStmtBlock x) = noExtCon x
445443
446444p_hsLocalBinds :: HsLocalBindsLR GhcPs GhcPs -> R ()
447445p_hsLocalBinds = \case
448− HsValBinds NoExt (ValBinds NoExt bag lsigs) -> do
446+ HsValBinds NoExtField (ValBinds NoExtField bag lsigs) -> do
449447 let ssStart =
450448 either
451449 (srcSpanStart . getLoc)
@@ -467,20 +465,23 @@ p_hsLocalBinds = \case
467465 sepSemi
468466 (\(m, i) -> (if m then br else id) $ p_item i)
469467 (markInit $ sortOn ssStart items)
470− HsValBinds NoExt _ -> notImplemented "HsValBinds"
471− HsIPBinds NoExt (IPBinds NoExt xs) ->
468+ HsValBinds NoExtField _ -> notImplemented "HsValBinds"
469+ HsIPBinds NoExtField (IPBinds NoExtField xs) ->
472470 -- Second argument of IPBind is always Left before type-checking.
473− let p_ipBind (IPBind NoExt (Left name) expr) = do
471+ let p_ipBind (IPBind NoExtField (Left name) expr) = do
474472 atom name
475473 space
476474 txt "="
477475 breakpoint
478476 useBraces $ inci $ located expr p_hsExpr
479− p_ipBind _ = notImplemented "XHsIPBinds"
477+ p_ipBind (IPBind NoExtField (Right _) _) =
478+ -- Should only occur after the type checker
479+ notImplemented "IPBind _ (Right _) _"
480+ p_ipBind (XIPBind x) = noExtCon x
480481 in sepSemi (located' p_ipBind) xs
481− HsIPBinds NoExt _ -> notImplemented "HsIpBinds"
482− EmptyLocalBinds NoExt -> return ()
483− XHsLocalBindsLR _ -> notImplemented "XHsLocalBindsLR"
482+ HsIPBinds NoExtField _ -> notImplemented "HsIpBinds"
483+ EmptyLocalBinds NoExtField -> return ()
484+ XHsLocalBindsLR x -> noExtCon x
484485
485486p_hsRecField ::
486487 HsRecField' RdrName (LHsExpr GhcPs) ->
@@ -495,42 +496,42 @@ p_hsRecField HsRecField {..} = do
495496
496497p_hsTupArg :: HsTupArg GhcPs -> R ()
497498p_hsTupArg = \case
498− Present NoExt x -> located x p_hsExpr
499− Missing NoExt -> pure ()
500− XTupArg {} -> notImplemented "XTupArg"
499+ Present NoExtField x -> located x p_hsExpr
500+ Missing NoExtField -> pure ()
501+ XTupArg x -> noExtCon x
501502
502503p_hsExpr :: HsExpr GhcPs -> R ()
503504p_hsExpr = p_hsExpr' N
504505
505506p_hsExpr' :: BracketStyle -> HsExpr GhcPs -> R ()
506507p_hsExpr' s = \case
507− HsVar NoExt name -> p_rdrName name
508− HsUnboundVar NoExt _ -> notImplemented "HsUnboundVar"
509− HsConLikeOut NoExt _ -> notImplemented "HsConLikeOut"
510− HsRecFld NoExt x ->
508+ HsVar NoExtField name -> p_rdrName name
509+ HsUnboundVar NoExtField v -> atom (unboundVarOcc v)
510+ HsConLikeOut NoExtField _ -> notImplemented "HsConLikeOut"
511+ HsRecFld NoExtField x ->
511512 case x of
512− Unambiguous NoExt name -> p_rdrName name
513− Ambiguous NoExt name -> p_rdrName name
514− XAmbiguousFieldOcc NoExt -> notImplemented "XAmbiguousFieldOcc"
515− HsOverLabel NoExt _ v -> do
513+ Unambiguous NoExtField name -> p_rdrName name
514+ Ambiguous NoExtField name -> p_rdrName name
515+ XAmbiguousFieldOcc xx -> noExtCon xx
516+ HsOverLabel NoExtField _ v -> do
516517 txt "#"
517518 atom v
518− HsIPVar NoExt (HsIPName name) -> do
519+ HsIPVar NoExtField (HsIPName name) -> do
519520 txt "?"
520521 atom name
521− HsOverLit NoExt v -> atom (ol_val v)
522− HsLit NoExt lit ->
522+ HsOverLit NoExtField v -> atom (ol_val v)
523+ HsLit NoExtField lit ->
523524 case lit of
524525 HsString (SourceText stxt) _ -> p_stringLit stxt
525526 HsStringPrim (SourceText stxt) _ -> p_stringLit stxt
526527 r -> atom r
527− HsLam NoExt mgroup ->
528+ HsLam NoExtField mgroup ->
528529 p_matchGroup Lambda mgroup
529− HsLamCase NoExt mgroup -> do
530+ HsLamCase NoExtField mgroup -> do
530531 txt "\\case"
531532 breakpoint
532533 inci (p_matchGroup LambdaCase mgroup)
533− HsApp NoExt f x -> do
534+ HsApp NoExtField f x -> do
534535 let -- In order to format function applications with multiple parameters
535536 -- nicer, traverse the AST to gather the function and all the
536537 -- parameters together.
@@ -564,9 +565,9 @@ p_hsExpr' s = \case
564565 -- expression is parenthesised.
565566 indent =
566567 case func of
567− L _ (HsPar NoExt _) -> inci
568− L _ (HsAppType NoExt _ _) -> inci
569− L _ (HsMultiIf NoExt _) -> inci
568+ L _ (HsPar NoExtField _) -> inci
569+ L _ (HsAppType NoExtField _ _) -> inci
570+ L _ (HsMultiIf NoExtField _) -> inci
570571 L spn _ ->
571572 if isOneLineSpan spn
572573 then inci
@@ -588,35 +589,35 @@ p_hsExpr' s = \case
588589 sep breakpoint (located' p_hsExpr) initp
589590 placeHanging placement $
590591 located lastp p_hsExpr
591− HsAppType NoExt e a -> do
592+ HsAppType NoExtField e a -> do
592593 located e p_hsExpr
593594 breakpoint
594595 inci $ do
595596 txt "@"
596597 located (hswc_body a) p_hsType
597− OpApp NoExt x op y -> do
598+ OpApp NoExtField x op y -> do
598599 let opTree = OpBranch (exprOpTree x) op (exprOpTree y)
599600 p_exprOpTree True s (reassociateOpTree getOpName opTree)
600− NegApp NoExt e _ -> do
601+ NegApp NoExtField e _ -> do
601602 txt "-"
602603 space
603604 located e p_hsExpr
604− HsPar NoExt e ->
605+ HsPar NoExtField e ->
605606 parens s (located e (dontUseBraces . p_hsExpr))
606− SectionL NoExt x op -> do
607+ SectionL NoExtField x op -> do
607608 located x p_hsExpr
608609 breakpoint
609610 inci (located op p_hsExpr)
610− SectionR NoExt op x -> do
611+ SectionR NoExtField op x -> do
611612 located op p_hsExpr
612613 useRecordDot' <- useRecordDot
613614 let isRecordDot' = isRecordDot (unLoc op) (getLoc x)
614615 unless (useRecordDot' && isRecordDot') breakpoint
615616 inci (located x p_hsExpr)
616− ExplicitTuple NoExt args boxity -> do
617+ ExplicitTuple NoExtField args boxity -> do
617618 let isSection = any (isMissing . unLoc) args
618619 isMissing = \case
619− Missing NoExt -> True
620+ Missing NoExtField -> True
620621 _ -> False
621622 let parens' =
622623 case boxity of
@@ -629,18 +630,18 @@ p_hsExpr' s = \case
629630 else
630631 switchLayout (getLoc <$> args) . parens' s . sitcc $
631632 sep (comma >> breakpoint) (sitcc . located' p_hsTupArg) args
632− ExplicitSum NoExt tag arity e ->
633+ ExplicitSum NoExtField tag arity e ->
633634 p_unboxedSum N tag arity (located e p_hsExpr)
634− HsCase NoExt e mgroup ->
635+ HsCase NoExtField e mgroup ->
635636 p_case exprPlacement p_hsExpr e mgroup
636− HsIf NoExt _ if' then' else' ->
637+ HsIf NoExtField _ if' then' else' ->
637638 p_if exprPlacement p_hsExpr if' then' else'
638− HsMultiIf NoExt guards -> do
639+ HsMultiIf NoExtField guards -> do
639640 txt "if "
640641 inci . inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
641− HsLet NoExt localBinds e ->
642+ HsLet NoExtField localBinds e ->
642643 p_let p_hsExpr localBinds e
643− HsDo NoExt ctx es -> do
644+ HsDo NoExtField ctx es -> do
644645 let doBody header = do
645646 txt header
646647 breakpoint
@@ -685,10 +686,10 @@ p_hsExpr' s = \case
685686 breakpoint
686687 let HsRecFields {..} = rcon_flds
687688 updName f =
688− f
689+ (f :: HsRecField GhcPs (LHsExpr GhcPs))
689690 { hsRecFieldLbl = case unLoc $ hsRecFieldLbl f of
690691 FieldOcc _ n -> n
691− XFieldOcc _ -> notImplemented "XFieldOcc"
692+ XFieldOcc x -> noExtCon x
692693 }
693694 fields = located' (p_hsRecField . updName) <$> rec_flds
694695 dotdot =
@@ -708,27 +709,26 @@ p_hsExpr' s = \case
708709 == (srcSpanStartCol <$> mrs (head rupd_flds))
709710 unless (useRecordDot' && isPluginForm) breakpoint
710711 let updName f =
711− f
712+ (f :: HsRecUpdField GhcPs)
712713 { hsRecFieldLbl = case unLoc $ hsRecFieldLbl f of
713714 Ambiguous _ n -> n
714715 Unambiguous _ n -> n
715− XAmbiguousFieldOcc _ -> notImplemented "XAmbiguousFieldOcc"
716+ XAmbiguousFieldOcc x -> noExtCon x
716717 }
717718 inci . braces N . sitcc $
718719 sep
719720 (comma >> breakpoint)
720721 (sitcc . located' (p_hsRecField . updName))
721722 rupd_flds
722− ExprWithTySig NoExt x HsWC {hswc_body = HsIB {..}} -> sitcc $ do
723+ ExprWithTySig NoExtField x HsWC {hswc_body = HsIB {..}} -> sitcc $ do
723724 located x p_hsExpr
724725 space
725726 txt "::"
726727 breakpoint
727728 inci $ located hsib_body p_hsType
728− ExprWithTySig NoExt _ HsWC {hswc_body = XHsImplicitBndrs {}} ->
729− notImplemented "XHsImplicitBndrs"
730− ExprWithTySig NoExt _ XHsWildCardBndrs {} -> notImplemented "XHsWildCardBndrs"
731− ArithSeq NoExt _ x ->
729+ ExprWithTySig NoExtField _ HsWC {hswc_body = XHsImplicitBndrs x} -> noExtCon x
730+ ExprWithTySig NoExtField _ (XHsWildCardBndrs x) -> noExtCon x
731+ ArithSeq NoExtField _ x ->
732732 case x of
733733 From from -> brackets s . sitcc $ do
734734 located from p_hsExpr
@@ -750,25 +750,25 @@ p_hsExpr' s = \case
750750 txt ".."
751751 space
752752 located to p_hsExpr
753− HsSCC NoExt _ name x -> do
753+ HsSCC NoExtField _ name x -> do
754754 txt "{-# SCC "
755755 atom name
756756 txt " #-}"
757757 breakpoint
758758 located x p_hsExpr
759− HsCoreAnn NoExt _ value x -> do
759+ HsCoreAnn NoExtField _ value x -> do
760760 txt "{-# CORE "
761761 atom value
762762 txt " #-}"
763763 breakpoint
764764 located x p_hsExpr
765− HsBracket NoExt x -> p_hsBracket x
765+ HsBracket NoExtField x -> p_hsBracket x
766766 HsRnBracketOut {} -> notImplemented "HsRnBracketOut"
767767 HsTcBracketOut {} -> notImplemented "HsTcBracketOut"
768− HsSpliceE NoExt splice -> p_hsSplice splice
769− HsProc NoExt p e -> do
768+ HsSpliceE NoExtField splice -> p_hsSplice splice
769+ HsProc NoExtField p e -> do
770770 txt "proc"
771− locatedPat p $ \x -> do
771+ located p $ \x -> do
772772 breakpoint
773773 inci (p_pat x)
774774 breakpoint
@@ -779,31 +779,11 @@ p_hsExpr' s = \case
779779 txt "static"
780780 breakpoint
781781 inci (located e p_hsExpr)
782− HsArrApp NoExt body input arrType cond ->
783− p_hsCmd (HsCmdArrApp NoExt body input arrType cond)
784− HsArrForm NoExt form mfixity cmds ->
785− p_hsCmd (HsCmdArrForm NoExt form Prefix mfixity cmds)
786782 HsTick {} -> notImplemented "HsTick"
787783 HsBinTick {} -> notImplemented "HsBinTick"
788784 HsTickPragma {} -> notImplemented "HsTickPragma"
789− -- These four constructs should never appear in correct programs.
790− -- See: https://github.com/tweag/ormolu/issues/343
791− EWildPat NoExt -> txt "_"
792− EAsPat NoExt n p -> do
793− p_rdrName n
794− txt "@"
795− located p p_hsExpr
796− EViewPat NoExt p e -> do
797− located p p_hsExpr
798− space
799− txt "->"
800− breakpoint
801− inci (located e p_hsExpr)
802− ELazyPat NoExt p -> do
803− txt "~"
804− located p p_hsExpr
805785 HsWrap {} -> notImplemented "HsWrap"
806− XExpr {} -> notImplemented "XExpr"
786+ XExpr x -> noExtCon x
807787
808788p_patSynBind :: PatSynBind GhcPs GhcPs -> R ()
809789p_patSynBind PSB {..} = do
@@ -813,15 +793,15 @@ p_patSynBind PSB {..} = do
813793 Unidirectional -> do
814794 txt "<-"
815795 breakpoint
816− p_pat psb_def
796+ located psb_def p_pat
817797 ImplicitBidirectional -> do
818798 txt "="
819799 breakpoint
820− p_pat psb_def
800+ located psb_def p_pat
821801 ExplicitBidirectional mgroup -> do
822802 txt "<-"
823803 breakpoint
824− p_pat psb_def
804+ located psb_def p_pat
825805 newline
826806 txt "where"
827807 newline
@@ -855,7 +835,7 @@ p_patSynBind PSB {..} = do
855835 space
856836 p_rdrName r
857837 inci rhs
858−p_patSynBind (XPatSynBind NoExt) = notImplemented "XPatSynBind"
838+p_patSynBind (XPatSynBind x) = noExtCon x
859839
860840p_case ::
861841 Data body =>
@@ -922,40 +902,37 @@ p_let render localBinds e = sitcc $ do
922902
923903p_pat :: Pat GhcPs -> R ()
924904p_pat = \case
925− -- Note: starting from GHC 8.8, 'LPat' == 'Pat'. Located 'Pat's are always
926− -- constructed with the 'XPat' constructor, containing a @Located Pat@.
927− XPat pat -> located pat p_pat
928− WildPat NoExt -> txt "_"
929− VarPat NoExt name -> p_rdrName name
930− LazyPat NoExt pat -> do
905+ WildPat NoExtField -> txt "_"
906+ VarPat NoExtField name -> p_rdrName name
907+ LazyPat NoExtField pat -> do
931908 txt "~"
932− p_pat pat
933− AsPat NoExt name pat -> do
909+ located pat p_pat
910+ AsPat NoExtField name pat -> do
934911 p_rdrName name
935912 txt "@"
936− p_pat pat
937− ParPat NoExt pat ->
938− locatedPat pat (parens S . p_pat)
939− BangPat NoExt pat -> do
913+ located pat p_pat
914+ ParPat NoExtField pat ->
915+ located pat (parens S . p_pat)
916+ BangPat NoExtField pat -> do
940917 txt "!"
941− p_pat pat
942− ListPat NoExt pats ->
943− brackets S . sitcc $ sep (comma >> breakpoint) p_pat pats
944− TuplePat NoExt pats boxing -> do
918+ located pat p_pat
919+ ListPat NoExtField pats ->
920+ brackets S . sitcc $ sep (comma >> breakpoint) (located' p_pat) pats
921+ TuplePat NoExtField pats boxing -> do
945922 let f =
946923 case boxing of
947924 Boxed -> parens S
948925 Unboxed -> parensHash S
949− f . sitcc $ sep (comma >> breakpoint) (sitcc . p_pat) pats
950− SumPat NoExt pat tag arity ->
951− p_unboxedSum S tag arity (p_pat pat)
926+ f . sitcc $ sep (comma >> breakpoint) (sitcc . located' p_pat) pats
927+ SumPat NoExtField pat tag arity ->
928+ p_unboxedSum S tag arity (located pat p_pat)
952929 ConPatIn pat details ->
953930 case details of
954931 PrefixCon xs -> sitcc $ do
955932 p_rdrName pat
956933 unless (null xs) $ do
957934 breakpoint
958− inci . sitcc $ sep breakpoint (sitcc . p_pat) xs
935+ inci . sitcc $ sep breakpoint (sitcc . located' p_pat) xs
959936 RecCon (HsRecFields fields dotdot) -> do
960937 p_rdrName pat
961938 breakpoint
@@ -965,36 +942,37 @@ p_pat = \case
965942 inci . braces N . sitcc . sep (comma >> breakpoint) f $
966943 case dotdot of
967944 Nothing -> Just <$> fields
968− Just n -> (Just <$> take n fields) ++ [Nothing]
945+ Just (L _ n) -> (Just <$> take n fields) ++ [Nothing]
969946 InfixCon l r -> do
970947 switchLayout [getLoc l, getLoc r] $ do
971− p_pat l
948+ located l p_pat
972949 breakpoint
973950 inci $ do
974951 p_rdrName pat
975952 space
976− p_pat r
953+ located r p_pat
977954 ConPatOut {} -> notImplemented "ConPatOut" -- presumably created by renamer?
978− ViewPat NoExt expr pat -> sitcc $ do
955+ ViewPat NoExtField expr pat -> sitcc $ do
979956 located expr p_hsExpr
980957 space
981958 txt "->"
982959 breakpoint
983− inci (p_pat pat)
984− SplicePat NoExt splice -> p_hsSplice splice
985− LitPat NoExt p -> atom p
986− NPat NoExt v _ _ -> located v (atom . ol_val)
987− NPlusKPat NoExt n k _ _ _ -> sitcc $ do
960+ inci (located pat p_pat)
961+ SplicePat NoExtField splice -> p_hsSplice splice
962+ LitPat NoExtField p -> atom p
963+ NPat NoExtField v _ _ -> located v (atom . ol_val)
964+ NPlusKPat NoExtField n k _ _ _ -> sitcc $ do
988965 p_rdrName n
989966 breakpoint
990967 inci $ do
991968 txt "+"
992969 space
993970 located k (atom . ol_val)
994− SigPat NoExt pat hswc -> do
995− p_pat pat
971+ SigPat NoExtField pat hswc -> do
972+ located pat p_pat
996973 p_typeAscription hswc
997974 CoPat {} -> notImplemented "CoPat" -- apparently created at some later stage
975+ XPat x -> noExtCon x
998976
999977p_pat_hsRecField :: HsRecField' (FieldOcc GhcPs) (LPat GhcPs) -> R ()
1000978p_pat_hsRecField HsRecField {..} = do
@@ -1004,7 +982,7 @@ p_pat_hsRecField HsRecField {..} = do
1004982 space
1005983 txt "="
1006984 breakpoint
1007− inci (p_pat hsRecFieldArg)
985+ inci (located hsRecFieldArg p_pat)
1008986
1009987p_unboxedSum :: BracketStyle -> ConTag -> Arity -> R () -> R ()
1010988p_unboxedSum s tag arity m = do
@@ -1025,9 +1003,9 @@ p_unboxedSum s tag arity m = do
10251003
10261004p_hsSplice :: HsSplice GhcPs -> R ()
10271005p_hsSplice = \case
1028− HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco
1029− HsUntypedSplice NoExt deco _ expr -> p_hsSpliceTH False expr deco
1030− HsQuasiQuote NoExt _ quoterName srcSpan str -> do
1006+ HsTypedSplice NoExtField deco _ expr -> p_hsSpliceTH True expr deco
1007+ HsUntypedSplice NoExtField deco _ expr -> p_hsSpliceTH False expr deco
1008+ HsQuasiQuote NoExtField _ quoterName srcSpan str -> do
10311009 txt "["
10321010 p_rdrName (L srcSpan quoterName)
10331011 txt "|"
@@ -1037,7 +1015,7 @@ p_hsSplice = \case
10371015 txt "|]"
10381016 HsSpliced {} -> notImplemented "HsSpliced"
10391017 HsSplicedT {} -> notImplemented "HsSplicedT"
1040− XSplice {} -> notImplemented "XSplice"
1018+ XSplice x -> noExtCon x
10411019
10421020p_hsSpliceTH ::
10431021 -- | Typed splice?
@@ -1061,17 +1039,17 @@ p_hsSpliceTH isTyped expr = \case
10611039
10621040p_hsBracket :: HsBracket GhcPs -> R ()
10631041p_hsBracket = \case
1064− ExpBr NoExt expr -> do
1042+ ExpBr NoExtField expr -> do
10651043 anns <- getEnclosingAnns
10661044 let name = case anns of
10671045 AnnOpenEQ : _ -> ""
10681046 _ -> "e"
10691047 quote name (located expr p_hsExpr)
1070− PatBr NoExt pat -> quote "p" (p_pat pat)
1071− DecBrL NoExt decls -> quote "d" (p_hsDecls Free decls)
1072− DecBrG NoExt _ -> notImplemented "DecBrG" -- result of renamer
1073− TypBr NoExt ty -> quote "t" (located ty p_hsType)
1074− VarBr NoExt isSingleQuote name -> do
1048+ PatBr NoExtField pat -> located pat (quote "p" . p_pat)
1049+ DecBrL NoExtField decls -> quote "d" (p_hsDecls Free decls)
1050+ DecBrG NoExtField _ -> notImplemented "DecBrG" -- result of renamer
1051+ TypBr NoExtField ty -> quote "t" (located ty p_hsType)
1052+ VarBr NoExtField isSingleQuote name -> do
10751053 txt (bool "''" "'" isSingleQuote)
10761054 -- HACK As you can see we use 'noLoc' here to be able to pass name into
10771055 -- 'p_rdrName' since the latter expects a "located" thing. The problem
@@ -1086,13 +1064,13 @@ p_hsBracket = \case
10861064 && not (doesNotNeedExtraParens name)
10871065 wrapper = if isOperator then parens N else id
10881066 wrapper $ p_rdrName (noLoc name)
1089− TExpBr NoExt expr -> do
1067+ TExpBr NoExtField expr -> do
10901068 txt "[||"
10911069 breakpoint'
10921070 located expr p_hsExpr
10931071 breakpoint'
10941072 txt "||]"
1095− XBracket {} -> notImplemented "XBracket"
1073+ XBracket x -> noExtCon x
10961074 where
10971075 quote :: Text -> R () -> R ()
10981076 quote name body = do
@@ -1171,9 +1149,9 @@ liftAppend (x : xs) [] = x : xs
11711149liftAppend (x : xs) (y : ys) = x <> y : liftAppend xs ys
11721150
11731151getGRHSSpan :: GRHS GhcPs (Located body) -> SrcSpan
1174−getGRHSSpan (GRHS NoExt guards body) =
1152+getGRHSSpan (GRHS NoExtField guards body) =
11751153 combineSrcSpans' $ getLoc body :| map getLoc guards
1176−getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
1154+getGRHSSpan (XGRHS x) = noExtCon x
11771155
11781156-- | Place a thing that may have a hanging form. This function handles how
11791157-- to separate it from preceding expressions and whether to bump indentation
@@ -1194,67 +1172,63 @@ blockPlacement ::
11941172 (body -> Placement) ->
11951173 [LGRHS GhcPs (Located body)] ->
11961174 Placement
1197−blockPlacement placer [L _ (GRHS NoExt _ (L _ x))] = placer x
1175+blockPlacement placer [L _ (GRHS NoExtField _ (L _ x))] = placer x
11981176blockPlacement _ _ = Normal
11991177
12001178-- | Check if given command has a hanging form.
12011179cmdPlacement :: HsCmd GhcPs -> Placement
12021180cmdPlacement = \case
1203− HsCmdLam NoExt _ -> Hanging
1204− HsCmdCase NoExt _ _ -> Hanging
1205− HsCmdDo NoExt _ -> Hanging
1181+ HsCmdLam NoExtField _ -> Hanging
1182+ HsCmdCase NoExtField _ _ -> Hanging
1183+ HsCmdDo NoExtField _ -> Hanging
12061184 _ -> Normal
12071185
12081186cmdTopPlacement :: HsCmdTop GhcPs -> Placement
12091187cmdTopPlacement = \case
1210− HsCmdTop NoExt (L _ x) -> cmdPlacement x
1211− XCmdTop {} -> notImplemented "XCmdTop"
1188+ HsCmdTop NoExtField (L _ x) -> cmdPlacement x
1189+ XCmdTop x -> noExtCon x
12121190
12131191-- | Check if given expression has a hanging form.
12141192exprPlacement :: HsExpr GhcPs -> Placement
12151193exprPlacement = \case
12161194 -- Only hang lambdas with single line parameter lists
1217− HsLam NoExt mg -> case mg of
1218− MG _ (L _ [L _ (Match NoExt _ (x : xs) _)]) _
1195+ HsLam NoExtField mg -> case mg of
1196+ MG _ (L _ [L _ (Match NoExtField _ (x : xs) _)]) _
12191197 | isOneLineSpan (combineSrcSpans' $ fmap getLoc (x :| xs)) ->
12201198 Hanging
12211199 _ -> Normal
1222− HsLamCase NoExt _ -> Hanging
1223− HsCase NoExt _ _ -> Hanging
1224− HsDo NoExt DoExpr _ -> Hanging
1225− HsDo NoExt MDoExpr _ -> Hanging
1200+ HsLamCase NoExtField _ -> Hanging
1201+ HsCase NoExtField _ _ -> Hanging
1202+ HsDo NoExtField DoExpr _ -> Hanging
1203+ HsDo NoExtField MDoExpr _ -> Hanging
12261204 -- If the rightmost expression in an operator chain is hanging, make the
12271205 -- whole block hanging; so that we can use the common @f = foo $ do@
12281206 -- style.
1229− OpApp NoExt _ _ y -> exprPlacement (unLoc y)
1207+ OpApp NoExtField _ _ y -> exprPlacement (unLoc y)
12301208 -- Same thing for function applications (usually with -XBlockArguments)
1231− HsApp NoExt _ y -> exprPlacement (unLoc y)
1232− HsProc NoExt p _ ->
1233− -- https://gitlab.haskell.org/ghc/ghc/issues/17330
1234− let loc = case p of
1235− XPat pat -> getLoc pat
1236− _ -> error "exprPlacement: HsProc: Pat does not contain a location"
1237− in -- Indentation breaks if pattern is longer than one line and left
1238− -- hanging. Consequently, only apply hanging when it is safe.
1239− if isOneLineSpan loc
1240− then Hanging
1241− else Normal
1209+ HsApp NoExtField _ y -> exprPlacement (unLoc y)
1210+ HsProc NoExtField p _ ->
1211+ -- Indentation breaks if pattern is longer than one line and left
1212+ -- hanging. Consequently, only apply hanging when it is safe.
1213+ if isOneLineSpan (getLoc p)
1214+ then Hanging
1215+ else Normal
12421216 _ -> Normal
12431217
12441218withGuards :: [LGRHS GhcPs (Located body)] -> Bool
12451219withGuards = any (checkOne . unLoc)
12461220 where
12471221 checkOne :: GRHS GhcPs (Located body) -> Bool
1248− checkOne (GRHS NoExt [] _) = False
1222+ checkOne (GRHS NoExtField [] _) = False
12491223 checkOne _ = True
12501224
12511225exprOpTree :: LHsExpr GhcPs -> OpTree (LHsExpr GhcPs) (LHsExpr GhcPs)
1252−exprOpTree (L _ (OpApp NoExt x op y)) = OpBranch (exprOpTree x) op (exprOpTree y)
1226+exprOpTree (L _ (OpApp NoExtField x op y)) = OpBranch (exprOpTree x) op (exprOpTree y)
12531227exprOpTree n = OpNode n
12541228
12551229getOpName :: HsExpr GhcPs -> Maybe RdrName
12561230getOpName = \case
1257− HsVar NoExt (L _ a) -> Just a
1231+ HsVar NoExtField (L _ a) -> Just a
12581232 _ -> Nothing
12591233
12601234p_exprOpTree ::
@@ -1276,8 +1250,10 @@ p_exprOpTree isDollarSpecial s (OpBranch x op y) = do
12761250 OpNode (L _ n) -> exprPlacement n
12771251 _ -> Normal
12781252 else Normal
1253+ -- Distinguish holes used in infix notation.
1254+ -- eg. '1 _foo 2' and '1 `_foo` 2'
12791255 opWrapper = case unLoc op of
1280− EWildPat NoExt -> backticks
1256+ HsUnboundVar NoExtField _ -> backticks
12811257 _ -> id
12821258 layout <- getLayout
12831259 let ub = case layout of
@@ -1332,7 +1308,7 @@ isRecordDot ::
13321308 SrcSpan ->
13331309 Bool
13341310isRecordDot op (RealSrcSpan ySpan) = case op of
1335− HsVar NoExt (L (RealSrcSpan opSpan) opName) ->
1311+ HsVar NoExtField (L (RealSrcSpan opSpan) opName) ->
13361312 isDot opName && (srcSpanEndCol opSpan == srcSpanStartCol ySpan)
13371313 _ -> False
13381314isRecordDot _ _ = False