ghc-7.4.1: The GHC API

Safe HaskellSafe-Infered

Outputable

Contents

Description

This module defines classes and functions for pretty-printing. It also exports a number of helpful debugging and other utilities such as trace and panic.

The interface to this module is very similar to the standard Hughes-PJ pretty printing module, except that it exports a number of additional functions that are rarely used, and works over the SDoc type.

Synopsis

Type classes

class Outputable a whereSource

Class designating that some type has an SDoc representation

Methods

ppr :: a -> SDocSource

pprPrec :: Rational -> a -> SDocSource

Instances

Outputable Bool 
Outputable Char 
Outputable Int 
Outputable Word 
Outputable Word16 
Outputable Word32 
Outputable () 
Outputable Fingerprint 
Outputable PackageId 
Outputable ModuleName 
Outputable Module 
Outputable FastString 
Outputable Name 
Outputable TyThing 
Outputable Type 
Outputable MetaDetails 
Outputable SrcSpan 
Outputable RealSrcSpan 
Outputable SrcLoc 
Outputable RealSrcLoc 
Outputable FractionalLit 
Outputable InlineSpec 
Outputable InlinePragma 
Outputable RuleMatchInfo 
Outputable Activation 
Outputable CompilerPhase 
Outputable SuccessFlag 
Outputable DefMethSpec 
Outputable StrictnessMark 
Outputable HsBang 
Outputable OccInfo 
Outputable OverlapFlag 
Outputable RecFlag 
Outputable TopLevelFlag 
Outputable FixityDirection 
Outputable Fixity 
Outputable WarningTxt 
Outputable FunctionOrData 
Outputable Unique 
Outputable IdDetails 
Outputable ArgDescr 
Outputable ClosureTypeInfo 
Outputable SMRep 
Outputable Phase 
Outputable OccName 
Outputable ModLocation 
Outputable Var 
Outputable TyCon 
Outputable DefMeth 
Outputable Class 
Outputable DataCon 
Outputable CostCentreStack 
Outputable CostCentre 
Outputable ImportSpec 
Outputable Parent 
Outputable GlobalRdrElt 
Outputable RdrName 
Outputable PrimRep 
Outputable CoAxiom 
Outputable TyConParent 
Outputable CCallConv 
Outputable CCallSpec 
Outputable CExportSpec 
Outputable Safety 
Outputable ForeignCall 
Outputable Serialized 
Outputable Annotation 
Outputable InScopeSet 
Outputable TvSubst 
Outputable Literal 
Outputable VolatileLoc 
Outputable AvailInfo 
Outputable StrictSig 
Outputable DmdResult 
Outputable DmdType 
Outputable Demands 
Outputable Demand 
Outputable Width 
Outputable CmmCat 
Outputable CmmType 
Outputable OverLitVal 
Outputable HsLit 
Outputable HsDocString 
Outputable RegClass 
Outputable Reg

Print a reg in a generic manner If you want the architecture specific names, then use the pprReg function from the appropriate Ppr module.

Outputable RealReg 
Outputable VirtualReg 
Outputable GhcMode 
Outputable SafeHaskellMode 
Outputable CvSubst 
Outputable Coercion 
Outputable UnfoldingGuidance 
Outputable UnfoldingSource 
Outputable Unfolding 
Outputable CoreVect 
Outputable CoreRule 
Outputable AltCon 
Outputable PrimCall 
Outputable PrimOp 
Outputable TickBoxOp 
Outputable LBVarInfo 
Outputable CafInfo 
Outputable ClsInstEnv 
Outputable Instance 
Outputable FamilyInstEnv 
Outputable FamInst 
Outputable CoreStats 
Outputable EvTerm 
Outputable EvBind 
Outputable EvBindsVar 
Outputable TcEvBinds 
Outputable HsWrapper 
Outputable TcCoercion 
Outputable TcSpecPrag 
Outputable OccEncl 
Outputable Details 
Outputable DocDecl 
Outputable ForeignExport 
Outputable ForeignImport 
Outputable NewOrData 
Outputable IfaceCoCon 
Outputable IfaceTyCon 
Outputable IfaceType 
Outputable IfaceBndr 
Outputable IfaceConAlt 
Outputable IfaceExpr 
Outputable IfaceUnfolding 
Outputable IfaceInfoItem 
Outputable IfaceIdInfo 
Outputable IfaceIdDetails 
Outputable IfaceRule 
Outputable IfaceFamInst 
Outputable IfaceInst 
Outputable IfaceATDefault 
Outputable IfaceAT 
Outputable IfaceClassOp 
Outputable IfaceDecl 
Outputable Subst 
Outputable EtaInfo 
Outputable ArgSummary 
Outputable CallCtxt 
Outputable ExprSize 
Outputable AnalEnv 
Outputable ForeignLabelSource 
Outputable BlockSet 
Outputable BlockId 
Outputable GlobalReg 
Outputable LocalReg 
Outputable Area 
Outputable CmmReg 
Outputable ForeignHint 
Outputable ForeignConvention 
Outputable Convention 
Outputable CmmStackInfo 
Outputable DualLive 
Outputable ParamLocation 
Outputable UpdateFlag 
Outputable AltType 
Outputable CgRep 
Outputable Protocol 
Outputable Status 
Outputable BreakInfo 
Outputable BCInstr 
Outputable UnlinkedBCO 
Outputable CompiledByteCode 
Outputable Unlinked 
Outputable Linkable 
Outputable IfaceTrustInfo 
Outputable VectInfo 
Outputable ModSummary 
Outputable FixItem 
Outputable Warnings 
Outputable InteractiveImport 
Outputable TargetId 
Outputable Target 
Outputable FloatBind 
Outputable EqOrigin 
Outputable CtOrigin 
Outputable SkolemInfo 
Outputable CtFlavor 
Outputable Implication 
Outputable Untouchables 
Outputable WantedConstraints 
Outputable Ct 
Outputable WhereFrom 
Outputable TcTyThing 
Outputable ThStage 
Outputable TcTyVarBind 
Outputable ZonkEnv 
Outputable Discr 
Outputable ArgRep 
Outputable EquationInfo 
Outputable CompRepr 
Outputable ProdRepr 
Outputable ConRepr 
Outputable SumRepr 
Outputable MetaTyCons 
Outputable SimplContext 
Outputable InertSet 
Outputable WorkList 
Outputable SwapFlag 
Outputable ExpKind 
Outputable TcSigInfo 
Outputable StopOrContinue 
Outputable GeneralisationPlan 
Outputable Tick 
Outputable FloatOutSwitches 
Outputable SimplifierMode 
Outputable CoreToDo 
Outputable OkToSpec 
Outputable Floats 
Outputable FloatingBind 
Outputable FloatSpec 
Outputable Level 
Outputable FloatBinds 
Outputable FloatFlag 
Outputable Floats 
Outputable SimplSR 
Outputable DupFlag 
Outputable SimplCont 
Outputable CallInfoSet 
Outputable CallKey 
Outputable UsageDetails 
Outputable ArgOcc 
Outputable HowBound 
Outputable Value 
Outputable ClosureType 
Outputable Term 
Outputable DerivSpec 
Outputable IfaceDeclExtras 
Outputable SpillStats 
Outputable Store 
Outputable Loc 
Outputable CoreModule 
Outputable a => Outputable [a] 
Outputable a => Outputable (Maybe a) 
Outputable elt => Outputable (IntMap elt) 
Outputable a => Outputable (Set a) 
OutputableBndr name => Outputable (Pat name) 
Outputable name => Outputable (IPName name) 
Outputable a => Outputable (Bag a) 
Outputable a => Outputable (Pair a) 
Outputable a => Outputable (UniqFM a) 
Outputable a => Outputable (OccEnv a) 
Outputable name => Outputable (AnnTarget name) 
Outputable a => Outputable (SCC a) 
Outputable node => Outputable (Edge node) 
Outputable node => Outputable (Graph node) 
OutputableBndr id => Outputable (HsSplice id) 
OutputableBndr id => Outputable (HsExpr id) 
OutputableBndr id => Outputable (HsOverLit id) 
OutputableBndr name => Outputable (HsTyVarBndr name) 
OutputableBndr name => Outputable (HsType name) 
OutputableBndr id => Outputable (HsQuasiQuote id) 
(OutputableBndr name, Outputable name) => Outputable (IE name) 
OutputableBndr name => Outputable (ImportDecl name) 
Outputable b => Outputable (TaggedBndr b) 
Outputable id => Outputable (Tickish id) 
OutputableBndr b => Outputable (Bind b) 
OutputableBndr b => Outputable (Expr b) 
Outputable name => Outputable (FixitySig name) 
OutputableBndr name => Outputable (Sig name) 
OutputableBndr id => Outputable (IPBind id) 
OutputableBndr id => Outputable (HsIPBinds id) 
OutputableBndr id => Outputable (ABExport id) 
Outputable a => Outputable (TypeMap a) 
Outputable a => Outputable (CoreMap a) 
OutputableBndr name => Outputable (AnnDecl name) 
OutputableBndr name => Outputable (WarnDecl name) 
OutputableBndr name => Outputable (VectDecl name) 
OutputableBndr name => Outputable (RuleBndr name) 
OutputableBndr name => Outputable (RuleDecl name) 
OutputableBndr name => Outputable (ForeignDecl name) 
OutputableBndr name => Outputable (DefaultDecl name) 
OutputableBndr name => Outputable (DerivDecl name) 
OutputableBndr name => Outputable (InstDecl name) 
OutputableBndr name => Outputable (ResType name) 
OutputableBndr name => Outputable (ConDecl name) 
OutputableBndr name => Outputable (TyClDecl name) 
OutputableBndr name => Outputable (SpliceDecl name) 
OutputableBndr name => Outputable (HsGroup name) 
OutputableBndr name => Outputable (HsDecl name) 
OutputableBndr id => Outputable (ArithSeqInfo id) 
OutputableBndr id => Outputable (HsBracket id) 
OutputableBndr id => Outputable (HsCmdTop id) 
OutputableBndr name => Outputable (HsModule name) 
Outputable a => Outputable (BlockEnv a) 
Outputable bdee => Outputable (GenStgArg bdee) 
Outputable a => Outputable (CmmHinted a) 
Outputable a => Outputable (ProtoBCO a) 
Outputable (EvVarX a) 
Outputable a => Outputable (NonVoid a) 
(Outputable a, Outputable b) => Outputable (Either a b) 
(Outputable a, Outputable b) => Outputable (a, b) 
(Outputable key, Outputable elt) => Outputable (Map key elt) 
(Outputable l, Outputable e) => Outputable (GenLocated l e) 
(OutputableBndr idL, OutputableBndr idR) => Outputable (HsBindLR idL idR) 
(OutputableBndr idL, OutputableBndr idR) => Outputable (HsValBindsLR idL idR) 
(OutputableBndr idL, OutputableBndr idR) => Outputable (HsLocalBindsLR idL idR) 
(OutputableBndr id, Outputable arg) => Outputable (HsRecField id arg) 
(OutputableBndr id, Outputable arg) => Outputable (HsRecFields id arg) 
(OutputableBndr idL, OutputableBndr idR) => Outputable (StmtLR idL idR) 
(Outputable bndr, Outputable bdee, Ord bdee) => Outputable (GenStgRhs bndr bdee) 
(Outputable bndr, Outputable bdee, Ord bdee) => Outputable (GenStgExpr bndr bdee) 
(Outputable bndr, Outputable bdee, Ord bdee) => Outputable (GenStgBinding bndr bdee) 
(Outputable a, Outputable b, Outputable c) => Outputable (a, b, c) 
(Outputable a, Outputable b, Outputable c, Outputable d) => Outputable (a, b, c, d) 
(Outputable a, Outputable b, Outputable c, Outputable d, Outputable e) => Outputable (a, b, c, d, e) 
(Outputable a, Outputable b, Outputable c, Outputable d, Outputable e, Outputable f) => Outputable (a, b, c, d, e, f) 
(Outputable a, Outputable b, Outputable c, Outputable d, Outputable e, Outputable f, Outputable g) => Outputable (a, b, c, d, e, f, g) 

