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

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

import Control.Monad
import GHC.Hs
import GHC.Types.Basic hiding (isPromoted)
import GHC.Types.SourceText
import GHC.Types.SrcLoc
import GHC.Types.Var
import Ormolu.Config
import Ormolu.Config.Types (FunctionArrowsStyle (..))
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_hsSplice, p_stringLit)
import Ormolu.Printer.Operators
import Ormolu.Utils

p_hsType :: HsType GhcPs -> R ()
p_hsType :: HsType GhcPs -> R ()
p_hsType HsType GhcPs
t = do
  TypeDocStyle
s <-
    forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      FunctionArrowsStyle
TrailingArrows -> forall (f :: * -> *) a. Applicative f => a -> f a
pure TypeDocStyle
PipeStyle
      FunctionArrowsStyle
LeadingArrows -> forall (f :: * -> *) a. Applicative f => a -> f a
pure TypeDocStyle
CaretStyle
      FunctionArrowsStyle
LeadingArgsArrows -> forall (f :: * -> *) a. Applicative f => a -> f a
pure TypeDocStyle
CaretStyle
  Layout
layout <- R Layout
getLayout
  Bool -> TypeDocStyle -> HsType GhcPs -> R ()
p_hsType' (HsType GhcPs -> Bool
hasDocStrings HsType GhcPs
t Bool -> Bool -> Bool
|| Layout
layout forall a. Eq a => a -> a -> Bool
== Layout
MultiLine) TypeDocStyle
s HsType GhcPs
t

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

-- | How to render Haddocks associated with a type.
data TypeDocStyle
  = PipeStyle
  | CaretStyle

p_hsType' :: Bool -> TypeDocStyle -> HsType GhcPs -> R ()
p_hsType' :: Bool -> TypeDocStyle -> HsType GhcPs -> R ()
p_hsType' Bool
multilineArgs TypeDocStyle
docStyle = \case
  HsForAllTy XForAllTy GhcPs
_ HsForAllTelescope GhcPs
tele XRec GhcPs (HsType GhcPs)
t -> do
    ForAllVisibility
vis <-
      case HsForAllTelescope GhcPs
tele of
        HsForAllInvis XHsForAllInvis GhcPs
_ [LHsTyVarBndr Specificity GhcPs]
bndrs -> forall l a. HasSrcSpan l => (a -> R ()) -> [GenLocated l a] -> R ()
p_forallBndrsStart forall flag.
IsInferredTyVarBndr flag =>
HsTyVarBndr flag GhcPs -> R ()
p_hsTyVarBndr [LHsTyVarBndr Specificity GhcPs]
bndrs forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure ForAllVisibility
ForAllInvis
        HsForAllVis XHsForAllVis GhcPs
_ [LHsTyVarBndr () GhcPs]
bndrs -> forall l a. HasSrcSpan l => (a -> R ()) -> [GenLocated l a] -> R ()
p_forallBndrsStart forall flag.
IsInferredTyVarBndr flag =>
HsTyVarBndr flag GhcPs -> R ()
p_hsTyVarBndr [LHsTyVarBndr () GhcPs]
bndrs forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure ForAllVisibility
ForAllVis
    forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      FunctionArrowsStyle
LeadingArrows | Bool
multilineArgs -> R ()
interArgBreak forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> R ()
txt Text
" " forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ForAllVisibility -> R ()
p_forallBndrsEnd ForAllVisibility
vis
      FunctionArrowsStyle
_ -> ForAllVisibility -> R ()
p_forallBndrsEnd ForAllVisibility
vis forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
interArgBreak
    HsType GhcPs -> R ()
p_hsTypeR (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
t)
  HsQualTy XQualTy GhcPs
_ LHsContext GhcPs
qs XRec GhcPs (HsType GhcPs)
t -> do
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located LHsContext GhcPs
qs HsContext GhcPs -> R ()
p_hsContext
    forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      FunctionArrowsStyle
LeadingArrows -> R ()
interArgBreak forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
token'darrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space
      FunctionArrowsStyle
TrailingArrows -> R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
token'darrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
interArgBreak
      FunctionArrowsStyle
LeadingArgsArrows -> R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
token'darrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
interArgBreak
    case forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
t of
      HsQualTy {} -> HsType GhcPs -> R ()
p_hsTypeR (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
t)
      HsFunTy {} -> HsType GhcPs -> R ()
p_hsTypeR (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
t)
      HsType GhcPs
