diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2017-08-30 08:57:40 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2017-08-31 08:16:58 +0100 |
commit | 805b29bb873c792ca5bcbd5540026848f9f11a8d (patch) | |
tree | 993291054fd388c0e493d11175ec27922d61bb1f /compiler/hsSyn/HsExpr.hs | |
parent | fca196280d38d07a697fbccdd8527821206b33eb (diff) | |
download | haskell-805b29bb873c792ca5bcbd5540026848f9f11a8d.tar.gz |
Add debugPprType
We pretty-print a type by converting it to an IfaceType and
pretty-printing that. But
(a) that's a bit indirect, and
(b) delibrately loses information about (e.g.) the kind
on the /occurrences/ of a type variable
So this patch implements debugPprType, which pretty prints
the type directly, with no fancy formatting. It's just used
for debugging.
I took the opportunity to refactor the debug-pretty-printing
machinery a little. In particular, define these functions
and use them:
ifPprDeubug :: SDoc -> SDOc -> SDoc
-- Says what to do with and without -dppr-debug
whenPprDebug :: SDoc -> SDoc
-- Says what to do with -dppr-debug; without is empty
getPprDebug :: (Bool -> SDoc) -> SDoc
getPprDebug used to be called sdocPprDebugWith
whenPprDebug used to be called ifPprDebug
So a lot of files get touched in a very mechanical way
Diffstat (limited to 'compiler/hsSyn/HsExpr.hs')
-rw-r--r-- | compiler/hsSyn/HsExpr.hs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs index 03df7ccade..2186a728f2 100644 --- a/compiler/hsSyn/HsExpr.hs +++ b/compiler/hsSyn/HsExpr.hs @@ -1944,7 +1944,7 @@ pprStmt :: forall idL idR body . (SourceTextX idL, SourceTextX idR, Outputable body) => (StmtLR idL idR body) -> SDoc pprStmt (LastStmt expr ret_stripped _) - = ifPprDebug (text "[last]") <+> + = whenPprDebug (text "[last]") <+> (if ret_stripped then text "return" else empty) <+> ppr expr pprStmt (BindStmt pat expr _ _ _) = hsep [ppr pat, larrow, ppr expr] @@ -1959,7 +1959,7 @@ pprStmt (RecStmt { recS_stmts = segment, recS_rec_ids = rec_ids , recS_later_ids = later_ids }) = text "rec" <+> vcat [ ppr_do_stmts segment - , ifPprDebug (vcat [ text "rec_ids=" <> ppr rec_ids + , whenPprDebug (vcat [ text "rec_ids=" <> ppr rec_ids , text "later_ids=" <> ppr later_ids])] pprStmt (ApplicativeStmt args mb_join _) @@ -2007,7 +2007,7 @@ pprStmt (ApplicativeStmt args mb_join _) pprTransformStmt :: (SourceTextX p, OutputableBndrId p) => [IdP p] -> LHsExpr p -> Maybe (LHsExpr p) -> SDoc pprTransformStmt bndrs using by - = sep [ text "then" <+> ifPprDebug (braces (ppr bndrs)) + = sep [ text "then" <+> whenPprDebug (braces (ppr bndrs)) , nest 2 (ppr using) , nest 2 (pprBy by)] @@ -2263,14 +2263,14 @@ pprSplice (HsQuasiQuote n q _ s) = ppr_quasi n q s pprSplice (HsSpliced _ thing) = ppr thing ppr_quasi :: OutputableBndr p => p -> p -> FastString -> SDoc -ppr_quasi n quoter quote = ifPprDebug (brackets (ppr n)) <> +ppr_quasi n quoter quote = whenPprDebug (brackets (ppr n)) <> char '[' <> ppr quoter <> vbar <> ppr quote <> text "|]" ppr_splice :: (SourceTextX p, OutputableBndrId p) => SDoc -> (IdP p) -> LHsExpr p -> SDoc -> SDoc ppr_splice herald n e trail - = herald <> ifPprDebug (brackets (ppr n)) <> ppr e <> trail + = herald <> whenPprDebug (brackets (ppr n)) <> ppr e <> trail -- | Haskell Bracket data HsBracket p = ExpBr (LHsExpr p) -- [| expr |] @@ -2519,13 +2519,11 @@ pprStmtContext (PatGuard ctxt) = text "pattern guard for" $$ pprMatchContext ctx -- transformed branch of -- transformed branch of monad comprehension pprStmtContext (ParStmtCtxt c) = - sdocWithPprDebug $ \dbg -> if dbg - then sep [text "parallel branch of", pprAStmtContext c] - else pprStmtContext c + ifPprDebug (sep [text "parallel branch of", pprAStmtContext c]) + (pprStmtContext c) pprStmtContext (TransStmtCtxt c) = - sdocWithPprDebug $ \dbg -> if dbg - then sep [text "transformed branch of", pprAStmtContext c] - else pprStmtContext c + ifPprDebug (sep [text "transformed branch of", pprAStmtContext c]) + (pprStmtContext c) instance (Outputable p, Outputable (NameOrRdrName p)) => Outputable (HsStmtContext p) where |