class Outputable a => OutputableBndr a whereSource

When we print a binder, we often want to print its type too. The OutputableBndr class encapsulates this idea.

class PlatformOutputable a whereSource

Instances

PlatformOutputable Int 
PlatformOutputable () 
PlatformOutputable StableLoc 
PlatformOutputable CgIdInfo 
PlatformOutputable CLabel 
PlatformOutputable LocalReg 
PlatformOutputable CmmLit 
PlatformOutputable CmmExpr 
PlatformOutputable ForeignHint 
PlatformOutputable ForeignTarget 
PlatformOutputable CmmStatics 
PlatformOutputable CmmStatic 
PlatformOutputable C_SRT 
PlatformOutputable CmmInfoTable 
PlatformOutputable CmmTopInfo 
PlatformOutputable CmmGraph 
PlatformOutputable CmmSafety 
PlatformOutputable CmmStmt 
PlatformOutputable CmmInfo 
PlatformOutputable CgLoc 
PlatformOutputable CgIdInfo 
PlatformOutputable TopSRT 
PlatformOutputable LiveInfo 
PlatformOutputable Instr 
PlatformOutputable Instr 
PlatformOutputable Instr 
PlatformOutputable a => PlatformOutputable [a] 
PlatformOutputable a => PlatformOutputable (Maybe a) 
PlatformOutputable a => PlatformOutputable (SCC a) 
PlatformOutputable a => PlatformOutputable (CmmHinted a) 
PlatformOutputable instr => PlatformOutputable (GenBasicBlock instr) 
PlatformOutputable instr => PlatformOutputable (ListGraph instr) 
PlatformOutputable instr => PlatformOutputable (LiveInstr instr) 
PlatformOutputable instr => PlatformOutputable (InstrSR instr) 
(PlatformOutputable a, PlatformOutputable b) => PlatformOutputable (a, b) 
(PlatformOutputable key, PlatformOutputable elt) => PlatformOutputable (Map key elt) 
PlatformOutputable (CmmNode e x) 
(PlatformOutputable statics, PlatformOutputable instr) => PlatformOutputable (RegAllocStats statics instr) 
PlatformOutputable (Block CmmNode O O) 
PlatformOutputable (Block CmmNode O C) 
PlatformOutputable (Block CmmNode C O) 
PlatformOutputable (Block CmmNode C C) 
PlatformOutputable (Graph CmmNode e x) 
(PlatformOutputable d, PlatformOutputable info, PlatformOutputable i) => PlatformOutputable (GenCmmDecl d info i) 