_ -> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (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 forall o. Outputable o => o -> String
showOutputable (forall l e. GenLocated l e -> e
unLoc LIdP GhcPs
n) of
          Char
_ : Char
'\'' : String
_ -> R ()
space
          String
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
      PromotionFlag
NotPromoted -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
    LocatedN RdrName -> R ()
p_rdrName LIdP GhcPs
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)
-> [XRec pass (HsType pass)]
-> (GenLocated l (HsType pass), [XRec pass (HsType pass)])
gatherArgs GenLocated l (HsType pass)
f' [XRec pass (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)
-> [XRec pass (HsType pass)]
-> (GenLocated l (HsType pass), [XRec pass (HsType pass)])
gatherArgs XRec pass (HsType pass)
l (XRec pass (HsType pass)
r forall a. a -> [a] -> [a]
: [XRec pass (HsType pass)]
knownArgs)
            GenLocated l (HsType pass)
_ -> (GenLocated l (HsType pass)
f', [XRec pass (HsType pass)]
knownArgs)
        (GenLocated SrcSpanAnnA (HsType GhcPs)
func, HsContext GhcPs
args) = forall {pass} {l}.
(XRec pass (HsType pass) ~ GenLocated l (HsType pass)) =>
GenLocated l (HsType pass)
-> [XRec pass (HsType pass)]
-> (GenLocated l (HsType pass), [XRec pass (HsType pass)])
gatherArgs XRec GhcPs (HsType GhcPs)
f [XRec GhcPs (HsType GhcPs)
x]
    [SrcSpan] -> R () -> R ()
switchLayout (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA XRec GhcPs (HsType GhcPs)
f forall a. a -> [a] -> [a]
: forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA HsContext GhcPs
args) forall b c a. (b -> c) -> (a -> b) -> a -> c
. R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ do
      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 forall a b. (a -> b) -> a -> b
$
        forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
