From 90e69d5d167b9d6cd63b04e42f8af375dc4b307f Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Thu, 4 May 2023 05:30:13 +0530 Subject: compiler: Use compact representation for SourceText SourceText is serialized along with INLINE pragmas into interface files. Many of these SourceTexts are identical, for example "{-# INLINE#". When deserialized, each such SourceText was previously expanded out into a [Char], which is highly wasteful of memory, and each such instance of the text would allocate an independent list with its contents as deserializing breaks any sharing that might have existed. Instead, we use a `FastString` to represent these, so that each instance unique text will be interned and stored in a memory efficient manner. --- compiler/GHC/Core/Opt/Simplify/Iteration.hs | 2 +- compiler/GHC/Core/Opt/WorkWrap.hs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'compiler/GHC/Core') diff --git a/compiler/GHC/Core/Opt/Simplify/Iteration.hs b/compiler/GHC/Core/Opt/Simplify/Iteration.hs index 1ecfa632e1..5a6644fd3e 100644 --- a/compiler/GHC/Core/Opt/Simplify/Iteration.hs +++ b/compiler/GHC/Core/Opt/Simplify/Iteration.hs @@ -668,7 +668,7 @@ tryCastWorkerWrapper env _ _ _ bndr rhs -- All other bindings mkCastWrapperInlinePrag :: InlinePragma -> InlinePragma -- See Note [Cast worker/wrapper] mkCastWrapperInlinePrag (InlinePragma { inl_inline = fn_inl, inl_act = fn_act, inl_rule = rule_info }) - = InlinePragma { inl_src = SourceText "{-# INLINE" + = InlinePragma { inl_src = SourceText $ fsLit "{-# INLINE" , inl_inline = fn_inl -- See Note [Worker/wrapper for INLINABLE functions] , inl_sat = Nothing -- in GHC.Core.Opt.WorkWrap , inl_act = wrap_act -- See Note [Wrapper activation] diff --git a/compiler/GHC/Core/Opt/WorkWrap.hs b/compiler/GHC/Core/Opt/WorkWrap.hs index 29f1e3973f..061f98f1bc 100644 --- a/compiler/GHC/Core/Opt/WorkWrap.hs +++ b/compiler/GHC/Core/Opt/WorkWrap.hs @@ -20,6 +20,8 @@ import GHC.Core.Type import GHC.Core.Opt.WorkWrap.Utils import GHC.Core.SimpleOpt +import GHC.Data.FastString + import GHC.Types.Var import GHC.Types.Id import GHC.Types.Id.Info @@ -819,7 +821,7 @@ mkWWBindPair ww_opts fn_id fn_info fn_args fn_body work_uniq div NoInline _ -> inl_act fn_inl_prag _ -> inl_act wrap_prag - work_prag = InlinePragma { inl_src = SourceText "{-# INLINE" + work_prag = InlinePragma { inl_src = SourceText $ fsLit "{-# INLINE" , inl_inline = fn_inline_spec , inl_sat = Nothing , inl_act = work_act @@ -887,7 +889,7 @@ mkStrWrapperInlinePrag :: InlinePragma -> [CoreRule] -> InlinePragma mkStrWrapperInlinePrag (InlinePragma { inl_inline = fn_inl , inl_act = fn_act , inl_rule = rule_info }) rules - = InlinePragma { inl_src = SourceText "{-# INLINE" + = InlinePragma { inl_src = SourceText $ fsLit "{-# INLINE" , inl_sat = Nothing , inl_inline = fn_inl -- cgit v1.2.1