Remove CPP

pull/357/head
Taylor Fausak 2021-11-06 17:03:42 +00:00 committed by GitHub
parent 0c33d9a6fa
commit d89cf0ad30
2 changed files with 2 additions and 92 deletions

View File

@ -1,11 +1,6 @@
#define INSERTTRACES 0
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
#if !INSERTTRACES
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
#endif
module Language.Haskell.Brittany.Internal.BackendUtils module Language.Haskell.Brittany.Internal.BackendUtils
( layoutWriteAppend ( layoutWriteAppend
@ -58,13 +53,7 @@ traceLocal
:: (MonadMultiState LayoutState m, MonadMultiWriter (Seq String) m, Show a) :: (MonadMultiState LayoutState m, MonadMultiWriter (Seq String) m, Show a)
=> a => a
-> m () -> m ()
#if INSERTTRACES
traceLocal x = do
mGet >>= tellDebugMessShow @LayoutState
tellDebugMessShow x
#else
traceLocal _ = return () traceLocal _ = return ()
#endif
layoutWriteAppend layoutWriteAppend
@ -79,21 +68,12 @@ layoutWriteAppend t = do
state <- mGet state <- mGet
case _lstate_curYOrAddNewline state of case _lstate_curYOrAddNewline state of
Right i -> do Right i -> do
#if INSERTTRACES
tellDebugMessShow (" inserted newlines: ", i)
#endif
replicateM_ i $ mTell $ Text.Builder.fromString $ "\n" replicateM_ i $ mTell $ Text.Builder.fromString $ "\n"
Left{} -> do Left{} -> do
#if INSERTTRACES
tellDebugMessShow (" inserted no newlines")
#endif
return () return ()
let spaces = case _lstate_addSepSpace state of let spaces = case _lstate_addSepSpace state of
Just i -> i Just i -> i
Nothing -> 0 Nothing -> 0
#if INSERTTRACES
tellDebugMessShow (" inserted spaces: ", spaces)
#endif
mTell $ Text.Builder.fromText $ Text.pack (replicate spaces ' ') mTell $ Text.Builder.fromText $ Text.pack (replicate spaces ' ')
mTell $ Text.Builder.fromText $ t mTell $ Text.Builder.fromText $ t
mModify $ \s -> s mModify $ \s -> s
@ -303,9 +283,6 @@ layoutRemoveIndentLevelLinger :: ( MonadMultiState LayoutState m
, MonadMultiWriter (Seq String) m , MonadMultiWriter (Seq String) m
) => m () ) => m ()
layoutRemoveIndentLevelLinger = do layoutRemoveIndentLevelLinger = do
#if INSERTTRACES
tellDebugMessShow ("layoutRemoveIndentLevelLinger")
#endif
mModify $ \s -> s { _lstate_indLevelLinger = lstate_indLevel s mModify $ \s -> s { _lstate_indLevelLinger = lstate_indLevel s
} }
@ -318,9 +295,6 @@ layoutWithAddBaseCol
=> m () => m ()
-> m () -> m ()
layoutWithAddBaseCol m = do layoutWithAddBaseCol m = do
#if INSERTTRACES
tellDebugMessShow ("layoutWithAddBaseCol")
#endif
amount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack amount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
state <- mGet state <- mGet
layoutBaseYPushInternal $ lstate_baseY state + amount layoutBaseYPushInternal $ lstate_baseY state + amount
@ -336,9 +310,6 @@ layoutWithAddBaseColBlock
=> m () => m ()
-> m () -> m ()
layoutWithAddBaseColBlock m = do layoutWithAddBaseColBlock m = do
#if INSERTTRACES
tellDebugMessShow ("layoutWithAddBaseColBlock")
#endif
amount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack amount <- mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
state <- mGet state <- mGet
layoutBaseYPushInternal $ lstate_baseY state + amount layoutBaseYPushInternal $ lstate_baseY state + amount
@ -390,9 +361,6 @@ layoutWithAddBaseColN
-> m () -> m ()
-> m () -> m ()
layoutWithAddBaseColN amount m = do layoutWithAddBaseColN amount m = do
#if INSERTTRACES
tellDebugMessShow ("layoutWithAddBaseColN", amount)
#endif
state <- mGet state <- mGet
layoutBaseYPushInternal $ lstate_baseY state + amount layoutBaseYPushInternal $ lstate_baseY state + amount
m m
@ -444,9 +412,6 @@ layoutAddSepSpace :: (MonadMultiState LayoutState m
, MonadMultiWriter (Seq String) m) , MonadMultiWriter (Seq String) m)
=> m () => m ()
layoutAddSepSpace = do layoutAddSepSpace = do
#if INSERTTRACES
tellDebugMessShow ("layoutAddSepSpace")
#endif
state <- mGet state <- mGet
mSet $ state mSet $ state
{ _lstate_addSepSpace = Just $ fromMaybe 1 $ _lstate_addSepSpace state } { _lstate_addSepSpace = Just $ fromMaybe 1 $ _lstate_addSepSpace state }
@ -523,9 +488,6 @@ layoutWritePriorComments ast = do
Map.adjust (\ann -> ann { ExactPrint.annPriorComments = [] }) key anns Map.adjust (\ann -> ann { ExactPrint.annPriorComments = [] }) key anns
} }
return mAnn return mAnn
#if INSERTTRACES
tellDebugMessShow ("layoutWritePriorComments", ExactPrint.mkAnnKey ast, mAnn)
#endif
case mAnn of case mAnn of
Nothing -> return () Nothing -> return ()
Just priors -> do Just priors -> do
@ -559,9 +521,6 @@ layoutWritePostComments ast = do
anns anns
} }
return mAnn return mAnn
#if INSERTTRACES
tellDebugMessShow ("layoutWritePostComments", ExactPrint.mkAnnKey ast, mAnn)
#endif
case mAnn of case mAnn of
Nothing -> return () Nothing -> return ()
Just posts -> do Just posts -> do
@ -584,9 +543,6 @@ layoutIndentRestorePostComment = do
state <- mGet state <- mGet
let mCommentCol = _lstate_commentCol state let mCommentCol = _lstate_commentCol state
let eCurYAddNL = _lstate_curYOrAddNewline state let eCurYAddNL = _lstate_curYOrAddNewline state
#if INSERTTRACES
tellDebugMessShow ("layoutIndentRestorePostComment", mCommentCol)
#endif
mModify $ \s -> s { _lstate_commentCol = Nothing mModify $ \s -> s { _lstate_commentCol = Nothing
, _lstate_commentNewlines = 0 , _lstate_commentNewlines = 0
} }

