ghc-8.4.3: The GHC API

Safe HaskellNone
LanguageHaskell2010

HsUtils

Contents

Synopsis

Documentation

mkHsPar :: LHsExpr id -> LHsExpr id #

mkHsApp :: LHsExpr name -> LHsExpr name -> LHsExpr name #

mkHsAppType :: LHsExpr name -> LHsWcType name -> LHsExpr name #

mkHsAppTypes :: LHsExpr name -> [LHsWcType name] -> LHsExpr name #

mkHsCaseAlt :: LPat id -> Located (body id) -> LMatch id (Located (body id)) #

A simple case alternative with a single pattern, no binds, no guards; pre-typechecking

mkSimpleMatch :: HsMatchContext (NameOrRdrName (IdP id)) -> [LPat id] -> Located (body id) -> LMatch id (Located (body id)) #

unguardedGRHSs :: Located (body id) -> GRHSs id (Located (body id)) #

unguardedRHS :: SrcSpan -> Located (body id) -> [LGRHS id (Located (body id))] #

mkMatchGroup :: PostTc name Type ~ PlaceHolder => Origin -> [LMatch name (Located (body name))] -> MatchGroup name (Located (body name)) #

mkPrefixFunRhs :: Located id -> HsMatchContext id #

Make a prefix, non-strict function HsMatchContext

mkHsIf :: SourceTextX p => LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p #

mkHsOpApp :: LHsExpr id -> IdP id -> LHsExpr id -> HsExpr id #

mkHsWrapPat :: HsWrapper -> Pat id -> Type -> Pat id #

mkLHsPar :: LHsExpr name -> LHsExpr name #

nlHsTyApp :: IdP name -> [Type] -> LHsExpr name #

nlHsTyApps :: IdP name -> [Type] -> [LHsExpr name] -> LHsExpr name #

nlHsVar :: IdP id -> LHsExpr id #

nlHsApp :: LHsExpr id -> LHsExpr id -> LHsExpr id #

nlHsApps :: IdP id -> [LHsExpr id] -> LHsExpr id #

nlHsVarApps :: IdP id -> [IdP id] -> LHsExpr id #

nlHsOpApp :: LHsExpr id -> IdP id -> LHsExpr id -> LHsExpr id #

nlHsPar :: LHsExpr id -> LHsExpr id #

nlHsIf :: LHsExpr id -> LHsExpr id -> LHsExpr id -> LHsExpr id #

typeToLHsType :: Type -> LHsType GhcPs #

Converting a Type to an HsType RdrName This is needed to implement GeneralizedNewtypeDeriving.

Note that we use getRdrName extensively, which generates Exact RdrNames rather than strings.

Constructing general big tuples

GHCs built in tuples can only go up to mAX_TUPLE_SIZE in arity, but we might concievably want to build such a massive tuple as part of the output of a desugaring stage (notably that for list comprehensions).

We call tuples above this size "big tuples", and emulate them by creating and pattern matching on >nested< tuples that are expressible by GHC.

Nesting policy: it's better to have a 2-tuple of 10-tuples (3 objects) than a 10-tuple of 2-tuples (11 objects), so we want the leaves of any construction to be big.

If you just use the mkBigCoreTup, mkBigCoreVarTupTy, mkTupleSelector and mkTupleCase functions to do all your work with tuples you should be fine, and not have to worry about the arity limitation at all.

mkChunkified #

Arguments

:: ([a] -> a)

"Small" constructor function, of maximum input arity mAX_TUPLE_SIZE

-> [a]

Possible "big" list of things to construct from

-> a

Constructed thing made possible by recursive decomposition

Lifts a "small" constructor into a "big" constructor by recursive decompositon

chunkify :: [a] -> [[a]] #

Split a list into lists that are small enough to have a corresponding tuple arity. The sub-lists of the result all have length <= mAX_TUPLE_SIZE But there may be more than mAX_TUPLE_SIZE sub-lists

mkVarBind :: IdP p -> LHsExpr p -> LHsBind p #

isInfixFunBind :: HsBindLR id1 id2 -> Bool #

If any of the matches in the FunBind are infix, the FunBind is considered infix.

nlVarPat :: IdP id -> LPat id #

nlLitPat :: HsLit p -> LPat p #

nlInfixConPat :: IdP id -> LPat id -> LPat id -> LPat id #