Pretty printing combinators

runSDoc :: SDoc -> SDocContext -> DocSource

interppSP :: Outputable a => [a] -> SDocSource

Returns the seperated concatenation of the pretty printed things.

interpp'SP :: Outputable a => [a] -> SDocSource

Returns the comma-seperated concatenation of the pretty printed things.

pprQuotedList :: Outputable a => [a] -> SDocSource

Returns the comma-seperated concatenation of the quoted pretty printed things.

 [x,y,z]  ==>  `x', `y', `z'

pprWithCommasSource

Arguments

:: (a -> SDoc)

The pretty printing function to use

-> [a]

The things to be pretty printed

-> SDoc

SDoc where the things have been pretty printed, comma-separated and finally packed into a paragraph.

nest :: Int -> SDoc -> SDocSource

Indent SDoc some specified amount

(<>) :: SDoc -> SDoc -> SDocSource

Join two SDoc together horizontally without a gap

(<+>) :: SDoc -> SDoc -> SDocSource

Join two SDoc together horizontally with a gap between them

hcat :: [SDoc] -> SDocSource

Concatenate SDoc horizontally

hsep :: [SDoc] -> SDocSource

Concatenate SDoc horizontally with a space between each one

($$) :: SDoc -> SDoc -> SDocSource

Join two SDoc together vertically; if there is no vertical overlap it dovetails the two onto one line

($+$) :: SDoc -> SDoc -> SDocSource

Join two SDoc together vertically

vcat :: [SDoc] -> SDocSource

Concatenate SDoc vertically with dovetailing

sep :: [SDoc] -> SDocSource

Separate: is either like hsep or like vcat, depending on what fits

cat :: [SDoc] -> SDocSource

Catenate: is either like hcat or like vcat, depending on what fits

fsep :: [SDoc] -> SDocSource

