Commit 4fe9eaff authored by Matthew Pickering's avatar Matthew Pickering Committed by Marge Bot
Browse files

Key ModSummary cache by UnitId as well as FilePath

Multiple units can refer to the same files without any problem. Just
another assumption which needs to be updated when we may have multiple
home units.

However, there is the invariant that within each unit each file only
maps to one module, so as long as we also key the cache by UnitId then
we are all good.

This led to some confusing behaviour in GHCi when reloading,
multipleHomeUnits_shared distils the essence of what can go wrong.

Fixes #22679
parent 06cc0a95
......@@ -1580,11 +1580,13 @@ downsweep hsc_env old_summaries excl_mods allow_dup_roots
logger = hsc_logger hsc_env
roots = hsc_targets hsc_env
-- A cache from file paths to the already summarised modules.
-- A cache from file paths to the already summarised modules. The same file
-- can be used in multiple units so the map is also keyed by which unit the
-- file was used in.
-- Reuse these if we can because the most expensive part of downsweep is
-- reading the headers.
old_summary_map :: M.Map FilePath ModSummary
old_summary_map = M.fromList [(msHsFilePath ms, ms) | ms <- old_summaries]
old_summary_map :: M.Map (UnitId, FilePath) ModSummary
old_summary_map = M.fromList [((ms_unitid ms, msHsFilePath ms), ms) | ms <- old_summaries]
getRootSummary :: Target -> IO (Either (UnitId, DriverMessages) ModSummary)
getRootSummary Target { targetId = TargetFile file mb_phase
......@@ -1966,7 +1968,7 @@ mkRootMap summaries = Map.fromListWith (flip (++))
:: HscEnv
-> HomeUnit
-> M.Map FilePath ModSummary -- old summaries
-> M.Map (UnitId, FilePath) ModSummary -- old summaries
-> FilePath -- source file name
-> Maybe Phase -- start phase
-> Maybe (StringBuffer,UTCTime)
......@@ -1974,9 +1976,8 @@ summariseFile
summariseFile hsc_env' home_unit old_summaries src_fn mb_phase maybe_buf
-- we can use a cached summary if one is available and the
-- source file hasn't changed, But we have to look up the summary
-- by source file, rather than module name as we do in summarise.
| Just old_summary <- M.lookup src_fn old_summaries
-- source file hasn't changed,
| Just old_summary <- M.lookup (homeUnitId home_unit, src_fn) old_summaries
= do
let location = ms_location $ old_summary
......@@ -2085,7 +2086,7 @@ data SummariseResult =
:: HscEnv
-> HomeUnit
-> M.Map FilePath ModSummary
-> M.Map (UnitId, FilePath) ModSummary
-- ^ Map of old summaries
-> IsBootInterface -- True <=> a {-# SOURCE #-} import
-> Located ModuleName -- Imported module to be summarised
......@@ -2146,7 +2147,7 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p
Right ms -> FoundHome ms
new_summary_cache_check loc mod src_fn h
| Just old_summary <- Map.lookup src_fn old_summary_map =
| Just old_summary <- Map.lookup ((toUnitId (moduleUnit mod), src_fn)) old_summary_map =
-- check the hash on the source file, and
-- return the cached summary if it hasn't changed. If the
......@@ -66,5 +66,10 @@ test('multipleHomeUnits_recomp', [copy_files,extra_files([ 'Recomp.hs', 'unitRec
test('multipleHomeUnits_recomp_th', [filter_stdout_lines(r'.*Compiling.*'), copy_files, extra_files(['thRecomp.script', 'unitRecompTH', 'unitDep', 'RecompTH.hs', 'Dep.hs', '../../ghci/shell.hs']) , extra_run_opts('-v1 -unit @unitRecompTH -unit @unitDep')], ghci_script, ['thRecomp.script'])
test('multipleHomeUnits_shared', [extra_files([ 'A.hs', 'unitShared1', 'unitShared2'])], multiunit_compile, [['unitShared1', 'unitShared2'], '-fhide-source-paths'])
test('multipleHomeUnits_shared_ghci', [extra_files([ 'shared.script', 'A.hs', 'unitShared1', 'unitShared2']), extra_run_opts('-unit @unitShared1 -unit @unitShared2')], ghci_script, ['shared.script'])
[1 of 2] Compiling A[shared1]
[2 of 2] Compiling A[shared2]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment