summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-10-12 10:31:42 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2021-10-12 16:54:34 +0100
commit2d4ad12df2b46eacf9b618262ba821c58df35bdb (patch)
tree9d30ba7dcd10f44e76e93afd5b86c498ee761415
parent245ab1662edd91a82c17de110c79450fec3f7b82 (diff)
downloadhaskell-wip/strict-annotation-fields.tar.gz
Some extra strictness in annotation fieldswip/strict-annotation-fields
Locations can be quite long-lived so it's important that things which live in locations, such as annotations are forced promptly. Otherwise they end up retaining the entire PState, as evidenced by this retainer trace: ``` PState 0x4277ce6cd8 0x4277ce6d00 0x7f61f12d37d8 0x7f61f12d37d8 0x7f61f135ef78 0x4277ce6d48 0x4277ce6d58 0x4277ce6d70 0x4277ce6d58 0x4277ce6d88 0x4277ce6da0 0x7f61f29782f0 0x7f61cd16b440 0x7f61cd16b440 0x7f61d00f8d18 0x7f61f296d290 0x7f61cd16b440 0x7f61d00f8d18 0x7f61cd16b4a8 0x7f61f135ef78 0x4277ce6db8 0x4277ce6dd0 0x7f61f134f358 0 3 <PState:GHC.Parser.Lexer:_build-ipe/stage1/compiler/build/GHC/Parser/Lexer.hs:3779:46> _thunk( ) 0x4277ce6280 0x4277ce68a0 <([LEpaComment], [LEpaComment]):GHC.Parser.Lexer:> _thunk( ) 0x4277ce6568 <EpAnnComments:GHC.Parser.Lexer:compiler/GHC/Parser/Lexer.x:2306:19-40> _thunk( ) 0x4277ce62b0 0x4277ce62c0 0x4277ce6280 0x7f61f287fc58 <EpAnn AnnList:GHC.Parser:_build-ipe/stage1/compiler/build/GHC/Parser.hs:12664:13-32> SrcSpanAnn 0x4277ce6060 0x4277ce6048 <SrcSpanAnn':GHC.Parser:_build-ipe/stage1/compiler/build/GHC/Parser.hs:12664:3-35> L 0x4277ce4e70 0x428f8c9158 <GenLocated:GHC.Data.BooleanFormula:compiler/GHC/Data/BooleanFormula.hs:40:23-29> 0x428f8c8318 : 0x428f8c8300 <[]:GHC.Base:libraries/base/GHC/Base.hs:1316:16-29> Or 0x428f8c7890 <BooleanFormula:GHC.Data.BooleanFormula:compiler/GHC/Data/BooleanFormula.hs:40:23-29> IfConcreteClass 0x7f61cd16b440 0x7f61cd16b440 0x428f8c7018 0x428f8c7030 <IfaceClassBody:GHC.Iface.Make:compiler/GHC/Iface/Make.hs:(640,12)-(645,13)> ``` Making these few places strict is sufficient for now but there are perhaps more places which will need strictifying in future. ------------------------- Metric Increase: parsing001 -------------------------
-rw-r--r--compiler/GHC/Parser/Annotation.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs
index 1692d394b5..ab0026d1a7 100644
--- a/compiler/GHC/Parser/Annotation.hs
+++ b/compiler/GHC/Parser/Annotation.hs
@@ -496,11 +496,11 @@ instance Outputable AddEpAnn where
-- new AST fragments out of old ones, and have them still printed out
-- in a precise way.
data EpAnn ann
- = EpAnn { entry :: Anchor
+ = EpAnn { entry :: !Anchor
-- ^ Base location for the start of the syntactic element
-- holding the annotations.
- , anns :: ann -- ^ Annotations added by the Parser
- , comments :: EpAnnComments
+ , anns :: !ann -- ^ Annotations added by the Parser
+ , comments :: !EpAnnComments
-- ^ Comments enclosed in the SrcSpan of the element
-- this `EpAnn` is attached to
}
@@ -567,7 +567,10 @@ emptyComments = EpaComments []
-- | The 'SrcSpanAnn\'' type wraps a normal 'SrcSpan', together with
-- an extra annotation type. This is mapped to a specific `GenLocated`
-- usage in the AST through the `XRec` and `Anno` type families.
-data SrcSpanAnn' a = SrcSpanAnn { ann :: a, locA :: SrcSpan }
+
+-- Important that the fields are strict as these live inside L nodes which
+-- are live for a long time.
+data SrcSpanAnn' a = SrcSpanAnn { ann :: !a, locA :: !SrcSpan }
deriving (Data, Eq)
-- See Note [XRec and Anno in the AST]