A paragraph-fill combinator. It's much like sep, only it keeps fitting things on one line until it can't fit any more.

fcat :: [SDoc] -> SDocSource

This behaves like fsep, but it uses <> for horizontal conposition rather than <+>

hangSource

Arguments

:: SDoc

The header

-> Int

Amount to indent the hung body

-> SDoc

The hung body, indented and placed below the header

-> SDoc 

punctuateSource

Arguments

:: SDoc

The punctuation

-> [SDoc]

The list that will have punctuation added between every adjacent pair of elements

-> [SDoc]

Punctuated list

speakNth :: Int -> SDocSource

Converts an integer to a verbal index:

 speakNth 1 = text "first"
 speakNth 5 = text "fifth"
 speakNth 21 = text "21st"

speakNTimes :: Int -> SDocSource

Converts a strictly positive integer into a number of times:

 speakNTimes 1 = text "once"
 speakNTimes 2 = text "twice"
 speakNTimes 4 = text "4 times"

speakN :: Int -> SDocSource

Converts an integer to a verbal multiplicity:

 speakN 0 = text "none"
 speakN 5 = text "five"
 speakN 10 = text "10"

speakNOf :: Int -> SDoc -> SDocSource

Converts an integer and object description to a statement about the multiplicity of those objects:

 speakNOf 0 (text "melon") = text "no melons"
 speakNOf 1 (text "melon") = text "one melon"
 speakNOf 3 (text "melon") = text "three melons"

plural :: [a] -> SDocSource

Determines the pluralisation suffix appropriate for the length of a list:

 plural [] = char 's'
 plural ["Hello"] = empty
 plural ["Hello", "World"] = char 's'

coloured :: PprColour -> SDoc -> SDocSource

Apply the given colour/style for the argument.

Only takes effect if colours are enabled.

data PprColour Source

A colour/style for use with coloured.

Converting SDoc into strings and outputing it

pprHsChar :: Char -> SDocSource

Special combinator for showing character literals.

pprHsString :: FastString -> SDocSource

Special combinator for showing string literals.

Controlling the style in which output is printed

data BindingSite Source

BindingSite is used to tell the thing that prints binder what language construct is binding the identifier. This can be used to decide how much info to print.

Constructors

LambdaBind 
CaseBind 
LetBind 

data CodeStyle Source

Constructors

CStyle 
AsmStyle 

type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)Source

qualName :: PprStyle -> QueryQualifyNameSource

qualModule :: PprStyle -> QueryQualifyModuleSource

mkErrStyle :: PrintUnqualified -> PprStyleSource

Style for printing error messages

data Depth Source

Constructors

AllTheWay 
PartWay Int 

Error handling and debugging utilities

pprPanic :: String -> SDoc -> aSource

Throw an exception saying bug in GHC

pprSorry :: String -> SDoc -> aSource

Throw an exception saying this isn't finished yet

assertPprPanic :: String -> Int -> SDoc -> aSource

Panic with an assertation failure, recording the given file and line number. Should typically be accessed with the ASSERT family of macros

pprPanicFastInt :: String -> SDoc -> FastIntSource

Specialization of pprPanic that can be safely used with FastInt

pprPgmError :: String -> SDoc -> aSource

Throw an exception saying bug in pgm being compiled (used for unusual program errors)

pprTrace :: String -> SDoc -> a -> aSource

If debug output is on, show some SDoc on the screen

pprDefiniteTrace :: String -> SDoc -> a -> aSource

Same as pprTrace, but show even if -dno-debug-output is on

warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> aSource

Just warn about an assertion failure, recording the given file and line number. Should typically be accessed with the WARN macros

trace :: String -> a -> aSource

The trace function outputs the trace message given as its first argument, before returning the second argument as its result.

For example, this returns the value of f x but first outputs the message.

 trace ("calling f with x = " ++ show x) (f x)

The trace function should only be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message.

panic, pgmError, sorry :: String -> aSource

Panics and asserts.

panicFastInt :: String -> FastIntSource

Panic while pretending to return an unboxed int. You can't use the regular panic functions in expressions producing unboxed ints because they have the wrong kind.

assertPanic :: String -> Int -> aSource

Throw an failed assertion exception for a given filename and line number.