diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2021-04-06 15:51:38 +0300 |
---|---|---|
committer | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2021-05-22 22:17:04 +0300 |
commit | 385c8d8809b26b2d86883041d42fd1a33a80e990 (patch) | |
tree | db9c01ec2678aa78ce7c230668c5f83a7f49c34d /compiler/GHC/Parser/PostProcess.hs | |
parent | 503388c53b0860e5a1fca11113ac7fc3e1e44492 (diff) | |
download | haskell-wip/strict-maybe.tar.gz |
Introduce Strict.Maybe, Strict.Pair (#19156)wip/strict-maybe
This patch fixes a space leak related to the use of
Maybe in RealSrcSpan by introducing a strict variant
of Maybe.
In addition to that, it also introduces a strict pair
and uses the newly introduced strict data types in a few
other places (e.g. the lexer/parser state) to reduce
allocations.
Includes a regression test.
Diffstat (limited to 'compiler/GHC/Parser/PostProcess.hs')
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 62d6c6b834..d7abde5975 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -147,6 +147,7 @@ import qualified Data.Semigroup as Semi import GHC.Utils.Panic import GHC.Utils.Panic.Plain import qualified GHC.LanguageExtensions as LangExt +import qualified GHC.Data.Strict as Strict import Control.Monad import Text.ParserCombinators.ReadP as ReadP @@ -963,13 +964,13 @@ checkTyClHdr is_cls ty lr = combineRealSrcSpans (realSrcSpan l) (anchor as) -- lr = widenAnchorR as (realSrcSpan l) an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c []) cs) - in SrcSpanAnn an (RealSrcSpan lr Nothing) + in SrcSpanAnn an (RealSrcSpan lr Strict.Nothing) newAnns _ EpAnnNotUsed = panic "missing AnnParen" newAnns (SrcSpanAnn (EpAnn ap (AnnListItem ta) csp) l) (EpAnn as (AnnParen _ o c) cs) = let lr = combineRealSrcSpans (anchor ap) (anchor as) an = (EpAnn (Anchor lr UnchangedAnchor) (NameAnn NameParens o (EpaSpan $ realSrcSpan l) c ta) (csp Semi.<> cs)) - in SrcSpanAnn an (RealSrcSpan lr Nothing) + in SrcSpanAnn an (RealSrcSpan lr Strict.Nothing) -- | Yield a parse error if we have a function applied directly to a do block -- etc. and BlockArguments is not enabled. @@ -1053,18 +1054,18 @@ checkImportDecl mPre mPost = do -- 'ImportQualifiedPost' is not in effect. whenJust mPost $ \post -> when (not importQualifiedPostEnabled) $ - failOpNotEnabledImportQualifiedPost (RealSrcSpan (epaLocationRealSrcSpan post) Nothing) + failOpNotEnabledImportQualifiedPost (RealSrcSpan (epaLocationRealSrcSpan post) Strict.Nothing) -- Error if 'qualified' occurs in both pre and postpositive -- positions. whenJust mPost $ \post -> when (isJust mPre) $ - failOpImportQualifiedTwice (RealSrcSpan (epaLocationRealSrcSpan post) Nothing) + failOpImportQualifiedTwice (RealSrcSpan (epaLocationRealSrcSpan post) Strict.Nothing) -- Warn if 'qualified' found in prepositive position and -- 'Opt_WarnPrepositiveQualifiedModule' is enabled. whenJust mPre $ \pre -> - warnPrepositiveQualifiedModule (RealSrcSpan (epaLocationRealSrcSpan pre) Nothing) + warnPrepositiveQualifiedModule (RealSrcSpan (epaLocationRealSrcSpan pre) Strict.Nothing) -- ------------------------------------------------------------------------- -- Checking Patterns. @@ -2724,7 +2725,7 @@ data PV_Accum = PV_Accum { pv_warnings :: Bag PsWarning , pv_errors :: Bag PsError - , pv_header_comments :: Maybe [LEpaComment] + , pv_header_comments :: Strict.Maybe [LEpaComment] , pv_comment_q :: [LEpaComment] } @@ -2828,7 +2829,7 @@ instance MonadP PV where PV_Ok s { pv_header_comments = header_comments', pv_comment_q = comment_q' - } (EpaCommentsBalanced (fromMaybe [] header_comments') (reverse newAnns)) + } (EpaCommentsBalanced (Strict.fromMaybe [] header_comments') (reverse newAnns)) {- Note [Parser-Validator Hint] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |