[commit: ghc] master: Avoid redundant invocation of 'findTopDir' (f64f06b)

git at git.haskell.org git at git.haskell.org
Fri Jul 20 14:55:04 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f64f06bebddd1dbfc6568f36fa1f91f758fa22f1/ghc

>---------------------------------------------------------------

commit f64f06bebddd1dbfc6568f36fa1f91f758fa22f1
Author: Michael Sloan <mgsloan at gmail.com>
Date:   Fri Jul 20 16:53:41 2018 +0200

    Avoid redundant invocation of 'findTopDir'
    
    Summary:
    While working on [D904](https://phabricator.haskell.org/D4904), I noticed that
    'findTopDir' was being invoked three times.  This isn't a big problem, because
    it is usually very cheap.  On windows, it does require some involved logic,
    though, so to me it would make sense to only run it once.
    
    Reviewers: bgamari, monoidal
    
    Reviewed By: monoidal
    
    Subscribers: rwbarton, thomie, carter
    
    Differential Revision: https://phabricator.haskell.org/D4987


>---------------------------------------------------------------

f64f06bebddd1dbfc6568f36fa1f91f758fa22f1
 compiler/main/GHC.hs      |  6 ++++--
 compiler/main/SysTools.hs | 16 +++++++---------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs
index 2b25646..0e20e21 100644
--- a/compiler/main/GHC.hs
+++ b/compiler/main/GHC.hs
@@ -326,6 +326,7 @@ import HscTypes
 import CmdLineParser
 import DynFlags hiding (WarnReason(..))
 import SysTools
+import SysTools.BaseDir
 import Annotations
 import Module
 import Panic
@@ -494,8 +495,9 @@ withCleanupSession ghc = ghc `gfinally` cleanup
 initGhcMonad :: GhcMonad m => Maybe FilePath -> m ()
 initGhcMonad mb_top_dir
   = do { env <- liftIO $
-                do { mySettings <- initSysTools mb_top_dir
-                   ; myLlvmConfig <- initLlvmConfig mb_top_dir
+                do { top_dir <- findTopDir mb_top_dir
+                   ; mySettings <- initSysTools top_dir
+                   ; myLlvmConfig <- initLlvmConfig top_dir
                    ; dflags <- initDynFlags (defaultDynFlags mySettings myLlvmConfig)
                    ; checkBrokenTablesNextToCode dflags
                    ; setUnsafeGlobalDynFlags dflags
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index c3d154f..ff36c04 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -110,17 +110,16 @@ stuff.
 ************************************************************************
 -}
 
-initLlvmConfig :: Maybe String
-                -> IO LlvmConfig
-initLlvmConfig mbMinusB
+initLlvmConfig :: String
+               -> IO LlvmConfig
+initLlvmConfig top_dir
   = do
       targets <- readAndParse "llvm-targets" mkLlvmTarget
       passes <- readAndParse "llvm-passes" id
       return (targets, passes)
   where
     readAndParse name builder =
-      do top_dir <- findTopDir mbMinusB
-         let llvmConfigFile = top_dir </> name
+      do let llvmConfigFile = top_dir </> name
          llvmConfigStr <- readFile llvmConfigFile
          case maybeReadFuzzy llvmConfigStr of
            Just s -> return (fmap builder <$> s)
@@ -130,14 +129,13 @@ initLlvmConfig mbMinusB
     mkLlvmTarget (dl, cpu, attrs) = LlvmTarget dl cpu (words attrs)
 
 
-initSysTools :: Maybe String    -- Maybe TopDir path (without the '-B' prefix)
+initSysTools :: String          -- TopDir path
              -> IO Settings     -- Set all the mutable variables above, holding
                                 --      (a) the system programs
                                 --      (b) the package-config file
                                 --      (c) the GHC usage message
-initSysTools mbMinusB
-  = do top_dir <- findTopDir mbMinusB
-             -- see Note [topdir: How GHC finds its files]
+initSysTools top_dir
+  = do       -- see Note [topdir: How GHC finds its files]
              -- NB: top_dir is assumed to be in standard Unix
              -- format, '/' separated
        mtool_dir <- findToolDir top_dir



More information about the ghc-commits mailing list