    {-# LANGUAGE LambdaCase #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards #-}
    {-# LANGUAGE TypeFamilies #-}

    -- | Rendering of types.
    module Ormolu.Printer.Meat.Type
      ( p_hsType,
        hasDocStrings,
        p_hsContext,
        p_hsTyVarBndr,
        ForAllVisibility (..),
        p_forallBndrs,
        p_conDeclFields,
        p_lhsTypeArg,
        p_hsSigType,
        tyVarsToTyPats,
        hsOuterTyVarBndrsToHsType,
        lhsTypeToSigType,
      )
    where

    import GHC.Hs hiding (isPromoted)
    import GHC.Types.SourceText
    import GHC.Types.SrcLoc
    import GHC.Types.Var
    import Ormolu.Printer.Combinators
    import Ormolu.Printer.Meat.Common
    import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration.OpTree (p_tyOpTree, tyOpTree)
    import {-# SOURCE #-} Ormolu.Printer.Meat.Declaration.Value (p_hsUntypedSplice, p_stringLit)
    import Ormolu.Printer.Operators
    import Ormolu.Utils

    p_hsType :: HsType GhcPs -> R ()
    p_hsType :: HsType GhcPs -> R ()
    p_hsType HsType GhcPs
    t = Bool -> HsType GhcPs -> R ()
    p_hsType' (HsType GhcPs -> Bool
    hasDocStrings HsType GhcPs
    t) HsType GhcPs
    t

    p_hsType' :: Bool -> HsType GhcPs -> R ()
    p_hsType' :: Bool -> HsType GhcPs -> R ()
    p_hsType' Bool
    multilineArgs = \case
      HsForAllTy XForAllTy GhcPs
    _ HsForAllTelescope GhcPs
    tele XRec GhcPs (HsType GhcPs)
    t -> do
        case HsForAllTelescope GhcPs
    tele of
          HsForAllInvis XHsForAllInvis GhcPs
    _ [LHsTyVarBndr Specificity GhcPs]
    bndrs -> ForAllVisibility
    -> (HsTyVarBndr Specificity GhcPs -> R ())
    -> [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcPs)]
    -> R ()
    forall l a.
    HasSrcSpan l =>
    ForAllVisibility -> (a -> R ()) -> [GenLocated l a] -> R ()
    p_forallBndrs ForAllVisibility
    ForAllInvis HsTyVarBndr Specificity GhcPs -> R ()
    forall flag.
    IsInferredTyVarBndr flag =>
    HsTyVarBndr flag GhcPs -> R ()
    p_hsTyVarBndr [LHsTyVarBndr Specificity GhcPs]
    [GenLocated SrcSpanAnnA (HsTyVarBndr Specificity GhcPs)]
    bndrs
          HsForAllVis XHsForAllVis GhcPs
    _ [LHsTyVarBndr () GhcPs]
    bndrs -> ForAllVisibility
    -> (HsTyVarBndr () GhcPs -> R ())
    -> [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
    -> R ()
    forall l a.
    HasSrcSpan l =>
    ForAllVisibility -> (a -> R ()) -> [GenLocated l a] -> R ()
    p_forallBndrs ForAllVisibility
    ForAllVis HsTyVarBndr () GhcPs -> R ()
    forall flag.
    IsInferredTyVarBndr flag =>
    HsTyVarBndr flag GhcPs -> R ()
    p_hsTyVarBndr [LHsTyVarBndr () GhcPs]
    [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
    bndrs
        R ()
    interArgBreak
        HsType GhcPs -> R ()
    p_hsTypeR (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t)
      HsQualTy XQualTy GhcPs
    _ LHsContext GhcPs
    qs XRec GhcPs (HsType GhcPs)
    t -> do
        GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> ([GenLocated SrcSpanAnnA (HsType GhcPs)] -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located LHsContext GhcPs
    GenLocated SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType GhcPs)]
    qs HsContext GhcPs -> R ()
    [GenLocated SrcSpanAnnA (HsType GhcPs)] -> R ()
    p_hsContext
        R ()
    space
        Text -> R ()
    txt Text
    "=>"
        R ()
    interArgBreak
        case GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t of
          HsQualTy {} -> HsType GhcPs -> R ()
    p_hsTypeR (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t)
          HsFunTy {} -> HsType GhcPs -> R ()
    p_hsTypeR (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t)
          HsType GhcPs
    _ -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsTypeR
      HsTyVar XTyVar GhcPs
    _ PromotionFlag
    p LIdP GhcPs
    n -> do
        case PromotionFlag
    p of
          PromotionFlag
    IsPromoted -> do
            Text -> R ()
    txt Text
    "'"
            case RdrName -> String
    forall o. Outputable o => o -> String
    showOutputable (GenLocated SrcSpanAnnN RdrName -> RdrName
    forall l e. GenLocated l e -> e
    unLoc LIdP GhcPs
    GenLocated SrcSpanAnnN RdrName
    n) of
              Char
    _ : Char
    '\'' : String
    _ -> R ()
    space
              String
    _ -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
          PromotionFlag
    NotPromoted -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        GenLocated SrcSpanAnnN RdrName -> R ()
    p_rdrName LIdP GhcPs
    GenLocated SrcSpanAnnN RdrName
    n
      HsAppTy XAppTy GhcPs
    _ XRec GhcPs (HsType GhcPs)
    f XRec GhcPs (HsType GhcPs)
    x -> do
        let -- In order to format type applications with multiple parameters
            -- nicer, traverse the AST to gather the function and all the
            -- parameters together.
            gatherArgs :: GenLocated l (HsType pass)
    -> [GenLocated l (HsType pass)]
    -> (GenLocated l (HsType pass), [GenLocated l (HsType pass)])
    gatherArgs GenLocated l (HsType pass)
    f' [GenLocated l (HsType pass)]
    knownArgs =
              case GenLocated l (HsType pass)
    f' of
                L l
    _ (HsAppTy XAppTy pass
    _ XRec pass (HsType pass)
    l XRec pass (HsType pass)
    r) -> GenLocated l (HsType pass)
    -> [GenLocated l (HsType pass)]
    -> (GenLocated l (HsType pass), [GenLocated l (HsType pass)])
    gatherArgs XRec pass (HsType pass)
    GenLocated l (HsType pass)
    l (XRec pass (HsType pass)
    GenLocated l (HsType pass)
    r GenLocated l (HsType pass)
    -> [GenLocated l (HsType pass)] -> [GenLocated l (HsType pass)]
    forall a. a -> [a] -> [a]
    : [GenLocated l (HsType pass)]
    knownArgs)
                GenLocated l (HsType pass)
    _ -> (GenLocated l (HsType pass)
    f', [GenLocated l (HsType pass)]
    knownArgs)
            (GenLocated SrcSpanAnnA (HsType GhcPs)
    func, [GenLocated SrcSpanAnnA (HsType GhcPs)]
    args) = GenLocated SrcSpanAnnA (HsType GhcPs)
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> (GenLocated SrcSpanAnnA (HsType GhcPs),
        [GenLocated SrcSpanAnnA (HsType GhcPs)])
    forall {pass} {l}.
    (XRec pass (HsType pass) ~ GenLocated l (HsType pass)) =>
    GenLocated l (HsType pass)
    -> [GenLocated l (HsType pass)]
    -> (GenLocated l (HsType pass), [GenLocated l (HsType pass)])
    gatherArgs XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    f [XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    x]
        [SrcSpan] -> R () -> R ()
    switchLayout (GenLocated SrcSpanAnnA (HsType GhcPs) -> SrcSpan
    forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
    getLocA XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    f SrcSpan -> [SrcSpan] -> [SrcSpan]
    forall a. a -> [a] -> [a]
    : (GenLocated SrcSpanAnnA (HsType GhcPs) -> SrcSpan)
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)] -> [SrcSpan]
    forall a b. (a -> b) -> [a] -> [b]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap GenLocated SrcSpanAnnA (HsType GhcPs) -> SrcSpan
    forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
    getLocA [GenLocated SrcSpanAnnA (HsType GhcPs)]
    args) (R () -> R ()) -> (R () -> R ()) -> R () -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located GenLocated SrcSpanAnnA (HsType GhcPs)
    func HsType GhcPs -> R ()
    p_hsType
          R ()
    breakpoint
          R () -> R ()
    inci (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $
            R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    breakpoint ((HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) [GenLocated SrcSpanAnnA (HsType GhcPs)]
    args
      HsAppKindTy XAppKindTy GhcPs
    _ XRec GhcPs (HsType GhcPs)
    ty XRec GhcPs (HsType GhcPs)
    kd -> R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        -- The first argument is the location of the "@..." part. Not 100% sure,
        -- but I think we can ignore it as long as we use 'located' on both the
        -- type and the kind.
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    ty HsType GhcPs -> R ()
    p_hsType
        R ()
    breakpoint
        R () -> R ()
    inci (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          Text -> R ()
    txt Text
    "@"
          GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    kd HsType GhcPs -> R ()
    p_hsType
      HsFunTy XFunTy GhcPs
    _ HsArrow GhcPs
    arrow XRec GhcPs (HsType GhcPs)
    x y :: XRec GhcPs (HsType GhcPs)
    y@(L SrcSpanAnnA
    _ HsType GhcPs
    y') -> do
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    x HsType GhcPs -> R ()
    p_hsType
        R ()
    space
        case HsArrow GhcPs
    arrow of
          HsUnrestrictedArrow LHsUniToken "->" "\8594" GhcPs
    _ -> Text -> R ()
    txt Text
    "->"
          HsLinearArrow HsLinearArrowTokens GhcPs
    _ -> Text -> R ()
    txt Text
    "%1 ->"
          HsExplicitMult LHsToken "%" GhcPs
    _ XRec GhcPs (HsType GhcPs)
    mult LHsUniToken "->" "\8594" GhcPs
    _ -> do
            Text -> R ()
    txt Text
    "%"
            HsType GhcPs -> R ()
    p_hsTypeR (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    mult)
            R ()
    space
            Text -> R ()
    txt Text
    "->"
        R ()
    interArgBreak
        case HsType GhcPs
    y' of
          HsFunTy {} -> HsType GhcPs -> R ()
    p_hsTypeR HsType GhcPs
    y'
          HsType GhcPs
    _ -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    y HsType GhcPs -> R ()
    p_hsTypeR
      HsListTy XListTy GhcPs
    _ XRec GhcPs (HsType GhcPs)
    t ->
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t (BracketStyle -> R () -> R ()
    brackets BracketStyle
    N (R () -> R ()) -> (HsType GhcPs -> R ()) -> HsType GhcPs -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HsType GhcPs -> R ()
    p_hsType)
      HsTupleTy XTupleTy GhcPs
    _ HsTupleSort
    tsort HsContext GhcPs
    xs ->
        let parens' :: R () -> R ()
    parens' =
              case HsTupleSort
    tsort of
                HsTupleSort
    HsUnboxedTuple -> BracketStyle -> R () -> R ()
    parensHash BracketStyle
    N
                HsTupleSort
    HsBoxedOrConstraintTuple -> BracketStyle -> R () -> R ()
    parens BracketStyle
    N
         in R () -> R ()
    parens' (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs
      HsSumTy XSumTy GhcPs
    _ HsContext GhcPs
    xs ->
        BracketStyle -> R () -> R ()
    parensHash BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $
          R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep (R ()
    space R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Text -> R ()
    txt Text
    "|" R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> R ()
    breakpoint) (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs
      HsOpTy XOpTy GhcPs
    _ PromotionFlag
    _ XRec GhcPs (HsType GhcPs)
    x LIdP GhcPs
    op XRec GhcPs (HsType GhcPs)
    y -> do
        ModuleFixityMap
    modFixityMap <- R ModuleFixityMap
    askModuleFixityMap
        let opTree :: OpTree
      (GenLocated SrcSpanAnnA (HsType GhcPs))
      (GenLocated SrcSpanAnnN RdrName)
    opTree = [OpTree
       (GenLocated SrcSpanAnnA (HsType GhcPs))
       (GenLocated SrcSpanAnnN RdrName)]
    -> [GenLocated SrcSpanAnnN RdrName]
    -> OpTree
         (GenLocated SrcSpanAnnA (HsType GhcPs))
         (GenLocated SrcSpanAnnN RdrName)
    forall ty op. [OpTree ty op] -> [op] -> OpTree ty op
    OpBranches [XRec GhcPs (HsType GhcPs)
    -> OpTree
         (XRec GhcPs (HsType GhcPs)) (GenLocated SrcSpanAnnN RdrName)
    tyOpTree XRec GhcPs (HsType GhcPs)
    x, XRec GhcPs (HsType GhcPs)
    -> OpTree
         (XRec GhcPs (HsType GhcPs)) (GenLocated SrcSpanAnnN RdrName)
    tyOpTree XRec GhcPs (HsType GhcPs)
    y] [LIdP GhcPs
    GenLocated SrcSpanAnnN RdrName
    op]
        OpTree
      (XRec GhcPs (HsType GhcPs))
      (OpInfo (GenLocated SrcSpanAnnN RdrName))
    -> R ()
    p_tyOpTree
          ((GenLocated SrcSpanAnnN RdrName -> Maybe RdrName)
    -> ModuleFixityMap
    -> OpTree
         (GenLocated SrcSpanAnnA (HsType GhcPs))
         (GenLocated SrcSpanAnnN RdrName)
    -> OpTree
         (GenLocated SrcSpanAnnA (HsType GhcPs))
         (OpInfo (GenLocated SrcSpanAnnN RdrName))
    forall op ty.
    (op -> Maybe RdrName)
    -> ModuleFixityMap -> OpTree ty op -> OpTree ty (OpInfo op)
    reassociateOpTree (RdrName -> Maybe RdrName
    forall a. a -> Maybe a
    Just (RdrName -> Maybe RdrName)
    -> (GenLocated SrcSpanAnnN RdrName -> RdrName)
    -> GenLocated SrcSpanAnnN RdrName
    -> Maybe RdrName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GenLocated SrcSpanAnnN RdrName -> RdrName
    forall l e. GenLocated l e -> e
    unLoc) ModuleFixityMap
    modFixityMap OpTree
      (GenLocated SrcSpanAnnA (HsType GhcPs))
      (GenLocated SrcSpanAnnN RdrName)
    opTree)
      HsParTy XParTy GhcPs
    _ XRec GhcPs (HsType GhcPs)
    t ->
        BracketStyle -> R () -> R ()
    parens BracketStyle
    N (GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsType)
      HsIParamTy XIParamTy GhcPs
    _ XRec GhcPs HsIPName
    n XRec GhcPs (HsType GhcPs)
    t -> R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        GenLocated (SrcAnn NoEpAnns) HsIPName -> (HsIPName -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs HsIPName
    GenLocated (SrcAnn NoEpAnns) HsIPName
    n HsIPName -> R ()
    forall a. Outputable a => a -> R ()
    atom
        R ()
    space
        Text -> R ()
    txt Text
    "::"
        R ()
    breakpoint
        R () -> R ()
    inci (GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsType)
      HsStarTy XStarTy GhcPs
    _ Bool
    _ -> Text -> R ()
    txt Text
    "*"
      HsKindSig XKindSig GhcPs
    _ XRec GhcPs (HsType GhcPs)
    t XRec GhcPs (HsType GhcPs)
    k -> R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsType
        R ()
    space
        Text -> R ()
    txt Text
    "::"
        R ()
    breakpoint
        R () -> R ()
    inci (GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    k HsType GhcPs -> R ()
    p_hsType)
      HsSpliceTy XSpliceTy GhcPs
    _ HsUntypedSplice GhcPs
    splice -> SpliceDecoration -> HsUntypedSplice GhcPs -> R ()
    p_hsUntypedSplice SpliceDecoration
    DollarSplice HsUntypedSplice GhcPs
    splice
      HsDocTy XDocTy GhcPs
    _ XRec GhcPs (HsType GhcPs)
    t LHsDoc GhcPs
    str -> do
        HaddockStyle -> Bool -> LHsDoc GhcPs -> R ()
    p_hsDoc HaddockStyle
    Pipe Bool
    True LHsDoc GhcPs
    str
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsType
      HsBangTy XBangTy GhcPs
    _ (HsSrcBang SourceText
    _ SrcUnpackedness
    u SrcStrictness
    s) XRec GhcPs (HsType GhcPs)
    t -> do
        case SrcUnpackedness
    u of
          SrcUnpackedness
    SrcUnpack -> Text -> R ()
    txt Text
    "{-# UNPACK #-}" R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> R ()
    space
          SrcUnpackedness
    SrcNoUnpack -> Text -> R ()
    txt Text
    "{-# NOUNPACK #-}" R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> R ()
    space
          SrcUnpackedness
    NoSrcUnpack -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        case SrcStrictness
    s of
          SrcStrictness
    SrcLazy -> Text -> R ()
    txt Text
    "~"
          SrcStrictness
    SrcStrict -> Text -> R ()
    txt Text
    "!"
          SrcStrictness
    NoSrcStrict -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    t HsType GhcPs -> R ()
    p_hsType
      HsRecTy XRecTy GhcPs
    _ [LConDeclField GhcPs]
    fields ->
        [LConDeclField GhcPs] -> R ()
    p_conDeclFields [LConDeclField GhcPs]
    fields
      HsExplicitListTy XExplicitListTy GhcPs
    _ PromotionFlag
    p HsContext GhcPs
    xs -> do
        case PromotionFlag
    p of
          PromotionFlag
    IsPromoted -> Text -> R ()
    txt Text
    "'"
          PromotionFlag
    NotPromoted -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        BracketStyle -> R () -> R ()
    brackets BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          -- If this list is promoted and the first element starts with a single
          -- quote, we need to put a space in between or it fails to parse.
          case (PromotionFlag
    p, HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs) of
            (PromotionFlag
    IsPromoted, L SrcSpanAnnA
    _ HsType GhcPs
    t : [GenLocated SrcSpanAnnA (HsType GhcPs)]
    _) | HsType GhcPs -> Bool
    startsWithSingleQuote HsType GhcPs
    t -> R ()
    space
            (PromotionFlag, [GenLocated SrcSpanAnnA (HsType GhcPs)])
    _ -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
          R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs
      HsExplicitTupleTy XExplicitTupleTy GhcPs
    _ HsContext GhcPs
    xs -> do
        Text -> R ()
    txt Text
    "'"
        BracketStyle -> R () -> R ()
    parens BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          case HsContext GhcPs
    xs of
            L SrcSpanAnnA
    _ HsType GhcPs
    t : HsContext GhcPs
    _ | HsType GhcPs -> Bool
    startsWithSingleQuote HsType GhcPs
    t -> R ()
    space
            HsContext GhcPs
    _ -> () -> R ()
    forall a. a -> R a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
          R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel ((HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs
      HsTyLit XTyLit GhcPs
    _ HsTyLit GhcPs
    t ->
        case HsTyLit GhcPs
    t of
          HsStrTy (SourceText String
    s) FastString
    _ -> String -> R ()
    p_stringLit String
    s
          HsTyLit GhcPs
    a -> HsTyLit GhcPs -> R ()
    forall a. Outputable a => a -> R ()
    atom HsTyLit GhcPs
    a
      HsWildCardTy XWildCardTy GhcPs
    _ -> Text -> R ()
    txt Text
    "_"
      XHsType XXType GhcPs
    t -> HsCoreTy -> R ()
    forall a. Outputable a => a -> R ()
    atom XXType GhcPs
    HsCoreTy
    t
      where
        startsWithSingleQuote :: HsType GhcPs -> Bool
    startsWithSingleQuote = \case
          HsAppTy XAppTy GhcPs
    _ (L SrcSpanAnnA
    _ HsType GhcPs
    f) XRec GhcPs (HsType GhcPs)
    _ -> HsType GhcPs -> Bool
    startsWithSingleQuote HsType GhcPs
    f
          HsTyVar XTyVar GhcPs
    _ PromotionFlag
    IsPromoted LIdP GhcPs
    _ -> Bool
    True
          HsExplicitTupleTy {} -> Bool
    True
          HsExplicitListTy {} -> Bool
    True
          HsTyLit XTyLit GhcPs
    _ HsCharTy {} -> Bool
    True
          HsType GhcPs
    _ -> Bool
    False
        interArgBreak :: R ()
    interArgBreak =
          if Bool
    multilineArgs
            then R ()
    newline
            else R ()
    breakpoint
        p_hsTypeR :: HsType GhcPs -> R ()
    p_hsTypeR = Bool -> HsType GhcPs -> R ()
    p_hsType' Bool
    multilineArgs

    -- | Return 'True' if at least one argument in 'HsType' has a doc string
    -- attached to it.
    hasDocStrings :: HsType GhcPs -> Bool
    hasDocStrings :: HsType GhcPs -> Bool
    hasDocStrings = \case
      HsDocTy {} -> Bool
    True
      HsFunTy XFunTy GhcPs
    _ HsArrow GhcPs
    _ (L SrcSpanAnnA
    _ HsType GhcPs
    x) (L SrcSpanAnnA
    _ HsType GhcPs
    y) -> HsType GhcPs -> Bool
    hasDocStrings HsType GhcPs
    x Bool -> Bool -> Bool
    || HsType GhcPs -> Bool
    hasDocStrings HsType GhcPs
    y
      HsForAllTy XForAllTy GhcPs
    _ HsForAllTelescope GhcPs
    _ (L SrcSpanAnnA
    _ HsType GhcPs
    x) -> HsType GhcPs -> Bool
    hasDocStrings HsType GhcPs
    x
      HsQualTy XQualTy GhcPs
    _ LHsContext GhcPs
    _ (L SrcSpanAnnA
    _ HsType GhcPs
    x) -> HsType GhcPs -> Bool
    hasDocStrings HsType GhcPs
    x
      HsType GhcPs
    _ -> Bool
    False

    p_hsContext :: HsContext GhcPs -> R ()
    p_hsContext :: HsContext GhcPs -> R ()
    p_hsContext = \case
      [] -> Text -> R ()
    txt Text
    "()"
      [XRec GhcPs (HsType GhcPs)
    x] -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    x HsType GhcPs -> R ()
    p_hsType
      HsContext GhcPs
    xs -> BracketStyle -> R () -> R ()
    parens BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ R ()
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (HsType GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HsType GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (HsType GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' HsType GhcPs -> R ()
    p_hsType) HsContext GhcPs
    [GenLocated SrcSpanAnnA (HsType GhcPs)]
    xs

    class IsInferredTyVarBndr flag where
      isInferred :: flag -> Bool

    instance IsInferredTyVarBndr () where
      isInferred :: () -> Bool
    isInferred () = Bool
    False

    instance IsInferredTyVarBndr Specificity where
      isInferred :: Specificity -> Bool
    isInferred = \case
        Specificity
    InferredSpec -> Bool
    True
        Specificity
    SpecifiedSpec -> Bool
    False

    p_hsTyVarBndr :: (IsInferredTyVarBndr flag) => HsTyVarBndr flag GhcPs -> R ()
    p_hsTyVarBndr :: forall flag.
    IsInferredTyVarBndr flag =>
    HsTyVarBndr flag GhcPs -> R ()
    p_hsTyVarBndr = \case
      UserTyVar XUserTyVar GhcPs
    _ flag
    flag LIdP GhcPs
    x ->
        (if flag -> Bool
    forall flag. IsInferredTyVarBndr flag => flag -> Bool
    isInferred flag
    flag then BracketStyle -> R () -> R ()
    braces BracketStyle
    N else R () -> R ()
    forall a. a -> a
    id) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ GenLocated SrcSpanAnnN RdrName -> R ()
    p_rdrName LIdP GhcPs
    GenLocated SrcSpanAnnN RdrName
    x
      KindedTyVar XKindedTyVar GhcPs
    _ flag
    flag LIdP GhcPs
    l XRec GhcPs (HsType GhcPs)
    k -> (if flag -> Bool
    forall flag. IsInferredTyVarBndr flag => flag -> Bool
    isInferred flag
    flag then BracketStyle -> R () -> R ()
    braces else BracketStyle -> R () -> R ()
    parens) BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        GenLocated SrcSpanAnnN RdrName -> (RdrName -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located LIdP GhcPs
    GenLocated SrcSpanAnnN RdrName
    l RdrName -> R ()
    forall a. Outputable a => a -> R ()
    atom
        R ()
    space
        Text -> R ()
    txt Text
    "::"
        R ()
    breakpoint
        R () -> R ()
    inci (GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    k HsType GhcPs -> R ()
    p_hsType)

    data ForAllVisibility = ForAllInvis | ForAllVis

    -- | Render several @forall@-ed variables.
    p_forallBndrs ::
      (HasSrcSpan l) =>
      ForAllVisibility ->
      (a -> R ()) ->
      [GenLocated l a] ->
      R ()
    p_forallBndrs :: forall l a.
    HasSrcSpan l =>
    ForAllVisibility -> (a -> R ()) -> [GenLocated l a] -> R ()
    p_forallBndrs ForAllVisibility
    ForAllInvis a -> R ()
    _ [] = Text -> R ()
    txt Text
    "forall."
    p_forallBndrs ForAllVisibility
    ForAllVis a -> R ()
    _ [] = Text -> R ()
    txt Text
    "forall ->"
    p_forallBndrs ForAllVisibility
    vis a -> R ()
    p [GenLocated l a]
    tyvars =
      [SrcSpan] -> R () -> R ()
    switchLayout (GenLocated l a -> SrcSpan
    forall l a. HasSrcSpan l => GenLocated l a -> SrcSpan
    getLoc' (GenLocated l a -> SrcSpan) -> [GenLocated l a] -> [SrcSpan]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [GenLocated l a]
    tyvars) (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
        Text -> R ()
    txt Text
    "forall"
        R ()
    breakpoint
        R () -> R ()
    inci (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ do
          R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ R () -> (GenLocated l a -> R ()) -> [GenLocated l a] -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    breakpoint (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated l a -> R ()) -> GenLocated l a -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> R ()) -> GenLocated l a -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' a -> R ()
    p) [GenLocated l a]
    tyvars
          case ForAllVisibility
    vis of
            ForAllVisibility
    ForAllInvis -> Text -> R ()
    txt Text
    "."
            ForAllVisibility
    ForAllVis -> R ()
    space R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Text -> R ()
    txt Text
    "->"

    p_conDeclFields :: [LConDeclField GhcPs] -> R ()
    p_conDeclFields :: [LConDeclField GhcPs] -> R ()
    p_conDeclFields [LConDeclField GhcPs]
    xs =
      BracketStyle -> R () -> R ()
    braces BracketStyle
    N (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ R ()
    -> (GenLocated SrcSpanAnnA (ConDeclField GhcPs) -> R ())
    -> [GenLocated SrcSpanAnnA (ConDeclField GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep R ()
    commaDel (R () -> R ()
    sitcc (R () -> R ())
    -> (GenLocated SrcSpanAnnA (ConDeclField GhcPs) -> R ())
    -> GenLocated SrcSpanAnnA (ConDeclField GhcPs)
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ConDeclField GhcPs -> R ())
    -> GenLocated SrcSpanAnnA (ConDeclField GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' ConDeclField GhcPs -> R ()
    p_conDeclField) [LConDeclField GhcPs]
    [GenLocated SrcSpanAnnA (ConDeclField GhcPs)]
    xs

    p_conDeclField :: ConDeclField GhcPs -> R ()
    p_conDeclField :: ConDeclField GhcPs -> R ()
    p_conDeclField ConDeclField {[LFieldOcc GhcPs]
    Maybe (LHsDoc GhcPs)
    XConDeclField GhcPs
    XRec GhcPs (HsType GhcPs)
    cd_fld_ext :: XConDeclField GhcPs
    cd_fld_names :: [LFieldOcc GhcPs]
    cd_fld_type :: XRec GhcPs (HsType GhcPs)
    cd_fld_doc :: Maybe (LHsDoc GhcPs)
    cd_fld_ext :: forall pass. ConDeclField pass -> XConDeclField pass
    cd_fld_names :: forall pass. ConDeclField pass -> [LFieldOcc pass]
    cd_fld_type :: forall pass. ConDeclField pass -> LBangType pass
    cd_fld_doc :: forall pass. ConDeclField pass -> Maybe (LHsDoc pass)
    ..} = do
      (LHsDoc GhcPs -> R ()) -> Maybe (LHsDoc GhcPs) -> R ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ (HaddockStyle -> Bool -> LHsDoc GhcPs -> R ()
    p_hsDoc HaddockStyle
    Pipe Bool
    True) Maybe (LHsDoc GhcPs)
    cd_fld_doc
      R () -> R ()
    sitcc (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $
        R ()
    -> (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs) -> R ())
    -> [GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs)]
    -> R ()
    forall a. R () -> (a -> R ()) -> [a] -> R ()
    sep
          R ()
    commaDel
          ((FieldOcc GhcPs -> R ())
    -> GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs) -> R ()
    forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
    located' (GenLocated SrcSpanAnnN RdrName -> R ()
    p_rdrName (GenLocated SrcSpanAnnN RdrName -> R ())
    -> (FieldOcc GhcPs -> GenLocated SrcSpanAnnN RdrName)
    -> FieldOcc GhcPs
    -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . FieldOcc GhcPs -> XRec GhcPs RdrName
    FieldOcc GhcPs -> GenLocated SrcSpanAnnN RdrName
    forall pass. FieldOcc pass -> XRec pass RdrName
    foLabel))
          [LFieldOcc GhcPs]
    [GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs)]
    cd_fld_names
      R ()
    space
      Text -> R ()
    txt Text
    "::"
      R ()
    breakpoint
      R () -> R ()
    sitcc (R () -> R ()) -> (R () -> R ()) -> R () -> R ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . R () -> R ()
    inci (R () -> R ()) -> R () -> R ()
    forall a b. (a -> b) -> a -> b
    $ HsType GhcPs -> R ()
    p_hsType (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    cd_fld_type)

    p_lhsTypeArg :: LHsTypeArg GhcPs -> R ()
    p_lhsTypeArg :: LHsTypeArg GhcPs -> R ()
    p_lhsTypeArg = \case
      HsValArg XRec GhcPs (HsType GhcPs)
    ty -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    ty HsType GhcPs -> R ()
    p_hsType
      -- first argument is the SrcSpan of the @,
      -- but the @ always has to be directly before the type argument
      HsTypeArg SrcSpan
    _ XRec GhcPs (HsType GhcPs)
    ty -> Text -> R ()
    txt Text
    "@" R () -> R () -> R ()
    forall a b. R a -> R b -> R b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> (HsType GhcPs -> R ()) -> R ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
    located XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    ty HsType GhcPs -> R ()
    p_hsType
      -- NOTE(amesgen) is this unreachable or just not implemented?
      HsArgPar SrcSpan
    _ -> String -> R ()
    forall a. String -> a
    notImplemented String
    "HsArgPar"

    p_hsSigType :: HsSigType GhcPs -> R ()
    p_hsSigType :: HsSigType GhcPs -> R ()
    p_hsSigType HsSig {XHsSig GhcPs
    XRec GhcPs (HsType GhcPs)
    HsOuterSigTyVarBndrs GhcPs
    sig_ext :: XHsSig GhcPs
    sig_bndrs :: HsOuterSigTyVarBndrs GhcPs
    sig_body :: XRec GhcPs (HsType GhcPs)
    sig_ext :: forall pass. HsSigType pass -> XHsSig pass
    sig_bndrs :: forall pass. HsSigType pass -> HsOuterSigTyVarBndrs pass
    sig_body :: forall pass. HsSigType pass -> LHsType pass
    ..} =
      HsType GhcPs -> R ()
    p_hsType (HsType GhcPs -> R ()) -> HsType GhcPs -> R ()
    forall a b. (a -> b) -> a -> b
    $ HsOuterSigTyVarBndrs GhcPs
    -> XRec GhcPs (HsType GhcPs) -> HsType GhcPs
    hsOuterTyVarBndrsToHsType HsOuterSigTyVarBndrs GhcPs
    sig_bndrs XRec GhcPs (HsType GhcPs)
    sig_body

    ----------------------------------------------------------------------------
    -- Conversion functions

    tyVarToType :: HsTyVarBndr () GhcPs -> HsType GhcPs
    tyVarToType :: HsTyVarBndr () GhcPs -> HsType GhcPs
    tyVarToType = \case
      UserTyVar XUserTyVar GhcPs
    _ () LIdP GhcPs
    tvar -> XTyVar GhcPs -> PromotionFlag -> LIdP GhcPs -> HsType GhcPs
    forall pass.
    XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
    HsTyVar XTyVar GhcPs
    EpAnn [AddEpAnn]
    forall ann. EpAnn ann
    EpAnnNotUsed PromotionFlag
    NotPromoted LIdP GhcPs
    tvar
      KindedTyVar XKindedTyVar GhcPs
    _ () LIdP GhcPs
    tvar XRec GhcPs (HsType GhcPs)
    kind ->
        -- Note: we always add parentheses because for whatever reason GHC does
        -- not use HsParTy for left-hand sides of declarations. Please see
        -- <https://gitlab.haskell.org/ghc/ghc/issues/17404>. This is fine as
        -- long as 'tyVarToType' does not get applied to right-hand sides of
        -- declarations.
        XParTy GhcPs -> XRec GhcPs (HsType GhcPs) -> HsType GhcPs
    forall pass. XParTy pass -> LHsType pass -> HsType pass
    HsParTy XParTy GhcPs
    EpAnn AnnParen
    forall ann. EpAnn ann
    EpAnnNotUsed (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs)
    -> (HsType GhcPs -> GenLocated SrcSpanAnnA (HsType GhcPs))
    -> HsType GhcPs
    -> HsType GhcPs
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HsType GhcPs -> GenLocated SrcSpanAnnA (HsType GhcPs)
    forall a an. a -> LocatedAn an a
    noLocA (HsType GhcPs -> HsType GhcPs) -> HsType GhcPs -> HsType GhcPs
    forall a b. (a -> b) -> a -> b
    $
          XKindSig GhcPs
    -> XRec GhcPs (HsType GhcPs)
    -> XRec GhcPs (HsType GhcPs)
    -> HsType GhcPs
    forall pass.
    XKindSig pass -> LHsType pass -> LHsType pass -> HsType pass
    HsKindSig XKindSig GhcPs
    EpAnn [AddEpAnn]
    forall ann. EpAnn ann
    EpAnnNotUsed (HsType GhcPs -> GenLocated SrcSpanAnnA (HsType GhcPs)
    forall a an. a -> LocatedAn an a
    noLocA (XTyVar GhcPs -> PromotionFlag -> LIdP GhcPs -> HsType GhcPs
    forall pass.
    XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
    HsTyVar XTyVar GhcPs
    EpAnn [AddEpAnn]
    forall ann. EpAnn ann
    EpAnnNotUsed PromotionFlag
    NotPromoted LIdP GhcPs
    tvar)) XRec GhcPs (HsType GhcPs)
    kind

    tyVarsToTyPats :: LHsQTyVars GhcPs -> HsTyPats GhcPs
    tyVarsToTyPats :: LHsQTyVars GhcPs -> HsTyPats GhcPs
    tyVarsToTyPats HsQTvs {[LHsTyVarBndr () GhcPs]
    XHsQTvs GhcPs
    hsq_ext :: XHsQTvs GhcPs
    hsq_explicit :: [LHsTyVarBndr () GhcPs]
    hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
    hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
    ..} = GenLocated SrcSpanAnnA (HsType GhcPs)
    -> HsArg
         (GenLocated SrcSpanAnnA (HsType GhcPs))
         (GenLocated SrcSpanAnnA (HsType GhcPs))
    forall tm ty. tm -> HsArg tm ty
    HsValArg (GenLocated SrcSpanAnnA (HsType GhcPs)
     -> HsArg
          (GenLocated SrcSpanAnnA (HsType GhcPs))
          (GenLocated SrcSpanAnnA (HsType GhcPs)))
    -> (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)
        -> GenLocated SrcSpanAnnA (HsType GhcPs))
    -> GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)
    -> HsArg
         (GenLocated SrcSpanAnnA (HsType GhcPs))
         (GenLocated SrcSpanAnnA (HsType GhcPs))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (HsTyVarBndr () GhcPs -> HsType GhcPs)
    -> GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    forall a b.
    (a -> b) -> GenLocated SrcSpanAnnA a -> GenLocated SrcSpanAnnA b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap HsTyVarBndr () GhcPs -> HsType GhcPs
    tyVarToType (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)
     -> HsArg
          (GenLocated SrcSpanAnnA (HsType GhcPs))
          (GenLocated SrcSpanAnnA (HsType GhcPs)))
    -> [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
    -> [HsArg
          (GenLocated SrcSpanAnnA (HsType GhcPs))
          (GenLocated SrcSpanAnnA (HsType GhcPs))]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [LHsTyVarBndr () GhcPs]
    [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
    hsq_explicit

    -- could be generalized to also handle () instead of Specificity
    hsOuterTyVarBndrsToHsType ::
      HsOuterTyVarBndrs Specificity GhcPs ->
      LHsType GhcPs ->
      HsType GhcPs
    hsOuterTyVarBndrsToHsType :: HsOuterSigTyVarBndrs GhcPs
    -> XRec GhcPs (HsType GhcPs) -> HsType GhcPs
    hsOuterTyVarBndrsToHsType HsOuterSigTyVarBndrs GhcPs
    obndrs XRec GhcPs (HsType GhcPs)
    ty = case HsOuterSigTyVarBndrs GhcPs
    obndrs of
      HsOuterImplicit XHsOuterImplicit GhcPs
    NoExtField
    NoExtField -> GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
    forall l e. GenLocated l e -> e
    unLoc XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    ty
      HsOuterExplicit XHsOuterExplicit GhcPs Specificity
    _ [LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
    bndrs ->
        XForAllTy GhcPs
    -> HsForAllTelescope GhcPs
    -> XRec GhcPs (HsType GhcPs)
    -> HsType GhcPs
    forall pass.
    XForAllTy pass
    -> HsForAllTelescope pass -> LHsType pass -> HsType pass
    HsForAllTy XForAllTy GhcPs
    NoExtField
    NoExtField (EpAnnForallTy
    -> [LHsTyVarBndr Specificity GhcPs] -> HsForAllTelescope GhcPs
    forall (p :: Pass).
    EpAnnForallTy
    -> [LHsTyVarBndr Specificity (GhcPass p)]
    -> HsForAllTelescope (GhcPass p)
    mkHsForAllInvisTele EpAnnForallTy
    forall ann. EpAnn ann
    EpAnnNotUsed [LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
    [LHsTyVarBndr Specificity GhcPs]
    bndrs) XRec GhcPs (HsType GhcPs)
    ty

    lhsTypeToSigType :: LHsType GhcPs -> LHsSigType GhcPs
    lhsTypeToSigType :: XRec GhcPs (HsType GhcPs) -> LHsSigType GhcPs
    lhsTypeToSigType XRec GhcPs (HsType GhcPs)
    ty =
      Located (HsSigType GhcPs) -> LHsSigType GhcPs
    Located (HsSigType GhcPs)
    -> LocatedAn AnnListItem (HsSigType GhcPs)
    forall e ann. Located e -> LocatedAn ann e
    reLocA (Located (HsSigType GhcPs) -> LHsSigType GhcPs)
    -> (XRec GhcPs (HsType GhcPs) -> Located (HsSigType GhcPs))
    -> XRec GhcPs (HsType GhcPs)
    -> LHsSigType GhcPs
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SrcSpan -> HsSigType GhcPs -> Located (HsSigType GhcPs)
    forall l e. l -> e -> GenLocated l e
    L (GenLocated SrcSpanAnnA (HsType GhcPs) -> SrcSpan
    forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
    getLocA XRec GhcPs (HsType GhcPs)
    GenLocated SrcSpanAnnA (HsType GhcPs)
    ty) (HsSigType GhcPs -> Located (HsSigType GhcPs))
    -> (GenLocated SrcSpanAnnA (HsType GhcPs) -> HsSigType GhcPs)
    -> GenLocated SrcSpanAnnA (HsType GhcPs)
    -> Located (HsSigType GhcPs)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XHsSig GhcPs
    -> HsOuterSigTyVarBndrs GhcPs
    -> XRec GhcPs (HsType GhcPs)
    -> HsSigType GhcPs
    forall pass.
    XHsSig pass
    -> HsOuterSigTyVarBndrs pass -> LHsType pass -> HsSigType pass
    HsSig XHsSig GhcPs
    NoExtField
    NoExtField (XHsOuterImplicit GhcPs -> HsOuterSigTyVarBndrs GhcPs
    forall flag pass.
    XHsOuterImplicit pass -> HsOuterTyVarBndrs flag pass
    HsOuterImplicit XHsOuterImplicit GhcPs
    NoExtField
    NoExtField) (XRec GhcPs (HsType GhcPs) -> LHsSigType GhcPs)
    -> XRec GhcPs (HsType GhcPs) -> LHsSigType GhcPs
    forall a b. (a -> b) -> a -> b
    $ XRec GhcPs (HsType GhcPs)
    ty