summaryrefslogtreecommitdiff
path: root/compiler/GHC/Parser/PostProcess
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2021-04-06 15:51:38 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-23 18:53:13 -0400
commitd82d38239f232c3970a8641bb6d47d436e3cbc11 (patch)
tree55b162143144486cddda1b2a2a7ca0b7eb373a1c /compiler/GHC/Parser/PostProcess
parent82c6a9394b0457e77bc8b03e3594111b51508469 (diff)
downloadhaskell-d82d38239f232c3970a8641bb6d47d436e3cbc11.tar.gz
Introduce Strict.Maybe, Strict.Pair (#19156)
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')
-rw-r--r--compiler/GHC/Parser/PostProcess/Haddock.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/GHC/Parser/PostProcess/Haddock.hs b/compiler/GHC/Parser/PostProcess/Haddock.hs
index 189ddce29c..301e902f8b 100644
--- a/compiler/GHC/Parser/PostProcess/Haddock.hs
+++ b/compiler/GHC/Parser/PostProcess/Haddock.hs
@@ -73,6 +73,7 @@ import qualified Data.Monoid
import GHC.Parser.Lexer
import GHC.Parser.Errors
import GHC.Utils.Misc (mergeListsBy, filterOut, mapLastM, (<&&>))
+import qualified GHC.Data.Strict as Strict
{- Note [Adding Haddock comments to the syntax tree]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1023,7 +1024,8 @@ instance HasHaddock (LocatedA (HsType GhcPs)) where
-- which it is used.
data HdkA a =
HdkA
- !(Maybe BufSpan) -- Just b <=> BufSpan occupied by the processed AST element.
+ !(Strict.Maybe BufSpan)
+ -- Just b <=> BufSpan occupied by the processed AST element.
-- The surrounding computations will not look inside.
--
-- Nothing <=> No BufSpan (e.g. when the HdkA is constructed by 'pure' or 'liftHdkA').
@@ -1056,9 +1058,9 @@ instance Applicative HdkA where
-- These delim1/delim2 are key to how HdkA operates.
where
-- Delimit the LHS by the location information from the RHS
- delim1 = inLocRange (locRangeTo (fmap @Maybe bufSpanStart l2))
+ delim1 = inLocRange (locRangeTo (fmap @Strict.Maybe bufSpanStart l2))
-- Delimit the RHS by the location information from the LHS
- delim2 = inLocRange (locRangeFrom (fmap @Maybe bufSpanEnd l1))
+ delim2 = inLocRange (locRangeFrom (fmap @Strict.Maybe bufSpanEnd l1))
pure a =
-- Return a value without performing any stateful computation, and without
@@ -1377,14 +1379,14 @@ instance Monoid LocRange where
mempty = LocRange mempty mempty mempty
-- The location range from the specified position to the end of the file.
-locRangeFrom :: Maybe BufPos -> LocRange
-locRangeFrom (Just l) = mempty { loc_range_from = StartLoc l }
-locRangeFrom Nothing = mempty
+locRangeFrom :: Strict.Maybe BufPos -> LocRange
+locRangeFrom (Strict.Just l) = mempty { loc_range_from = StartLoc l }
+locRangeFrom Strict.Nothing = mempty
-- The location range from the start of the file to the specified position.
-locRangeTo :: Maybe BufPos -> LocRange
-locRangeTo (Just l) = mempty { loc_range_to = EndLoc l }
-locRangeTo Nothing = mempty
+locRangeTo :: Strict.Maybe BufPos -> LocRange
+locRangeTo (Strict.Just l) = mempty { loc_range_to = EndLoc l }
+locRangeTo Strict.Nothing = mempty
-- Represents a predicate on BufPos:
--