breakpoint (forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext GhcPs
args
  HsAppKindTy XAppKindTy GhcPs
_ XRec GhcPs (HsType GhcPs)
ty XRec GhcPs (HsType GhcPs)
kd -> R () -> R ()
sitcc 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.
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
ty HsType GhcPs -> R ()
p_hsType
    R ()
breakpoint
    R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ do
      Text -> R ()
txt Text
"@"
      forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
kd HsType GhcPs -> R ()
p_hsType
  HsFunTy XFunTy GhcPs
_ HsArrow GhcPs
arrow XRec GhcPs (HsType GhcPs)
x XRec GhcPs (HsType GhcPs)
y -> do
    let p_arrow :: R ()
p_arrow =
          case HsArrow GhcPs
arrow of
            HsUnrestrictedArrow LHsUniToken "->" "\8594" GhcPs
_ -> R ()
token'rarrow
            HsLinearArrow HsLinearArrowTokens GhcPs
_ -> R ()
token'lolly
            HsExplicitMult LHsToken "%" GhcPs
_ XRec GhcPs (HsType GhcPs)
mult LHsUniToken "->" "\8594" GhcPs
_ -> do
              Text -> R ()
txt Text
"%"
              HsType GhcPs -> R ()
p_hsTypeR (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
mult)
              R ()
space
              R ()
token'rarrow
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
x HsType GhcPs -> R ()
p_hsType
    forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      FunctionArrowsStyle
LeadingArrows -> R ()
interArgBreak forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
y (\HsType GhcPs
y' -> R ()
p_arrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HsType GhcPs -> R ()
p_hsTypeR HsType GhcPs
y')
      FunctionArrowsStyle
TrailingArrows -> R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
p_arrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
interArgBreak forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
y HsType GhcPs -> R ()
p_hsTypeR
      FunctionArrowsStyle
LeadingArgsArrows -> R ()
interArgBreak forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
y (\HsType GhcPs
y' -> R ()
p_arrow forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HsType GhcPs -> R ()
p_hsTypeR HsType GhcPs
y')
  HsListTy XListTy GhcPs
_ XRec GhcPs (HsType GhcPs)
t ->
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
t (BracketStyle -> R () -> R ()
brackets BracketStyle
N 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' forall a b. (a -> b) -> a -> b
$ forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
commaDel (R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext GhcPs
xs
  HsSumTy XSumTy GhcPs
_ HsContext GhcPs
xs ->
    BracketStyle -> R () -> R ()
parensHash BracketStyle
N forall a b. (a -> b) -> a -> b
$
      forall a. R () -> (a -> R ()) -> [a] -> R ()
sep (R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> R ()
txt Text
"|" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
breakpoint) (R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext GhcPs
xs
  HsOpTy XOpTy GhcPs
_ PromotionFlag
_ XRec GhcPs (HsType GhcPs)
x LIdP GhcPs
op XRec GhcPs (HsType GhcPs)
y -> do
    FixityMap
fixityOverrides <- R FixityMap
askFixityOverrides
    LazyFixityMap
fixityMap <- R LazyFixityMap
askFixityMap
    let opTree :: OpTree (GenLocated SrcSpanAnnA (HsType GhcPs)) (LocatedN RdrName)
opTree = forall ty op. [OpTree ty op] -> [op] -> OpTree ty op
OpBranches [XRec GhcPs (HsType GhcPs)
-> OpTree (XRec GhcPs (HsType GhcPs)) (LocatedN RdrName)
tyOpTree XRec GhcPs (HsType GhcPs)
x, XRec GhcPs (HsType GhcPs)
-> OpTree (XRec GhcPs (HsType GhcPs)) (LocatedN RdrName)
tyOpTree XRec GhcPs (HsType GhcPs)
y] [LIdP GhcPs
op]
    OpTree (XRec GhcPs (HsType GhcPs)) (OpInfo (LocatedN RdrName))
-> R ()
p_tyOpTree
      (forall op ty.
(op -> Maybe RdrName)
-> FixityMap
-> LazyFixityMap
-> OpTree ty op
-> OpTree ty (OpInfo op)
reassociateOpTree (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) FixityMap
fixityOverrides LazyFixityMap
fixityMap OpTree (GenLocated SrcSpanAnnA (HsType GhcPs)) (LocatedN RdrName)
opTree)
  HsParTy XParTy GhcPs
_ XRec GhcPs (HsType GhcPs)
t ->
    BracketStyle -> R () -> R ()
parens BracketStyle
N forall a b. (a -> b) -> a -> b
$ R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
t HsType GhcPs -> R ()
p_hsType
  HsIParamTy XIParamTy GhcPs
_ XRec GhcPs HsIPName
n XRec GhcPs (HsType GhcPs)
t -> R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ do
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs HsIPName
n forall a. Outputable a => a -> R ()
atom
    R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation XRec GhcPs (HsType GhcPs)
t HsType GhcPs -> R ()
p_hsType
  HsStarTy XStarTy GhcPs
_ Bool
_ -> R ()
token'star
  HsKindSig XKindSig GhcPs
_ XRec GhcPs (HsType GhcPs)
t XRec GhcPs (HsType GhcPs)
k -> R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ do
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
t HsType GhcPs -> R ()
p_hsType
    R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation XRec GhcPs (HsType GhcPs)
k HsType GhcPs -> R ()
p_hsType
  HsSpliceTy XSpliceTy GhcPs
_ HsSplice GhcPs
splice -> HsSplice GhcPs -> R ()
p_hsSplice HsSplice GhcPs
splice
  HsDocTy XDocTy GhcPs
_ XRec GhcPs (HsType GhcPs)
t LHsDoc GhcPs
str ->
    case TypeDocStyle
docStyle of
      TypeDocStyle
PipeStyle -> do
        HaddockStyle -> Bool -> LHsDoc GhcPs -> R ()
p_hsDoc HaddockStyle
Pipe Bool
True LHsDoc GhcPs
str
        forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
t HsType GhcPs -> R ()
p_hsType
      TypeDocStyle
CaretStyle -> do
        forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
t HsType GhcPs -> R ()
p_hsType
        R ()
newline
        HaddockStyle -> Bool -> LHsDoc GhcPs -> R ()
p_hsDoc HaddockStyle
Caret Bool
False LHsDoc GhcPs
str
  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 #-}" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space
      SrcUnpackedness
SrcNoUnpack -> Text -> R ()
txt Text
"{-# NOUNPACK #-}" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space
      SrcUnpackedness
NoSrcUnpack -> 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 -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (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 -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
    BracketStyle -> R () -> R ()
brackets BracketStyle
N forall a b. (a -> b) -> a -> b
$ do
      -- If both this list itself and the first element is promoted,
      -- we need to put a space in between or it fails to parse.
      case (PromotionFlag
p, HsContext GhcPs
xs) of
        (PromotionFlag
IsPromoted, L SrcSpanAnnA
_ HsType GhcPs
t : [GenLocated SrcSpanAnnA (HsType GhcPs)]
_) | HsType GhcPs -> Bool
isPromoted HsType GhcPs
t -> R ()
space
        (PromotionFlag, [GenLocated SrcSpanAnnA (HsType GhcPs)])
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
      forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
commaDel (R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext GhcPs
xs
  HsExplicitTupleTy XExplicitTupleTy GhcPs
_ HsContext GhcPs
xs -> do
    Text -> R ()
txt Text
"'"
    BracketStyle -> R () -> R ()
parens BracketStyle
N forall a b. (a -> b) -> a -> b
$ do
      case HsContext GhcPs
xs of
        L SrcSpanAnnA
_ HsType GhcPs
t : HsContext GhcPs
_ | HsType GhcPs -> Bool
isPromoted HsType GhcPs
t -> R ()
space
        HsContext GhcPs
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
      forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
commaDel (forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext GhcPs
xs
  HsTyLit XTyLit GhcPs
_ HsTyLit
t ->
    case HsTyLit
t of
      HsStrTy (SourceText String
s) FastString
_ -> String -> R ()
p_stringLit String
s
      HsTyLit
a -> forall a. Outputable a => a -> R ()
atom HsTyLit
a
  HsWildCardTy XWildCardTy GhcPs
_ -> Text -> R ()
txt Text
"_"
  XHsType XXType GhcPs
t -> forall a. Outputable a => a -> R ()
atom XXType GhcPs
t
  where
    isPromoted :: HsType GhcPs -> Bool
isPromoted = \case
      HsAppTy XAppTy GhcPs
_ (L SrcSpanAnnA
_ HsType GhcPs
f) XRec GhcPs (HsType GhcPs)
_ -> HsType GhcPs -> Bool
isPromoted HsType GhcPs
f
      HsTyVar XTyVar GhcPs
_ PromotionFlag
IsPromoted LIdP GhcPs
_ -> Bool
True
      HsExplicitTupleTy {} -> Bool
True
      HsExplicitListTy {} -> 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 HsType GhcPs
m = Bool -> TypeDocStyle -> HsType GhcPs -> R ()
p_hsType' Bool
multilineArgs TypeDocStyle
docStyle HsType GhcPs
m

startTypeAnnotation ::
  HasSrcSpan l =>
  GenLocated l a ->
  (a -> R ()) ->
  R ()
startTypeAnnotation :: forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation = forall l a.
HasSrcSpan l =>
R () -> R () -> GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation' R ()
breakpoint R ()
breakpoint

startTypeAnnotationDecl ::
  HasSrcSpan l =>
  GenLocated l a ->
  (a -> HsType GhcPs) ->
  (a -> R ()) ->
  R ()
startTypeAnnotationDecl :: forall l a.
HasSrcSpan l =>
GenLocated l a -> (a -> HsType GhcPs) -> (a -> R ()) -> R ()
startTypeAnnotationDecl GenLocated l a
lItem a -> HsType GhcPs
getType =
  forall l a.
HasSrcSpan l =>
R () -> R () -> GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation'
    ( if HsType GhcPs -> Bool
hasDocStrings forall a b. (a -> b) -> a -> b
$ a -> HsType GhcPs
getType forall a b. (a -> b) -> a -> b
$ forall l e. GenLocated l e -> e
unLoc GenLocated l a
lItem
        then R ()
newline
        else R ()
breakpoint
    )
    R ()
breakpoint
    GenLocated l a
lItem

startTypeAnnotation' ::
  HasSrcSpan l =>
  R () ->
  R () ->
  GenLocated l a ->
  (a -> R ()) ->
  R ()
startTypeAnnotation' :: forall l a.
HasSrcSpan l =>
R () -> R () -> GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation' R ()
breakTrailing R ()
breakLeading GenLocated l a
lItem a -> R ()
renderItem =
  forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    FunctionArrowsStyle
TrailingArrows -> do
      R ()
space
      R ()
token'dcolon
      R ()
breakTrailing
      forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located GenLocated l a
lItem a -> R ()
renderItem
    FunctionArrowsStyle
LeadingArrows -> do
      R ()
breakLeading
      forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located GenLocated l a
lItem forall a b. (a -> b) -> a -> b
$ \a
item -> do
        R ()
token'dcolon
        R ()
space
        a -> R ()
renderItem a
item
    FunctionArrowsStyle
LeadingArgsArrows -> do
      R ()
space
      R ()
token'dcolon
      R ()
breakTrailing
      forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located GenLocated l a
lItem a -> R ()
renderItem

-- | 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] -> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
x HsType GhcPs -> R ()
p_hsType
  HsContext GhcPs
xs -> BracketStyle -> R () -> R ()
parens BracketStyle
N forall a b. (a -> b) -> a -> b
$ forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
commaDel (R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' HsType GhcPs -> R ()
p_hsType) HsContext 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 forall flag. IsInferredTyVarBndr flag => flag -> Bool
isInferred flag
flag then BracketStyle -> R () -> R ()
braces BracketStyle
N else forall a. a -> a
id) forall a b. (a -> b) -> a -> b
$ LocatedN RdrName -> R ()
p_rdrName LIdP GhcPs
x
  KindedTyVar XKindedTyVar GhcPs
_ flag
flag LIdP GhcPs
l XRec GhcPs (HsType GhcPs)
k -> (if forall flag. IsInferredTyVarBndr flag => flag -> Bool
isInferred flag
flag then BracketStyle -> R () -> R ()
braces else BracketStyle -> R () -> R ()
parens) BracketStyle
N forall b c a. (b -> c) -> (a -> b) -> a -> c
. R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ do
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located LIdP GhcPs
l forall a. Outputable a => a -> R ()
atom
    R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
startTypeAnnotation XRec GhcPs (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
vis a -> R ()
p [GenLocated l a]
tyvars = do
  forall l a. HasSrcSpan l => (a -> R ()) -> [GenLocated l a] -> R ()
p_forallBndrsStart a -> R ()
p [GenLocated l a]
tyvars
  ForAllVisibility -> R ()
p_forallBndrsEnd ForAllVisibility
vis

p_forallBndrsStart :: HasSrcSpan l => (a -> R ()) -> [GenLocated l a] -> R ()
p_forallBndrsStart :: forall l a. HasSrcSpan l => (a -> R ()) -> [GenLocated l a] -> R ()
p_forallBndrsStart a -> R ()
_ [] = R ()
token'forall
p_forallBndrsStart a -> R ()
p [GenLocated l a]
tyvars = do
  [SrcSpan] -> R () -> R ()
switchLayout (forall l a. HasSrcSpan l => GenLocated l a -> SrcSpan
getLoc' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [GenLocated l a]
tyvars) forall a b. (a -> b) -> a -> b
$ do
    R ()
token'forall
    R ()
breakpoint
    R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ do
      R () -> R ()
sitcc forall a b. (a -> b) -> a -> b
$ forall a. R () -> (a -> R ()) -> [a] -> R ()
sep R ()
breakpoint (R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' a -> R ()
p) [GenLocated l a]
tyvars

p_forallBndrsEnd :: ForAllVisibility -> R ()
p_forallBndrsEnd :: ForAllVisibility -> R ()
p_forallBndrsEnd ForAllVisibility
ForAllInvis = Text -> R ()
txt Text
"." forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
space
p_forallBndrsEnd ForAllVisibility
ForAllVis = R ()
space forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> R ()
token'rarrow

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

p_conDeclField :: ConDeclField GhcPs -> R ()
p_conDeclField :: ConDeclField GhcPs -> R ()
p_conDeclField ConDeclField {[LFieldOcc GhcPs]
Maybe (LHsDoc GhcPs)
XRec GhcPs (HsType GhcPs)
XConDeclField 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)
cd_fld_doc :: Maybe (LHsDoc GhcPs)
cd_fld_type :: XRec GhcPs (HsType GhcPs)
cd_fld_names :: [LFieldOcc GhcPs]
cd_fld_ext :: XConDeclField GhcPs
..} = do
  CommaStyle
commaStyle <- forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f CommaStyle
poCommaStyle
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CommaStyle
commaStyle forall a. Eq a => a -> a -> Bool
== CommaStyle
Trailing) forall a b. (a -> b) -> a -> b
$
    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 forall a b. (a -> b) -> a -> b
$
    forall a. R () -> (a -> R ()) -> [a] -> R ()
sep
      R ()
commaDel
      (forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' (LocatedN RdrName -> R ()
p_rdrName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pass. FieldOcc pass -> XRec pass RdrName
foLabel))
      [LFieldOcc GhcPs]
cd_fld_names
  forall a. (forall (f :: * -> *). PrinterOpts f -> f a) -> R a
getPrinterOpt forall (f :: * -> *). PrinterOpts f -> f FunctionArrowsStyle
poFunctionArrows forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    FunctionArrowsStyle
LeadingArrows -> R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ do
      R ()
breakpoint
      R ()
token'dcolon
      R ()
space
      HsType GhcPs -> R ()
p_hsType (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
cd_fld_type)
    FunctionArrowsStyle
TrailingArrows -> do
      R ()
space
      R ()
token'dcolon
      R ()
breakpoint
      R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ HsType GhcPs -> R ()
p_hsType (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
cd_fld_type)
    FunctionArrowsStyle
LeadingArgsArrows -> do
      R ()
space
      R ()
token'dcolon
      R ()
breakpoint
      R () -> R ()
sitcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ HsType GhcPs -> R ()
p_hsType (forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
cd_fld_type)
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CommaStyle
commaStyle forall a. Eq a => a -> a -> Bool
== CommaStyle
Leading) forall a b. (a -> b) -> a -> b
$
    forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Int -> R () -> R ()
inciByFrac (-Int
1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (R ()
newline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. HaddockStyle -> Bool -> LHsDoc GhcPs -> R ()
p_hsDoc HaddockStyle
Caret Bool
False) Maybe (LHsDoc GhcPs)
cd_fld_doc

p_lhsTypeArg :: LHsTypeArg GhcPs -> R ()
p_lhsTypeArg :: LHsTypeArg GhcPs -> R ()
p_lhsTypeArg = \case
  HsValArg XRec GhcPs (HsType GhcPs)
ty -> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (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
"@" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located XRec GhcPs (HsType GhcPs)
ty HsType GhcPs -> R ()
p_hsType
  -- NOTE(amesgen) is this unreachable or just not implemented?
  HsArgPar SrcSpan
_ -> forall a. String -> a
notImplemented String
"HsArgPar"

p_hsSigType :: HsSigType GhcPs -> R ()
p_hsSigType :: HsSigType GhcPs -> R ()
p_hsSigType HsSig {HsOuterSigTyVarBndrs GhcPs
XRec GhcPs (HsType GhcPs)
XHsSig 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
sig_body :: XRec GhcPs (HsType GhcPs)
sig_bndrs :: HsOuterSigTyVarBndrs GhcPs
sig_ext :: XHsSig GhcPs
..} =
  HsType GhcPs -> R ()
p_hsType 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 -> forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar 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.
    forall pass. XParTy pass -> LHsType pass -> HsType pass
HsParTy forall ann. EpAnn ann
EpAnnNotUsed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a an. a -> LocatedAn an a
noLocA forall a b. (a -> b) -> a -> b
$
      forall pass.
XKindSig pass -> LHsType pass -> LHsType pass -> HsType pass
HsKindSig forall ann. EpAnn ann
EpAnnNotUsed (forall a an. a -> LocatedAn an a
noLocA (forall pass.
XTyVar pass -> PromotionFlag -> LIdP pass -> HsType pass
HsTyVar 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 :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit :: [LHsTyVarBndr () GhcPs]
hsq_ext :: XHsQTvs GhcPs
..} = forall tm ty. tm -> HsArg tm ty
HsValArg forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsTyVarBndr () GhcPs -> HsType GhcPs
tyVarToType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr () 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 NoExtField
XHsOuterImplicit GhcPs
NoExtField -> forall l e. GenLocated l e -> e
unLoc XRec GhcPs (HsType GhcPs)
ty
  HsOuterExplicit XHsOuterExplicit GhcPs Specificity
_ [LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
bndrs ->
    forall pass.
XForAllTy pass
-> HsForAllTelescope pass -> LHsType pass -> HsType pass
HsForAllTy NoExtField
NoExtField (forall (p :: Pass).
EpAnnForallTy
-> [LHsTyVarBndr Specificity (GhcPass p)]
-> HsForAllTelescope (GhcPass p)
mkHsForAllInvisTele forall ann. EpAnn ann
EpAnnNotUsed [LHsTyVarBndr Specificity (NoGhcTc 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 =
  forall e ann. Located e -> LocatedAn ann e
reLocA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. l -> e -> GenLocated l e
L (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA XRec GhcPs (HsType GhcPs)
ty) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pass.
XHsSig pass
-> HsOuterSigTyVarBndrs pass -> LHsType pass -> HsSigType pass
HsSig NoExtField
NoExtField (forall flag pass.
XHsOuterImplicit pass -> HsOuterTyVarBndrs flag pass
HsOuterImplicit NoExtField
NoExtField) forall a b. (a -> b) -> a -> b
$ XRec GhcPs (HsType GhcPs)
ty