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. --- .../tests/ghc-api/annotations-literals/parsed.hs | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'testsuite') diff --git a/testsuite/tests/ghc-api/annotations-literals/parsed.hs b/testsuite/tests/ghc-api/annotations-literals/parsed.hs index 06fa9ea60d..9e9ae93c29 100644 --- a/testsuite/tests/ghc-api/annotations-literals/parsed.hs +++ b/testsuite/tests/ghc-api/annotations-literals/parsed.hs @@ -3,6 +3,7 @@ -- argument. module Main where +import GHC.Data.FastString import GHC.Types.Basic import GHC.Types.SourceText import Data.Data @@ -46,32 +47,32 @@ testOneFile libdir fileName = do doHsLit :: HsLit GhcPs -> [String] doHsLit (HsChar (SourceText src) c) - = ["HsChar [" ++ src ++ "] " ++ show c] + = ["HsChar [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsCharPrim (SourceText src) c) - = ["HsCharPrim [" ++ src ++ "] " ++ show c] + = ["HsCharPrim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsString (SourceText src) c) - = ["HsString [" ++ src ++ "] " ++ show c] + = ["HsString [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsStringPrim (SourceText src) c) - = ["HsStringPrim [" ++ src ++ "] " ++ show c] + = ["HsStringPrim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsInt _ (IL (SourceText src) _ c)) - = ["HsInt [" ++ src ++ "] " ++ show c] + = ["HsInt [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsIntPrim (SourceText src) c) - = ["HsIntPrim [" ++ src ++ "] " ++ show c] + = ["HsIntPrim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsWordPrim (SourceText src) c) - = ["HsWordPrim [" ++ src ++ "] " ++ show c] + = ["HsWordPrim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsInt64Prim (SourceText src) c) - = ["HsInt64Prim [" ++ src ++ "] " ++ show c] + = ["HsInt64Prim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsWord64Prim (SourceText src) c) - = ["HsWord64Prim [" ++ src ++ "] " ++ show c] + = ["HsWord64Prim [" ++ unpackFS src ++ "] " ++ show c] doHsLit (HsInteger (SourceText src) c _) - = ["HsInteger [" ++ src ++ "] " ++ show c] + = ["HsInteger [" ++ unpackFS src ++ "] " ++ show c] doHsLit _ = [] doOverLit :: OverLitVal -> [String] doOverLit (HsIntegral (IL (SourceText src) _ c)) - = ["HsIntegral [" ++ src ++ "] " ++ show c] + = ["HsIntegral [" ++ unpackFS src ++ "] " ++ show c] doOverLit (HsIsString (SourceText src) c) - = ["HsIsString [" ++ src ++ "] " ++ show c] + = ["HsIsString [" ++ unpackFS src ++ "] " ++ show c] doOverLit _ = [] pp a = showPprUnsafe a -- cgit v1.2.1