nlTuplePat :: [LPat id] -> Boxity -> LPat id #

mkParPat :: LPat name -> LPat name #

nlParPat :: LPat name -> LPat name #

mkBigLHsVarTup :: [IdP id] -> LHsExpr id #

mkBigLHsVarPatTup :: [IdP id] -> LPat id #

mkBigLHsPatTup :: [LPat id] -> LPat id #

mkHsAppTy :: LHsType pass -> LHsType pass -> LHsType pass #

mkHsAppTys :: LHsType pass -> [LHsType pass] -> LHsType pass #

userHsTyVarBndrs :: SrcSpan -> [IdP name] -> [LHsTyVarBndr name] #

mkHsSigEnv :: forall a. (LSig GhcRn -> Maybe ([Located Name], a)) -> [LSig GhcRn] -> NameEnv a #

nlHsAppTy :: LHsType name -> LHsType name -> LHsType name #

nlHsTyVar :: IdP name -> LHsType name #

nlHsFunTy :: LHsType name -> LHsType name -> LHsType name #

nlHsParTy :: LHsType name -> LHsType name #

nlHsTyConApp :: IdP name -> [LHsType name] -> LHsType name #

mkTransformStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => [ExprLStmt idL] -> LHsExpr idR -> StmtLR idL idR (LHsExpr idL) #

mkTransformByStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => [ExprLStmt idL] -> LHsExpr idR -> LHsExpr idR -> StmtLR idL idR (LHsExpr idL) #

mkBodyStmt :: Located (bodyR GhcPs) -> StmtLR idL GhcPs (Located (bodyR GhcPs)) #

mkBindStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => LPat idL -> Located (bodyR idR) -> StmtLR idL idR (Located (bodyR idR)) #

mkLastStmt :: SourceTextX idR => Located (bodyR idR) -> StmtLR idL idR (Located (bodyR idR)) #

emptyTransStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => StmtLR idL idR (LHsExpr idR) #

mkGroupUsingStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => [ExprLStmt idL] -> LHsExpr idR -> StmtLR idL idR (LHsExpr idL) #

mkGroupByUsingStmt :: (SourceTextX idR, PostTc idR Type ~ PlaceHolder) => [ExprLStmt idL] -> LHsExpr idR -> LHsExpr idR -> StmtLR idL idR (LHsExpr idL) #

emptyRecStmt :: StmtLR idL GhcPs bodyR #

mkRecStmt :: [LStmtLR idL GhcPs bodyR] -> StmtLR idL GhcPs bodyR #

isUnliftedHsBind :: HsBind GhcTc -> Bool #

Should we treat this as an unlifted bind? This will be true for any bind that binds an unlifted variable, but we must be careful around AbsBinds. See Note [Unlifted id check in isUnliftedHsBind]. For usage information, see Note [Strict binds check] is DsBinds.

isBangedHsBind :: HsBind GhcTc -> Bool #

Is a binding a strict variable or pattern bind (e.g. !x = ...)?

collectHsBindListBinders :: [LHsBindLR idL idR] -> [IdP idL] #

collectHsIdBinders :: HsValBindsLR idL idR -> [IdP idL] #

collectHsBindBinders :: HsBindLR idL idR -> [IdP idL] #

collectLStmtsBinders :: [LStmtLR idL idR body] -> [IdP idL] #

collectStmtsBinders :: [StmtLR idL idR body] -> [IdP idL] #

collectLStmtBinders :: LStmtLR idL idR body -> [IdP idL] #

collectStmtBinders :: StmtLR idL idR body -> [IdP idL] #

hsLTyClDeclBinders :: Located (TyClDecl pass) -> ([Located (IdP pass)], [LFieldOcc pass]) #

Returns all the binding names of the decl. The first one is guaranteed to be the name of the decl. The first component represents all binding names except record fields; the second represents field occurrences. For record fields mentioned in multiple constructors, the SrcLoc will be from the first occurrence.

Each returned (Located name) has a SrcSpan for the whole declaration. See Note [SrcSpan for binders]

hsDataDefnBinders :: HsDataDefn pass -> ([Located (IdP pass)], [LFieldOcc pass]) #

lStmtsImplicits :: [LStmtLR GhcRn idR (Located (body idR))] -> NameSet #