summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit/Module/Location.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-09-30 11:12:10 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-19 03:30:16 -0400
commitdf419c1abd7daa3aa0231747582333357b8e9b85 (patch)
treea73aaf04830425c43afe525f22138ca58550301e /compiler/GHC/Unit/Module/Location.hs
parent8144a92f5a73dd22c0d855d5b2bead930111511c (diff)
downloadhaskell-df419c1abd7daa3aa0231747582333357b8e9b85.tar.gz
driver: Cleanups related to ModLocation
ModLocation is the data type which tells you the locations of all the build products which can affect recompilation. It is now computed in one place and not modified through the pipeline. Important locations will now just consult ModLocation rather than construct the dynamic object path incorrectly. * Add paths for dynamic object and dynamic interface files to ModLocation. * Always use the paths from mod location when looking for where to find any interface or object file. * Always use the paths in a ModLocation when deciding where to write an interface and object file. * Remove `dynamicOutputFile` and `dynamicOutputHi` functions which *calculated* (incorrectly) the location of `dyn_o` and `dyn_hi` files. * Don't set `outputFile_` and so-on in `enableCodeGenWhen`, `-o` and hence `outputFile_` should not affect the location of object files in `--make` mode. It is now sufficient to just update the ModLocation with the temporary paths. * In `hscGenBackendPipeline` don't recompute the `ModLocation` to account for `-dynamic-too`, the paths are now accurate from the start of the run. * Rename `getLocation` to `mkOneShotModLocation`, as that's the only place it's used. Increase the locality of the definition by moving it close to the use-site. * Load the dynamic interface from ml_dyn_hi_file rather than attempting to reconstruct it in load_dynamic_too. * Add a variety of tests to check how -o -dyno etc interact with each other. Some other clean-ups * DeIOify mkHomeModLocation and friends, they are all pure functions. * Move FinderOpts into GHC.Driver.Config.Finder, next to initFinderOpts. * Be more precise about whether we mean outputFile or outputFile_: there were many places where outputFile was used but the result shouldn't have been affected by `-dyno` (for example the filename of the resulting executable). In these places dynamicNow would never be set but it's still more precise to not allow for this possibility. * Typo fixes suffices -> suffixes in the appropiate places.
Diffstat (limited to 'compiler/GHC/Unit/Module/Location.hs')
-rw-r--r--compiler/GHC/Unit/Module/Location.hs27
1 files changed, 25 insertions, 2 deletions
diff --git a/compiler/GHC/Unit/Module/Location.hs b/compiler/GHC/Unit/Module/Location.hs
index ff5354bfdb..866ccf127a 100644
--- a/compiler/GHC/Unit/Module/Location.hs
+++ b/compiler/GHC/Unit/Module/Location.hs
@@ -16,7 +16,7 @@ import GHC.Utils.Outputable
-- | Module Location
--
-- Where a module lives on the file system: the actual locations
--- of the .hs, .hi and .o files, if we have them.
+-- of the .hs, .hi, .dyn_hi, .o, .dyn_o and .hie files, if we have them.
--
-- For a module in another unit, the ml_hs_file and ml_obj_file components of
-- ModLocation are undefined.
@@ -25,6 +25,16 @@ import GHC.Utils.Outputable
-- correspond to actual files yet: for example, even if the object
-- file doesn't exist, the ModLocation still contains the path to
-- where the object file will reside if/when it is created.
+--
+-- The paths of anything which can affect recompilation should be placed inside
+-- ModLocation.
+--
+-- When a ModLocation is created none of the filepaths will have -boot suffixes.
+-- This is because in --make mode the ModLocation is put in the finder cache which
+-- is indexed by ModuleName, when a ModLocation is retrieved from the FinderCache
+-- the boot suffixes are appended.
+-- The other case is in -c mode, there the ModLocation immediately gets given the
+-- boot suffixes in mkOneShotModLocation.
data ModLocation
= ModLocation {
@@ -37,12 +47,20 @@ data ModLocation
-- yet. Always of form foo.hi, even if there is an
-- hi-boot file (we add the -boot suffix later)
+ ml_dyn_hi_file :: FilePath,
+ -- ^ Where the .dyn_hi file is, whether or not it exists
+ -- yet.
+
ml_obj_file :: FilePath,
-- ^ Where the .o file is, whether or not it exists yet.
-- (might not exist either because the module hasn't
-- been compiled yet, or because it is part of a
-- unit with a .a file)
+ ml_dyn_obj_file :: FilePath,
+ -- ^ Where the .dy file is, whether or not it exists
+ -- yet.
+
ml_hie_file :: FilePath
-- ^ Where the .hie file is, whether or not it exists
-- yet.
@@ -73,7 +91,9 @@ addBootSuffixLocn :: ModLocation -> ModLocation
addBootSuffixLocn locn
= locn { ml_hs_file = fmap addBootSuffix (ml_hs_file locn)
, ml_hi_file = addBootSuffix (ml_hi_file locn)
+ , ml_dyn_hi_file = addBootSuffix (ml_dyn_hi_file locn)
, ml_obj_file = addBootSuffix (ml_obj_file locn)
+ , ml_dyn_obj_file = addBootSuffix (ml_dyn_obj_file locn)
, ml_hie_file = addBootSuffix (ml_hie_file locn) }
-- | Add the @-boot@ suffix to all output file paths associated with the
@@ -81,7 +101,10 @@ addBootSuffixLocn locn
addBootSuffixLocnOut :: ModLocation -> ModLocation
addBootSuffixLocnOut locn
= locn { ml_hi_file = addBootSuffix (ml_hi_file locn)
+ , ml_dyn_hi_file = addBootSuffix (ml_dyn_hi_file locn)
, ml_obj_file = addBootSuffix (ml_obj_file locn)
- , ml_hie_file = addBootSuffix (ml_hie_file locn) }
+ , ml_dyn_obj_file = addBootSuffix (ml_dyn_obj_file locn)
+ , ml_hie_file = addBootSuffix (ml_hie_file locn)
+ }