summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZubin Duggal <zubin.duggal@gmail.com>2023-05-04 06:07:40 +0530
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-05-16 14:00:00 -0400
commit6231a126562db917c882fdc5ecd0769081032d90 (patch)
tree9454e3e45dde97975238911a3874b177cb9d814c
parentb70bc6900fcee7ff1e334bf8099283f610d6f9d4 (diff)
downloadhaskell-6231a126562db917c882fdc5ecd0769081032d90.tar.gz
compiler: Use compact representation for UsageFile (#22744)
Use FastString to store filepaths in interface files, as this data is highly redundant so we want to share all instances of filepaths in the compiler session.
-rw-r--r--compiler/GHC/HsToCore/Usage.hs5
-rw-r--r--compiler/GHC/Iface/Load.hs2
-rw-r--r--compiler/GHC/Iface/Recomp.hs4
-rw-r--r--compiler/GHC/Unit/Module/Deps.hs4
4 files changed, 9 insertions, 6 deletions
diff --git a/compiler/GHC/HsToCore/Usage.hs b/compiler/GHC/HsToCore/Usage.hs
index e2ac533ba8..59a8c01073 100644
--- a/compiler/GHC/HsToCore/Usage.hs
+++ b/compiler/GHC/HsToCore/Usage.hs
@@ -35,6 +35,7 @@ import GHC.Unit.Module.ModIface
import GHC.Unit.Module.Deps
import GHC.Data.Maybe
+import GHC.Data.FastString
import Data.IORef
import Data.List (sortBy)
@@ -86,7 +87,7 @@ mkUsageInfo uc plugins fc unit_env this_mod dir_imp_mods used_names dependent_fi
let all_home_ids = ue_all_home_unit_ids unit_env
mod_usages <- mk_mod_usage_info uc hu all_home_ids this_mod
dir_imp_mods used_names
- let usages = mod_usages ++ [ UsageFile { usg_file_path = f
+ let usages = mod_usages ++ [ UsageFile { usg_file_path = mkFastString f
, usg_file_hash = hash
, usg_file_label = Nothing }
| (f, hash) <- zip dependent_files hashes ]
@@ -174,7 +175,7 @@ mkObjectUsage pit plugins fc hug th_links_needed th_pkgs_needed = do
msg m = moduleNameString (moduleName m) ++ "[TH] changed"
- fing mmsg fn = UsageFile fn <$> lookupFileCache fc fn <*> pure mmsg
+ fing mmsg fn = UsageFile (mkFastString fn) <$> lookupFileCache fc fn <*> pure mmsg
unlinkedToUsage m ul =
case nameOfObject_maybe ul of
diff --git a/compiler/GHC/Iface/Load.hs b/compiler/GHC/Iface/Load.hs
index 16f4b900b5..f5628e8fb6 100644
--- a/compiler/GHC/Iface/Load.hs
+++ b/compiler/GHC/Iface/Load.hs
@@ -1175,7 +1175,7 @@ pprUsage usage@UsageHomeModule{}
)
pprUsage usage@UsageFile{}
= hsep [text "addDependentFile",
- doubleQuotes (text (usg_file_path usage)),
+ doubleQuotes (ftext (usg_file_path usage)),
ppr (usg_file_hash usage)]
pprUsage usage@UsageMergedRequirement{}
= hsep [text "merged", ppr (usg_mod usage), ppr (usg_mod_hash usage)]
diff --git a/compiler/GHC/Iface/Recomp.hs b/compiler/GHC/Iface/Recomp.hs
index b0e668f0e6..298e876595 100644
--- a/compiler/GHC/Iface/Recomp.hs
+++ b/compiler/GHC/Iface/Recomp.hs
@@ -771,12 +771,12 @@ checkModUsage fc UsageFile{ usg_file_path = file,
usg_file_label = mlabel } =
liftIO $
handleIO handler $ do
- new_hash <- lookupFileCache fc file
+ new_hash <- lookupFileCache fc $ unpackFS file
if (old_hash /= new_hash)
then return recomp
else return UpToDate
where
- reason = FileChanged file
+ reason = FileChanged $ unpackFS file
recomp = needsRecompileBecause $ fromMaybe reason $ fmap CustomReason mlabel
handler = if debugIsOn
then \e -> pprTrace "UsageFile" (text (show e)) $ return recomp
diff --git a/compiler/GHC/Unit/Module/Deps.hs b/compiler/GHC/Unit/Module/Deps.hs
index 583b7fdaaa..75063e901f 100644
--- a/compiler/GHC/Unit/Module/Deps.hs
+++ b/compiler/GHC/Unit/Module/Deps.hs
@@ -21,6 +21,8 @@ where
import GHC.Prelude
+import GHC.Data.FastString
+
import GHC.Types.SafeHaskell
import GHC.Types.Name
@@ -275,7 +277,7 @@ data Usage
-- | A file upon which the module depends, e.g. a CPP #include, or using TH's
-- 'addDependentFile'
| UsageFile {
- usg_file_path :: FilePath,
+ usg_file_path :: FastString,
-- ^ External file dependency. From a CPP #include or TH
-- addDependentFile. Should be absolute.
usg_file_hash :: Fingerprint,