View File

@ -1,7 +1,3 @@
#define INSERTTRACESALT 0
#define INSERTTRACESALTVISIT 0
#define INSERTTRACESGETSPACING 0
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
@ -117,14 +113,6 @@ transformAlts =
rec :: BriDocNumbered -> Memo.MemoT Int [VerticalSpacing] (MultiRWSS.MultiRWS r w (AltCurPos ': s)) BriDocNumbered rec :: BriDocNumbered -> Memo.MemoT Int [VerticalSpacing] (MultiRWSS.MultiRWS r w (AltCurPos ': s)) BriDocNumbered
rec bdX@(brDcId, brDc) = do rec bdX@(brDcId, brDc) = do
#if INSERTTRACESALTVISIT
do
acp :: AltCurPos <- mGet
tellDebugMess $ "transformAlts: visiting: " ++ case brDc of
BDFAnnotationPrior annKey _ -> show (toConstr brDc, annKey, acp)
BDFAnnotationRest annKey _ -> show (toConstr brDc, annKey, acp)
_ -> show (toConstr brDc, acp)
#endif
let reWrap = (,) brDcId let reWrap = (,) brDcId
-- debugAcp :: AltCurPos <- mGet -- debugAcp :: AltCurPos <- mGet
case brDc of case brDc of
@ -206,20 +194,10 @@ transformAlts =
-- TODO: use COMPLETE pragma instead? -- TODO: use COMPLETE pragma instead?
lineCheck _ = error "ghc exhaustive check is insufficient" lineCheck _ = error "ghc exhaustive check is insufficient"
lconf <- _conf_layout <$> mAsk lconf <- _conf_layout <$> mAsk
#if INSERTTRACESALT
tellDebugMess $ "considering options with " ++ show (length alts, acp)
#endif
let options = -- trace ("considering options:" ++ show (length alts, acp)) $ let options = -- trace ("considering options:" ++ show (length alts, acp)) $
(zip spacings alts (zip spacings alts
<&> \(vs, bd) -> -- trace ("spacing=" ++ show vs ++ ",hasSpace=" ++ show (hasSpace lconf acp vs) ++ ",lineCheck=" ++ show (lineCheck vs)) <&> \(vs, bd) -> -- trace ("spacing=" ++ show vs ++ ",hasSpace=" ++ show (hasSpace lconf acp vs) ++ ",lineCheck=" ++ show (lineCheck vs))
( hasSpace1 lconf acp vs && lineCheck vs, bd)) ( hasSpace1 lconf acp vs && lineCheck vs, bd))
#if INSERTTRACESALT
zip spacings options `forM_` \(vs, (_, bd)) ->
tellDebugMess $ " " ++ "spacing=" ++ show vs
++ ",hasSpace1=" ++ show (hasSpace1 lconf acp vs)
++ ",lineCheck=" ++ show (lineCheck vs)
++ " " ++ show (toConstr bd)
#endif
id -- - $ (fmap $ \x -> traceShow (briDocToDoc x) x) id -- - $ (fmap $ \x -> traceShow (briDocToDoc x) x)
$ rec $ rec
$ fromMaybe (-- trace ("choosing last") $ $ fromMaybe (-- trace ("choosing last") $
@ -240,9 +218,6 @@ transformAlts =
AltLineModeStateForceML{} -> p /= VerticalSpacingParNone AltLineModeStateForceML{} -> p /= VerticalSpacingParNone
AltLineModeStateContradiction -> False AltLineModeStateContradiction -> False
lconf <- _conf_layout <$> mAsk lconf <- _conf_layout <$> mAsk
#if INSERTTRACESALT
tellDebugMess $ "considering options with " ++ show (length alts, acp)
#endif
let options = -- trace ("considering options:" ++ show (length alts, acp)) $ let options = -- trace ("considering options:" ++ show (length alts, acp)) $
(zip spacings alts (zip spacings alts
<&> \(vs, bd) -> -- trace ("spacing=" ++ show vs ++ ",hasSpace=" ++ show (hasSpace lconf acp vs) ++ ",lineCheck=" ++ show (lineCheck vs)) <&> \(vs, bd) -> -- trace ("spacing=" ++ show vs ++ ",hasSpace=" ++ show (hasSpace lconf acp vs) ++ ",lineCheck=" ++ show (lineCheck vs))
@ -250,14 +225,6 @@ transformAlts =
&& any lineCheck vs, bd)) && any lineCheck vs, bd))
let checkedOptions :: [Maybe (Int, BriDocNumbered)] = let checkedOptions :: [Maybe (Int, BriDocNumbered)] =
zip [1..] options <&> (\(i, (b,x)) -> [ (i, x) | b ]) zip [1..] options <&> (\(i, (b,x)) -> [ (i, x) | b ])
#if INSERTTRACESALT
zip spacings options `forM_` \(vs, (_, bd)) ->
tellDebugMess $ " " ++ "spacing=" ++ show vs
++ ",hasSpace2=" ++ show (hasSpace2 lconf acp <$> vs)
++ ",lineCheck=" ++ show (lineCheck <$> vs)
++ " " ++ show (toConstr bd)
tellDebugMess $ " " ++ show (Data.Maybe.mapMaybe (fmap fst) checkedOptions)
#endif
id -- - $ (fmap $ \x -> traceShow (briDocToDoc x) x) id -- - $ (fmap $ \x -> traceShow (briDocToDoc x) x)
$ rec $ rec
$ fromMaybe (-- trace ("choosing last") $ $ fromMaybe (-- trace ("choosing last") $
@ -510,9 +477,6 @@ getSpacing !bridoc = rec bridoc
r <- rec bd r <- rec bd
tellDebugMess $ "getSpacing: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): mVs=" ++ show r tellDebugMess $ "getSpacing: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): mVs=" ++ show r
return r return r
#if INSERTTRACESGETSPACING
tellDebugMess $ "getSpacing: visiting: " ++ show (toConstr $ brDc) ++ " -> " ++ show result
#endif
return result return result
maxVs :: [LineModeValidity VerticalSpacing] -> LineModeValidity VerticalSpacing maxVs :: [LineModeValidity VerticalSpacing] -> LineModeValidity VerticalSpacing
maxVs = foldl' maxVs = foldl'
@ -867,16 +831,6 @@ getSpacings limit bridoc = preFilterLimit <$> rec bridoc
r <- rec bd r <- rec bd
tellDebugMess $ "getSpacings: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): vs=" ++ show (take 9 r) tellDebugMess $ "getSpacings: BDFDebug " ++ show s ++ " (node-id=" ++ show brDcId ++ "): vs=" ++ show (take 9 r)
return r return r
#if INSERTTRACESGETSPACING
case brdc of
BDFAnnotationPrior{} -> return ()
BDFAnnotationRest{} -> return ()
_ -> mTell $ Seq.fromList ["getSpacings: visiting: "
++ show (toConstr $ brdc) -- (briDocToDoc $ unwrapBriDocNumbered (0, brdc))
, " -> "
++ show (take 9 result)
]
#endif
return result return result
maxVs :: [VerticalSpacing] -> VerticalSpacing maxVs :: [VerticalSpacing] -> VerticalSpacing
maxVs = foldl' maxVs = foldl'